CCMain.m 263 KB

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