CCMain.m 265 KB

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