CCMain.m 257 KB

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