CCMain.m 255 KB

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