CCMain.m 254 KB

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