CCMain.m 268 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910
  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 ===== Remove Local File =====
  2282. #pragma --------------------------------------------------------------------------------------------
  2283. - (void)removeLocalFile:(CCMetadata *)metadata
  2284. {
  2285. }
  2286. #pragma --------------------------------------------------------------------------------------------
  2287. #pragma mark ===== Order Table & GroupBy & DirectoryOnTop =====
  2288. #pragma --------------------------------------------------------------------------------------------
  2289. - (void)orderTable:(NSString *)order
  2290. {
  2291. [CCUtility setOrderSettings:order];
  2292. // Clear data-read of DataSource
  2293. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2294. // new menu
  2295. [self createReMainMenu];
  2296. }
  2297. - (void)ascendingTable:(BOOL)ascending
  2298. {
  2299. [CCUtility setAscendingSettings:ascending];
  2300. // Clear data-read of DataSource
  2301. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2302. // new menu
  2303. [self createReMainMenu];
  2304. }
  2305. - (void)directoryOnTop:(BOOL)directoryOnTop
  2306. {
  2307. [CCUtility setDirectoryOnTop:directoryOnTop];
  2308. // Clear data-read of DataSource
  2309. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2310. // new menu
  2311. [self createReMainMenu];
  2312. }
  2313. - (void)tableGroupBy:(NSString *)groupBy
  2314. {
  2315. [CCUtility setGroupBySettings:groupBy];
  2316. // Clear data-read of DataSource
  2317. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2318. // new menu
  2319. [self createReMainMenu];
  2320. }
  2321. #pragma --------------------------------------------------------------------------------------------
  2322. #pragma mark ==== Menu LOGO ====
  2323. #pragma --------------------------------------------------------------------------------------------
  2324. - (void)menuLogo
  2325. {
  2326. if (app.reSelectMenu.isOpen || app.reMainMenu.isOpen)
  2327. return;
  2328. NSMutableArray *menuArray = [NSMutableArray new];
  2329. #ifndef OPTION_MULTIUSER_DISABLE
  2330. 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) {
  2331. [app messageNotification:@"_transfers_in_queue_" description:nil visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  2332. return;
  2333. }
  2334. NSArray *listTableAccount = [CCCoreData getAllTableAccount];
  2335. for (TableAccount *record in listTableAccount) {
  2336. if ([record.account isEqualToString:app.activeAccount]) continue;
  2337. CCMenuItem *item = [[CCMenuItem alloc] init];
  2338. item.title = [record.account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  2339. item.argument = record.account;
  2340. item.image = [UIImage imageNamed:image_Nextcloud];
  2341. item.target = self;
  2342. item.action = @selector(changeDefaultAccount:);
  2343. [menuArray addObject:item];
  2344. }
  2345. if ([menuArray count] == 0)
  2346. return;
  2347. OptionalConfiguration options;
  2348. Color textColor, backgroundColor;
  2349. textColor.R = 0;
  2350. textColor.G = 0;
  2351. textColor.B = 0;
  2352. backgroundColor.R = 1;
  2353. backgroundColor.G = 1;
  2354. backgroundColor.B = 1;
  2355. NSInteger originY = 60;
  2356. options.arrowSize = 9;
  2357. options.marginXSpacing = 7;
  2358. options.marginYSpacing = 10;
  2359. options.intervalSpacing = 20;
  2360. options.menuCornerRadius = 6.5;
  2361. options.maskToBackground = NO;
  2362. options.shadowOfMenu = YES;
  2363. options.hasSeperatorLine = YES;
  2364. options.seperatorLineHasInsets = YES;
  2365. options.textColor = textColor;
  2366. options.menuBackgroundColor = backgroundColor;
  2367. CGRect rect = self.view.frame;
  2368. rect.origin.y = rect.origin.y + originY;
  2369. rect.size.height = rect.size.height - originY;
  2370. [CCMenu setTitleFont:[UIFont systemFontOfSize:12.0]];
  2371. [CCMenu showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
  2372. #endif
  2373. #if defined(MENU_BRAND_ENABLE) && defined(OPTION_MULTIUSER_DISABLE)
  2374. CCMenuItem *item;
  2375. item = [CCMenuItem new];
  2376. item.title = @"Example title ... N. 1";
  2377. item.image = [UIImage imageNamed:image_notification];
  2378. item.target = self;
  2379. item.action = @selector(goToWebVC:);
  2380. item.argument = @"https://www.nextcloud.com";
  2381. [menuArray addObject:item];
  2382. item = [CCMenuItem new];
  2383. item.title = @"Example title ... N. 2";
  2384. item.image = [UIImage imageNamed:image_notification];
  2385. item.target = self;
  2386. item.action = @selector(goToWebVC:);
  2387. item.argument = @"https://www.nextcloud.com";
  2388. [menuArray addObject:item];
  2389. item = [CCMenuItem new];
  2390. item.title = @"Example title ... N. 3";
  2391. item.image = [UIImage imageNamed:image_notification];
  2392. item.target = self;
  2393. item.action = @selector(goToWebVC:);
  2394. item.argument = @"https://www.nextcloud.com";
  2395. [menuArray addObject:item];
  2396. OptionalConfiguration options;
  2397. Color textColor, backgroundColor;
  2398. textColor.R = 0;
  2399. textColor.G = 0;
  2400. textColor.B = 0;
  2401. backgroundColor.R = 1;
  2402. backgroundColor.G = 1;
  2403. backgroundColor.B = 1;
  2404. NSInteger originY = 60;
  2405. options.arrowSize = 9;
  2406. options.marginXSpacing = 7;
  2407. options.marginYSpacing = 10;
  2408. options.intervalSpacing = 20;
  2409. options.menuCornerRadius = 6.5;
  2410. options.maskToBackground = NO;
  2411. options.shadowOfMenu = YES;
  2412. options.hasSeperatorLine = YES;
  2413. options.seperatorLineHasInsets = YES;
  2414. options.textColor = textColor;
  2415. options.menuBackgroundColor = backgroundColor;
  2416. CGRect rect = self.view.frame;
  2417. rect.origin.y = rect.origin.y + originY;
  2418. rect.size.height = rect.size.height - originY;
  2419. [CCMenu setTitleFont:[UIFont systemFontOfSize:12.0]];
  2420. [CCMenu showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
  2421. #endif
  2422. }
  2423. - (void)changeDefaultAccount:(CCMenuItem *)sender
  2424. {
  2425. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
  2426. // STOP, erase all in queue networking
  2427. [app cancelAllOperations];
  2428. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  2429. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  2430. TableAccount *tableAccount = [CCCoreData setActiveAccount:[sender argument]];
  2431. if (tableAccount)
  2432. [app settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activePassword:tableAccount.password];
  2433. // go to home sweet home
  2434. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  2435. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  2436. });
  2437. }
  2438. - (void)goToWebVC:(CCMenuItem *)sender
  2439. {
  2440. if (self.splitViewController.isCollapsed) {
  2441. SwiftWebVC *webVC = [[SwiftWebVC alloc] initWithUrlString:sender.argument];
  2442. [self.navigationController pushViewController:webVC animated:YES];
  2443. } else {
  2444. SwiftModalWebVC *webVC = [[SwiftModalWebVC alloc] initWithUrlString:sender.argument];
  2445. [self presentViewController:webVC animated:YES completion:nil];
  2446. }
  2447. }
  2448. #pragma --------------------------------------------------------------------------------------------
  2449. #pragma mark ==== ReMenu ====
  2450. #pragma --------------------------------------------------------------------------------------------
  2451. - (void)createReMenuBackgroundView:(REMenu *)menu
  2452. {
  2453. __block CGFloat navigationBarH = self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
  2454. _reMenuBackgroundView.frame = CGRectMake(0, navigationBarH, self.view.frame.size.width, self.view.frame.size.height);
  2455. [UIView animateWithDuration:0.2 animations:^{
  2456. float height = (self.view.frame.size.height + navigationBarH) - (menu.menuView.frame.size.height - self.navigationController.navigationBar.frame.size.height + 3);
  2457. if (height < self.tabBarController.tabBar.frame.size.height)
  2458. height = self.tabBarController.tabBar.frame.size.height;
  2459. _reMenuBackgroundView.frame = CGRectMake(0, self.view.frame.size.height + navigationBarH, self.view.frame.size.width, - height);
  2460. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  2461. }];
  2462. }
  2463. - (void)createReMainMenu
  2464. {
  2465. NSString *ordinamento;
  2466. NSString *groupBy = _directoryGroupBy;
  2467. __block NSString *nuovoOrdinamento;
  2468. NSString *titoloNuovo, *titoloAttuale;
  2469. BOOL ascendente;
  2470. __block BOOL nuovoAscendente;
  2471. UIImage *image;
  2472. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  2473. if (app.selezionaItem == nil) app.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)
  2474. subtitle:@""
  2475. image:[UIImage imageNamed:image_seleziona]
  2476. highlightedImage:nil
  2477. action:^(REMenuItem *item) {
  2478. if ([_sectionDataSource.allRecordsDataSource count] > 0) {
  2479. [self tableViewSelect:YES];
  2480. }
  2481. }];
  2482. else app.selezionaItem = [app.selezionaItem initWithTitle:NSLocalizedString(@"_select_", nil)
  2483. subtitle:@""
  2484. image:[UIImage imageNamed:image_seleziona]
  2485. highlightedImage:nil
  2486. action:^(REMenuItem *item) {
  2487. if ([_sectionDataSource.allRecordsDataSource count] > 0)
  2488. [self tableViewSelect:YES];
  2489. }];
  2490. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  2491. ordinamento = _directoryOrder;
  2492. if ([ordinamento isEqualToString:@"fileName"]) {
  2493. image = [UIImage imageNamed:image_MenuOrdeyByDate];
  2494. titoloNuovo = NSLocalizedString(@"_order_by_date_", nil);
  2495. titoloAttuale = NSLocalizedString(@"_current_order_name_", nil);
  2496. nuovoOrdinamento = @"fileDate";
  2497. }
  2498. if ([ordinamento isEqualToString:@"fileDate"]) {
  2499. image = [UIImage imageNamed:image_MenuOrderByFileName];
  2500. titoloNuovo = NSLocalizedString(@"_order_by_name_", nil);
  2501. titoloAttuale = NSLocalizedString(@"_current_order_date_", nil);
  2502. nuovoOrdinamento = @"fileName";
  2503. }
  2504. if (app.ordinaItem == nil) app.ordinaItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2505. subtitle:titoloAttuale
  2506. image:image
  2507. highlightedImage:nil
  2508. action:^(REMenuItem *item) {
  2509. [self orderTable:nuovoOrdinamento];
  2510. }];
  2511. else app.ordinaItem = [app.ordinaItem initWithTitle:titoloNuovo
  2512. subtitle:titoloAttuale
  2513. image:image
  2514. highlightedImage:nil
  2515. action:^(REMenuItem *item) {
  2516. [self orderTable:nuovoOrdinamento];
  2517. }];
  2518. // ITEM ASCENDING -----------------------------------------------------------------------------------------------------
  2519. ascendente = [CCUtility getAscendingSettings];
  2520. if (ascendente) {
  2521. image = [UIImage imageNamed:image_MenuOrdinamentoDiscendente];
  2522. titoloNuovo = NSLocalizedString(@"_sort_descending_", nil);
  2523. titoloAttuale = NSLocalizedString(@"_current_sort_ascending_", nil);
  2524. nuovoAscendente = false;
  2525. }
  2526. if (!ascendente) {
  2527. image = [UIImage imageNamed:image_MenuOrdinamentoAscendente];
  2528. titoloNuovo = NSLocalizedString(@"_sort_ascending_", nil);
  2529. titoloAttuale = NSLocalizedString(@"_current_sort_descending_", nil);
  2530. nuovoAscendente = true;
  2531. }
  2532. if (app.ascendenteItem == nil) app.ascendenteItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2533. subtitle:titoloAttuale
  2534. image:image
  2535. highlightedImage:nil
  2536. action:^(REMenuItem *item) {
  2537. [self ascendingTable:nuovoAscendente];
  2538. }];
  2539. else app.ascendenteItem = [app.ascendenteItem initWithTitle:titoloNuovo
  2540. subtitle:titoloAttuale
  2541. image:image
  2542. highlightedImage:nil
  2543. action:^(REMenuItem *item) {
  2544. [self ascendingTable:nuovoAscendente];
  2545. }];
  2546. // ITEM ALPHABETIC -----------------------------------------------------------------------------------------------------
  2547. if ([groupBy isEqualToString:@"alphabetic"]) { titoloNuovo = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  2548. else { titoloNuovo = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  2549. if (app.alphabeticItem == nil) app.alphabeticItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2550. subtitle:@""
  2551. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2552. highlightedImage:nil
  2553. action:^(REMenuItem *item) {
  2554. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2555. else [self tableGroupBy:@"alphabetic"];
  2556. }];
  2557. else app.alphabeticItem = [app.alphabeticItem initWithTitle:titoloNuovo
  2558. subtitle:@""
  2559. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2560. highlightedImage:nil
  2561. action:^(REMenuItem *item) {
  2562. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2563. else [self tableGroupBy:@"alphabetic"];
  2564. }];
  2565. // ITEM TYPEFILE -------------------------------------------------------------------------------------------------------
  2566. if ([groupBy isEqualToString:@"typefile"]) { titoloNuovo = NSLocalizedString(@"_group_typefile_yes_", nil); }
  2567. else { titoloNuovo = NSLocalizedString(@"_group_typefile_no_", nil); }
  2568. if (app.typefileItem == nil) app.typefileItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2569. subtitle:@""
  2570. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2571. highlightedImage:nil
  2572. action:^(REMenuItem *item) {
  2573. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2574. else [self tableGroupBy:@"typefile"];
  2575. }];
  2576. else app.typefileItem = [app.typefileItem initWithTitle:titoloNuovo
  2577. subtitle:@""
  2578. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2579. highlightedImage:nil
  2580. action:^(REMenuItem *item) {
  2581. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2582. else [self tableGroupBy:@"typefile"];
  2583. }];
  2584. // ITEM DATE -------------------------------------------------------------------------------------------------------
  2585. if ([groupBy isEqualToString:@"date"]) { titoloNuovo = NSLocalizedString(@"_group_date_yes_", nil); }
  2586. else { titoloNuovo = NSLocalizedString(@"_group_date_no_", nil); }
  2587. if (app.dateItem == nil) app.dateItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2588. subtitle:@""
  2589. image:[UIImage imageNamed:image_MenuGroupByDate]
  2590. highlightedImage:nil
  2591. action:^(REMenuItem *item) {
  2592. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2593. else [self tableGroupBy:@"date"];
  2594. }];
  2595. else app.dateItem = [app.dateItem initWithTitle:titoloNuovo
  2596. subtitle:@""
  2597. image:[UIImage imageNamed:image_MenuGroupByDate]
  2598. highlightedImage:nil
  2599. action:^(REMenuItem *item) {
  2600. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2601. else [self tableGroupBy:@"date"];
  2602. }];
  2603. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  2604. if ([CCUtility getDirectoryOnTop]) { titoloNuovo = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  2605. else { titoloNuovo = NSLocalizedString(@"_directory_on_top_no_", nil); }
  2606. if (app.directoryOnTopItem == nil) app.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2607. subtitle:@""
  2608. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2609. highlightedImage:nil
  2610. action:^(REMenuItem *item) {
  2611. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2612. else [self directoryOnTop:YES];
  2613. }];
  2614. else app.directoryOnTopItem = [app.directoryOnTopItem initWithTitle:titoloNuovo
  2615. subtitle:@""
  2616. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2617. highlightedImage:nil
  2618. action:^(REMenuItem *item) {
  2619. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2620. else [self directoryOnTop:YES];
  2621. }];
  2622. // REMENU --------------------------------------------------------------------------------------------------------------
  2623. if (app.reMainMenu == nil) app.reMainMenu = [[REMenu alloc] initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2624. else app.reMainMenu = [app.reMainMenu initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2625. app.reMainMenu.imageOffset = CGSizeMake(5, -1);
  2626. app.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2627. app.reMainMenu.imageOffset = CGSizeMake(0, 0);
  2628. app.reMainMenu.waitUntilAnimationIsComplete = NO;
  2629. app.reMainMenu.separatorHeight = 0.5;
  2630. app.reMainMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2631. app.reMainMenu.backgroundColor = COLOR_BACKGROUND_MENU;
  2632. app.reMainMenu.textColor = [UIColor blackColor];
  2633. app.reMainMenu.textAlignment = NSTextAlignmentLeft;
  2634. app.reMainMenu.textShadowColor = nil;
  2635. app.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  2636. app.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  2637. app.reMainMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2638. app.reMainMenu.highlightedSeparatorColor = nil;
  2639. app.reMainMenu.highlightedTextColor = [UIColor blackColor];
  2640. app.reMainMenu.highlightedTextShadowColor = nil;
  2641. app.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2642. app.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  2643. app.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2644. app.reMainMenu.subtitleTextShadowColor = nil;
  2645. app.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2646. app.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2647. app.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2648. app.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2649. app.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  2650. app.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2651. app.reMainMenu.borderWidth = 0.3;
  2652. app.reMainMenu.borderColor = [UIColor lightGrayColor];
  2653. app.reMainMenu.animationDuration = 0.2;
  2654. app.reMainMenu.closeAnimationDuration = 0.2;
  2655. app.reMainMenu.bounce = NO;
  2656. [app.reMainMenu setClosePreparationBlock:^{
  2657. // Backgroun reMenu (Gesture)
  2658. [_reMenuBackgroundView removeFromSuperview];
  2659. [app.controlCenter disableSingleFingerTap];
  2660. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2661. }];
  2662. }
  2663. - (void)toggleReMainMenu
  2664. {
  2665. if (app.reMainMenu.isOpen) {
  2666. [app.reMainMenu close];
  2667. } else {
  2668. [app.reMainMenu showFromNavigationController:self.navigationController];
  2669. // Backgroun reMenu & (Gesture)
  2670. [self createReMenuBackgroundView:app.reMainMenu];
  2671. [app.controlCenter enableSingleFingerTap:@selector(toggleReMainMenu) target:self];
  2672. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  2673. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2674. }
  2675. }
  2676. - (void)createReSelectMenu
  2677. {
  2678. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  2679. if (app.deleteItem == nil) app.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2680. subtitle:@""
  2681. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2682. highlightedImage:nil
  2683. action:^(REMenuItem *item) {
  2684. [self deleteSelectionFile];
  2685. }];
  2686. else app.deleteItem = [app.deleteItem initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2687. subtitle:@""
  2688. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2689. highlightedImage:nil
  2690. action:^(REMenuItem *item) {
  2691. [self deleteSelectionFile];
  2692. }];
  2693. // ITEM MOVE ------------------------------------------------------------------------------------------------------
  2694. if (app.moveItem == nil) app.moveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2695. subtitle:@""
  2696. image:[UIImage imageNamed:image_moveSelectedFiles]
  2697. highlightedImage:nil
  2698. action:^(REMenuItem *item) {
  2699. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2700. }];
  2701. else app.moveItem = [app.moveItem initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2702. subtitle:@""
  2703. image:[UIImage imageNamed:image_moveSelectedFiles]
  2704. highlightedImage:nil
  2705. action:^(REMenuItem *item) {
  2706. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2707. }];
  2708. if (app.isCryptoCloudMode) {
  2709. // ITEM ENCRYPTED ------------------------------------------------------------------------------------------------------
  2710. if (app.encryptItem == nil) app.encryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2711. subtitle:@""
  2712. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2713. highlightedImage:nil
  2714. action:^(REMenuItem *item) {
  2715. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil];
  2716. }];
  2717. else app.encryptItem = [app.encryptItem initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2718. subtitle:@""
  2719. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2720. highlightedImage:nil
  2721. action:^(REMenuItem *item) {
  2722. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil];
  2723. }];
  2724. // ITEM DECRYPTED ----------------------------------------------------------------------------------------------------
  2725. if (app.decryptItem == nil) app.decryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2726. subtitle:@""
  2727. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2728. highlightedImage:nil
  2729. action:^(REMenuItem *item) {
  2730. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil];
  2731. }];
  2732. else app.decryptItem = [app.decryptItem initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2733. subtitle:@""
  2734. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2735. highlightedImage:nil
  2736. action:^(REMenuItem *item) {
  2737. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil];
  2738. }];
  2739. }
  2740. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  2741. if (app.downloadItem == nil) app.downloadItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2742. subtitle:@""
  2743. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2744. highlightedImage:nil
  2745. action:^(REMenuItem *item) {
  2746. [self downloadSelectedFiles];
  2747. }];
  2748. else app.downloadItem = [app.downloadItem initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2749. subtitle:@""
  2750. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2751. highlightedImage:nil
  2752. action:^(REMenuItem *item) {
  2753. [self downloadSelectedFiles];
  2754. }];
  2755. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  2756. if (app.saveItem == nil) app.saveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2757. subtitle:@""
  2758. image:[UIImage imageNamed:image_saveSelectedFiles]
  2759. highlightedImage:nil
  2760. action:^(REMenuItem *item) {
  2761. [self saveSelectedFiles];
  2762. }];
  2763. else app.saveItem = [app.saveItem initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2764. subtitle:@""
  2765. image:[UIImage imageNamed:image_saveSelectedFiles]
  2766. highlightedImage:nil
  2767. action:^(REMenuItem *item) {
  2768. [self saveSelectedFiles];
  2769. }];
  2770. // REMENU --------------------------------------------------------------------------------------------------------------
  2771. if (app.isCryptoCloudMode) {
  2772. if (app.reSelectMenu == nil)
  2773. app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2774. else
  2775. app.reSelectMenu = [app.reSelectMenu initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2776. } else {
  2777. if (app.reSelectMenu == nil)
  2778. app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.downloadItem, app.saveItem]];
  2779. else
  2780. app.reSelectMenu = [app.reSelectMenu initWithItems:@[app.deleteItem,app.moveItem, app.downloadItem, app.saveItem]];
  2781. }
  2782. app.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  2783. app.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2784. app.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  2785. app.reSelectMenu.waitUntilAnimationIsComplete = NO;
  2786. app.reSelectMenu.separatorHeight = 0.5;
  2787. app.reSelectMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2788. app.reSelectMenu.backgroundColor = COLOR_BACKGROUND_MENU;
  2789. app.reSelectMenu.textColor = [UIColor blackColor];
  2790. app.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  2791. app.reSelectMenu.textShadowColor = nil;
  2792. app.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  2793. app.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  2794. app.reSelectMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2795. app.reSelectMenu.highlightedSeparatorColor = nil;
  2796. app.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  2797. app.reSelectMenu.highlightedTextShadowColor = nil;
  2798. app.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2799. app.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  2800. app.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2801. app.reSelectMenu.subtitleTextShadowColor = nil;
  2802. app.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2803. app.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2804. app.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2805. app.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2806. app.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  2807. app.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2808. app.reSelectMenu.borderWidth = 0.3;
  2809. app.reSelectMenu.borderColor = [UIColor lightGrayColor];
  2810. app.reSelectMenu.closeAnimationDuration = 0.2;
  2811. app.reSelectMenu.animationDuration = 0.2;
  2812. app.reSelectMenu.bounce = NO;
  2813. [app.reSelectMenu setClosePreparationBlock:^{
  2814. // Backgroun reMenu (Gesture)
  2815. [_reMenuBackgroundView removeFromSuperview];
  2816. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2817. }];
  2818. }
  2819. - (void)toggleReSelectMenu
  2820. {
  2821. if (app.reSelectMenu.isOpen) {
  2822. [app.reSelectMenu close];
  2823. } else {
  2824. [app.reSelectMenu showFromNavigationController:self.navigationController];
  2825. // Backgroun reMenu & (Gesture)
  2826. [self createReMenuBackgroundView:app.reSelectMenu];
  2827. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  2828. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2829. }
  2830. }
  2831. #pragma --------------------------------------------------------------------------------------------
  2832. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  2833. #pragma --------------------------------------------------------------------------------------------
  2834. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  2835. {
  2836. if (recognizer.state == UIGestureRecognizerStateBegan) {
  2837. UITableView *tableView = (UITableView*)self.view;
  2838. CGPoint touchPoint = [recognizer locationInView:self.view];
  2839. NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:touchPoint];
  2840. if (indexPath)
  2841. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  2842. else
  2843. _metadata = nil;
  2844. [self becomeFirstResponder];
  2845. UIMenuController *menuController = [UIMenuController sharedMenuController];
  2846. UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
  2847. UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
  2848. UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
  2849. UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
  2850. UIMenuItem *pasteFileEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_encrypted_", nil) action:@selector(pasteFileEncrypted:)];
  2851. UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
  2852. UIMenuItem *pasteFilesEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_encrypted_", nil) action:@selector(pasteFilesEncrypted:)];
  2853. if (app.isCryptoCloudMode)
  2854. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, pasteFileEncryptedItem, pasteFilesEncryptedItem, nil]];
  2855. else
  2856. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, nil]];
  2857. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:tableView];
  2858. [menuController setMenuVisible:YES animated:YES];
  2859. }
  2860. }
  2861. - (BOOL)canBecomeFirstResponder
  2862. {
  2863. return YES;
  2864. }
  2865. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  2866. {
  2867. // For copy file, copy files, Open in ... :
  2868. //
  2869. // NO Directory
  2870. // NO Error Passcode
  2871. // NO In Session mode (download/upload)
  2872. // NO Template
  2873. if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
  2874. if (_isSelectedMode == NO && _metadata && !_metadata.directory && !_metadata.errorPasscode && [_metadata.session length] == 0 && ![_metadata.typeFile isEqualToString: k_metadataTypeFile_template]) {
  2875. // NO Cryptated with Title lenght = 0
  2876. if (!_metadata.cryptated || (_metadata.cryptated && _metadata.title.length > 0))
  2877. return YES;
  2878. }
  2879. return NO;
  2880. }
  2881. if (@selector(copyFiles:) == action) {
  2882. if (_isSelectedMode) {
  2883. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2884. for (CCMetadata *metadata in selectedMetadatas) {
  2885. if (!metadata.directory && !metadata.errorPasscode && metadata.session.length == 0 && ![metadata.typeFile isEqualToString: k_metadataTypeFile_template]) {
  2886. // NO Cryptated with Title lenght = 0
  2887. if (!metadata.cryptated || (metadata.cryptated && metadata.title.length > 0))
  2888. return YES;
  2889. }
  2890. }
  2891. }
  2892. return NO;
  2893. }
  2894. if (@selector(pasteFile:) == action || @selector(pasteFileEncrypted:) == action) {
  2895. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2896. NSArray *items = [pasteboard items];
  2897. if ([items count] == 1) {
  2898. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2899. NSDictionary *dic = [items objectAtIndex:0];
  2900. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2901. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2902. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2903. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2904. if (directoryUser) {
  2905. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2906. return YES;
  2907. }
  2908. return NO;
  2909. } else return NO;
  2910. }
  2911. if (@selector(pasteFiles:) == action || @selector(pasteFilesEncrypted:) == action) {
  2912. BOOL isValid = NO;
  2913. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2914. NSArray *items = [pasteboard items];
  2915. if ([items count] <= 1) return NO;
  2916. for (NSDictionary *dic in items) {
  2917. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2918. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2919. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2920. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2921. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2922. if (directoryUser) {
  2923. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2924. isValid = YES;
  2925. }
  2926. }
  2927. return isValid;
  2928. }
  2929. return NO;
  2930. }
  2931. /************************************ COPY ************************************/
  2932. - (void)copyFile:(id)sender
  2933. {
  2934. // Remove all item
  2935. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2936. pasteboard.items = [[NSArray alloc] init];
  2937. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser,_metadata.fileID]]) {
  2938. [self copyFileToPasteboard:_metadata];
  2939. } else {
  2940. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  2941. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2942. }
  2943. }
  2944. - (void)copyFiles:(id)sender
  2945. {
  2946. // Remove all item
  2947. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2948. pasteboard.items = [[NSArray alloc] init];
  2949. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2950. for (CCMetadata *metadata in selectedMetadatas) {
  2951. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]]) {
  2952. [self copyFileToPasteboard:metadata];
  2953. } else {
  2954. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  2955. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2956. }
  2957. }
  2958. [self tableViewSelect:NO];
  2959. }
  2960. - (void)copyFileToPasteboard:(CCMetadata *)metadata
  2961. {
  2962. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2963. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  2964. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2965. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata], @"it.twsweb.Crypto-Cloud.CCMetadata",nil];
  2966. [items addObject:item];
  2967. [pasteboard setItems:items];
  2968. }
  2969. /************************************ OPEN IN ... ************************************/
  2970. - (void)openinFile:(id)sender
  2971. {
  2972. [self openIn:_metadata];
  2973. }
  2974. /************************************ PASTE ************************************/
  2975. - (void)pasteFile:(id)sender
  2976. {
  2977. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2978. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2979. }
  2980. - (void)pasteFileEncrypted:(id)sender
  2981. {
  2982. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2983. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2984. }
  2985. - (void)pasteFiles:(id)sender
  2986. {
  2987. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2988. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2989. }
  2990. - (void)pasteFilesEncrypted:(id)sender
  2991. {
  2992. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2993. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2994. }
  2995. - (void)uploadFilePasteArray:(NSArray *)items cryptated:(BOOL)cryptated
  2996. {
  2997. for (NSDictionary *dic in items) {
  2998. // key : it.twsweb.Crypto-Cloud.CCMetadata
  2999. // Value : (NSData) metadata
  3000. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  3001. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  3002. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  3003. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  3004. if (directoryUser) {
  3005. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]]) {
  3006. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint]];
  3007. [[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];
  3008. }
  3009. }
  3010. }
  3011. }
  3012. #pragma --------------------------------------------------------------------------------------------
  3013. #pragma mark ===== Lock Passcode =====
  3014. #pragma --------------------------------------------------------------------------------------------
  3015. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  3016. {
  3017. return _failedAttempts;
  3018. }
  3019. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  3020. {
  3021. return _lockUntilDate;
  3022. }
  3023. - (void)passcodeViewCloseButtonPressed:(id)sender
  3024. {
  3025. [self dismissViewControllerAnimated:YES completion:nil];
  3026. }
  3027. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  3028. {
  3029. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  3030. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  3031. _lockUntilDate = nil;
  3032. _failedAttempts = 0;
  3033. aResultHandler(YES);
  3034. } else aResultHandler(NO);
  3035. } else aResultHandler(YES);
  3036. }
  3037. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  3038. {
  3039. [aViewController dismissViewControllerAnimated:YES completion:nil];
  3040. switch (aViewController.type) {
  3041. case BKPasscodeViewControllerCheckPasscodeType: {
  3042. if (aViewController.fromType == CCBKPasscodeFromPasscode) {
  3043. // verifichiamo se il passcode è corretto per il seguente file -> UUID
  3044. if ([[CCCrypto sharedManager] verifyPasscode:aPasscode uuid:_metadata.uuid text:_metadata.title]) {
  3045. // scriviamo il passcode
  3046. [CCUtility setKeyChainPasscodeForUUID:_metadata.uuid conPasscode:aPasscode];
  3047. [self readFolderWithForced:YES serverUrl:_serverUrl];
  3048. } else {
  3049. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_error_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3050. [alertView show];
  3051. }
  3052. }
  3053. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  3054. // possiamo procedere alla prossima directory
  3055. [self performSegueDirectoryWithControlPasscode:false];
  3056. // avviamo la sessione Passcode Lock con now
  3057. app.sessionePasscodeLock = [NSDate date];
  3058. }
  3059. // disattivazione lock cartella
  3060. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  3061. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  3062. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3063. if ([CCCoreData setDirectoryUnLock:lockServerUrl activeAccount:app.activeAccount] == NO) {
  3064. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  3065. }
  3066. [self.tableView reloadData];
  3067. }
  3068. }
  3069. break;
  3070. default:
  3071. break;
  3072. }
  3073. }
  3074. - (void)comandoLockPassword
  3075. {
  3076. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  3077. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3078. // se non è abilitato il Lock Passcode esci
  3079. if ([[CCUtility getBlockCode] length] == 0) {
  3080. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3081. [alertView show];
  3082. return;
  3083. }
  3084. // se è richiesta la disattivazione si chiede la password
  3085. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  3086. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  3087. viewController.delegate = self;
  3088. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  3089. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  3090. viewController.inputViewTitlePassword = YES;
  3091. if ([CCUtility getSimplyBlockCode]) {
  3092. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  3093. viewController.passcodeInputView.maximumLength = 6;
  3094. } else {
  3095. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  3096. viewController.passcodeInputView.maximumLength = 64;
  3097. }
  3098. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  3099. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  3100. viewController.touchIDManager = touchIDManager;
  3101. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  3102. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  3103. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  3104. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  3105. [self presentViewController:navigationController animated:YES completion:nil];
  3106. return;
  3107. }
  3108. // ---------------- ACTIVATE PASSWORD
  3109. if([CCCoreData setDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  3110. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  3111. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  3112. } else {
  3113. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  3114. }
  3115. }
  3116. #pragma mark -
  3117. #pragma --------------------------------------------------------------------------------------------
  3118. #pragma mark ===== Swipe Tablet -> menu =====
  3119. #pragma --------------------------------------------------------------------------------------------
  3120. // more
  3121. - (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  3122. return NSLocalizedString(@"_more_", nil);
  3123. }
  3124. - (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
  3125. {
  3126. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3127. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  3128. NSString *titoloCriptaDecripta, *titoloOffline, *titoloLock, *titleOfflineFolder, *titleFavorite;
  3129. BOOL offlineFolder = NO;
  3130. if (_metadata.cryptated) titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_decrypt_", nil)];
  3131. else titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_encrypt_", nil)];
  3132. if ([CCCoreData isOfflineLocalFileID:_metadata.fileID activeAccount:app.activeAccount]) titoloOffline = [NSString stringWithFormat:NSLocalizedString(@"_remove_offline_", nil)];
  3133. else titoloOffline = [NSString stringWithFormat:NSLocalizedString(@"_add_offline_", nil)];
  3134. NSString *offlineServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3135. if (_metadata.directory && [CCCoreData isOfflineDirectoryServerUrl:offlineServerUrl activeAccount:app.activeAccount]) {
  3136. titleOfflineFolder = [NSString stringWithFormat:NSLocalizedString(@"_remove_offline_", nil)];
  3137. offlineFolder = YES;
  3138. } else titleOfflineFolder = [NSString stringWithFormat:NSLocalizedString(@"_add_offline_", nil)];
  3139. if (_metadata.favorite) {
  3140. titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_remove_favorites_", nil)];
  3141. } else {
  3142. titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_add_favorites_", nil)];
  3143. }
  3144. if (_metadata.directory) {
  3145. // calcolo lockServerUrl
  3146. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3147. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  3148. else titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  3149. }
  3150. TableLocalFile *recordLocalFile = [CCCoreData getLocalFileWithFileID:_metadata.fileID activeAccount:app.activeAccount];
  3151. /******************************************* AHKActionSheet *******************************************/
  3152. UIImage *iconHeader;
  3153. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  3154. actionSheet.animationDuration = 0.2;
  3155. actionSheet.blurRadius = 0.0f;
  3156. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  3157. actionSheet.buttonHeight = 50.0;
  3158. actionSheet.cancelButtonHeight = 50.0f;
  3159. actionSheet.separatorHeight = 5.0f;
  3160. actionSheet.automaticallyTintButtonImages = @(NO);
  3161. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_CRYPTOCLOUD };
  3162. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  3163. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  3164. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  3165. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  3166. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  3167. /******************************************* DIRECTORY *******************************************/
  3168. if (_metadata.directory) {
  3169. UIImage *iconHeader;
  3170. BOOL lockDirectory = NO;
  3171. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3172. // Directory bloccata ?
  3173. if ([CCCoreData isDirectoryLock:dirServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3174. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3175. NSString *cameraUploadFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  3176. NSString *cameraUploadFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  3177. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3178. image: iconHeader
  3179. backgroundColor: COLOR_TABBAR
  3180. height: 50.0
  3181. type: AHKActionSheetButtonTypeDisabled
  3182. handler: nil
  3183. ];
  3184. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3185. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3186. image:[UIImage imageNamed:image_actionSheetRename]
  3187. backgroundColor:[UIColor whiteColor]
  3188. height: 50.0
  3189. type:AHKActionSheetButtonTypeDefault
  3190. handler:^(AHKActionSheet *as) {
  3191. // close swipe
  3192. [self setEditing:NO animated:YES];
  3193. //chiediamo il nome del file
  3194. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3195. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3196. alertView.tag = alertRename;
  3197. UITextField *textField = [alertView textFieldAtIndex:0];
  3198. textField.text = _metadata.fileNamePrint;
  3199. [alertView show];
  3200. }];
  3201. }
  3202. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3203. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3204. image:[UIImage imageNamed:image_actionSheetMove]
  3205. backgroundColor:[UIColor whiteColor]
  3206. height: 50.0
  3207. type:AHKActionSheetButtonTypeDefault
  3208. handler:^(AHKActionSheet *as) {
  3209. // close swipe
  3210. [self setEditing:NO animated:YES];
  3211. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3212. }];
  3213. }
  3214. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory && app.isCryptoCloudMode) {
  3215. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3216. image:[UIImage imageNamed:image_actionSheetCrypto]
  3217. backgroundColor:[UIColor whiteColor]
  3218. height: 50.0
  3219. type:AHKActionSheetButtonTypeEncrypted
  3220. handler:^(AHKActionSheet *as) {
  3221. // close swipe
  3222. [self setEditing:NO animated:YES];
  3223. [self performSelector:@selector(encyptedDecryptedFolder) withObject:nil];
  3224. }];
  3225. }
  3226. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES)) {
  3227. [actionSheet addButtonWithTitle:titoloLock
  3228. image:[UIImage imageNamed:image_actionSheetLock]
  3229. backgroundColor:[UIColor whiteColor]
  3230. height: 50.0
  3231. type:AHKActionSheetButtonTypeEncrypted
  3232. handler:^(AHKActionSheet *as) {
  3233. // close swipe
  3234. [self setEditing:NO animated:YES];
  3235. [self performSelector:@selector(comandoLockPassword) withObject:nil];
  3236. }];
  3237. }
  3238. if (_metadata.cryptated == NO && app.hasServerShareSupport && !lockDirectory) {
  3239. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3240. image:[UIImage imageNamed:image_actionSheetShare]
  3241. backgroundColor:[UIColor whiteColor]
  3242. height: 50.0
  3243. type:AHKActionSheetButtonTypeDefault
  3244. handler:^(AHKActionSheet *as) {
  3245. // close swipe
  3246. [self setEditing:NO animated:YES];
  3247. [self openWindowShare:_metadata];
  3248. }];
  3249. }
  3250. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [serverUrl isEqualToString:cameraUploadFolderPath] == YES) && _metadata.cryptated == NO) {
  3251. [actionSheet addButtonWithTitle:NSLocalizedString(@"_folder_automatic_upload_", nil)
  3252. image:[UIImage imageNamed:image_folderphotocamera]
  3253. backgroundColor:[UIColor whiteColor]
  3254. height: 50.0
  3255. type:AHKActionSheetButtonTypeDefault
  3256. handler:^(AHKActionSheet *as) {
  3257. // close swipe
  3258. [self setEditing:NO animated:YES];
  3259. // Settings new folder Automatatic upload
  3260. NSString *oldPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  3261. [CCCoreData setCameraUploadFolderName:_metadata.fileName activeAccount:app.activeAccount];
  3262. [CCCoreData setCameraUploadFolderPath:serverUrl activeUrl:app.activeUrl activeAccount:app.activeAccount];
  3263. [CCCoreData clearDateReadDirectory:oldPath activeAccount:app.activeAccount];
  3264. if (app.activeAccount.length > 0 && app.activePhotosCameraUpload)
  3265. [app.activePhotosCameraUpload reloadDatasourceForced];
  3266. [self readFolderWithForced:YES serverUrl:serverUrl];
  3267. NSLog(@"[LOG] Update Folder Photo");
  3268. NSString *folderCameraUpload = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  3269. if ([folderCameraUpload length] > 0)
  3270. [[CCSynchronize sharedSynchronize] readFolderServerUrl:folderCameraUpload directoryID:[CCCoreData getDirectoryIDFromServerUrl:folderCameraUpload activeAccount:app.activeAccount] selector:selectorReadFolderRefresh];
  3271. }];
  3272. }
  3273. #ifndef OPTION_OFFLINE_DISABLE
  3274. NSString *upDir = [CCUtility deletingLastPathComponentFromServerUrl:dirServerUrl];
  3275. NSString *homeDir = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
  3276. if (!lockDirectory && ([upDir isEqualToString:homeDir] || ![CCCoreData isOfflineDirectoryServerUrl:upDir activeAccount:app.activeAccount]) && !_metadata.cryptated) {
  3277. [actionSheet addButtonWithTitle:titleOfflineFolder
  3278. image:[UIImage imageNamed:image_actionSheetOffline]
  3279. backgroundColor:[UIColor whiteColor]
  3280. height: 50.0
  3281. type:AHKActionSheetButtonTypeDefault
  3282. handler:^(AHKActionSheet *as) {
  3283. // close swipe
  3284. [self setEditing:NO animated:YES];
  3285. if (offlineFolder == NO) {
  3286. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"",nil) message:NSLocalizedString(@"_offline_folder_confirm_",nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3287. alertView.tag = alertOfflineFolder;
  3288. [alertView show];
  3289. } else {
  3290. // remove tag offline for all folder/subfolder/file
  3291. NSArray *directories = [CCCoreData getOfflineDirectoryActiveAccount:app.activeAccount];
  3292. for (TableDirectory *directory in directories)
  3293. if ([directory.serverUrl containsString:dirServerUrl]) {
  3294. [CCCoreData setOfflineDirectoryServerUrl:directory.serverUrl offline:NO activeAccount:app.activeAccount];
  3295. [CCCoreData removeOfflineAllFileFromServerUrl:directory.serverUrl activeAccount:app.activeAccount];
  3296. }
  3297. [self performSelector:@selector(reloadDatasource) withObject:nil];
  3298. }
  3299. }];
  3300. }
  3301. #endif
  3302. if (!lockDirectory && !_metadata.cryptated) {
  3303. [actionSheet addButtonWithTitle:titleFavorite
  3304. image:[UIImage imageNamed:image_actionSheetFavorite]
  3305. backgroundColor:[UIColor whiteColor]
  3306. height: 50.0
  3307. type:AHKActionSheetButtonTypeDefault
  3308. handler:^(AHKActionSheet *as) {
  3309. // close swipe
  3310. [self setEditing:NO animated:YES];
  3311. if (_metadata.favorite)
  3312. [self removeFavorite:_metadata];
  3313. else
  3314. [self addFavorite:_metadata];
  3315. }];
  3316. }
  3317. [actionSheet show];
  3318. }
  3319. /******************************************* FILE *******************************************/
  3320. if ([_metadata.type isEqualToString: k_metadataType_file] && !_metadata.directory) {
  3321. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3322. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]])
  3323. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]];
  3324. else
  3325. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3326. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3327. image: iconHeader
  3328. backgroundColor: COLOR_TABBAR
  3329. height: 50.0
  3330. type: AHKActionSheetButtonTypeDisabled
  3331. handler: nil
  3332. ];
  3333. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3334. image:[UIImage imageNamed:image_actionSheetRename]
  3335. backgroundColor:[UIColor whiteColor]
  3336. height: 50.0
  3337. type:AHKActionSheetButtonTypeDefault
  3338. handler:^(AHKActionSheet *as) {
  3339. // close swipe
  3340. [self setEditing:NO animated:YES];
  3341. //chiediamo il nome del file
  3342. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3343. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3344. alertView.tag = alertRename;
  3345. UITextField *textField = [alertView textFieldAtIndex:0];
  3346. textField.text = _metadata.fileNamePrint;
  3347. [alertView show];
  3348. }];
  3349. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3350. image:[UIImage imageNamed:image_actionSheetMove]
  3351. backgroundColor:[UIColor whiteColor]
  3352. height: 50.0
  3353. type:AHKActionSheetButtonTypeDefault
  3354. handler:^(AHKActionSheet *as) {
  3355. // close swipe
  3356. [self setEditing:NO animated:YES];
  3357. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3358. }];
  3359. [actionSheet addButtonWithTitle:NSLocalizedString(@"_reload_", nil)
  3360. image:[UIImage imageNamed:image_actionSheetReload]
  3361. backgroundColor:[UIColor whiteColor]
  3362. height: 50.0
  3363. type:AHKActionSheetButtonTypeDefault
  3364. handler:^(AHKActionSheet *as) {
  3365. // close swipe
  3366. [self setEditing:NO animated:YES];
  3367. [self performSelector:@selector(reloadFile:) withObject:_metadata];
  3368. }];
  3369. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  3370. image:[UIImage imageNamed:image_actionSheetOpenIn]
  3371. backgroundColor:[UIColor whiteColor]
  3372. height: 50.0
  3373. type:AHKActionSheetButtonTypeDefault
  3374. handler:^(AHKActionSheet *as) {
  3375. // close swipe
  3376. [self setEditing:NO animated:YES];
  3377. [self performSelector:@selector(openIn:) withObject:_metadata];
  3378. }];
  3379. if (_metadata.cryptated == NO && app.hasServerShareSupport) {
  3380. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3381. image:[UIImage imageNamed:image_actionSheetShare]
  3382. backgroundColor:[UIColor whiteColor]
  3383. height: 50.0
  3384. type:AHKActionSheetButtonTypeDefault
  3385. handler:^(AHKActionSheet *as) {
  3386. // close swipe
  3387. [self setEditing:NO animated:YES];
  3388. [self openWindowShare:_metadata];
  3389. }];
  3390. }
  3391. if (app.isCryptoCloudMode) {
  3392. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3393. image:[UIImage imageNamed:image_actionSheetCrypto]
  3394. backgroundColor:[UIColor whiteColor]
  3395. height: 50.0
  3396. type:AHKActionSheetButtonTypeEncrypted
  3397. handler:^(AHKActionSheet *as) {
  3398. // close swipe
  3399. [self setEditing:NO animated:YES];
  3400. [self performSelector:@selector(cmdEncryptedDecryptedFile) withObject:nil];
  3401. }];
  3402. }
  3403. if (recordLocalFile) {
  3404. [actionSheet addButtonWithTitle:NSLocalizedString(@"_remove_local_file_", nil)
  3405. image:[UIImage imageNamed:image_actionSheetRemoveLocal]
  3406. backgroundColor:[UIColor whiteColor]
  3407. height: 50.0
  3408. type:AHKActionSheetButtonTypeDefault
  3409. handler:^(AHKActionSheet *as) {
  3410. // close swipe
  3411. [self setEditing:NO animated:YES];
  3412. [self performSelector:@selector(removeLocalFile:) withObject:_metadata];
  3413. }];
  3414. }
  3415. #ifndef OPTION_OFFLINE_DISABLE
  3416. if (!_metadata.cryptated) {
  3417. [actionSheet addButtonWithTitle:titoloOffline
  3418. image:[UIImage imageNamed:image_actionSheetOffline]
  3419. backgroundColor:[UIColor whiteColor]
  3420. height: 50.0
  3421. type:AHKActionSheetButtonTypeDefault
  3422. handler:^(AHKActionSheet *as) {
  3423. // close swipe
  3424. [self setEditing:NO animated:YES];
  3425. if ([CCCoreData isOfflineLocalFileID:_metadata.fileID activeAccount:app.activeAccount]) {
  3426. [self removeOffline:_metadata];
  3427. } else {
  3428. [self addOffline:_metadata];
  3429. }
  3430. }];
  3431. }
  3432. #endif
  3433. if (!_metadata.cryptated) {
  3434. [actionSheet addButtonWithTitle:titleFavorite
  3435. image:[UIImage imageNamed:image_actionSheetFavorite]
  3436. backgroundColor:[UIColor whiteColor]
  3437. height: 50.0
  3438. type:AHKActionSheetButtonTypeDefault
  3439. handler:^(AHKActionSheet *as) {
  3440. // close swipe
  3441. [self setEditing:NO animated:YES];
  3442. if (_metadata.favorite)
  3443. [self removeFavorite:_metadata];
  3444. else
  3445. [self addFavorite:_metadata];
  3446. }];
  3447. }
  3448. [actionSheet addButtonWithTitle:NSLocalizedString(@"_add_local_", nil)
  3449. image:[UIImage imageNamed:image_actionSheetLocal]
  3450. backgroundColor:[UIColor whiteColor]
  3451. height: 50.0
  3452. type:AHKActionSheetButtonTypeDefault
  3453. handler:^(AHKActionSheet *as) {
  3454. // close swipe
  3455. [self setEditing:NO animated:YES];
  3456. [self performSelector:@selector(addLocal:) withObject:_metadata];
  3457. }];
  3458. [actionSheet show];
  3459. }
  3460. /******************************************* TEMPLATE *******************************************/
  3461. if ([_metadata.type isEqualToString: k_metadataType_template]) {
  3462. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3463. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3464. image: iconHeader
  3465. backgroundColor: COLOR_TABBAR
  3466. height: 50.0
  3467. type: AHKActionSheetButtonTypeDisabled
  3468. handler: nil
  3469. ];
  3470. if ([_metadata.model isEqualToString:@"note"]) {
  3471. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3472. image:[UIImage imageNamed:image_actionSheetRename]
  3473. backgroundColor:[UIColor whiteColor]
  3474. height: 50.0
  3475. type:AHKActionSheetButtonTypeDefault
  3476. handler:^(AHKActionSheet *as) {
  3477. // close swipe
  3478. [self setEditing:NO animated:YES];
  3479. //chiediamo il nome del file
  3480. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3481. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3482. alertView.tag = alertRename;
  3483. UITextField *textField = [alertView textFieldAtIndex:0];
  3484. textField.text = _metadata.fileNamePrint;
  3485. [alertView show];
  3486. }];
  3487. }
  3488. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3489. image:[UIImage imageNamed:image_actionSheetMove]
  3490. backgroundColor:[UIColor whiteColor]
  3491. height: 50.0
  3492. type:AHKActionSheetButtonTypeDefault
  3493. handler:^(AHKActionSheet *as) {
  3494. // close swipe
  3495. [self setEditing:NO animated:YES];
  3496. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3497. }];
  3498. [actionSheet show];
  3499. }
  3500. }
  3501. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  3502. {
  3503. return NSLocalizedString(@"_delete_", nil);
  3504. }
  3505. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  3506. {
  3507. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3508. if (metadata == nil || metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier >= 0 || metadata.sessionTaskIdentifier >= 0) return NO;
  3509. else return YES;
  3510. }
  3511. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  3512. {
  3513. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3514. if (metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier >= 0 || metadata.sessionTaskIdentifier >= 0) return UITableViewCellEditingStyleNone;
  3515. else return UITableViewCellEditingStyleDelete;
  3516. }
  3517. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  3518. {
  3519. BOOL lockDirectory = NO;
  3520. // Directory locked ?
  3521. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:[CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account] addFileName:_metadata.fileNameData];
  3522. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3523. if (lockDirectory && editingStyle == UITableViewCellEditingStyleDelete) {
  3524. [app messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  3525. return;
  3526. }
  3527. if (editingStyle == UITableViewCellEditingStyleDelete) {
  3528. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3529. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  3530. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  3531. style:UIAlertActionStyleDestructive
  3532. handler:^(UIAlertAction *action) {
  3533. [self performSelector:@selector(deleteFile) withObject:nil];
  3534. }]];
  3535. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  3536. style:UIAlertActionStyleCancel
  3537. handler:^(UIAlertAction *action) {
  3538. [alertController dismissViewControllerAnimated:YES completion:nil];
  3539. }]];
  3540. alertController.popoverPresentationController.sourceView = self.view;
  3541. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  3542. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  3543. [alertController.view layoutIfNeeded];
  3544. [self presentViewController:alertController animated:YES completion:nil];
  3545. }
  3546. }
  3547. #pragma --------------------------------------------------------------------------------------------
  3548. #pragma mark - ==== Datasource ====
  3549. #pragma --------------------------------------------------------------------------------------------
  3550. - (void)clearDateReadDataSource:(NSNotification *)notification
  3551. {
  3552. _dateReadDataSource = Nil;
  3553. [self reloadDatasource];
  3554. }
  3555. - (void)reloadDatasource
  3556. {
  3557. [self reloadDatasource:_serverUrl fileID:nil selector:nil];
  3558. }
  3559. - (void)reloadDatasource:(NSString *)serverUrl fileID:(NSString *)fileID selector:(NSString *)selector
  3560. {
  3561. // test
  3562. if (app.activeAccount.length == 0 || serverUrl.length == 0)
  3563. return;
  3564. // Search Mode
  3565. if(_isSearchMode) {
  3566. if ([selector length] == 0 || [selector isEqualToString:selectorSearch]) {
  3567. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:_searchResultMetadatas listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
  3568. } else {
  3569. [self readFolderWithForced:NO serverUrl:serverUrl];
  3570. }
  3571. [self tableViewReload];
  3572. [self setTitleBackgroundTableView:nil];
  3573. [app updateApplicationIconBadgeNumber];
  3574. return;
  3575. }
  3576. // Reload -> Self se non siamo nella dir appropriata cercala e se è in memoria reindirizza il reload
  3577. if ([serverUrl isEqualToString:_serverUrl] == NO || _serverUrl == nil) {
  3578. if ([selector isEqualToString:selectorDownloadSynchronize]) {
  3579. [app.controlCenterTransfer reloadDatasource];
  3580. } else {
  3581. CCMain *main = [app.listMainVC objectForKey:serverUrl];
  3582. if (main) {
  3583. [main reloadDatasource];
  3584. } else {
  3585. [self tableViewReload];
  3586. [app.controlCenterTransfer reloadDatasource];
  3587. }
  3588. }
  3589. return;
  3590. }
  3591. // Offline folder ?
  3592. _isOfflineServerUrl = [CCCoreData isOfflineDirectoryServerUrl:_serverUrl activeAccount:app.activeAccount];
  3593. [app.controlCenterTransfer reloadDatasource];
  3594. // Settaggio variabili per le ottimizzazioni
  3595. _directoryGroupBy = [CCUtility getGroupBySettings];
  3596. _directoryOrder = [CCUtility getOrderSettings];
  3597. // Controllo data lettura Data Source
  3598. NSDate *dateDateRecordDirectory = [CCCoreData getDateReadDirectoryID:[CCCoreData getDirectoryIDFromServerUrl:_serverUrl activeAccount:app.activeAccount] activeAccount:app.activeAccount];
  3599. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  3600. NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
  3601. _dateReadDataSource = [NSDate date];
  3602. // Data Source
  3603. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount]] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  3604. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
  3605. } else {
  3606. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
  3607. }
  3608. [self tableViewReload];
  3609. [self setTitleBackgroundTableView];
  3610. [app updateApplicationIconBadgeNumber];
  3611. }
  3612. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  3613. {
  3614. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  3615. if (selectedRows.count > 0) {
  3616. for (NSIndexPath *selectionIndex in selectedRows) {
  3617. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  3618. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3619. [metadatas addObject:metadata];
  3620. }
  3621. }
  3622. return metadatas;
  3623. }
  3624. - (CCMetadata *)getMetadataFromSectionDataSource:(NSIndexPath *)indexPath
  3625. {
  3626. NSInteger section = indexPath.section + 1;
  3627. NSInteger row = indexPath.row + 1;
  3628. NSInteger totSections =[_sectionDataSource.sections count] ;
  3629. if ((totSections < section) || (section > totSections)) {
  3630. NSLog(@"[LOG] %@", [NSString stringWithFormat:@"DEBUG [0] : error section, totSections = %lu - section = %lu", (long)totSections, (long)section]);
  3631. return nil;
  3632. }
  3633. id valueSection = [_sectionDataSource.sections objectAtIndex:indexPath.section];
  3634. NSArray *fileIDs = [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3635. if (fileIDs) {
  3636. NSInteger totRows =[fileIDs count] ;
  3637. if ((totRows < row) || (row > totRows)) {
  3638. NSLog(@"[LOG] %@", [NSString stringWithFormat:@"DEBUG [1] : error row, totRows = %lu - row = %lu", (long)totRows, (long)row]);
  3639. return nil;
  3640. }
  3641. } else {
  3642. NSLog(@"[LOG] DEBUG [2] : fileIDs is NIL");
  3643. return nil;
  3644. }
  3645. NSString *fileID = [fileIDs objectAtIndex:indexPath.row];
  3646. return [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3647. }
  3648. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  3649. {
  3650. NSInteger totSections =[_sectionDataSource.sections count] ;
  3651. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  3652. #if DEBUG
  3653. 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];
  3654. [alertView show];
  3655. #endif
  3656. return nil;
  3657. }
  3658. id valueSection = [_sectionDataSource.sections objectAtIndex:section];
  3659. return [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3660. }
  3661. #pragma --------------------------------------------------------------------------------------------
  3662. #pragma mark - ==== Table ====
  3663. #pragma --------------------------------------------------------------------------------------------
  3664. - (void)tableViewSelect:(BOOL)edit
  3665. {
  3666. // chiudiamo eventuali swipe aperti
  3667. if (edit) [self.tableView setEditing:NO animated:NO];
  3668. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  3669. [self.tableView setEditing:edit animated:YES];
  3670. _isSelectedMode = edit;
  3671. if (edit)
  3672. [self setUINavigationBarSelected];
  3673. else
  3674. [self setUINavigationBarDefault];
  3675. [self setTitle];
  3676. }
  3677. - (void)tableViewReload
  3678. {
  3679. // ricordiamoci le row selezionate
  3680. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  3681. [self.tableView reloadData];
  3682. for (NSIndexPath *path in indexPaths)
  3683. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  3684. [self setTableViewFooter];
  3685. if (self.tableView.editing)
  3686. [self setTitle];
  3687. }
  3688. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  3689. {
  3690. return 60;
  3691. }
  3692. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  3693. {
  3694. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  3695. }
  3696. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  3697. {
  3698. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  3699. }
  3700. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  3701. {
  3702. NSArray *sections = [_sectionDataSource.sectionArrayRow allKeys];
  3703. NSString *sectionTitle = [sections objectAtIndex:section];
  3704. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  3705. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  3706. if ([_directoryGroupBy isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
  3707. return 20.f;
  3708. }
  3709. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  3710. {
  3711. float shift;
  3712. UIVisualEffectView *visualEffectView;
  3713. // Titolo
  3714. NSString *titleSection;
  3715. // Controllo
  3716. if ([_sectionDataSource.sections count] == 0)
  3717. return nil;
  3718. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  3719. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  3720. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  3721. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  3722. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  3723. else titleSection = NSLocalizedString(titleSection,nil);
  3724. // Formato titolo
  3725. NSString *currentDevice = [CCUtility currentDevice];
  3726. if ([currentDevice rangeOfString:@"iPad3"].location != NSNotFound) {
  3727. visualEffectView = [[UIVisualEffectView alloc] init];
  3728. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR_NO_BLUR;
  3729. } else {
  3730. UIVisualEffect *blurEffect;
  3731. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  3732. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  3733. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR;
  3734. }
  3735. if ([_directoryGroupBy isEqualToString:@"alphabetic"]) {
  3736. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) shift = - 35;
  3737. else shift = - 20;
  3738. } else shift = - 10;
  3739. // Title
  3740. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  3741. titleLabel.backgroundColor=[UIColor clearColor];
  3742. titleLabel.textColor = COLOR_TEXT_ANTHRACITE;
  3743. titleLabel.font = [UIFont systemFontOfSize:12];
  3744. titleLabel.textAlignment = NSTextAlignmentLeft;
  3745. titleLabel.text = titleSection;
  3746. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3747. [visualEffectView addSubview:titleLabel];
  3748. // Elements
  3749. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  3750. elementLabel.backgroundColor=[UIColor clearColor];
  3751. elementLabel.textColor = COLOR_TEXT_ANTHRACITE;
  3752. elementLabel.font = [UIFont systemFontOfSize:12];
  3753. elementLabel.textAlignment = NSTextAlignmentRight;
  3754. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3755. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  3756. NSUInteger rowsCount = [metadatas count];
  3757. if (rowsCount == 0) return nil;
  3758. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  3759. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  3760. [visualEffectView addSubview:elementLabel];
  3761. return visualEffectView;
  3762. }
  3763. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  3764. {
  3765. return [_sectionDataSource.sections indexOfObject:title];
  3766. }
  3767. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  3768. {
  3769. if ([_directoryGroupBy isEqualToString:@"alphabetic"])
  3770. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  3771. else
  3772. return nil;
  3773. }
  3774. /*
  3775. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  3776. {
  3777. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  3778. }
  3779. }
  3780. */
  3781. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  3782. {
  3783. NSString *typeCell;
  3784. NSString *dataFile;
  3785. NSString *lunghezzaFile;
  3786. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3787. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  3788. if ([metadata.session isEqualToString:@""] || metadata.session == nil) typeCell = @"CellMain";
  3789. else typeCell = @"CellMainTransfer";
  3790. if (!metadata)
  3791. return [tableView dequeueReusableCellWithIdentifier:typeCell];
  3792. CCCellMainTransfer *cell = (CCCellMainTransfer *)[tableView dequeueReusableCellWithIdentifier:typeCell forIndexPath:indexPath];
  3793. // separator
  3794. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  3795. // change color selection
  3796. UIView *selectionColor = [[UIView alloc] init];
  3797. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  3798. cell.selectedBackgroundView = selectionColor;
  3799. if ([typeCell isEqualToString:@"CellMain"]) cell.backgroundColor = [UIColor whiteColor];
  3800. if ([typeCell isEqualToString:@"CellMainTransfer"]) cell.backgroundColor = COLOR_TRANSFER_BACKGROUND;
  3801. // ----------------------------------------------------------------------------------------------------------
  3802. // DEFAULT
  3803. // ----------------------------------------------------------------------------------------------------------
  3804. cell.fileImageView.image = nil;
  3805. cell.statusImageView.image = nil;
  3806. cell.offlineImageView.image = nil;
  3807. cell.synchronizedImageView.image = nil;
  3808. cell.sharedImageView.image = nil;
  3809. cell.labelTitle.enabled = YES;
  3810. cell.labelTitle.text = @"";
  3811. cell.labelInfoFile.enabled = YES;
  3812. cell.labelInfoFile.text = @"";
  3813. cell.progressView.progress = 0.0;
  3814. cell.progressView.hidden = YES;
  3815. cell.cancelTaskButton.hidden = YES;
  3816. cell.reloadTaskButton.hidden = YES;
  3817. cell.stopTaskButton.hidden = YES;
  3818. // colori e font
  3819. if (metadata.cryptated) {
  3820. cell.labelTitle.textColor = COLOR_CRYPTOCLOUD;
  3821. cell.labelInfoFile.textColor = [UIColor blackColor];
  3822. } else {
  3823. cell.labelTitle.textColor = COLOR_TEXT_ANTHRACITE;
  3824. cell.labelInfoFile.textColor = [UIColor blackColor];
  3825. }
  3826. // ----------------------------------------------------------------------------------------------------------
  3827. // File Name & Folder
  3828. // ----------------------------------------------------------------------------------------------------------
  3829. // nome del file
  3830. cell.labelTitle.text = metadata.fileNamePrint;
  3831. // è una directory
  3832. if (metadata.directory) {
  3833. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3834. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  3835. lunghezzaFile = @" ";
  3836. // ----------------------------------------------------------------------------------------------------------
  3837. // Offline Folder
  3838. // ----------------------------------------------------------------------------------------------------------
  3839. NSString *directoryServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
  3840. BOOL isOfflineDirectory = [CCCoreData isOfflineDirectoryServerUrl:directoryServerUrl activeAccount:app.activeAccount];
  3841. // Verify Offline
  3842. if (_isOfflineServerUrl == YES && isOfflineDirectory == NO) {
  3843. [CCCoreData setOfflineDirectoryServerUrl:directoryServerUrl offline:YES activeAccount:app.activeAccount];
  3844. isOfflineDirectory = YES;
  3845. }
  3846. if (isOfflineDirectory) {
  3847. cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  3848. }
  3849. // ----------------------------------------------------------------------------------------------------------
  3850. // Favorite Folder
  3851. // ----------------------------------------------------------------------------------------------------------
  3852. if (metadata.favorite) {
  3853. cell.offlineImageView.image = [UIImage imageNamed:image_favorite];
  3854. }
  3855. // Animation synchronized gif
  3856. if ([[CCSynchronize sharedSynchronize] synchronizeFolderAnimationDirectory:[[NSArray alloc] initWithObjects:directoryServerUrl, nil] setGraphicsFolder:NO]) {
  3857. NSURL *myURL;
  3858. if (metadata.cryptated) myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  3859. else myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  3860. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  3861. }
  3862. } else {
  3863. // è un file
  3864. dataFile = [CCUtility dateDiff:metadata.date];
  3865. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  3866. // Plist ancora da scaricare
  3867. if (metadata.cryptated && [metadata.title length] == 0) {
  3868. dataFile = @" ";
  3869. lunghezzaFile = @" ";
  3870. }
  3871. TableLocalFile *recordLocalFile = [CCCoreData getLocalFileWithFileID:metadata.fileID activeAccount:app.activeAccount];
  3872. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3873. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  3874. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  3875. if ([metadata.type isEqualToString: k_metadataType_template] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO)
  3876. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", dataFile];
  3877. if ([metadata.type isEqualToString: k_metadataType_file] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO) {
  3878. if (recordLocalFile && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
  3879. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", dataFile, lunghezzaFile];
  3880. else
  3881. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ ◦ %@", dataFile, lunghezzaFile];
  3882. }
  3883. // Plist ancora da scaricare
  3884. if ([dataFile isEqualToString:@" "] && [lunghezzaFile isEqualToString:@" "])
  3885. cell.labelInfoFile.text = NSLocalizedString(@"_no_plist_pull_down_",nil);
  3886. cell.accessoryType = UITableViewCellAccessoryNone;
  3887. }
  3888. // ----------------------------------------------------------------------------------------------------------
  3889. // File Image View
  3890. // ----------------------------------------------------------------------------------------------------------
  3891. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3892. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  3893. cell.fileImageView.image = [app.icoImagesCache objectForKey:metadata.fileID];
  3894. if (cell.fileImageView.image == nil) {
  3895. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  3896. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  3897. [app.icoImagesCache setObject:image forKey:metadata.fileID];
  3898. dispatch_async(dispatch_get_main_queue(), ^{
  3899. CCCellMainTransfer *cell = [tableView cellForRowAtIndexPath:indexPath];
  3900. if (cell)
  3901. cell.fileImageView.image = image;
  3902. });
  3903. });
  3904. }
  3905. } else {
  3906. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  3907. if (metadata.thumbnailExists)
  3908. [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
  3909. }
  3910. // ----------------------------------------------------------------------------------------------------------
  3911. // Image Status cyptated & Lock Passcode
  3912. // ----------------------------------------------------------------------------------------------------------
  3913. // File Cyptated
  3914. if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_template] == NO) {
  3915. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  3916. }
  3917. // Directory con passcode lock attivato
  3918. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
  3919. if (metadata.directory && ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length])) cell.statusImageView.image = [UIImage imageNamed:image_passcode];
  3920. // ----------------------------------------------------------------------------------------------------------
  3921. // Offline
  3922. // ----------------------------------------------------------------------------------------------------------
  3923. BOOL isOfflineFile = [CCCoreData isOfflineLocalFileID:metadata.fileID activeAccount:app.activeAccount];
  3924. if (isOfflineFile) {
  3925. cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  3926. }
  3927. // ----------------------------------------------------------------------------------------------------------
  3928. // Favorite
  3929. // ----------------------------------------------------------------------------------------------------------
  3930. if (metadata.favorite) {
  3931. cell.offlineImageView.image = [UIImage imageNamed:image_favorite];
  3932. }
  3933. // ----------------------------------------------------------------------------------------------------------
  3934. // Share
  3935. // ----------------------------------------------------------------------------------------------------------
  3936. NSString *shareLink = [app.sharesLink objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
  3937. NSString *shareUserAndGroup = [app.sharesUserAndGroup objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
  3938. BOOL isShare = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_shared].location == NSNotFound);
  3939. BOOL isMounted = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_mounted].location == NSNotFound);
  3940. // Aggiungiamo il Tap per le shared
  3941. if (isShare || [shareLink length] > 0 || [shareUserAndGroup length] > 0 || isMounted) {
  3942. if (isShare) {
  3943. cell.sharedImageView.image = [UIImage imageNamed:image_shareConnect];
  3944. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3945. [tap setNumberOfTapsRequired:1];
  3946. cell.sharedImageView.userInteractionEnabled = YES;
  3947. [cell.sharedImageView addGestureRecognizer:tap];
  3948. }
  3949. if (isMounted) {
  3950. cell.sharedImageView.image = [UIImage imageNamed:image_shareMounted];
  3951. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3952. [tap setNumberOfTapsRequired:1];
  3953. cell.sharedImageView.userInteractionEnabled = YES;
  3954. [cell.sharedImageView addGestureRecognizer:tap];
  3955. }
  3956. if ([shareLink length] > 0 || [shareUserAndGroup length] > 0) {
  3957. if ([shareLink length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareLink];
  3958. if ([shareUserAndGroup length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareUser];
  3959. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  3960. [tap setNumberOfTapsRequired:1];
  3961. cell.sharedImageView.userInteractionEnabled = YES;
  3962. [cell.sharedImageView addGestureRecognizer:tap];
  3963. }
  3964. } else {
  3965. cell.sharedImageView.userInteractionEnabled = NO;
  3966. }
  3967. // ----------------------------------------------------------------------------------------------------------
  3968. // downloadFile
  3969. // ----------------------------------------------------------------------------------------------------------
  3970. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  3971. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusdownloadcrypto];
  3972. else cell.statusImageView.image = [UIImage imageNamed:image_statusdownload];
  3973. // sessionTaskIdentifier : RELOAD + STOP
  3974. if (metadata.sessionTaskIdentifier != k_taskIdentifierDone) {
  3975. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  3976. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  3977. cell.cancelTaskButton.hidden = NO;
  3978. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3979. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3980. cell.reloadTaskButton.hidden = NO;
  3981. }
  3982. // sessionTaskIdentifierPlist : RELOAD
  3983. if (metadata.sessionTaskIdentifierPlist != k_taskIdentifierDone) {
  3984. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3985. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3986. cell.reloadTaskButton.hidden = NO;
  3987. }
  3988. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3989. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3990. if (progress > 0) {
  3991. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  3992. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  3993. cell.progressView.progress = progress;
  3994. cell.progressView.hidden = NO;
  3995. }
  3996. // ----------------------------------------------------------------------------------------------------------
  3997. // downloadFile Error
  3998. // ----------------------------------------------------------------------------------------------------------
  3999. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  4000. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  4001. if ([metadata.sessionError length] == 0)
  4002. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  4003. else
  4004. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  4005. }
  4006. }
  4007. // ----------------------------------------------------------------------------------------------------------
  4008. // uploadFile
  4009. // ----------------------------------------------------------------------------------------------------------
  4010. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  4011. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusuploadcrypto];
  4012. else cell.statusImageView.image = [UIImage imageNamed:image_statusupload];
  4013. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetaskcrypto] forState:UIControlStateNormal];
  4014. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetask] forState:UIControlStateNormal];
  4015. cell.cancelTaskButton.hidden = NO;
  4016. if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
  4017. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  4018. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  4019. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusstopcrypto];
  4020. else cell.statusImageView.image = [UIImage imageNamed:image_statusstop];
  4021. cell.reloadTaskButton.hidden = NO;
  4022. cell.stopTaskButton.hidden = YES;
  4023. } else {
  4024. if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  4025. else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  4026. cell.stopTaskButton.hidden = NO;
  4027. cell.reloadTaskButton.hidden = YES;
  4028. }
  4029. // se non c'è una preview in bianconero metti l'immagine di default
  4030. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  4031. cell.fileImageView.image = [UIImage imageNamed:image_uploaddisable];
  4032. cell.labelTitle.enabled = NO;
  4033. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  4034. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  4035. if (progress > 0) {
  4036. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  4037. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  4038. cell.progressView.progress = progress;
  4039. cell.progressView.hidden = NO;
  4040. }
  4041. // ----------------------------------------------------------------------------------------------------------
  4042. // uploadFileError
  4043. // ----------------------------------------------------------------------------------------------------------
  4044. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  4045. cell.labelTitle.enabled = NO;
  4046. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  4047. if ([metadata.sessionError length] == 0)
  4048. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  4049. else
  4050. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  4051. }
  4052. }
  4053. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  4054. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  4055. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  4056. return cell;
  4057. }
  4058. - (void)setTableViewFooter
  4059. {
  4060. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  4061. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  4062. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  4063. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  4064. UIFont *appFont = [UIFont systemFontOfSize:12];
  4065. footerLabel.font = appFont;
  4066. footerLabel.textColor = [UIColor grayColor];
  4067. footerLabel.backgroundColor = [UIColor clearColor];
  4068. footerLabel.textAlignment = NSTextAlignmentCenter;
  4069. NSString *folders;
  4070. NSString *files;
  4071. NSString *footerText;
  4072. if (_sectionDataSource.directories > 1) {
  4073. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  4074. } else if (_sectionDataSource.directories == 1){
  4075. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  4076. } else {
  4077. folders = @"";
  4078. }
  4079. if (_sectionDataSource.files > 1) {
  4080. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  4081. } else if (_sectionDataSource.files == 1){
  4082. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  4083. } else {
  4084. files = @"";
  4085. }
  4086. if ([folders isEqualToString:@""]) {
  4087. footerText = files;
  4088. } else if ([files isEqualToString:@""]) {
  4089. footerText = folders;
  4090. } else {
  4091. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  4092. }
  4093. footerLabel.text = footerText;
  4094. [footerView addSubview:footerLabel];
  4095. [self.tableView setTableFooterView:footerView];
  4096. }
  4097. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  4098. {
  4099. NSString *textMessage;
  4100. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  4101. // se non può essere selezionata deseleziona
  4102. if ([cell isEditing] == NO)
  4103. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  4104. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  4105. if (self.tableView.editing) {
  4106. [self setTitle];
  4107. return;
  4108. }
  4109. // test crash
  4110. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
  4111. if (indexPath.row >= [metadatas count]) return;
  4112. // settiamo il record file.
  4113. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  4114. //
  4115. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  4116. // se è in corso una sessione
  4117. if ([_metadata.session length] > 0) return;
  4118. if (_metadata.errorPasscode) {
  4119. // se UUID è nil lo sta ancora caricando quindi esci
  4120. if (!_metadata.uuid) return;
  4121. // esiste un hint ??
  4122. NSString *hint = [[CCCrypto sharedManager] getHintFromFile:_metadata.fileName isLocal:NO directoryUser:app.directoryUser];
  4123. // qui !! la richiesta della nuova passcode
  4124. if ([_metadata.uuid isEqualToString:[CCUtility getUUID]]) {
  4125. // stesso UUID ... la password è stata modificata !!!!!!
  4126. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_same_device_different_passcode_hint_",nil), hint];
  4127. else textMessage = NSLocalizedString(@"_same_device_different_passcode_", nil);
  4128. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  4129. [alertView show];
  4130. } else {
  4131. // UUID diverso.
  4132. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_hint_",nil), _metadata.nameCurrentDevice, hint];
  4133. else textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_",nil), _metadata.nameCurrentDevice];
  4134. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  4135. [alertView show];
  4136. }
  4137. // chiediamo la passcode e ricarichiamo tutto.
  4138. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  4139. viewController.delegate = self;
  4140. viewController.fromType = CCBKPasscodeFromPasscode;
  4141. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  4142. viewController.passcodeInputView.maximumLength = 64;
  4143. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  4144. viewController.inputViewTitlePassword = NO;
  4145. viewController.title = _brand_;
  4146. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  4147. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  4148. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  4149. [self presentViewController:navigationController animated:YES completion:nil];
  4150. }
  4151. // modello o plist con il title a 0 allora è andato storto qualcosa ... ricaricalo
  4152. if (_metadata.cryptated && [_metadata.title length] == 0) {
  4153. NSString* selector;
  4154. if ([_metadata.type isEqualToString: k_metadataType_template]) selector = selectorLoadModelView;
  4155. else selector = selectorLoadPlist;
  4156. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:serverUrl downloadData:NO downloadPlist:YES selector:selector selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  4157. return;
  4158. }
  4159. // se il plist è caricato ed è un modello aprilo
  4160. if ([_metadata.type isEqualToString:k_metadataType_template]) [self openModel:_metadata.model isNew:false];
  4161. // file
  4162. if (_metadata.directory == NO && _metadata.errorPasscode == NO && [_metadata.type isEqualToString: k_metadataType_file]) {
  4163. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  4164. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
  4165. [self downloadFileSuccess:_metadata.fileID serverUrl:serverUrl selector:selectorLoadFileView selectorPost:nil];
  4166. } else {
  4167. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadFileView selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  4168. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  4169. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  4170. }
  4171. }
  4172. if (_metadata.directory) [self performSegueDirectoryWithControlPasscode:true];
  4173. }
  4174. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  4175. {
  4176. [self setTitle];
  4177. }
  4178. #pragma --------------------------------------------------------------------------------------------
  4179. #pragma mark ===== Synchronize Folder Cell =====
  4180. #pragma --------------------------------------------------------------------------------------------
  4181. - (void)synchronizeFolderGraphicsServerUrl:(NSString *)serverUrl animation:(BOOL)animation
  4182. {
  4183. BOOL cryptated = NO;
  4184. CCCellMain *cell;
  4185. for (NSString* fileID in _sectionDataSource.allRecordsDataSource) {
  4186. CCMetadata *recordMetadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4187. if (recordMetadata.directory == NO)
  4188. continue;
  4189. if ([[CCUtility stringAppendServerUrl:_serverUrl addFileName:recordMetadata.fileNameData] isEqualToString:serverUrl]) {
  4190. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:recordMetadata.fileID];
  4191. cell = (CCCellMain *)[self.tableView cellForRowAtIndexPath:indexPath];
  4192. cryptated = recordMetadata.cryptated;
  4193. break;
  4194. }
  4195. }
  4196. if (!cell)
  4197. return;
  4198. if (animation) {
  4199. NSURL *myURL;
  4200. if (cryptated)
  4201. myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  4202. else
  4203. myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  4204. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  4205. } else {
  4206. cell.synchronizedImageView.image = nil;
  4207. }
  4208. }
  4209. #pragma --------------------------------------------------------------------------------------------
  4210. #pragma mark ===== Navigation ====
  4211. #pragma --------------------------------------------------------------------------------------------
  4212. - (BOOL)shouldPerformSegue:(NSString *)serverUrl
  4213. {
  4214. // if background return
  4215. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  4216. if (self.view.window == NO)
  4217. return NO;
  4218. // Collapsed ma siamo già in detail esci
  4219. if (self.splitViewController.isCollapsed)
  4220. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return NO;
  4221. // Video in esecuzione esci
  4222. if (_detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && _detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  4223. return YES;
  4224. }
  4225. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  4226. {
  4227. id viewController = segue.destinationViewController;
  4228. if ([viewController isKindOfClass:[UINavigationController class]]) {
  4229. UINavigationController *nav = viewController;
  4230. _detailViewController = (CCDetail *)nav.topViewController;
  4231. } else {
  4232. _detailViewController = segue.destinationViewController;
  4233. }
  4234. NSMutableArray *allRecordsDataSourceImagesVideos = [[NSMutableArray alloc] init];
  4235. for (NSString *fileID in _sectionDataSource.allFileID) {
  4236. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4237. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
  4238. [allRecordsDataSourceImagesVideos addObject:metadata];
  4239. }
  4240. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  4241. _detailViewController.metadataDetail = _metadataSegue;
  4242. _detailViewController.dateFilterQuery = nil;
  4243. _detailViewController.isCameraUpload = NO;
  4244. [_detailViewController setTitle:_metadata.fileNamePrint];
  4245. }
  4246. // can i go to next viewcontroller
  4247. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode
  4248. {
  4249. NSString *nomeDir;
  4250. if(self.tableView.editing == NO && _metadata.errorPasscode == NO){
  4251. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  4252. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  4253. // 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
  4254. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil && controlPasscode) {
  4255. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  4256. viewController.delegate = self;
  4257. viewController.fromType = CCBKPasscodeFromLockDirectory;
  4258. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  4259. viewController.inputViewTitlePassword = YES;
  4260. if ([CCUtility getSimplyBlockCode]) {
  4261. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  4262. viewController.passcodeInputView.maximumLength = 6;
  4263. } else {
  4264. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  4265. viewController.passcodeInputView.maximumLength = 64;
  4266. }
  4267. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  4268. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  4269. viewController.touchIDManager = touchIDManager;
  4270. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  4271. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  4272. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_CRYPTOCLOUD;
  4273. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
  4274. [self presentViewController:navController animated:YES completion:nil];
  4275. return;
  4276. }
  4277. if (_metadata.cryptated) nomeDir = [_metadata.fileName substringToIndex:[_metadata.fileName length]-6];
  4278. else nomeDir = _metadata.fileName;
  4279. NSString *serverUrlPush = [CCUtility stringAppendServerUrl:serverUrl addFileName:nomeDir];
  4280. CCMain *viewController = [app.listMainVC objectForKey:serverUrlPush];
  4281. if (viewController.isViewLoaded == false) {
  4282. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMainVC"];
  4283. viewController.isFolderEncrypted = _metadata.cryptated;
  4284. viewController.serverUrl = serverUrlPush;
  4285. viewController.titleMain = _metadata.fileNamePrint;
  4286. viewController.textBackButton = _titleMain;
  4287. // save self
  4288. [app.listMainVC setObject:viewController forKey:serverUrlPush];
  4289. }
  4290. // OFF SearchBar
  4291. [viewController cancelSearchBar];
  4292. [self.navigationController pushViewController:viewController animated:YES];
  4293. }
  4294. }
  4295. @end