예제 #1
0
    def __init__(self, sort_fn=sort_channels_by_name, filter_fn=None):
        red_listmodel.ListModel.__init__(self, sort_fn, filter_fn)
        red_serverlistener.ServerListener.__init__(self)

        self.__channels = rcd_util.get_all_channels()

        for name, callback, type in COLUMNS:
            self.add_column(callback, type)

        self.refresh()
예제 #2
0
    def get_icon(self, name):
        # FIXME: Special hacks for current (bad) news file
        if name == "Ximian GNOME":
            name = "Ximian Desktop"

        if name == "OpenOffice":
            name = "OpenOffice.org"

        channels = rcd_util.get_all_channels()
        for c in channels:
            if c["name"] == name:
                return rcd_util.get_channel_icon(c["id"])

        return None
예제 #3
0
def mount_channel(path, name, recursive):
    # Handle ~ to mean $HOME
    if path[0] == "~":
        homedir = os.getenv("HOME")
        if homedir:
            path = homedir + path[1:]
            print path

    path_base = os.path.basename(path)
    alias = string.lower(path_base)

    aliases = map(lambda x: rcd_util.get_channel_alias(x["id"]),
                  rcd_util.get_all_channels())

    old_alias = alias
    count = 1
    while alias in aliases:
        alias = "%s%d" % (old_alias, count)
        count += 1

    if not name:
        name = path

    server = rcd_util.get_server_proxy()
    mount_th = server.rcd.packsys.mount_directory(path, name, alias,
                                                  int(recursive))

    def mount_cb(th, path):
        try:
            th.get_result()
        except ximian_xmlrpclib.Fault, f:
            if f.faultCode == rcd_util.fault.invalid_service:
                dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
                                           gtk.BUTTONS_OK,
                                           "%s" % f.faultString)

                def idle_cb(d):
                    gtk.threads_enter()
                    d.show()
                    d.run()
                    d.destroy()
                    gtk.threads_leave()

                # Always run the dialog in the main thread
                gtk.idle_add(idle_cb, dialog)
            else:
                raise
예제 #4
0
    def get_filter(self):

        channel_id = self.__ch_opt.get_channel_id()
        subd_dict = {}
        if channel_id == red_channeloption.MATCH_ANY_SUBD_CHANNEL:
            subd_dict[0] = 1  # We are always subscribed to channel 0
            # (i.e. system packages)
            for c in rcd_util.get_all_channels():
                if c.get("subscribed"):
                    subd_dict[c["id"]] = 1

        def filter_fn(p,
                      n=self.__match_section,
                      status_fn=self.__status_filter,
                      subd_dict=subd_dict):

            if subd_dict and not subd_dict.has_key(p.get("channel")):
                return 0

            if channel_id == red_channeloption.MATCH_NO_CHANNEL \
                   and (p.get("channel") or p.has_key("channel_guess")):
                return 0

            if self.__system_packages_only \
               and red_channeloption.is_valid_channel(channel_id) \
               and channel_id != p.get("channel_guess"):
                return 0

            if self.__uninstalled_packages_only \
               and red_channeloption.is_valid_channel(channel_id) \
               and channel_id != p.get("channel"):
                return 0

            sect = p.get("section_num")
            return (not status_fn or status_fn(p)) and (n < 0 or sect == n)

        return filter_fn
예제 #5
0
 def refresh_cb(me):
     me.__channels = rcd_util.get_all_channels()
예제 #6
0
    def __assemble(self):
        self.item_id_list = []
        menu = gtk.Menu()

        channels = rcd_util.get_all_channels()
        channels.sort(
            lambda x, y: cmp(string.lower(x["name"]), string.lower(y["name"])))

        if self.__allow_any_channel:
            channels.insert(0, {
                "name": _("All Catalogs"),
                "id": MATCH_ANY_CHANNEL
            })

        if self.__allow_any_subd_channel:
            channels.insert(
                0, {
                    "name": _("All Subscribed Catalogs"),
                    "id": MATCH_ANY_SUBD_CHANNEL,
                    "subscribed": 1
                })

        if self.__allow_no_channel:
            channels.append({
                "name": _("No Catalog/Unknown Catalog"),
                "id": MATCH_NO_CHANNEL
            })

        width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
        for c in channels:
            hbox = gtk.HBox(0, 0)

            if not is_channel_wildcard(c["id"]):
                pixbuf = rcd_util.get_channel_icon(c["id"], 24, 24)
            else:
                pixbuf = None

            img = gtk.Image()
            img.set_size_request(24, 24)
            if pixbuf:
                img.set_from_pixbuf(pixbuf)

            label = gtk.Label(c["name"])

            hbox.pack_start(img, 0, 0, 0)
            hbox.pack_start(label, 0, 0, 4)

            if c.get("subscribed"):
                sub_img = red_pixbuf.get_widget("status-installed",
                                                width=width,
                                                height=height)
                hbox.pack_end(sub_img, expand=0, fill=0, padding=2)

            item = gtk.MenuItem()
            item.add(hbox)
            item.show_all()

            self.item_id_list.append(c["id"])

            def activate_cb(item, id, opt):
                if id != self.__last_id:
                    opt.__last_id = id
                    opt.emit("selected", id)

            item.connect("activate", activate_cb, c["id"], self)

            menu.append(item)

        menu.show()
        self.set_menu(menu)
예제 #7
0
def has_mounted_channels():
    return len(
        [x["id"] for x in rcd_util.get_all_channels() if x.get("mounted", 0)])