Hello,

I thought again abount the tv.ProgramItem class and came up with this solution.
It is not finished yet, but I think you can see the point.
I would say, we do not need an extra class for scheduled recordings as they are 
just programs.
I mean, you can (un)schedule them or make them a favorite or watch them, thus their actions are the same as for normal programs. But favorites are a different business, as we need different infos there as "day of week", "time of day" and so on. So creating a new class seems to be the right way here. But what I do not like in the way it is now implemented is that you have a submenu "Favorite..." for each ProgramItem and in this "Add favorite" or "Remove favorite". I would like to have those options top level.
Thus one would need to have the following extra actions in ProgramItem:
"add to favorites"
"edit favorite"
"remove from favorites"
The first two should open the menu with the actions for a favorite which are to change all the points like "when" and "where" and so on.

Jose, are you still working on this stuff?
Maybe I should look into something else, as I do not want to interfere with you.

Dischi, did you see my other post with the patch for "Search for more of this 
program"?

Regards
Tanja


Jose schrieb:
Hi,

Some time ago I started with expanding the favorite functionality in
freevo2. And when doing this I walked into more or less the same issues
Tanja described. I have looked into the option of making some kind of a
generic class, which would contain the existing program item plus record
and favorite functionality. But every time I tried a new approach I
found out that something could not work any more. I think these classes
are just to different from each other. But, maybe I should try
harder.. :)

Finally I just started expanding the existing tv.favorite.py class. For
now this class is created from a kaa.epg.program (in case of the
TVGuide) or from the ipc.tvserver.favorite (in case of the a query of
all the favorites). Upon creation I check with which class it was
created and use the correct members. The tv.program class uses this
tv.favorite class.
Maybe there should also be a tv.recording.py class which handles all the
recording stuff. And the tv.program class should use that also, i.s.o.
implementing it self.
But if you or some one else has a nice idea, I would love to see it.

Later on I will sent the changes I made for expanding the favorite
functionality.

regards,
Jose


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Index: ui/src/tv/plugins/scheduled.py
===================================================================
--- ui/src/tv/plugins/scheduled.py	(Revision 9583)
+++ ui/src/tv/plugins/scheduled.py	(Arbeitskopie)
@@ -29,178 +29,67 @@
 # -----------------------------------------------------------------------------
 
 # python imports
-import time
 
 # kaa imports
-import kaa.notifier
-from kaa.strutils import unicode_to_str
 
 # freevo core imports
 import freevo.ipc
 
-# freevo ui imports
-from freevo.ui import config
-from freevo.ui.menu import Menu, ActionItem, Action, Item
-from freevo.ui.mainmenu import MainMenuPlugin
+# freevo imports
+from freevo.ui.mainmenu import Menu, MainMenuPlugin
+from freevo.ui.menu import ActionItem
 from freevo.ui.application import MessageWindow
+from freevo.ui.tv.program import ProgramItem
 
 # get tvserver interface
 tvserver = freevo.ipc.Instance('freevo').tvserver
 
-class RecordingItem(Item):
-    """
-    A recording item to remove/watch a scheduled recording.
-    """
-    def __init__(self, channel, start, stop, parent):
-        Item.__init__(self, parent)
-
-        self.scheduled = tvserver.recordings.get(channel, start, stop)
-        if self.scheduled.description.has_key('title'):
-            self.title = self.scheduled.description['title']
-            self.name  = self.scheduled.description['title']
-        else:
-            self.name  = self.title = ''
-        self.channel = channel
-        self.start = start
-        self.stop = stop
-
-
-    def __unicode__(self):
-        """
-        return as unicode for debug
-        """
-        bt = time.localtime(self.start)   # Beginning time tuple
-        et = time.localtime(self.stop)    # End time tuple
-        begins = '%s-%02d-%02d %02d:%02d' % (bt[0], bt[1], bt[2], bt[3], bt[4])
-        ends   = '%s-%02d-%02d %02d:%02d' % (et[0], et[1], et[2], et[3], et[4])
-        return u'%s to %s  %3s ' % (begins, ends, self.channel) + \
-               self.title
-
-
-    def __str__(self):
-        """
-        return as string for debug
-        """
-        return unicode_to_str(self.__unicode__())
-
-
-    def __cmp__(self, other):
-        """
-        compare function, return 0 if the objects are identical, 1 otherwise
-        """
-        if not isinstance(other, (RecordingItem)):
-            return 1
-
-        return self.start != other.start or \
-               self.stop  != other.stop or \
-               self.channel != other.channel
-
-
-    def __getitem__(self, key):
-        """
-        return the specific attribute as string or an empty string
-        """
-        if key == 'start':
-            return unicode(time.strftime(config.tv.timeformat,
-                                         time.localtime(self.start)))
-        if key == 'stop':
-            return unicode(time.strftime(config.tv.timeformat,
-                                         time.localtime(self.stop)))
-        if key == 'date':
-            return unicode(time.strftime(config.tv.dateformat,
-                                         time.localtime(self.start)))
-        if key == 'time':
-            return self['start'] + u' - ' + self['stop']
-        if key == 'channel':
-            return self.channel
-
-        return Item.__getitem__(self, key)
-
-
-    def actions(self):
-        """
-        return a list of possible actions on this item.
-        """
-        return [ Action(_('Show recording menu'), self.submenu) ]
-
-
-    def submenu(self):
-        """
-        show a submenu for this item
-        """
-        items = []
-        if self.start < time.time() + 10 and \
-               self.scheduled.status in ('recording', 'saved'):
-            items.append(ActionItem(_('Watch recording'), self,
-                                    self.watch_recording))
-        if self.stop > time.time():
-            if self.start < time.time():
-                items.append(ActionItem(_('Stop recording'), self,
-                                        self.remove))
-            else:
-                items.append(ActionItem(_('Remove recording'), self,
-                                        self.remove))
-
-        s = Menu(self, items, type = 'tv program menu')
-        s.submenu = True
-        s.infoitem = self
-        self.get_menustack().pushmenu(s)
-
-
-    def watch_recording(self):
-        MessageWindow('Not implemented yet').show()
-
-
-    @kaa.notifier.yield_execution()
-    def remove(self):
-        result = tvserver.recordings.remove(self.scheduled.id)
-        if isinstance(result, kaa.notifier.InProgress):
-            yield result
-            result = result()
-        if result != tvserver.recordings.SUCCESS:
-            MessageWindow(_('Scheduling Failed')+(': %s' % result)).show()
-        self.get_menustack().delete_submenu()
-
-
 class PluginInterface(MainMenuPlugin):
     """
     This plugin is used to display your scheduled recordings.
     """
