CCMain.m 264 KB

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