CCMain.m 271 KB

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