Esempio n. 1
0
class FavoriteItem(Item):
    """
    Item class for favorite items
    """
    def __init__(self, parent, fav, fav_action='edit'):
        """ """
        Item.__init__(self, parent, skin_type='video')
        logger.log(9,
                   'FavoriteItem.__init__(parent=%r, fav=%r, fav_action=%r)',
                   parent, fav, fav_action)
        self.recordclient = RecordClient()
        self.fav = fav
        self.name = self.origname = fav.name
        self.title = fav.title
        self.fav_action = fav_action
        if hasattr(fav, 'allowDuplicates'):
            self.allowDuplicates = int(fav.allowDuplicates)

        if hasattr(self.fav, 'onlyNew'):
            self.onlyNew = int(fav.onlyNew)

        self.week_days = (_('Monday'), _('Tuesday'), _('Wednesday'),
                          _('Thursday'), _('Friday'), _('Saturday'),
                          _('Sunday'))

        if fav.channel == 'ANY':
            self.channel = _('ANY CHANNEL')
        else:
            self.channel = fav.channel
        if fav.dow == 'ANY':
            self.dow = _('ANY DAY')
        else:
            self.dow = self.week_days[int(fav.dow)]
        if fav.mod == 'ANY':
            self.mod = _('ANY TIME')
        else:
            try:
                self.mod = time.strftime(config.TV_TIME_FORMAT,
                                         time.gmtime(float(int(fav.mod) * 60)))
            except:
                print 'Cannot add "%s" to favorites' % fav.name

        # needed by the inputbox handler
        self.menuw = None

    def actions(self):
        logger.log(9, 'actions()')
        return [(self.display_submenu, _('Edit favorite')),
                (self.priority_up, _('Increase priority')),
                (self.priority_down, _('Decrease priority')),
                (self.rem_favorite, _('Remove favorite'))]

    def display_submenu(self, arg=None, menuw=None):
        """ Display menu for a favorite

        With this menu the user can made a program a favorite.
        All attributes of a favorite can be edited here and in the end
        the user must select 'save changes' to finally create the favorite.
        """
        logger.log(9, 'display_submenu(arg=%r, menuw=%r)', arg, menuw)
        ### create menu items for editing the favorites attributes
        items = []

        items.append(
            menu.MenuItem(_('Name') + u'\t' + _(self.name),
                          action=self.mod_name))
        items.append(
            menu.MenuItem(_('Channel') + u'\t' + _(self.channel),
                          action=self.mod_channel))
        items.append(
            menu.MenuItem(_('Day of the Week') + u'\t' + _(self.dow),
                          action=self.mod_day))
        items.append(
            menu.MenuItem(_('Time of Day') + u'\t' + _(self.mod),
                          action=self.mod_time))

        if config.TV_RECORD_DUPLICATE_DETECTION:
            if self.allowDuplicates:
                value = _('Allow duplicates')
            else:
                value = _('Prevent duplicates')
            items.append(
                menu.MenuItem(_('Duplicate Recordings') + u'\t' + _(value),
                              action=self.alter_prop,
                              arg=('dup', not self.allowDuplicates)))

        if config.TV_RECORD_ONLY_NEW_DETECTION:
            if self.onlyNew:
                value = _('Only new episodes')
            else:
                value = _('All episodes')
            items.append(
                menu.MenuItem(_('Episode Filter') + u'\t' + _(value),
                              action=self.alter_prop,
                              arg=('new', not self.onlyNew)))

        # XXX: priorities aren't quite supported yet
        if 0:
            (status, favorites) = self.recordclient.getFavoritesNow()
            if status and len(favorites) > 1:
                items.append(
                    menu.MenuItem(_('Modify priority'),
                                  action=self.mod_priority))

        ### save favorite
        items.append(
            menu.MenuItem(_('Save changes') + u'\t', action=self.save_changes))

        ### remove this program from favorites
        if not self.fav_action == 'add':
            items.append(
                menu.MenuItem(_('Remove favorite') + u'\t',
                              action=self.rem_favorite))

        ### put the whole menu together
        favorite_menu = menu.Menu(_('Favorite Menu'),
                                  items,
                                  item_types='tv favorite menu')
        favorite_menu.infoitem = self
        favorite_menu.is_submenu = True
        favorite_menu.table = (50, 50)
        menuw.pushmenu(favorite_menu)
        menuw.refresh()

    ### Actions:

    def mod_name(self, arg=None, menuw=None):
        """ Modify name

        This opens a input box to ask the user for a new name for this favorite.
        The default name of a favorite is the name of the program.
        """
        logger.log(9, 'mod_name(arg=%r, menuw=%r)', arg, menuw)
        self.menuw = menuw
        InputBox(text=_('Alter Name'), handler=self.alter_name, \
            width=osd.get_singleton().width - config.OSD_OVERSCAN_LEFT - 20, input_text=self.name).show()

    def alter_name(self, name):
        """ set the new name"""
        logger.log(9, 'alter_name(name=%r)', name)
        if name:
            self.name = self.fav.name = name.strip()
        menustack = self.menuw.menustack[-1]
        menustack.selected.dirty = True
        self.menuw.refresh()

    def mod_channel(self, arg=None, menuw=None):
        """Modify channel"""
        logger.log(9, 'mod_channel(arg=%r, menuw=%r)', arg, menuw)
        items = []

        items.append(
            menu.MenuItem('ANY CHANNEL',
                          action=self.alter_prop,
                          arg=('channel', 'ANY')))

        for chanline in config.TV_CHANNELS:
            items.append(
                menu.MenuItem(chanline[1],
                              action=self.alter_prop,
                              arg=('channel', chanline[1])))

        favorite_menu = menu.Menu(_('Modify Channel'),
                                  items,
                                  item_types='tv favorite menu')
        favorite_menu.infoitem = self
        menuw.pushmenu(favorite_menu)
        menuw.refresh()

    def mod_day(self, arg=None, menuw=None):
        """ Modify day

        Opens a submenu where the day of the week of a favorite can be configured.
        """
        logger.log(9, 'mod_day(arg=%r, menuw=%r)', arg, menuw)
        items = []

        items.append(
            menu.MenuItem(_('ANY DAY'),
                          action=self.alter_prop,
                          arg=('dow', 'ANY')))

        for i in range(len(self.week_days)):
            items.append(
                menu.MenuItem(self.week_days[i],
                              action=self.alter_prop,
                              arg=('dow', i)))

        favorite_menu = menu.Menu(_('Modify Day'),
                                  items,
                                  item_types='tv favorite menu')
        favorite_menu.infoitem = self
        menuw.pushmenu(favorite_menu)
        menuw.refresh()

    def mod_time(self, arg=None, menuw=None):
        """ Modify time

        Opens a submenu where the time of a favorite can be configured.
        """
        logger.log(9, 'mod_time(arg=%r, menuw=%r)', arg, menuw)
        items = []

        items.append(
            menu.MenuItem(_('ANY TIME'),
                          action=self.alter_prop,
                          arg=('mod', 'ANY')))

        for i in range(48):
            mod = i * 30
            items.append(menu.MenuItem(time.strftime(config.TV_TIME_FORMAT, time.gmtime(float(mod * 60))), \
                action=self.alter_prop, arg=('mod', mod)))

        favorite_menu = menu.Menu(_('Modify Time'),
                                  items,
                                  item_types='tv favorite menu')
        favorite_menu.infoitem = self
        menuw.pushmenu(favorite_menu)
        menuw.refresh()

    def alter_prop(self, arg=(None, None), menuw=None):
        """ Alter a favorites property

        This function is where the properties of a favorite really are changed.
        """
        logger.log(9, 'alter_prop(arg=%r, menuw=%r)', arg, menuw)
        (prop, val) = arg
        new_text = None
        new_arg = None
        back = True

        if prop == 'channel':
            if val == 'ANY':
                self.channel = 'ANY CHANNEL'
                self.fav.channel = 'ANY'
            else:
                self.channel = val
                self.fav.channel = val
            new_text = _('Channel') + u'\t' + _(self.channel)

        elif prop == 'dow':
            if val == 'ANY':
                self.dow = 'ANY DAY'
                self.fav.dow = 'ANY'
            else:
                self.dow = self.week_days[val]
                self.fav.dow = val
            new_text = _('Day of the Week') + u'\t' + _(self.dow)

        elif prop == 'mod':
            if val == 'ANY':
                self.mod = 'ANY TIME'
                self.fav.mod = 'ANY'
            else:
                # self.mod = tv_util.minToTOD(val)
                self.mod = time.strftime(config.TV_TIME_FORMAT,
                                         time.gmtime(float(val * 60)))
                self.fav.mod = val
            new_text = _('Time of Day') + u'\t' + _(self.mod)

        elif prop == 'dup':
            self.allowDuplicates = self.fav.allowDuplicates = val
            if val:
                value = _('Allow Duplicates')
            else:
                value = _('Prevent Duplicates')

            new_text = _('Duplicate Recordings') + u'\t' + value
            new_arg = ('dup', not val)
            back = False

        elif prop == 'new':
            self.onlyNew = self.fav.onlyNew = val
            if val:
                value = _('Only New Episodes')
            else:
                value = _('All New Episodes')
            new_text = _('Episode Filter') + u'\t' + value
            new_arg = ('new', not val)
            back = False

        if menuw and new_text:
            menu = menuw.menustack[back and -2 or -1]
            menu.selected.name = new_text
            if new_arg:
                menu.selected.arg = new_arg
            menu.selected.dirty = True
            if back:
                menuw.back_one_menu(arg='reload')
            else:
                menuw.refresh()

    def save_changes(self, arg=None, menuw=None):
        """
        Save favorite
        """
        logger.log(9, 'save_changes(arg=%r, menuw=%r)', arg, menuw)
        # this can take some time, as it means although to update the schedule
        msgtext = _('Saving the changes to this favorite.') + '\n' + _(
            'This may take some time.')
        pop = dialog.show_working_indicator(msgtext)

        if self.fav_action == 'edit':
            # first we remove the old favorite
            (result, msg) = self.recordclient.removeFavoriteNow(self.origname)
        elif self.fav_action == 'add':
            result = True

        if result:
            # create a new edited favorite
            (result, msg) = self.recordclient.addEditedFavoriteNow(
                self.fav.name, self.fav.title, self.fav.channel, self.fav.dow,
                self.fav.mod, self.fav.priority, self.fav.allowDuplicates,
                self.fav.onlyNew)
            if result:
                if menuw:
                    menuw.delete_submenu()
                    if self.fav_action == 'add':
                        menuw.refresh(reload=1)
                self.fav_action = 'edit'
                pop.hide()
            else:
                pop.hide()
                # it is important to show the user this error,
                # because that means the favorite is removed,
                # and must be created again
                msgtext = _('Save failed, favorite was lost') + (':\n%s' % msg)
                dialog.show_alert(msgtext)

    def rem_favorite(self, arg=None, menuw=None):
        """
        Remove favorite
        """
        logger.log(9, 'rem_favorite(arg=%r, menuw=%r)', arg, menuw)
        name = self.origname
        (result, msg) = self.recordclient.removeFavoriteNow(name)
        if result:
            # if this is successfull
            if menuw:
                menuw.delete_submenu()
                menuw.refresh(reload=1)
            # and show a short message of success
            msgtext = text = _('"%s" has been removed from favorites') % name
            dialog.show_alert(msgtext)
        else:
            # if all fails then we should show an error
            msgtext = _('Remove failed') + (':\n%s' % msg)
            dialog.show_alert(msgtext)

    def priority_mod(self, adjust, menuw=None):
        """
        Move current item in the priority list and refresh menu to
        show new position
        """
        name = self.origname
        result = self.recordclient.adjustPriorityNow(name, adjust)
        if result:
            # if this is successfull
            if menuw:
                menuw.delete_submenu()
                menuw.refresh(reload=1)
            else:
                event.Event('MENU_RELOAD').post()
        else:
            # if all fails then we should show an error
            msgtext = _('Priority adjustment failed') + (':\n%s' % msg)
            dialog.show_message(msgtext)

    def priority_up(self, arg=None, menuw=None):
        self.priority_mod(-1, menuw)

    def priority_down(self, arg=None, menuw=None):
        self.priority_mod(1, menuw)