-    def scheduled(self, parent):
+    def browse(self, parent):
+        """ 
+        Construct the menu
         """
-        Show all scheduled recordings.
-        """
         self.parent = parent
         items = self.get_items(parent)
         if items:
             self.menu = Menu(_('View scheduled recordings'), items,
-                             type='tv program menu',
-                             reload_func = self.reload_scheduled)
+                                 type='tv program menu',
+                                 reload_func = self.reload_scheduled)
             parent.get_menustack().pushmenu(self.menu)
         else:
             MessageWindow(_('There are no scheduled recordings.')).show()
-
-
+    
+    
     def reload_scheduled(self):
+        """
+        reload the list of scheduled recordings
+        """
         items = self.get_items(self.parent)
         if items:
             self.menu.set_items(items)
         else:
             self.parent.get_menustack().back_one_menu()
 
+    
     def get_items(self, parent):
+        """
+        create the list of scheduled recordings
+        """
         items = []
         rec = tvserver.recordings.list()
-        for p in rec:
-            scheduled = tvserver.recordings.get(p.channel, p.start, p.stop)
+        for scheduled in rec:
             if scheduled and not scheduled.status in ('deleted', 'missed'):
-                items.append(RecordingItem(parent=parent, channel=p.channel,
-                                           start=p.start, stop=p.stop))
-
+                items.append(ProgramItem(scheduled, parent=parent))
         return items
-
+        
+                   
     def items(self, parent):
         """
         Return the main menu item.
         """
-        return [ ActionItem(_('View scheduled recordings'), parent, self.scheduled) ]
+        return [ ActionItem(_('View scheduled recordings'), parent, self.browse) ]
+       
+    
Index: ui/src/tv/program.py
===================================================================
--- ui/src/tv/program.py	(Revision 9583)
+++ ui/src/tv/program.py	(Arbeitskopie)
@@ -53,32 +53,64 @@
 # get tvserver interface
 tvserver = freevo.ipc.Instance('freevo').tvserver
 
+
 class ProgramItem(Item):
     """
     A tv program item for the tv guide and other parts of the tv submenu.
     """
     def __init__(self, program, parent):
         Item.__init__(self, parent)
-        self.program = program
-        self.title = program.title
-        self.name  = program.title
         self.start = program.start
         self.stop  = program.stop
-
-        self.channel = program.channel
-        self.subtitle = program.subtitle
-        self.description = program.description
-        self.episode = program.episode
         
-        self.scheduled = tvserver.recordings.get(program.channel.name,
-                                        program.start, program.stop)
-
-        # TODO: add category support
-        self.categories = ''
-        # TODO: add ratings support
-        self.ratings = ''
-
-
+        if isinstance(program, kaa.epg.Program):
+            self.program = program
+            self.channel = program.channel
+            self.title = program.title
+            self.name  = program.title
+            
+            
+            self.subtitle = program.subtitle
+            self.episode = program.episode
+            self.description = program.description
+            # TODO: add category/genre support
+            self.categories = ''
+            self.genre = ''
+            # TODO: add ratings support
+            self.ratings = ''
+            self.scheduled = tvserver.recordings.get(program.channel.name,
+                                                     program.start, 
+                                                     program.stop)
+        
+        elif isinstance(program, freevo.ipc.tvserver.Recording):
+            # TODO: Is this allowed?
+            self.channel = kaa.epg.get_channel(program.channel)
+            
+            if program.description.has_key('title'):
+                self.title = program.description['title']
+                self.name  = program.description['title']
+            else: 
+                self.name = self.title = _(u'Unknown') 
+             
+            if program.description.has_key('subtitle'):
+                self.subtitle = program.description['subtitle']
+            else:               
+                self.subtitle = ''
+            if program.description.has_key('episode'):
+                self.episode = program.description['episode']
+            else:               
+                self.episode = ''
+            # TODO: check if this is also available    
+            self.description = ''
+                       
+            # TODO: add catergory/genre support
+            self.categories = ''
+            self.genre = ''
+            # TODO: add ratings support
+            self.rating = ''
+            self.scheduled = program            
+                                
+                        
     def __unicode__(self):
         """
         return as unicode for debug
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Reply via email to