CCMain.m 262 KB

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