CCMain.m 254 KB

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