Esempio n. 2
0
class FavoriteItem(Item):
    """
    Item class for favorite items
    """
    def __init__(self, parent, fav, fav_action='edit'):
        """ """
        Item.__init__(self, parent, skin_type='video')
        _debug_('FavoriteItem.__init__(parent=%r, fav=%r, fav_action=%r)' % (parent, fav, fav_action), 2)
        self.recordclient = RecordClient()
        self.fav   = fav
        self.name  = self.origname = fav.name
        self.title = fav.title
        self.fav_action = fav_action
        # twisted needs FALSE and TRUE, it does not know False and True
        if hasattr(fav,'allowDuplicates') and not fav.allowDuplicates:
            self.allowDuplicates = fav.allowDuplicates = FALSE
        else:
            self.allowDuplicates = fav.allowDuplicates = TRUE
        # twisted needs FALSE and TRUE, it does not know False and True
        if hasattr(fav,'onlyNew') and fav.onlyNew:
            self.onlyNew = fav.onlyNew = TRUE
        else:
            self.onlyNew = fav.onlyNew = FALSE

        self.week_days = (_('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat'), _('Sun'))

        if fav.channel == 'ANY':
            self.channel = _('ANY CHANNEL')
        else:
            self.channel = fav.channel
        if fav.dow == 'ANY':
            self.dow = _('ANY DAY')
        else:
            self.dow = self.week_days[int(fav.dow)]
        if fav.mod == 'ANY':
            self.mod = _('ANY TIME')
        else:
            try:
                self.mod = time.strftime(config.TV_TIME_FORMAT, time.gmtime(float(int(fav.mod) * 60)))
            except:
                print 'Cannot add "%s" to favorites' % fav.name

        # needed by the inputbox handler
        self.menuw = None

        self.red_action = (self.display_submenu,_('Edit favorite'))
        self.green_action = (self.rem_favorite, _('Remove favorite'))


    def actions(self):
        _debug_('actions()', 2)
        return [( self.display_submenu , _('Edit favorite'))]


    def display_submenu(self, arg=None, menuw=None):
        """ Display menu for a favorite

        With this menu the user can made a program a favorite.
        All attributes of a favorite can be edited here and in the end
        the user must select 'save changes' to finally create the favorite.
        """
        _debug_('display_submenu(arg=%r, menuw=%r)' % (arg, menuw), 2)
        ### create menu items for editing the favorites attributes
        items = []

        items.append(menu.MenuItem(_('Modify name'), action=self.mod_name))
        items.append(menu.MenuItem(_('Modify channel'), action=self.mod_channel))
        items.append(menu.MenuItem(_('Modify day of week'), action=self.mod_day))
        items.append(menu.MenuItem(_('Modify time of day'), action=self.mod_time))

        if config.TV_RECORD_DUPLICATE_DETECTION:
            if self.allowDuplicates:
                items.append(menu.MenuItem(_('Prevent Recording of Duplicates'), \
                    action=self.alter_prop, arg=('dup', 'False')))
            else:
                items.append(menu.MenuItem(_('Allow Recording of Duplicates'),
                    action=self.alter_prop, arg=('dup', 'True')))


        if config.TV_RECORD_ONLY_NEW_DETECTION:
            if self.onlyNew:
                items.append(menu.MenuItem(_('Record All Episodes'), action=self.alter_prop, arg=('new', 'False')))
            else:
                items.append(menu.MenuItem(_('Record Only New Episodes'), action=self.alter_prop, arg=('new', 'True')))

        # XXX: priorities aren't quite supported yet
        if 0:
            (status, favorites) = self.recordclient.getFavoritesNow()
            if status and len(favorites) > 1:
                items.append(menu.MenuItem(_('Modify priority'), action=self.mod_priority))


        ### save favorite
        items.append(menu.MenuItem(_('Save changes'), action=self.save_changes))

        ### remove this program from favorites
        if not self.fav_action == 'add':
            items.append(menu.MenuItem(_('Remove favorite'), action=self.rem_favorite))

        ### put the whole menu together
        favorite_menu = menu.Menu(_('Favorite Menu'), items, item_types='tv favorite menu')
        favorite_menu.infoitem = self
        favorite_menu.is_submenu = True
        menuw.pushmenu(favorite_menu)
        menuw.refresh()



    ### Actions:

    def mod_name(self, arg=None, menuw=None):
        """ Modify name

        This opens a input box to ask the user for a new name for this favorite.
        The default name of a favorite is the name of the program.
        """
        _debug_('mod_name(arg=%r, menuw=%r)' % (arg, menuw), 2)
        self.menuw = menuw
        InputBox(text=_('Alter Name'), handler=self.alter_name, \
            width=osd.get_singleton().width - config.OSD_OVERSCAN_LEFT - 20, input_text=self.name).show()


    def alter_name(self, name):
        """ set the new name"""
        _debug_('alter_name(name=%r)' % (name,), 2)
        if name:
            self.name = self.fav.name = name.strip()

        self.menuw.refresh()


    def mod_channel(self, arg=None, menuw=None):
        """Modify channel"""
        _debug_('mod_channel(arg=%r, menuw=%r)' % (arg, menuw), 2)
        items = []

        items.append(menu.MenuItem('ANY CHANNEL', action=self.alter_prop, arg=('channel', 'ANY')))

        for chanline in config.TV_CHANNELS:
            items.append(menu.MenuItem(chanline[1], action=self.alter_prop, arg=('channel', chanline[1])))

        favorite_menu = menu.Menu(_('Modify Channel'), items, item_types='tv favorite menu')
        favorite_menu.infoitem = self
        menuw.pushmenu(favorite_menu)
        menuw.refresh()


    def mod_day(self, arg=None, menuw=None):
        """ Modify day

        Opens a submenu where the day of the week of a favorite can be configured.
        """
        _debug_('mod_day(arg=%r, menuw=%r)' % (arg, menuw), 2)
        items = []

        items.append(menu.MenuItem(_('ANY DAY'), action=self.alter_prop, arg=('dow', 'ANY')))

        for i in range(len(self.week_days)):
            items.append(menu.MenuItem(self.week_days[i], action=self.alter_prop, arg=('dow', i)))

        favorite_menu = menu.Menu(_('Modify Day'), items, item_types = 'tv favorite menu')
        favorite_menu.infoitem = self
        menuw.pushmenu(favorite_menu)
        menuw.refresh()


    def mod_time(self, arg=None, menuw=None):
        """ Modify time

        Opens a submenu where the time of a favorite can be configured.
        """
        _debug_('mod_time(arg=%r, menuw=%r)' % (arg, menuw), 2)
        items = []

        items.append(menu.MenuItem(_('ANY TIME'), action=self.alter_prop, arg=('mod', 'ANY')))

        for i in range(48):
            mod = i * 30
            items.append(menu.MenuItem(time.strftime(config.TV_TIME_FORMAT, time.gmtime(float(mod * 60))), \
                action=self.alter_prop, arg=('mod', mod)))

        favorite_menu = menu.Menu(_('Modify Time'), items, item_types = 'tv favorite menu')
        favorite_menu.infoitem = self
        menuw.pushmenu(favorite_menu)
        menuw.refresh()


    def alter_prop(self, arg=(None,None), menuw=None):
        """ Alter a favorites property

        This function is where the properties of a favorite really are changed.
        """
        _debug_('alter_prop(arg=%r, menuw=%r)' % (arg, menuw), 2)
        (prop, val) = arg

        if prop == 'channel':
            if val == 'ANY':
                self.channel = 'ANY CHANNEL'
                self.fav.channel = 'ANY'
            else:
                self.channel = val
                self.fav.channel = val
            if menuw:
                menuw.back_one_menu(arg='reload')

        elif prop == 'dow':
            if val == 'ANY':
                self.dow = 'ANY DAY'
                self.fav.dow = 'ANY'
            else:
                self.dow = self.week_days[val]
                self.fav.dow = val
            if menuw:
                menuw.back_one_menu(arg='reload')

        elif prop == 'mod':
            if val == 'ANY':
                self.mod = 'ANY TIME'
                self.fav.mod = 'ANY'
            else:
                # self.mod = tv_util.minToTOD(val)
                self.mod = time.strftime(config.TV_TIME_FORMAT, time.gmtime(float(val * 60)))
                self.fav.mod = val
            if menuw:
                menuw.back_one_menu(arg='reload')

        elif prop == 'dup':
            if val == 'True':
                # twisted needs FALSE and TRUE, it does not know False and True
                self.allowDuplicates=TRUE
                self.fav.allowDuplicates=TRUE
                newname = _('Prevent Recording of Duplicates')
                val = 'False'
            else:
                # twisted needs FALSE and TRUE, it does not know False and True
                self.allowDuplicates=FALSE
                self.fav.allowDuplicates=FALSE
                newname = _('Allow Recordings of Duplicates')
                val = 'True'
            if menuw:
                menustack = menuw.menustack[-1]
                pos = menustack.choices.index(menustack.selected)
                new = menu.MenuItem(newname, action=self.alter_prop, arg=('dup', val))
                menustack.choices[pos] = new
                menustack.selected = menustack.choices[pos]
                menuw.init_page()
                menuw.refresh()

        elif prop == 'new':
            # twisted needs FALSE and TRUE, it does not know False and True
            if val == 'True':
                self.onlyNew=TRUE
                self.fav.onlyNew=TRUE
                newname = _('Record All Episodes')
                val = 'False'
            else:
                self.onlyNew=FALSE
                self.fav.onlyNew=FALSE
                newname = _('Record Only New Episodes')
                val = 'True'
            if menuw:
                menustack = menuw.menustack[-1]
                pos = menustack.choices.index(menustack.selected)
                new = menu.MenuItem(newname, action=self.alter_prop, arg=('new', val))
                menustack.choices[pos] = new
                menustack.selected = menustack.choices[pos]
                menuw.init_page()
                menuw.refresh()


    def save_changes(self, arg=None, menuw=None):
        """
        Save favorite
        """
        _debug_('save_changes(arg=%r, menuw=%r)' % (arg, menuw), 2)
        # this can take some time, as it means although to update the schedule
        msgtext = _('Saving the changes to this favorite.')+'\n'+_('This may take some time.')
        pop = PopupBox(text=msgtext)
        pop.show()

        if self.fav_action == 'edit':
            # first we remove the old favorite
            (result, msg) = self.recordclient.removeFavoriteNow(self.origname)
        elif self.fav_action =='add':
            result = True

        if result:
            # create a new edited favorite
            (result, msg) = self.recordclient.addEditedFavoriteNow(self.fav.name,
                self.fav.title, self.fav.channel, self.fav.dow, self.fav.mod,
                self.fav.priority, self.fav.allowDuplicates, self.fav.onlyNew)
            if result:
                if menuw:
                    menuw.delete_submenu()
                    if self.fav_action == 'add':
                        menuw.refresh(reload=1)
                self.fav_action = 'edit'
                pop.destroy()
            else:
                pop.destroy()
                # it is important to show the user this error,
                # because that means the favorite is removed,
                # and must be created again
                msgtext=_('Save failed, favorite was lost')+(':\n%s' % msg)
                AlertBox(text=msgtext).show()


    def rem_favorite(self, arg=None, menuw=None):
        """
        Remove favorite
        """
        _debug_('rem_favorite(arg=%r, menuw=%r)' % (arg, menuw), 2)
        name = self.origname
        (result, msg) = self.recordclient.removeFavoriteNow(name)
        if result:
            # if this is successfull
            if menuw:
                menuw.delete_submenu()
                menuw.refresh(reload=1)
            # and show a short message of success
            msgtext = text=_('"%s" has been removed from favorites') % name
            AlertBox(text=msgtext).show()
        else:
            # if all fails then we should show an error
            msgtext = _('Remove failed')+(':\n%s' % msg)
            AlertBox(text=msgtext).show()
