CCMain.m 270 KB

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