def _append_group(self, dev_group):
        group_id = dev_group.get_id()
        group_name = dev_group.get_name()

        group_iter = self.append(None, [group_id, group_name, 0, dev_group])
        channellist = dev_group.get_channel_list()

        d = Callback()
        if self._use_channel_groups:
            d.add_callback(self._append_channel_groups, channellist, group_id,
                           group_iter, dev_group)
            self._manager.get_channel_groups(
                result_handler=lambda p, x, u: d.callback(x),
                error_handler=global_error_handler)
            # Put all available channels either in TV or radio group
            tv_group_iter = self.append(
                group_iter,
                [group_id, _("TV Channels"), 0, dev_group])
            radio_group_iter = self.append(
                group_iter,
                [group_id, _("Radio Channels"), 0, dev_group])
        else:
            # Do not distinguish between radio and TV
            tv_group_iter = group_iter
            radio_group_iter = group_iter

        d_all = Callback()
        d_all.add_callback(self._append_channels, group_id, dev_group,
                           tv_group_iter, radio_group_iter)
        channellist.get_channel_infos(
            result_handler=lambda p, x, u: d_all.callback(x),
            error_handler=global_error_handler)
    def _append_group(self, dev_group):
        group_id = dev_group.get_id()
        group_name = dev_group.get_name()

        group_iter = self.append(None, [group_id, group_name, 0, dev_group])
        channellist = dev_group.get_channel_list()

        d = Callback()
        if self._use_channel_groups:
            d.add_callback(self._append_channel_groups, channellist, group_id, group_iter, dev_group)
            self._manager.get_channel_groups(
                result_handler=lambda p, x, u: d.callback(x), error_handler=global_error_handler
            )
            # Put all available channels either in TV or radio group
            tv_group_iter = self.append(group_iter, [group_id, _("TV Channels"), 0, dev_group])
            radio_group_iter = self.append(group_iter, [group_id, _("Radio Channels"), 0, dev_group])
        else:
            # Do not distinguish between radio and TV
            tv_group_iter = group_iter
            radio_group_iter = group_iter

        d_all = Callback()
        d_all.add_callback(self._append_channels, group_id, dev_group, tv_group_iter, radio_group_iter)
        channellist.get_channel_infos(
            result_handler=lambda p, x, u: d_all.callback(x), error_handler=global_error_handler
        )
    def _append_channel_groups(self, channel_groups, channellist, group_id, group_iter, dev_group):
        def append_channel(channels, chan_group_iter):
            for channel_id in channels:
                name, success = channellist.get_channel_name(channel_id)
                if success:
                    self.append(chan_group_iter, [group_id, escape(name), channel_id, dev_group])

        for chan_group_id, name in channel_groups:
            chan_group_iter = self.append(group_iter, [group_id, escape(name), 0, dev_group])
            d = Callback()
            d.add_callback(append_channel, chan_group_iter)
            channellist.get_channels_of_group(
                chan_group_id, result_handler=lambda p, data, u: d.callback(data[1]), error_handler=global_error_handler
            )

        self.emit("loading-finished", group_id)
    def _append_channel_groups(self, channel_groups, channellist, group_id,
                               group_iter, dev_group):
        def append_channel(channels, chan_group_iter):
            for channel_id in channels:
                name, success = channellist.get_channel_name(channel_id)
                if success:
                    self.append(
                        chan_group_iter,
                        [group_id,
                         escape(name), channel_id, dev_group])

        for chan_group_id, name in channel_groups:
            chan_group_iter = self.append(
                group_iter, [group_id, escape(name), 0, dev_group])
            d = Callback()
            d.add_callback(append_channel, chan_group_iter)
            channellist.get_channels_of_group(
                chan_group_id,
                result_handler=lambda p, data, u: d.callback(data[1]),
                error_handler=global_error_handler)

        self.emit("loading-finished", group_id)