working on move, edit mode and add remove service to context menu
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Mon, 14 Nov 2005 02:40:16 +0000 (02:40 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Mon, 14 Nov 2005 02:40:16 +0000 (02:40 +0000)
lib/dvb/db.cpp
lib/dvb/idvb.h
lib/python/Components/ServiceList.py
lib/python/Screens/ChannelSelection.py
lib/service/iservice.h
lib/service/listboxservice.h
lib/service/servicedvb.cpp
lib/service/servicedvb.h

index 153f580..93b13cc 100644 (file)
@@ -10,7 +10,6 @@
 
 DEFINE_REF(eDVBService);
 
 
 DEFINE_REF(eDVBService);
 
-// the following three methodes are declared in idvb.h
 RESULT eBouquet::addService(const eServiceReference &ref)
 {
        list::iterator it =
 RESULT eBouquet::addService(const eServiceReference &ref)
 {
        list::iterator it =
@@ -389,6 +388,49 @@ void eDVBDB::save()
        fclose(f);
 }
 
        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;
 void eDVBDB::loadBouquet(const char *path)
 {
        std::string bouquet_name = path;
index 6b65711..a23960a 100644 (file)
@@ -21,7 +21,8 @@ struct eBouquet
        std::string m_path;
        typedef std::list<eServiceReference> list;
        list m_services;
        std::string m_path;
        typedef std::list<eServiceReference> 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);
        RESULT addService(const eServiceReference &);
        RESULT removeService(const eServiceReference &);
        RESULT moveService(const eServiceReference &, unsigned int);
index efe928d..76e1c82 100644 (file)
@@ -52,6 +52,12 @@ class ServiceList(HTMLComponent, GUIComponent):
                self.l.setRoot(root)
                self.l.sort()
 
                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()
 # stuff for multiple marks (edit mode / later multiepg)
        def clearMarks(self):
                self.l.initMarked()
index 14bc4dc..496131b 100644 (file)
@@ -29,16 +29,23 @@ class ChannelContextMenu(FixedMenu):
                                else:
                                        menu.append(("edit bouquet...", self.bouquetMarkStart))
 
                                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"
 
                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):
        def toggleMoveMode(self):
                self.csel.toggleMoveMode()
                self.close()
 
        def bouquetMarkStart(self):
-               self.csel.startMarkedEdit()
                self.close()
                self.close()
+               self.csel.startMarkedEdit()
 
        def bouquetMarkEnd(self):
                self.csel.endMarkedEdit(abort=False)
 
        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
                                                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"], 
                                        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))
 
                        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:
        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:
                                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
                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
        def toggleMoveMode(self):
                if self.movemode:
                        self.movemode = False
+                       self.mutableList.flushChanges() # FIXME add check if changes was made
                else:
                        self.movemode = True
                else:
                        self.movemode = True
index 5f86189..e21fd99 100644 (file)
@@ -252,6 +252,8 @@ TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr);
 class iMutableServiceList: public iObject
 {
 public:
 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 */
                /* adds a service to a list */
        virtual RESULT addService(eServiceReference &ref)=0;
                /* removes a service from a list */
index b2fc311..e65ffc8 100644 (file)
@@ -13,13 +13,13 @@ public:
        eListboxServiceContent();
        void setRoot(const eServiceReference &ref);
        void getCurrent(eServiceReference &ref);
        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);
                /* 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);
                /* this is NOT thread safe! */
        void markedQueryStart();
        int markedQueryNext(eServiceReference &ref);
@@ -46,17 +46,16 @@ public:
        void setElementFont(int element, gFont *font);
        
        void sort();
        void setElementFont(int element, gFont *font);
        
        void sort();
-       
+
        int setCurrentMarked(bool);
        int setCurrentMarked(bool);
-       
+       int cursorSet(int n);
+       int cursorGet();
 protected:
        void cursorHome();
        void cursorEnd();
        int cursorMove(int count=1);
        int cursorValid();
 protected:
        void cursorHome();
        void cursorEnd();
        int cursorMove(int count=1);
        int cursorValid();
-       int cursorSet(int n);
-       int cursorGet();
-       
+
        void cursorSave();
        void cursorRestore();
        int size();
        void cursorSave();
        void cursorRestore();
        int size();
@@ -87,7 +86,6 @@ private:
 
                /* support for marked services */
        std::set<eServiceReference> m_marked;
 
                /* support for marked services */
        std::set<eServiceReference> m_marked;
-       
        std::set<eServiceReference>::const_iterator m_marked_iterator;
 
                /* support for movemode */
        std::set<eServiceReference>::const_iterator m_marked_iterator;
 
                /* support for movemode */
index b1c18a1..77fe3fa 100644 (file)
@@ -312,6 +312,13 @@ RESULT eDVBServiceList::moveService(eServiceReference &ref, int pos)
        return m_bouquet->moveService(ref, 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<iPlayableService> &ptr)
 {
        ePtr<eDVBService> service;
 RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
 {
        ePtr<eDVBService> service;
index 165703d..ac856ed 100644 (file)
@@ -37,6 +37,7 @@ public:
        int compareLessEqual(const eServiceReference &a, const eServiceReference &b);
        
        RESULT startEdit(ePtr<iMutableServiceList> &);
        int compareLessEqual(const eServiceReference &a, const eServiceReference &b);
        
        RESULT startEdit(ePtr<iMutableServiceList> &);
+       RESULT flushChanges();
        RESULT addService(eServiceReference &ref);
        RESULT removeService(eServiceReference &ref);
        RESULT moveService(eServiceReference &ref, int pos);
        RESULT addService(eServiceReference &ref);
        RESULT removeService(eServiceReference &ref);
        RESULT moveService(eServiceReference &ref, int pos);