CCMain.m 259 KB

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