Example #1
0
    def create_spinbutton(self, name, range,
                          from_daemon_func=None,
                          to_daemon_func=None):
        def spinbutton_value_changed_cb(sb, p, n, cfunc):
            value = sb.get_value_as_int()

            if cfunc:
                value = cfunc(value)

            p.prefs[n]["value"] = value
            self.enqueue(n)

        min, max = range

        value = self.prefs[name]["value"]

        if from_daemon_func:
            value = from_daemon_func(value)

        adj = gtk.Adjustment(value=value,
                             lower=min, upper=max,
                             step_incr=1, page_incr=5)
                             
        spin = gtk.SpinButton(adjustment=adj, digits=0)
        if rcd_util.check_server_permission("superuser"):
            spin.set_update_policy(gtk.UPDATE_IF_VALID)
            spin.connect("value-changed", spinbutton_value_changed_cb,
                         self, name, to_daemon_func)
        else:
            spin.set_sensitive(0)

        self.handled_prefs.append(name)

        return spin
Example #2
0
def can_perform_action_single(pkg, action):
    if not pkg:
        return 0

    pkg_action = package_action(pkg)
    if pkg_action == action:
        return 0

    if action == NO_ACTION and \
       pkg_action != NO_ACTION:
        return 1

    if not can_set_action(pkg):
        return 0

    if action == TO_BE_REMOVED:
        if not can_remove_package(pkg):
            return 0
        if red_packagearray.pkg_is_installed(pkg) or \
           red_packagearray.pkg_is_name_installed(pkg) and \
           rcd_util.check_server_permission("remove"):
            return 1
        else:
            return 0

    if action == TO_BE_INSTALLED:
        if red_packagearray.pkg_is_installed(pkg):
            return 0

        if not red_packagearray.pkg_is_name_installed(pkg) and \
           rcd_util.check_server_permission("install"):
            return 1

        elif (red_packagearray.pkg_is_upgrade(pkg) or \
              red_packagearray.pkg_is_downgrade(pkg)) and \
              rcd_util.check_server_permission("upgrade"):
            return 1
        else:
            return 0

    return 0
Example #3
0
def can_perform_action_single(pkg, action):
    if not pkg:
        return 0

    pkg_action = package_action(pkg)
    if pkg_action == action:
        return 0

    if action == NO_ACTION and \
       pkg_action != NO_ACTION:
        return 1

    if not can_set_action(pkg):
        return 0

    if action == TO_BE_REMOVED:
        if not can_remove_package(pkg):
            return 0
        if red_packagearray.pkg_is_installed(pkg) or \
           red_packagearray.pkg_is_name_installed(pkg) and \
           rcd_util.check_server_permission("remove"):
            return 1
        else:
            return 0

    if action == TO_BE_INSTALLED:
        if red_packagearray.pkg_is_installed(pkg):
            return 0
        
        if not red_packagearray.pkg_is_name_installed(pkg) and \
           rcd_util.check_server_permission("install"):
            return 1

        elif (red_packagearray.pkg_is_upgrade(pkg) or \
              red_packagearray.pkg_is_downgrade(pkg)) and \
              rcd_util.check_server_permission("upgrade"):
            return 1
        else:
            return 0

    return 0
Example #4
0
    def create_checkbox(self, name, label):
        def checkbox_toggled_cb(cb, p, n):
            p.prefs[n]["value"] = ximian_xmlrpclib.Boolean(cb.get_active())
            self.enqueue(n)

        cb = gtk.CheckButton(label)
        cb.set_active((self.prefs[name]["value"] and 1) or 0)
        if rcd_util.check_server_permission("superuser"):
            cb.connect("toggled", checkbox_toggled_cb, self, name)
        else:
            cb.set_sensitive(0)

        self.handled_prefs.append(name)

        return cb
Example #5
0
    def __init__(self):
        gtk.ScrolledWindow.__init__(self)

        global model
        if not model:
            model = red_channelmodel.ChannelModel()

        view = self.make_channel_view()

        view.show_all()
        view.set_sensitive(rcd_util.check_server_permission("subscribe"))

        self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.set_shadow_type(gtk.SHADOW_IN)
        self.add(view)
