CCMain.m 265 KB

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