CCMain.m 260 KB

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