Example #6
0
    def __init__(self):
        gtk.ScrolledWindow.__init__(self)

        global model
        if not model:
            model = red_channelmodel.ChannelModel()

        view = self.make_channel_view()

        view.show_all()
        view.set_sensitive(rcd_util.check_server_permission("subscribe"))

        self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.set_shadow_type(gtk.SHADOW_IN)
        self.add(view)
Example #7
0
    def create_entry(self, name):
        def entry_focus_out_cb(e, ev, p, n):
            p.prefs[n]["value"] = e.get_text()
            self.enqueue(n)
        
        entry = gtk.Entry()
        entry.set_text(self.prefs[name]["value"])
        if rcd_util.check_server_permission("superuser"):
            entry.set_activates_default(1)
            entry.connect("focus_out_event", entry_focus_out_cb, self, name)
        else:
            entry.set_sensitive(0)

        self.handled_prefs.append(name)

        return entry
Example #8
0
    def sensitize(self):
        is_superuser = rcd_util.check_server_permission("superuser")
        selected_user = self.opt.get_selected_user()
        me = (selected_user and selected_user.name_get() == \
              rcd_util.get_current_user())

        self.__add_button.set_sensitive(is_superuser)

        if selected_user:
            self.opt.set_sensitive(1)
            self.__remove_button.set_sensitive(is_superuser)
            self.__password_part.set_sensitive(is_superuser or me)
            self.__privileges_part.set_sensitive(is_superuser)
        else:
            self.opt.set_sensitive(0)
            self.__remove_button.set_sensitive(0)
            self.__password_part.set_sensitive(0)
            self.__privileges_part.set_sensitive(0)
Example #9
0
    def sensitize(self):
        is_superuser = rcd_util.check_server_permission("superuser")
        selected_user = self.opt.get_selected_user()
        me = (selected_user and selected_user.name_get() == \
              rcd_util.get_current_user())

        self.__add_button.set_sensitive(is_superuser)

        if selected_user:
            self.opt.set_sensitive(1)
            self.__remove_button.set_sensitive(is_superuser)
            self.__password_part.set_sensitive(is_superuser or me)
            self.__privileges_part.set_sensitive(is_superuser)
        else:
            self.opt.set_sensitive(0)
            self.__remove_button.set_sensitive(0)
            self.__password_part.set_sensitive(0)
            self.__privileges_part.set_sensitive(0)
Example #10
0
    def build(self):
        unique_prefs = [self.prefs[x] for x in self.prefs
                        if not x in self.view.all_handled_prefs()]
        
        model = PrefsModel(unique_prefs, None)
        view = red_thrashingtreeview.TreeView(model)
        view.set_sensitive(rcd_util.check_server_permission("superuser"))

        col = gtk.TreeViewColumn(_("Description"),
                                 gtk.CellRendererText(),
                                 text=COLUMN_DESCRIPTION)
        view.append_column(col)

        r = CellRendererPref()

        def activated_cb(r, pref, page):
            opp = ximian_xmlrpclib.Boolean(not pref["value"])

            page.prefs[pref["name"]]["value"] = opp
            page.enqueue(pref["name"])

        r.connect("activated", activated_cb, self)

        def editing_done_cb(r, pref, value, page):
            try:
                v = int(value)
            except ValueError:
                v = value

            # Don't set the pref if we didn't change anything.
            if v == pref.get("value"):
                return

            page.prefs[pref["name"]]["value"] = v
            page.enqueue(pref["name"])

        r.connect("editing_done", editing_done_cb, self)

        col = gtk.TreeViewColumn(_("Value"), r, value=COLUMN_VALUE)
        view.append_column(col)

        self.pack_start(view, expand=1, fill=1, padding=12)
Example #11
0
 def install_file_sensitive_fn():
     return rcd_util.check_server_permission("install")
Example #12
0
 def install_url_sensitive_fn():
     return rcd_util.check_server_permission("install") and \
            red_installfiles.can_install_remote()
