CCMain.m 261 KB

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