CCMain.m 260 KB

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