From 1185a1b9eba94cf6716ab177ac2dc63668770b93 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Wed, 18 Jun 2008 10:50:12 +0100 Subject: [PATCH] Split AppList out from AppListBox This allows the AppListBox to manage other lists of applications, such as the list of plugins of an application, not just the list of applications on the menu. --- zeroinstall/gtkui/applistbox.py | 32 ++++++++++++++++++++++++++------ zeroinstall/gtkui/desktop.py | 4 ++-- zeroinstall/gtkui/xdgutils.py | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/zeroinstall/gtkui/applistbox.py b/zeroinstall/gtkui/applistbox.py index 631371a..602007f 100644 --- a/zeroinstall/gtkui/applistbox.py +++ b/zeroinstall/gtkui/applistbox.py @@ -12,13 +12,35 @@ from zeroinstall.gtkui import icon, xdgutils def _pango_escape(s): return s.replace('&', '&').replace('<', '<') +class AppList: + """A list of applications which can be displayed in an L{AppListBox}. + For example, a program might implement this to display a list of plugins. + This default implementation lists applications in the freedesktop.org menus. + """ + def get_apps(self): + """Return a list of application URIs.""" + self.apps = xdgutils.discover_existing_apps() + return self.apps.keys() + + def remove_app(self, uri): + """Remove this application from the list.""" + path = self.apps[uri] + os.unlink(path) + class AppListBox: """A dialog box which lists applications already added to the menus.""" ICON, URI, NAME, MARKUP = range(4) - def __init__(self, iface_cache): + def __init__(self, iface_cache, app_list): + """Constructor. + @param iface_cache: used to find extra information about programs + @type iface_cache: L{zeroinstall.injector.iface_cache.IfaceCache} + @param app_list: used to list or remove applications + @type app_list: L{AppList} + """ gladefile = os.path.join(os.path.dirname(__file__), 'desktop.glade') self.iface_cache = iface_cache + self.app_list = app_list widgets = gtk.glade.XML(gladefile, 'applist') self.window = widgets.get_widget('applist') @@ -80,11 +102,10 @@ class AppListBox: self.window.connect('response', response) def populate_model(self): - self.apps = xdgutils.discover_existing_apps() model = self.model model.clear() - for uri in self.apps: + for uri in self.app_list.get_apps(): itr = model.append() model[itr][AppListBox.URI] = uri @@ -138,11 +159,10 @@ class AppListBox: resp = box.run() box.destroy() if resp == gtk.RESPONSE_OK: - path = self.apps[uri] try: - os.unlink(path) + self.app_list.remove_app(uri) except Exception, ex: - box = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Failed to remove %s: %s" % (path, ex)) + box = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Failed to remove %s: %s" % (name, ex)) box.run() box.destroy() self.populate_model() diff --git a/zeroinstall/gtkui/desktop.py b/zeroinstall/gtkui/desktop.py index 5593a70..90ed80a 100644 --- a/zeroinstall/gtkui/desktop.py +++ b/zeroinstall/gtkui/desktop.py @@ -51,9 +51,9 @@ def main(command_args): import gtk if options.manage: - from zeroinstall.gtkui.applistbox import AppListBox + from zeroinstall.gtkui.applistbox import AppListBox, AppList from zeroinstall.injector.iface_cache import iface_cache - box = AppListBox(iface_cache) + box = AppListBox(iface_cache, AppList()) else: from zeroinstall.gtkui.addbox import AddBox box = AddBox(interface_uri) diff --git a/zeroinstall/gtkui/xdgutils.py b/zeroinstall/gtkui/xdgutils.py index 7fa6c0b..2a5546d 100644 --- a/zeroinstall/gtkui/xdgutils.py +++ b/zeroinstall/gtkui/xdgutils.py @@ -45,7 +45,7 @@ def add_to_menu(iface, icon_path, category): raise SafeException('Failed to run xdg-desktop-menu (error code %d)' % status) def discover_existing_apps(): - """Search through the configured XDG datadirs looking for .desktop files created by us. + """Search through the configured XDG datadirs looking for .desktop files created by L{add_to_menu}. @return: a map from application URIs to .desktop filenames""" already_installed = {} for d in basedir.load_data_paths('applications'): -- 2.11.4.GIT