CCMain.m 264 KB

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