CCMain.m 260 KB

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