CCMain.m 255 KB

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