CCMain.m 256 KB

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