CCMain.m 264 KB

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