CCMain.m 259 KB

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