CCMain.m 262 KB

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