CCMain.m 257 KB

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