From 059982cc102de394ac316abc3ee0806673d003d5 Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Mon, 14 Nov 2005 02:40:16 +0000 Subject: [PATCH] working on move, edit mode and add remove service to context menu --- lib/dvb/db.cpp | 44 +++++++++++++++++++++++++- lib/dvb/idvb.h | 3 +- lib/python/Components/ServiceList.py | 6 ++++ lib/python/Screens/ChannelSelection.py | 25 +++++++++++++-- lib/service/iservice.h | 2 ++ lib/service/listboxservice.h | 14 ++++---- lib/service/servicedvb.cpp | 7 ++++ lib/service/servicedvb.h | 1 + 8 files changed, 90 insertions(+), 12 deletions(-) diff --git a/lib/dvb/db.cpp b/lib/dvb/db.cpp index 153f5804..93b13cc6 100644 --- a/lib/dvb/db.cpp +++ b/lib/dvb/db.cpp @@ -10,7 +10,6 @@ DEFINE_REF(eDVBService); -// the following three methodes are declared in idvb.h RESULT eBouquet::addService(const eServiceReference &ref) { list::iterator it = @@ -389,6 +388,49 @@ void eDVBDB::save() fclose(f); } +RESULT eBouquet::flushChanges() +{ + FILE *f=fopen(m_path.c_str(), "wt"); + if (!f) + return -1; + if ( fprintf(f, "#NAME %s\r\n", m_bouquet_name.c_str()) < 0 ) + goto err; + for (list::iterator i(m_services.begin()); i != m_services.end(); ++i) + { + eServiceReference tmp = *i; + std::string str = tmp.path; + if ( (i->flags&eServiceReference::flagDirectory) == eServiceReference::flagDirectory ) + { + unsigned int p1 = str.find("FROM BOUQUET \""); + if (p1 == std::string::npos) + { + eDebug("doof... kaputt"); + continue; + } + str.erase(0, p1+14); + p1 = str.find("\""); + if (p1 == std::string::npos) + { + eDebug("doof2... kaputt"); + continue; + } + str.erase(p1); + tmp.path=str; + } + if ( fprintf(f, "#SERVICE %s\r\n", tmp.toString().c_str()) < 0 ) + goto err; + if ( i->name.length() ) + if ( fprintf(f, "#DESCRIPTION %s\r\n", i->name.c_str()) < 0 ) + goto err; + } + fclose(f); + return 0; +err: + fclose(f); + eDebug("couldn't write file %s", m_path.c_str()); + return -1; +} + void eDVBDB::loadBouquet(const char *path) { std::string bouquet_name = path; diff --git a/lib/dvb/idvb.h b/lib/dvb/idvb.h index 6b657119..a23960af 100644 --- a/lib/dvb/idvb.h +++ b/lib/dvb/idvb.h @@ -21,7 +21,8 @@ struct eBouquet std::string m_path; typedef std::list list; list m_services; -// the following three methods are implemented in db.cpp +// the following four methods are implemented in db.cpp + RESULT flushChanges(); RESULT addService(const eServiceReference &); RESULT removeService(const eServiceReference &); RESULT moveService(const eServiceReference &, unsigned int); diff --git a/lib/python/Components/ServiceList.py b/lib/python/Components/ServiceList.py index efe928dd..76e1c822 100644 --- a/lib/python/Components/ServiceList.py +++ b/lib/python/Components/ServiceList.py @@ -52,6 +52,12 @@ class ServiceList(HTMLComponent, GUIComponent): self.l.setRoot(root) self.l.sort() + def cursorGet(self): + return self.l.cursorGet() + + def cursorSet(self, val): + self.l.cursorSet(val) + # stuff for multiple marks (edit mode / later multiepg) def clearMarks(self): self.l.initMarked() diff --git a/lib/python/Screens/ChannelSelection.py b/lib/python/Screens/ChannelSelection.py index 14bc4dce..496131bd 100644 --- a/lib/python/Screens/ChannelSelection.py +++ b/lib/python/Screens/ChannelSelection.py @@ -29,16 +29,23 @@ class ChannelContextMenu(FixedMenu): else: menu.append(("edit bouquet...", self.bouquetMarkStart)) + if not csel.bouquet_mark_edit and not csel.movemode: + menu.append(("remove service", self.removeCurrentService)) + FixedMenu.__init__(self, session, "Channel Selection", menu) self.skinName = "Menu" + def removeCurrentService(self): + self.close() + self.csel.removeCurrentService() + def toggleMoveMode(self): self.csel.toggleMoveMode() self.close() def bouquetMarkStart(self): - self.csel.startMarkedEdit() self.close() + self.csel.startMarkedEdit() def bouquetMarkEnd(self): self.csel.endMarkedEdit(abort=False) @@ -80,6 +87,8 @@ class ChannelSelection(Screen): if l.movemode: #movemode active? l.channelSelected() # unmark l.toggleMoveMode() # disable move mode + elif l.bouquet_mark_edit: + l.endMarkedEdit(True) # abort edit mode ActionMap.action(self, contexts, action) self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"], @@ -112,6 +121,16 @@ class ChannelSelection(Screen): for x in self.__marked: l.addMarked(eServiceReference(x)) + def removeCurrentService(self): + l = self["list"] + ref=l.getCurrent() + if ref.valid() and self.mutableList is not None: + self.mutableList.removeService(ref) + pos = l.cursorGet() + self.mutableList.flushChanges() #FIXME dont flush on each single removed service + self.setRoot(l.getRoot()) +# l.cursorSet(pos) #whats going wrong here???? + def endMarkedEdit(self, abort): l = self["list"] if not abort and self.mutableList is not None: @@ -127,7 +146,8 @@ class ChannelSelection(Screen): changed = True self.mutableList.addService(eServiceReference(x)) if changed: - l.setRoot(self.bouquetRoot) + self.mutableList.flushChanges() + self.setRoot(self.bouquetRoot) self.__marked = [] self.clearMarks() self.bouquet_mark_edit = False @@ -189,5 +209,6 @@ class ChannelSelection(Screen): def toggleMoveMode(self): if self.movemode: self.movemode = False + self.mutableList.flushChanges() # FIXME add check if changes was made else: self.movemode = True diff --git a/lib/service/iservice.h b/lib/service/iservice.h index 5f861899..e21fd99f 100644 --- a/lib/service/iservice.h +++ b/lib/service/iservice.h @@ -252,6 +252,8 @@ TEMPLATE_TYPEDEF(ePtr, iRecordableServicePtr); class iMutableServiceList: public iObject { public: + /* flush changes */ + virtual RESULT flushChanges()=0; /* adds a service to a list */ virtual RESULT addService(eServiceReference &ref)=0; /* removes a service from a list */ diff --git a/lib/service/listboxservice.h b/lib/service/listboxservice.h index b2fc311b..e65ffc8d 100644 --- a/lib/service/listboxservice.h +++ b/lib/service/listboxservice.h @@ -13,13 +13,13 @@ public: eListboxServiceContent(); void setRoot(const eServiceReference &ref); void getCurrent(eServiceReference &ref); - + /* support for marked services */ void initMarked(); void addMarked(const eServiceReference &ref); void removeMarked(const eServiceReference &ref); int isMarked(const eServiceReference &ref); - + /* this is NOT thread safe! */ void markedQueryStart(); int markedQueryNext(eServiceReference &ref); @@ -46,17 +46,16 @@ public: void setElementFont(int element, gFont *font); void sort(); - + int setCurrentMarked(bool); - + int cursorSet(int n); + int cursorGet(); protected: void cursorHome(); void cursorEnd(); int cursorMove(int count=1); int cursorValid(); - int cursorSet(int n); - int cursorGet(); - + void cursorSave(); void cursorRestore(); int size(); @@ -87,7 +86,6 @@ private: /* support for marked services */ std::set m_marked; - std::set::const_iterator m_marked_iterator; /* support for movemode */ diff --git a/lib/service/servicedvb.cpp b/lib/service/servicedvb.cpp index b1c18a1d..77fe3faf 100644 --- a/lib/service/servicedvb.cpp +++ b/lib/service/servicedvb.cpp @@ -312,6 +312,13 @@ RESULT eDVBServiceList::moveService(eServiceReference &ref, int pos) return m_bouquet->moveService(ref, pos); } +RESULT eDVBServiceList::flushChanges() +{ + if (!m_bouquet) + return -1; + return m_bouquet->flushChanges(); +} + RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr &ptr) { ePtr service; diff --git a/lib/service/servicedvb.h b/lib/service/servicedvb.h index 165703dd..ac856ed7 100644 --- a/lib/service/servicedvb.h +++ b/lib/service/servicedvb.h @@ -37,6 +37,7 @@ public: int compareLessEqual(const eServiceReference &a, const eServiceReference &b); RESULT startEdit(ePtr &); + RESULT flushChanges(); RESULT addService(eServiceReference &ref); RESULT removeService(eServiceReference &ref); RESULT moveService(eServiceReference &ref, int pos); -- 2.30.2