CCMain.m 255 KB

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