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 = NO;
  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. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  1317. // File is changed ??
  1318. BOOL offline = [CCCoreData isOfflineDirectoryServerUrl:_localServerUrl activeAccount:app.activeAccount];
  1319. [[CCOfflineFileFolder sharedOfflineFileFolder] verifyChangeMedatas:metadatas serverUrl:metadataNet.serverUrl directoryID:metadataNet.directoryID account:app.activeAccount offline:offline];
  1320. });
  1321. // this is the same directory
  1322. if ([metadataNet.serverUrl isEqualToString:_localServerUrl]) {
  1323. // reload
  1324. [self getDataSourceWithReloadTableView:metadataNet.directoryID fileID:nil selector:metadataNet.selector];
  1325. // stoprefresh
  1326. [_ccRefreshControl endRefreshing];
  1327. // Enable change user
  1328. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  1329. [_hud hideHud];
  1330. }
  1331. }
  1332. - (void)readFolderWithForced:(BOOL)forced
  1333. {
  1334. [self setTitleBackgroundTableView:nil];
  1335. // init control
  1336. if (!_localServerUrl || !app.activeAccount)
  1337. return;
  1338. if (([CCCoreData isDirectoryOutOfDate:dayForceReadFolder directoryID:_localDirectoryID activeAccount:app.activeAccount] || forced) && _localDirectoryID && app.activeAccount) {
  1339. if (_ccRefreshControl.isRefreshing == NO)
  1340. [_hud visibleIndeterminateHud];
  1341. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1342. metadataNet.action = actionReadFolder;
  1343. metadataNet.date = [NSDate date];
  1344. metadataNet.directoryID = _localDirectoryID;
  1345. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1346. metadataNet.selector = selectorReadFolder;
  1347. metadataNet.serverUrl = [CCCoreData getServerUrlFromDirectoryID:_localDirectoryID activeAccount:app.activeAccount];
  1348. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1349. } else {
  1350. if ([_sectionDataSource.allRecordsDataSource count] == 0) [self setTitleBackgroundTableView:NSLocalizedString(@"_no_file_pull_down_",nil)];
  1351. else [self setTitleBackgroundTableView:nil];
  1352. }
  1353. }
  1354. #pragma --------------------------------------------------------------------------------------------
  1355. #pragma mark ===== Delete File or Folder =====
  1356. #pragma --------------------------------------------------------------------------------------------
  1357. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1358. {
  1359. [_hud hideHud];
  1360. if (errorCode == 404)
  1361. [self deleteFileOrFolderSuccess:metadataNet];
  1362. if (message)
  1363. [app messageNotification:@"_delete_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1364. // is detailViewController active ?
  1365. if (_detailViewController) {
  1366. dispatch_async(dispatch_get_main_queue(), ^{
  1367. [_detailViewController deleteFileFailure:errorCode];
  1368. });
  1369. }
  1370. [_selectedMetadatas removeAllObjects];
  1371. [_queueSelector removeAllObjects];
  1372. }
  1373. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  1374. {
  1375. [_queueSelector removeObject:metadataNet.selector];
  1376. if ([_queueSelector count] == 0) {
  1377. [_hud hideHud];
  1378. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  1379. if (metadata) {
  1380. [CCCoreData deleteFile:metadata serverUrl:metadataNet.serverUrl directoryUser:app.directoryUser typeCloud:app.typeCloud activeAccount:app.activeAccount];
  1381. // Carico la Folder o il Datasource
  1382. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
  1383. [self readFolderWithForced:YES];
  1384. } else {
  1385. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:metadataNet.selector];
  1386. }
  1387. }
  1388. // if detailViewController
  1389. if (_detailViewController) {
  1390. dispatch_async(dispatch_get_main_queue(), ^{
  1391. [_detailViewController deleteFileSuccess:metadata metadataNetVar:metadataNet];
  1392. });
  1393. }
  1394. // next
  1395. if ([_selectedMetadatas count] > 0) {
  1396. [_selectedMetadatas removeObjectAtIndex:0];
  1397. if ([_selectedMetadatas count] > 0)
  1398. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1399. }
  1400. }
  1401. }
  1402. - (void)deleteFileOrFolder:(CCMetadata *)metadata numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
  1403. {
  1404. if (metadata.cryptated == YES) {
  1405. // Cryptated
  1406. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1407. metadataNet.action = actionDeleteFileDirectory;
  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.fileID = metadata.fileID;
  1426. metadataNet.fileName = metadata.fileName;
  1427. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1428. metadataNet.selector = selectorDelete;
  1429. metadataNet.serverUrl = _localServerUrl;
  1430. [_queueSelector addObject:metadataNet.selector];
  1431. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1432. }
  1433. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_delete_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1434. }
  1435. - (void)deleteSelectionFile
  1436. {
  1437. [_selectedMetadatas removeAllObjects];
  1438. [_queueSelector removeAllObjects];
  1439. _selectedMetadatas = [[NSMutableArray alloc] initWithArray: [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]]];
  1440. _numSelectedMetadatas = [_selectedMetadatas count];
  1441. if ([_selectedMetadatas count] > 0)
  1442. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1443. [self tableViewSelect:NO];
  1444. }
  1445. - (void)deleteFile
  1446. {
  1447. [_selectedMetadatas removeAllObjects];
  1448. [_queueSelector removeAllObjects];
  1449. _numSelectedMetadatas = 1;
  1450. [_selectedMetadatas addObject:_metadata];
  1451. if ([_selectedMetadatas count] > 0)
  1452. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1453. [self tableViewSelect:NO];
  1454. }
  1455. #pragma --------------------------------------------------------------------------------------------
  1456. #pragma mark ===== Rename =====
  1457. #pragma --------------------------------------------------------------------------------------------
  1458. - (void)renameSuccess:(CCMetadataNet *)metadataNet revTo:(NSString *)revTo
  1459. {
  1460. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  1461. if (metadata.directory == YES)
  1462. [CCCoreData renameDirectory:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadataNet.fileName] serverUrlTo:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadataNet.fileNameTo] activeAccount:app.activeAccount];
  1463. else
  1464. [CCCoreData renameLocalFileWithFileID:metadata.fileID fileNameTo:metadataNet.fileNameTo fileNamePrintTo:metadataNet.fileNameTo activeAccount:app.activeAccount];
  1465. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced])
  1466. [self readFolderWithForced:YES];
  1467. }
  1468. - (void)renameFile:(CCMetadata *)metadata fileName:(NSString *)fileName
  1469. {
  1470. NSString *fileNameTo, *newTitleTo;
  1471. CCCrypto *crypto = [[CCCrypto alloc] init];
  1472. fileNameTo = [CCUtility removeForbiddenCharacters:fileName];
  1473. if (![fileNameTo length]) return;
  1474. if ([metadata.fileNamePrint isEqualToString:fileNameTo]) return;
  1475. // Plain
  1476. if (metadata.cryptated == NO) {
  1477. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1478. metadataNet.action = actionMoveFileOrFolder;
  1479. metadataNet.fileID = metadata.fileID;
  1480. metadataNet.fileName = metadata.fileName;
  1481. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1482. metadataNet.fileNameTo = fileNameTo;
  1483. metadataNet.selector = selectorRename;
  1484. metadataNet.selectorPost = selectorReadFolderForced;
  1485. metadataNet.serverUrl = _localServerUrl;
  1486. metadataNet.serverUrlTo = _localServerUrl;
  1487. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1488. } else {
  1489. // Change only the contenent of plist, then upload it
  1490. newTitleTo = [AESCrypt encrypt:fileNameTo password:[crypto getKeyPasscode:metadata.uuid]];
  1491. if ([crypto updateTitleFilePlist:metadata.fileName title:newTitleTo directoryUser:app.directoryUser] == NO) {
  1492. NSLog(@"[LOG] Rename cryptated error %@", fileName);
  1493. [app messageNotification:@"_rename_" description:@"_file_not_found_reload_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1494. return;
  1495. }
  1496. if (metadata.directory == NO) {
  1497. // cripto il file fileID in temp
  1498. NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]];
  1499. if (data) data = [RNEncryptor encryptData:data withSettings:kRNCryptorAES256Settings password:[crypto getKeyPasscode:metadata.uuid] error:nil];
  1500. if (data) [data writeToFile:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameData] atomically:YES];
  1501. }
  1502. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1503. metadataNet.action = actionUploadOnlyPlist;
  1504. metadataNet.fileName = metadata.fileName;
  1505. metadataNet.selectorPost = selectorReadFolderForced;
  1506. metadataNet.serverUrl = _localServerUrl;
  1507. metadataNet.session = upload_session_foreground;
  1508. metadataNet.taskStatus = taskStatusResume;
  1509. if ([CCCoreData isOfflineLocalFileID:metadata.fileID activeAccount:app.activeAccount])
  1510. metadataNet.selectorPost = selectorAddOffline;
  1511. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1512. // delete file in filesystem
  1513. [CCCoreData deleteFile:metadata serverUrl:_localServerUrl directoryUser:app.directoryUser typeCloud:app.typeCloud activeAccount:app.activeAccount];
  1514. }
  1515. }
  1516. - (void)renameNote:(CCMetadata *)metadata fileName:(NSString *)fileName
  1517. {
  1518. CCTemplates *templates = [[CCTemplates alloc] init];
  1519. CCCrypto *crypto = [[CCCrypto alloc] init];
  1520. NSMutableDictionary *field = [crypto getDictionaryEncrypted:metadata.fileName uuid:metadata.uuid isLocal:NO directoryUser:app.directoryUser];
  1521. NSString *fileNameModel = [templates salvaNote:[field objectForKey:@"note"] titolo:fileName fileName:metadata.fileName uuid:metadata.uuid];
  1522. if (fileNameModel) {
  1523. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1524. metadataNet.action = actionUploadTemplate;
  1525. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  1526. metadataNet.fileNamePrint = fileName;
  1527. metadataNet.rev = metadata.rev;
  1528. metadataNet.serverUrl = _localServerUrl;
  1529. metadataNet.session = upload_session_foreground;
  1530. metadataNet.taskStatus = taskStatusResume;
  1531. if ([CCCoreData isOfflineLocalFileID:metadata.fileID activeAccount:app.activeAccount])
  1532. metadataNet.selectorPost = selectorAddOffline;
  1533. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1534. }
  1535. }
  1536. #pragma --------------------------------------------------------------------------------------------
  1537. #pragma mark ===== Move =====
  1538. #pragma --------------------------------------------------------------------------------------------
  1539. - (void)moveFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1540. {
  1541. [_hud hideHud];
  1542. if (message)
  1543. [app messageNotification:@"_move_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1544. [_selectedMetadatas removeAllObjects];
  1545. [_queueSelector removeAllObjects];
  1546. }
  1547. - (void)moveSuccess:(CCMetadataNet *)metadataNet revTo:(NSString *)revTo
  1548. {
  1549. [_queueSelector removeObject:metadataNet.selector];
  1550. if ([_queueSelector count] == 0) {
  1551. [_hud hideHud];
  1552. NSString *fileName = [CCUtility trasformedFileNameCryptoInPlist:metadataNet.fileName];
  1553. NSString *directoryID = metadataNet.directoryID;
  1554. NSString *directoryIDTo = metadataNet.directoryIDTo;
  1555. NSString *serverUrlTo = [CCCoreData getServerUrlFromDirectoryID:directoryIDTo activeAccount:app.activeAccount];
  1556. // FILE -> Metadata
  1557. if (metadataNet.directory == NO) {
  1558. // move metadata
  1559. [CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
  1560. // Check Offline
  1561. if ([CCCoreData isOfflineDirectoryServerUrl:serverUrlTo activeAccount:app.activeAccount])
  1562. [CCCoreData setOfflineLocalFileID:metadataNet.fileID offline:YES activeAccount:app.activeAccount];
  1563. }
  1564. // DIRECTORY -> Directory - CCMetadata
  1565. if (metadataNet.directory == YES) {
  1566. // delete all dir / subdir
  1567. NSArray *directoryIDs = [CCCoreData deleteDirectoryAndSubDirectory:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:fileName] activeAccount:app.activeAccount];
  1568. // delete all metadata and local file in dir / subdir
  1569. for (NSString *directoryIDDelete in directoryIDs)
  1570. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(directoryID == %@)AND (account == %@)",directoryIDDelete, app.activeAccount]];
  1571. // move metadata
  1572. [CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
  1573. // Add new directory
  1574. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrlTo, fileName];
  1575. [CCCoreData addDirectory:newDirectory date:[NSDate date] permissions:nil activeAccount:app.activeAccount];
  1576. // Check Offline
  1577. if ([CCCoreData isOfflineDirectoryServerUrl:serverUrlTo activeAccount:app.activeAccount])
  1578. [CCCoreData setOfflineDirectoryServerUrl:newDirectory offline:YES activeAccount:app.activeAccount];
  1579. }
  1580. // reload Datasource
  1581. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced])
  1582. [self readFolderWithForced:YES];
  1583. else
  1584. [self getDataSourceWithReloadTableView];
  1585. // Next file
  1586. [_selectedMetadatas removeObjectAtIndex:0];
  1587. [self moveFileOrFolder:metadataNet.serverUrlTo];
  1588. }
  1589. }
  1590. - (void)moveFileOrFolder:(NSString *)serverUrlTo
  1591. {
  1592. if ([_selectedMetadatas count] > 0) {
  1593. CCMetadata *metadata = [_selectedMetadatas objectAtIndex:0];
  1594. // Plain
  1595. if (metadata.cryptated == NO) {
  1596. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1597. metadataNet.action = actionMoveFileOrFolder;
  1598. metadataNet.directory = metadata.directory;
  1599. metadataNet.fileID = metadata.fileID;
  1600. metadataNet.directoryID = _localDirectoryID;
  1601. metadataNet.directoryIDTo = [CCCoreData getDirectoryIDFromServerUrl:serverUrlTo activeAccount:app.activeAccount];
  1602. metadataNet.fileName = metadata.fileName;
  1603. metadataNet.fileNamePrint = metadataNet.fileNamePrint;
  1604. metadataNet.fileNameTo = metadata.fileName;
  1605. metadataNet.rev = metadata.rev;
  1606. metadataNet.selector = selectorMove;
  1607. metadataNet.serverUrl = _localServerUrl;
  1608. metadataNet.serverUrlTo = serverUrlTo;
  1609. [_queueSelector addObject:metadataNet.selector];
  1610. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1611. }
  1612. // cyptated
  1613. if (metadata.cryptated == YES) {
  1614. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1615. metadataNet.action = actionMoveFileOrFolder;
  1616. metadataNet.directory = metadata.directory;
  1617. metadataNet.fileID = metadata.fileID;
  1618. metadataNet.directoryID = _localDirectoryID;
  1619. metadataNet.directoryIDTo = [CCCoreData getDirectoryIDFromServerUrl:serverUrlTo activeAccount:app.activeAccount];
  1620. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1621. metadataNet.rev = metadata.rev;
  1622. metadataNet.serverUrl = _localServerUrl;
  1623. metadataNet.serverUrlTo = serverUrlTo;
  1624. // data
  1625. metadataNet.fileName = metadata.fileNameData;
  1626. metadataNet.fileNameTo = metadata.fileNameData;
  1627. metadataNet.selector = selectorMoveCrypto;
  1628. [_queueSelector addObject:metadataNet.selector];
  1629. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1630. // plist
  1631. metadataNet.fileName = metadata.fileName;
  1632. metadataNet.fileNameTo = metadata.fileName;
  1633. metadataNet.selector = selectorMovePlist;
  1634. [_queueSelector addObject:metadataNet.selector];
  1635. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1636. }
  1637. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), _numSelectedMetadatas - [_selectedMetadatas count] + 1, _numSelectedMetadatas] mode:MBProgressHUDModeIndeterminate color:nil];
  1638. }
  1639. }
  1640. - (void)move:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
  1641. {
  1642. // Test
  1643. if ([_localServerUrl isEqualToString:serverUrlTo]) {
  1644. [self tableViewSelect:NO];
  1645. return;
  1646. }
  1647. [_selectedMetadatas removeAllObjects];
  1648. [_queueSelector removeAllObjects];
  1649. _selectedMetadatas = [[NSMutableArray alloc] initWithArray:selectedMetadatas];
  1650. _numSelectedMetadatas = [_selectedMetadatas count];
  1651. [self moveFileOrFolder:serverUrlTo];
  1652. [self tableViewSelect:NO];
  1653. }
  1654. - (void)moveOpenWindow:(NSArray *)indexPaths
  1655. {
  1656. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  1657. CCMove *viewController = (CCMove *)navigationController.topViewController;
  1658. viewController.delegate = self;
  1659. viewController.move.title = NSLocalizedString(@"_move_", nil);
  1660. viewController.selectedMetadatas = [self getMetadatasFromSelectedRows:indexPaths];
  1661. viewController.tintColor = COLOR_BRAND;
  1662. viewController.barTintColor = COLOR_BAR;
  1663. viewController.tintColorTitle = COLOR_GRAY;
  1664. viewController.networkingOperationQueue = app.netQueue;
  1665. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  1666. [self presentViewController:navigationController animated:YES completion:nil];
  1667. }
  1668. #pragma --------------------------------------------------------------------------------------------
  1669. #pragma mark ===== Create folder =====
  1670. #pragma --------------------------------------------------------------------------------------------
  1671. - (void)createFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1672. {
  1673. [_hud hideHud];
  1674. if (message)
  1675. [app messageNotification:@"_create_folder_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1676. }
  1677. - (void)createFolderSuccess:(CCMetadataNet *)metadataNet
  1678. {
  1679. [_hud hideHud];
  1680. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", metadataNet.serverUrl, metadataNet.fileName];
  1681. [CCCoreData addDirectory:newDirectory date:[NSDate date] permissions:nil activeAccount:app.activeAccount];
  1682. // Check Offline
  1683. if ([CCCoreData isOfflineDirectoryServerUrl:_localServerUrl activeAccount:app.activeAccount])
  1684. [CCCoreData setOfflineDirectoryServerUrl:newDirectory offline:YES activeAccount:app.activeAccount];
  1685. // Load Folder or the Datasource
  1686. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
  1687. [self readFolderWithForced:YES];
  1688. } else {
  1689. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:metadataNet.fileID selector:metadataNet.selector];
  1690. }
  1691. }
  1692. - (void)createFolder:(NSString *)fileNameFolder folderCameraUpload:(BOOL)folderCameraUpload
  1693. {
  1694. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1695. fileNameFolder = [CCUtility removeForbiddenCharacters:fileNameFolder];
  1696. if (![fileNameFolder length]) return;
  1697. if (folderCameraUpload) metadataNet.serverUrl = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  1698. else metadataNet.serverUrl = _localServerUrl;
  1699. metadataNet.action = actionCreateFolder;
  1700. if (folderCameraUpload)
  1701. metadataNet.options = @"folderCameraUpload";
  1702. metadataNet.fileName = fileNameFolder;
  1703. metadataNet.selector = selectorCreateFolder;
  1704. metadataNet.selectorPost = selectorReadFolderForced;
  1705. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1706. if (!folderCameraUpload)
  1707. [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1708. }
  1709. - (void)createFolderEncrypted:(NSString *)fileNameFolder
  1710. {
  1711. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1712. CCCrypto *crypto = [[CCCrypto alloc] init];
  1713. NSString *fileNamePlist;
  1714. fileNameFolder = [CCUtility removeForbiddenCharacters:fileNameFolder];
  1715. if (![fileNameFolder length]) return;
  1716. NSString *title = [AESCrypt encrypt:fileNameFolder password:[crypto getKeyPasscode:[CCUtility getUUID]]];
  1717. fileNamePlist = [crypto createFilenameEncryptor:fileNameFolder uuid:[CCUtility getUUID]];
  1718. [crypto createFilePlist:[NSTemporaryDirectory() stringByAppendingString:fileNamePlist] title:title len:0 directory:true uuid:[CCUtility getUUID] nameCurrentDevice:[CCUtility getNameCurrentDevice] icon:@""];
  1719. // Create folder
  1720. metadataNet.action = actionCreateFolder;
  1721. metadataNet.fileName = fileNamePlist;
  1722. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1723. metadataNet.selector = selectorCreateFolder;
  1724. metadataNet.serverUrl = _localServerUrl;
  1725. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1726. // upload plist file
  1727. metadataNet.action = actionUploadOnlyPlist;
  1728. metadataNet.fileName = [fileNamePlist stringByAppendingString:@".plist"];
  1729. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1730. metadataNet.selectorPost = selectorReadFolderForced;
  1731. metadataNet.serverUrl = _localServerUrl;
  1732. metadataNet.session = upload_session_foreground;
  1733. metadataNet.taskStatus = taskStatusResume;
  1734. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1735. [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1736. }
  1737. - (void)createFolderCameraUpload
  1738. {
  1739. [self createFolder:[CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount] folderCameraUpload:YES];
  1740. }
  1741. #pragma --------------------------------------------------------------------------------------------
  1742. #pragma mark ===== Encrypted / Decrypted Folder =====
  1743. #pragma --------------------------------------------------------------------------------------------
  1744. - (void)encyptedDecryptedFolder
  1745. {
  1746. if (_metadata.cryptated) {
  1747. // DECRYPTED
  1748. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1749. //-------------------------- RENAME -------------------------------------------//
  1750. metadataNet.action = actionMoveFileOrFolder;
  1751. metadataNet.fileID = _metadata.fileID;
  1752. metadataNet.fileName = _metadata.fileNameData;
  1753. metadataNet.fileNameTo = _metadata.fileNamePrint;
  1754. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1755. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1756. metadataNet.selector = selectorRename;
  1757. metadataNet.serverUrl = _localServerUrl;
  1758. metadataNet.serverUrlTo = _localServerUrl;
  1759. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1760. //-------------------------- DELETE -------------------------------------------//
  1761. metadataNet.action = actionDeleteFileDirectory;
  1762. metadataNet.fileID = _metadata.fileID;
  1763. metadataNet.fileName = _metadata.fileName;
  1764. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1765. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1766. metadataNet.selector = selectorDeletePlist;
  1767. metadataNet.selectorPost = selectorReadFolderForced;
  1768. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1769. } else {
  1770. // ENCRYPTED
  1771. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1772. CCCrypto *crypto = [[CCCrypto alloc] init];
  1773. // Create File Plist
  1774. NSString *fileNameCrypto = [crypto createFileDirectoryPlist:_metadata];
  1775. //-------------------------- RENAME -------------------------------------------//
  1776. metadataNet.action = actionMoveFileOrFolder;
  1777. metadataNet.fileID = _metadata.fileID;
  1778. metadataNet.fileName = _metadata.fileName;
  1779. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1780. metadataNet.fileNameTo = fileNameCrypto;
  1781. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1782. metadataNet.selector = selectorRename;
  1783. metadataNet.serverUrl = _localServerUrl;
  1784. metadataNet.serverUrlTo = _localServerUrl;
  1785. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1786. //-------------------------- UPLOAD -------------------------------------------//
  1787. metadataNet.action = actionUploadOnlyPlist;
  1788. metadataNet.fileName = [fileNameCrypto stringByAppendingString:@".plist"];
  1789. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1790. metadataNet.selectorPost = selectorReadFolderForced;
  1791. metadataNet.serverUrl = _localServerUrl;
  1792. metadataNet.session = upload_session_foreground;
  1793. metadataNet.taskStatus = taskStatusResume;
  1794. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1795. }
  1796. }
  1797. #pragma --------------------------------------------------------------------------------------------
  1798. #pragma mark ===== Encrypted/Decrypted File =====
  1799. #pragma --------------------------------------------------------------------------------------------
  1800. - (void)encryptedSelectedFiles
  1801. {
  1802. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1803. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1804. for (CCMetadata *metadata in selectedMetadatas) {
  1805. if (metadata.cryptated == NO && metadata.directory == NO)
  1806. [metadatas addObject:metadata];
  1807. }
  1808. if ([metadatas count] > 0) {
  1809. NSLog(@"[LOG] Start encrypted selected files ...");
  1810. for (CCMetadata* metadata in metadatas)
  1811. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorEncryptFile selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  1812. }
  1813. [self tableViewSelect:NO];
  1814. }
  1815. - (void)decryptedSelectedFiles
  1816. {
  1817. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1818. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1819. for (CCMetadata *metadata in selectedMetadatas) {
  1820. if (metadata.cryptated == YES && metadata.directory == NO && [metadata.model length] == 0)
  1821. [metadatas addObject:metadata];
  1822. }
  1823. if ([metadatas count] > 0) {
  1824. NSLog(@"[LOG] Start decrypted selected files ...");
  1825. for (CCMetadata* metadata in metadatas)
  1826. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorDecryptFile selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  1827. }
  1828. [self tableViewSelect:NO];
  1829. }
  1830. - (void)cmdEncryptedDecryptedFile
  1831. {
  1832. NSString *selector;
  1833. if (_metadata.cryptated == YES) selector = selectorDecryptFile;
  1834. if (_metadata.cryptated == NO) selector = selectorEncryptFile;
  1835. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selector selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  1836. }
  1837. - (void)encryptedFile:(CCMetadata *)metadata
  1838. {
  1839. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1840. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  1841. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  1842. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
  1843. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  1844. dispatch_async(dispatch_get_main_queue(), ^{
  1845. [[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];
  1846. [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.1];
  1847. });
  1848. } else {
  1849. [app messageNotification:@"_encrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1850. }
  1851. }
  1852. - (void)decryptedFile:(CCMetadata *)metadata
  1853. {
  1854. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1855. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  1856. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  1857. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
  1858. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  1859. dispatch_async(dispatch_get_main_queue(), ^{
  1860. [[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];
  1861. [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.1];
  1862. });
  1863. } else {
  1864. [app messageNotification:@"_decrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1865. }
  1866. }
  1867. #pragma --------------------------------------------------------------------------------------------
  1868. #pragma mark ===== Progress & Task Button =====
  1869. #pragma --------------------------------------------------------------------------------------------
  1870. - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
  1871. {
  1872. // Check
  1873. if (!fileID)
  1874. return;
  1875. [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  1876. if (![serverUrl isEqualToString:_localServerUrl])
  1877. return;
  1878. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  1879. if (indexPath) {
  1880. CCControlCenterCell *cell = (CCControlCenterCell *)[self.tableView cellForRowAtIndexPath:indexPath];
  1881. if (cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
  1882. else cell.progressView.progressTintColor = COLOR_CLEAR;
  1883. cell.progressView.hidden = NO;
  1884. [cell.progressView setProgress:progress];
  1885. }
  1886. }
  1887. - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
  1888. {
  1889. UITouch * touch = [[event allTouches] anyObject];
  1890. CGPoint location = [touch locationInView:self.tableView];
  1891. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1892. if (indexPath) {
  1893. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1894. if (metadata)
  1895. [self reloadTaskButton:metadata];
  1896. }
  1897. }
  1898. - (void)reloadTaskButton:(CCMetadata *)metadata
  1899. {
  1900. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1901. __block NSURLSessionTask *findTask;
  1902. // DOWNLOAD
  1903. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  1904. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1905. for (NSURLSessionUploadTask *task in downloadTasks)
  1906. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1907. findTask = task;
  1908. [app.listChangeTask setObject:@"reloadDownload" forKey:metadata.fileID];
  1909. [task cancel];
  1910. }
  1911. if (!findTask) {
  1912. dispatch_async(dispatch_get_main_queue(), ^{
  1913. [app.listChangeTask setObject:@"reloadDownload" forKey:metadata.fileID];
  1914. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1915. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1916. });
  1917. }
  1918. }];
  1919. }
  1920. // UPLOAD
  1921. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1922. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1923. for (NSURLSessionUploadTask *task in uploadTasks)
  1924. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1925. findTask = task;
  1926. [app.listChangeTask setObject:@"reloadUpload" forKey:metadata.fileID];
  1927. [task cancel];
  1928. }
  1929. if (!findTask) {
  1930. dispatch_async(dispatch_get_main_queue(), ^{
  1931. [app.listChangeTask setObject:@"reloadUpload" forKey:metadata.fileID];
  1932. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1933. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1934. });
  1935. }
  1936. }];
  1937. }
  1938. }
  1939. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  1940. {
  1941. UITouch * touch = [[event allTouches] anyObject];
  1942. CGPoint location = [touch locationInView:self.tableView];
  1943. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1944. if (indexPath) {
  1945. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1946. if (metadata)
  1947. [self cancelTaskButton:metadata reloadTable:YES];
  1948. }
  1949. }
  1950. - (void)cancelTaskButton:(CCMetadata *)metadata reloadTable:(BOOL)reloadTable
  1951. {
  1952. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1953. __block NSURLSessionTask *findTask;
  1954. // DOWNLOAD
  1955. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  1956. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1957. for (NSURLSessionTask *task in downloadTasks)
  1958. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1959. findTask = task;
  1960. [app.listChangeTask setObject:@"cancelDownload" forKey:metadata.fileID];
  1961. [task cancel];
  1962. }
  1963. if (!findTask) {
  1964. [app.listChangeTask setObject:@"cancelDownload" forKey:metadata.fileID];
  1965. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1966. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1967. }
  1968. }];
  1969. }
  1970. // UPLOAD
  1971. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1972. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1973. for (NSURLSessionUploadTask *task in uploadTasks)
  1974. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1975. findTask = task;
  1976. [app.listChangeTask setObject:@"cancelUpload" forKey:metadata.fileID];
  1977. [task cancel];
  1978. }
  1979. if (!findTask) {
  1980. dispatch_async(dispatch_get_main_queue(), ^{
  1981. [app.listChangeTask setObject:@"cancelUpload" forKey:metadata.fileID];
  1982. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1983. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1984. });
  1985. }
  1986. }];
  1987. }
  1988. }
  1989. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  1990. {
  1991. UITouch * touch = [[event allTouches] anyObject];
  1992. CGPoint location = [touch locationInView:self.tableView];
  1993. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1994. if (indexPath) {
  1995. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1996. if (metadata)
  1997. [self stopTaskButton:metadata];
  1998. }
  1999. }
  2000. - (void)stopTaskButton:(CCMetadata *)metadata
  2001. {
  2002. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  2003. __block NSURLSessionTask *findTask;
  2004. // UPLOAD
  2005. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  2006. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  2007. for (NSURLSessionUploadTask *task in uploadTasks)
  2008. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  2009. [app.listChangeTask setObject:@"stopUpload" forKey:metadata.fileID];
  2010. findTask = task;
  2011. [task cancel];
  2012. }
  2013. if (!findTask) {
  2014. dispatch_async(dispatch_get_main_queue(), ^{
  2015. [app.listChangeTask setObject:@"stopUpload" forKey:metadata.fileID];
  2016. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  2017. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  2018. });
  2019. }
  2020. }];
  2021. }
  2022. }
  2023. #pragma --------------------------------------------------------------------------------------------
  2024. #pragma mark ===== Shared =====
  2025. #pragma --------------------------------------------------------------------------------------------
  2026. - (void)readSharedSuccess:(CCMetadataNet *)metadataNet items:(NSDictionary *)items openWindow:(BOOL)openWindow
  2027. {
  2028. [_hud hideHud];
  2029. // change account ?
  2030. TableAccount *record = [CCCoreData getActiveAccount];
  2031. if([record.account isEqualToString:metadataNet.account] == NO)
  2032. return;
  2033. [CCCoreData updateShare:items sharesLink:app.sharesLink sharesUserAndGroup:app.sharesUserAndGroup activeAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  2034. if (openWindow && ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud])) {
  2035. if (_shareOC) {
  2036. [_shareOC reloadData];
  2037. } else {
  2038. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  2039. // Apriamo la view
  2040. _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
  2041. _shareOC.delegate = self;
  2042. _shareOC.metadata = metadata;
  2043. _shareOC.serverUrl = metadataNet.serverUrl;
  2044. _shareOC.shareLink = [app.sharesLink objectForKey:metadata.fileID];
  2045. _shareOC.shareUserAndGroup = [app.sharesUserAndGroup objectForKey:metadata.fileID];
  2046. [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
  2047. [self presentViewController:_shareOC animated:YES completion:nil];
  2048. }
  2049. }
  2050. [self tableViewReload];
  2051. }
  2052. - (void)requestSharedByServer
  2053. {
  2054. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2055. metadataNet.action = actionReadShareServer;
  2056. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2057. }
  2058. - (void)shareFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2059. {
  2060. [_hud hideHud];
  2061. [app messageNotification:@"_share_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2062. if (_shareOC)
  2063. [_shareOC reloadData];
  2064. [self tableViewReload];
  2065. if (errorCode == 401)
  2066. [self changePasswordAccount];
  2067. }
  2068. - (void)share:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password
  2069. {
  2070. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2071. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  2072. metadataNet.action = actionShare;
  2073. metadataNet.fileID = metadata.fileID;
  2074. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl typeCloud:app.typeCloud];
  2075. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2076. metadataNet.password = password;
  2077. metadataNet.selector = selectorShare;
  2078. metadataNet.serverUrl = serverUrl;
  2079. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2080. }
  2081. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2082. }
  2083. - (void)unShareSuccess:(CCMetadataNet *)metadataNet
  2084. {
  2085. [_hud hideHud];
  2086. // rimuoviamo la condivisione da db
  2087. [CCCoreData unShare:metadataNet.share fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl sharesLink:app.sharesLink sharesUserAndGroup:app.sharesUserAndGroup activeAccount:app.activeAccount];
  2088. if ([app.typeCloud isEqualToString:typeCloudNextcloud] && _shareOC)
  2089. [_shareOC reloadData];
  2090. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] && _shareOC)
  2091. [_shareOC reloadData];
  2092. [self tableViewReload];
  2093. }
  2094. - (void)unShare:(NSString *)share metadata:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl
  2095. {
  2096. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2097. metadataNet.action = actionUnShare;
  2098. metadataNet.fileID = metadata.fileID;
  2099. metadataNet.fileName = metadata.fileName;
  2100. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2101. metadataNet.selector = selectorUnshare;
  2102. metadataNet.serverUrl = serverUrl;
  2103. metadataNet.share = share;
  2104. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2105. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2106. }
  2107. - (void)updateShare:(NSString *)share metadata:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission
  2108. {
  2109. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2110. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  2111. metadataNet.action = actionUpdateShare;
  2112. metadataNet.fileID = metadata.fileID;
  2113. metadataNet.expirationTime = expirationTime;
  2114. metadataNet.password = password;
  2115. metadataNet.selector = selectorUpdateShare;
  2116. metadataNet.serverUrl = serverUrl;
  2117. metadataNet.share = share;
  2118. metadataNet.sharePermission = permission;
  2119. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2120. }
  2121. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2122. }
  2123. - (void)getUserAndGroupSuccess:(CCMetadataNet *)metadataNet items:(NSArray *)items
  2124. {
  2125. [_hud hideHud];
  2126. if (_shareOC)
  2127. [_shareOC reloadUserAndGroup:items];
  2128. }
  2129. - (void)getUserAndGroupFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2130. {
  2131. [_hud hideHud];
  2132. [app messageNotification:@"_error_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2133. }
  2134. - (void)getUserAndGroup:(NSString *)find
  2135. {
  2136. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2137. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  2138. metadataNet.action = actionGetUserAndGroup;
  2139. metadataNet.options = find;
  2140. metadataNet.selector = selectorGetUserAndGroup;
  2141. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2142. }
  2143. [_hud visibleIndeterminateHud];
  2144. }
  2145. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission metadata:(CCMetadata *)metadata directoryID:(NSString *)directoryID serverUrl:(NSString *)serverUrl
  2146. {
  2147. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2148. metadataNet.action = actionShareWith;
  2149. metadataNet.fileID = metadata.fileID;
  2150. metadataNet.directoryID = directoryID;
  2151. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl typeCloud:app.typeCloud];
  2152. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2153. metadataNet.serverUrl = serverUrl;
  2154. metadataNet.selector = selectorShare;
  2155. metadataNet.share = user;
  2156. metadataNet.shareeType = shareeType;
  2157. metadataNet.sharePermission = permission;
  2158. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2159. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2160. }
  2161. - (void)openWindowShare:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl
  2162. {
  2163. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2164. metadataNet.action = actionReadShareServer;
  2165. metadataNet.fileID = metadata.fileID;
  2166. metadataNet.fileName = metadata.fileName;
  2167. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2168. metadataNet.selector = selectorOpenWindowShare;
  2169. metadataNet.serverUrl = serverUrl;
  2170. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2171. [_hud visibleIndeterminateHud];
  2172. }
  2173. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  2174. {
  2175. CGPoint location = [tapGesture locationInView:self.tableView];
  2176. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  2177. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2178. if (metadata)
  2179. [self openWindowShare:metadata serverUrl:_localServerUrl];
  2180. }
  2181. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  2182. {
  2183. CGPoint location = [tapGesture locationInView:self.tableView];
  2184. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  2185. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2186. if (metadata) {
  2187. CCShareInfoCMOC *vc = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareInfoCMOC"];
  2188. vc.metadata = metadata;
  2189. [vc setModalPresentationStyle:UIModalPresentationFormSheet];
  2190. [self presentViewController:vc animated:YES completion:nil];
  2191. }
  2192. }
  2193. #pragma --------------------------------------------------------------------------------------------
  2194. #pragma mark ===== Offline =====
  2195. #pragma --------------------------------------------------------------------------------------------
  2196. - (void)addOffline:(CCMetadata *)metadata
  2197. {
  2198. if (metadata.errorPasscode || !metadata.uuid) return;
  2199. if ([metadata.type isEqualToString:metadataType_file])
  2200. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorAddOffline selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2201. if ([metadata.type isEqualToString:metadataType_model])
  2202. [CCCoreData setOfflineLocalFileID:metadata.fileID offline:YES activeAccount:app.activeAccount];
  2203. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2204. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2205. }
  2206. - (void)removeOffline:(CCMetadata *)metadata
  2207. {
  2208. [CCCoreData setOfflineLocalFileID:metadata.fileID offline:NO activeAccount:app.activeAccount];
  2209. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2210. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2211. }
  2212. #pragma --------------------------------------------------------------------------------------------
  2213. #pragma mark ===== Local =====
  2214. #pragma --------------------------------------------------------------------------------------------
  2215. - (void)addLocal:(CCMetadata *)metadata
  2216. {
  2217. if (metadata.errorPasscode || !metadata.uuid) return;
  2218. if ([metadata.type isEqualToString:metadataType_file])
  2219. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorAddLocal selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2220. if ([metadata.type isEqualToString:metadataType_model]) {
  2221. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileName]];
  2222. [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  2223. }
  2224. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2225. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2226. }
  2227. #pragma --------------------------------------------------------------------------------------------
  2228. #pragma mark ===== Reload =====
  2229. #pragma --------------------------------------------------------------------------------------------
  2230. - (void)reloadFile:(CCMetadata *)metadata
  2231. {
  2232. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorReload selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2233. }
  2234. #pragma --------------------------------------------------------------------------------------------
  2235. #pragma mark ===== Open in... =====
  2236. #pragma --------------------------------------------------------------------------------------------
  2237. - (void)openIn:(CCMetadata *)metadata
  2238. {
  2239. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorOpenIn selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2240. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2241. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2242. }
  2243. #pragma --------------------------------------------------------------------------------------------
  2244. #pragma mark ===== Order Table & GroupBy & DirectoryOnTop =====
  2245. #pragma --------------------------------------------------------------------------------------------
  2246. - (void)orderTable:(NSString *)order
  2247. {
  2248. // Clear data-read of DataSource
  2249. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2250. [CCUtility setOrderSettings:order];
  2251. // refresh
  2252. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2253. // new menu
  2254. [self createReMainMenu];
  2255. }
  2256. - (void)ascendingTable:(BOOL)ascending
  2257. {
  2258. // Clear data-read of DataSource
  2259. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2260. [CCUtility setAscendingSettings:ascending];
  2261. // refresh
  2262. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2263. // new menu
  2264. [self createReMainMenu];
  2265. }
  2266. - (void)directoryOnTop:(BOOL)directoryOnTop
  2267. {
  2268. // Clear data-read of DataSource
  2269. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2270. [CCUtility setDirectoryOnTop:directoryOnTop];
  2271. // refresh
  2272. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2273. // new menu
  2274. [self createReMainMenu];
  2275. }
  2276. - (void)tableGroupBy:(NSString *)groupBy
  2277. {
  2278. // Clear data-read of DataSource
  2279. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2280. [CCUtility setGroupBySettings:groupBy];
  2281. // refresh
  2282. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2283. // new menu
  2284. [self createReMainMenu];
  2285. }
  2286. #pragma --------------------------------------------------------------------------------------------
  2287. #pragma mark ==== Menu change User ====
  2288. #pragma --------------------------------------------------------------------------------------------
  2289. - (void)menuChangeUser
  2290. {
  2291. if (app.reSelectMenu.isOpen || app.reMainMenu.isOpen)
  2292. return;
  2293. 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) {
  2294. [app messageNotification:@"_transfers_in_queue_" description:nil visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  2295. return;
  2296. }
  2297. NSArray *listTableAccount = [CCCoreData getAllTableAccount];
  2298. NSMutableArray *menuArray = [[NSMutableArray alloc] init];
  2299. for (TableAccount *record in listTableAccount) {
  2300. if ([record.account isEqualToString:app.activeAccount]) continue;
  2301. CCMenuItem *item = [[CCMenuItem alloc] init];
  2302. item.title = [record.account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  2303. item.argument = record.account;
  2304. if ([record.typeCloud isEqualToString:typeCloudNextcloud]) item.image = [UIImage imageNamed:image_typeCloudNextcloud];
  2305. if ([record.typeCloud isEqualToString:typeCloudOwnCloud]) item.image = [UIImage imageNamed:image_typeCloudOwnCloud];
  2306. item.target = self;
  2307. item.action = @selector(changeDefaultAccount:);
  2308. [menuArray addObject:item];
  2309. }
  2310. if ([menuArray count] == 0)
  2311. return;
  2312. OptionalConfiguration options;
  2313. Color textColor, backgroundColor;
  2314. textColor.R = 0;
  2315. textColor.G = 0;
  2316. textColor.B = 0;
  2317. backgroundColor.R = 1;
  2318. backgroundColor.G = 1;
  2319. backgroundColor.B = 1;
  2320. options.arrowSize = 9;
  2321. options.marginXSpacing = 7;
  2322. options.marginYSpacing = 10;
  2323. options.intervalSpacing = 20;
  2324. options.menuCornerRadius = 6.5;
  2325. options.maskToBackground = NO;
  2326. options.shadowOfMenu = YES;
  2327. options.hasSeperatorLine = YES;
  2328. options.seperatorLineHasInsets = YES;
  2329. options.textColor = textColor;
  2330. options.menuBackgroundColor = backgroundColor;
  2331. [CCMenu setTitleFont:[UIFont systemFontOfSize:12.0]];
  2332. [CCMenu showMenuInView:self.navigationController.view fromRect:self.view.frame menuItems:menuArray withOptions:options];
  2333. }
  2334. - (void)changeDefaultAccount:(CCMenuItem *)sender
  2335. {
  2336. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
  2337. // STOP, erase all in queue networking
  2338. [app cancelAllOperations];
  2339. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  2340. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  2341. TableAccount *tableAccount = [CCCoreData setActiveAccount:[sender argument]];
  2342. if (tableAccount)
  2343. [app settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activePassword:tableAccount.password activeUID:tableAccount.uid activeAccessToken:tableAccount.token typeCloud:tableAccount.typeCloud];
  2344. // go to home sweet home
  2345. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  2346. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  2347. });
  2348. }
  2349. #pragma --------------------------------------------------------------------------------------------
  2350. #pragma mark ==== ReMenu ====
  2351. #pragma --------------------------------------------------------------------------------------------
  2352. - (void)createReMenuBackgroundView:(REMenu *)menu
  2353. {
  2354. __block CGFloat navigationBarH = self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
  2355. _reMenuBackgroundView.frame = CGRectMake(0, navigationBarH, self.view.frame.size.width, self.view.frame.size.height);
  2356. [UIView animateWithDuration:0.2 animations:^{
  2357. float height = (self.view.frame.size.height + navigationBarH) - (menu.menuView.frame.size.height - self.navigationController.navigationBar.frame.size.height + 3);
  2358. if (height < self.tabBarController.tabBar.frame.size.height)
  2359. height = self.tabBarController.tabBar.frame.size.height;
  2360. _reMenuBackgroundView.frame = CGRectMake(0, self.view.frame.size.height + navigationBarH, self.view.frame.size.width, - height);
  2361. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  2362. }];
  2363. }
  2364. - (void)createReMainMenu
  2365. {
  2366. NSString *ordinamento;
  2367. NSString *groupBy = _directoryGroupBy;
  2368. __block NSString *nuovoOrdinamento;
  2369. NSString *titoloNuovo, *titoloAttuale;
  2370. BOOL ascendente;
  2371. __block BOOL nuovoAscendente;
  2372. UIImage *image;
  2373. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  2374. if (app.selezionaItem == nil) app.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)
  2375. subtitle:@""
  2376. image:[UIImage imageNamed:image_seleziona]
  2377. highlightedImage:nil
  2378. action:^(REMenuItem *item) {
  2379. if ([_sectionDataSource.allRecordsDataSource count] > 0) {
  2380. [self tableViewSelect:YES];
  2381. }
  2382. }];
  2383. else app.selezionaItem = [app.selezionaItem initWithTitle:NSLocalizedString(@"_select_", nil)
  2384. subtitle:@""
  2385. image:[UIImage imageNamed:image_seleziona]
  2386. highlightedImage:nil
  2387. action:^(REMenuItem *item) {
  2388. if ([_sectionDataSource.allRecordsDataSource count] > 0)
  2389. [self tableViewSelect:YES];
  2390. }];
  2391. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  2392. ordinamento = _directoryOrder;
  2393. if ([ordinamento isEqualToString:@"fileName"]) {
  2394. image = [UIImage imageNamed:image_MenuOrdeyByDate];
  2395. titoloNuovo = NSLocalizedString(@"_order_by_date_", nil);
  2396. titoloAttuale = NSLocalizedString(@"_current_order_name_", nil);
  2397. nuovoOrdinamento = @"fileDate";
  2398. }
  2399. if ([ordinamento isEqualToString:@"fileDate"]) {
  2400. image = [UIImage imageNamed:image_MenuOrderByFileName];
  2401. titoloNuovo = NSLocalizedString(@"_order_by_name_", nil);
  2402. titoloAttuale = NSLocalizedString(@"_current_order_date_", nil);
  2403. nuovoOrdinamento = @"fileName";
  2404. }
  2405. if (app.ordinaItem == nil) app.ordinaItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2406. subtitle:titoloAttuale
  2407. image:image
  2408. highlightedImage:nil
  2409. action:^(REMenuItem *item) {
  2410. [self orderTable:nuovoOrdinamento];
  2411. }];
  2412. else app.ordinaItem = [app.ordinaItem initWithTitle:titoloNuovo
  2413. subtitle:titoloAttuale
  2414. image:image
  2415. highlightedImage:nil
  2416. action:^(REMenuItem *item) {
  2417. [self orderTable:nuovoOrdinamento];
  2418. }];
  2419. // ITEM ASCENDING -----------------------------------------------------------------------------------------------------
  2420. ascendente = [CCUtility getAscendingSettings];
  2421. if (ascendente) {
  2422. image = [UIImage imageNamed:image_MenuOrdinamentoDiscendente];
  2423. titoloNuovo = NSLocalizedString(@"_sort_descending_", nil);
  2424. titoloAttuale = NSLocalizedString(@"_current_sort_ascending_", nil);
  2425. nuovoAscendente = false;
  2426. }
  2427. if (!ascendente) {
  2428. image = [UIImage imageNamed:image_MenuOrdinamentoAscendente];
  2429. titoloNuovo = NSLocalizedString(@"_sort_ascending_", nil);
  2430. titoloAttuale = NSLocalizedString(@"_current_sort_descending_", nil);
  2431. nuovoAscendente = true;
  2432. }
  2433. if (app.ascendenteItem == nil) app.ascendenteItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2434. subtitle:titoloAttuale
  2435. image:image
  2436. highlightedImage:nil
  2437. action:^(REMenuItem *item) {
  2438. [self ascendingTable:nuovoAscendente];
  2439. }];
  2440. else app.ascendenteItem = [app.ascendenteItem initWithTitle:titoloNuovo
  2441. subtitle:titoloAttuale
  2442. image:image
  2443. highlightedImage:nil
  2444. action:^(REMenuItem *item) {
  2445. [self ascendingTable:nuovoAscendente];
  2446. }];
  2447. // ITEM ALPHABETIC -----------------------------------------------------------------------------------------------------
  2448. if ([groupBy isEqualToString:@"alphabetic"]) { titoloNuovo = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  2449. else { titoloNuovo = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  2450. if (app.alphabeticItem == nil) app.alphabeticItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2451. subtitle:@""
  2452. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2453. highlightedImage:nil
  2454. action:^(REMenuItem *item) {
  2455. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2456. else [self tableGroupBy:@"alphabetic"];
  2457. }];
  2458. else app.alphabeticItem = [app.alphabeticItem initWithTitle:titoloNuovo
  2459. subtitle:@""
  2460. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2461. highlightedImage:nil
  2462. action:^(REMenuItem *item) {
  2463. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2464. else [self tableGroupBy:@"alphabetic"];
  2465. }];
  2466. // ITEM TYPEFILE -------------------------------------------------------------------------------------------------------
  2467. if ([groupBy isEqualToString:@"typefile"]) { titoloNuovo = NSLocalizedString(@"_group_typefile_yes_", nil); }
  2468. else { titoloNuovo = NSLocalizedString(@"_group_typefile_no_", nil); }
  2469. if (app.typefileItem == nil) app.typefileItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2470. subtitle:@""
  2471. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2472. highlightedImage:nil
  2473. action:^(REMenuItem *item) {
  2474. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2475. else [self tableGroupBy:@"typefile"];
  2476. }];
  2477. else app.typefileItem = [app.typefileItem initWithTitle:titoloNuovo
  2478. subtitle:@""
  2479. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2480. highlightedImage:nil
  2481. action:^(REMenuItem *item) {
  2482. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2483. else [self tableGroupBy:@"typefile"];
  2484. }];
  2485. // ITEM DATE -------------------------------------------------------------------------------------------------------
  2486. if ([groupBy isEqualToString:@"date"]) { titoloNuovo = NSLocalizedString(@"_group_date_yes_", nil); }
  2487. else { titoloNuovo = NSLocalizedString(@"_group_date_no_", nil); }
  2488. if (app.dateItem == nil) app.dateItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2489. subtitle:@""
  2490. image:[UIImage imageNamed:image_MenuGroupByDate]
  2491. highlightedImage:nil
  2492. action:^(REMenuItem *item) {
  2493. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2494. else [self tableGroupBy:@"date"];
  2495. }];
  2496. else app.dateItem = [app.dateItem initWithTitle:titoloNuovo
  2497. subtitle:@""
  2498. image:[UIImage imageNamed:image_MenuGroupByDate]
  2499. highlightedImage:nil
  2500. action:^(REMenuItem *item) {
  2501. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2502. else [self tableGroupBy:@"date"];
  2503. }];
  2504. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  2505. if ([CCUtility getDirectoryOnTop]) { titoloNuovo = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  2506. else { titoloNuovo = NSLocalizedString(@"_directory_on_top_no_", nil); }
  2507. if (app.directoryOnTopItem == nil) app.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2508. subtitle:@""
  2509. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2510. highlightedImage:nil
  2511. action:^(REMenuItem *item) {
  2512. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2513. else [self directoryOnTop:YES];
  2514. }];
  2515. else app.directoryOnTopItem = [app.directoryOnTopItem initWithTitle:titoloNuovo
  2516. subtitle:@""
  2517. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2518. highlightedImage:nil
  2519. action:^(REMenuItem *item) {
  2520. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2521. else [self directoryOnTop:YES];
  2522. }];
  2523. // REMENU --------------------------------------------------------------------------------------------------------------
  2524. if (app.reMainMenu == nil) app.reMainMenu = [[REMenu alloc] initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2525. else app.reMainMenu = [app.reMainMenu initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2526. app.reMainMenu.imageOffset = CGSizeMake(5, -1);
  2527. app.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2528. app.reMainMenu.imageOffset = CGSizeMake(0, 0);
  2529. app.reMainMenu.waitUntilAnimationIsComplete = NO;
  2530. app.reMainMenu.separatorHeight = 0.5;
  2531. app.reMainMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2532. app.reMainMenu.backgroundColor = COLOR_BAR;
  2533. app.reMainMenu.textColor = [UIColor blackColor];
  2534. app.reMainMenu.textAlignment = NSTextAlignmentLeft;
  2535. app.reMainMenu.textShadowColor = nil;
  2536. app.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  2537. app.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  2538. app.reMainMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2539. app.reMainMenu.highlightedSeparatorColor = nil;
  2540. app.reMainMenu.highlightedTextColor = [UIColor blackColor];
  2541. app.reMainMenu.highlightedTextShadowColor = nil;
  2542. app.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2543. app.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  2544. app.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2545. app.reMainMenu.subtitleTextShadowColor = nil;
  2546. app.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2547. app.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2548. app.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2549. app.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2550. app.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  2551. app.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2552. app.reMainMenu.borderWidth = 0.3;
  2553. app.reMainMenu.borderColor = [UIColor lightGrayColor];
  2554. app.reMainMenu.animationDuration = 0.2;
  2555. app.reMainMenu.closeAnimationDuration = 0.2;
  2556. app.reMainMenu.bounce = NO;
  2557. [app.reMainMenu setClosePreparationBlock:^{
  2558. // Backgroun reMenu (Gesture)
  2559. [_reMenuBackgroundView removeFromSuperview];
  2560. [app.controlCenter disableSingleFingerTap];
  2561. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2562. }];
  2563. }
  2564. - (void)toggleReMainMenu
  2565. {
  2566. if (app.reMainMenu.isOpen) {
  2567. [app.reMainMenu close];
  2568. } else {
  2569. [app.reMainMenu showFromNavigationController:self.navigationController];
  2570. // Backgroun reMenu & (Gesture)
  2571. [self createReMenuBackgroundView:app.reMainMenu];
  2572. [app.controlCenter enableSingleFingerTap:@selector(toggleReMainMenu) target:self];
  2573. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  2574. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2575. }
  2576. }
  2577. - (void)createReSelectMenu
  2578. {
  2579. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  2580. if (app.deleteItem == nil) app.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2581. subtitle:@""
  2582. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2583. highlightedImage:nil
  2584. action:^(REMenuItem *item) {
  2585. [self deleteSelectionFile];
  2586. }];
  2587. else app.deleteItem = [app.deleteItem initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2588. subtitle:@""
  2589. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2590. highlightedImage:nil
  2591. action:^(REMenuItem *item) {
  2592. [self deleteSelectionFile];
  2593. }];
  2594. // ITEM MOVE ------------------------------------------------------------------------------------------------------
  2595. if (app.moveItem == nil) app.moveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2596. subtitle:@""
  2597. image:[UIImage imageNamed:image_moveSelectedFiles]
  2598. highlightedImage:nil
  2599. action:^(REMenuItem *item) {
  2600. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2601. }];
  2602. else app.moveItem = [app.moveItem initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2603. subtitle:@""
  2604. image:[UIImage imageNamed:image_moveSelectedFiles]
  2605. highlightedImage:nil
  2606. action:^(REMenuItem *item) {
  2607. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2608. }];
  2609. // ITEM ENCRYPTED ------------------------------------------------------------------------------------------------------
  2610. if (app.encryptItem == nil) app.encryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2611. subtitle:@""
  2612. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2613. highlightedImage:nil
  2614. action:^(REMenuItem *item) {
  2615. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2616. }];
  2617. else app.encryptItem = [app.encryptItem initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2618. subtitle:@""
  2619. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2620. highlightedImage:nil
  2621. action:^(REMenuItem *item) {
  2622. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2623. }];
  2624. // ITEM DECRYPTED ----------------------------------------------------------------------------------------------------
  2625. if (app.decryptItem == nil) app.decryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2626. subtitle:@""
  2627. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2628. highlightedImage:nil
  2629. action:^(REMenuItem *item) {
  2630. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2631. }];
  2632. else app.decryptItem = [app.decryptItem initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2633. subtitle:@""
  2634. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2635. highlightedImage:nil
  2636. action:^(REMenuItem *item) {
  2637. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2638. }];
  2639. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  2640. if (app.downloadItem == nil) app.downloadItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2641. subtitle:@""
  2642. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2643. highlightedImage:nil
  2644. action:^(REMenuItem *item) {
  2645. [self downloadSelectedFiles];
  2646. }];
  2647. else app.downloadItem = [app.downloadItem initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2648. subtitle:@""
  2649. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2650. highlightedImage:nil
  2651. action:^(REMenuItem *item) {
  2652. [self downloadSelectedFiles];
  2653. }];
  2654. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  2655. if (app.saveItem == nil) app.saveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2656. subtitle:@""
  2657. image:[UIImage imageNamed:image_saveSelectedFiles]
  2658. highlightedImage:nil
  2659. action:^(REMenuItem *item) {
  2660. [self saveSelectedFiles];
  2661. }];
  2662. else app.saveItem = [app.saveItem initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2663. subtitle:@""
  2664. image:[UIImage imageNamed:image_saveSelectedFiles]
  2665. highlightedImage:nil
  2666. action:^(REMenuItem *item) {
  2667. [self saveSelectedFiles];
  2668. }];
  2669. // REMENU --------------------------------------------------------------------------------------------------------------
  2670. if (app.reSelectMenu == nil)
  2671. app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2672. else
  2673. app.reSelectMenu = [app.reSelectMenu initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2674. app.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  2675. app.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2676. app.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  2677. app.reSelectMenu.waitUntilAnimationIsComplete = NO;
  2678. app.reSelectMenu.separatorHeight = 0.5;
  2679. app.reSelectMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2680. app.reSelectMenu.backgroundColor = COLOR_BAR;
  2681. app.reSelectMenu.textColor = [UIColor blackColor];
  2682. app.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  2683. app.reSelectMenu.textShadowColor = nil;
  2684. app.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  2685. app.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  2686. app.reSelectMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2687. app.reSelectMenu.highlightedSeparatorColor = nil;
  2688. app.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  2689. app.reSelectMenu.highlightedTextShadowColor = nil;
  2690. app.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2691. app.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  2692. app.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2693. app.reSelectMenu.subtitleTextShadowColor = nil;
  2694. app.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2695. app.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2696. app.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2697. app.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2698. app.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  2699. app.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2700. app.reSelectMenu.borderWidth = 0.3;
  2701. app.reSelectMenu.borderColor = [UIColor lightGrayColor];
  2702. app.reSelectMenu.closeAnimationDuration = 0.2;
  2703. app.reSelectMenu.animationDuration = 0.2;
  2704. app.reSelectMenu.bounce = NO;
  2705. [app.reSelectMenu setClosePreparationBlock:^{
  2706. // Backgroun reMenu (Gesture)
  2707. [_reMenuBackgroundView removeFromSuperview];
  2708. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2709. }];
  2710. }
  2711. - (void)toggleReSelectMenu
  2712. {
  2713. if (app.reSelectMenu.isOpen) {
  2714. [app.reSelectMenu close];
  2715. } else {
  2716. [app.reSelectMenu showFromNavigationController:self.navigationController];
  2717. // Backgroun reMenu & (Gesture)
  2718. [self createReMenuBackgroundView:app.reSelectMenu];
  2719. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  2720. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2721. }
  2722. }
  2723. #pragma --------------------------------------------------------------------------------------------
  2724. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  2725. #pragma --------------------------------------------------------------------------------------------
  2726. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  2727. {
  2728. if (recognizer.state == UIGestureRecognizerStateBegan) {
  2729. UITableView *tableView = (UITableView*)self.view;
  2730. CGPoint touchPoint = [recognizer locationInView:self.view];
  2731. NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:touchPoint];
  2732. if (indexPath)
  2733. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  2734. else
  2735. _metadata = nil;
  2736. [self becomeFirstResponder];
  2737. UIMenuController *menuController = [UIMenuController sharedMenuController];
  2738. UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
  2739. UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
  2740. UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
  2741. UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
  2742. UIMenuItem *pasteFileEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_encrypted_", nil) action:@selector(pasteFileEncrypted:)];
  2743. UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
  2744. UIMenuItem *pasteFilesEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_encrypted_", nil) action:@selector(pasteFilesEncrypted:)];
  2745. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, pasteFileEncryptedItem, pasteFilesEncryptedItem, nil]];
  2746. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:tableView];
  2747. [menuController setMenuVisible:YES animated:YES];
  2748. }
  2749. }
  2750. - (BOOL)canBecomeFirstResponder
  2751. {
  2752. return YES;
  2753. }
  2754. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  2755. {
  2756. // For copy file, copy files, Open in ... :
  2757. //
  2758. // NO Directory
  2759. // NO Error Passcode
  2760. // NO In Session mode (download/upload)
  2761. // NO Template
  2762. if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
  2763. if (_isSelectedMode == NO && _metadata && !_metadata.directory && !_metadata.errorPasscode && [_metadata.session length] == 0 && ![_metadata.typeFile isEqualToString:metadataTypeFile_template]) {
  2764. // NO Cryptated with Title lenght = 0
  2765. if (!_metadata.cryptated || (_metadata.cryptated && _metadata.title.length > 0))
  2766. return YES;
  2767. }
  2768. return NO;
  2769. }
  2770. if (@selector(copyFiles:) == action) {
  2771. if (_isSelectedMode) {
  2772. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2773. for (CCMetadata *metadata in selectedMetadatas) {
  2774. if (!metadata.directory && !metadata.errorPasscode && metadata.session.length == 0 && ![metadata.typeFile isEqualToString:metadataTypeFile_template]) {
  2775. // NO Cryptated with Title lenght = 0
  2776. if (!metadata.cryptated || (metadata.cryptated && metadata.title.length > 0))
  2777. return YES;
  2778. }
  2779. }
  2780. }
  2781. return NO;
  2782. }
  2783. if (@selector(pasteFile:) == action || @selector(pasteFileEncrypted:) == action) {
  2784. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2785. NSArray *items = [pasteboard items];
  2786. if ([items count] == 1) {
  2787. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2788. NSDictionary *dic = [items objectAtIndex:0];
  2789. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2790. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2791. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2792. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2793. if (directoryUser) {
  2794. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2795. return YES;
  2796. }
  2797. return NO;
  2798. } else return NO;
  2799. }
  2800. if (@selector(pasteFiles:) == action || @selector(pasteFilesEncrypted:) == action) {
  2801. BOOL isValid = NO;
  2802. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2803. NSArray *items = [pasteboard items];
  2804. if ([items count] <= 1) return NO;
  2805. for (NSDictionary *dic in items) {
  2806. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2807. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2808. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2809. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2810. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2811. if (directoryUser) {
  2812. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2813. isValid = YES;
  2814. }
  2815. }
  2816. return isValid;
  2817. }
  2818. return NO;
  2819. }
  2820. /************************************ COPY ************************************/
  2821. - (void)copyFile:(id)sender
  2822. {
  2823. // Remove all item
  2824. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2825. pasteboard.items = [[NSArray alloc] init];
  2826. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser,_metadata.fileID]])
  2827. [self copyFileToPasteboard:_metadata];
  2828. else
  2829. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2830. }
  2831. - (void)copyFiles:(id)sender
  2832. {
  2833. // Remove all item
  2834. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2835. pasteboard.items = [[NSArray alloc] init];
  2836. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2837. for (CCMetadata *metadata in selectedMetadatas) {
  2838. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
  2839. [self copyFileToPasteboard:metadata];
  2840. else
  2841. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2842. }
  2843. [self tableViewSelect:NO];
  2844. }
  2845. - (void)copyFileToPasteboard:(CCMetadata *)metadata
  2846. {
  2847. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2848. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  2849. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2850. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata], @"it.twsweb.Crypto-Cloud.CCMetadata",nil];
  2851. [items addObject:item];
  2852. [pasteboard setItems:items];
  2853. }
  2854. /************************************ OPEN IN ... ************************************/
  2855. - (void)openinFile:(id)sender
  2856. {
  2857. [self openIn:_metadata];
  2858. }
  2859. /************************************ PASTE ************************************/
  2860. - (void)pasteFile:(id)sender
  2861. {
  2862. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2863. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2864. }
  2865. - (void)pasteFileEncrypted:(id)sender
  2866. {
  2867. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2868. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2869. }
  2870. - (void)pasteFiles:(id)sender
  2871. {
  2872. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2873. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2874. }
  2875. - (void)pasteFilesEncrypted:(id)sender
  2876. {
  2877. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2878. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2879. }
  2880. - (void)uploadFilePasteArray:(NSArray *)items cryptated:(BOOL)cryptated
  2881. {
  2882. for (NSDictionary *dic in items) {
  2883. // key : it.twsweb.Crypto-Cloud.CCMetadata
  2884. // Value : (NSData) metadata
  2885. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2886. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2887. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2888. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2889. if (directoryUser) {
  2890. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]]) {
  2891. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint]];
  2892. [[CCNetworking sharedNetworking] uploadFile:metadata.fileNamePrint serverUrl:_localServerUrl cryptated:cryptated onlyPlist:NO session:upload_session taskStatus:taskStatusResume selector:nil selectorPost:nil parentRev:nil errorCode:0 delegate:nil];
  2893. }
  2894. }
  2895. }
  2896. }
  2897. #pragma --------------------------------------------------------------------------------------------
  2898. #pragma mark ===== Lock Passcode =====
  2899. #pragma --------------------------------------------------------------------------------------------
  2900. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  2901. {
  2902. return _failedAttempts;
  2903. }
  2904. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  2905. {
  2906. return _lockUntilDate;
  2907. }
  2908. - (void)passcodeViewCloseButtonPressed:(id)sender
  2909. {
  2910. [self dismissViewControllerAnimated:YES completion:nil];
  2911. }
  2912. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  2913. {
  2914. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  2915. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  2916. _lockUntilDate = nil;
  2917. _failedAttempts = 0;
  2918. aResultHandler(YES);
  2919. } else aResultHandler(NO);
  2920. } else aResultHandler(YES);
  2921. }
  2922. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  2923. {
  2924. [aViewController dismissViewControllerAnimated:YES completion:nil];
  2925. switch (aViewController.type) {
  2926. case BKPasscodeViewControllerCheckPasscodeType: {
  2927. if (aViewController.fromType == CCBKPasscodeFromPasscode) {
  2928. CCCrypto *crypto = [[CCCrypto alloc] init];
  2929. // verifichiamo se il passcode è corretto per il seguente file -> UUID
  2930. if ([crypto verifyPasscode:aPasscode uuid:_metadata.uuid text:_metadata.title]) {
  2931. // scriviamo il passcode
  2932. [CCUtility setKeyChainPasscodeForUUID:_metadata.uuid conPasscode:aPasscode];
  2933. [self readFolderWithForced:YES];
  2934. } else {
  2935. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_error_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  2936. [alertView show];
  2937. }
  2938. }
  2939. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  2940. // possiamo procedere alla prossima directory
  2941. [self performSegueDirectoryWithControlPasscode:false];
  2942. // avviamo la sessione Passcode Lock con now
  2943. app.sessionePasscodeLock = [NSDate date];
  2944. }
  2945. // disattivazione lock cartella
  2946. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  2947. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  2948. if ([CCCoreData setDirectoryUnLock:lockServerUrl activeAccount:app.activeAccount] == NO) {
  2949. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2950. }
  2951. [self.tableView reloadData];
  2952. }
  2953. }
  2954. break;
  2955. default:
  2956. break;
  2957. }
  2958. }
  2959. - (void)comandoLockPassword
  2960. {
  2961. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  2962. // se non è abilitato il Lock Passcode esci
  2963. if ([[CCUtility getBlockCode] length] == 0) {
  2964. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  2965. [alertView show];
  2966. return;
  2967. }
  2968. // se è richiesta la disattivazione si chiede la password
  2969. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  2970. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2971. viewController.delegate = self;
  2972. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  2973. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2974. viewController.inputViewTitlePassword = YES;
  2975. if ([CCUtility getSimplyBlockCode]) {
  2976. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2977. viewController.passcodeInputView.maximumLength = 6;
  2978. } else {
  2979. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2980. viewController.passcodeInputView.maximumLength = 64;
  2981. }
  2982. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  2983. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  2984. viewController.touchIDManager = touchIDManager;
  2985. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  2986. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  2987. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  2988. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  2989. [self presentViewController:navigationController animated:YES completion:nil];
  2990. return;
  2991. }
  2992. // ---------------- ACTIVATE PASSWORD
  2993. if([CCCoreData setDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  2994. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  2995. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2996. } else {
  2997. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2998. }
  2999. }
  3000. #pragma --------------------------------------------------------------------------------------------
  3001. #pragma mark ===== Swipe Tablet -> menu =====
  3002. #pragma --------------------------------------------------------------------------------------------
  3003. // more
  3004. - (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  3005. return NSLocalizedString(@"_more_", nil);
  3006. }
  3007. - (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
  3008. {
  3009. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3010. NSString *titoloCriptaDecripta, *titoloOffline, *titoloLock, *titleOfflineFolder;
  3011. BOOL offlineFolder = NO;
  3012. if (_metadata.cryptated) titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_decrypt_", nil)];
  3013. else titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_encrypt_", nil)];
  3014. if ([CCCoreData isOfflineLocalFileID:_metadata.fileID activeAccount:app.activeAccount]) titoloOffline = [NSString stringWithFormat:NSLocalizedString(@"_remove_offline_", nil)];
  3015. else titoloOffline = [NSString stringWithFormat:NSLocalizedString(@"_add_offline_", nil)];
  3016. NSString *offlineServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3017. if (_metadata.directory && [CCCoreData isOfflineDirectoryServerUrl:offlineServerUrl activeAccount:app.activeAccount]) {
  3018. titleOfflineFolder = [NSString stringWithFormat:NSLocalizedString(@"_remove_offline_", nil)];
  3019. offlineFolder = YES;
  3020. } else titleOfflineFolder = [NSString stringWithFormat:NSLocalizedString(@"_add_offline_", nil)];
  3021. if (_metadata.directory) {
  3022. // calcolo lockServerUrl
  3023. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3024. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  3025. else titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  3026. }
  3027. /******************************************* AHKActionSheet *******************************************/
  3028. UIImage *iconHeader;
  3029. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  3030. actionSheet.animationDuration = 0.2;
  3031. actionSheet.blurRadius = 0.0f;
  3032. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  3033. actionSheet.buttonHeight = 50.0;
  3034. actionSheet.cancelButtonHeight = 50.0f;
  3035. actionSheet.separatorHeight = 5.0f;
  3036. actionSheet.automaticallyTintButtonImages = @(NO);
  3037. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_ENCRYPTED };
  3038. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_GRAY };
  3039. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  3040. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:COLOR_GRAY };
  3041. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  3042. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  3043. /******************************************* DIRECTORY *******************************************/
  3044. if (_metadata.directory) {
  3045. UIImage *iconHeader;
  3046. BOOL lockDirectory = NO;
  3047. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3048. NSString *upDir = [CCUtility deletingLastPathComponentFromServerUrl:dirServerUrl];
  3049. NSString *homeDir = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud];
  3050. // Directory bloccata ?
  3051. if ([CCCoreData isDirectoryLock:dirServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3052. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3053. NSString *cameraUploadFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  3054. NSString *cameraUploadFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  3055. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3056. image: iconHeader
  3057. backgroundColor: COLOR_NAVBAR_IOS7
  3058. height: 50.0
  3059. type: AHKActionSheetButtonTypeDisabled
  3060. handler: nil
  3061. ];
  3062. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3063. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3064. image:[UIImage imageNamed:image_actionSheetRename]
  3065. backgroundColor:[UIColor whiteColor]
  3066. height: 50.0
  3067. type:AHKActionSheetButtonTypeDefault
  3068. handler:^(AHKActionSheet *as) {
  3069. // close swipe
  3070. [self setEditing:NO animated:YES];
  3071. //chiediamo il nome del file
  3072. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3073. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3074. alertView.tag = alertRename;
  3075. UITextField *textField = [alertView textFieldAtIndex:0];
  3076. textField.text = _metadata.fileNamePrint;
  3077. [alertView show];
  3078. }];
  3079. }
  3080. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3081. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3082. image:[UIImage imageNamed:image_actionSheetMove]
  3083. backgroundColor:[UIColor whiteColor]
  3084. height: 50.0
  3085. type:AHKActionSheetButtonTypeDefault
  3086. handler:^(AHKActionSheet *as) {
  3087. // close swipe
  3088. [self setEditing:NO animated:YES];
  3089. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3090. }];
  3091. }
  3092. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3093. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3094. image:[UIImage imageNamed:image_actionSheetCrypto]
  3095. backgroundColor:[UIColor whiteColor]
  3096. height: 50.0
  3097. type:AHKActionSheetButtonTypeEncrypted
  3098. handler:^(AHKActionSheet *as) {
  3099. // close swipe
  3100. [self setEditing:NO animated:YES];
  3101. [self performSelector:@selector(encyptedDecryptedFolder) withObject:nil afterDelay:0.1];
  3102. }];
  3103. }
  3104. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES)) {
  3105. [actionSheet addButtonWithTitle:titoloLock
  3106. image:[UIImage imageNamed:image_actionSheetLock]
  3107. backgroundColor:[UIColor whiteColor]
  3108. height: 50.0
  3109. type:AHKActionSheetButtonTypeEncrypted
  3110. handler:^(AHKActionSheet *as) {
  3111. // close swipe
  3112. [self setEditing:NO animated:YES];
  3113. [self performSelector:@selector(comandoLockPassword) withObject:nil afterDelay:0.1];
  3114. }];
  3115. }
  3116. if (_metadata.cryptated == NO && app.hasServerShareSupport && !lockDirectory) {
  3117. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3118. image:[UIImage imageNamed:image_actionSheetShare]
  3119. backgroundColor:[UIColor whiteColor]
  3120. height: 50.0
  3121. type:AHKActionSheetButtonTypeDefault
  3122. handler:^(AHKActionSheet *as) {
  3123. // close swipe
  3124. [self setEditing:NO animated:YES];
  3125. [self openWindowShare:_metadata serverUrl:_localServerUrl];
  3126. }];
  3127. }
  3128. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && _metadata.cryptated == NO) {
  3129. [actionSheet addButtonWithTitle:NSLocalizedString(@"_folder_automatic_upload_", nil)
  3130. image:[UIImage imageNamed:image_folderphotocamera]
  3131. backgroundColor:[UIColor whiteColor]
  3132. height: 50.0
  3133. type:AHKActionSheetButtonTypeDefault
  3134. handler:^(AHKActionSheet *as) {
  3135. // close swipe
  3136. [self setEditing:NO animated:YES];
  3137. // Settings new folder Automatatic upload
  3138. NSString *oldPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  3139. [CCCoreData setCameraUploadFolderName:_metadata.fileName activeAccount:app.activeAccount];
  3140. [CCCoreData setCameraUploadFolderPath:_localServerUrl activeUrl:app.activeUrl typeCloud:app.typeCloud activeAccount:app.activeAccount];
  3141. [CCCoreData clearDateReadDirectory:oldPath activeAccount:app.activeAccount];
  3142. if (app.activeAccount && app.activeUrl && app.activePhotosCameraUpload)
  3143. [app.activePhotosCameraUpload reloadDatasourceForced];
  3144. [self readFolderWithForced:YES];
  3145. }];
  3146. }
  3147. if (!lockDirectory && ([upDir isEqualToString:homeDir] || ![CCCoreData isOfflineDirectoryServerUrl:upDir activeAccount:app.activeAccount])) {
  3148. [actionSheet addButtonWithTitle:titleOfflineFolder
  3149. image:[UIImage imageNamed:image_actionSheetOffline]
  3150. backgroundColor:[UIColor whiteColor]
  3151. height: 50.0
  3152. type:AHKActionSheetButtonTypeDefault
  3153. handler:^(AHKActionSheet *as) {
  3154. // close swipe
  3155. [self setEditing:NO animated:YES];
  3156. if (offlineFolder == NO) {
  3157. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"",nil) message:NSLocalizedString(@"_offline_folder_confirm_",nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3158. alertView.tag = alertOfflineFolder;
  3159. [alertView show];
  3160. } else {
  3161. // remove tag offline for all folder/subfolder/file
  3162. NSArray *directories = [CCCoreData getOfflineDirectoryActiveAccount:app.activeAccount];
  3163. for (TableDirectory *directory in directories)
  3164. if ([directory.serverUrl containsString:dirServerUrl]) {
  3165. [CCCoreData setOfflineDirectoryServerUrl:directory.serverUrl offline:NO activeAccount:app.activeAccount];
  3166. [CCCoreData removeOfflineAllFileFromServerUrl:directory.serverUrl activeAccount:app.activeAccount];
  3167. }
  3168. [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil];
  3169. }
  3170. }];
  3171. }
  3172. [actionSheet show];
  3173. }
  3174. /******************************************* FILE *******************************************/
  3175. if ([_metadata.type isEqualToString:metadataType_file] && !_metadata.directory) {
  3176. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3177. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]])
  3178. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]];
  3179. else
  3180. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3181. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3182. image: iconHeader
  3183. backgroundColor: COLOR_NAVBAR_IOS7
  3184. height: 50.0
  3185. type: AHKActionSheetButtonTypeDisabled
  3186. handler: nil
  3187. ];
  3188. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3189. image:[UIImage imageNamed:image_actionSheetRename]
  3190. backgroundColor:[UIColor whiteColor]
  3191. height: 50.0
  3192. type:AHKActionSheetButtonTypeDefault
  3193. handler:^(AHKActionSheet *as) {
  3194. // close swipe
  3195. [self setEditing:NO animated:YES];
  3196. //chiediamo il nome del file
  3197. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3198. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3199. alertView.tag = alertRename;
  3200. UITextField *textField = [alertView textFieldAtIndex:0];
  3201. textField.text = _metadata.fileNamePrint;
  3202. [alertView show];
  3203. }];
  3204. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3205. image:[UIImage imageNamed:image_actionSheetMove]
  3206. backgroundColor:[UIColor whiteColor]
  3207. height: 50.0
  3208. type:AHKActionSheetButtonTypeDefault
  3209. handler:^(AHKActionSheet *as) {
  3210. // close swipe
  3211. [self setEditing:NO animated:YES];
  3212. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3213. }];
  3214. [actionSheet addButtonWithTitle:NSLocalizedString(@"_reload_", nil)
  3215. image:[UIImage imageNamed:image_actionSheetReload]
  3216. backgroundColor:[UIColor whiteColor]
  3217. height: 50.0
  3218. type:AHKActionSheetButtonTypeDefault
  3219. handler:^(AHKActionSheet *as) {
  3220. // close swipe
  3221. [self setEditing:NO animated:YES];
  3222. [self performSelector:@selector(reloadFile:) withObject:_metadata afterDelay:0.1];
  3223. }];
  3224. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  3225. image:[UIImage imageNamed:image_actionSheetOpenIn]
  3226. backgroundColor:[UIColor whiteColor]
  3227. height: 50.0
  3228. type:AHKActionSheetButtonTypeDefault
  3229. handler:^(AHKActionSheet *as) {
  3230. // close swipe
  3231. [self setEditing:NO animated:YES];
  3232. [self performSelector:@selector(openIn:) withObject:_metadata afterDelay:0.1];
  3233. }];
  3234. if (_metadata.cryptated == NO && app.hasServerShareSupport) {
  3235. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3236. image:[UIImage imageNamed:image_actionSheetShare]
  3237. backgroundColor:[UIColor whiteColor]
  3238. height: 50.0
  3239. type:AHKActionSheetButtonTypeDefault
  3240. handler:^(AHKActionSheet *as) {
  3241. // close swipe
  3242. [self setEditing:NO animated:YES];
  3243. [self openWindowShare:_metadata serverUrl:_localServerUrl];
  3244. }];
  3245. }
  3246. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3247. image:[UIImage imageNamed:image_actionSheetCrypto]
  3248. backgroundColor:[UIColor whiteColor]
  3249. height: 50.0
  3250. type:AHKActionSheetButtonTypeEncrypted
  3251. handler:^(AHKActionSheet *as) {
  3252. // close swipe
  3253. [self setEditing:NO animated:YES];
  3254. [self performSelector:@selector(cmdEncryptedDecryptedFile) withObject:nil afterDelay:0.1];
  3255. }];
  3256. if (![CCCoreData isOfflineDirectoryServerUrl:_localServerUrl activeAccount:app.activeAccount]) {
  3257. [actionSheet addButtonWithTitle:titoloOffline
  3258. image:[UIImage imageNamed:image_actionSheetOffline]
  3259. backgroundColor:[UIColor whiteColor]
  3260. height: 50.0
  3261. type:AHKActionSheetButtonTypeDefault
  3262. handler:^(AHKActionSheet *as) {
  3263. // close swipe
  3264. [self setEditing:NO animated:YES];
  3265. if ([CCCoreData isOfflineLocalFileID:_metadata.fileID activeAccount:app.activeAccount]) {
  3266. [self removeOffline:_metadata];
  3267. } else {
  3268. [self addOffline:_metadata];
  3269. }
  3270. }];
  3271. }
  3272. [actionSheet addButtonWithTitle:NSLocalizedString(@"_add_local_", nil)
  3273. image:[UIImage imageNamed:image_actionSheetLocal]
  3274. backgroundColor:[UIColor whiteColor]
  3275. height: 50.0
  3276. type:AHKActionSheetButtonTypeDefault
  3277. handler:^(AHKActionSheet *as) {
  3278. // close swipe
  3279. [self setEditing:NO animated:YES];
  3280. [self performSelector:@selector(addLocal:) withObject:_metadata afterDelay:0.1];
  3281. }];
  3282. [actionSheet show];
  3283. }
  3284. /******************************************* TEMPLATE *******************************************/
  3285. if ([_metadata.type isEqualToString:metadataType_model]) {
  3286. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3287. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3288. image: iconHeader
  3289. backgroundColor: COLOR_NAVBAR_IOS7
  3290. height: 50.0
  3291. type: AHKActionSheetButtonTypeDisabled
  3292. handler: nil
  3293. ];
  3294. if ([_metadata.model isEqualToString:@"note"]) {
  3295. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3296. image:[UIImage imageNamed:image_actionSheetRename]
  3297. backgroundColor:[UIColor whiteColor]
  3298. height: 50.0
  3299. type:AHKActionSheetButtonTypeDefault
  3300. handler:^(AHKActionSheet *as) {
  3301. // close swipe
  3302. [self setEditing:NO animated:YES];
  3303. //chiediamo il nome del file
  3304. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3305. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3306. alertView.tag = alertRename;
  3307. UITextField *textField = [alertView textFieldAtIndex:0];
  3308. textField.text = _metadata.fileNamePrint;
  3309. [alertView show];
  3310. }];
  3311. }
  3312. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3313. image:[UIImage imageNamed:image_actionSheetMove]
  3314. backgroundColor:[UIColor whiteColor]
  3315. height: 50.0
  3316. type:AHKActionSheetButtonTypeDefault
  3317. handler:^(AHKActionSheet *as) {
  3318. // close swipe
  3319. [self setEditing:NO animated:YES];
  3320. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3321. }];
  3322. [actionSheet addButtonWithTitle:titoloOffline
  3323. image:[UIImage imageNamed:image_actionSheetOffline]
  3324. backgroundColor:[UIColor whiteColor]
  3325. height: 50.0
  3326. type:AHKActionSheetButtonTypeDefault
  3327. handler:^(AHKActionSheet *as) {
  3328. // close swipe
  3329. [self setEditing:NO animated:YES];
  3330. if ([CCCoreData isOfflineLocalFileID:_metadata.fileID activeAccount:app.activeAccount])
  3331. [self removeOffline:_metadata];
  3332. else
  3333. [self addOffline:_metadata];
  3334. }];
  3335. [actionSheet addButtonWithTitle:NSLocalizedString(@"_add_local_", nil)
  3336. image:[UIImage imageNamed:image_actionSheetLocal]
  3337. backgroundColor:[UIColor whiteColor]
  3338. height: 50.0
  3339. type:AHKActionSheetButtonTypeDefault
  3340. handler:^(AHKActionSheet *as) {
  3341. // close swipe
  3342. [self setEditing:NO animated:YES];
  3343. [self performSelector:@selector(addLocal:) withObject:_metadata afterDelay:0.1];
  3344. }];
  3345. [actionSheet show];
  3346. }
  3347. }
  3348. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  3349. {
  3350. return NSLocalizedString(@"_delete_", nil);
  3351. }
  3352. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  3353. {
  3354. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3355. if (metadata == nil || metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier >= 0 || metadata.sessionTaskIdentifier >= 0) return NO;
  3356. else return YES;
  3357. }
  3358. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  3359. {
  3360. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3361. if (_metadata.errorPasscode || (_metadata.cryptated && [_metadata.title length] == 0) || _metadata.sessionTaskIdentifier >= 0 || _metadata.sessionTaskIdentifier >= 0) return UITableViewCellEditingStyleNone;
  3362. else return UITableViewCellEditingStyleDelete;
  3363. }
  3364. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  3365. {
  3366. BOOL lockDirectory = NO;
  3367. // Directory locked ?
  3368. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3369. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3370. if (lockDirectory && editingStyle == UITableViewCellEditingStyleDelete) {
  3371. [app messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  3372. return;
  3373. }
  3374. if (editingStyle == UITableViewCellEditingStyleDelete) {
  3375. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3376. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  3377. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  3378. style:UIAlertActionStyleDestructive
  3379. handler:^(UIAlertAction *action) {
  3380. [self performSelector:@selector(deleteFile) withObject:nil afterDelay:0.1];
  3381. }]];
  3382. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  3383. style:UIAlertActionStyleCancel
  3384. handler:^(UIAlertAction *action) {
  3385. [alertController dismissViewControllerAnimated:YES completion:nil];
  3386. }]];
  3387. alertController.popoverPresentationController.sourceView = self.view;
  3388. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  3389. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  3390. [alertController.view layoutIfNeeded];
  3391. [self presentViewController:alertController animated:YES completion:nil];
  3392. }
  3393. }
  3394. #pragma --------------------------------------------------------------------------------------------
  3395. #pragma mark - ==== Datasource ====
  3396. #pragma --------------------------------------------------------------------------------------------
  3397. - (void)clearDateReadDataSource:(NSNotification *)notification
  3398. {
  3399. _dateReadDataSource = Nil;
  3400. }
  3401. - (void)getDataSourceWithReloadTableView
  3402. {
  3403. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  3404. }
  3405. - (void)getDataSourceWithReloadTableView:(NSString *)directoryID fileID:(NSString *)fileID selector:(NSString *)selector
  3406. {
  3407. if (app.activeAccount == nil || app.activeUrl == nil || directoryID == nil)
  3408. return;
  3409. // Reload -> Self se non siamo nella dir appropriata cercala e se è in memoria reindirizza il reload
  3410. if ([directoryID isEqualToString:_localDirectoryID] == NO || _localServerUrl == nil) {
  3411. if ([selector isEqualToString:selectorDownloadOffline]) {
  3412. [app.controlCenter reloadDatasource];
  3413. } else {
  3414. CCMain *main = [app.listMainVC objectForKey:[CCCoreData getServerUrlFromDirectoryID:directoryID activeAccount:app.activeAccount]];
  3415. if (main) {
  3416. [main getDataSourceWithReloadTableView];
  3417. } else {
  3418. [self tableViewReload];
  3419. [app.controlCenter reloadDatasource];
  3420. }
  3421. }
  3422. return;
  3423. }
  3424. // Offline folder ?
  3425. _isOfflineLocalServerUrl = [CCCoreData isOfflineDirectoryServerUrl:_localServerUrl activeAccount:app.activeAccount];
  3426. [app.controlCenter reloadDatasource];
  3427. // Settaggio variabili per le ottimizzazioni
  3428. _directoryGroupBy = [CCUtility getGroupBySettings];
  3429. _directoryOrder = [CCUtility getOrderSettings];
  3430. // Controllo data lettura Data Source
  3431. NSDate *dateDateRecordDirectory = [CCCoreData getDateReadDirectoryID:_localDirectoryID activeAccount:app.activeAccount];
  3432. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  3433. NSLog(@"[LOG] Rebuild Data Source File : %@", _localServerUrl);
  3434. _dateReadDataSource = [NSDate date];
  3435. // Data Source
  3436. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, directoryID] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  3437. _sectionDataSource = [CCSection creataDataSourseSectionTableMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
  3438. } else {
  3439. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _localServerUrl, _dateReadDataSource);
  3440. }
  3441. [self tableViewReload];
  3442. [self setTitleBackgroundTableView];
  3443. [app updateApplicationIconBadgeNumber];
  3444. }
  3445. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  3446. {
  3447. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  3448. if (selectedRows.count > 0) {
  3449. for (NSIndexPath *selectionIndex in selectedRows) {
  3450. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  3451. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3452. [metadatas addObject:metadata];
  3453. }
  3454. }
  3455. return metadatas;
  3456. }
  3457. - (CCMetadata *)getMetadataFromSectionDataSource:(NSIndexPath *)indexPath
  3458. {
  3459. NSInteger section = indexPath.section + 1;
  3460. NSInteger row = indexPath.row + 1;
  3461. NSInteger totSections =[_sectionDataSource.sections count] ;
  3462. if ((totSections < section) || (section > totSections)) {
  3463. NSString *message = [NSString stringWithFormat:@"DEBUG [0] : error section, totSections = %lu - section = %lu", (long)totSections, (long)section];
  3464. NSLog(@"[LOG] %@", message);
  3465. #if DEBUG
  3466. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3467. [alertView show];
  3468. #endif
  3469. return nil;
  3470. }
  3471. id valueSection = [_sectionDataSource.sections objectAtIndex:indexPath.section];
  3472. NSArray *fileIDs = [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3473. if (fileIDs) {
  3474. NSInteger totRows =[fileIDs count] ;
  3475. if ((totRows < row) || (row > totRows)) {
  3476. NSString *message = [NSString stringWithFormat:@"DEBUG [1] : error row, totRows = %lu - row = %lu [%@] [%@] [%@]", (long)totRows, (long)row, valueSection, _localDirectoryID, _localServerUrl];
  3477. NSLog(@"[LOG] %@", message);
  3478. #if DEBUG
  3479. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3480. [alertView show];
  3481. #endif
  3482. return nil;
  3483. }
  3484. } else {
  3485. NSLog(@"[LOG] DEBUG [2] : fileIDs is NIL");
  3486. #if DEBUG
  3487. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:@"DEBUG [2] : fileIDs is NIL" delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3488. [alertView show];
  3489. #endif
  3490. return nil;
  3491. }
  3492. NSString *fileID = [fileIDs objectAtIndex:indexPath.row];
  3493. return [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3494. }
  3495. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  3496. {
  3497. NSInteger totSections =[_sectionDataSource.sections count] ;
  3498. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  3499. #if DEBUG
  3500. 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];
  3501. [alertView show];
  3502. #endif
  3503. return nil;
  3504. }
  3505. id valueSection = [_sectionDataSource.sections objectAtIndex:section];
  3506. return [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3507. }
  3508. #pragma --------------------------------------------------------------------------------------------
  3509. #pragma mark - ==== Table ====
  3510. #pragma --------------------------------------------------------------------------------------------
  3511. - (void)tableViewSelect:(BOOL)edit
  3512. {
  3513. // chiudiamo eventuali swipe aperti
  3514. if (edit) [self.tableView setEditing:NO animated:NO];
  3515. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  3516. [self.tableView setEditing:edit animated:YES];
  3517. _isSelectedMode = edit;
  3518. if (edit)
  3519. [self setUINavigationBarSelected];
  3520. else
  3521. [self setUINavigationBarDefault];
  3522. [self setTitleNOAnimation];
  3523. }
  3524. - (void)tableViewReload
  3525. {
  3526. // ricordiamoci le row selezionate
  3527. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  3528. [self.tableView reloadData];
  3529. for (NSIndexPath *path in indexPaths)
  3530. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  3531. [self setTableViewFooter];
  3532. if (self.tableView.editing)
  3533. [self setTitleNOAnimation];
  3534. }
  3535. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  3536. {
  3537. return 60;
  3538. }
  3539. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  3540. {
  3541. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  3542. }
  3543. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  3544. {
  3545. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  3546. }
  3547. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  3548. {
  3549. NSArray *sections = [_sectionDataSource.sectionArrayRow allKeys];
  3550. NSString *sectionTitle = [sections objectAtIndex:section];
  3551. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  3552. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  3553. if ([_directoryGroupBy isEqualToString:@"none"] && [sections count] <= 1) return 0.f;
  3554. return 20.f;
  3555. }
  3556. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  3557. {
  3558. float shift;
  3559. UIVisualEffectView *visualEffectView;
  3560. // Titolo
  3561. NSString *titleSection;
  3562. // Controllo
  3563. if ([_sectionDataSource.sections count] == 0)
  3564. return nil;
  3565. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  3566. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  3567. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  3568. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  3569. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  3570. else titleSection = NSLocalizedString(titleSection,nil);
  3571. // Formato titolo
  3572. NSString *currentDevice = [CCUtility currentDevice];
  3573. if ([currentDevice rangeOfString:@"iPad3"].location != NSNotFound) {
  3574. visualEffectView = [[UIVisualEffectView alloc] init];
  3575. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR_NO_BLUR;
  3576. } else {
  3577. UIVisualEffect *blurEffect;
  3578. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  3579. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  3580. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR;
  3581. }
  3582. if ([_directoryGroupBy isEqualToString:@"alphabetic"]) {
  3583. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) shift = - 35;
  3584. else shift = - 20;
  3585. } else shift = - 10;
  3586. // Title
  3587. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  3588. titleLabel.backgroundColor=[UIColor clearColor];
  3589. titleLabel.textColor = COLOR_GRAY;
  3590. titleLabel.font = [UIFont systemFontOfSize:12];
  3591. titleLabel.textAlignment = NSTextAlignmentLeft;
  3592. titleLabel.text = titleSection;
  3593. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3594. [visualEffectView addSubview:titleLabel];
  3595. // Elements
  3596. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  3597. elementLabel.backgroundColor=[UIColor clearColor];
  3598. elementLabel.textColor = COLOR_GRAY;
  3599. elementLabel.font = [UIFont systemFontOfSize:12];
  3600. elementLabel.textAlignment = NSTextAlignmentRight;
  3601. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3602. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  3603. NSUInteger rowsCount = [metadatas count];
  3604. if (rowsCount == 0) return nil;
  3605. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  3606. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  3607. [visualEffectView addSubview:elementLabel];
  3608. return visualEffectView;
  3609. }
  3610. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  3611. {
  3612. return [_sectionDataSource.sections indexOfObject:title];
  3613. }
  3614. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  3615. {
  3616. if ([_directoryGroupBy isEqualToString:@"alphabetic"])
  3617. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  3618. else
  3619. return nil;
  3620. }
  3621. /*
  3622. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  3623. {
  3624. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  3625. }
  3626. }
  3627. */
  3628. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  3629. {
  3630. NSString *typeCell;
  3631. NSString *dataFile;
  3632. NSString *lunghezzaFile;
  3633. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3634. if ([metadata.session isEqualToString:@""] || metadata.session == nil) typeCell = @"CellMain";
  3635. else typeCell = @"CellMainTransfer";
  3636. if (!metadata)
  3637. return [tableView dequeueReusableCellWithIdentifier:typeCell];
  3638. CCCellMainTransfer *cell = (CCCellMainTransfer *)[tableView dequeueReusableCellWithIdentifier:typeCell forIndexPath:indexPath];
  3639. // separator
  3640. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  3641. // change color selection
  3642. UIView *selectionColor = [[UIView alloc] init];
  3643. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  3644. cell.selectedBackgroundView = selectionColor;
  3645. if ([typeCell isEqualToString:@"CellMain"]) cell.backgroundColor = [UIColor whiteColor];
  3646. if ([typeCell isEqualToString:@"CellMainTransfer"]) cell.backgroundColor = COLOR_TRANSFER_BACKGROUND;
  3647. // ----------------------------------------------------------------------------------------------------------
  3648. // DEFAULT
  3649. // ----------------------------------------------------------------------------------------------------------
  3650. cell.fileImageView.image = nil;
  3651. cell.statusImageView.image = nil;
  3652. cell.offlineImageView.image = nil;
  3653. cell.synchronizedImageView.image = nil;
  3654. cell.sharedImageView.image = nil;
  3655. cell.labelTitle.enabled = YES;
  3656. cell.labelTitle.text = @"";
  3657. cell.labelInfoFile.enabled = YES;
  3658. cell.labelInfoFile.text = @"";
  3659. cell.progressView.progress = 0.0;
  3660. cell.progressView.hidden = YES;
  3661. cell.cancelTaskButton.hidden = YES;
  3662. cell.reloadTaskButton.hidden = YES;
  3663. cell.stopTaskButton.hidden = YES;
  3664. // colori e font
  3665. if (metadata.cryptated) {
  3666. cell.labelTitle.textColor = COLOR_ENCRYPTED;
  3667. //nameLabel.font = RalewayLight(13.0f);
  3668. cell.labelInfoFile.textColor = [UIColor blackColor];
  3669. //detailLabel.font = RalewayLight(9.0f);
  3670. } else {
  3671. cell.labelTitle.textColor = COLOR_CLEAR;
  3672. //nameLabel.font = RalewayLight(13.0f);
  3673. cell.labelInfoFile.textColor = [UIColor blackColor];
  3674. //detailLabel.font = RalewayLight(9.0f);
  3675. }
  3676. // ----------------------------------------------------------------------------------------------------------
  3677. // File Name & Folder
  3678. // ----------------------------------------------------------------------------------------------------------
  3679. // nome del file
  3680. cell.labelTitle.text = metadata.fileNamePrint;
  3681. // è una directory
  3682. if (metadata.directory) {
  3683. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3684. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  3685. lunghezzaFile = @" ";
  3686. // ----------------------------------------------------------------------------------------------------------
  3687. // Offline Folder
  3688. // ----------------------------------------------------------------------------------------------------------
  3689. NSString *directoryServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:metadata.fileNameData];
  3690. BOOL isOfflineDirectory = [CCCoreData isOfflineDirectoryServerUrl:directoryServerUrl activeAccount:app.activeAccount];
  3691. // Verify Offline
  3692. if (_isOfflineLocalServerUrl == YES && isOfflineDirectory == NO) {
  3693. [CCCoreData setOfflineDirectoryServerUrl:directoryServerUrl offline:YES activeAccount:app.activeAccount];
  3694. isOfflineDirectory = YES;
  3695. }
  3696. if (isOfflineDirectory) {
  3697. // Image Offline
  3698. if (metadata.cryptated) cell.offlineImageView.image = [UIImage imageNamed:image_offlinecrypto];
  3699. else cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  3700. // Animation synchronized gif
  3701. if ([[CCOfflineFileFolder sharedOfflineFileFolder] offlineFolderAnimationDirectory:[[NSArray alloc] initWithObjects:directoryServerUrl, nil] callViewController:NO]) {
  3702. NSURL *myURL;
  3703. if (metadata.cryptated) myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  3704. else myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  3705. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  3706. }
  3707. }
  3708. } else {
  3709. // è un file
  3710. dataFile = [CCUtility dateDiff:metadata.date];
  3711. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  3712. // Plist ancora da scaricare
  3713. if (metadata.cryptated && [metadata.title length] == 0) {
  3714. dataFile = @" ";
  3715. lunghezzaFile = @" ";
  3716. }
  3717. TableLocalFile *recordLocalFile = [CCCoreData getLocalFileWithFileID:metadata.fileID activeAccount:app.activeAccount];
  3718. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3719. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  3720. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  3721. if ([metadata.type isEqualToString:metadataType_model] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO)
  3722. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", dataFile];
  3723. if ([metadata.type isEqualToString:metadataType_file] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO) {
  3724. if (recordLocalFile && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
  3725. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", dataFile, lunghezzaFile];
  3726. else
  3727. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ ◦ %@", dataFile, lunghezzaFile];
  3728. }
  3729. // Plist ancora da scaricare
  3730. if ([dataFile isEqualToString:@" "] && [lunghezzaFile isEqualToString:@" "])
  3731. cell.labelInfoFile.text = NSLocalizedString(@"_no_plist_pull_down_",nil);
  3732. cell.accessoryType = UITableViewCellAccessoryNone;
  3733. }
  3734. // ----------------------------------------------------------------------------------------------------------
  3735. // File Image View
  3736. // ----------------------------------------------------------------------------------------------------------
  3737. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3738. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  3739. cell.fileImageView.image = [app.icoImagesCache objectForKey:metadata.fileID];
  3740. if (cell.fileImageView.image == nil) {
  3741. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  3742. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  3743. [app.icoImagesCache setObject:image forKey:metadata.fileID];
  3744. dispatch_async(dispatch_get_main_queue(), ^{
  3745. CCCellMainTransfer *cell = [tableView cellForRowAtIndexPath:indexPath];
  3746. if (cell)
  3747. cell.fileImageView.image = image;
  3748. });
  3749. });
  3750. }
  3751. } else {
  3752. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  3753. if (metadata.thumbnailExists)
  3754. [self downloadThumbnail:metadata];
  3755. }
  3756. // ----------------------------------------------------------------------------------------------------------
  3757. // Image Status cyptated & Lock Passcode
  3758. // ----------------------------------------------------------------------------------------------------------
  3759. // File Cyptated
  3760. if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString:metadataType_model] == NO) {
  3761. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  3762. }
  3763. // Directory con passcode lock attivato
  3764. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:metadata.fileNameData];
  3765. if (metadata.directory && ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length])) cell.statusImageView.image = [UIImage imageNamed:image_passcode];
  3766. // ----------------------------------------------------------------------------------------------------------
  3767. // Offline
  3768. // ----------------------------------------------------------------------------------------------------------
  3769. BOOL isOfflineFile = [CCCoreData isOfflineLocalFileID:metadata.fileID activeAccount:app.activeAccount];
  3770. // Verify Offline
  3771. if(_isOfflineLocalServerUrl == YES && isOfflineFile == NO) {
  3772. [CCCoreData setOfflineLocalFileID:metadata.fileID offline:YES activeAccount:app.activeAccount];
  3773. isOfflineFile = YES;
  3774. }
  3775. if (isOfflineFile) {
  3776. if (metadata.cryptated) cell.offlineImageView.image = [UIImage imageNamed:image_offlinecrypto];
  3777. else cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  3778. }
  3779. // ----------------------------------------------------------------------------------------------------------
  3780. // Share
  3781. // ----------------------------------------------------------------------------------------------------------
  3782. NSString *shareLink = [app.sharesLink objectForKey:[_localServerUrl stringByAppendingString:metadata.fileName]];
  3783. NSString *shareUserAndGroup = [app.sharesUserAndGroup objectForKey:[_localServerUrl stringByAppendingString:metadata.fileName]];
  3784. BOOL isShare = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_shared].location == NSNotFound);
  3785. BOOL isMounted = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_mounted].location == NSNotFound);
  3786. // Aggiungiamo il Tap per le shared
  3787. if (isShare || [shareLink length] > 0 || [shareUserAndGroup length] > 0 || isMounted) {
  3788. if (isShare) {
  3789. cell.sharedImageView.image = [UIImage imageNamed:image_shareConnect];
  3790. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3791. [tap setNumberOfTapsRequired:1];
  3792. cell.sharedImageView.userInteractionEnabled = YES;
  3793. [cell.sharedImageView addGestureRecognizer:tap];
  3794. }
  3795. if (isMounted) {
  3796. cell.sharedImageView.image = [UIImage imageNamed:image_shareMounted];
  3797. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3798. [tap setNumberOfTapsRequired:1];
  3799. cell.sharedImageView.userInteractionEnabled = YES;
  3800. [cell.sharedImageView addGestureRecognizer:tap];
  3801. }
  3802. if ([shareLink length] > 0 || [shareUserAndGroup length] > 0) {
  3803. if ([shareLink length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareLink];
  3804. if ([shareUserAndGroup length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareUser];
  3805. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  3806. [tap setNumberOfTapsRequired:1];
  3807. cell.sharedImageView.userInteractionEnabled = YES;
  3808. [cell.sharedImageView addGestureRecognizer:tap];
  3809. }
  3810. } else {
  3811. cell.sharedImageView.userInteractionEnabled = NO;
  3812. }
  3813. // ----------------------------------------------------------------------------------------------------------
  3814. // downloadFile
  3815. // ----------------------------------------------------------------------------------------------------------
  3816. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
  3817. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusdownloadcrypto];
  3818. else cell.statusImageView.image = [UIImage imageNamed:image_statusdownload];
  3819. // sessionTaskIdentifier : RELOAD + STOP
  3820. if (metadata.sessionTaskIdentifier != taskIdentifierDone) {
  3821. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  3822. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  3823. cell.cancelTaskButton.hidden = NO;
  3824. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3825. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3826. cell.reloadTaskButton.hidden = NO;
  3827. }
  3828. // sessionTaskIdentifierPlist : RELOAD
  3829. if (metadata.sessionTaskIdentifierPlist != taskIdentifierDone) {
  3830. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3831. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3832. cell.reloadTaskButton.hidden = NO;
  3833. }
  3834. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3835. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3836. if (progress > 0) {
  3837. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
  3838. else cell.progressView.progressTintColor = COLOR_CLEAR;
  3839. cell.progressView.progress = progress;
  3840. cell.progressView.hidden = NO;
  3841. }
  3842. // ----------------------------------------------------------------------------------------------------------
  3843. // downloadFile Error
  3844. // ----------------------------------------------------------------------------------------------------------
  3845. if (metadata.sessionTaskIdentifier == taskIdentifierError || metadata.sessionTaskIdentifierPlist == taskIdentifierError) {
  3846. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  3847. if ([metadata.sessionError length] == 0)
  3848. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  3849. else
  3850. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3851. }
  3852. }
  3853. // ----------------------------------------------------------------------------------------------------------
  3854. // uploadFile
  3855. // ----------------------------------------------------------------------------------------------------------
  3856. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  3857. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusuploadcrypto];
  3858. else cell.statusImageView.image = [UIImage imageNamed:image_statusupload];
  3859. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetaskcrypto] forState:UIControlStateNormal];
  3860. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetask] forState:UIControlStateNormal];
  3861. cell.cancelTaskButton.hidden = NO;
  3862. if (metadata.sessionTaskIdentifier == taskIdentifierStop) {
  3863. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3864. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3865. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusstopcrypto];
  3866. else cell.statusImageView.image = [UIImage imageNamed:image_statusstop];
  3867. cell.reloadTaskButton.hidden = NO;
  3868. cell.stopTaskButton.hidden = YES;
  3869. } else {
  3870. if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  3871. else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  3872. cell.stopTaskButton.hidden = NO;
  3873. cell.reloadTaskButton.hidden = YES;
  3874. }
  3875. // se non c'è una preview in bianconero metti l'immagine di default
  3876. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  3877. cell.fileImageView.image = [UIImage imageNamed:image_uploaddisable];
  3878. cell.labelTitle.enabled = NO;
  3879. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3880. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3881. if (progress > 0) {
  3882. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
  3883. else cell.progressView.progressTintColor = COLOR_CLEAR;
  3884. cell.progressView.progress = progress;
  3885. cell.progressView.hidden = NO;
  3886. }
  3887. // ----------------------------------------------------------------------------------------------------------
  3888. // uploadFileError
  3889. // ----------------------------------------------------------------------------------------------------------
  3890. if (metadata.sessionTaskIdentifier == taskIdentifierError || metadata.sessionTaskIdentifierPlist == taskIdentifierError) {
  3891. cell.labelTitle.enabled = NO;
  3892. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  3893. if ([metadata.sessionError length] == 0)
  3894. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  3895. else
  3896. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3897. }
  3898. }
  3899. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3900. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3901. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3902. return cell;
  3903. }
  3904. - (void)setTableViewFooter
  3905. {
  3906. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3907. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3908. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3909. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3910. UIFont *appFont = [UIFont systemFontOfSize:12];
  3911. footerLabel.font = appFont;
  3912. footerLabel.textColor = [UIColor grayColor];
  3913. footerLabel.backgroundColor = [UIColor clearColor];
  3914. footerLabel.textAlignment = NSTextAlignmentCenter;
  3915. NSString *folders;
  3916. NSString *files;
  3917. NSString *footerText;
  3918. if (_sectionDataSource.directories > 1) {
  3919. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  3920. } else if (_sectionDataSource.directories == 1){
  3921. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  3922. } else {
  3923. folders = @"";
  3924. }
  3925. if (_sectionDataSource.files > 1) {
  3926. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  3927. } else if (_sectionDataSource.files == 1){
  3928. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  3929. } else {
  3930. files = @"";
  3931. }
  3932. if ([folders isEqualToString:@""]) {
  3933. footerText = files;
  3934. } else if ([files isEqualToString:@""]) {
  3935. footerText = folders;
  3936. } else {
  3937. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  3938. }
  3939. footerLabel.text = footerText;
  3940. [footerView addSubview:footerLabel];
  3941. [self.tableView setTableFooterView:footerView];
  3942. }
  3943. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3944. {
  3945. NSString *textMessage;
  3946. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  3947. // se non può essere selezionata deseleziona
  3948. if ([cell isEditing] == NO)
  3949. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  3950. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  3951. if (self.tableView.editing) {
  3952. [self setTitleNOAnimation];
  3953. return;
  3954. }
  3955. // test crash
  3956. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
  3957. if (indexPath.row >= [metadatas count]) return;
  3958. // settiamo il record file.
  3959. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3960. // se è in corso una sessione
  3961. if ([_metadata.session length] > 0) return;
  3962. if (_metadata.errorPasscode) {
  3963. // se UUID è nil lo sta ancora caricando quindi esci
  3964. if (!_metadata.uuid) return;
  3965. // esiste un hint ??
  3966. CCCrypto *crypto = [[CCCrypto alloc] init];
  3967. NSString *hint = [crypto getHintFromFile:_metadata.fileName isLocal:NO directoryUser:app.directoryUser];
  3968. // qui !! la richiesta della nuova passcode
  3969. if ([_metadata.uuid isEqualToString:[CCUtility getUUID]]) {
  3970. // stesso UUID ... la password è stata modificata !!!!!!
  3971. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_same_device_different_passcode_hint_",nil), hint];
  3972. else textMessage = NSLocalizedString(@"_same_device_different_passcode_", nil);
  3973. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3974. [alertView show];
  3975. } else {
  3976. // UUID diverso.
  3977. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_hint_",nil), _metadata.nameCurrentDevice, hint];
  3978. else textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_",nil), _metadata.nameCurrentDevice];
  3979. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3980. [alertView show];
  3981. }
  3982. // chiediamo la passcode e ricarichiamo tutto.
  3983. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  3984. viewController.delegate = self;
  3985. viewController.fromType = CCBKPasscodeFromPasscode;
  3986. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  3987. viewController.passcodeInputView.maximumLength = 64;
  3988. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  3989. viewController.inputViewTitlePassword = NO;
  3990. viewController.title = _brand_;
  3991. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  3992. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  3993. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  3994. [self presentViewController:navigationController animated:YES completion:nil];
  3995. }
  3996. // modello o plist con il title a 0 allora è andato storto qualcosa ... ricaricalo
  3997. if (_metadata.cryptated && [_metadata.title length] == 0) {
  3998. NSString* selector;
  3999. if ([_metadata.type isEqualToString:metadataType_model]) selector = selectorLoadModelView;
  4000. else selector = selectorLoadPlist;
  4001. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:NO downloadPlist:YES selector:selector selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  4002. return;
  4003. }
  4004. // se il plist è caricato ed è un modello aprilo
  4005. if ([_metadata.type isEqualToString:metadataType_model]) [self openModel:_metadata.model isNew:false];
  4006. // file
  4007. if (_metadata.directory == NO && _metadata.errorPasscode == NO && [_metadata.type isEqualToString:metadataType_file]) {
  4008. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  4009. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
  4010. [self downloadFileSuccess:_metadata.fileID serverUrl:_localServerUrl selector:selectorLoadFileView selectorPost:nil];
  4011. } else {
  4012. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorLoadFileView selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  4013. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  4014. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  4015. }
  4016. }
  4017. if (_metadata.directory) [self performSegueDirectoryWithControlPasscode:true];
  4018. }
  4019. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  4020. {
  4021. [self setTitleNOAnimation];
  4022. }
  4023. #pragma --------------------------------------------------------------------------------------------
  4024. #pragma mark ===== Offline Folder Cell =====
  4025. #pragma --------------------------------------------------------------------------------------------
  4026. - (void)offlineFolderGraphicsServerUrl:(NSString *)serverUrl animation:(BOOL)animation
  4027. {
  4028. BOOL cryptated = NO;
  4029. CCCellMain *cell;
  4030. for (NSString* fileID in _sectionDataSource.allRecordsDataSource) {
  4031. CCMetadata *recordMetadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4032. if (recordMetadata.directory == NO)
  4033. continue;
  4034. if ([[CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:recordMetadata.fileNameData] isEqualToString:serverUrl]) {
  4035. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:recordMetadata.fileID];
  4036. cell = (CCCellMain *)[self.tableView cellForRowAtIndexPath:indexPath];
  4037. cryptated = recordMetadata.cryptated;
  4038. break;
  4039. }
  4040. }
  4041. if (!cell)
  4042. return;
  4043. if (animation) {
  4044. NSURL *myURL;
  4045. if (cryptated)
  4046. myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  4047. else
  4048. myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  4049. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  4050. } else {
  4051. cell.synchronizedImageView.image = nil;
  4052. }
  4053. }
  4054. #pragma --------------------------------------------------------------------------------------------
  4055. #pragma mark ===== Navigation ====
  4056. #pragma --------------------------------------------------------------------------------------------
  4057. - (BOOL)shouldPerformSegue:(NSString *)serverUrl
  4058. {
  4059. // if background return
  4060. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  4061. // se non siamo in primo piano o se non siamo nella stessa directory esci
  4062. if (self.view.window == NO || ([serverUrl isEqualToString:_localServerUrl] == NO && serverUrl))
  4063. return NO;
  4064. // Collapsed ma siamo già in detail esci
  4065. if (self.splitViewController.isCollapsed)
  4066. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return NO;
  4067. // Video in esecuzione esci
  4068. if (_detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && _detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  4069. return YES;
  4070. }
  4071. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  4072. {
  4073. id viewController = segue.destinationViewController;
  4074. if ([viewController isKindOfClass:[UINavigationController class]]) {
  4075. UINavigationController *nav = viewController;
  4076. _detailViewController = (CCDetail *)nav.topViewController;
  4077. } else {
  4078. _detailViewController = segue.destinationViewController;
  4079. }
  4080. NSMutableArray *allRecordsDataSourceImagesVideos = [[NSMutableArray alloc] init];
  4081. for (NSString *fileID in _sectionDataSource.allFileID) {
  4082. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4083. if ([metadata.typeFile isEqualToString:metadataTypeFile_image] || [metadata.typeFile isEqualToString:metadataTypeFile_video])
  4084. [allRecordsDataSourceImagesVideos addObject:metadata];
  4085. }
  4086. _detailViewController.delegate = self;
  4087. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  4088. _detailViewController.metadataDetail = _metadataSegue;
  4089. _detailViewController.dateFilterQuery = nil;
  4090. _detailViewController.isCameraUpload = NO;
  4091. _detailViewController.sourceDirectory = sorceDirectoryAccount;
  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