CCMain.m 266 KB

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