CCMain.m 257 KB

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