CCMain.m 258 KB

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