CCMain.m 260 KB

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