Example #1
0
  def __init__(self, parent, datadir, distro, custom_mirrors):
    """
    Initialize the dialog that allows to choose a custom or official mirror
    """
    def is_separator(model, iter, data=None):
        return model.get_value(iter, COLUMN_SEPARATOR)

    self.custom_mirrors = custom_mirrors
    self.country_info = CountryInformation()

    setup_ui(self, os.path.join(datadir, "gtkbuilder", "dialog-mirror.ui"), domain="software-properties")
    
    self.dialog = self.dialog_mirror
    self.dialog.set_transient_for(parent)
    
    self.dialog_test = self.dialog_mirror_test
    self.dialog_test.set_transient_for(self.dialog)
    self.distro = distro
    self.treeview = self.treeview_mirrors
    self.button_edit = self.button_mirror_edit
    self.button_remove = self.button_mirror_remove
    self.button_choose = self.button_mirror_choose
    self.button_cancel = self.button_test_cancel
    self.label_test = self.label_test_mirror
    self.progressbar_test = self.progressbar_test_mirror
    self.combobox = self.combobox_mirror_proto
    self.progress = self.progressbar_test_mirror
    self.label_action = self.label_test_mirror

    # store each proto and its dir
    model_proto = Gtk.ListStore(GObject.TYPE_STRING,
                                GObject.TYPE_STRING)
    self.combobox.set_model(model_proto)
    cr = Gtk.CellRendererText()
    self.combobox.pack_start(cr, True)
    self.combobox.add_attribute(cr, "markup", 0)

    self.model = Gtk.TreeStore(GObject.TYPE_STRING,  # COLUMN_URI
                               GObject.TYPE_BOOLEAN, # COLUMN_SEPARATOR
                               GObject.TYPE_BOOLEAN, # COLUMN_CUSTOM
                               GObject.TYPE_PYOBJECT)# COLUMN_MIRROR
    self.treeview.set_row_separator_func(is_separator, None)
    self.model_sort = Gtk.TreeModelSort(model=self.model)

    self.distro = distro

    self.treeview.set_model(self.model_sort)
    # the cell renderer for the mirror uri
    self.renderer_mirror = Gtk.CellRendererText()
    self.renderer_mirror.connect('edited', 
                                 self.on_edited_custom_mirror, 
                                 self.model)
    # the visible column that holds the mirror uris
    self.column_mirror = Gtk.TreeViewColumn("URI", 
                                            self.renderer_mirror, 
                                            text=COLUMN_URI)
    self.treeview.append_column(self.column_mirror)

    # used to find the corresponding iter of a location
    map_loc = {}
    patriot = None
    model = self.treeview.get_model().get_model()
    # at first add all custom mirrors and a separator
    if len(self.custom_mirrors) > 0:
        for mirror in self.custom_mirrors:
            model.append(None, [mirror, False, True, None])
            self.column_mirror.add_attribute(self.renderer_mirror, 
                                             "editable", 
                                             COLUMN_CUSTOM)
        model.append(None, [None, True, False, None])
    # secondly add all official mirrors
    for hostname in self.distro.source_template.mirror_set.keys():
        mirror = self.distro.source_template.mirror_set[hostname]
        if mirror.location in map_loc:
            model.append(map_loc[mirror.location],
                         [hostname, False, False, mirror])
        elif mirror.location != None:
            parent = model.append(None, 
                                  [self.country_info.get_country_name(mirror.location), False, False, None])
            if mirror.location == self.country_info.code and patriot == None:
                patriot = parent
            model.append(parent, [hostname, False, False, mirror]),
            map_loc[mirror.location] = parent
        else:
            model.append(None, [hostname, False, False, mirror])
    # Scroll to the local mirror set
    if patriot != None:
        path_sort = self.model_sort.get_path(self.model_sort.convert_child_iter_to_iter(patriot)[1])
        self.treeview.expand_row(path_sort, False)
        self.treeview.set_cursor(path_sort, None, False)
        self.treeview.scroll_to_cell(path_sort, use_align=True, row_align=0.5)
    # set the sort function, this will also trigger a sort
    self.model_sort.set_default_sort_func(sort_mirrors, None)
    def __init__(self, parent, datadir, distro, custom_mirrors):
        """
    Initialize the dialog that allows to choose a custom or official mirror
    """
        QDialog.__init__(self, parent)
        uic.loadUi("%s/designer/dialog_mirror.ui" % datadir, self)
        self.parent = parent

        self.custom_mirrors = custom_mirrors

        self.country_info = CountryInformation()

        self.button_choose = self.buttonBox.button(QDialogButtonBox.Ok)
        self.button_choose.setEnabled(False)
        self.button_cancel = self.buttonBox.button(QDialogButtonBox.Cancel)
        self.distro = distro

        self.treeview.setColumnCount(1)
        self.treeview.setHeaderLabels([_("Mirror")])

        # used to find the corresponding iter of a location
        map_loc = {}
        patriot = None
        """ no custom yet
    # at first add all custom mirrors and a separator
    if len(self.custom_mirrors) > 0:
        for mirror in self.custom_mirrors:

            model.append(None, [mirror, False, True, None])
            self.column_mirror.add_attribute(self.renderer_mirror, 
                                             "editable", 
                                             COLUMN_CUSTOM)
        model.append(None, [None, True, False, None])
    """
        self.mirror_map = {}
        # secondly add all official mirrors
        for hostname in self.distro.source_template.mirror_set.keys():
            mirror = self.distro.source_template.mirror_set[hostname]
            if map_loc.has_key(mirror.location):  # a mirror in a country
                QTreeWidgetItem(map_loc[mirror.location], [hostname])
                self.mirror_map[hostname] = mirror
            elif mirror.location != None:  # a country new to the list
                country = self.country_info.get_country_name(mirror.location)
                parent = QTreeWidgetItem([unicode(country, 'utf-8')])
                self.mirror_map[country] = None
                self.treeview.addTopLevelItem(parent)
                QTreeWidgetItem(parent, [hostname])
                self.mirror_map[hostname] = mirror
                if mirror.location == self.country_info.code and patriot == None:
                    patriot = parent
                map_loc[mirror.location] = parent
            else:  # a mirror without country
                item = QTreeWidgetItem([hostname])
                self.treeview.addTopLevelItem(item)
        # Scroll to the local mirror set
        if patriot != None:
            self.treeview.scrollToItem(patriot)
        self.treeview.sortItems(0, Qt.AscendingOrder)
        self.connect(self.treeview,
                     SIGNAL("itemClicked(QTreeWidgetItem*, int)"),
                     self.on_treeview_mirrors_cursor_changed)
        self.connect(self.button_find_server, SIGNAL("clicked()"),
                     self.on_button_test_clicked)
        self.edit_buttons_frame.hide()  ##FIXME not yet implemented
