CCMain.m 263 KB

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