CCMain.m 260 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720
  1. //
  2. // CCMain.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/09/14.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCMain.h"
  24. #import "AppDelegate.h"
  25. #import "CCPhotosCameraUpload.h"
  26. #import "CCSynchronize.h"
  27. #import "CCControlCenterTransferCell.h"
  28. #import <OCCommunicationLib/OCActivity.h>
  29. #import <OCCommunicationLib/OCNotifications.h>
  30. #import <OCCommunicationLib/OCNotificationsAction.h>
  31. #import <OCCommunicationLib/OCFrameworkConstants.h>
  32. #import <OCCommunicationLib/OCCapabilities.h>
  33. #import "CTAssetCheckmark.h"
  34. #ifdef CUSTOM_BUILD
  35. #import "NextcloudCustom-Swift.h"
  36. #else
  37. #import "Nextcloud-Swift.h"
  38. #endif
  39. #pragma GCC diagnostic ignored "-Wundeclared-selector"
  40. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  41. #define alertCreateFolder 1
  42. #define alertCreateFolderCrypto 2
  43. #define alertRename 3
  44. #define alertOfflineFolder 4
  45. @interface CCMain () <CCActionsDeleteDelegate, CCActionsRenameDelegate, CCActionsSearchDelegate, CCActionsDownloadThumbnailDelegate, CCActionsSettingFavoriteDelegate>
  46. {
  47. CCMetadata *_metadataSegue;
  48. CCMetadata *_metadata;
  49. BOOL _isRoot;
  50. BOOL _isViewDidLoad;
  51. BOOL _isOfflineServerUrl;
  52. BOOL _isPickerCriptate; // if is cryptated image or video back from picker
  53. BOOL _isSelectedMode;
  54. NSMutableArray *_selectedMetadatas;
  55. NSMutableArray *_queueSelector;
  56. NSUInteger _numSelectedMetadatas;
  57. UIImageView *_ImageTitleHomeCryptoCloud;
  58. UIView *_reMenuBackgroundView;
  59. UITapGestureRecognizer *_singleFingerTap;
  60. NSString *_directoryGroupBy;
  61. NSString *_directoryOrder;
  62. NSUInteger _failedAttempts;
  63. NSDate *_lockUntilDate;
  64. NSString *_fatherPermission;
  65. UIRefreshControl *_refreshControl;
  66. UIDocumentInteractionController *_docController;
  67. CCHud *_hud;
  68. CCHud *_hudDeterminate;
  69. // Datasource
  70. CCSectionDataSource *_sectionDataSource;
  71. NSDate *_dateReadDataSource;
  72. // Search
  73. BOOL _isSearchMode;
  74. NSString *_searchFileName;
  75. NSArray *_searchResultMetadatas;
  76. }
  77. @end
  78. @implementation CCMain
  79. #pragma --------------------------------------------------------------------------------------------
  80. #pragma mark ===== Init =====
  81. #pragma --------------------------------------------------------------------------------------------
  82. - (id)initWithCoder:(NSCoder *)aDecoder
  83. {
  84. if (self = [super initWithCoder:aDecoder]) {
  85. _directoryOrder = [CCUtility getOrderSettings];
  86. _directoryGroupBy = [CCUtility getGroupBySettings];
  87. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain:) name:@"initializeMain" object:nil];
  88. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearDateReadDataSource:) name:@"clearDateReadDataSource" object:nil];
  89. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTitle) name:@"setTitleMain" object:nil];
  90. }
  91. return self;
  92. }
  93. #pragma --------------------------------------------------------------------------------------------
  94. #pragma mark ===== View =====
  95. #pragma --------------------------------------------------------------------------------------------
  96. - (void)viewDidLoad
  97. {
  98. [super viewDidLoad];
  99. // init object
  100. _metadata = [CCMetadata new];
  101. _metadataSegue = [CCMetadata new];
  102. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  103. _hudDeterminate = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  104. _selectedMetadatas = [NSMutableArray new];
  105. _queueSelector = [NSMutableArray new];
  106. _isViewDidLoad = YES;
  107. _fatherPermission = @"";
  108. _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
  109. _searchResultMetadatas = [NSArray new];
  110. _searchFileName = @"";
  111. // delegate
  112. self.tableView.delegate = self;
  113. self.tableView.tableFooterView = [UIView new];
  114. self.tableView.separatorColor = COLOR_SEPARATOR_TABLE;
  115. self.searchController.delegate = self;
  116. self.searchController.searchBar.delegate = self;
  117. [[CCNetworking sharedNetworking] settingDelegate:self];
  118. // Custom Cell
  119. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMain" bundle:nil] forCellReuseIdentifier:@"CellMain"];
  120. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
  121. // long press recognizer TableView
  122. UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressTableView:)];
  123. [self.tableView addGestureRecognizer:longPressRecognizer];
  124. // Pull-to-Refresh
  125. [self createRefreshControl];
  126. // Register for 3D Touch Previewing if available
  127. if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable))
  128. {
  129. [self registerForPreviewingWithDelegate:self sourceView:self.view];
  130. }
  131. // Back Button
  132. if ([_serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl]])
  133. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:image_brandNavigationController] style:UIBarButtonItemStylePlain target:nil action:nil];
  134. // reMenu Background
  135. _reMenuBackgroundView = [[UIView alloc] init];
  136. _reMenuBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
  137. // if this is not Main (the Main uses inizializeMain)
  138. if (_isRoot == NO && app.activeAccount.length > 0) {
  139. // Settings this folder & delegate & Loading datasource
  140. app.directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  141. // Load Datasource
  142. [self reloadDatasource:_serverUrl fileID:nil selector:nil];
  143. // Read Folder
  144. [self readFolderWithForced:NO serverUrl:_serverUrl];
  145. }
  146. // Title
  147. [self setTitle];
  148. // List Transfers
  149. //app.controlCenter = (CCControlCenter *)self.navigationController;
  150. // Search
  151. self.definesPresentationContext = YES;
  152. self.searchController.searchResultsUpdater = self;
  153. self.searchController.dimsBackgroundDuringPresentation = NO;
  154. self.tableView.tableHeaderView = self.searchController.searchBar;
  155. self.searchController.searchBar.barTintColor = COLOR_SEPARATOR_TABLE;
  156. [self.searchController.searchBar sizeToFit];
  157. if ([CCCoreData getServerVersionActiveAccount:app.activeAccount] >= 12) {
  158. if (_isRoot)
  159. self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_all_folders_",nil);
  160. else
  161. self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_sub_folder_",nil);
  162. } else {
  163. self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_this_folder_",nil);
  164. }
  165. }
  166. // Apparirà
  167. - (void)viewWillAppear:(BOOL)animated
  168. {
  169. [super viewWillAppear:animated];
  170. // test
  171. if (app.activeAccount.length == 0)
  172. return;
  173. // Settings this folder & delegate & Loading datasource
  174. app.directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  175. [[CCNetworking sharedNetworking] settingDelegate:self];
  176. // Color
  177. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
  178. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  179. // Menu e Bar
  180. [self createReMainMenu];
  181. [self createReSelectMenu];
  182. if (_isSelectedMode)
  183. [self setUINavigationBarSelected];
  184. else
  185. [self setUINavigationBarDefault];
  186. // Plus Button
  187. [app plusButtonVisibile:true];
  188. }
  189. // E' arrivato
  190. - (void)viewDidAppear:(BOOL)animated
  191. {
  192. [super viewDidAppear:animated];
  193. // Active Main
  194. app.activeMain = self;
  195. // Test viewDidLoad
  196. if (_isViewDidLoad) {
  197. _isViewDidLoad = NO;
  198. } else {
  199. if (app.activeAccount.length > 0) {
  200. // Load Datasource
  201. [self reloadDatasource:_serverUrl fileID:nil selector:nil];
  202. // Read Folder
  203. [self readFolderWithForced:NO serverUrl:_serverUrl];
  204. }
  205. }
  206. // Title
  207. [self setTitle];
  208. // cancell Progress
  209. [self.navigationController cancelCCProgress];
  210. }
  211. - (void)viewWillDisappear:(BOOL)animated
  212. {
  213. [super viewWillDisappear:animated];
  214. // Close MainMenu & SelectMenu
  215. if (app.reMainMenu.isOpen || app.reSelectMenu.isOpen) {
  216. [app.reMainMenu close];
  217. [app.reSelectMenu close];
  218. }
  219. // Close Menu change user
  220. [CCMenu dismissMenu];
  221. }
  222. - (void)didReceiveMemoryWarning
  223. {
  224. [super didReceiveMemoryWarning];
  225. // Dispose of any resources that can be recreated.
  226. }
  227. - (BOOL)prefersStatusBarHidden
  228. {
  229. return NO;
  230. }
  231. // detect scroll for remove keyboard in search mode
  232. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  233. {
  234. if (_isSearchMode && scrollView == self.tableView) {
  235. [self.searchController.searchBar endEditing:YES];
  236. }
  237. }
  238. #pragma --------------------------------------------------------------------------------------------
  239. #pragma mark ===== Initizlize Mail =====
  240. #pragma --------------------------------------------------------------------------------------------
  241. - (void)initializeMain:(NSNotification *)notification
  242. {
  243. _directoryGroupBy = nil;
  244. _directoryOrder = nil;
  245. _dateReadDataSource = nil;
  246. // test
  247. if (app.activeAccount.length == 0)
  248. return;
  249. if ([app.listMainVC count] == 0 || _isRoot) {
  250. // This is Root
  251. _isRoot = YES;
  252. // Crypto Mode
  253. if ([[CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]] length] == 0) {
  254. app.isCryptoCloudMode = NO;
  255. } else {
  256. app.isCryptoCloudMode = YES;
  257. }
  258. // go Home
  259. [self.navigationController popToRootViewControllerAnimated:NO];
  260. // Remove search mode
  261. [self cancelSearchBar];
  262. _serverUrl = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
  263. _isFolderEncrypted = NO;
  264. app.directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  265. // add list
  266. [app.listMainVC setObject:self forKey:_serverUrl];
  267. // setting Networking
  268. [[CCNetworking sharedNetworking] settingDelegate:self];
  269. [[CCNetworking sharedNetworking] settingAccount];
  270. // populate shared Link & User variable
  271. [CCCoreData populateSharesVariableFromDBActiveAccount:app.activeAccount sharesLink:app.sharesLink sharesUserAndGroup:app.sharesUserAndGroup];
  272. // Load Datasource
  273. [self reloadDatasource:_serverUrl fileID:nil selector:nil];
  274. // Load Folder
  275. [self readFolderWithForced:NO serverUrl:_serverUrl];
  276. // Load photo datasorce
  277. if (app.activePhotosCameraUpload)
  278. [app.activePhotosCameraUpload reloadDatasourceForced];
  279. // remove all of detail
  280. if (app.activeDetail)
  281. [app.activeDetail removeAllView];
  282. // remove all Notification Messages
  283. [app.listOfNotifications removeAllObjects];
  284. // home main
  285. app.homeMain = self;
  286. // Initializations
  287. [app applicationInitialized];
  288. } else {
  289. // reload datasource
  290. [self reloadDatasource:_serverUrl fileID:nil selector:nil];
  291. }
  292. }
  293. #pragma --------------------------------------------------------------------------------------------
  294. #pragma mark ===== AlertView =====
  295. #pragma --------------------------------------------------------------------------------------------
  296. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  297. {
  298. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  299. if (alertView.tag == alertCreateFolder && buttonIndex == 1) [self createFolder:[alertView textFieldAtIndex:0].text folderCameraUpload:NO];
  300. if (alertView.tag == alertCreateFolderCrypto && buttonIndex == 1) [self createFolderEncrypted:[alertView textFieldAtIndex:0].text];
  301. if (alertView.tag == alertRename && buttonIndex == 1) {
  302. if ([_metadata.model isEqualToString:@"note"]) {
  303. [self renameNote:_metadata fileName:[alertView textFieldAtIndex:0].text];
  304. } else {
  305. [self renameFile:_metadata fileName:[alertView textFieldAtIndex:0].text];
  306. }
  307. }
  308. if (alertView.tag == alertOfflineFolder && buttonIndex == 1) {
  309. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  310. NSString *dir = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  311. [[CCSynchronize sharedSynchronize] addOfflineFolder:dir];
  312. [self performSelector:@selector(reloadDatasource) withObject:nil];
  313. }
  314. }
  315. // accept only number char > 0
  316. - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
  317. {
  318. /* Retrieve a text field at an index -
  319. raises NSRangeException when textFieldIndex is out-of-bounds.
  320. The field at index 0 will be the first text field
  321. (the single field or the login field),
  322. The field at index 1 will be the password field. */
  323. /*
  324. 1> Get the Text Field in alertview
  325. 2> Get the text of that Text Field
  326. 3> Verify that text length
  327. 4> return YES or NO Based on the length
  328. */
  329. if (alertView.tag == alertOfflineFolder) return YES;
  330. else return ([[[alertView textFieldAtIndex:0] text] length]>0)?YES:NO;
  331. }
  332. #pragma --------------------------------------------------------------------------------------------
  333. #pragma mark ===== Graphic Window =====
  334. #pragma --------------------------------------------------------------------------------------------
  335. - (void)createRefreshControl
  336. {
  337. _refreshControl = [UIRefreshControl new];
  338. _refreshControl.tintColor = COLOR_REFRESH_CONTROL;
  339. [_refreshControl addTarget:self action:@selector(refreshControlTarget) forControlEvents:UIControlEventValueChanged];
  340. [self setRefreshControl:_refreshControl];
  341. }
  342. - (void)deleteRefreshControl
  343. {
  344. [_refreshControl endRefreshing];
  345. self.refreshControl = nil;
  346. }
  347. - (void)refreshControlTarget
  348. {
  349. [self readFolderWithForced:YES serverUrl:_serverUrl];
  350. // Actuate `Peek` feedback (weak boom)
  351. AudioServicesPlaySystemSound(1519);
  352. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
  353. }
  354. - (void)setTitle
  355. {
  356. // PopGesture in progress [swipe gesture to switch between views]
  357. if (app.controlCenter.isPopGesture)
  358. return;
  359. // Color text self.navigationItem.title
  360. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
  361. if (_isSelectedMode) {
  362. NSUInteger totali = [_sectionDataSource.allRecordsDataSource count];
  363. NSUInteger selezionati = [[self.tableView indexPathsForSelectedRows] count];
  364. self.navigationItem.titleView = nil;
  365. self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)selezionati, (unsigned long)totali];
  366. } else {
  367. // we are in home : LOGO BRAND
  368. if ([_serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl]]) {
  369. self.navigationItem.title = nil;
  370. if ([app.reachability isReachable] == NO) _ImageTitleHomeCryptoCloud = [[UIImageView alloc] initWithImage:[UIImage imageNamed:image_brandNavigationControllerOffline]];
  371. else _ImageTitleHomeCryptoCloud = [[UIImageView alloc] initWithImage:[UIImage imageNamed:image_brandNavigationController]];
  372. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  373. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuChangeUser)];
  374. [singleTap setNumberOfTapsRequired:1];
  375. [_ImageTitleHomeCryptoCloud addGestureRecognizer:singleTap];
  376. self.navigationItem.titleView = _ImageTitleHomeCryptoCloud;
  377. } else {
  378. BOOL isOfflineDirectory = [CCCoreData isOfflineDirectoryServerUrl:_serverUrl activeAccount:app.activeAccount];
  379. if (isOfflineDirectory) {
  380. self.navigationItem.titleView = [CCGraphics navigationBarTitle:_titleMain image:[UIImage imageNamed:image_offlineTitle] frame:self.navigationController.navigationBar.frame];
  381. } else
  382. self.navigationItem.title = _titleMain;
  383. }
  384. }
  385. }
  386. - (void)setTitleBackgroundTableView
  387. {
  388. if ([_sectionDataSource.allRecordsDataSource count] == 0) {
  389. [self setTitleBackgroundTableView:NSLocalizedString(@"_no_file_pull_down_", nil)];
  390. } else {
  391. [self setTitleBackgroundTableView:nil];
  392. }
  393. }
  394. - (void)setTitleBackgroundTableView:(NSString *)title
  395. {
  396. if (title) {
  397. // message if table is empty
  398. UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
  399. if ([app.reachability isReachable] == NO) {
  400. messageLabel.text = NSLocalizedString(@"_comm_erro_pull_down_", nil);
  401. messageLabel.textColor = COLOR_TEXT_NO_CONNECTION;
  402. messageLabel.font = [UIFont systemFontOfSize:14];
  403. } else {
  404. messageLabel.text = NSLocalizedString(title ,nil);
  405. messageLabel.textColor = [UIColor blackColor];
  406. messageLabel.font = [UIFont systemFontOfSize:14];
  407. }
  408. messageLabel.numberOfLines = 0;
  409. messageLabel.textAlignment = NSTextAlignmentCenter;
  410. [messageLabel sizeToFit];
  411. [self.tableView reloadData];
  412. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  413. self.tableView.backgroundView = messageLabel;
  414. } else {
  415. [self.tableView setBackgroundView:nil];
  416. self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  417. }
  418. }
  419. - (void)setUINavigationBarDefault
  420. {
  421. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
  422. UIBarButtonItem *buttonMore, *buttonNotification;
  423. // =
  424. buttonMore = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:image_more] style:UIBarButtonItemStylePlain target:self action:@selector(toggleReMainMenu)];
  425. buttonMore.enabled = true;
  426. // <
  427. self.navigationController.navigationBar.hidden = NO;
  428. // Notification
  429. if ([app.listOfNotifications count] > 0) {
  430. buttonNotification = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:image_notification] style:UIBarButtonItemStylePlain target:self action:@selector(viewNotification)];
  431. buttonNotification.tintColor = COLOR_NAVIGATIONBAR_TEXT;
  432. buttonNotification.enabled = true;
  433. }
  434. if (buttonNotification)
  435. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, buttonNotification, nil];
  436. else
  437. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
  438. self.navigationItem.leftBarButtonItem = nil;
  439. // close Menu
  440. [app.reSelectMenu close];
  441. [app.reMainMenu close];
  442. }
  443. - (void)setUINavigationBarSelected
  444. {
  445. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
  446. UIImage *icon = [UIImage imageNamed:image_more];
  447. UIBarButtonItem *buttonMore = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(toggleReSelectMenu)];
  448. UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelSelect)];
  449. self.navigationItem.leftBarButtonItem = leftButton;
  450. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
  451. }
  452. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  453. {
  454. // close the menus
  455. if (app.reMainMenu.isOpen)
  456. [app.reMainMenu close];
  457. if (app.reSelectMenu.isOpen)
  458. [app.reSelectMenu close];
  459. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  460. }];
  461. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  462. }
  463. - (void)cancelSelect
  464. {
  465. [self tableViewSelect:NO];
  466. }
  467. #pragma --------------------------------------------------------------------------------------------
  468. #pragma mark ===== Document Picker =====
  469. #pragma --------------------------------------------------------------------------------------------
  470. - (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu
  471. {
  472. NSLog(@"Cancelled");
  473. }
  474. - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
  475. {
  476. NSLog(@"Cancelled");
  477. }
  478. - (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
  479. {
  480. documentPicker.delegate = self;
  481. [self presentViewController:documentPicker animated:YES completion:nil];
  482. }
  483. - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
  484. {
  485. if (controller.documentPickerMode == UIDocumentPickerModeImport) {
  486. NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
  487. __block NSError *error;
  488. [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
  489. NSString *fileName = [url lastPathComponent];
  490. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, fileName];
  491. NSData *data = [NSData dataWithContentsOfURL:newURL];
  492. if (data && error == nil) {
  493. if ([data writeToFile:fileNamePath options:NSDataWritingAtomic error:&error]) {
  494. // Upload File
  495. [[CCNetworking sharedNetworking] uploadFile:fileName serverUrl:_serverUrl cryptated:_isPickerCriptate onlyPlist:NO session:k_upload_session taskStatus: k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  496. } else {
  497. [app messageNotification:@"_error_" description:error.description visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  498. }
  499. } else {
  500. [app messageNotification:@"_error_" description:@"_read_file_error_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  501. }
  502. }];
  503. }
  504. }
  505. - (void)openImportDocumentPicker
  506. {
  507. UIDocumentMenuViewController *documentProviderMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];
  508. documentProviderMenu.modalPresentationStyle = UIModalPresentationFormSheet;
  509. documentProviderMenu.popoverPresentationController.sourceView = self.view;
  510. documentProviderMenu.popoverPresentationController.sourceRect = self.view.bounds;
  511. documentProviderMenu.delegate = self;
  512. [self presentViewController:documentProviderMenu animated:YES completion:nil];
  513. }
  514. #pragma --------------------------------------------------------------------------------------------
  515. #pragma mark ===== Assets Picker =====
  516. #pragma --------------------------------------------------------------------------------------------
  517. - (void)openAssetsPickerController
  518. {
  519. CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
  520. checkmark.tintColor = COLOR_BRAND;
  521. [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeTop];
  522. UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:[CTAssetsPickerController class], nil];
  523. [CCAspect aspectNavigationControllerBar:navBar encrypted:NO online:YES hidden:NO];
  524. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
  525. dispatch_async(dispatch_get_main_queue(), ^{
  526. // init picker
  527. CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];
  528. // set delegate
  529. picker.delegate = self;
  530. // to show selection order
  531. //picker.showsSelectionIndex = YES;
  532. // to present picker as a form sheet in iPad
  533. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  534. picker.modalPresentationStyle = UIModalPresentationFormSheet;
  535. // present picker
  536. [self presentViewController:picker animated:YES completion:nil];
  537. });
  538. }];
  539. }
  540. - (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSMutableArray *)assets
  541. {
  542. [picker dismissViewControllerAnimated:YES completion:^{
  543. CreateFormUploadAssets *form = [[CreateFormUploadAssets alloc] init:_titleMain serverUrl:_serverUrl assets:assets cryptated:_isPickerCriptate session:k_upload_session];
  544. form.title = NSLocalizedString(@"_upload_photos_videos_", nil);
  545. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:form];
  546. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  547. //navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  548. [self presentViewController:navigationController animated:YES completion:nil];
  549. }];
  550. }
  551. #pragma --------------------------------------------------------------------------------------------
  552. #pragma mark ===== UIDocumentInteractionControllerDelegate =====
  553. #pragma --------------------------------------------------------------------------------------------
  554. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  555. {
  556. // evitiamo il rimando della eventuale photo e/o video
  557. if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
  558. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  559. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  560. }
  561. }
  562. #pragma --------------------------------------------------------------------------------------------
  563. #pragma mark ===== UnZipFile =====
  564. #pragma --------------------------------------------------------------------------------------------
  565. - (void)unZipFile:(NSString *)fileID
  566. {
  567. [_hudDeterminate visibleHudTitle:NSLocalizedString(@"_unzip_in_progress_", nil) mode:MBProgressHUDModeDeterminate color:nil];
  568. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  569. NSString *fileZip = [NSString stringWithFormat:@"%@/%@", app.directoryUser, fileID];
  570. [SSZipArchive unzipFileAtPath:fileZip toDestination:[CCUtility getDirectoryLocal] overwrite:YES password:nil progressHandler:^(NSString *entry, unz_file_info zipInfo, long entryNumber, long total) {
  571. dispatch_async(dispatch_get_main_queue(), ^{
  572. float progress = (float) entryNumber / (float)total;
  573. [_hudDeterminate progress:progress];
  574. });
  575. } completionHandler:^(NSString *path, BOOL succeeded, NSError *error) {
  576. dispatch_async(dispatch_get_main_queue(), ^{
  577. [_hudDeterminate hideHud];
  578. if (succeeded) [app messageNotification:@"_info_" description:@"_file_unpacked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  579. else [app messageNotification:@"_error_" description:[NSString stringWithFormat:@"Error %ld", (long)error.code] visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  580. });
  581. }];
  582. });
  583. }
  584. #pragma --------------------------------------------------------------------------------------------
  585. #pragma mark ===== Create New (OpenModel) =====
  586. #pragma --------------------------------------------------------------------------------------------
  587. - (void)openModel:(NSString *)tipo isNew:(BOOL)isnew
  588. {
  589. UIViewController *viewController;
  590. NSString *fileName, *uuid, *fileID, *serverUrl;
  591. NSIndexPath * index = [self.tableView indexPathForSelectedRow];
  592. [self.tableView deselectRowAtIndexPath:index animated:NO];
  593. if (isnew) {
  594. fileName = nil;
  595. uuid = [CCUtility getUUID];
  596. fileID = nil;
  597. serverUrl = _serverUrl;
  598. } else {
  599. fileName = _metadata.fileName;
  600. uuid = _metadata.uuid;
  601. fileID = _metadata.fileID;
  602. serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  603. }
  604. if ([tipo isEqualToString:@"cartadicredito"])
  605. viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  606. if ([tipo isEqualToString:@"bancomat"])
  607. viewController = [[CCBancomat alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  608. if ([tipo isEqualToString:@"contocorrente"])
  609. viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  610. if ([tipo isEqualToString:@"accountweb"])
  611. viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  612. if ([tipo isEqualToString:@"patenteguida"])
  613. viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  614. if ([tipo isEqualToString:@"cartaidentita"])
  615. viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  616. if ([tipo isEqualToString:@"passaporto"])
  617. viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  618. if ([tipo isEqualToString:@"note"]) {
  619. viewController = [[CCNote alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  620. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  621. [self presentViewController:navigationController animated:YES completion:nil];
  622. } else {
  623. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  624. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  625. [self presentViewController:navigationController animated:YES completion:nil];
  626. }
  627. }
  628. // New folder or new photo or video
  629. - (void)returnCreate:(NSInteger)type
  630. {
  631. switch (type) {
  632. /* PLAIN */
  633. case k_returnCreateFolderPlain: {
  634. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_create_folder_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  635. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  636. alertView.tag = alertCreateFolder;
  637. [alertView show];
  638. }
  639. break;
  640. case k_returnCreateFotoVideoPlain: {
  641. _isPickerCriptate = false;
  642. [self openAssetsPickerController];
  643. }
  644. break;
  645. case k_returnCreateFilePlain: {
  646. _isPickerCriptate = false;
  647. [self openImportDocumentPicker];
  648. }
  649. break;
  650. /* ENCRYPTED */
  651. case k_returnCreateFolderEncrypted: {
  652. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_create_folder_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  653. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  654. alertView.tag = alertCreateFolderCrypto;
  655. [alertView show];
  656. }
  657. break;
  658. case k_returnCreateFotoVideoEncrypted: {
  659. _isPickerCriptate = true;
  660. [self openAssetsPickerController];
  661. }
  662. break;
  663. case k_returnCreateFileEncrypted: {
  664. _isPickerCriptate = true;
  665. [self openImportDocumentPicker];
  666. }
  667. break;
  668. /* UTILITY */
  669. case k_returnNote:
  670. [self openModel:@"note" isNew:true];
  671. break;
  672. case k_returnAccountWeb:
  673. [self openModel:@"accountweb" isNew:true];
  674. break;
  675. /* BANK */
  676. case k_returnCartaDiCredito:
  677. [self openModel:@"cartadicredito" isNew:true];
  678. break;
  679. case k_returnBancomat:
  680. [self openModel:@"bancomat" isNew:true];
  681. break;
  682. case k_returnContoCorrente:
  683. [self openModel:@"contocorrente" isNew:true];
  684. break;
  685. /* DOCUMENT */
  686. case k_returnPatenteGuida:
  687. [self openModel:@"patenteguida" isNew:true];
  688. break;
  689. case k_returnCartaIdentita:
  690. [self openModel:@"cartaidentita" isNew:true];
  691. break;
  692. case k_returnPassaporto:
  693. [self openModel:@"passaporto" isNew:true];
  694. break;
  695. }
  696. }
  697. #pragma --------------------------------------------------------------------------------------------
  698. #pragma mark ===== Save selected File =====
  699. #pragma --------------------------------------------------------------------------------------------
  700. -(void)saveSelectedFilesSelector:(NSString *)path didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
  701. {
  702. if (error)
  703. [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  704. else
  705. [app messageNotification:@"_save_selected_files_" description:@"_file_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  706. }
  707. - (void)saveSelectedFiles
  708. {
  709. NSLog(@"[LOG] Start download selected files ...");
  710. [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil];
  711. NSArray *metadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  712. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  713. for (CCMetadata *metadata in metadatas) {
  714. if (metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_file] && ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])) {
  715. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  716. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorSave selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
  717. }
  718. }
  719. [_hud hideHud];
  720. });
  721. [self tableViewSelect:NO];
  722. }
  723. #pragma --------------------------------------------------------------------------------------------
  724. #pragma mark ===== Change Password =====
  725. #pragma --------------------------------------------------------------------------------------------
  726. - (void) loginSuccess:(NSInteger)loginType
  727. {
  728. [self readFolderWithForced:YES serverUrl:_serverUrl];
  729. }
  730. - (void)changePasswordAccount
  731. {
  732. CCLogin *loginVC = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"CCLoginNextcloud"];
  733. loginVC.delegate = self;
  734. loginVC.loginType = loginModifyPasswordUser;
  735. [self presentViewController:loginVC animated:YES completion:nil];
  736. }
  737. #pragma mark -
  738. #pragma --------------------------------------------------------------------------------------------
  739. #pragma mark ===== Peek & Pop =====
  740. #pragma --------------------------------------------------------------------------------------------
  741. - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
  742. {
  743. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  744. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  745. if (metadata.thumbnailExists && !metadata.cryptated) {
  746. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  747. if (cell) {
  748. previewingContext.sourceRect = cell.frame;
  749. CCPeekPop *vc = [[UIStoryboard storyboardWithName:@"CCPeekPop" bundle:nil] instantiateViewControllerWithIdentifier:@"PeekPopImagePreview"];
  750. vc.delegate = self;
  751. vc.metadata = metadata;
  752. return vc;
  753. }
  754. }
  755. return nil;
  756. }
  757. - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
  758. {
  759. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:previewingContext.sourceRect.origin];
  760. [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
  761. }
  762. #pragma mark -
  763. #pragma --------------------------------------------------------------------------------------------
  764. #pragma mark ==== Activity ====
  765. #pragma --------------------------------------------------------------------------------------------
  766. - (void)getActivityServerSuccess:(NSArray *)listOfActivity
  767. {
  768. for (OCActivity *activity in listOfActivity) {
  769. [CCCoreData addActivity:activity account:app.activeAccount];
  770. }
  771. }
  772. - (void)getActivityServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  773. {
  774. }
  775. #pragma --------------------------------------------------------------------------------------------
  776. #pragma mark ==== Notification ====
  777. #pragma --------------------------------------------------------------------------------------------
  778. - (void)getNotificationServerSuccess:(NSArray *)listOfNotifications
  779. {
  780. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  781. NSString *old = @"", *new = @"";
  782. // Order by date
  783. NSArray *sortedListOfNotifications = [listOfNotifications sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
  784. OCNotifications *notification1 = obj1, *notification2 = obj2;
  785. return [notification2.date compare: notification1.date];
  786. }];
  787. // verify if listOfNotifications is changed
  788. for (OCNotifications *notification in listOfNotifications)
  789. new = [new stringByAppendingString:@(notification.idNotification).stringValue];
  790. for (OCNotifications *notification in appDelegate.listOfNotifications)
  791. old = [old stringByAppendingString:@(notification.idNotification).stringValue];
  792. if (![new isEqualToString:old]) {
  793. appDelegate.listOfNotifications = [[NSMutableArray alloc] initWithArray:sortedListOfNotifications];
  794. // reload Notification view
  795. [[NSNotificationCenter defaultCenter] postNotificationName:@"notificationReloadData" object:nil];
  796. }
  797. // Update NavigationBar
  798. if (!_isSelectedMode)
  799. [self setUINavigationBarDefault];
  800. }
  801. - (void)getNotificationServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  802. {
  803. // Update NavigationBar
  804. if (!_isSelectedMode)
  805. [self setUINavigationBarDefault];
  806. }
  807. - (void)viewNotification
  808. {
  809. if ([app.listOfNotifications count] > 0) {
  810. CCNotification *notificationVC = [[UIStoryboard storyboardWithName:@"CCNotification" bundle:nil] instantiateViewControllerWithIdentifier:@"CCNotification"];
  811. [notificationVC setModalPresentationStyle:UIModalPresentationFormSheet];
  812. [self presentViewController:notificationVC animated:YES completion:nil];
  813. }
  814. }
  815. #pragma --------------------------------------------------------------------------------------------
  816. #pragma mark ==== Request Server ====
  817. #pragma --------------------------------------------------------------------------------------------
  818. - (void)getUserProfileSuccess:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile
  819. {
  820. [CCCoreData setUserProfileActiveAccount:metadataNet.account userProfile:userProfile];
  821. NSString *address = [NSString stringWithFormat:@"%@/index.php/avatar/%@/128", app.activeUrl, app.activeUser];
  822. UIImage *avatar = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];
  823. if (avatar)
  824. [UIImagePNGRepresentation(avatar) writeToFile:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser] atomically:YES];
  825. else
  826. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser] error:nil];
  827. }
  828. - (void)getCapabilitiesOfServerSuccess:(OCCapabilities *)capabilities
  829. {
  830. app.capabilities = capabilities;
  831. [CCCoreData setServerVersionActiveAccount:app.activeAccount versionMajor:capabilities.versionMajor versionMinor:capabilities.versionMinor versionMicro:capabilities.versionMicro];
  832. // Search placeholder
  833. if (capabilities.versionMajor >= 12) {
  834. if (_isRoot)
  835. self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_all_folders_",nil);
  836. else
  837. self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_sub_folder_",nil);
  838. } else {
  839. self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_this_folder_",nil);
  840. }
  841. }
  842. - (void)getFeaturesSupportedByServerSuccess:(BOOL)hasCapabilitiesSupport hasForbiddenCharactersSupport:(BOOL)hasForbiddenCharactersSupport hasShareSupport:(BOOL)hasShareSupport hasShareeSupport:(BOOL)hasShareeSupport
  843. {
  844. app.hasServerCapabilitiesSupport = hasCapabilitiesSupport;
  845. app.hasServerForbiddenCharactersSupport = hasForbiddenCharactersSupport;
  846. app.hasServerShareSupport = hasShareSupport;
  847. app.hasServerShareeSupport = hasShareeSupport;
  848. if (hasShareSupport || hasShareeSupport)
  849. [self requestSharedByServer];
  850. }
  851. - (void)getInfoServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  852. {
  853. if (errorCode == 401)
  854. [self changePasswordAccount];
  855. }
  856. - (void)requestServerInformation
  857. {
  858. // test
  859. if (app.activeAccount.length == 0)
  860. return;
  861. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  862. [app.sharesID removeAllObjects];
  863. app.hasServerForbiddenCharactersSupport = YES;
  864. app.hasServerShareSupport = YES;
  865. metadataNet.action = actionGetFeaturesSuppServer;
  866. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  867. metadataNet.action = actionGetCapabilities;
  868. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  869. metadataNet.action = actionGetNotificationServer;
  870. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  871. metadataNet.action = actionGetUserProfile;
  872. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  873. NSInteger lastID = [CCCoreData getLastIDActivityActiveAccount:app.activeAccount];
  874. metadataNet.action = actionGetActivityServer;
  875. metadataNet.options = [@(lastID) stringValue];;
  876. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  877. }
  878. #pragma --------------------------------------------------------------------------------------------
  879. #pragma mark ==== Download Thumbnail Delegate ====
  880. #pragma --------------------------------------------------------------------------------------------
  881. - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
  882. {
  883. __block CCCellMain *cell;
  884. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
  885. if (indexPath && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataNet.fileID]]) {
  886. cell = [self.tableView cellForRowAtIndexPath:indexPath];
  887. cell.fileImageView.image = [app.icoImagesCache objectForKey:metadataNet.fileID];
  888. if (cell.fileImageView.image == nil) {
  889. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  890. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataNet.fileID]];
  891. [app.icoImagesCache setObject:image forKey:metadataNet.fileID];
  892. });
  893. }
  894. }
  895. }
  896. #pragma --------------------------------------------------------------------------------------------
  897. #pragma mark ==== Download ====
  898. #pragma --------------------------------------------------------------------------------------------
  899. - (void)downloadFileFailure:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  900. {
  901. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  902. // File do not exists on server, remove in local
  903. if (errorCode == kOCErrorServerPathNotFound || errorCode == kCFURLErrorBadServerResponse) {
  904. [CCCoreData deleteFile:metadata serverUrl:serverUrl directoryUser:app.directoryUser activeAccount:app.activeAccount];
  905. }
  906. if ([selector isEqualToString:selectorLoadViewImage]) {
  907. dispatch_async(dispatch_get_main_queue(), ^{
  908. // Updating Detail
  909. if (app.activeDetail)
  910. [app.activeDetail downloadPhotoBrowserFailure:errorCode];
  911. // Updating Photos
  912. if (app.activePhotosCameraUpload)
  913. [app.activePhotosCameraUpload downloadFileFailure:errorCode];
  914. });
  915. } else {
  916. if (errorCode != kCFURLErrorCancelled)
  917. [app messageNotification:@"_download_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  918. }
  919. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  920. }
  921. - (void)downloadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  922. {
  923. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  924. if (metadata == nil) return;
  925. // reload
  926. if ([selector isEqualToString:selectorReload]) {
  927. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  928. }
  929. // Synchronized
  930. if ([selector isEqualToString:selectorDownloadSynchronize]) {
  931. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  932. }
  933. // add Favorite
  934. if ([selector isEqualToString:selectorAddFavorite]) {
  935. [[CCActions sharedInstance] settingFavorite:metadata favorite:YES delegate:self];
  936. }
  937. // add Offline
  938. if ([selector isEqualToString:selectorAddOffline]) {
  939. [CCCoreData setOfflineLocalFileID:metadata.fileID offline:YES activeAccount:app.activeAccount];
  940. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  941. }
  942. // encrypted file
  943. if ([selector isEqualToString:selectorEncryptFile]) {
  944. [self encryptedFile:metadata];
  945. }
  946. // decrypted file
  947. if ([selector isEqualToString:selectorDecryptFile]) {
  948. [self decryptedFile:metadata];
  949. }
  950. // open View File
  951. if ([selector isEqualToString:selectorLoadFileView] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
  952. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  953. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_compress]) {
  954. [self performSelector:@selector(unZipFile:) withObject:metadata.fileID];
  955. } else if ([metadata.typeFile isEqualToString: k_metadataTypeFile_unknown]) {
  956. selector = selectorOpenIn;
  957. } else {
  958. _metadataSegue = metadata;
  959. _metadataSegue.sessionSelector = selector;
  960. if ([self shouldPerformSegue:serverUrl])
  961. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  962. }
  963. }
  964. // addLocal
  965. if ([selector isEqualToString:selectorAddLocal]) {
  966. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileNamePrint]];
  967. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  968. [CCGraphics saveIcoWithFileID:metadata.fileNamePrint image:image writeToFile:nil copy:YES move:NO fromPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/.%@.ico", [CCUtility getDirectoryLocal], metadata.fileNamePrint]];
  969. [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  970. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  971. }
  972. // Open with...
  973. if ([selector isEqualToString:selectorOpenIn] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
  974. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  975. [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  976. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  977. NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint]];
  978. _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  979. _docController.delegate = self;
  980. [_docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  981. }
  982. // Save to Photo Album
  983. if ([selector isEqualToString:selectorSave] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
  984. NSString *file = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  985. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  986. // evitiamo il rimando photo
  987. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  988. UIImage *image = [UIImage imageWithContentsOfFile:file];
  989. if (image)
  990. UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  991. else
  992. [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  993. }
  994. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  995. // we avoid the cross-reference video
  996. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  997. [[NSFileManager defaultManager] linkItemAtPath:file toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  998. if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint])) {
  999. UISaveVideoAtPathToSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint], self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  1000. } else {
  1001. [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  1002. }
  1003. }
  1004. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  1005. }
  1006. // Copy File
  1007. if ([selector isEqualToString:selectorLoadCopy]) {
  1008. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  1009. [self copyFileToPasteboard:metadata];
  1010. }
  1011. // download and view a template
  1012. if ([selector isEqualToString:selectorLoadModelView]) {
  1013. [CCCoreData downloadFilePlist:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl directoryUser:app.directoryUser];
  1014. [self openModel:metadata.model isNew:false];
  1015. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  1016. }
  1017. //download file plist
  1018. if ([selector isEqualToString:selectorLoadPlist]) {
  1019. [CCCoreData downloadFilePlist:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl directoryUser:app.directoryUser];
  1020. long countSelectorLoadPlist = 0;
  1021. for (NSOperation *operation in [app.netQueue operations]) {
  1022. if ([((OCnetworking *)operation).metadataNet.selector isEqualToString:selectorLoadPlist])
  1023. countSelectorLoadPlist++;
  1024. }
  1025. if ((countSelectorLoadPlist == 0 || countSelectorLoadPlist % k_maxConcurrentOperation == 0) && [metadata.directoryID isEqualToString:[CCCoreData getDirectoryIDFromServerUrl:_serverUrl activeAccount:app.activeAccount]]) {
  1026. dispatch_async(dispatch_get_main_queue(), ^{
  1027. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  1028. });
  1029. }
  1030. }
  1031. //selectorLoadViewImage
  1032. if ([selector isEqualToString:selectorLoadViewImage]) {
  1033. dispatch_async(dispatch_get_main_queue(), ^{
  1034. // Detail
  1035. if (app.activeDetail)
  1036. [app.activeDetail downloadPhotoBrowserSuccess:metadata selector:selector];
  1037. // Photos
  1038. if (app.activePhotosCameraUpload)
  1039. [app.activePhotosCameraUpload downloadFileSuccess:metadata];
  1040. });
  1041. [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
  1042. }
  1043. // if exists postselector call self with selectorPost
  1044. if ([selectorPost length] > 0)
  1045. [self downloadFileSuccess:fileID serverUrl:serverUrl selector:selectorPost selectorPost:nil];
  1046. }
  1047. - (void)downloadSelectedFiles
  1048. {
  1049. NSLog(@"[LOG] Start download selected files ...");
  1050. [_hud visibleHudTitle:NSLocalizedString(@"_downloading_progress_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1051. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1052. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  1053. for (CCMetadata *metadata in selectedMetadatas) {
  1054. if (metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_file]) {
  1055. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  1056. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorReload selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
  1057. }
  1058. }
  1059. [_hud hideHud];
  1060. });
  1061. [self tableViewSelect:NO];
  1062. }
  1063. - (void)downloadPlist:(NSString *)directoryID serverUrl:(NSString *)serverUrl
  1064. {
  1065. NSArray *records = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND ((session == NULL) OR (session == ''))", app.activeAccount, directoryID] context:nil];
  1066. for (TableMetadata *recordMetadata in records) {
  1067. if ([CCUtility isCryptoPlistString:recordMetadata.fileName] && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, recordMetadata.fileName]] == NO && [recordMetadata.session length] == 0) {
  1068. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1069. metadataNet.action = actionDownloadFile;
  1070. metadataNet.metadata = [CCCoreData insertEntityInMetadata:recordMetadata];
  1071. metadataNet.downloadData = NO;
  1072. metadataNet.downloadPlist = YES;
  1073. metadataNet.selector = selectorLoadPlist;
  1074. metadataNet.serverUrl = serverUrl;
  1075. metadataNet.session = k_download_session_foreground;
  1076. metadataNet.taskStatus = k_taskStatusResume;
  1077. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1078. }
  1079. }
  1080. }
  1081. #pragma --------------------------------------------------------------------------------------------
  1082. #pragma mark ===== Upload new Photos/Videos =====
  1083. #pragma --------------------------------------------------------------------------------------------
  1084. - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  1085. {
  1086. // Automatic upload
  1087. if([selector isEqualToString:selectorUploadAutomatic] || [selector isEqualToString:selectorUploadAutomaticAll])
  1088. [app loadTableAutomaticUploadForSelector:selector];
  1089. // Read File test do not exists
  1090. if (errorCode == k_CCErrorFileUploadNotFound && fileID) {
  1091. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  1092. // reUpload
  1093. if (metadata)
  1094. [[CCNetworking sharedNetworking] uploadFileMetadata:metadata taskStatus:k_taskStatusResume];
  1095. }
  1096. // Print error
  1097. else if (errorCode != kCFURLErrorCancelled && errorCode != 403) {
  1098. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  1099. }
  1100. [self reloadDatasource:serverUrl fileID:nil selector:selector];
  1101. }
  1102. - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  1103. {
  1104. // Automatic upload
  1105. if([selector isEqualToString:selectorUploadAutomatic] || [selector isEqualToString:selectorUploadAutomaticAll])
  1106. [app loadTableAutomaticUploadForSelector:selector];
  1107. if ([selectorPost isEqualToString:selectorReadFolderForced] ) {
  1108. [self readFolderWithForced:YES serverUrl:serverUrl];
  1109. } else {
  1110. [self reloadDatasource:serverUrl fileID:nil selector:selector];
  1111. }
  1112. }
  1113. //
  1114. // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
  1115. //
  1116. - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  1117. {
  1118. [_hud visibleHudTitle:nil mode:MBProgressHUDModeIndeterminate color:nil];
  1119. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
  1120. [self performSelectorOnMainThread:@selector(uploadFileAssetBridge:) withObject:@[assets, serverUrl, [NSNumber numberWithBool:cryptated], [NSNumber numberWithBool:useSubFolder], session] waitUntilDone:NO];
  1121. });
  1122. }
  1123. - (void)uploadFileAssetBridge:(NSArray *)arguments
  1124. {
  1125. NSArray *assets = [arguments objectAtIndex:0];
  1126. NSString *serverUrl = [arguments objectAtIndex:1];
  1127. BOOL cryptated = [[arguments objectAtIndex:2] boolValue];
  1128. BOOL useSubFolder = [[arguments objectAtIndex:3] boolValue];
  1129. NSString * session = [arguments objectAtIndex:4];
  1130. // remove title (graphics)
  1131. [self setTitleBackgroundTableView:nil];
  1132. NSString *folderPhotos = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  1133. NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
  1134. // Create if request the folder for Photos
  1135. if ((useSubFolder || [serverUrl isEqualToString:folderPhotos]) && [_serverUrl isEqualToString:serverUrl] == NO){
  1136. if(![app.activePhotosCameraUpload automaticCreateFolder:folderPhotos]) {
  1137. [_hud hideHud];
  1138. [app messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  1139. return;
  1140. }
  1141. }
  1142. // Create if request the subfolders
  1143. if (useSubFolder) {
  1144. for (NSString *dateSubFolder in [CCUtility createNameSubFolder:assets]) {
  1145. if(![app.activePhotosCameraUpload automaticCreateFolder:[NSString stringWithFormat:@"%@/%@", folderPhotos, dateSubFolder]]) {
  1146. [_hud hideHud];
  1147. [app messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  1148. return;
  1149. }
  1150. }
  1151. }
  1152. NSLog(@"[LOG] Asset N. %lu", (unsigned long)[assets count]);
  1153. for (PHAsset *asset in assets) {
  1154. NSString *fileName = [CCUtility createFileNameFromAsset:asset key: k_keyFileNameMask];
  1155. NSDate *assetDate = asset.creationDate;
  1156. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  1157. // Create serverUrl if use sub folder
  1158. if (useSubFolder) {
  1159. [formatter setDateFormat:@"yyyy"];
  1160. NSString *yearString = [formatter stringFromDate:assetDate];
  1161. [formatter setDateFormat:@"MM"];
  1162. NSString *monthString = [formatter stringFromDate:assetDate];
  1163. serverUrl = [NSString stringWithFormat:@"%@/%@/%@", folderPhotos, yearString, monthString];
  1164. }
  1165. // Check if is in upload
  1166. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND (fileName == %@) AND (session != NULL) AND (session != '')", app.activeAccount, directoryID, fileName];
  1167. NSArray *isRecordInSessions = [CCCoreData getTableMetadataWithPredicate:predicate context:nil];
  1168. if ([isRecordInSessions count] > 0) {
  1169. // next upload
  1170. continue;
  1171. } else {
  1172. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1173. metadataNet.action = actionReadFile;
  1174. metadataNet.identifier = asset.localIdentifier;
  1175. metadataNet.cryptated = cryptated;
  1176. metadataNet.fileName = fileName;
  1177. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1178. metadataNet.session = session;
  1179. metadataNet.selector = selectorReadFileUploadFile;
  1180. metadataNet.serverUrl = serverUrl;
  1181. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1182. }
  1183. }
  1184. [_hud hideHud];
  1185. }
  1186. #pragma --------------------------------------------------------------------------------------------
  1187. #pragma mark ==== Read File ====
  1188. #pragma --------------------------------------------------------------------------------------------
  1189. - (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1190. {
  1191. // UploadFile
  1192. if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
  1193. // File not exists
  1194. if (errorCode == 404) {
  1195. metadataNet.action = actionUploadAsset;
  1196. metadataNet.errorCode = 0;
  1197. metadataNet.selector = selectorUploadFile;
  1198. metadataNet.selectorPost = nil;
  1199. metadataNet.taskStatus = k_taskStatusResume;
  1200. if ([metadataNet.session containsString:@"wwan"])
  1201. [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
  1202. else
  1203. [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
  1204. } else {
  1205. // error ho many retry befor notification and go to on next asses
  1206. if (metadataNet.errorRetry < 3) {
  1207. // Retry read file
  1208. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1209. } else {
  1210. // STOP check file, view message error
  1211. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  1212. }
  1213. }
  1214. }
  1215. }
  1216. - (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(CCMetadata *)metadata
  1217. {
  1218. // UploadFile
  1219. if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
  1220. metadataNet.action = actionUploadAsset;
  1221. metadataNet.errorCode = 403; // File exists 403 Forbidden
  1222. metadataNet.selector = selectorUploadFile;
  1223. metadataNet.selectorPost = nil;
  1224. metadataNet.taskStatus = k_taskStatusResume;
  1225. if ([metadataNet.session containsString:@"wwan"])
  1226. [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
  1227. else
  1228. [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
  1229. }
  1230. }
  1231. #pragma --------------------------------------------------------------------------------------------
  1232. #pragma mark ==== Read Folder ====
  1233. #pragma --------------------------------------------------------------------------------------------
  1234. - (void)readFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1235. {
  1236. // verify active user
  1237. TableAccount *record = [CCCoreData getActiveAccount];
  1238. [_hud hideHud];
  1239. [_refreshControl endRefreshing];
  1240. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  1241. if (message && [record.account isEqualToString:metadataNet.account])
  1242. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  1243. [self reloadDatasource:metadataNet.serverUrl fileID:nil selector:metadataNet.selector];
  1244. if (errorCode == 401)
  1245. [self changePasswordAccount];
  1246. }
  1247. - (void)readFolderSuccess:(CCMetadataNet *)metadataNet permissions:(NSString *)permissions metadatas:(NSArray *)metadatas
  1248. {
  1249. // verify active user
  1250. TableAccount *record = [CCCoreData getActiveAccount];
  1251. if (![record.account isEqualToString:metadataNet.account])
  1252. return;
  1253. // save father e update permission
  1254. if(!_isSearchMode)
  1255. _fatherPermission = permissions;
  1256. NSArray *recordsInSessions;
  1257. if (_isSearchMode) {
  1258. recordsInSessions = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (session != NULL) AND (session != '')", app.activeAccount] context:nil];
  1259. } else {
  1260. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND ((session == NULL) OR (session == ''))", app.activeAccount, metadataNet.directoryID]];
  1261. recordsInSessions = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND (session != NULL) AND (session != '')", app.activeAccount, metadataNet.directoryID] context:nil];
  1262. [CCCoreData setDateReadDirectoryID:metadataNet.directoryID activeAccount:app.activeAccount];
  1263. }
  1264. for (CCMetadata *metadata in metadatas) {
  1265. // Delete Record only in Search Mode
  1266. if (_isSearchMode)
  1267. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND (fileID = %@) AND ((session == NULL) OR (session == ''))", app.activeAccount, metadata.directoryID, metadata.fileID]];
  1268. // type of file
  1269. NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
  1270. // if crypto do not insert
  1271. if (typeFilename == k_metadataTypeFilenameCrypto) continue;
  1272. // verify if the record encrypted has plist + crypto
  1273. if (typeFilename == k_metadataTypeFilenamePlist && metadata.directory == NO) {
  1274. BOOL isCryptoComplete = NO;
  1275. NSString *fileNameCrypto = [CCUtility trasformedFileNamePlistInCrypto:metadata.fileName];
  1276. for (CCMetadata *completeMetadata in metadatas) {
  1277. if (completeMetadata.cryptated == NO) continue;
  1278. else if ([completeMetadata.fileName isEqualToString:fileNameCrypto]) {
  1279. isCryptoComplete = YES;
  1280. break;
  1281. }
  1282. }
  1283. if (isCryptoComplete == NO) continue;
  1284. }
  1285. // verify if the record is in download/upload progress
  1286. if (metadata.directory == NO && [recordsInSessions count] > 0) {
  1287. CCMetadata *metadataDB = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND (fileName == %@)", app.activeAccount, metadataNet.directoryID, metadata.fileName] context:nil];
  1288. // is in Upload
  1289. if (metadataDB.session && [metadataDB.session containsString:@"upload"]) {
  1290. NSString *sessionID = metadataDB.sessionID;
  1291. // rename SessionID -> fileID
  1292. [CCUtility moveFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, sessionID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]];
  1293. metadataDB.session = @"";
  1294. metadataDB.date = metadata.date;
  1295. metadataDB.fileID = metadata.fileID;
  1296. metadataDB.rev = metadata.fileID;
  1297. metadataDB.sessionError = @"";
  1298. metadataDB.sessionID = @"";
  1299. metadataDB.sessionTaskIdentifier = k_taskIdentifierDone;
  1300. metadataDB.sessionTaskIdentifierPlist = k_taskIdentifierDone;
  1301. [CCCoreData updateMetadata:metadataDB predicate:[NSPredicate predicateWithFormat:@"(sessionID == %@) AND (account == %@)", sessionID, app.activeAccount] activeAccount:app.activeAccount activeUrl:app.activeUrl context:nil];
  1302. [CCCoreData addLocalFile:metadataDB activeAccount:app.activeAccount];
  1303. [CCGraphics createNewImageFrom:metadata.fileID directoryUser:app.directoryUser fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  1304. continue;
  1305. }
  1306. // download in progress
  1307. if (metadataDB.session && [metadataDB.session containsString:@"download"])
  1308. continue;
  1309. }
  1310. // end test, insert in CoreData
  1311. [CCCoreData addMetadata:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl context:nil];
  1312. }
  1313. // read plist
  1314. [self downloadPlist:metadataNet.directoryID serverUrl:metadataNet.serverUrl];
  1315. // File is changed ??
  1316. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  1317. if (!_isSearchMode)
  1318. [[CCSynchronize sharedSynchronize] verifyChangeMedatas:metadatas serverUrl:metadataNet.serverUrl account:app.activeAccount synchronize:NO];
  1319. });
  1320. // Search Mode
  1321. if (_isSearchMode)
  1322. [self reloadDatasource:metadataNet.serverUrl fileID:nil selector:metadataNet.selector];
  1323. // this is the same directory
  1324. if ([metadataNet.serverUrl isEqualToString:_serverUrl] && !_isSearchMode) {
  1325. // reload
  1326. [self reloadDatasource:metadataNet.serverUrl fileID:nil selector:metadataNet.selector];
  1327. // stoprefresh
  1328. [_refreshControl endRefreshing];
  1329. // Enable change user
  1330. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  1331. [_hud hideHud];
  1332. }
  1333. }
  1334. - (void)readFolderWithForced:(BOOL)forced serverUrl:(NSString *)serverUrl
  1335. {
  1336. [self setTitleBackgroundTableView:nil];
  1337. // init control
  1338. if (!serverUrl || !app.activeAccount)
  1339. return;
  1340. // Search Mode
  1341. if (_isSearchMode) {
  1342. if (forced) {
  1343. [CCCoreData clearDateReadDirectory:serverUrl activeAccount:app.activeAccount];
  1344. _searchFileName = @""; // forced reload searchg
  1345. }
  1346. [self updateSearchResultsForSearchController:self.searchController];
  1347. return;
  1348. }
  1349. NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
  1350. if ([CCCoreData isDirectoryOutOfDate:k_dayForceReadFolder directoryID:directoryID activeAccount:app.activeAccount] || forced) {
  1351. if (_refreshControl.isRefreshing == NO)
  1352. [_hud visibleIndeterminateHud];
  1353. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1354. metadataNet.action = actionReadFolder;
  1355. metadataNet.date = [NSDate date];
  1356. metadataNet.directoryID = directoryID;
  1357. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1358. metadataNet.selector = selectorReadFolder;
  1359. metadataNet.serverUrl = serverUrl;
  1360. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1361. } else {
  1362. if ([_sectionDataSource.allRecordsDataSource count] == 0) [self setTitleBackgroundTableView:NSLocalizedString(@"_no_file_pull_down_",nil)];
  1363. else [self setTitleBackgroundTableView:nil];
  1364. }
  1365. }
  1366. #pragma mark -
  1367. #pragma --------------------------------------------------------------------------------------------
  1368. #pragma mark ===== Search =====
  1369. #pragma --------------------------------------------------------------------------------------------
  1370. -(void)updateSearchResultsForSearchController:(UISearchController *)searchController
  1371. {
  1372. _isSearchMode = YES;
  1373. [self deleteRefreshControl];
  1374. NSString *fileName = [CCUtility removeForbiddenCharacters:searchController.searchBar.text hasServerForbiddenCharactersSupport:app.hasServerForbiddenCharactersSupport];
  1375. if (fileName.length >= k_minCharsSearch && [fileName isEqualToString:_searchFileName] == NO) {
  1376. _searchFileName = fileName;
  1377. NSString *depth = @"1";
  1378. if ([[CCUtility getHomeServerUrlActiveUrl:app.activeUrl] isEqualToString:_serverUrl])
  1379. depth = @"infinity";
  1380. [[CCActions sharedInstance] search:_serverUrl fileName:_searchFileName depth:depth delegate:self];
  1381. }
  1382. if (_searchResultMetadatas.count == 0 && fileName.length == 0) {
  1383. [self reloadDatasource];
  1384. }
  1385. }
  1386. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  1387. {
  1388. [self cancelSearchBar];
  1389. [self readFolderWithForced:NO serverUrl:_serverUrl];
  1390. }
  1391. - (void)searchFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1392. {
  1393. _searchFileName = @"";
  1394. if (message)
  1395. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  1396. }
  1397. - (void)searchSuccess:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas
  1398. {
  1399. _searchResultMetadatas = [[NSArray alloc] initWithArray:metadatas];
  1400. [self readFolderSuccess:metadataNet permissions:nil metadatas:metadatas];
  1401. }
  1402. - (void)cancelSearchBar
  1403. {
  1404. if (self.searchController.active) {
  1405. [self.searchController setActive:NO];
  1406. [self createRefreshControl];
  1407. _isSearchMode = NO;
  1408. _searchFileName = @"";
  1409. _dateReadDataSource = nil;
  1410. _searchResultMetadatas = [NSArray new];
  1411. [self reloadDatasource];
  1412. }
  1413. }
  1414. #pragma mark -
  1415. #pragma --------------------------------------------------------------------------------------------
  1416. #pragma mark ===== Delete File or Folder =====
  1417. #pragma --------------------------------------------------------------------------------------------
  1418. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1419. {
  1420. [self deleteFileOrFolderSuccess:metadataNet];
  1421. }
  1422. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  1423. {
  1424. [_queueSelector removeObject:metadataNet.selector];
  1425. if ([_queueSelector count] == 0) {
  1426. [_hud hideHud];
  1427. if (_isSearchMode)
  1428. [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
  1429. else
  1430. [self reloadDatasource:metadataNet.serverUrl fileID:metadataNet.metadata.fileID selector:metadataNet.selector];
  1431. // next
  1432. if ([_selectedMetadatas count] > 0) {
  1433. [_selectedMetadatas removeObjectAtIndex:0];
  1434. if ([_selectedMetadatas count] > 0)
  1435. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1436. }
  1437. }
  1438. }
  1439. - (void)deleteFileOrFolder:(CCMetadata *)metadata numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
  1440. {
  1441. if (metadata.cryptated) {
  1442. [_queueSelector addObject:selectorDeleteCrypto];
  1443. [_queueSelector addObject:selectorDeletePlist];
  1444. } else {
  1445. [_queueSelector addObject:selectorDelete];
  1446. }
  1447. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  1448. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_delete_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1449. }
  1450. - (void)deleteSelectionFile
  1451. {
  1452. [_selectedMetadatas removeAllObjects];
  1453. [_queueSelector removeAllObjects];
  1454. _selectedMetadatas = [[NSMutableArray alloc] initWithArray: [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]]];
  1455. _numSelectedMetadatas = [_selectedMetadatas count];
  1456. if ([_selectedMetadatas count] > 0)
  1457. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1458. [self tableViewSelect:NO];
  1459. }
  1460. - (void)deleteFile
  1461. {
  1462. [_selectedMetadatas removeAllObjects];
  1463. [_queueSelector removeAllObjects];
  1464. _numSelectedMetadatas = 1;
  1465. [_selectedMetadatas addObject:_metadata];
  1466. if ([_selectedMetadatas count] > 0)
  1467. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1468. [self tableViewSelect:NO];
  1469. }
  1470. #pragma --------------------------------------------------------------------------------------------
  1471. #pragma mark ===== Rename / Move =====
  1472. #pragma --------------------------------------------------------------------------------------------
  1473. - (void)renameSuccess:(CCMetadataNet *)metadataNet
  1474. {
  1475. [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
  1476. }
  1477. - (void)renameFile:(CCMetadata *)metadata fileName:(NSString *)fileName
  1478. {
  1479. [[CCActions sharedInstance] renameFileOrFolder:metadata fileName:fileName delegate:self];
  1480. }
  1481. - (void)renameNote:(CCMetadata *)metadata fileName:(NSString *)fileName
  1482. {
  1483. CCTemplates *templates = [[CCTemplates alloc] init];
  1484. CCCrypto *crypto = [[CCCrypto alloc] init];
  1485. NSMutableDictionary *field = [crypto getDictionaryEncrypted:metadata.fileName uuid:metadata.uuid isLocal:NO directoryUser:app.directoryUser];
  1486. NSString *fileNameModel = [templates salvaNote:[field objectForKey:@"note"] titolo:fileName fileName:metadata.fileName uuid:metadata.uuid];
  1487. if (fileNameModel) {
  1488. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1489. metadataNet.action = actionUploadTemplate;
  1490. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  1491. metadataNet.fileNamePrint = fileName;
  1492. metadataNet.rev = metadata.rev;
  1493. metadataNet.serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  1494. metadataNet.session = k_upload_session_foreground;
  1495. metadataNet.taskStatus = k_taskStatusResume;
  1496. if ([CCCoreData isOfflineLocalFileID:metadata.fileID activeAccount:app.activeAccount])
  1497. metadataNet.selectorPost = selectorAddOffline;
  1498. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1499. }
  1500. }
  1501. - (void)renameMoveFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1502. {
  1503. if ([metadataNet.selector isEqualToString:selectorMove]) {
  1504. [_hud hideHud];
  1505. if (message)
  1506. [app messageNotification:@"_move_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  1507. [_selectedMetadatas removeAllObjects];
  1508. [_queueSelector removeAllObjects];
  1509. }
  1510. }
  1511. - (void)moveSuccess:(CCMetadataNet *)metadataNet revTo:(NSString *)revTo
  1512. {
  1513. [_queueSelector removeObject:metadataNet.selector];
  1514. if ([_queueSelector count] == 0) {
  1515. [_hud hideHud];
  1516. NSString *fileName = [CCUtility trasformedFileNameCryptoInPlist:metadataNet.fileName];
  1517. NSString *directoryID = metadataNet.directoryID;
  1518. NSString *directoryIDTo = metadataNet.directoryIDTo;
  1519. NSString *serverUrlTo = [CCCoreData getServerUrlFromDirectoryID:directoryIDTo activeAccount:app.activeAccount];
  1520. // FILE -> Metadata
  1521. if (metadataNet.directory == NO) {
  1522. // move metadata
  1523. [CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
  1524. }
  1525. // DIRECTORY -> Directory - CCMetadata
  1526. if (metadataNet.directory == YES) {
  1527. // delete all dir / subdir
  1528. NSArray *directoryIDs = [CCCoreData deleteDirectoryAndSubDirectory:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:fileName] activeAccount:app.activeAccount];
  1529. // delete all metadata and local file in dir / subdir
  1530. for (NSString *directoryIDDelete in directoryIDs)
  1531. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(directoryID == %@)AND (account == %@)",directoryIDDelete, app.activeAccount]];
  1532. // move metadata
  1533. [CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
  1534. // Add new directory
  1535. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrlTo, fileName];
  1536. [CCCoreData addDirectory:newDirectory permissions:nil activeAccount:app.activeAccount];
  1537. // Check Offline
  1538. if ([CCCoreData isOfflineDirectoryServerUrl:serverUrlTo activeAccount:app.activeAccount])
  1539. [CCCoreData setOfflineDirectoryServerUrl:newDirectory offline:YES activeAccount:app.activeAccount];
  1540. }
  1541. // reload Datasource
  1542. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced] || _isSearchMode)
  1543. [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
  1544. else
  1545. [self reloadDatasource];
  1546. // Next file
  1547. [_selectedMetadatas removeObjectAtIndex:0];
  1548. [self moveFileOrFolder:metadataNet.serverUrlTo];
  1549. }
  1550. }
  1551. - (void)moveFileOrFolder:(NSString *)serverUrlTo
  1552. {
  1553. if ([_selectedMetadatas count] > 0) {
  1554. CCMetadata *metadata = [_selectedMetadatas objectAtIndex:0];
  1555. // Plain
  1556. if (metadata.cryptated == NO) {
  1557. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1558. metadataNet.action = actionMoveFileOrFolder;
  1559. metadataNet.directory = metadata.directory;
  1560. metadataNet.fileID = metadata.fileID;
  1561. metadataNet.directoryID = metadata.directoryID;
  1562. metadataNet.directoryIDTo = [CCCoreData getDirectoryIDFromServerUrl:serverUrlTo activeAccount:app.activeAccount];
  1563. metadataNet.fileName = metadata.fileName;
  1564. metadataNet.fileNamePrint = metadataNet.fileNamePrint;
  1565. metadataNet.fileNameTo = metadata.fileName;
  1566. metadataNet.rev = metadata.rev;
  1567. metadataNet.selector = selectorMove;
  1568. metadataNet.serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  1569. metadataNet.serverUrlTo = serverUrlTo;
  1570. [_queueSelector addObject:metadataNet.selector];
  1571. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1572. }
  1573. // cyptated
  1574. if (metadata.cryptated == YES) {
  1575. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1576. metadataNet.action = actionMoveFileOrFolder;
  1577. metadataNet.directory = metadata.directory;
  1578. metadataNet.fileID = metadata.fileID;
  1579. metadataNet.directoryID = metadata.directoryID;
  1580. metadataNet.directoryIDTo = [CCCoreData getDirectoryIDFromServerUrl:serverUrlTo activeAccount:app.activeAccount];
  1581. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1582. metadataNet.rev = metadata.rev;
  1583. metadataNet.serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  1584. metadataNet.serverUrlTo = serverUrlTo;
  1585. // data
  1586. metadataNet.fileName = metadata.fileNameData;
  1587. metadataNet.fileNameTo = metadata.fileNameData;
  1588. metadataNet.selector = selectorMoveCrypto;
  1589. [_queueSelector addObject:metadataNet.selector];
  1590. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1591. // plist
  1592. metadataNet.fileName = metadata.fileName;
  1593. metadataNet.fileNameTo = metadata.fileName;
  1594. metadataNet.selector = selectorMovePlist;
  1595. [_queueSelector addObject:metadataNet.selector];
  1596. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1597. }
  1598. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), _numSelectedMetadatas - [_selectedMetadatas count] + 1, _numSelectedMetadatas] mode:MBProgressHUDModeIndeterminate color:nil];
  1599. }
  1600. }
  1601. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
  1602. {
  1603. [_selectedMetadatas removeAllObjects];
  1604. [_queueSelector removeAllObjects];
  1605. _selectedMetadatas = [[NSMutableArray alloc] initWithArray:selectedMetadatas];
  1606. _numSelectedMetadatas = [_selectedMetadatas count];
  1607. [self moveFileOrFolder:serverUrlTo];
  1608. [self tableViewSelect:NO];
  1609. }
  1610. - (void)moveOpenWindow:(NSArray *)indexPaths
  1611. {
  1612. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  1613. CCMove *viewController = (CCMove *)navigationController.topViewController;
  1614. viewController.delegate = self;
  1615. viewController.move.title = NSLocalizedString(@"_move_", nil);
  1616. viewController.selectedMetadatas = [self getMetadatasFromSelectedRows:indexPaths];
  1617. viewController.tintColor = COLOR_NAVIGATIONBAR_TEXT;
  1618. viewController.barTintColor = COLOR_NAVIGATIONBAR;
  1619. viewController.tintColorTitle = COLOR_NAVIGATIONBAR_TEXT;
  1620. viewController.networkingOperationQueue = app.netQueue;
  1621. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  1622. [self presentViewController:navigationController animated:YES completion:nil];
  1623. }
  1624. #pragma --------------------------------------------------------------------------------------------
  1625. #pragma mark ===== Create folder =====
  1626. #pragma --------------------------------------------------------------------------------------------
  1627. - (void)createFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1628. {
  1629. [_hud hideHud];
  1630. if (message)
  1631. [app messageNotification:@"_create_folder_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  1632. }
  1633. - (void)createFolderSuccess:(CCMetadataNet *)metadataNet
  1634. {
  1635. [_hud hideHud];
  1636. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", metadataNet.serverUrl, metadataNet.fileName];
  1637. [CCCoreData addDirectory:newDirectory permissions:nil activeAccount:app.activeAccount];
  1638. // Check Offline
  1639. if ([CCCoreData isOfflineDirectoryServerUrl:_serverUrl activeAccount:app.activeAccount])
  1640. [CCCoreData setOfflineDirectoryServerUrl:newDirectory offline:YES activeAccount:app.activeAccount];
  1641. // Load Folder or the Datasource
  1642. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
  1643. [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
  1644. } else {
  1645. [self reloadDatasource:metadataNet.serverUrl fileID:metadataNet.fileID selector:metadataNet.selector];
  1646. }
  1647. }
  1648. - (void)createFolder:(NSString *)fileNameFolder folderCameraUpload:(BOOL)folderCameraUpload
  1649. {
  1650. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1651. fileNameFolder = [CCUtility removeForbiddenCharacters:fileNameFolder hasServerForbiddenCharactersSupport:app.hasServerForbiddenCharactersSupport];
  1652. if (![fileNameFolder length]) return;
  1653. if (folderCameraUpload) metadataNet.serverUrl = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  1654. else metadataNet.serverUrl = _serverUrl;
  1655. metadataNet.action = actionCreateFolder;
  1656. if (folderCameraUpload)
  1657. metadataNet.options = @"folderCameraUpload";
  1658. metadataNet.fileName = fileNameFolder;
  1659. metadataNet.selector = selectorCreateFolder;
  1660. metadataNet.selectorPost = selectorReadFolderForced;
  1661. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1662. if (!folderCameraUpload)
  1663. [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1664. }
  1665. - (void)createFolderEncrypted:(NSString *)fileNameFolder
  1666. {
  1667. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1668. CCCrypto *crypto = [[CCCrypto alloc] init];
  1669. NSString *fileNamePlist;
  1670. fileNameFolder = [CCUtility removeForbiddenCharacters:fileNameFolder hasServerForbiddenCharactersSupport:app.hasServerForbiddenCharactersSupport];
  1671. if (![fileNameFolder length]) return;
  1672. NSString *title = [AESCrypt encrypt:fileNameFolder password:[crypto getKeyPasscode:[CCUtility getUUID]]];
  1673. fileNamePlist = [crypto createFilenameEncryptor:fileNameFolder uuid:[CCUtility getUUID]];
  1674. [crypto createFilePlist:[NSTemporaryDirectory() stringByAppendingString:fileNamePlist] title:title len:0 directory:true uuid:[CCUtility getUUID] nameCurrentDevice:[CCUtility getNameCurrentDevice] icon:@""];
  1675. // Create folder
  1676. metadataNet.action = actionCreateFolder;
  1677. metadataNet.fileName = fileNamePlist;
  1678. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1679. metadataNet.selector = selectorCreateFolder;
  1680. metadataNet.serverUrl = _serverUrl;
  1681. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1682. // upload plist file
  1683. metadataNet.action = actionUploadOnlyPlist;
  1684. metadataNet.fileName = [fileNamePlist stringByAppendingString:@".plist"];
  1685. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1686. metadataNet.selectorPost = selectorReadFolderForced;
  1687. metadataNet.serverUrl = _serverUrl;
  1688. metadataNet.session = k_upload_session_foreground;
  1689. metadataNet.taskStatus = k_taskStatusResume;
  1690. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1691. [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1692. }
  1693. - (void)createFolderCameraUpload
  1694. {
  1695. [self createFolder:[CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount] folderCameraUpload:YES];
  1696. }
  1697. #pragma --------------------------------------------------------------------------------------------
  1698. #pragma mark ===== Encrypted / Decrypted Folder =====
  1699. #pragma --------------------------------------------------------------------------------------------
  1700. - (void)encyptedDecryptedFolder
  1701. {
  1702. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  1703. if (_metadata.cryptated) {
  1704. // DECRYPTED
  1705. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1706. //-------------------------- RENAME -------------------------------------------//
  1707. metadataNet.action = actionMoveFileOrFolder;
  1708. metadataNet.fileID = _metadata.fileID;
  1709. metadataNet.fileName = _metadata.fileNameData;
  1710. metadataNet.fileNameTo = _metadata.fileNamePrint;
  1711. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1712. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1713. metadataNet.selector = selectorRename;
  1714. metadataNet.serverUrl = serverUrl;
  1715. metadataNet.serverUrlTo = serverUrl;
  1716. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1717. //-------------------------- DELETE -------------------------------------------//
  1718. metadataNet.action = actionDeleteFileDirectory;
  1719. metadataNet.fileID = _metadata.fileID;
  1720. metadataNet.fileName = _metadata.fileName;
  1721. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1722. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1723. metadataNet.selector = selectorDeletePlist;
  1724. metadataNet.selectorPost = selectorReadFolderForced;
  1725. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1726. } else {
  1727. // ENCRYPTED
  1728. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1729. CCCrypto *crypto = [[CCCrypto alloc] init];
  1730. // Create File Plist
  1731. NSString *fileNameCrypto = [crypto createFileDirectoryPlist:_metadata];
  1732. //-------------------------- RENAME -------------------------------------------//
  1733. metadataNet.action = actionMoveFileOrFolder;
  1734. metadataNet.fileID = _metadata.fileID;
  1735. metadataNet.fileName = _metadata.fileName;
  1736. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1737. metadataNet.fileNameTo = fileNameCrypto;
  1738. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1739. metadataNet.selector = selectorRename;
  1740. metadataNet.serverUrl = serverUrl;
  1741. metadataNet.serverUrlTo = serverUrl;
  1742. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1743. //-------------------------- UPLOAD -------------------------------------------//
  1744. metadataNet.action = actionUploadOnlyPlist;
  1745. metadataNet.fileName = [fileNameCrypto stringByAppendingString:@".plist"];
  1746. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1747. metadataNet.selectorPost = selectorReadFolderForced;
  1748. metadataNet.serverUrl = serverUrl;
  1749. metadataNet.session = k_upload_session_foreground;
  1750. metadataNet.taskStatus = k_taskStatusResume;
  1751. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1752. }
  1753. }
  1754. #pragma --------------------------------------------------------------------------------------------
  1755. #pragma mark ===== Encrypted/Decrypted File =====
  1756. #pragma --------------------------------------------------------------------------------------------
  1757. - (void)encryptedSelectedFiles
  1758. {
  1759. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1760. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1761. for (CCMetadata *metadata in selectedMetadatas) {
  1762. if (metadata.cryptated == NO && metadata.directory == NO)
  1763. [metadatas addObject:metadata];
  1764. }
  1765. if ([metadatas count] > 0) {
  1766. NSLog(@"[LOG] Start encrypted selected files ...");
  1767. for (CCMetadata* metadata in metadatas) {
  1768. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  1769. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorEncryptFile selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
  1770. }
  1771. }
  1772. [self tableViewSelect:NO];
  1773. }
  1774. - (void)decryptedSelectedFiles
  1775. {
  1776. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1777. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1778. for (CCMetadata *metadata in selectedMetadatas) {
  1779. if (metadata.cryptated == YES && metadata.directory == NO && [metadata.model length] == 0)
  1780. [metadatas addObject:metadata];
  1781. }
  1782. if ([metadatas count] > 0) {
  1783. NSLog(@"[LOG] Start decrypted selected files ...");
  1784. for (CCMetadata* metadata in metadatas) {
  1785. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  1786. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorDecryptFile selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
  1787. }
  1788. }
  1789. [self tableViewSelect:NO];
  1790. }
  1791. - (void)cmdEncryptedDecryptedFile
  1792. {
  1793. NSString *selector;
  1794. if (_metadata.cryptated == YES) selector = selectorDecryptFile;
  1795. if (_metadata.cryptated == NO) selector = selectorEncryptFile;
  1796. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  1797. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selector selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  1798. }
  1799. - (void)encryptedFile:(CCMetadata *)metadata
  1800. {
  1801. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1802. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  1803. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  1804. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
  1805. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  1806. dispatch_async(dispatch_get_main_queue(), ^{
  1807. [[CCNetworking sharedNetworking] uploadFile:metadata.fileName serverUrl:serverUrl cryptated:YES onlyPlist:NO session:k_upload_session taskStatus:k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  1808. [self performSelector:@selector(reloadDatasource) withObject:nil];
  1809. });
  1810. } else {
  1811. [app messageNotification:@"_encrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  1812. }
  1813. }
  1814. - (void)decryptedFile:(CCMetadata *)metadata
  1815. {
  1816. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1817. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  1818. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  1819. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
  1820. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  1821. dispatch_async(dispatch_get_main_queue(), ^{
  1822. [[CCNetworking sharedNetworking] uploadFile:metadata.fileNamePrint serverUrl:serverUrl cryptated:NO onlyPlist:NO session:k_upload_session taskStatus:k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  1823. [self performSelector:@selector(reloadDatasource) withObject:nil];
  1824. });
  1825. } else {
  1826. [app messageNotification:@"_decrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  1827. }
  1828. }
  1829. #pragma --------------------------------------------------------------------------------------------
  1830. #pragma mark ===== Progress & Task Button =====
  1831. #pragma --------------------------------------------------------------------------------------------
  1832. - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
  1833. {
  1834. // Check
  1835. if (!fileID)
  1836. return;
  1837. [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  1838. if (![serverUrl isEqualToString:_serverUrl])
  1839. return;
  1840. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  1841. if (indexPath) {
  1842. CCControlCenterTransferCell *cell = (CCControlCenterTransferCell *)[self.tableView cellForRowAtIndexPath:indexPath];
  1843. if (cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  1844. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  1845. cell.progressView.hidden = NO;
  1846. [cell.progressView setProgress:progress];
  1847. }
  1848. }
  1849. - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
  1850. {
  1851. UITouch * touch = [[event allTouches] anyObject];
  1852. CGPoint location = [touch locationInView:self.tableView];
  1853. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1854. if (indexPath) {
  1855. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1856. if (metadata)
  1857. [self reloadTaskButton:metadata];
  1858. }
  1859. }
  1860. - (void)reloadTaskButton:(CCMetadata *)metadata
  1861. {
  1862. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1863. __block NSURLSessionTask *findTask;
  1864. // DOWNLOAD
  1865. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  1866. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1867. for (NSURLSessionUploadTask *task in downloadTasks)
  1868. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1869. findTask = task;
  1870. [app.listChangeTask setObject:@"reloadDownload" forKey:metadata.fileID];
  1871. [task cancel];
  1872. }
  1873. if (!findTask) {
  1874. dispatch_async(dispatch_get_main_queue(), ^{
  1875. [app.listChangeTask setObject:@"reloadDownload" forKey:metadata.fileID];
  1876. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1877. [[NSNotificationCenter defaultCenter] postNotificationName:k_networkingSessionNotification object:object];
  1878. });
  1879. }
  1880. }];
  1881. }
  1882. // UPLOAD
  1883. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1884. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1885. for (NSURLSessionUploadTask *task in uploadTasks)
  1886. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1887. findTask = task;
  1888. [app.listChangeTask setObject:@"reloadUpload" forKey:metadata.fileID];
  1889. [task cancel];
  1890. }
  1891. if (!findTask) {
  1892. dispatch_async(dispatch_get_main_queue(), ^{
  1893. [app.listChangeTask setObject:@"reloadUpload" forKey:metadata.fileID];
  1894. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1895. [[NSNotificationCenter defaultCenter] postNotificationName:k_networkingSessionNotification object:object];
  1896. });
  1897. }
  1898. }];
  1899. }
  1900. }
  1901. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  1902. {
  1903. UITouch * touch = [[event allTouches] anyObject];
  1904. CGPoint location = [touch locationInView:self.tableView];
  1905. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1906. if (indexPath) {
  1907. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1908. if (metadata)
  1909. [self cancelTaskButton:metadata reloadTable:YES];
  1910. }
  1911. }
  1912. - (void)cancelTaskButton:(CCMetadata *)metadata reloadTable:(BOOL)reloadTable
  1913. {
  1914. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1915. __block NSURLSessionTask *findTask;
  1916. // DOWNLOAD
  1917. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  1918. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1919. for (NSURLSessionTask *task in downloadTasks)
  1920. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1921. findTask = task;
  1922. [app.listChangeTask setObject:@"cancelDownload" forKey:metadata.fileID];
  1923. [task cancel];
  1924. }
  1925. if (!findTask) {
  1926. [app.listChangeTask setObject:@"cancelDownload" forKey:metadata.fileID];
  1927. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1928. [[NSNotificationCenter defaultCenter] postNotificationName:k_networkingSessionNotification object:object];
  1929. }
  1930. }];
  1931. }
  1932. // UPLOAD
  1933. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1934. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1935. for (NSURLSessionUploadTask *task in uploadTasks)
  1936. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1937. findTask = task;
  1938. [app.listChangeTask setObject:@"cancelUpload" forKey:metadata.fileID];
  1939. [task cancel];
  1940. }
  1941. if (!findTask) {
  1942. dispatch_async(dispatch_get_main_queue(), ^{
  1943. [app.listChangeTask setObject:@"cancelUpload" forKey:metadata.fileID];
  1944. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1945. [[NSNotificationCenter defaultCenter] postNotificationName:k_networkingSessionNotification object:object];
  1946. });
  1947. }
  1948. }];
  1949. }
  1950. }
  1951. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  1952. {
  1953. UITouch * touch = [[event allTouches] anyObject];
  1954. CGPoint location = [touch locationInView:self.tableView];
  1955. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1956. if (indexPath) {
  1957. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1958. if (metadata)
  1959. [self stopTaskButton:metadata];
  1960. }
  1961. }
  1962. - (void)stopTaskButton:(CCMetadata *)metadata
  1963. {
  1964. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1965. __block NSURLSessionTask *findTask;
  1966. // UPLOAD
  1967. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1968. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1969. for (NSURLSessionUploadTask *task in uploadTasks)
  1970. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1971. [app.listChangeTask setObject:@"stopUpload" forKey:metadata.fileID];
  1972. findTask = task;
  1973. [task cancel];
  1974. }
  1975. if (!findTask) {
  1976. dispatch_async(dispatch_get_main_queue(), ^{
  1977. [app.listChangeTask setObject:@"stopUpload" forKey:metadata.fileID];
  1978. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1979. [[NSNotificationCenter defaultCenter] postNotificationName:k_networkingSessionNotification object:object];
  1980. });
  1981. }
  1982. }];
  1983. }
  1984. }
  1985. #pragma --------------------------------------------------------------------------------------------
  1986. #pragma mark ===== Shared =====
  1987. #pragma --------------------------------------------------------------------------------------------
  1988. - (void)readSharedSuccess:(CCMetadataNet *)metadataNet items:(NSDictionary *)items openWindow:(BOOL)openWindow
  1989. {
  1990. [_hud hideHud];
  1991. // change account ?
  1992. TableAccount *record = [CCCoreData getActiveAccount];
  1993. if([record.account isEqualToString:metadataNet.account] == NO)
  1994. return;
  1995. [CCCoreData updateShare:items sharesLink:app.sharesLink sharesUserAndGroup:app.sharesUserAndGroup activeAccount:app.activeAccount activeUrl:app.activeUrl];
  1996. if (openWindow) {
  1997. if (_shareOC) {
  1998. [_shareOC reloadData];
  1999. } else {
  2000. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  2001. // Apriamo la view
  2002. _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
  2003. _shareOC.delegate = self;
  2004. _shareOC.metadata = metadata;
  2005. _shareOC.serverUrl = metadataNet.serverUrl;
  2006. _shareOC.shareLink = [app.sharesLink objectForKey:metadata.fileID];
  2007. _shareOC.shareUserAndGroup = [app.sharesUserAndGroup objectForKey:metadata.fileID];
  2008. [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
  2009. [self presentViewController:_shareOC animated:YES completion:nil];
  2010. }
  2011. }
  2012. [self tableViewReload];
  2013. }
  2014. - (void)requestSharedByServer
  2015. {
  2016. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2017. metadataNet.action = actionReadShareServer;
  2018. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2019. }
  2020. - (void)shareFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2021. {
  2022. [_hud hideHud];
  2023. [app messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  2024. if (_shareOC)
  2025. [_shareOC reloadData];
  2026. [self tableViewReload];
  2027. if (errorCode == 401)
  2028. [self changePasswordAccount];
  2029. }
  2030. - (void)share:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password
  2031. {
  2032. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2033. metadataNet.action = actionShare;
  2034. metadataNet.fileID = metadata.fileID;
  2035. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl];
  2036. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2037. metadataNet.password = password;
  2038. metadataNet.selector = selectorShare;
  2039. metadataNet.serverUrl = serverUrl;
  2040. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2041. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2042. }
  2043. - (void)unShareSuccess:(CCMetadataNet *)metadataNet
  2044. {
  2045. [_hud hideHud];
  2046. // rimuoviamo la condivisione da db
  2047. [CCCoreData unShare:metadataNet.share fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl sharesLink:app.sharesLink sharesUserAndGroup:app.sharesUserAndGroup activeAccount:app.activeAccount];
  2048. if (_shareOC)
  2049. [_shareOC reloadData];
  2050. [self tableViewReload];
  2051. }
  2052. - (void)unShare:(NSString *)share metadata:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl
  2053. {
  2054. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2055. metadataNet.action = actionUnShare;
  2056. metadataNet.fileID = metadata.fileID;
  2057. metadataNet.fileName = metadata.fileName;
  2058. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2059. metadataNet.selector = selectorUnshare;
  2060. metadataNet.serverUrl = serverUrl;
  2061. metadataNet.share = share;
  2062. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2063. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2064. }
  2065. - (void)updateShare:(NSString *)share metadata:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission
  2066. {
  2067. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2068. metadataNet.action = actionUpdateShare;
  2069. metadataNet.fileID = metadata.fileID;
  2070. metadataNet.expirationTime = expirationTime;
  2071. metadataNet.password = password;
  2072. metadataNet.selector = selectorUpdateShare;
  2073. metadataNet.serverUrl = serverUrl;
  2074. metadataNet.share = share;
  2075. metadataNet.sharePermission = permission;
  2076. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2077. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2078. }
  2079. - (void)getUserAndGroupSuccess:(CCMetadataNet *)metadataNet items:(NSArray *)items
  2080. {
  2081. [_hud hideHud];
  2082. if (_shareOC)
  2083. [_shareOC reloadUserAndGroup:items];
  2084. }
  2085. - (void)getUserAndGroupFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2086. {
  2087. [_hud hideHud];
  2088. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  2089. }
  2090. - (void)getUserAndGroup:(NSString *)find
  2091. {
  2092. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2093. metadataNet.action = actionGetUserAndGroup;
  2094. metadataNet.options = find;
  2095. metadataNet.selector = selectorGetUserAndGroup;
  2096. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2097. [_hud visibleIndeterminateHud];
  2098. }
  2099. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission metadata:(CCMetadata *)metadata directoryID:(NSString *)directoryID serverUrl:(NSString *)serverUrl
  2100. {
  2101. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2102. metadataNet.action = actionShareWith;
  2103. metadataNet.fileID = metadata.fileID;
  2104. metadataNet.directoryID = directoryID;
  2105. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl];
  2106. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2107. metadataNet.serverUrl = serverUrl;
  2108. metadataNet.selector = selectorShare;
  2109. metadataNet.share = user;
  2110. metadataNet.shareeType = shareeType;
  2111. metadataNet.sharePermission = permission;
  2112. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2113. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2114. }
  2115. - (void)openWindowShare:(CCMetadata *)metadata
  2116. {
  2117. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2118. metadataNet.action = actionReadShareServer;
  2119. metadataNet.fileID = metadata.fileID;
  2120. metadataNet.fileName = metadata.fileName;
  2121. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2122. metadataNet.selector = selectorOpenWindowShare;
  2123. metadataNet.serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  2124. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2125. [_hud visibleIndeterminateHud];
  2126. }
  2127. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  2128. {
  2129. CGPoint location = [tapGesture locationInView:self.tableView];
  2130. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  2131. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2132. if (metadata)
  2133. [self openWindowShare:metadata];
  2134. }
  2135. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  2136. {
  2137. CGPoint location = [tapGesture locationInView:self.tableView];
  2138. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  2139. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2140. if (metadata) {
  2141. CCShareInfoCMOC *vc = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareInfoCMOC"];
  2142. vc.metadata = metadata;
  2143. [vc setModalPresentationStyle:UIModalPresentationFormSheet];
  2144. [self presentViewController:vc animated:YES completion:nil];
  2145. }
  2146. }
  2147. #pragma --------------------------------------------------------------------------------------------
  2148. #pragma mark ===== Favorite =====
  2149. #pragma --------------------------------------------------------------------------------------------
  2150. - (void)settingFavoriteSuccess:(CCMetadataNet *)metadataNet
  2151. {
  2152. [CCCoreData SetMetadataFavoriteFileID:metadataNet.fileID favorite:[metadataNet.options boolValue] activeAccount:app.activeAccount context:nil];
  2153. _dateReadDataSource = nil;
  2154. if (_isSearchMode)
  2155. [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
  2156. else
  2157. [self reloadDatasource:metadataNet.serverUrl fileID:metadataNet.fileID selector:metadataNet.selector];
  2158. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  2159. if (metadata.directory && metadata.favorite) {
  2160. NSString *dir = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:metadata.fileNameData];
  2161. [[CCSynchronize sharedSynchronize] addFavoriteFolder:dir];
  2162. }
  2163. }
  2164. - (void)settingFavoriteFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2165. {
  2166. }
  2167. - (void)addFavorite:(CCMetadata *)metadata
  2168. {
  2169. if (metadata.directory) {
  2170. [[CCActions sharedInstance] settingFavorite:metadata favorite:YES delegate:self];
  2171. } else {
  2172. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  2173. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddFavorite selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2174. }
  2175. }
  2176. - (void)removeFavorite:(CCMetadata *)metadata
  2177. {
  2178. [[CCActions sharedInstance] settingFavorite:metadata favorite:NO delegate:self];
  2179. }
  2180. #pragma --------------------------------------------------------------------------------------------
  2181. #pragma mark ===== Offline =====
  2182. #pragma --------------------------------------------------------------------------------------------
  2183. - (void)addOffline:(CCMetadata *)metadata
  2184. {
  2185. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  2186. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddOffline selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2187. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2188. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2189. }
  2190. - (void)removeOffline:(CCMetadata *)metadata
  2191. {
  2192. [CCCoreData setOfflineLocalFileID:metadata.fileID offline:NO activeAccount:app.activeAccount];
  2193. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2194. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2195. }
  2196. #pragma --------------------------------------------------------------------------------------------
  2197. #pragma mark ===== Local =====
  2198. #pragma --------------------------------------------------------------------------------------------
  2199. - (void)addLocal:(CCMetadata *)metadata
  2200. {
  2201. if (metadata.errorPasscode || !metadata.uuid) return;
  2202. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  2203. if ([metadata.type isEqualToString: k_metadataType_file])
  2204. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddLocal selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2205. if ([metadata.type isEqualToString: k_metadataType_template]) {
  2206. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileName]];
  2207. [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  2208. }
  2209. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2210. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2211. }
  2212. #pragma --------------------------------------------------------------------------------------------
  2213. #pragma mark ===== Reload =====
  2214. #pragma --------------------------------------------------------------------------------------------
  2215. - (void)reloadFile:(CCMetadata *)metadata
  2216. {
  2217. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  2218. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorReload selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2219. }
  2220. #pragma --------------------------------------------------------------------------------------------
  2221. #pragma mark ===== Open in... =====
  2222. #pragma --------------------------------------------------------------------------------------------
  2223. - (void)openIn:(CCMetadata *)metadata
  2224. {
  2225. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  2226. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorOpenIn selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2227. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2228. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2229. }
  2230. #pragma --------------------------------------------------------------------------------------------
  2231. #pragma mark ===== Order Table & GroupBy & DirectoryOnTop =====
  2232. #pragma --------------------------------------------------------------------------------------------
  2233. - (void)orderTable:(NSString *)order
  2234. {
  2235. [CCUtility setOrderSettings:order];
  2236. // Clear data-read of DataSource
  2237. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2238. // new menu
  2239. [self createReMainMenu];
  2240. }
  2241. - (void)ascendingTable:(BOOL)ascending
  2242. {
  2243. [CCUtility setAscendingSettings:ascending];
  2244. // Clear data-read of DataSource
  2245. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2246. // new menu
  2247. [self createReMainMenu];
  2248. }
  2249. - (void)directoryOnTop:(BOOL)directoryOnTop
  2250. {
  2251. [CCUtility setDirectoryOnTop:directoryOnTop];
  2252. // Clear data-read of DataSource
  2253. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2254. // new menu
  2255. [self createReMainMenu];
  2256. }
  2257. - (void)tableGroupBy:(NSString *)groupBy
  2258. {
  2259. [CCUtility setGroupBySettings:groupBy];
  2260. // Clear data-read of DataSource
  2261. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2262. // new menu
  2263. [self createReMainMenu];
  2264. }
  2265. #pragma --------------------------------------------------------------------------------------------
  2266. #pragma mark ==== Menu change User ====
  2267. #pragma --------------------------------------------------------------------------------------------
  2268. - (void)menuChangeUser
  2269. {
  2270. if (app.reSelectMenu.isOpen || app.reMainMenu.isOpen)
  2271. return;
  2272. if ([app.netQueue operationCount] > 0 || [app.netQueueDownload operationCount] > 0 || [app.netQueueDownloadWWan operationCount] > 0 || [app.netQueueUpload operationCount] > 0 || [app.netQueueUploadWWan operationCount] > 0 || [CCCoreData countTableAutomaticUploadForAccount:app.activeAccount selector:nil] > 0) {
  2273. [app messageNotification:@"_transfers_in_queue_" description:nil visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  2274. return;
  2275. }
  2276. NSArray *listTableAccount = [CCCoreData getAllTableAccount];
  2277. NSMutableArray *menuArray = [[NSMutableArray alloc] init];
  2278. for (TableAccount *record in listTableAccount) {
  2279. if ([record.account isEqualToString:app.activeAccount]) continue;
  2280. CCMenuItem *item = [[CCMenuItem alloc] init];
  2281. item.title = [record.account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  2282. item.argument = record.account;
  2283. item.image = [UIImage imageNamed:image_Nextcloud];
  2284. item.target = self;
  2285. item.action = @selector(changeDefaultAccount:);
  2286. [menuArray addObject:item];
  2287. }
  2288. if ([menuArray count] == 0)
  2289. return;
  2290. OptionalConfiguration options;
  2291. Color textColor, backgroundColor;
  2292. textColor.R = 0;
  2293. textColor.G = 0;
  2294. textColor.B = 0;
  2295. backgroundColor.R = 1;
  2296. backgroundColor.G = 1;
  2297. backgroundColor.B = 1;
  2298. NSInteger originY = 60;
  2299. options.arrowSize = 9;
  2300. options.marginXSpacing = 7;
  2301. options.marginYSpacing = 10;
  2302. options.intervalSpacing = 20;
  2303. options.menuCornerRadius = 6.5;
  2304. options.maskToBackground = NO;
  2305. options.shadowOfMenu = YES;
  2306. options.hasSeperatorLine = YES;
  2307. options.seperatorLineHasInsets = YES;
  2308. options.textColor = textColor;
  2309. options.menuBackgroundColor = backgroundColor;
  2310. CGRect rect = self.view.frame;
  2311. rect.origin.y = rect.origin.y + originY;
  2312. rect.size.height = rect.size.height - originY;
  2313. [CCMenu setTitleFont:[UIFont systemFontOfSize:12.0]];
  2314. [CCMenu showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
  2315. }
  2316. - (void)changeDefaultAccount:(CCMenuItem *)sender
  2317. {
  2318. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
  2319. // STOP, erase all in queue networking
  2320. [app cancelAllOperations];
  2321. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  2322. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  2323. TableAccount *tableAccount = [CCCoreData setActiveAccount:[sender argument]];
  2324. if (tableAccount)
  2325. [app settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activePassword:tableAccount.password];
  2326. // go to home sweet home
  2327. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  2328. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  2329. });
  2330. }
  2331. #pragma --------------------------------------------------------------------------------------------
  2332. #pragma mark ==== ReMenu ====
  2333. #pragma --------------------------------------------------------------------------------------------
  2334. - (void)createReMenuBackgroundView:(REMenu *)menu
  2335. {
  2336. __block CGFloat navigationBarH = self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
  2337. _reMenuBackgroundView.frame = CGRectMake(0, navigationBarH, self.view.frame.size.width, self.view.frame.size.height);
  2338. [UIView animateWithDuration:0.2 animations:^{
  2339. float height = (self.view.frame.size.height + navigationBarH) - (menu.menuView.frame.size.height - self.navigationController.navigationBar.frame.size.height + 3);
  2340. if (height < self.tabBarController.tabBar.frame.size.height)
  2341. height = self.tabBarController.tabBar.frame.size.height;
  2342. _reMenuBackgroundView.frame = CGRectMake(0, self.view.frame.size.height + navigationBarH, self.view.frame.size.width, - height);
  2343. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  2344. }];
  2345. }
  2346. - (void)createReMainMenu
  2347. {
  2348. NSString *ordinamento;
  2349. NSString *groupBy = _directoryGroupBy;
  2350. __block NSString *nuovoOrdinamento;
  2351. NSString *titoloNuovo, *titoloAttuale;
  2352. BOOL ascendente;
  2353. __block BOOL nuovoAscendente;
  2354. UIImage *image;
  2355. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  2356. if (app.selezionaItem == nil) app.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)
  2357. subtitle:@""
  2358. image:[UIImage imageNamed:image_seleziona]
  2359. highlightedImage:nil
  2360. action:^(REMenuItem *item) {
  2361. if ([_sectionDataSource.allRecordsDataSource count] > 0) {
  2362. [self tableViewSelect:YES];
  2363. }
  2364. }];
  2365. else app.selezionaItem = [app.selezionaItem initWithTitle:NSLocalizedString(@"_select_", nil)
  2366. subtitle:@""
  2367. image:[UIImage imageNamed:image_seleziona]
  2368. highlightedImage:nil
  2369. action:^(REMenuItem *item) {
  2370. if ([_sectionDataSource.allRecordsDataSource count] > 0)
  2371. [self tableViewSelect:YES];
  2372. }];
  2373. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  2374. ordinamento = _directoryOrder;
  2375. if ([ordinamento isEqualToString:@"fileName"]) {
  2376. image = [UIImage imageNamed:image_MenuOrdeyByDate];
  2377. titoloNuovo = NSLocalizedString(@"_order_by_date_", nil);
  2378. titoloAttuale = NSLocalizedString(@"_current_order_name_", nil);
  2379. nuovoOrdinamento = @"fileDate";
  2380. }
  2381. if ([ordinamento isEqualToString:@"fileDate"]) {
  2382. image = [UIImage imageNamed:image_MenuOrderByFileName];
  2383. titoloNuovo = NSLocalizedString(@"_order_by_name_", nil);
  2384. titoloAttuale = NSLocalizedString(@"_current_order_date_", nil);
  2385. nuovoOrdinamento = @"fileName";
  2386. }
  2387. if (app.ordinaItem == nil) app.ordinaItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2388. subtitle:titoloAttuale
  2389. image:image
  2390. highlightedImage:nil
  2391. action:^(REMenuItem *item) {
  2392. [self orderTable:nuovoOrdinamento];
  2393. }];
  2394. else app.ordinaItem = [app.ordinaItem initWithTitle:titoloNuovo
  2395. subtitle:titoloAttuale
  2396. image:image
  2397. highlightedImage:nil
  2398. action:^(REMenuItem *item) {
  2399. [self orderTable:nuovoOrdinamento];
  2400. }];
  2401. // ITEM ASCENDING -----------------------------------------------------------------------------------------------------
  2402. ascendente = [CCUtility getAscendingSettings];
  2403. if (ascendente) {
  2404. image = [UIImage imageNamed:image_MenuOrdinamentoDiscendente];
  2405. titoloNuovo = NSLocalizedString(@"_sort_descending_", nil);
  2406. titoloAttuale = NSLocalizedString(@"_current_sort_ascending_", nil);
  2407. nuovoAscendente = false;
  2408. }
  2409. if (!ascendente) {
  2410. image = [UIImage imageNamed:image_MenuOrdinamentoAscendente];
  2411. titoloNuovo = NSLocalizedString(@"_sort_ascending_", nil);
  2412. titoloAttuale = NSLocalizedString(@"_current_sort_descending_", nil);
  2413. nuovoAscendente = true;
  2414. }
  2415. if (app.ascendenteItem == nil) app.ascendenteItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2416. subtitle:titoloAttuale
  2417. image:image
  2418. highlightedImage:nil
  2419. action:^(REMenuItem *item) {
  2420. [self ascendingTable:nuovoAscendente];
  2421. }];
  2422. else app.ascendenteItem = [app.ascendenteItem initWithTitle:titoloNuovo
  2423. subtitle:titoloAttuale
  2424. image:image
  2425. highlightedImage:nil
  2426. action:^(REMenuItem *item) {
  2427. [self ascendingTable:nuovoAscendente];
  2428. }];
  2429. // ITEM ALPHABETIC -----------------------------------------------------------------------------------------------------
  2430. if ([groupBy isEqualToString:@"alphabetic"]) { titoloNuovo = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  2431. else { titoloNuovo = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  2432. if (app.alphabeticItem == nil) app.alphabeticItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2433. subtitle:@""
  2434. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2435. highlightedImage:nil
  2436. action:^(REMenuItem *item) {
  2437. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2438. else [self tableGroupBy:@"alphabetic"];
  2439. }];
  2440. else app.alphabeticItem = [app.alphabeticItem initWithTitle:titoloNuovo
  2441. subtitle:@""
  2442. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2443. highlightedImage:nil
  2444. action:^(REMenuItem *item) {
  2445. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2446. else [self tableGroupBy:@"alphabetic"];
  2447. }];
  2448. // ITEM TYPEFILE -------------------------------------------------------------------------------------------------------
  2449. if ([groupBy isEqualToString:@"typefile"]) { titoloNuovo = NSLocalizedString(@"_group_typefile_yes_", nil); }
  2450. else { titoloNuovo = NSLocalizedString(@"_group_typefile_no_", nil); }
  2451. if (app.typefileItem == nil) app.typefileItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2452. subtitle:@""
  2453. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2454. highlightedImage:nil
  2455. action:^(REMenuItem *item) {
  2456. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2457. else [self tableGroupBy:@"typefile"];
  2458. }];
  2459. else app.typefileItem = [app.typefileItem initWithTitle:titoloNuovo
  2460. subtitle:@""
  2461. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2462. highlightedImage:nil
  2463. action:^(REMenuItem *item) {
  2464. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2465. else [self tableGroupBy:@"typefile"];
  2466. }];
  2467. // ITEM DATE -------------------------------------------------------------------------------------------------------
  2468. if ([groupBy isEqualToString:@"date"]) { titoloNuovo = NSLocalizedString(@"_group_date_yes_", nil); }
  2469. else { titoloNuovo = NSLocalizedString(@"_group_date_no_", nil); }
  2470. if (app.dateItem == nil) app.dateItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2471. subtitle:@""
  2472. image:[UIImage imageNamed:image_MenuGroupByDate]
  2473. highlightedImage:nil
  2474. action:^(REMenuItem *item) {
  2475. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2476. else [self tableGroupBy:@"date"];
  2477. }];
  2478. else app.dateItem = [app.dateItem initWithTitle:titoloNuovo
  2479. subtitle:@""
  2480. image:[UIImage imageNamed:image_MenuGroupByDate]
  2481. highlightedImage:nil
  2482. action:^(REMenuItem *item) {
  2483. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2484. else [self tableGroupBy:@"date"];
  2485. }];
  2486. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  2487. if ([CCUtility getDirectoryOnTop]) { titoloNuovo = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  2488. else { titoloNuovo = NSLocalizedString(@"_directory_on_top_no_", nil); }
  2489. if (app.directoryOnTopItem == nil) app.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2490. subtitle:@""
  2491. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2492. highlightedImage:nil
  2493. action:^(REMenuItem *item) {
  2494. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2495. else [self directoryOnTop:YES];
  2496. }];
  2497. else app.directoryOnTopItem = [app.directoryOnTopItem initWithTitle:titoloNuovo
  2498. subtitle:@""
  2499. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2500. highlightedImage:nil
  2501. action:^(REMenuItem *item) {
  2502. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2503. else [self directoryOnTop:YES];
  2504. }];
  2505. // REMENU --------------------------------------------------------------------------------------------------------------
  2506. if (app.reMainMenu == nil) app.reMainMenu = [[REMenu alloc] initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2507. else app.reMainMenu = [app.reMainMenu initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2508. app.reMainMenu.imageOffset = CGSizeMake(5, -1);
  2509. app.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2510. app.reMainMenu.imageOffset = CGSizeMake(0, 0);
  2511. app.reMainMenu.waitUntilAnimationIsComplete = NO;
  2512. app.reMainMenu.separatorHeight = 0.5;
  2513. app.reMainMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2514. app.reMainMenu.backgroundColor = COLOR_BACKGROUND_MENU;
  2515. app.reMainMenu.textColor = [UIColor blackColor];
  2516. app.reMainMenu.textAlignment = NSTextAlignmentLeft;
  2517. app.reMainMenu.textShadowColor = nil;
  2518. app.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  2519. app.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  2520. app.reMainMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2521. app.reMainMenu.highlightedSeparatorColor = nil;
  2522. app.reMainMenu.highlightedTextColor = [UIColor blackColor];
  2523. app.reMainMenu.highlightedTextShadowColor = nil;
  2524. app.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2525. app.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  2526. app.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2527. app.reMainMenu.subtitleTextShadowColor = nil;
  2528. app.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2529. app.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2530. app.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2531. app.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2532. app.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  2533. app.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2534. app.reMainMenu.borderWidth = 0.3;
  2535. app.reMainMenu.borderColor = [UIColor lightGrayColor];
  2536. app.reMainMenu.animationDuration = 0.2;
  2537. app.reMainMenu.closeAnimationDuration = 0.2;
  2538. app.reMainMenu.bounce = NO;
  2539. [app.reMainMenu setClosePreparationBlock:^{
  2540. // Backgroun reMenu (Gesture)
  2541. [_reMenuBackgroundView removeFromSuperview];
  2542. [app.controlCenter disableSingleFingerTap];
  2543. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2544. }];
  2545. }
  2546. - (void)toggleReMainMenu
  2547. {
  2548. if (app.reMainMenu.isOpen) {
  2549. [app.reMainMenu close];
  2550. } else {
  2551. [app.reMainMenu showFromNavigationController:self.navigationController];
  2552. // Backgroun reMenu & (Gesture)
  2553. [self createReMenuBackgroundView:app.reMainMenu];
  2554. [app.controlCenter enableSingleFingerTap:@selector(toggleReMainMenu) target:self];
  2555. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  2556. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2557. }
  2558. }
  2559. - (void)createReSelectMenu
  2560. {
  2561. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  2562. if (app.deleteItem == nil) app.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2563. subtitle:@""
  2564. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2565. highlightedImage:nil
  2566. action:^(REMenuItem *item) {
  2567. [self deleteSelectionFile];
  2568. }];
  2569. else app.deleteItem = [app.deleteItem initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2570. subtitle:@""
  2571. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2572. highlightedImage:nil
  2573. action:^(REMenuItem *item) {
  2574. [self deleteSelectionFile];
  2575. }];
  2576. // ITEM MOVE ------------------------------------------------------------------------------------------------------
  2577. if (app.moveItem == nil) app.moveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2578. subtitle:@""
  2579. image:[UIImage imageNamed:image_moveSelectedFiles]
  2580. highlightedImage:nil
  2581. action:^(REMenuItem *item) {
  2582. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2583. }];
  2584. else app.moveItem = [app.moveItem initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2585. subtitle:@""
  2586. image:[UIImage imageNamed:image_moveSelectedFiles]
  2587. highlightedImage:nil
  2588. action:^(REMenuItem *item) {
  2589. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2590. }];
  2591. if (app.isCryptoCloudMode) {
  2592. // ITEM ENCRYPTED ------------------------------------------------------------------------------------------------------
  2593. if (app.encryptItem == nil) app.encryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2594. subtitle:@""
  2595. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2596. highlightedImage:nil
  2597. action:^(REMenuItem *item) {
  2598. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil];
  2599. }];
  2600. else app.encryptItem = [app.encryptItem initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2601. subtitle:@""
  2602. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2603. highlightedImage:nil
  2604. action:^(REMenuItem *item) {
  2605. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil];
  2606. }];
  2607. // ITEM DECRYPTED ----------------------------------------------------------------------------------------------------
  2608. if (app.decryptItem == nil) app.decryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2609. subtitle:@""
  2610. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2611. highlightedImage:nil
  2612. action:^(REMenuItem *item) {
  2613. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil];
  2614. }];
  2615. else app.decryptItem = [app.decryptItem initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2616. subtitle:@""
  2617. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2618. highlightedImage:nil
  2619. action:^(REMenuItem *item) {
  2620. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil];
  2621. }];
  2622. }
  2623. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  2624. if (app.downloadItem == nil) app.downloadItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2625. subtitle:@""
  2626. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2627. highlightedImage:nil
  2628. action:^(REMenuItem *item) {
  2629. [self downloadSelectedFiles];
  2630. }];
  2631. else app.downloadItem = [app.downloadItem initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2632. subtitle:@""
  2633. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2634. highlightedImage:nil
  2635. action:^(REMenuItem *item) {
  2636. [self downloadSelectedFiles];
  2637. }];
  2638. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  2639. if (app.saveItem == nil) app.saveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2640. subtitle:@""
  2641. image:[UIImage imageNamed:image_saveSelectedFiles]
  2642. highlightedImage:nil
  2643. action:^(REMenuItem *item) {
  2644. [self saveSelectedFiles];
  2645. }];
  2646. else app.saveItem = [app.saveItem initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2647. subtitle:@""
  2648. image:[UIImage imageNamed:image_saveSelectedFiles]
  2649. highlightedImage:nil
  2650. action:^(REMenuItem *item) {
  2651. [self saveSelectedFiles];
  2652. }];
  2653. // REMENU --------------------------------------------------------------------------------------------------------------
  2654. if (app.isCryptoCloudMode) {
  2655. if (app.reSelectMenu == nil)
  2656. app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2657. else
  2658. app.reSelectMenu = [app.reSelectMenu initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2659. } else {
  2660. if (app.reSelectMenu == nil)
  2661. app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.downloadItem, app.saveItem]];
  2662. else
  2663. app.reSelectMenu = [app.reSelectMenu initWithItems:@[app.deleteItem,app.moveItem, app.downloadItem, app.saveItem]];
  2664. }
  2665. app.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  2666. app.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2667. app.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  2668. app.reSelectMenu.waitUntilAnimationIsComplete = NO;
  2669. app.reSelectMenu.separatorHeight = 0.5;
  2670. app.reSelectMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2671. app.reSelectMenu.backgroundColor = COLOR_BACKGROUND_MENU;
  2672. app.reSelectMenu.textColor = [UIColor blackColor];
  2673. app.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  2674. app.reSelectMenu.textShadowColor = nil;
  2675. app.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  2676. app.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  2677. app.reSelectMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2678. app.reSelectMenu.highlightedSeparatorColor = nil;
  2679. app.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  2680. app.reSelectMenu.highlightedTextShadowColor = nil;
  2681. app.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2682. app.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  2683. app.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2684. app.reSelectMenu.subtitleTextShadowColor = nil;
  2685. app.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2686. app.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2687. app.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2688. app.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2689. app.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  2690. app.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2691. app.reSelectMenu.borderWidth = 0.3;
  2692. app.reSelectMenu.borderColor = [UIColor lightGrayColor];
  2693. app.reSelectMenu.closeAnimationDuration = 0.2;
  2694. app.reSelectMenu.animationDuration = 0.2;
  2695. app.reSelectMenu.bounce = NO;
  2696. [app.reSelectMenu setClosePreparationBlock:^{
  2697. // Backgroun reMenu (Gesture)
  2698. [_reMenuBackgroundView removeFromSuperview];
  2699. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2700. }];
  2701. }
  2702. - (void)toggleReSelectMenu
  2703. {
  2704. if (app.reSelectMenu.isOpen) {
  2705. [app.reSelectMenu close];
  2706. } else {
  2707. [app.reSelectMenu showFromNavigationController:self.navigationController];
  2708. // Backgroun reMenu & (Gesture)
  2709. [self createReMenuBackgroundView:app.reSelectMenu];
  2710. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  2711. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2712. }
  2713. }
  2714. #pragma --------------------------------------------------------------------------------------------
  2715. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  2716. #pragma --------------------------------------------------------------------------------------------
  2717. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  2718. {
  2719. if (recognizer.state == UIGestureRecognizerStateBegan) {
  2720. UITableView *tableView = (UITableView*)self.view;
  2721. CGPoint touchPoint = [recognizer locationInView:self.view];
  2722. NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:touchPoint];
  2723. if (indexPath)
  2724. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  2725. else
  2726. _metadata = nil;
  2727. [self becomeFirstResponder];
  2728. UIMenuController *menuController = [UIMenuController sharedMenuController];
  2729. UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
  2730. UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
  2731. UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
  2732. UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
  2733. UIMenuItem *pasteFileEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_encrypted_", nil) action:@selector(pasteFileEncrypted:)];
  2734. UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
  2735. UIMenuItem *pasteFilesEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_encrypted_", nil) action:@selector(pasteFilesEncrypted:)];
  2736. if (app.isCryptoCloudMode)
  2737. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, pasteFileEncryptedItem, pasteFilesEncryptedItem, nil]];
  2738. else
  2739. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, nil]];
  2740. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:tableView];
  2741. [menuController setMenuVisible:YES animated:YES];
  2742. }
  2743. }
  2744. - (BOOL)canBecomeFirstResponder
  2745. {
  2746. return YES;
  2747. }
  2748. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  2749. {
  2750. // For copy file, copy files, Open in ... :
  2751. //
  2752. // NO Directory
  2753. // NO Error Passcode
  2754. // NO In Session mode (download/upload)
  2755. // NO Template
  2756. if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
  2757. if (_isSelectedMode == NO && _metadata && !_metadata.directory && !_metadata.errorPasscode && [_metadata.session length] == 0 && ![_metadata.typeFile isEqualToString: k_metadataTypeFile_template]) {
  2758. // NO Cryptated with Title lenght = 0
  2759. if (!_metadata.cryptated || (_metadata.cryptated && _metadata.title.length > 0))
  2760. return YES;
  2761. }
  2762. return NO;
  2763. }
  2764. if (@selector(copyFiles:) == action) {
  2765. if (_isSelectedMode) {
  2766. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2767. for (CCMetadata *metadata in selectedMetadatas) {
  2768. if (!metadata.directory && !metadata.errorPasscode && metadata.session.length == 0 && ![metadata.typeFile isEqualToString: k_metadataTypeFile_template]) {
  2769. // NO Cryptated with Title lenght = 0
  2770. if (!metadata.cryptated || (metadata.cryptated && metadata.title.length > 0))
  2771. return YES;
  2772. }
  2773. }
  2774. }
  2775. return NO;
  2776. }
  2777. if (@selector(pasteFile:) == action || @selector(pasteFileEncrypted:) == action) {
  2778. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2779. NSArray *items = [pasteboard items];
  2780. if ([items count] == 1) {
  2781. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2782. NSDictionary *dic = [items objectAtIndex:0];
  2783. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2784. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2785. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2786. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2787. if (directoryUser) {
  2788. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2789. return YES;
  2790. }
  2791. return NO;
  2792. } else return NO;
  2793. }
  2794. if (@selector(pasteFiles:) == action || @selector(pasteFilesEncrypted:) == action) {
  2795. BOOL isValid = NO;
  2796. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2797. NSArray *items = [pasteboard items];
  2798. if ([items count] <= 1) return NO;
  2799. for (NSDictionary *dic in items) {
  2800. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2801. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2802. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2803. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2804. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2805. if (directoryUser) {
  2806. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2807. isValid = YES;
  2808. }
  2809. }
  2810. return isValid;
  2811. }
  2812. return NO;
  2813. }
  2814. /************************************ COPY ************************************/
  2815. - (void)copyFile:(id)sender
  2816. {
  2817. // Remove all item
  2818. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2819. pasteboard.items = [[NSArray alloc] init];
  2820. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser,_metadata.fileID]]) {
  2821. [self copyFileToPasteboard:_metadata];
  2822. } else {
  2823. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  2824. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2825. }
  2826. }
  2827. - (void)copyFiles:(id)sender
  2828. {
  2829. // Remove all item
  2830. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2831. pasteboard.items = [[NSArray alloc] init];
  2832. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2833. for (CCMetadata *metadata in selectedMetadatas) {
  2834. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]]) {
  2835. [self copyFileToPasteboard:metadata];
  2836. } else {
  2837. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  2838. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2839. }
  2840. }
  2841. [self tableViewSelect:NO];
  2842. }
  2843. - (void)copyFileToPasteboard:(CCMetadata *)metadata
  2844. {
  2845. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2846. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  2847. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2848. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata], @"it.twsweb.Crypto-Cloud.CCMetadata",nil];
  2849. [items addObject:item];
  2850. [pasteboard setItems:items];
  2851. }
  2852. /************************************ OPEN IN ... ************************************/
  2853. - (void)openinFile:(id)sender
  2854. {
  2855. [self openIn:_metadata];
  2856. }
  2857. /************************************ PASTE ************************************/
  2858. - (void)pasteFile:(id)sender
  2859. {
  2860. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2861. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2862. }
  2863. - (void)pasteFileEncrypted:(id)sender
  2864. {
  2865. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2866. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2867. }
  2868. - (void)pasteFiles:(id)sender
  2869. {
  2870. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2871. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2872. }
  2873. - (void)pasteFilesEncrypted:(id)sender
  2874. {
  2875. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2876. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2877. }
  2878. - (void)uploadFilePasteArray:(NSArray *)items cryptated:(BOOL)cryptated
  2879. {
  2880. for (NSDictionary *dic in items) {
  2881. // key : it.twsweb.Crypto-Cloud.CCMetadata
  2882. // Value : (NSData) metadata
  2883. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2884. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2885. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2886. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2887. if (directoryUser) {
  2888. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]]) {
  2889. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint]];
  2890. [[CCNetworking sharedNetworking] uploadFile:metadata.fileNamePrint serverUrl:_serverUrl cryptated:cryptated onlyPlist:NO session:k_upload_session taskStatus:k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  2891. }
  2892. }
  2893. }
  2894. }
  2895. #pragma --------------------------------------------------------------------------------------------
  2896. #pragma mark ===== Lock Passcode =====
  2897. #pragma --------------------------------------------------------------------------------------------
  2898. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  2899. {
  2900. return _failedAttempts;
  2901. }
  2902. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  2903. {
  2904. return _lockUntilDate;
  2905. }
  2906. - (void)passcodeViewCloseButtonPressed:(id)sender
  2907. {
  2908. [self dismissViewControllerAnimated:YES completion:nil];
  2909. }
  2910. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  2911. {
  2912. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  2913. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  2914. _lockUntilDate = nil;
  2915. _failedAttempts = 0;
  2916. aResultHandler(YES);
  2917. } else aResultHandler(NO);
  2918. } else aResultHandler(YES);
  2919. }
  2920. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  2921. {
  2922. [aViewController dismissViewControllerAnimated:YES completion:nil];
  2923. switch (aViewController.type) {
  2924. case BKPasscodeViewControllerCheckPasscodeType: {
  2925. if (aViewController.fromType == CCBKPasscodeFromPasscode) {
  2926. CCCrypto *crypto = [[CCCrypto alloc] init];
  2927. // verifichiamo se il passcode è corretto per il seguente file -> UUID
  2928. if ([crypto verifyPasscode:aPasscode uuid:_metadata.uuid text:_metadata.title]) {
  2929. // scriviamo il passcode
  2930. [CCUtility setKeyChainPasscodeForUUID:_metadata.uuid conPasscode:aPasscode];
  2931. [self readFolderWithForced:YES serverUrl:_serverUrl];
  2932. } else {
  2933. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_error_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  2934. [alertView show];
  2935. }
  2936. }
  2937. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  2938. // possiamo procedere alla prossima directory
  2939. [self performSegueDirectoryWithControlPasscode:false];
  2940. // avviamo la sessione Passcode Lock con now
  2941. app.sessionePasscodeLock = [NSDate date];
  2942. }
  2943. // disattivazione lock cartella
  2944. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  2945. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  2946. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  2947. if ([CCCoreData setDirectoryUnLock:lockServerUrl activeAccount:app.activeAccount] == NO) {
  2948. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  2949. }
  2950. [self.tableView reloadData];
  2951. }
  2952. }
  2953. break;
  2954. default:
  2955. break;
  2956. }
  2957. }
  2958. - (void)comandoLockPassword
  2959. {
  2960. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  2961. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  2962. // se non è abilitato il Lock Passcode esci
  2963. if ([[CCUtility getBlockCode] length] == 0) {
  2964. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  2965. [alertView show];
  2966. return;
  2967. }
  2968. // se è richiesta la disattivazione si chiede la password
  2969. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  2970. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2971. viewController.delegate = self;
  2972. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  2973. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2974. viewController.inputViewTitlePassword = YES;
  2975. if ([CCUtility getSimplyBlockCode]) {
  2976. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2977. viewController.passcodeInputView.maximumLength = 6;
  2978. } else {
  2979. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2980. viewController.passcodeInputView.maximumLength = 64;
  2981. }
  2982. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  2983. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  2984. viewController.touchIDManager = touchIDManager;
  2985. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  2986. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  2987. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  2988. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  2989. [self presentViewController:navigationController animated:YES completion:nil];
  2990. return;
  2991. }
  2992. // ---------------- ACTIVATE PASSWORD
  2993. if([CCCoreData setDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  2994. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  2995. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2996. } else {
  2997. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  2998. }
  2999. }
  3000. #pragma mark -
  3001. #pragma --------------------------------------------------------------------------------------------
  3002. #pragma mark ===== Swipe Tablet -> menu =====
  3003. #pragma --------------------------------------------------------------------------------------------
  3004. // more
  3005. - (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  3006. return NSLocalizedString(@"_more_", nil);
  3007. }
  3008. - (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
  3009. {
  3010. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3011. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  3012. NSString *titoloCriptaDecripta, *titoloOffline, *titoloLock, *titleOfflineFolder, *titleFavorite;
  3013. BOOL offlineFolder = NO;
  3014. if (_metadata.cryptated) titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_decrypt_", nil)];
  3015. else titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_encrypt_", nil)];
  3016. if ([CCCoreData isOfflineLocalFileID:_metadata.fileID activeAccount:app.activeAccount]) titoloOffline = [NSString stringWithFormat:NSLocalizedString(@"_remove_offline_", nil)];
  3017. else titoloOffline = [NSString stringWithFormat:NSLocalizedString(@"_add_offline_", nil)];
  3018. NSString *offlineServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3019. if (_metadata.directory && [CCCoreData isOfflineDirectoryServerUrl:offlineServerUrl activeAccount:app.activeAccount]) {
  3020. titleOfflineFolder = [NSString stringWithFormat:NSLocalizedString(@"_remove_offline_", nil)];
  3021. offlineFolder = YES;
  3022. } else titleOfflineFolder = [NSString stringWithFormat:NSLocalizedString(@"_add_offline_", nil)];
  3023. if (_metadata.favorite) {
  3024. titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_remove_favorites_", nil)];
  3025. } else {
  3026. titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_add_favorites_", nil)];
  3027. }
  3028. if (_metadata.directory) {
  3029. // calcolo lockServerUrl
  3030. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3031. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  3032. else titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  3033. }
  3034. /******************************************* AHKActionSheet *******************************************/
  3035. UIImage *iconHeader;
  3036. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  3037. actionSheet.animationDuration = 0.2;
  3038. actionSheet.blurRadius = 0.0f;
  3039. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  3040. actionSheet.buttonHeight = 50.0;
  3041. actionSheet.cancelButtonHeight = 50.0f;
  3042. actionSheet.separatorHeight = 5.0f;
  3043. actionSheet.automaticallyTintButtonImages = @(NO);
  3044. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_CRYPTOCLOUD };
  3045. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  3046. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  3047. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  3048. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  3049. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  3050. /******************************************* DIRECTORY *******************************************/
  3051. if (_metadata.directory) {
  3052. UIImage *iconHeader;
  3053. BOOL lockDirectory = NO;
  3054. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3055. NSString *upDir = [CCUtility deletingLastPathComponentFromServerUrl:dirServerUrl];
  3056. NSString *homeDir = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
  3057. // Directory bloccata ?
  3058. if ([CCCoreData isDirectoryLock:dirServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3059. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3060. NSString *cameraUploadFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  3061. NSString *cameraUploadFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  3062. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3063. image: iconHeader
  3064. backgroundColor: COLOR_BACKGROUND_MENU
  3065. height: 50.0
  3066. type: AHKActionSheetButtonTypeDisabled
  3067. handler: nil
  3068. ];
  3069. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3070. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3071. image:[UIImage imageNamed:image_actionSheetRename]
  3072. backgroundColor:[UIColor whiteColor]
  3073. height: 50.0
  3074. type:AHKActionSheetButtonTypeDefault
  3075. handler:^(AHKActionSheet *as) {
  3076. // close swipe
  3077. [self setEditing:NO animated:YES];
  3078. //chiediamo il nome del file
  3079. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3080. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3081. alertView.tag = alertRename;
  3082. UITextField *textField = [alertView textFieldAtIndex:0];
  3083. textField.text = _metadata.fileNamePrint;
  3084. [alertView show];
  3085. }];
  3086. }
  3087. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3088. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3089. image:[UIImage imageNamed:image_actionSheetMove]
  3090. backgroundColor:[UIColor whiteColor]
  3091. height: 50.0
  3092. type:AHKActionSheetButtonTypeDefault
  3093. handler:^(AHKActionSheet *as) {
  3094. // close swipe
  3095. [self setEditing:NO animated:YES];
  3096. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3097. }];
  3098. }
  3099. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory && app.isCryptoCloudMode) {
  3100. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3101. image:[UIImage imageNamed:image_actionSheetCrypto]
  3102. backgroundColor:[UIColor whiteColor]
  3103. height: 50.0
  3104. type:AHKActionSheetButtonTypeEncrypted
  3105. handler:^(AHKActionSheet *as) {
  3106. // close swipe
  3107. [self setEditing:NO animated:YES];
  3108. [self performSelector:@selector(encyptedDecryptedFolder) withObject:nil];
  3109. }];
  3110. }
  3111. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES)) {
  3112. [actionSheet addButtonWithTitle:titoloLock
  3113. image:[UIImage imageNamed:image_actionSheetLock]
  3114. backgroundColor:[UIColor whiteColor]
  3115. height: 50.0
  3116. type:AHKActionSheetButtonTypeEncrypted
  3117. handler:^(AHKActionSheet *as) {
  3118. // close swipe
  3119. [self setEditing:NO animated:YES];
  3120. [self performSelector:@selector(comandoLockPassword) withObject:nil];
  3121. }];
  3122. }
  3123. if (_metadata.cryptated == NO && app.hasServerShareSupport && !lockDirectory) {
  3124. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3125. image:[UIImage imageNamed:image_actionSheetShare]
  3126. backgroundColor:[UIColor whiteColor]
  3127. height: 50.0
  3128. type:AHKActionSheetButtonTypeDefault
  3129. handler:^(AHKActionSheet *as) {
  3130. // close swipe
  3131. [self setEditing:NO animated:YES];
  3132. [self openWindowShare:_metadata];
  3133. }];
  3134. }
  3135. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES) && _metadata.cryptated == NO) {
  3136. [actionSheet addButtonWithTitle:NSLocalizedString(@"_folder_automatic_upload_", nil)
  3137. image:[UIImage imageNamed:image_folderphotocamera]
  3138. backgroundColor:[UIColor whiteColor]
  3139. height: 50.0
  3140. type:AHKActionSheetButtonTypeDefault
  3141. handler:^(AHKActionSheet *as) {
  3142. // close swipe
  3143. [self setEditing:NO animated:YES];
  3144. // Settings new folder Automatatic upload
  3145. NSString *oldPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  3146. [CCCoreData setCameraUploadFolderName:_metadata.fileName activeAccount:app.activeAccount];
  3147. [CCCoreData setCameraUploadFolderPath:serverUrl activeUrl:app.activeUrl activeAccount:app.activeAccount];
  3148. [CCCoreData clearDateReadDirectory:oldPath activeAccount:app.activeAccount];
  3149. if (app.activeAccount.length > 0 && app.activePhotosCameraUpload)
  3150. [app.activePhotosCameraUpload reloadDatasourceForced];
  3151. [self readFolderWithForced:YES serverUrl:serverUrl];
  3152. }];
  3153. }
  3154. if (!lockDirectory && ([upDir isEqualToString:homeDir] || ![CCCoreData isOfflineDirectoryServerUrl:upDir activeAccount:app.activeAccount]) && !_metadata.cryptated) {
  3155. [actionSheet addButtonWithTitle:titleOfflineFolder
  3156. image:[UIImage imageNamed:image_actionSheetOffline]
  3157. backgroundColor:[UIColor whiteColor]
  3158. height: 50.0
  3159. type:AHKActionSheetButtonTypeDefault
  3160. handler:^(AHKActionSheet *as) {
  3161. // close swipe
  3162. [self setEditing:NO animated:YES];
  3163. if (offlineFolder == NO) {
  3164. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"",nil) message:NSLocalizedString(@"_offline_folder_confirm_",nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3165. alertView.tag = alertOfflineFolder;
  3166. [alertView show];
  3167. } else {
  3168. // remove tag offline for all folder/subfolder/file
  3169. NSArray *directories = [CCCoreData getOfflineDirectoryActiveAccount:app.activeAccount];
  3170. for (TableDirectory *directory in directories)
  3171. if ([directory.serverUrl containsString:dirServerUrl]) {
  3172. [CCCoreData setOfflineDirectoryServerUrl:directory.serverUrl offline:NO activeAccount:app.activeAccount];
  3173. [CCCoreData removeOfflineAllFileFromServerUrl:directory.serverUrl activeAccount:app.activeAccount];
  3174. }
  3175. [self performSelector:@selector(reloadDatasource) withObject:nil];
  3176. }
  3177. }];
  3178. }
  3179. if (!lockDirectory && !_metadata.cryptated) {
  3180. [actionSheet addButtonWithTitle:titleFavorite
  3181. image:[UIImage imageNamed:image_actionSheetFavorite]
  3182. backgroundColor:[UIColor whiteColor]
  3183. height: 50.0
  3184. type:AHKActionSheetButtonTypeDefault
  3185. handler:^(AHKActionSheet *as) {
  3186. // close swipe
  3187. [self setEditing:NO animated:YES];
  3188. if (_metadata.favorite)
  3189. [self removeFavorite:_metadata];
  3190. else
  3191. [self addFavorite:_metadata];
  3192. }];
  3193. }
  3194. [actionSheet show];
  3195. }
  3196. /******************************************* FILE *******************************************/
  3197. if ([_metadata.type isEqualToString: k_metadataType_file] && !_metadata.directory) {
  3198. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3199. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]])
  3200. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]];
  3201. else
  3202. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3203. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3204. image: iconHeader
  3205. backgroundColor: COLOR_BACKGROUND_MENU
  3206. height: 50.0
  3207. type: AHKActionSheetButtonTypeDisabled
  3208. handler: nil
  3209. ];
  3210. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3211. image:[UIImage imageNamed:image_actionSheetRename]
  3212. backgroundColor:[UIColor whiteColor]
  3213. height: 50.0
  3214. type:AHKActionSheetButtonTypeDefault
  3215. handler:^(AHKActionSheet *as) {
  3216. // close swipe
  3217. [self setEditing:NO animated:YES];
  3218. //chiediamo il nome del file
  3219. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3220. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3221. alertView.tag = alertRename;
  3222. UITextField *textField = [alertView textFieldAtIndex:0];
  3223. textField.text = _metadata.fileNamePrint;
  3224. [alertView show];
  3225. }];
  3226. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3227. image:[UIImage imageNamed:image_actionSheetMove]
  3228. backgroundColor:[UIColor whiteColor]
  3229. height: 50.0
  3230. type:AHKActionSheetButtonTypeDefault
  3231. handler:^(AHKActionSheet *as) {
  3232. // close swipe
  3233. [self setEditing:NO animated:YES];
  3234. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3235. }];
  3236. [actionSheet addButtonWithTitle:NSLocalizedString(@"_reload_", nil)
  3237. image:[UIImage imageNamed:image_actionSheetReload]
  3238. backgroundColor:[UIColor whiteColor]
  3239. height: 50.0
  3240. type:AHKActionSheetButtonTypeDefault
  3241. handler:^(AHKActionSheet *as) {
  3242. // close swipe
  3243. [self setEditing:NO animated:YES];
  3244. [self performSelector:@selector(reloadFile:) withObject:_metadata];
  3245. }];
  3246. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  3247. image:[UIImage imageNamed:image_actionSheetOpenIn]
  3248. backgroundColor:[UIColor whiteColor]
  3249. height: 50.0
  3250. type:AHKActionSheetButtonTypeDefault
  3251. handler:^(AHKActionSheet *as) {
  3252. // close swipe
  3253. [self setEditing:NO animated:YES];
  3254. [self performSelector:@selector(openIn:) withObject:_metadata];
  3255. }];
  3256. if (_metadata.cryptated == NO && app.hasServerShareSupport) {
  3257. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3258. image:[UIImage imageNamed:image_actionSheetShare]
  3259. backgroundColor:[UIColor whiteColor]
  3260. height: 50.0
  3261. type:AHKActionSheetButtonTypeDefault
  3262. handler:^(AHKActionSheet *as) {
  3263. // close swipe
  3264. [self setEditing:NO animated:YES];
  3265. [self openWindowShare:_metadata];
  3266. }];
  3267. }
  3268. if (app.isCryptoCloudMode) {
  3269. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3270. image:[UIImage imageNamed:image_actionSheetCrypto]
  3271. backgroundColor:[UIColor whiteColor]
  3272. height: 50.0
  3273. type:AHKActionSheetButtonTypeEncrypted
  3274. handler:^(AHKActionSheet *as) {
  3275. // close swipe
  3276. [self setEditing:NO animated:YES];
  3277. [self performSelector:@selector(cmdEncryptedDecryptedFile) withObject:nil];
  3278. }];
  3279. }
  3280. if (!_metadata.cryptated) {
  3281. [actionSheet addButtonWithTitle:titoloOffline
  3282. image:[UIImage imageNamed:image_actionSheetOffline]
  3283. backgroundColor:[UIColor whiteColor]
  3284. height: 50.0
  3285. type:AHKActionSheetButtonTypeDefault
  3286. handler:^(AHKActionSheet *as) {
  3287. // close swipe
  3288. [self setEditing:NO animated:YES];
  3289. if ([CCCoreData isOfflineLocalFileID:_metadata.fileID activeAccount:app.activeAccount]) {
  3290. [self removeOffline:_metadata];
  3291. } else {
  3292. [self addOffline:_metadata];
  3293. }
  3294. }];
  3295. }
  3296. if (!_metadata.cryptated) {
  3297. [actionSheet addButtonWithTitle:titleFavorite
  3298. image:[UIImage imageNamed:image_actionSheetFavorite]
  3299. backgroundColor:[UIColor whiteColor]
  3300. height: 50.0
  3301. type:AHKActionSheetButtonTypeDefault
  3302. handler:^(AHKActionSheet *as) {
  3303. // close swipe
  3304. [self setEditing:NO animated:YES];
  3305. if (_metadata.favorite)
  3306. [self removeFavorite:_metadata];
  3307. else
  3308. [self addFavorite:_metadata];
  3309. }];
  3310. }
  3311. [actionSheet addButtonWithTitle:NSLocalizedString(@"_add_local_", nil)
  3312. image:[UIImage imageNamed:image_actionSheetLocal]
  3313. backgroundColor:[UIColor whiteColor]
  3314. height: 50.0
  3315. type:AHKActionSheetButtonTypeDefault
  3316. handler:^(AHKActionSheet *as) {
  3317. // close swipe
  3318. [self setEditing:NO animated:YES];
  3319. [self performSelector:@selector(addLocal:) withObject:_metadata];
  3320. }];
  3321. [actionSheet show];
  3322. }
  3323. /******************************************* TEMPLATE *******************************************/
  3324. if ([_metadata.type isEqualToString: k_metadataType_template]) {
  3325. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3326. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3327. image: iconHeader
  3328. backgroundColor: COLOR_BACKGROUND_MENU
  3329. height: 50.0
  3330. type: AHKActionSheetButtonTypeDisabled
  3331. handler: nil
  3332. ];
  3333. if ([_metadata.model isEqualToString:@"note"]) {
  3334. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3335. image:[UIImage imageNamed:image_actionSheetRename]
  3336. backgroundColor:[UIColor whiteColor]
  3337. height: 50.0
  3338. type:AHKActionSheetButtonTypeDefault
  3339. handler:^(AHKActionSheet *as) {
  3340. // close swipe
  3341. [self setEditing:NO animated:YES];
  3342. //chiediamo il nome del file
  3343. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3344. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3345. alertView.tag = alertRename;
  3346. UITextField *textField = [alertView textFieldAtIndex:0];
  3347. textField.text = _metadata.fileNamePrint;
  3348. [alertView show];
  3349. }];
  3350. }
  3351. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3352. image:[UIImage imageNamed:image_actionSheetMove]
  3353. backgroundColor:[UIColor whiteColor]
  3354. height: 50.0
  3355. type:AHKActionSheetButtonTypeDefault
  3356. handler:^(AHKActionSheet *as) {
  3357. // close swipe
  3358. [self setEditing:NO animated:YES];
  3359. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3360. }];
  3361. [actionSheet show];
  3362. }
  3363. }
  3364. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  3365. {
  3366. return NSLocalizedString(@"_delete_", nil);
  3367. }
  3368. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  3369. {
  3370. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3371. if (metadata == nil || metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier >= 0 || metadata.sessionTaskIdentifier >= 0) return NO;
  3372. else return YES;
  3373. }
  3374. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  3375. {
  3376. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3377. if (metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier >= 0 || metadata.sessionTaskIdentifier >= 0) return UITableViewCellEditingStyleNone;
  3378. else return UITableViewCellEditingStyleDelete;
  3379. }
  3380. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  3381. {
  3382. BOOL lockDirectory = NO;
  3383. // Directory locked ?
  3384. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:[CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account] addFileName:_metadata.fileNameData];
  3385. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3386. if (lockDirectory && editingStyle == UITableViewCellEditingStyleDelete) {
  3387. [app messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  3388. return;
  3389. }
  3390. if (editingStyle == UITableViewCellEditingStyleDelete) {
  3391. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3392. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  3393. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  3394. style:UIAlertActionStyleDestructive
  3395. handler:^(UIAlertAction *action) {
  3396. [self performSelector:@selector(deleteFile) withObject:nil];
  3397. }]];
  3398. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  3399. style:UIAlertActionStyleCancel
  3400. handler:^(UIAlertAction *action) {
  3401. [alertController dismissViewControllerAnimated:YES completion:nil];
  3402. }]];
  3403. alertController.popoverPresentationController.sourceView = self.view;
  3404. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  3405. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  3406. [alertController.view layoutIfNeeded];
  3407. [self presentViewController:alertController animated:YES completion:nil];
  3408. }
  3409. }
  3410. #pragma --------------------------------------------------------------------------------------------
  3411. #pragma mark - ==== Datasource ====
  3412. #pragma --------------------------------------------------------------------------------------------
  3413. - (void)clearDateReadDataSource:(NSNotification *)notification
  3414. {
  3415. _dateReadDataSource = Nil;
  3416. [self reloadDatasource];
  3417. }
  3418. - (void)reloadDatasource
  3419. {
  3420. [self reloadDatasource:_serverUrl fileID:nil selector:nil];
  3421. }
  3422. - (void)reloadDatasource:(NSString *)serverUrl fileID:(NSString *)fileID selector:(NSString *)selector
  3423. {
  3424. // test
  3425. if (app.activeAccount.length == 0 || serverUrl.length == 0)
  3426. return;
  3427. // Search Mode
  3428. if(_isSearchMode) {
  3429. if ([selector length] == 0 || [selector isEqualToString:selectorSearch]) {
  3430. _sectionDataSource = [CCSection creataDataSourseSectionMetadata:_searchResultMetadatas listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
  3431. } else {
  3432. [self readFolderWithForced:NO serverUrl:serverUrl];
  3433. }
  3434. [self tableViewReload];
  3435. [self setTitleBackgroundTableView:nil];
  3436. [app updateApplicationIconBadgeNumber];
  3437. return;
  3438. }
  3439. // Reload -> Self se non siamo nella dir appropriata cercala e se è in memoria reindirizza il reload
  3440. if ([serverUrl isEqualToString:_serverUrl] == NO || _serverUrl == nil) {
  3441. if ([selector isEqualToString:selectorDownloadSynchronize]) {
  3442. [app.controlCenterTransfer reloadDatasource];
  3443. } else {
  3444. CCMain *main = [app.listMainVC objectForKey:serverUrl];
  3445. if (main) {
  3446. [main reloadDatasource];
  3447. } else {
  3448. [self tableViewReload];
  3449. [app.controlCenterTransfer reloadDatasource];
  3450. }
  3451. }
  3452. return;
  3453. }
  3454. // Offline folder ?
  3455. _isOfflineServerUrl = [CCCoreData isOfflineDirectoryServerUrl:_serverUrl activeAccount:app.activeAccount];
  3456. [app.controlCenterTransfer reloadDatasource];
  3457. // Settaggio variabili per le ottimizzazioni
  3458. _directoryGroupBy = [CCUtility getGroupBySettings];
  3459. _directoryOrder = [CCUtility getOrderSettings];
  3460. // Controllo data lettura Data Source
  3461. NSDate *dateDateRecordDirectory = [CCCoreData getDateReadDirectoryID:[CCCoreData getDirectoryIDFromServerUrl:_serverUrl activeAccount:app.activeAccount] activeAccount:app.activeAccount];
  3462. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  3463. NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
  3464. _dateReadDataSource = [NSDate date];
  3465. // Data Source
  3466. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount]] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  3467. _sectionDataSource = [CCSection creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
  3468. } else {
  3469. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
  3470. }
  3471. [self tableViewReload];
  3472. [self setTitleBackgroundTableView];
  3473. [app updateApplicationIconBadgeNumber];
  3474. }
  3475. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  3476. {
  3477. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  3478. if (selectedRows.count > 0) {
  3479. for (NSIndexPath *selectionIndex in selectedRows) {
  3480. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  3481. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3482. [metadatas addObject:metadata];
  3483. }
  3484. }
  3485. return metadatas;
  3486. }
  3487. - (CCMetadata *)getMetadataFromSectionDataSource:(NSIndexPath *)indexPath
  3488. {
  3489. NSInteger section = indexPath.section + 1;
  3490. NSInteger row = indexPath.row + 1;
  3491. NSInteger totSections =[_sectionDataSource.sections count] ;
  3492. if ((totSections < section) || (section > totSections)) {
  3493. NSLog(@"[LOG] %@", [NSString stringWithFormat:@"DEBUG [0] : error section, totSections = %lu - section = %lu", (long)totSections, (long)section]);
  3494. return nil;
  3495. }
  3496. id valueSection = [_sectionDataSource.sections objectAtIndex:indexPath.section];
  3497. NSArray *fileIDs = [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3498. if (fileIDs) {
  3499. NSInteger totRows =[fileIDs count] ;
  3500. if ((totRows < row) || (row > totRows)) {
  3501. NSLog(@"[LOG] %@", [NSString stringWithFormat:@"DEBUG [1] : error row, totRows = %lu - row = %lu", (long)totRows, (long)row]);
  3502. return nil;
  3503. }
  3504. } else {
  3505. NSLog(@"[LOG] DEBUG [2] : fileIDs is NIL");
  3506. return nil;
  3507. }
  3508. NSString *fileID = [fileIDs objectAtIndex:indexPath.row];
  3509. return [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3510. }
  3511. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  3512. {
  3513. NSInteger totSections =[_sectionDataSource.sections count] ;
  3514. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  3515. #if DEBUG
  3516. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:[NSString stringWithFormat:@"DEBUG [3] : error section, totSections = %lu - section = %lu", (long)totSections, (long)section] delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3517. [alertView show];
  3518. #endif
  3519. return nil;
  3520. }
  3521. id valueSection = [_sectionDataSource.sections objectAtIndex:section];
  3522. return [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3523. }
  3524. #pragma --------------------------------------------------------------------------------------------
  3525. #pragma mark - ==== Table ====
  3526. #pragma --------------------------------------------------------------------------------------------
  3527. - (void)tableViewSelect:(BOOL)edit
  3528. {
  3529. // chiudiamo eventuali swipe aperti
  3530. if (edit) [self.tableView setEditing:NO animated:NO];
  3531. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  3532. [self.tableView setEditing:edit animated:YES];
  3533. _isSelectedMode = edit;
  3534. if (edit)
  3535. [self setUINavigationBarSelected];
  3536. else
  3537. [self setUINavigationBarDefault];
  3538. [self setTitle];
  3539. }
  3540. - (void)tableViewReload
  3541. {
  3542. // ricordiamoci le row selezionate
  3543. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  3544. [self.tableView reloadData];
  3545. for (NSIndexPath *path in indexPaths)
  3546. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  3547. [self setTableViewFooter];
  3548. if (self.tableView.editing)
  3549. [self setTitle];
  3550. }
  3551. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  3552. {
  3553. return 60;
  3554. }
  3555. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  3556. {
  3557. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  3558. }
  3559. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  3560. {
  3561. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  3562. }
  3563. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  3564. {
  3565. NSArray *sections = [_sectionDataSource.sectionArrayRow allKeys];
  3566. NSString *sectionTitle = [sections objectAtIndex:section];
  3567. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  3568. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  3569. if ([_directoryGroupBy isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
  3570. return 20.f;
  3571. }
  3572. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  3573. {
  3574. float shift;
  3575. UIVisualEffectView *visualEffectView;
  3576. // Titolo
  3577. NSString *titleSection;
  3578. // Controllo
  3579. if ([_sectionDataSource.sections count] == 0)
  3580. return nil;
  3581. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  3582. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  3583. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  3584. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  3585. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  3586. else titleSection = NSLocalizedString(titleSection,nil);
  3587. // Formato titolo
  3588. NSString *currentDevice = [CCUtility currentDevice];
  3589. if ([currentDevice rangeOfString:@"iPad3"].location != NSNotFound) {
  3590. visualEffectView = [[UIVisualEffectView alloc] init];
  3591. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR_NO_BLUR;
  3592. } else {
  3593. UIVisualEffect *blurEffect;
  3594. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  3595. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  3596. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR;
  3597. }
  3598. if ([_directoryGroupBy isEqualToString:@"alphabetic"]) {
  3599. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) shift = - 35;
  3600. else shift = - 20;
  3601. } else shift = - 10;
  3602. // Title
  3603. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  3604. titleLabel.backgroundColor=[UIColor clearColor];
  3605. titleLabel.textColor = COLOR_TEXT_ANTHRACITE;
  3606. titleLabel.font = [UIFont systemFontOfSize:12];
  3607. titleLabel.textAlignment = NSTextAlignmentLeft;
  3608. titleLabel.text = titleSection;
  3609. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3610. [visualEffectView addSubview:titleLabel];
  3611. // Elements
  3612. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  3613. elementLabel.backgroundColor=[UIColor clearColor];
  3614. elementLabel.textColor = COLOR_TEXT_ANTHRACITE;
  3615. elementLabel.font = [UIFont systemFontOfSize:12];
  3616. elementLabel.textAlignment = NSTextAlignmentRight;
  3617. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3618. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  3619. NSUInteger rowsCount = [metadatas count];
  3620. if (rowsCount == 0) return nil;
  3621. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  3622. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  3623. [visualEffectView addSubview:elementLabel];
  3624. return visualEffectView;
  3625. }
  3626. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  3627. {
  3628. return [_sectionDataSource.sections indexOfObject:title];
  3629. }
  3630. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  3631. {
  3632. if ([_directoryGroupBy isEqualToString:@"alphabetic"])
  3633. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  3634. else
  3635. return nil;
  3636. }
  3637. /*
  3638. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  3639. {
  3640. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  3641. }
  3642. }
  3643. */
  3644. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  3645. {
  3646. NSString *typeCell;
  3647. NSString *dataFile;
  3648. NSString *lunghezzaFile;
  3649. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3650. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  3651. if ([metadata.session isEqualToString:@""] || metadata.session == nil) typeCell = @"CellMain";
  3652. else typeCell = @"CellMainTransfer";
  3653. if (!metadata)
  3654. return [tableView dequeueReusableCellWithIdentifier:typeCell];
  3655. CCCellMainTransfer *cell = (CCCellMainTransfer *)[tableView dequeueReusableCellWithIdentifier:typeCell forIndexPath:indexPath];
  3656. // separator
  3657. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  3658. // change color selection
  3659. UIView *selectionColor = [[UIView alloc] init];
  3660. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  3661. cell.selectedBackgroundView = selectionColor;
  3662. if ([typeCell isEqualToString:@"CellMain"]) cell.backgroundColor = [UIColor whiteColor];
  3663. if ([typeCell isEqualToString:@"CellMainTransfer"]) cell.backgroundColor = COLOR_TRANSFER_BACKGROUND;
  3664. // ----------------------------------------------------------------------------------------------------------
  3665. // DEFAULT
  3666. // ----------------------------------------------------------------------------------------------------------
  3667. cell.fileImageView.image = nil;
  3668. cell.statusImageView.image = nil;
  3669. cell.offlineImageView.image = nil;
  3670. cell.synchronizedImageView.image = nil;
  3671. cell.sharedImageView.image = nil;
  3672. cell.labelTitle.enabled = YES;
  3673. cell.labelTitle.text = @"";
  3674. cell.labelInfoFile.enabled = YES;
  3675. cell.labelInfoFile.text = @"";
  3676. cell.progressView.progress = 0.0;
  3677. cell.progressView.hidden = YES;
  3678. cell.cancelTaskButton.hidden = YES;
  3679. cell.reloadTaskButton.hidden = YES;
  3680. cell.stopTaskButton.hidden = YES;
  3681. // colori e font
  3682. if (metadata.cryptated) {
  3683. cell.labelTitle.textColor = COLOR_CRYPTOCLOUD;
  3684. cell.labelInfoFile.textColor = [UIColor blackColor];
  3685. } else {
  3686. cell.labelTitle.textColor = COLOR_TEXT_ANTHRACITE;
  3687. cell.labelInfoFile.textColor = [UIColor blackColor];
  3688. }
  3689. // ----------------------------------------------------------------------------------------------------------
  3690. // File Name & Folder
  3691. // ----------------------------------------------------------------------------------------------------------
  3692. // nome del file
  3693. cell.labelTitle.text = metadata.fileNamePrint;
  3694. // è una directory
  3695. if (metadata.directory) {
  3696. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3697. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  3698. lunghezzaFile = @" ";
  3699. // ----------------------------------------------------------------------------------------------------------
  3700. // Offline Folder
  3701. // ----------------------------------------------------------------------------------------------------------
  3702. NSString *directoryServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
  3703. BOOL isOfflineDirectory = [CCCoreData isOfflineDirectoryServerUrl:directoryServerUrl activeAccount:app.activeAccount];
  3704. // Verify Offline
  3705. if (_isOfflineServerUrl == YES && isOfflineDirectory == NO) {
  3706. [CCCoreData setOfflineDirectoryServerUrl:directoryServerUrl offline:YES activeAccount:app.activeAccount];
  3707. isOfflineDirectory = YES;
  3708. }
  3709. if (isOfflineDirectory) {
  3710. cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  3711. }
  3712. // ----------------------------------------------------------------------------------------------------------
  3713. // Favorite Folder
  3714. // ----------------------------------------------------------------------------------------------------------
  3715. if (metadata.favorite) {
  3716. cell.offlineImageView.image = [UIImage imageNamed:image_favorite];
  3717. }
  3718. // Animation synchronized gif
  3719. if ([[CCSynchronize sharedSynchronize] synchronizeFolderAnimationDirectory:[[NSArray alloc] initWithObjects:directoryServerUrl, nil] setGraphicsFolder:NO]) {
  3720. NSURL *myURL;
  3721. if (metadata.cryptated) myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  3722. else myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  3723. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  3724. }
  3725. } else {
  3726. // è un file
  3727. dataFile = [CCUtility dateDiff:metadata.date];
  3728. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  3729. // Plist ancora da scaricare
  3730. if (metadata.cryptated && [metadata.title length] == 0) {
  3731. dataFile = @" ";
  3732. lunghezzaFile = @" ";
  3733. }
  3734. TableLocalFile *recordLocalFile = [CCCoreData getLocalFileWithFileID:metadata.fileID activeAccount:app.activeAccount];
  3735. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3736. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  3737. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  3738. if ([metadata.type isEqualToString: k_metadataType_template] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO)
  3739. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", dataFile];
  3740. if ([metadata.type isEqualToString: k_metadataType_file] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO) {
  3741. if (recordLocalFile && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
  3742. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", dataFile, lunghezzaFile];
  3743. else
  3744. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ ◦ %@", dataFile, lunghezzaFile];
  3745. }
  3746. // Plist ancora da scaricare
  3747. if ([dataFile isEqualToString:@" "] && [lunghezzaFile isEqualToString:@" "])
  3748. cell.labelInfoFile.text = NSLocalizedString(@"_no_plist_pull_down_",nil);
  3749. cell.accessoryType = UITableViewCellAccessoryNone;
  3750. }
  3751. // ----------------------------------------------------------------------------------------------------------
  3752. // File Image View
  3753. // ----------------------------------------------------------------------------------------------------------
  3754. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3755. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  3756. cell.fileImageView.image = [app.icoImagesCache objectForKey:metadata.fileID];
  3757. if (cell.fileImageView.image == nil) {
  3758. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  3759. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  3760. [app.icoImagesCache setObject:image forKey:metadata.fileID];
  3761. dispatch_async(dispatch_get_main_queue(), ^{
  3762. CCCellMainTransfer *cell = [tableView cellForRowAtIndexPath:indexPath];
  3763. if (cell)
  3764. cell.fileImageView.image = image;
  3765. });
  3766. });
  3767. }
  3768. } else {
  3769. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  3770. if (metadata.thumbnailExists)
  3771. [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
  3772. }
  3773. // ----------------------------------------------------------------------------------------------------------
  3774. // Image Status cyptated & Lock Passcode
  3775. // ----------------------------------------------------------------------------------------------------------
  3776. // File Cyptated
  3777. if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_template] == NO) {
  3778. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  3779. }
  3780. // Directory con passcode lock attivato
  3781. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
  3782. if (metadata.directory && ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length])) cell.statusImageView.image = [UIImage imageNamed:image_passcode];
  3783. // ----------------------------------------------------------------------------------------------------------
  3784. // Offline
  3785. // ----------------------------------------------------------------------------------------------------------
  3786. BOOL isOfflineFile = [CCCoreData isOfflineLocalFileID:metadata.fileID activeAccount:app.activeAccount];
  3787. if (isOfflineFile) {
  3788. cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  3789. }
  3790. // ----------------------------------------------------------------------------------------------------------
  3791. // Favorite
  3792. // ----------------------------------------------------------------------------------------------------------
  3793. if (metadata.favorite) {
  3794. cell.offlineImageView.image = [UIImage imageNamed:image_favorite];
  3795. }
  3796. // ----------------------------------------------------------------------------------------------------------
  3797. // Share
  3798. // ----------------------------------------------------------------------------------------------------------
  3799. NSString *shareLink = [app.sharesLink objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
  3800. NSString *shareUserAndGroup = [app.sharesUserAndGroup objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
  3801. BOOL isShare = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_shared].location == NSNotFound);
  3802. BOOL isMounted = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_mounted].location == NSNotFound);
  3803. // Aggiungiamo il Tap per le shared
  3804. if (isShare || [shareLink length] > 0 || [shareUserAndGroup length] > 0 || isMounted) {
  3805. if (isShare) {
  3806. cell.sharedImageView.image = [UIImage imageNamed:image_shareConnect];
  3807. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3808. [tap setNumberOfTapsRequired:1];
  3809. cell.sharedImageView.userInteractionEnabled = YES;
  3810. [cell.sharedImageView addGestureRecognizer:tap];
  3811. }
  3812. if (isMounted) {
  3813. cell.sharedImageView.image = [UIImage imageNamed:image_shareMounted];
  3814. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3815. [tap setNumberOfTapsRequired:1];
  3816. cell.sharedImageView.userInteractionEnabled = YES;
  3817. [cell.sharedImageView addGestureRecognizer:tap];
  3818. }
  3819. if ([shareLink length] > 0 || [shareUserAndGroup length] > 0) {
  3820. if ([shareLink length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareLink];
  3821. if ([shareUserAndGroup length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareUser];
  3822. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  3823. [tap setNumberOfTapsRequired:1];
  3824. cell.sharedImageView.userInteractionEnabled = YES;
  3825. [cell.sharedImageView addGestureRecognizer:tap];
  3826. }
  3827. } else {
  3828. cell.sharedImageView.userInteractionEnabled = NO;
  3829. }
  3830. // ----------------------------------------------------------------------------------------------------------
  3831. // downloadFile
  3832. // ----------------------------------------------------------------------------------------------------------
  3833. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  3834. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusdownloadcrypto];
  3835. else cell.statusImageView.image = [UIImage imageNamed:image_statusdownload];
  3836. // sessionTaskIdentifier : RELOAD + STOP
  3837. if (metadata.sessionTaskIdentifier != k_taskIdentifierDone) {
  3838. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  3839. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  3840. cell.cancelTaskButton.hidden = NO;
  3841. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3842. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3843. cell.reloadTaskButton.hidden = NO;
  3844. }
  3845. // sessionTaskIdentifierPlist : RELOAD
  3846. if (metadata.sessionTaskIdentifierPlist != k_taskIdentifierDone) {
  3847. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3848. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3849. cell.reloadTaskButton.hidden = NO;
  3850. }
  3851. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3852. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3853. if (progress > 0) {
  3854. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  3855. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  3856. cell.progressView.progress = progress;
  3857. cell.progressView.hidden = NO;
  3858. }
  3859. // ----------------------------------------------------------------------------------------------------------
  3860. // downloadFile Error
  3861. // ----------------------------------------------------------------------------------------------------------
  3862. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  3863. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  3864. if ([metadata.sessionError length] == 0)
  3865. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  3866. else
  3867. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3868. }
  3869. }
  3870. // ----------------------------------------------------------------------------------------------------------
  3871. // uploadFile
  3872. // ----------------------------------------------------------------------------------------------------------
  3873. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  3874. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusuploadcrypto];
  3875. else cell.statusImageView.image = [UIImage imageNamed:image_statusupload];
  3876. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetaskcrypto] forState:UIControlStateNormal];
  3877. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetask] forState:UIControlStateNormal];
  3878. cell.cancelTaskButton.hidden = NO;
  3879. if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
  3880. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3881. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3882. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusstopcrypto];
  3883. else cell.statusImageView.image = [UIImage imageNamed:image_statusstop];
  3884. cell.reloadTaskButton.hidden = NO;
  3885. cell.stopTaskButton.hidden = YES;
  3886. } else {
  3887. if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  3888. else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  3889. cell.stopTaskButton.hidden = NO;
  3890. cell.reloadTaskButton.hidden = YES;
  3891. }
  3892. // se non c'è una preview in bianconero metti l'immagine di default
  3893. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  3894. cell.fileImageView.image = [UIImage imageNamed:image_uploaddisable];
  3895. cell.labelTitle.enabled = NO;
  3896. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3897. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3898. if (progress > 0) {
  3899. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  3900. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  3901. cell.progressView.progress = progress;
  3902. cell.progressView.hidden = NO;
  3903. }
  3904. // ----------------------------------------------------------------------------------------------------------
  3905. // uploadFileError
  3906. // ----------------------------------------------------------------------------------------------------------
  3907. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  3908. cell.labelTitle.enabled = NO;
  3909. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  3910. if ([metadata.sessionError length] == 0)
  3911. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  3912. else
  3913. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3914. }
  3915. }
  3916. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3917. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3918. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3919. return cell;
  3920. }
  3921. - (void)setTableViewFooter
  3922. {
  3923. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3924. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3925. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3926. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3927. UIFont *appFont = [UIFont systemFontOfSize:12];
  3928. footerLabel.font = appFont;
  3929. footerLabel.textColor = [UIColor grayColor];
  3930. footerLabel.backgroundColor = [UIColor clearColor];
  3931. footerLabel.textAlignment = NSTextAlignmentCenter;
  3932. NSString *folders;
  3933. NSString *files;
  3934. NSString *footerText;
  3935. if (_sectionDataSource.directories > 1) {
  3936. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  3937. } else if (_sectionDataSource.directories == 1){
  3938. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  3939. } else {
  3940. folders = @"";
  3941. }
  3942. if (_sectionDataSource.files > 1) {
  3943. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  3944. } else if (_sectionDataSource.files == 1){
  3945. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  3946. } else {
  3947. files = @"";
  3948. }
  3949. if ([folders isEqualToString:@""]) {
  3950. footerText = files;
  3951. } else if ([files isEqualToString:@""]) {
  3952. footerText = folders;
  3953. } else {
  3954. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  3955. }
  3956. footerLabel.text = footerText;
  3957. [footerView addSubview:footerLabel];
  3958. [self.tableView setTableFooterView:footerView];
  3959. }
  3960. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3961. {
  3962. NSString *textMessage;
  3963. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  3964. // se non può essere selezionata deseleziona
  3965. if ([cell isEditing] == NO)
  3966. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  3967. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  3968. if (self.tableView.editing) {
  3969. [self setTitle];
  3970. return;
  3971. }
  3972. // test crash
  3973. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
  3974. if (indexPath.row >= [metadatas count]) return;
  3975. // settiamo il record file.
  3976. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3977. //
  3978. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  3979. // se è in corso una sessione
  3980. if ([_metadata.session length] > 0) return;
  3981. if (_metadata.errorPasscode) {
  3982. // se UUID è nil lo sta ancora caricando quindi esci
  3983. if (!_metadata.uuid) return;
  3984. // esiste un hint ??
  3985. CCCrypto *crypto = [[CCCrypto alloc] init];
  3986. NSString *hint = [crypto getHintFromFile:_metadata.fileName isLocal:NO directoryUser:app.directoryUser];
  3987. // qui !! la richiesta della nuova passcode
  3988. if ([_metadata.uuid isEqualToString:[CCUtility getUUID]]) {
  3989. // stesso UUID ... la password è stata modificata !!!!!!
  3990. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_same_device_different_passcode_hint_",nil), hint];
  3991. else textMessage = NSLocalizedString(@"_same_device_different_passcode_", nil);
  3992. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3993. [alertView show];
  3994. } else {
  3995. // UUID diverso.
  3996. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_hint_",nil), _metadata.nameCurrentDevice, hint];
  3997. else textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_",nil), _metadata.nameCurrentDevice];
  3998. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3999. [alertView show];
  4000. }
  4001. // chiediamo la passcode e ricarichiamo tutto.
  4002. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  4003. viewController.delegate = self;
  4004. viewController.fromType = CCBKPasscodeFromPasscode;
  4005. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  4006. viewController.passcodeInputView.maximumLength = 64;
  4007. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  4008. viewController.inputViewTitlePassword = NO;
  4009. viewController.title = _brand_;
  4010. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  4011. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  4012. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  4013. [self presentViewController:navigationController animated:YES completion:nil];
  4014. }
  4015. // modello o plist con il title a 0 allora è andato storto qualcosa ... ricaricalo
  4016. if (_metadata.cryptated && [_metadata.title length] == 0) {
  4017. NSString* selector;
  4018. if ([_metadata.type isEqualToString: k_metadataType_template]) selector = selectorLoadModelView;
  4019. else selector = selectorLoadPlist;
  4020. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:serverUrl downloadData:NO downloadPlist:YES selector:selector selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  4021. return;
  4022. }
  4023. // se il plist è caricato ed è un modello aprilo
  4024. if ([_metadata.type isEqualToString:k_metadataType_template]) [self openModel:_metadata.model isNew:false];
  4025. // file
  4026. if (_metadata.directory == NO && _metadata.errorPasscode == NO && [_metadata.type isEqualToString: k_metadataType_file]) {
  4027. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  4028. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
  4029. [self downloadFileSuccess:_metadata.fileID serverUrl:serverUrl selector:selectorLoadFileView selectorPost:nil];
  4030. } else {
  4031. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadFileView selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  4032. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  4033. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  4034. }
  4035. }
  4036. if (_metadata.directory) [self performSegueDirectoryWithControlPasscode:true];
  4037. }
  4038. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  4039. {
  4040. [self setTitle];
  4041. }
  4042. #pragma --------------------------------------------------------------------------------------------
  4043. #pragma mark ===== Synchronize Folder Cell =====
  4044. #pragma --------------------------------------------------------------------------------------------
  4045. - (void)synchronizeFolderGraphicsServerUrl:(NSString *)serverUrl animation:(BOOL)animation
  4046. {
  4047. BOOL cryptated = NO;
  4048. CCCellMain *cell;
  4049. for (NSString* fileID in _sectionDataSource.allRecordsDataSource) {
  4050. CCMetadata *recordMetadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4051. if (recordMetadata.directory == NO)
  4052. continue;
  4053. if ([[CCUtility stringAppendServerUrl:_serverUrl addFileName:recordMetadata.fileNameData] isEqualToString:serverUrl]) {
  4054. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:recordMetadata.fileID];
  4055. cell = (CCCellMain *)[self.tableView cellForRowAtIndexPath:indexPath];
  4056. cryptated = recordMetadata.cryptated;
  4057. break;
  4058. }
  4059. }
  4060. if (!cell)
  4061. return;
  4062. if (animation) {
  4063. NSURL *myURL;
  4064. if (cryptated)
  4065. myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  4066. else
  4067. myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  4068. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  4069. } else {
  4070. cell.synchronizedImageView.image = nil;
  4071. }
  4072. }
  4073. #pragma --------------------------------------------------------------------------------------------
  4074. #pragma mark ===== Navigation ====
  4075. #pragma --------------------------------------------------------------------------------------------
  4076. - (BOOL)shouldPerformSegue:(NSString *)serverUrl
  4077. {
  4078. // if background return
  4079. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  4080. if (self.view.window == NO)
  4081. return NO;
  4082. // Collapsed ma siamo già in detail esci
  4083. if (self.splitViewController.isCollapsed)
  4084. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return NO;
  4085. // Video in esecuzione esci
  4086. if (_detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && _detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  4087. return YES;
  4088. }
  4089. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  4090. {
  4091. id viewController = segue.destinationViewController;
  4092. if ([viewController isKindOfClass:[UINavigationController class]]) {
  4093. UINavigationController *nav = viewController;
  4094. _detailViewController = (CCDetail *)nav.topViewController;
  4095. } else {
  4096. _detailViewController = segue.destinationViewController;
  4097. }
  4098. NSMutableArray *allRecordsDataSourceImagesVideos = [[NSMutableArray alloc] init];
  4099. for (NSString *fileID in _sectionDataSource.allFileID) {
  4100. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4101. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
  4102. [allRecordsDataSourceImagesVideos addObject:metadata];
  4103. }
  4104. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  4105. _detailViewController.metadataDetail = _metadataSegue;
  4106. _detailViewController.dateFilterQuery = nil;
  4107. _detailViewController.isCameraUpload = NO;
  4108. [_detailViewController setTitle:_metadata.fileNamePrint];
  4109. }
  4110. // can i go to next viewcontroller
  4111. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode
  4112. {
  4113. NSString *nomeDir;
  4114. if(self.tableView.editing == NO && _metadata.errorPasscode == NO){
  4115. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  4116. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  4117. // SE siamo in presenza di una directory bloccata E è attivo il block E la sessione password Lock è senza data ALLORA chiediamo la password per procedere
  4118. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil && controlPasscode) {
  4119. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  4120. viewController.delegate = self;
  4121. viewController.fromType = CCBKPasscodeFromLockDirectory;
  4122. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  4123. viewController.inputViewTitlePassword = YES;
  4124. if ([CCUtility getSimplyBlockCode]) {
  4125. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  4126. viewController.passcodeInputView.maximumLength = 6;
  4127. } else {
  4128. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  4129. viewController.passcodeInputView.maximumLength = 64;
  4130. }
  4131. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  4132. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  4133. viewController.touchIDManager = touchIDManager;
  4134. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  4135. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  4136. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  4137. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
  4138. [self presentViewController:navController animated:YES completion:nil];
  4139. return;
  4140. }
  4141. if (_metadata.cryptated) nomeDir = [_metadata.fileName substringToIndex:[_metadata.fileName length]-6];
  4142. else nomeDir = _metadata.fileName;
  4143. NSString *serverUrlPush = [CCUtility stringAppendServerUrl:serverUrl addFileName:nomeDir];
  4144. CCMain *viewController = [app.listMainVC objectForKey:serverUrlPush];
  4145. if (viewController.isViewLoaded == false) {
  4146. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMainVC"];
  4147. viewController.isFolderEncrypted = _metadata.cryptated;
  4148. viewController.serverUrl = serverUrlPush;
  4149. viewController.titleMain = _metadata.fileNamePrint;
  4150. viewController.textBackButton = _titleMain;
  4151. // save self
  4152. [app.listMainVC setObject:viewController forKey:serverUrlPush];
  4153. }
  4154. // OFF SearchBar
  4155. [viewController cancelSearchBar];
  4156. [self.navigationController pushViewController:viewController animated:YES];
  4157. }
  4158. }
  4159. @end