--- SoftwarePropertiesGtk.py.orig 2012-04-25 19:46:07.000000000 +0000 +++ SoftwarePropertiesGtk.py 2012-05-08 21:44:33.510763323 +0000 @@ -76,6 +76,12 @@ dialog.destroy() return False +# using this often, so defining it here. +def permission_denied_dialog(parent_window): + error(parent_window, + "Authorization failed.", + "Software sources can't be changed without permission.") + class SoftwarePropertiesGtk(SoftwareProperties,SimpleGtkbuilderApp): def __init__(self, datadir=None, options=None, file=None, parent=None): @@ -444,8 +450,12 @@ elif index == 2: # Download and install automatically state = softwareproperties.UPDATE_INST_SEC # only set if something actually changed - if state != self.get_update_automation_level(): - self.backend.SetUpdateAutomationLevel(state) + try: + if state != self.get_update_automation_level(): + self.backend.SetUpdateAutomationLevel(state) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def set_other_update_automation_level(self, widget): """Set the other update automation level to the given value via gconf""" @@ -463,7 +473,11 @@ """ set the release upgrades policy """ #print "on_combobox_release_upgrades_changed()" i = combobox.get_active() - self.backend.SetReleaseUpgradesPolicy(i) + try: + self.backend.SetReleaseUpgradesPolicy(i) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def on_combobox_server_changed(self, combobox): """ @@ -476,19 +490,24 @@ iter = combobox.get_active_iter() uri = server_store.get_value(iter, 1) name = server_store.get_value(iter, 0) - if name == _("Other..."): - dialog = DialogMirror(self.window_main, - self.datadir, - self.distro, - self.custom_mirrors) - res = dialog.run() - if res != None: - self.backend.ChangeMainDownloadServer(res) - else: - combobox.set_active(self.active_server) - elif uri != None and len(self.distro.used_servers) > 0: - self.active_server = combobox.get_active() - self.backend.ChangeMainDownloadServer(uri) + try: + if name == _("Other..."): + dialog = DialogMirror(self.window_main, + self.datadir, + self.distro, + self.custom_mirrors) + res = dialog.run() + if res != None: + self.backend.ChangeMainDownloadServer(res) + else: + combobox.set_active(self.active_server) + elif uri != None and len(self.distro.used_servers) > 0: + self.active_server = combobox.get_active() + self.backend.ChangeMainDownloadServer(uri) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) + # mvo: is this still needed? #else: # self.distro.default_server = uri @@ -498,48 +517,68 @@ Sync the components of all main sources (excluding cdroms), child sources and source code sources """ - if checkbutton.get_active() == True: - self.backend.EnableComponent(comp) - else: - self.backend.DisableComponent(comp) + try: + if checkbutton.get_active() == True: + self.backend.EnableComponent(comp) + else: + self.backend.DisableComponent(comp) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def on_checkbutton_child_toggled(self, checkbutton, template): """ Enable or disable a child repo of the distribution main repository """ - if checkbutton.get_active() == False: - self.backend.DisableChildSource(template.name) - else: - self.backend.EnableChildSource(template.name) + try: + if checkbutton.get_active() == False: + self.backend.DisableChildSource(template.name) + else: + self.backend.EnableChildSource(template.name) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def on_checkbutton_source_code_toggled(self, checkbutton): """ Disable or enable the source code for all sources """ - if checkbutton.get_active() == True: - self.backend.EnableSourceCodeSources() - else: - self.backend.DisableSourceCodeSources() + try: + if checkbutton.get_active() == True: + self.backend.EnableSourceCodeSources() + else: + self.backend.DisableSourceCodeSources() + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def on_checkbutton_popcon_toggled(self, widget): """ The user clicked on the popcon paritipcation button """ # only trigger the backend if something actually changed do_popcon = self.get_popcon_participation() if widget.get_active() != do_popcon: - self.backend.SetPopconPariticipation(widget.get_active()) + try: + self.backend.SetPopconPariticipation(widget.get_active()) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def open_file(self, file): """Show a confirmation for adding the channels of the specified file""" - dialog = DialogAddSourcesList(self.window_main, - self.sourceslist, - self.render_source, - self.get_comparable, - self.datadir, - file) - (res, new_sources) = dialog.run() - if res == RESPONSE_REPLACE: - self.sourceslist.list = [] - if res in (RESPONSE_ADD, RESPONSE_REPLACE): - for source in new_sources: - self.backend.AddSourceFromLine(str(source)) + try: + dialog = DialogAddSourcesList(self.window_main, + self.sourceslist, + self.render_source, + self.get_comparable, + self.datadir, + file) + (res, new_sources) = dialog.run() + if res == RESPONSE_REPLACE: + self.sourceslist.list = [] + if res in (RESPONSE_ADD, RESPONSE_REPLACE): + for source in new_sources: + self.backend.AddSourceFromLine(str(source)) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def on_sources_drag_data_received(self, widget, context, x, y, selection, target_type, timestamp): @@ -635,7 +674,11 @@ #FIXME cdroms need to disable the comps in the childs and sources iter = store.get_iter((int(path),)) source_entry = store.get_value(iter, STORE_SOURCE) - self.backend.ToggleSourceUse(str(source_entry)) + try: + self.backend.ToggleSourceUse(str(source_entry)) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def init_keys(self): """Setup the user interface parts needed for the key handling""" @@ -690,7 +733,11 @@ def on_button_revert_clicked(self, button): """Restore the source list from the startup of the dialog""" - self.backend.Revert() + try: + self.backend.Revert() + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) if self.settings: self.settings.set_int("regular-auto-launch-interval", self.initial_auto_launch) self.show_auto_update_level() @@ -771,7 +818,11 @@ i = self.combobox_update_interval.get_active() if i != -1: value = self.combobox_interval_mapping[i] - self.backend.SetUpdateInterval(value) + try: + self.backend.SetUpdateInterval(value) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def on_add_clicked(self, widget): """Show a dialog that allows to enter the apt line of a to be used repo""" @@ -779,7 +830,11 @@ self.datadir, self.distro) line = dialog.run() if line != None: - self.backend.AddSourceFromLine(line) + try: + self.backend.AddSourceFromLine(line) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def on_edit_clicked(self, widget): """Show a dialog to edit an ISV source""" @@ -791,8 +846,12 @@ dialog = DialogEdit(self.window_main, self.sourceslist, old_source_entry, self.datadir) if dialog.run() == Gtk.ResponseType.OK: - self.backend.ReplaceSourceEntry(str(old_source_entry), - str(dialog.new_source_entry)) + try: + self.backend.ReplaceSourceEntry(str(old_source_entry), + str(dialog.new_source_entry)) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) # FIXME:outstanding from merge def on_isv_source_activated(self, treeview, path, column): @@ -829,7 +888,11 @@ iter = model.get_iter(path) if iter: source_entry = model.get_value(iter, LIST_ENTRY_OBJ) - self.backend.RemoveSource(str(source_entry)) + try: + self.backend.RemoveSource(str(source_entry)) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def add_key_clicked(self, widget): """Provide a file chooser that allows to add the gnupg of a trusted @@ -845,11 +908,15 @@ res = chooser.run() chooser.hide() if res == Gtk.ResponseType.ACCEPT: - if not self.backend.AddKey(chooser.get_filename()): - error(self.window_main, - _("Error importing selected file"), - _("The selected file may not be a GPG key file " \ - "or it might be corrupt.")) + try: + if not self.backend.AddKey(chooser.get_filename()): + error(self.window_main, + _("Error importing selected file"), + _("The selected file may not be a GPG key file " \ + "or it might be corrupt.")) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def remove_key_clicked(self, widget): """Remove a trusted software vendor key""" @@ -858,15 +925,23 @@ if a_iter == None: return key = model.get_value(a_iter,0) - if not self.backend.RemoveKey(key[:8]): - error(self.main, - _("Error removing the key"), - _("The key you selected could not be removed. " - "Please report this as a bug.")) + try: + if not self.backend.RemoveKey(key[:8]): + error(self.main, + _("Error removing the key"), + _("The key you selected could not be removed. " + "Please report this as a bug.")) + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def on_restore_clicked(self, widget): """Restore the original keys""" - self.backend.UpdateKeys() + try: + self.backend.UpdateKeys() + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main) def on_delete_event(self, widget, args): """Close the window if requested""" @@ -884,4 +959,8 @@ def on_button_add_cdrom_clicked(self, widget): """ when a cdrom is requested for adding """ - self.backend.AddCdromSource() + try: + self.backend.AddCdromSource() + except dbus.DBusException as e: + if e._dbus_error_name == 'com.ubuntu.SoftwareProperties.PermissionDeniedByPolicy': + permission_denied_dialog(self.window_main)