fix service/movie remove (hold cursor position when possible)
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Mon, 19 Dec 2005 12:05:48 +0000 (12:05 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Mon, 19 Dec 2005 12:05:48 +0000 (12:05 +0000)
change titlebar of channelselection when edit mode or move mode is enabled

lib/python/Components/MovieList.py
lib/python/Components/ServiceList.py
lib/python/Screens/ChannelSelection.py
lib/python/Screens/MovieSelection.py

index 2e010ab..7121772 100644 (file)
@@ -62,7 +62,13 @@ class MovieList(HTMLComponent, GUIComponent):
                self.l.setList(self.list)
                self.l.setFont(0, gFont("Arial", 30))
                self.l.setFont(1, gFont("Arial", 18))
                self.l.setList(self.list)
                self.l.setFont(0, gFont("Arial", 30))
                self.l.setFont(1, gFont("Arial", 18))
-       
+
+       def moveToIndex(self, index):
+               self.instance.moveSelectionTo(index)
+
+       def getCurrentIndex(self):
+               return self.instance.getCurrentIndex()
+
        def getCurrent(self):
                return self.l.getCurrentSelection()
        
        def getCurrent(self):
                return self.l.getCurrentSelection()
        
@@ -103,3 +109,6 @@ class MovieList(HTMLComponent, GUIComponent):
        def reload(self):
                self.load(self.root)
                self.l.setList(self.list)
        def reload(self):
                self.load(self.root)
                self.l.setList(self.list)
+
+       def moveDown(self):
+               self.instance.moveSelection(self.instance.moveDown)
index d008c47..d24f956 100644 (file)
@@ -43,6 +43,12 @@ class ServiceList(HTMLComponent, GUIComponent):
                self.instance.moveSelectionTo(index)
                print "Moving to character " + str(char)
 
                self.instance.moveSelectionTo(index)
                print "Moving to character " + str(char)
 
+       def moveToIndex(self, index):
+               self.instance.moveSelectionTo(index)
+
+       def getCurrentIndex(self):
+               return self.instance.getCurrentIndex()
+
        def GUIcreate(self, parent):
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
        def GUIcreate(self, parent):
                self.instance = eListbox(parent)
                self.instance.setContent(self.l)
index b98df0f..c7d8d16 100644 (file)
@@ -31,10 +31,14 @@ class ChannelContextMenu(FixedMenu):
 
                inBouquetRootList = csel.servicelist.getRoot().getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
                inBouquet = csel.getMutableList() is not None
 
                inBouquetRootList = csel.servicelist.getRoot().getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
                inBouquet = csel.getMutableList() is not None
+               haveBouquets = csel.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1
 
                if not csel.bouquet_mark_edit and not csel.movemode and not inBouquetRootList:
                        if (csel.getCurrentSelection().type & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
 
                if not csel.bouquet_mark_edit and not csel.movemode and not inBouquetRootList:
                        if (csel.getCurrentSelection().type & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
-                               menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
+                               if haveBouquets:
+                                       menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
+                               else:
+                                       menu.append((_("add service to favourites"), self.addServiceToBouquetSelected))
                        if inBouquet:
                                menu.append((_("remove service"), self.removeCurrentService))
 
                        if inBouquet:
                                menu.append((_("remove service"), self.removeCurrentService))
 
@@ -43,12 +47,19 @@ class ChannelContextMenu(FixedMenu):
                                if not csel.movemode:
                                        menu.append((_("enable move mode"), self.toggleMoveMode))
                                        if not inBouquetRootList:
                                if not csel.movemode:
                                        menu.append((_("enable move mode"), self.toggleMoveMode))
                                        if not inBouquetRootList:
-                                               menu.append((_("enable bouquet edit"), self.bouquetMarkStart))
+                                               if haveBouquets:
+                                                       menu.append((_("enable bouquet edit"), self.bouquetMarkStart))
+                                               else:
+                                                       menu.append((_("enable favourite edit"), self.bouquetMarkStart))
                                else:
                                        menu.append((_("disable move mode"), self.toggleMoveMode))
                        elif not inBouquetRootList:
                                else:
                                        menu.append((_("disable move mode"), self.toggleMoveMode))
                        elif not inBouquetRootList:
-                               menu.append((_("end bouquet edit"), self.bouquetMarkEnd))
-                               menu.append((_("abort bouquet edit"), self.bouquetMarkAbort))
+                               if haveBouquets:
+                                       menu.append((_("end bouquet edit"), self.bouquetMarkEnd))
+                                       menu.append((_("abort bouquet edit"), self.bouquetMarkAbort))
+                               else:
+                                       menu.append((_("end favourites edit"), self.bouquetMarkEnd))
+                                       menu.append((_("abort favourites edit"), self.bouquetMarkAbort))
 
                menu.append((_("back"), self.close))
 
 
                menu.append((_("back"), self.close))
 
@@ -107,6 +118,8 @@ class ChannelSelectionEdit:
                self.bouquet_mark_edit = False
                self.mutableList = None
                self.__marked = [ ]
                self.bouquet_mark_edit = False
                self.mutableList = None
                self.__marked = [ ]
+               self.saved_title = None
+               self.saved_root = None
 
        def getMutableList(self, root=eServiceReference()):
                if not self.mutableList is None:
 
        def getMutableList(self, root=eServiceReference()):
                if not self.mutableList is None:
@@ -125,10 +138,19 @@ class ChannelSelectionEdit:
                # add all services from the current list to internal marked set in listboxservicecontent
                self.bouquetRoot = self.servicelist.getRoot()
                self.clearMarks() # this clears the internal marked set in the listboxservicecontent
                # add all services from the current list to internal marked set in listboxservicecontent
                self.bouquetRoot = self.servicelist.getRoot()
                self.clearMarks() # this clears the internal marked set in the listboxservicecontent
+               self.saved_title = self.instance.getTitle()
+               new_title = self.saved_title
+               if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1:
+                       new_title += ' ' + _("[bouquet edit]")
+               else:
+                       new_title += ' ' + _("[favourite edit]")
+               self.instance.setTitle(new_title)
                self.bouquet_mark_edit = True
                self.__marked = self.servicelist.getRootServices()
                for x in self.__marked:
                        self.servicelist.addMarked(eServiceReference(x))
                self.bouquet_mark_edit = True
                self.__marked = self.servicelist.getRootServices()
                for x in self.__marked:
                        self.servicelist.addMarked(eServiceReference(x))
+               self.saved_root = self.getRoot()
+               self.showAllServices()
 
        def endMarkedEdit(self, abort):
                if not abort and self.mutableList is not None:
 
        def endMarkedEdit(self, abort):
                if not abort and self.mutableList is not None:
@@ -145,13 +167,14 @@ class ChannelSelectionEdit:
                                self.mutableList.addService(eServiceReference(x))
                        if changed:
                                self.mutableList.flushChanges()
                                self.mutableList.addService(eServiceReference(x))
                        if changed:
                                self.mutableList.flushChanges()
-                               self.setRoot(self.bouquetRoot)
-                               #self.showFavourites()
                self.__marked = []
                self.clearMarks()
                self.bouquet_mark_edit = False
                self.bouquetRoot = None
                self.mutableList = None
                self.__marked = []
                self.clearMarks()
                self.bouquet_mark_edit = False
                self.bouquetRoot = None
                self.mutableList = None
+               self.instance.setTitle(self.saved_title)
+               self.saved_title = None
+               self.setRoot(self.saved_root)
 
        def clearMarks(self):
                self.servicelist.clearMarks()
 
        def clearMarks(self):
                self.servicelist.clearMarks()
@@ -168,8 +191,13 @@ class ChannelSelectionEdit:
                mutableList = self.getMutableList()
                if ref.valid() and mutableList is not None:
                        if not mutableList.removeService(ref):
                mutableList = self.getMutableList()
                if ref.valid() and mutableList is not None:
                        if not mutableList.removeService(ref):
+                               currentIndex = self.servicelist.getCurrentIndex()
+                               self.servicelist.moveDown()
+                               if self.servicelist.getCurrentIndex() == currentIndex:
+                                       currentIndex -= 1
                                mutableList.flushChanges() #FIXME dont flush on each single removed service
                                self.setRoot(self.servicelist.getRoot())
                                mutableList.flushChanges() #FIXME dont flush on each single removed service
                                self.setRoot(self.servicelist.getRoot())
+                               self.servicelist.moveToIndex(currentIndex)
 
        def addCurrentServiceToBouquet(self, dest):
                mutableList = self.getMutableList(dest)
 
        def addCurrentServiceToBouquet(self, dest):
                mutableList = self.getMutableList(dest)
@@ -185,9 +213,15 @@ class ChannelSelectionEdit:
                        self.movemode = False
                        self.mutableList.flushChanges() # FIXME add check if changes was made
                        self.mutableList = None
                        self.movemode = False
                        self.mutableList.flushChanges() # FIXME add check if changes was made
                        self.mutableList = None
+                       self.instance.setTitle(self.saved_title)
+                       self.saved_title = None
                else:
                        self.mutableList = self.getMutableList()
                        self.movemode = True
                else:
                        self.mutableList = self.getMutableList()
                        self.movemode = True
+                       self.saved_title = self.instance.getTitle()
+                       new_title = self.saved_title
+                       new_title += ' ' + _("[move mode]");
+                       self.instance.setTitle(new_title);
 
        def handleEditCancel(self):
                if self.movemode: #movemode active?
 
        def handleEditCancel(self):
                if self.movemode: #movemode active?
index ce3a973..86d2547 100644 (file)
@@ -49,9 +49,14 @@ class ChannelContextMenu(FixedMenu):
                if result == False:
                        self.session.openWithCallback(self.close, MessageBox, "Delete failed!")
                else:
                if result == False:
                        self.session.openWithCallback(self.close, MessageBox, "Delete failed!")
                else:
-                       self.csel["list"].reload()
+                       list = self.csel["list"]
+                       currentIndex = list.getCurrentIndex()
+                       list.moveDown()
+                       if list.getCurrentIndex() == currentIndex:
+                               currentIndex -= 1
+                       list.reload()
+                       list.moveToIndex(currentIndex)
                        self.close()
                        self.close()
-               
  
 class MovieSelection(Screen):
        def __init__(self, session):
  
 class MovieSelection(Screen):
        def __init__(self, session):