CCMain.m 266 KB

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