CCMain.m 256 KB

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