Author: dmeyer
Date: Thu Mar 29 12:00:34 2007
New Revision: 9414

Modified:
   trunk/core/src/ipc/tvserver.py
   trunk/tvserver/src/server.py

Log:
Update favorite ipc handling; based on patch by Jose

Modified: trunk/core/src/ipc/tvserver.py
==============================================================================
--- trunk/core/src/ipc/tvserver.py      (original)
+++ trunk/core/src/ipc/tvserver.py      Thu Mar 29 12:00:34 2007
@@ -7,12 +7,12 @@
 #
 # -----------------------------------------------------------------------------
 # Freevo - A Home Theater PC framework
-# Copyright (C) 2002-2005 Krister Lagerstrom, Dirk Meyer, et al.
+# Copyright (C) 2005-2007 Dirk Meyer, et al.
 #
 # First Edition: Dirk Meyer <[EMAIL PROTECTED]>
 # Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
 #
-# Please see the file doc/CREDITS for a complete list of authors.
+# Please see the file AUTHORS for a complete list of authors.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -45,6 +45,9 @@
 import kaa.notifier
 from kaa.strutils import unicode_to_str
 
+# get basic ipc handling
+import ipc
+
 # get logging object
 log = logging.getLogger('record')
 
@@ -125,7 +128,6 @@
 
         instance.signals['new-entity'].connect(self.new_entity)
         instance.signals['lost-entity'].connect(self.lost_entity)
-        
instance.events['home-theatre.record.list.update'].connect(self.list_update_cb)
 
         self.comingup = ''
         self.running = ''
@@ -165,7 +167,8 @@
         return True
 
 
-    def list_update_cb(self, result):
+    @ipc.eventhandler('home-theatre.record.list.update')
+    def _event_update(self, result):
         self.updating = 1
         log.info('got recording list update')
         for l in result:
@@ -288,7 +291,7 @@
     """
     A favorite object from the recordserver.
     """
-    def __init__(self, id, title, channels, priority, day, time, one_shot,
+    def __init__(self, id, title, channels, priority, days, time, one_shot,
                  substring):
         """
         The init function creates the object. The parameters are the complete
@@ -298,7 +301,7 @@
         self.title = title
         self.channels = channels
         self.priority = priority
-        self.day = day
+        self.days = days
         self.time = time
         self.one_shot = one_shot
         self.substring = substring
@@ -311,11 +314,15 @@
     Handling of favorites from the recordserver. The object will auto sync with
     the recordserver to keep the list up to date.
     """
+    
+    SUCCESS = 'SUCCESS'
+
     def __init__(self, instance):
         self.last_update = time.time()
         self._favorites = []
         self.server = None
-
+        instance.connect(self)
+        
         instance.signals['new-entity'].connect(self.new_entity)
         instance.signals['lost-entity'].connect(self.lost_entity)
 
@@ -325,6 +332,7 @@
         if not entity.matches(SERVER):
             return
         self.server = entity
+        self.server.register('home-theatre.favorite.list.update')
         self.rpc = self.server.rpc
         wait = self.rpc('home-theatre.favorite.list')
         yield wait
@@ -347,29 +355,63 @@
         return True
 
 
-    def add(self, prog):
+    @ipc.eventhandler('home-theatre.favorite.list.update')
+    def _event_update(self, result):
+        log.info('favorites updated')
+        self.last_update = time.time()
+        self._favorites = []
+        for f in result:
+            self._favorites.append(Favorite(*f))
+        
+
+    @kaa.notifier.yield_execution()
+    def add(self, title, channels, days, times, priority, once):
+        """
+        add a favorite
+        parameter: name channels priority days times
+        channels is a list of channels
+        days is a list of days ( 0 = Sunday - 6 = Saturday )
+        times is a list of hh:mm-hh:mm
+        """
         if not self.server:
-            return False, 'Recordserver unavailable'
+            yield _('tvserver unavailable')
 
-        if prog.channel == 'ANY':
-            # FIXME: crash!!!!!!
-            channel = []
-            for c in kaa.epg.channels:
-                channel.append(c.id)
-        else:
-            channel = [ prog.channel.id ]
-        days = (_('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'),
-                _('Sat'), _('Sun'))
-        if prog.days in days:
-            days = [ days.index(prog.dow) ]
-        else:
+        if channels == 'ANY':
+            channels = kaa.epg.get_channels()
+            if isinstance(channels, kaa.notifier.InProgress):
+                yield channels
+                channels = channels()
+            channels = [ c.id for c in channels ]
+
+        if days == 'ANY':
             days = [ 0, 1, 2, 3, 4, 5, 6 ]
 
-        self.rpc('home-theatre.favorite.add', prog.title, channel, 50, days,
-                 [ '00:00-23:59' ], False)
+        if times == 'ANY':
+            times = [ '00:00-23:59' ]
+            
+        result = self.rpc('home-theatre.favorite.add', title, channels,
+                          priority, days, times, once)
+        yield result
+        if not result():
+            # FIXME: get real error message from tvserver
+            yield 'failed'
+        yield self.SUCCESS
 
-        # FIXME: make it possible to return a failure
-        return True, 'Scheduled'
+
+    @kaa.notifier.yield_execution()
+    def remove(self, id):
+        """
+        remove a favorite
+        parameter: id of the favorite
+        """
+        if not self.server:
+            yield _('tvserver unavailable')
+        result = self.rpc('home-theatre.favorite.remove', id)
+        yield result
+        if not result():
+            # FIXME: get real error message from tvserver
+            yield 'failed'
+        yield self.SUCCESS
 
 
     def list(self):

Modified: trunk/tvserver/src/server.py
==============================================================================
--- trunk/tvserver/src/server.py        (original)
+++ trunk/tvserver/src/server.py        Thu Mar 29 12:00:34 2007
@@ -563,18 +563,42 @@
         if f in self.favorites:
             return NameError('Already scheduled')
         self.favorites.append(f)
-        self.rpc_favorite_update()
+
+        # update schedule
+        self.epg_update()
+        
+        # send update to all clients
+        msg = [ f.long_list() for f in self.favorites ]
+        self.send_event('home-theatre.favorite.list.update', *msg)
         return []
 
 
-    @freevo.ipc.expose('home-theatre.favorite.list', add_source=True)
-    def rpc_favorite_list(self, source):
+    @freevo.ipc.expose('home-theatre.favorite.remove')
+    def rpc_favorite_remove(self, id):
         """
+        remove a favorite
+        parameter: id of the favorite
         """
-        ret = []
         for f in self.favorites:
-            ret.append(f.long_list())
-        return ret
+            if id == f.id:
+                break
+        else:
+            return NameError('Favorite not found!')
+        log.info('favorite.remove: %s', f)
+        self.favorites.remove(f)
+
+        # send update to all clients
+        msg = [ f.long_list() for f in self.favorites ]
+        self.send_event('home-theatre.favorite.list.update', *msg)
+        return []
+
+
+    @freevo.ipc.expose('home-theatre.favorite.list')
+    def rpc_favorite_list(self):
+        """
+        Return list of all favorites
+        """
+        return [ f.long_list() for f in self.favorites ]
 
 
     #

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to