CCMain.m 260 KB

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