CCMain.m 265 KB

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