CCMain.m 264 KB

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