CCMain.m 261 KB

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