CCMain.m 264 KB

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