CCMain.m 263 KB

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