CCMain.m 264 KB

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