Example #3
0
    def __init__(self, parent, datadir, distro, custom_mirrors):
        """
    Initialize the dialog that allows to choose a custom or official mirror
    """
        def is_separator(model, iter, data=None):
            return model.get_value(iter, COLUMN_SEPARATOR)

        self.custom_mirrors = custom_mirrors

        self.country_info = CountryInformation()

        self.gladexml = gtk.glade.XML("%s/glade/dialogs.glade" %\
                                      datadir)
        self.gladexml.signal_autoconnect(self)
        self.dialog = self.gladexml.get_widget("dialog_mirror")
        self.dialog.set_transient_for(parent)
        self.dialog_test = self.gladexml.get_widget("dialog_mirror_test")
        self.dialog_test.set_transient_for(self.dialog)
        self.distro = distro
        self.treeview = self.gladexml.get_widget("treeview_mirrors")
        self.button_edit = self.gladexml.get_widget("button_mirror_edit")
        self.button_remove = self.gladexml.get_widget("button_mirror_remove")
        self.button_choose = self.gladexml.get_widget("button_mirror_choose")
        self.button_cancel = self.gladexml.get_widget("button_test_cancel")
        self.label_test = self.gladexml.get_widget("label_test_mirror")
        self.progressbar_test = self.gladexml.get_widget(
            "progressbar_test_mirror")
        self.combobox = self.gladexml.get_widget("combobox_mirror_proto")
        self.progress = self.gladexml.get_widget("progressbar_test_mirror")
        self.label_action = self.gladexml.get_widget("label_test_mirror")

        # store each proto and its dir
        model_proto = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        self.combobox.set_model(model_proto)

        self.model = gtk.TreeStore(
            gobject.TYPE_STRING,  # COLUMN_URI
            gobject.TYPE_BOOLEAN,  # COLUMN_SEPARATOR
            gobject.TYPE_BOOLEAN,  # COLUMN_CUSTOM
            gobject.TYPE_PYOBJECT)  # COLUMN_MIRROR
        self.treeview.set_row_separator_func(is_separator)
        self.model_sort = gtk.TreeModelSort(self.model)
        self.model_sort.set_default_sort_func(sort_mirrors)

        self.distro = distro

        self.treeview.set_model(self.model_sort)
        # the cell renderer for the mirror uri
        self.renderer_mirror = gtk.CellRendererText()
        self.renderer_mirror.connect('edited', self.on_edited_custom_mirror,
                                     self.model)
        # the visible column that holds the mirror uris
        self.column_mirror = gtk.TreeViewColumn("URI",
                                                self.renderer_mirror,
                                                text=COLUMN_URI)
        self.treeview.append_column(self.column_mirror)

        # used to find the corresponding iter of a location
        map_loc = {}
        patriot = None
        model = self.treeview.get_model().get_model()
        # at first add all custom mirrors and a separator
        if len(self.custom_mirrors) > 0:
            for mirror in self.custom_mirrors:
                model.append(None, [mirror, False, True, None])
                self.column_mirror.add_attribute(self.renderer_mirror,
                                                 "editable", COLUMN_CUSTOM)
            model.append(None, [None, True, False, None])
        # secondly add all official mirrors
        for hostname in self.distro.source_template.mirror_set.keys():
            mirror = self.distro.source_template.mirror_set[hostname]
            if map_loc.has_key(mirror.location):
                model.append(map_loc[mirror.location],
                             [hostname, False, False, mirror])
            elif mirror.location != None:
                parent = model.append(None, [
                    self.country_info.get_country_name(mirror.location), False,
                    False, None
                ])
                if mirror.location == self.country_info.code and patriot == None:
                    patriot = parent
                model.append(parent, [hostname, False, False, mirror]),
                map_loc[mirror.location] = parent
            else:
                model.append(None, [hostname, False, False, mirror])
        # Scroll to the local mirror set
        if patriot != None:
            path_sort = self.model_sort.get_path(
                self.model_sort.convert_child_iter_to_iter(None, patriot))
            self.treeview.expand_row(path_sort, False)
            self.treeview.set_cursor(path_sort)
            self.treeview.scroll_to_cell(path_sort,
                                         use_align=True,
                                         row_align=0.5)