CCMain.m 267 KB

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