CCMain.m 231 KB

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