Example #13
0
 def mount_sensitive_fn():
     return rcd_util.check_server_permission("superuser")
Example #14
0
        def cache_cleanup_toggled_cb(cb, p):
            sensitive = cb.get_active() and \
                        rcd_util.check_server_permission("superuser")

            p.cache_size_spin.set_sensitive(sensitive)
            p.cache_age_spin.set_sensitive(sensitive)
Example #15
0
    def build(self):
        vbox = gtk.VBox(spacing=18)
        self.pack_start(vbox, expand=0, fill=0, padding=12)

        hbox = gtk.HBox(spacing=6)
        vbox.pack_start(hbox, expand=0, fill=0)

        label = gtk.Label(_("Interval to refresh catalog data (in hours):"))
        hbox.pack_start(label, expand=0, fill=0)

        refresh_spin = self.create_spinbutton("refresh-interval",
                                              (1, 24),
                                              lambda x:x / 3600 or 1,
                                              lambda x:x * 3600)
        hbox.pack_start(refresh_spin, expand=0, fill=0)


        # Packages section
        section, content = self.create_section(_("Packages"))
        vbox.pack_start(section, expand=0, fill=0)

        table = gtk.Table(rows=3, columns=2)
        table.set_row_spacings(6)
        table.set_col_spacings(6)
        content.pack_start(table, expand=0, fill=0)

        self.signed_check = self.create_checkbox("require-signatures",
                                                 _("Require package "
                                                   "signatures"))
        table.attach(self.signed_check, 0, 2, 0, 1,
                     xoptions=gtk.FILL)

        label = gtk.Label(_("Maximum number of packages to download at once:"))
        label.set_alignment(0.0, 0.5)
        table.attach(label, 0, 1, 1, 2, xoptions=gtk.FILL)

        self.max_download_spin = self.create_spinbutton("max-downloads",
                                                        (0, 20))
        table.attach(self.max_download_spin, 1, 2, 1, 2,
                     xoptions=gtk.FILL)

        rollback_check = self.create_checkbox("rollback",
                                              _("Enable package rollback"))
        table.attach(rollback_check, 0, 2, 2, 3, xoptions=gtk.FILL)

        # Proxy section - requires superuser
        section, content = self.create_section(_("Proxy"))
        vbox.pack_start(section, expand=0, fill=0)

        if rcd_util.check_server_permission("superuser"):
            table = gtk.Table(rows=4, columns=2)
            table.set_row_spacings(6)
            table.set_col_spacings(6)
            content.pack_start(table, expand=0, fill=0)

            self.use_proxy_check = gtk.CheckButton(_("Use a proxy"))
            table.attach(self.use_proxy_check, 0, 2, 0, 1,
                         xoptions=gtk.FILL)

            label = gtk.Label(_("Proxy URL:"))
            label.set_alignment(0.0, 0.5)
            table.attach(label, 0, 1, 1, 2, xoptions=gtk.FILL)

            self.proxy_url_entry = self.create_entry("proxy-url")
            table.attach(self.proxy_url_entry, 1, 2, 1, 2)

            label = gtk.Label(_("Username:"******"proxy-username")
            table.attach(self.proxy_username_entry, 1, 2, 2, 3)

            label = gtk.Label(_("Password:"******"proxy-password")
            self.proxy_password_entry.set_visibility(0)
            table.attach(self.proxy_password_entry, 1, 2, 3, 4)

            # Have to wait for the above widgets to be created.
            def use_proxy_toggled_cb(cb, p):
                sensitive = cb.get_active()

                p.proxy_url_entry.set_sensitive(sensitive)
                p.proxy_username_entry.set_sensitive(sensitive)
                p.proxy_password_entry.set_sensitive(sensitive)

                if not sensitive:
                    p.prefs["proxy-url"]["value"] = ""
                    p.prefs["proxy-username"]["value"] = ""
                    p.prefs["proxy-password"]["value"] = ""
                else:
                    p.prefs["proxy-url"]["value"] = p.proxy_url_entry.get_text()
                    p.prefs["proxy-username"]["value"] = p.proxy_username_entry.get_text()
                    p.prefs["proxy-password"]["value"] = p.proxy_password_entry.get_text()

                p.enqueue("proxy-url")
                p.enqueue("proxy-username")
                p.enqueue("proxy-password")

            self.use_proxy_check.connect("toggled", use_proxy_toggled_cb, self)
            self.use_proxy_check.set_active((self.prefs["proxy-url"]["value"] and 1) or 0)
            self.use_proxy_check.toggled()
        else:
            label = gtk.Label(_("You do not have permissions to view "
                                "proxy settings"))
            label.set_alignment(0.0, 0.5)
            content.pack_start(label, expand=0, fill=0)
Example #16
0
 def activate_sensitive_fn():
     return rcd_util.check_server_permission("superuser") \
            and rcd_util.get_all_services()
Example #17
0
 def unmount_sensitive_fn():
     return rcd_util.check_server_permission("superuser") and \
            red_mount.has_mounted_channels()
Example #18
0
 def activate_sensitive_fn():
     return rcd_util.check_server_permission("superuser") \
            and rcd_util.get_all_services()
Example #19
0
    def build(self):

        hbox = gtk.HBox()
        self.vbox.pack_start(hbox, expand=1, fill=1, padding=12)

        vbox = gtk.VBox()
        hbox.pack_start(vbox, expand=1, fill=1, padding=12)

        model = ServicesModel()
        self.view = red_thrashingtreeview.TreeView(model)

        col = gtk.TreeViewColumn(_("Name"),
                                 gtk.CellRendererText(),
                                 text=COLUMN_NAME)
        self.view.append_column(col)

        col = gtk.TreeViewColumn(_("URL"),
                                 gtk.CellRendererText(),
                                 text=COLUMN_URL)
        self.view.append_column(col)

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.set_shadow_type(gtk.SHADOW_IN)
        sw.add(self.view)
                                 
        vbox.pack_start(sw)

        bbox = gtk.HButtonBox()
        bbox.set_spacing(6)
        bbox.set_layout(gtk.BUTTONBOX_END)

        self.remove_button = gtk.Button(_("_Remove service"))
        self.remove_button_sensitize()
        self.remove_button.connect("clicked", lambda x:self.remove_service())
        bbox.pack_start(self.remove_button, expand=0, fill=0, padding=3)

        def tree_changed_cb(this):
            this.remove_button_sensitize()

        model.connect("changed",
                      lambda x,y:tree_changed_cb(y),
                      self)

        select = self.view.get_selection()
        select.connect("changed",
                       lambda x,y:tree_changed_cb(y),
                       self)

        button = gtk.Button(_("_Add service"))
        button.set_sensitive(rcd_util.check_server_permission("superuser"))
        button.connect("clicked", lambda x:self.add_service())
        bbox.pack_start(button, expand=0, fill=0, padding=3)

        vbox.pack_end(bbox, expand=0, fill=0, padding=6)

        self.vbox.show_all()

        button = self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
        button.grab_default()
        button.connect("clicked", lambda x:self.destroy())
Example #20
0
 def install_url_sensitive_fn():
     return rcd_util.check_server_permission("install") and \
            red_installfiles.can_install_remote()
Example #21
0
 def install_file_sensitive_fn():
     return rcd_util.check_server_permission("install")
Example #22
0
 def remove_button_sensitize(self):
     if rcd_util.check_server_permission("superuser") \
        and self.get_selected_service() is not None:
         self.remove_button.set_sensitive(1)
     else:
         self.remove_button.set_sensitive(0)
Example #23
0
    def build(self):
        vbox = gtk.VBox(spacing=18)
        self.pack_start(vbox, expand=0, fill=0, padding=12)

        content = gtk.VBox(spacing=6)
        vbox.pack_start(content, expand=0, fill=0)

        table = gtk.Table(rows=2, columns=2)
        table.set_row_spacings(6)
        table.set_col_spacings(6)
        content.pack_start(table, expand=0, fill=0)

        self.enable_cache_check = self.create_checkbox("cache-enabled",
                                                       _("Cache downloaded "
                                                         "packages and "
                                                         "metadata"))
        table.attach(self.enable_cache_check, 0, 2, 0, 1,
                     xoptions=gtk.FILL)

        label = gtk.Label(_("Location of cached data:"))
        label.set_alignment(0.0, 0.5)
        table.attach(label, 0, 1, 1, 2, xoptions=gtk.FILL)

        self.cache_dir_entry = self.create_entry("cache-directory")
        table.attach(self.cache_dir_entry, 1, 2, 1, 2)

        # Expiration section
        section, content = self.create_section(_("Expiration"))
        vbox.pack_start(section, expand=0, fill=0)

        self.cache_cleanup_check = self.create_checkbox("cache-cleanup-enabled",
                                                        _("Cache expires"))
        content.pack_start(self.cache_cleanup_check, expand=0, fill=0)

        hbox = gtk.HBox(spacing=6)
        content.pack_start(hbox, expand=0, fill=0)

        label = gtk.Label(_("Maximum age in days:"))
        label.set_alignment(0.0, 0.5)
        hbox.pack_start(label, expand=0, fill=1)

        self.cache_age_spin = self.create_spinbutton("max-cache-age",
                                                     (0, 1460))
        hbox.pack_start(self.cache_age_spin, expand=0, fill=1)

        hbox = gtk.HBox(spacing=6)
        content.pack_start(hbox, expand=0, fill=0)
        
        label = gtk.Label(_("Maximum size in MB:"))
        label.set_alignment(0.0, 0.5)
        hbox.pack_start(label, expand=0, fill=1)

        self.cache_size_spin = self.create_spinbutton("cache-max-size-in-mb",
                                                      (0, 100000))
        hbox.pack_start(self.cache_size_spin, expand=0, fill=1)

        hbox = gtk.HBox(spacing=6)
        vbox.pack_start(hbox, expand=0, fill=0)
        
        label = gtk.Label(_("Current cache size:"))
        label.set_alignment(0.0, 0.5)
        hbox.pack_start(label, expand=0, fill=1)

        self.cache_size_label = gtk.Label("")
        self.cache_size_label.set_alignment(0.0, 0.5)
        hbox.pack_start(self.cache_size_label, expand=0, fill=1)

        def flush_cache_cb(b):
            parent_window = self.get_toplevel()
            if not parent_window.flags() & gtk.TOPLEVEL:
                parent_window = None
                
            dialog = gtk.MessageDialog(parent_window,
                                       gtk.DIALOG_DESTROY_WITH_PARENT,
                                       gtk.MESSAGE_QUESTION,
                                       gtk.BUTTONS_YES_NO,
                                       _("Are you sure you want to delete "
                                         "the package files in your cache?"))
            response = dialog.run()
            dialog.destroy()

            if response != gtk.RESPONSE_YES:
                return
            
            def flush_cb(th, page):
                gtk.idle_add(page.update_cache_size_label)
            server = rcd_util.get_server_proxy()
            th = server.rcd.system.flush_cache()
            th.connect("ready", flush_cb, self)

        self.update_cache_size_label()

        button = gtk.Button(_("Empty Cache"))
        if rcd_util.check_server_permission("superuser"):
            button.connect("clicked", flush_cache_cb)
        else:
            button.set_sensitive(0)
        hbox.pack_start(button, expand=0, fill=1)

        # Have to do this after the other widgets are created
        def cache_cleanup_toggled_cb(cb, p):
            sensitive = cb.get_active() and \
                        rcd_util.check_server_permission("superuser")

            p.cache_size_spin.set_sensitive(sensitive)
            p.cache_age_spin.set_sensitive(sensitive)
                
        self.cache_cleanup_check.connect("toggled", cache_cleanup_toggled_cb,
                                         self)
        self.cache_cleanup_check.toggled()
Example #24
0
 def mount_sensitive_fn():
     return rcd_util.check_server_permission("superuser")
Example #25
0
 def unmount_sensitive_fn():
     return rcd_util.check_server_permission("superuser") and \
            red_mount.has_mounted_channels()