Esempio n. 3
0
class FavoriteItem(Item):
    """
    Item class for favorite items
    """
    def __init__(self, parent, fav, fav_action='edit'):
        """ """
        Item.__init__(self, parent, skin_type='video')
        logger.log( 9, 'FavoriteItem.__init__(parent=%r, fav=%r, fav_action=%r)', parent, fav, fav_action)
        self.recordclient = RecordClient()
        self.fav   = fav
        self.name  = self.origname = fav.name
        self.title = fav.title
        self.fav_action = fav_action
        if hasattr(fav, 'allowDuplicates'):
            self.allowDuplicates = int(fav.allowDuplicates)

        if hasattr(self.fav, 'onlyNew'):
            self.onlyNew = int(fav.onlyNew)

        self.week_days = (_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'), _('Sunday'))


        if fav.channel == 'ANY':
            self.channel = _('ANY CHANNEL')
        else:
            self.channel = fav.channel
        if fav.dow == 'ANY':
            self.dow = _('ANY DAY')
        else:
            self.dow = self.week_days[int(fav.dow)]
        if fav.mod == 'ANY':
            self.mod = _('ANY TIME')
        else:
            try:
                self.mod = time.strftime(config.TV_TIME_FORMAT, time.gmtime(float(int(fav.mod) * 60)))
            except:
                print 'Cannot add "%s" to favorites' % fav.name

        # needed by the inputbox handler
        self.menuw = None


    def actions(self):
        logger.log( 9, 'actions()')
        return [( self.display_submenu, _('Edit favorite')), 
                ( self.priority_up, _('Increase priority')), 
                ( self.priority_down, _('Decrease priority')),
                ( self.rem_favorite, _('Remove favorite'))]


    def display_submenu(self, arg=None, menuw=None):
        """ Display menu for a favorite

        With this menu the user can made a program a favorite.
        All attributes of a favorite can be edited here and in the end
        the user must select 'save changes' to finally create the favorite.
        """
        logger.log( 9, 'display_submenu(arg=%r, menuw=%r)', arg, menuw)
        ### create menu items for editing the favorites attributes
        items = []

        items.append(menu.MenuItem(_('Name') + u'\t' + _(self.name), action=self.mod_name))
        items.append(menu.MenuItem(_('Channel') + u'\t' + _(self.channel), action=self.mod_channel))
        items.append(menu.MenuItem(_('Day of the Week') + u'\t' + _(self.dow), action=self.mod_day))
        items.append(menu.MenuItem(_('Time of Day') + u'\t' + _(self.mod), action=self.mod_time))

        if config.TV_RECORD_DUPLICATE_DETECTION:
            if self.allowDuplicates:
                value = _('Allow duplicates')
            else:
                value = _('Prevent duplicates')
            items.append(menu.MenuItem(_('Duplicate Recordings') + u'\t' + _(value),
                                        action=self.alter_prop,
                                        arg=('dup', not self.allowDuplicates)))


        if config.TV_RECORD_ONLY_NEW_DETECTION:
            if self.onlyNew:
                value = _('Only new episodes')
            else:
                value = _('All episodes')
            items.append(menu.MenuItem(_('Episode Filter') + u'\t' + _(value),
                                        action=self.alter_prop,
                                        arg=('new', not self.onlyNew)))

        # XXX: priorities aren't quite supported yet
        if 0:
            (status, favorites) = self.recordclient.getFavoritesNow()
            if status and len(favorites) > 1:
                items.append(menu.MenuItem(_('Modify priority'), action=self.mod_priority))


        ### save favorite
        items.append(menu.MenuItem(_('Save changes') + u'\t', action=self.save_changes))

        ### remove this program from favorites
        if not self.fav_action == 'add':
            items.append(menu.MenuItem(_('Remove favorite') + u'\t', action=self.rem_favorite))

        ### put the whole menu together
        favorite_menu = menu.Menu(_('Favorite Menu'), items, item_types='tv favorite menu')
        favorite_menu.infoitem = self
        favorite_menu.is_submenu = True
        favorite_menu.table = (50, 50)
        menuw.pushmenu(favorite_menu)
        menuw.refresh()



    ### Actions:

    def mod_name(self, arg=None, menuw=None):
        """ Modify name

        This opens a input box to ask the user for a new name for this favorite.
        The default name of a favorite is the name of the program.
        """
        logger.log( 9, 'mod_name(arg=%r, menuw=%r)', arg, menuw)
        self.menuw = menuw
        InputBox(text=_('Alter Name'), handler=self.alter_name, \
            width=osd.get_singleton().width - config.OSD_OVERSCAN_LEFT - 20, input_text=self.name).show()


    def alter_name(self, name):
        """ set the new name"""
        logger.log( 9, 'alter_name(name=%r)', name)
        if name:
            self.name = self.fav.name = name.strip()
        menustack = self.menuw.menustack[-1]
        menustack.selected.dirty = True
        self.menuw.refresh()


    def mod_channel(self, arg=None, menuw=None):
        """Modify channel"""
        logger.log( 9, 'mod_channel(arg=%r, menuw=%r)', arg, menuw)
        items = []

        items.append(menu.MenuItem('ANY CHANNEL', action=self.alter_prop, arg=('channel', 'ANY')))

        for chanline in config.TV_CHANNELS:
            items.append(menu.MenuItem(chanline[1], action=self.alter_prop, arg=('channel', chanline[1])))

        favorite_menu = menu.Menu(_('Modify Channel'), items, item_types='tv favorite menu')
        favorite_menu.infoitem = self
        menuw.pushmenu(favorite_menu)
        menuw.refresh()


    def mod_day(self, arg=None, menuw=None):
        """ Modify day

        Opens a submenu where the day of the week of a favorite can be configured.
        """
        logger.log( 9, 'mod_day(arg=%r, menuw=%r)', arg, menuw)
        items = []

        items.append(menu.MenuItem(_('ANY DAY'), action=self.alter_prop, arg=('dow', 'ANY')))

        for i in range(len(self.week_days)):
            items.append(menu.MenuItem(self.week_days[i], action=self.alter_prop, arg=('dow', i)))

        favorite_menu = menu.Menu(_('Modify Day'), items, item_types = 'tv favorite menu')
        favorite_menu.infoitem = self
        menuw.pushmenu(favorite_menu)
        menuw.refresh()


    def mod_time(self, arg=None, menuw=None):
        """ Modify time

        Opens a submenu where the time of a favorite can be configured.
        """
        logger.log( 9, 'mod_time(arg=%r, menuw=%r)', arg, menuw)
        items = []

        items.append(menu.MenuItem(_('ANY TIME'), action=self.alter_prop, arg=('mod', 'ANY')))

        for i in range(48):
            mod = i * 30
            items.append(menu.MenuItem(time.strftime(config.TV_TIME_FORMAT, time.gmtime(float(mod * 60))), \
                action=self.alter_prop, arg=('mod', mod)))

        favorite_menu = menu.Menu(_('Modify Time'), items, item_types = 'tv favorite menu')
        favorite_menu.infoitem = self
        menuw.pushmenu(favorite_menu)
        menuw.refresh()


    def alter_prop(self, arg=(None, None), menuw=None):
        """ Alter a favorites property

        This function is where the properties of a favorite really are changed.
        """
        logger.log( 9, 'alter_prop(arg=%r, menuw=%r)', arg, menuw)
        (prop, val) = arg
        new_text = None
        new_arg = None
        back = True

        if prop == 'channel':
            if val == 'ANY':
                self.channel = 'ANY CHANNEL'
                self.fav.channel = 'ANY'
            else:
                self.channel = val
                self.fav.channel = val
            new_text = _('Channel') + u'\t' + _(self.channel)

        elif prop == 'dow':
            if val == 'ANY':
                self.dow = 'ANY DAY'
                self.fav.dow = 'ANY'
            else:
                self.dow = self.week_days[val]
                self.fav.dow = val
            new_text = _('Day of the Week') + u'\t' + _(self.dow)

        elif prop == 'mod':
            if val == 'ANY':
                self.mod = 'ANY TIME'
                self.fav.mod = 'ANY'
            else:
                # self.mod = tv_util.minToTOD(val)
                self.mod = time.strftime(config.TV_TIME_FORMAT, time.gmtime(float(val * 60)))
                self.fav.mod = val
            new_text = _('Time of Day') + u'\t' + _(self.mod)

        elif prop == 'dup':
            self.allowDuplicates= self.fav.allowDuplicates= val
            if val:
                value = _('Allow Duplicates')
            else:
                value = _('Prevent Duplicates')

            new_text =  _('Duplicate Recordings') + u'\t' + value
            new_arg = ('dup', not val)
            back = False

        elif prop == 'new':
            self.onlyNew= self.fav.onlyNew = val
            if val:
                value = _('Only New Episodes')
            else:
                value = _('All New Episodes')
            new_text = _('Episode Filter') + u'\t' + value
            new_arg = ('new', not val)
            back = False

        if menuw and new_text:
            menu = menuw.menustack[back and -2 or -1]
            menu.selected.name = new_text
            if new_arg:
                menu.selected.arg = new_arg
            menu.selected.dirty = True
            if back:
                menuw.back_one_menu(arg='reload')
            else:
                menuw.refresh()

    def save_changes(self, arg=None, menuw=None):
        """
        Save favorite
        """
        logger.log( 9, 'save_changes(arg=%r, menuw=%r)', arg, menuw)
        # this can take some time, as it means although to update the schedule
        msgtext = _('Saving the changes to this favorite.')+'\n'+_('This may take some time.')
        pop = dialog.show_working_indicator(msgtext)

        if self.fav_action == 'edit':
            # first we remove the old favorite
            (result, msg) = self.recordclient.removeFavoriteNow(self.origname)
        elif self.fav_action =='add':
            result = True

        if result:
            # create a new edited favorite
            (result, msg) = self.recordclient.addEditedFavoriteNow(self.fav.name,
                self.fav.title, self.fav.channel, self.fav.dow, self.fav.mod,
                self.fav.priority, self.fav.allowDuplicates, self.fav.onlyNew)
            if result:
                if menuw:
                    menuw.delete_submenu()
                    if self.fav_action == 'add':
                        menuw.refresh(reload=1)
                self.fav_action = 'edit'
                pop.hide()
            else:
                pop.hide()
                # it is important to show the user this error,
                # because that means the favorite is removed,
                # and must be created again
                msgtext=_('Save failed, favorite was lost')+(':\n%s' % msg)
                dialog.show_alert(msgtext)


    def rem_favorite(self, arg=None, menuw=None):
        """
        Remove favorite
        """
        logger.log( 9, 'rem_favorite(arg=%r, menuw=%r)', arg, menuw)
        name = self.origname
        (result, msg) = self.recordclient.removeFavoriteNow(name)
        if result:
            # if this is successfull
            if menuw:
                menuw.delete_submenu()
                menuw.refresh(reload=1)
            # and show a short message of success
            msgtext = text=_('"%s" has been removed from favorites') % name
            dialog.show_alert(msgtext)
        else:
            # if all fails then we should show an error
            msgtext = _('Remove failed')+(':\n%s' % msg)
            dialog.show_alert(msgtext)


    def priority_mod(self, adjust, menuw=None):
        """
        Move current item in the priority list and refresh menu to
        show new position
        """
        name = self.origname
        result = self.recordclient.adjustPriorityNow(name, adjust)
        if result:
            # if this is successfull
            if menuw:
                menuw.delete_submenu()
                menuw.refresh(reload=1)
            else:
                event.Event('MENU_RELOAD').post()
        else:
            # if all fails then we should show an error
            msgtext = _('Priority adjustment failed')+(':\n%s' % msg)
            dialog.show_message(msgtext)


    def priority_up(self, arg=None, menuw=None):
        self.priority_mod(-1, menuw)


    def priority_down(self, arg=None, menuw=None):
        self.priority_mod(1, menuw)
Esempio n. 4
0
class ViewFavoritesItem(Item):
    def __init__(self, parent):
        _debug_('ViewFavoritesItem.__init__(parent=%r)' % (parent,), 2)
        Item.__init__(self, parent, skin_type='tv')
        self.name = _('View Favorites')
        self.menuw = None
        self.recordclient = RecordClient()


    def actions(self):
        _debug_('actions()', 2)
        return [ ( self.view_favorites , _('View Favorites') ) ]


    def view_favorites(self, arg=None, menuw=None):
        _debug_('view_favorites(arg=%r, menuw=%r)' % (arg, menuw), 2)
        if not self.recordclient.pingNow():
            AlertBox(self.recordclient.recordserverdown).show()
            return

        items = self.get_items()
        if not len(items):
            AlertBox(_('No favorites.')).show()
            return

        favorite_menu = menu.Menu(_( 'View Favorites'), items, reload_func=self.reload, item_types='tv favorite menu')
        self.menuw = menuw
        rc.app(None)
        menuw.pushmenu(favorite_menu)
        menuw.refresh()


    def reload(self):
        _debug_('reload()', 2)
        menuw = self.menuw

        menu = menuw.menustack[-1]

        new_choices = self.get_items()
        if not menu.selected in new_choices and len(new_choices):
            sel = menu.choices.index(menu.selected)
            if len(new_choices) <= sel:
                menu.selected = new_choices[-1]
            else:
                menu.selected = new_choices[sel]

        menu.choices = new_choices

        return menu


    def get_items(self):
        _debug_('get_items()', 2)
        items = []

        (status, favorites) = self.recordclient.getFavoritesNow()
        if status:
            f = lambda a, b: cmp(a.priority, b.priority)
            favs = favorites.values()
            favs.sort(f)
            for fav in favs:
                items.append(FavoriteItem(self, fav))

        return items
Esempio n. 5
0
class ViewFavoritesItem(Item):
    def __init__(self, parent):
        logger.log( 9, 'ViewFavoritesItem.__init__(parent=%r)', parent)
        Item.__init__(self, parent, skin_type='tv')
        self.name = _('View Favorites')
        self.menuw = None
        self.recordclient = RecordClient()


    def actions(self):
        logger.log( 9, 'actions()')
        return [ ( self.view_favorites , _('View Favorites') ),
                 ( self.reschedule_favorites, _('Reschedule Favorites'))]


    def view_favorites(self, arg=None, menuw=None):
        logger.log( 9, 'view_favorites(arg=%r, menuw=%r)', arg, menuw)
        if not self.recordclient.pingNow():
            dialog.show_alert(self.recordclient.recordserverdown)
            return

        items = self.get_items()
        if not len(items):
            dialog.show_alert(_('No favorites.'))
            return

        favorite_menu = menu.Menu(_( 'View Favorites'), items, reload_func=self.reload, item_types='tv favorite menu')
        self.menuw = menuw
        menuw.pushmenu(favorite_menu)
        menuw.refresh()


    def reschedule_favorites(self, arg=None, menuw=None):
        """
        Force rescheduling of favorites
        """
        logger.log( 9, 'resched_favs(arg=%r, menuw=%r)', arg, menuw)
        dialog.show_message(_('Rescheduling Favorites...'))
        self.recordclient.updateFavoritesScheduleCo().connect(self.reschedule_favorites_complete)
        if menuw:
            menuw.delete_submenu()

    def reschedule_favorites_complete(self, result):
        if result:
            dialog.show_message(_('Favorites rescheduled'))
        else:
            dialog.show_alert(_('Reschedule failed'))


    def reload(self):
        logger.log( 9, 'reload()')
        menuw = self.menuw

        menu = menuw.menustack[-1]

        new_choices = self.get_items()
        if not menu.selected in new_choices and len(new_choices):
            sel = menu.choices.index(menu.selected)
            if len(new_choices) <= sel:
                menu.selected = new_choices[-1]
            else:
                menu.selected = new_choices[sel]

        menu.choices = new_choices

        return menu


    def get_items(self):
        logger.log( 9, 'get_items()')
        items = []

        (status, favorites) = self.recordclient.getFavoritesNow()
        if status:
            f = lambda a, b: cmp(a.priority, b.priority)
            favs = favorites.values()
            favs.sort(f)
            for fav in favs:
                items.append(FavoriteItem(self, fav))

        return items
Esempio n. 6
0
class ViewFavoritesItem(Item):
    def __init__(self, parent):
        logger.log(9, 'ViewFavoritesItem.__init__(parent=%r)', parent)
        Item.__init__(self, parent, skin_type='tv')
        self.name = _('View Favorites')
        self.menuw = None
        self.recordclient = RecordClient()

    def actions(self):
        logger.log(9, 'actions()')
        return [(self.view_favorites, _('View Favorites')),
                (self.reschedule_favorites, _('Reschedule Favorites'))]

    def view_favorites(self, arg=None, menuw=None):
        logger.log(9, 'view_favorites(arg=%r, menuw=%r)', arg, menuw)
        if not self.recordclient.pingNow():
            dialog.show_alert(self.recordclient.recordserverdown)
            return

        items = self.get_items()
        if not len(items):
            dialog.show_alert(_('No favorites.'))
            return

        favorite_menu = menu.Menu(_('View Favorites'),
                                  items,
                                  reload_func=self.reload,
                                  item_types='tv favorite menu')
        self.menuw = menuw
        menuw.pushmenu(favorite_menu)
        menuw.refresh()

    def reschedule_favorites(self, arg=None, menuw=None):
        """
        Force rescheduling of favorites
        """
        logger.log(9, 'resched_favs(arg=%r, menuw=%r)', arg, menuw)
        dialog.show_message(_('Rescheduling Favorites...'))
        self.recordclient.updateFavoritesScheduleCo().connect(
            self.reschedule_favorites_complete)
        if menuw:
            menuw.delete_submenu()

    def reschedule_favorites_complete(self, result):
        if result:
            dialog.show_message(_('Favorites rescheduled'))
        else:
            dialog.show_alert(_('Reschedule failed'))

    def reload(self):
        logger.log(9, 'reload()')
        menuw = self.menuw

        menu = menuw.menustack[-1]

        new_choices = self.get_items()
        if not menu.selected in new_choices and len(new_choices):
            sel = menu.choices.index(menu.selected)
            if len(new_choices) <= sel:
                menu.selected = new_choices[-1]
            else:
                menu.selected = new_choices[sel]

        menu.choices = new_choices

        return menu

    def get_items(self):
        logger.log(9, 'get_items()')
        items = []

        (status, favorites) = self.recordclient.getFavoritesNow()
        if status:
            f = lambda a, b: cmp(a.priority, b.priority)
            favs = favorites.values()
            favs.sort(f)
            for fav in favs:
                items.append(FavoriteItem(self, fav))

        return items