From e065ed970b01cd4d145466918921d592aeab952c Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 8 Sep 2009 12:58:19 +0200 Subject: GUI: added UI for global settings (just preview, not usable!) --- src/Gui/ABRTPlugin.py | 3 + src/Gui/CCDBusBackend.py | 13 +- src/Gui/CCMainWindow.py | 10 +- src/Gui/Makefile.am | 3 +- src/Gui/PluginList.py | 8 ++ src/Gui/PluginsSettingsDialog.py | 161 ++++++++++++++++++++++++ src/Gui/SettingsDialog.py | 161 ------------------------ src/Gui/ccgui.glade | 7 ++ src/Gui/settings.GtkBuilder | 260 ++++++++++++++++++++++++++++++++++++++- 9 files changed, 458 insertions(+), 168 deletions(-) create mode 100644 src/Gui/PluginsSettingsDialog.py delete mode 100644 src/Gui/SettingsDialog.py diff --git a/src/Gui/ABRTPlugin.py b/src/Gui/ABRTPlugin.py index da9c9e57..4a94e670 100644 --- a/src/Gui/ABRTPlugin.py +++ b/src/Gui/ABRTPlugin.py @@ -57,4 +57,7 @@ class PluginInfo(): def __str__(self): return self.Name + + def __getitem__(self, item): + return self.__dict__[item] diff --git a/src/Gui/CCDBusBackend.py b/src/Gui/CCDBusBackend.py index b0230bd6..8e09f6d1 100644 --- a/src/Gui/CCDBusBackend.py +++ b/src/Gui/CCDBusBackend.py @@ -171,10 +171,10 @@ class DBusManager(gobject.GObject): print "Started our job: %s" % job_id self.addJob(job_id) - def jobdone_cb(self, dest, job_id): + def jobdone_cb(self, dest, uuid): if self.uniq_name == dest: - print "Our job: %s is done." % job_id - dump = self.cc.GetJobResult(job_id) + print "Our job: %s is done." % uuid + dump = self.cc.GetJobResult(uuid) if dump: self.emit("analyze-complete", dump) else: @@ -219,7 +219,7 @@ class DBusManager(gobject.GObject): #for i in settings.keys(): # print i return settings - + def registerPlugin(self, plugin_name): return self.cc.RegisterPlugin(plugin_name) @@ -229,3 +229,8 @@ class DBusManager(gobject.GObject): def setPluginSettings(self, plugin_name, plugin_settings): return self.cc.SetPluginSettings(plugin_name, plugin_settings) + def getSettings(self): + return self.cc.GetSettings() + + def setSettings(self, settings): + return self.cc.SetSettings(settings) diff --git a/src/Gui/CCMainWindow.py b/src/Gui/CCMainWindow.py index e7472562..4fe07751 100644 --- a/src/Gui/CCMainWindow.py +++ b/src/Gui/CCMainWindow.py @@ -11,6 +11,7 @@ import CCDBusBackend from CC_gui_functions import * from CCDumpList import getDumpList, DumpList from CCReporterDialog import ReporterDialog +from PluginsSettingsDialog import PluginsSettingsDialog from SettingsDialog import SettingsDialog from CCReport import Report import ABRTExceptions @@ -108,6 +109,7 @@ class MainWindow(): self.wTree.get_widget("miQuit").connect("activate", self.on_bQuit_clicked) self.wTree.get_widget("miAbout").connect("activate", self.on_miAbout_clicked) self.wTree.get_widget("miPreferences").connect("activate", self.on_miPreferences_clicked) + self.wTree.get_widget("miSettings").connect("activate", self.on_miSettings_clicked) # connect handlers for daemon signals self.ccdaemon.connect("crash", self.on_data_changed_cb, None) self.ccdaemon.connect("analyze-complete", self.on_analyze_complete_cb, self.pBarWindow) @@ -133,9 +135,15 @@ class MainWindow(): dialog.hide() def on_miPreferences_clicked(self, widget): - dialog = SettingsDialog(self.window,self.ccdaemon) + dialog = PluginsSettingsDialog(self.window,self.ccdaemon) dialog.hydrate() dialog.show() + + def on_miSettings_clicked(self, widget): + dialog = SettingsDialog(self.window, self.ccdaemon) + dialog.hydrate() + dialog.show() + self.ccdaemon.getSettings() def warning_cb(self, daemon, message=None): # try to hide the progressbar, we dont really care if it was visible .. diff --git a/src/Gui/Makefile.am b/src/Gui/Makefile.am index 6435c1f0..8fea3946 100644 --- a/src/Gui/Makefile.am +++ b/src/Gui/Makefile.am @@ -5,7 +5,8 @@ bin_SCRIPTS = abrt-gui PYTHON_FILES = CCDBusBackend.py CCDumpList.py CCDump.py CC_gui_functions.py \ CCReporterDialog.py CCReport.py abrt_utils.py \ CCMainWindow.py CellRenderers.py ABRTExceptions.py \ - SettingsDialog.py ABRTPlugin.py PluginList.py PluginSettingsUI.py + SettingsDialog.py ABRTPlugin.py PluginList.py PluginSettingsUI.py \ + SettingsDialog.py GLADE_FILES = ccgui.glade report.glade settings.GtkBuilder dialogs.GtkBuilder diff --git a/src/Gui/PluginList.py b/src/Gui/PluginList.py index 591096bd..76bdf81e 100644 --- a/src/Gui/PluginList.py +++ b/src/Gui/PluginList.py @@ -33,6 +33,14 @@ class PluginInfoList(list): return else: print "db == None!" + + + def getEnabledPlugins(self): + return [x for x in self if x["Enabled"] == 'yes'] + + def getActionPlugins(self): + return [x for x in self if x["Enabled"] == 'yes' and x["Type"] == 'Action'] + __PFList = None diff --git a/src/Gui/PluginsSettingsDialog.py b/src/Gui/PluginsSettingsDialog.py new file mode 100644 index 00000000..b56f9d7c --- /dev/null +++ b/src/Gui/PluginsSettingsDialog.py @@ -0,0 +1,161 @@ +import sys +import gtk +from PluginList import getPluginInfoList, PluginInfoList +from CC_gui_functions import * +from PluginSettingsUI import PluginSettingsUI +from ABRTPlugin import PluginSettings, PluginInfo +from abrt_utils import _ + +class PluginsSettingsDialog: + def __init__(self, parent, daemon): + #print "Settings dialog init" + self.ccdaemon = daemon + self.builder = gtk.Builder() + builderfile = "%s%ssettings.GtkBuilder" % (sys.path[0],"/") + #print builderfile + try: + self.builder.add_from_file(builderfile) + except Exception, e: + print e + self.window = self.builder.get_object("wPluginsSettings") + if not self.window: + raise Exception(_("Can't load gui description for SettingsDialog!")) + #self.window.set_parent(parent) + + self.pluginlist = self.builder.get_object("tvSettings") + # cell_text, toggle_active, toggle_visible, group_name_visible, color, plugin + self.pluginsListStore = gtk.TreeStore(str, bool, bool, bool, str, object) + # set filter + self.modelfilter = self.pluginsListStore.filter_new() + self.modelfilter.set_visible_func(self.filter_plugins, None) + self.pluginlist.set_model(self.modelfilter) + # =============================================== + columns = [None]*1 + columns[0] = gtk.TreeViewColumn(_("Name")) + + # create list + for column in columns: + n = self.pluginlist.append_column(column) + column.cell = gtk.CellRendererText() + column.gray_background = gtk.CellRendererText() + column.pack_start(column.cell, True) + column.pack_start(column.gray_background, True) + column.set_attributes(column.cell, markup=(n-1), visible=2) + column.set_attributes(column.gray_background, visible=3, cell_background=4) + column.set_resizable(True) + + # toggle + group_name_renderer = gtk.CellRendererText() + toggle_renderer = gtk.CellRendererToggle() + toggle_renderer.set_property('activatable', True) + toggle_renderer.connect( 'toggled', self.on_enabled_toggled, self.pluginsListStore ) + column = gtk.TreeViewColumn(_('Enabled')) + column.pack_start(toggle_renderer, True) + column.pack_start(group_name_renderer, True) + column.add_attribute( toggle_renderer, "active", 1) + column.add_attribute( toggle_renderer, "visible", 2) + column.add_attribute( group_name_renderer, "visible", 3) + column.add_attribute( group_name_renderer, "markup", 0) + column.add_attribute( group_name_renderer, "cell_background", 4) + self.pluginlist.insert_column(column, 0) + + #connect signals + self.pluginlist.connect("cursor-changed", self.on_tvDumps_cursor_changed) + self.builder.get_object("bConfigurePlugin").connect("clicked", self.on_bConfigurePlugin_clicked, self.pluginlist) + self.builder.get_object("bClose").connect("clicked", self.on_bClose_clicked) + self.builder.get_object("bConfigurePlugin").set_sensitive(False) + + def on_enabled_toggled(self,cell, path, model): + plugin = model[path][model.get_n_columns()-1] + if plugin: + if model[path][1]: + #print "self.ccdaemon.UnRegisterPlugin(%s)" % (plugin.getName()) + self.ccdaemon.unRegisterPlugin(plugin.getName()) + # FIXME: create class plugin and move this into method Plugin.Enable() + plugin.Enabled = "no" + plugin.Settings = None + else: + #print "self.ccdaemon.RegisterPlugin(%s)" % (model[path][model.get_n_columns()-1]) + self.ccdaemon.registerPlugin(plugin.getName()) + # FIXME: create class plugin and move this into method Plugin.Enable() + plugin.Enabled = "yes" + plugin.Settings = PluginSettings(self.ccdaemon.getPluginSettings(plugin.getName())) + model[path][1] = not model[path][1] + + def filter_plugins(self, model, miter, data): + return True + def hydrate(self): + #print "settings hydrate" + self.pluginsListStore.clear() + try: + pluginlist = getPluginInfoList(self.ccdaemon, refresh=True) + except Exception, e: + print e + #gui_error_message("Error while loading plugins info, please check if abrt daemon is running\n %s" % e) + plugin_rows = {} + for plugin_type in PluginInfo.types.keys(): + it = self.pluginsListStore.append(None, ["%s" % (PluginInfo.types[plugin_type]),0 , 0, 1,"gray", None]) + plugin_rows[plugin_type] = it + for entry in pluginlist: + n = self.pluginsListStore.append(plugin_rows[entry.getType()],["%s\n%s" % (entry.getName(), entry.Description), entry.Enabled == "yes", 1, 0, "white", entry]) + self.pluginlist.expand_all() + + def dehydrate(self): + # we have nothing to save, plugin's does the work + pass + + def show(self): + self.window.show() + #if result == gtk.RESPONSE_APPLY: + # self.dehydrate() + #self.window.destroy() + #return result + + def on_bConfigurePlugin_clicked(self, button, pluginview): + pluginsListStore, path = pluginview.get_selection().get_selected_rows() + if not path: + self.builder.get_object("lDescription").set_label(_("Can't get plugin description")) + return + # this should work until we keep the row object in the last position + pluginfo = pluginsListStore.get_value(pluginsListStore.get_iter(path[0]), pluginsListStore.get_n_columns()-1) + if pluginfo: + try: + ui = PluginSettingsUI(pluginfo) + except Exception, e: + gui_error_message(_("Error while opening plugin settings UI: \n\n%s" % e)) + return + ui.hydrate() + response = ui.run() + if response == gtk.RESPONSE_APPLY: + ui.dehydrate() + if pluginfo.Settings: + try: + self.ccdaemon.setPluginSettings(pluginfo.getName(), pluginfo.Settings) + except Exception, e: + gui_error_message(_("Can't save plugin settings:\n %s", e)) + #for key, val in pluginfo.Settings.iteritems(): + # print "%s:%s" % (key, val) + elif response == gtk.RESPONSE_CANCEL: + pass + else: + print _("unknown response from settings dialog") + ui.destroy() + + def on_bClose_clicked(self, button): + self.window.destroy() + + def on_tvDumps_cursor_changed(self, treeview): + pluginsListStore, path = treeview.get_selection().get_selected_rows() + if not path: + self.builder.get_object("lDescription").set_label("No description") + return + # this should work until we keep the row object in the last position + pluginfo = pluginsListStore.get_value(pluginsListStore.get_iter(path[0]), pluginsListStore.get_n_columns()-1) + if pluginfo: + self.builder.get_object("lPluginAuthor").set_text(pluginfo.Email) + self.builder.get_object("lPluginVersion").set_text(pluginfo.Version) + self.builder.get_object("lPluginWebSite").set_text(pluginfo.WWW) + self.builder.get_object("lPluginName").set_text(pluginfo.Name) + self.builder.get_object("lPluginDescription").set_text(pluginfo.Description) + # print (pluginfo.Enabled == "yes" and pluginfo.GTKBuilder != "") + self.builder.get_object("bConfigurePlugin").set_sensitive(pluginfo != None and pluginfo.Enabled == "yes" and pluginfo.GTKBuilder != "") diff --git a/src/Gui/SettingsDialog.py b/src/Gui/SettingsDialog.py deleted file mode 100644 index 79dfad74..00000000 --- a/src/Gui/SettingsDialog.py +++ /dev/null @@ -1,161 +0,0 @@ -import sys -import gtk -from PluginList import getPluginInfoList, PluginInfoList -from CC_gui_functions import * -from PluginSettingsUI import PluginSettingsUI -from ABRTPlugin import PluginSettings, PluginInfo -from abrt_utils import _ - -class SettingsDialog: - def __init__(self, parent, daemon): - #print "Settings dialog init" - self.ccdaemon = daemon - self.builder = gtk.Builder() - builderfile = "%s%ssettings.GtkBuilder" % (sys.path[0],"/") - #print builderfile - try: - self.builder.add_from_file(builderfile) - except Exception, e: - print e - self.window = self.builder.get_object("wSettings") - if not self.window: - raise Exception(_("Can't load gui description for SettingsDialog!")) - #self.window.set_parent(parent) - - self.pluginlist = self.builder.get_object("tvSettings") - # cell_text, toggle_active, toggle_visible, group_name_visible, color, plugin - self.pluginsListStore = gtk.TreeStore(str, bool, bool, bool, str, object) - # set filter - self.modelfilter = self.pluginsListStore.filter_new() - self.modelfilter.set_visible_func(self.filter_plugins, None) - self.pluginlist.set_model(self.modelfilter) - # =============================================== - columns = [None]*1 - columns[0] = gtk.TreeViewColumn(_("Name")) - - # create list - for column in columns: - n = self.pluginlist.append_column(column) - column.cell = gtk.CellRendererText() - column.gray_background = gtk.CellRendererText() - column.pack_start(column.cell, True) - column.pack_start(column.gray_background, True) - column.set_attributes(column.cell, markup=(n-1), visible=2) - column.set_attributes(column.gray_background, visible=3, cell_background=4) - column.set_resizable(True) - - # toggle - group_name_renderer = gtk.CellRendererText() - toggle_renderer = gtk.CellRendererToggle() - toggle_renderer.set_property('activatable', True) - toggle_renderer.connect( 'toggled', self.on_enabled_toggled, self.pluginsListStore ) - column = gtk.TreeViewColumn(_('Enabled')) - column.pack_start(toggle_renderer, True) - column.pack_start(group_name_renderer, True) - column.add_attribute( toggle_renderer, "active", 1) - column.add_attribute( toggle_renderer, "visible", 2) - column.add_attribute( group_name_renderer, "visible", 3) - column.add_attribute( group_name_renderer, "markup", 0) - column.add_attribute( group_name_renderer, "cell_background", 4) - self.pluginlist.insert_column(column, 0) - - #connect signals - self.pluginlist.connect("cursor-changed", self.on_tvDumps_cursor_changed) - self.builder.get_object("bConfigurePlugin").connect("clicked", self.on_bConfigurePlugin_clicked, self.pluginlist) - self.builder.get_object("bClose").connect("clicked", self.on_bClose_clicked) - self.builder.get_object("bConfigurePlugin").set_sensitive(False) - - def on_enabled_toggled(self,cell, path, model): - plugin = model[path][model.get_n_columns()-1] - if plugin: - if model[path][1]: - #print "self.ccdaemon.UnRegisterPlugin(%s)" % (plugin.getName()) - self.ccdaemon.unRegisterPlugin(plugin.getName()) - # FIXME: create class plugin and move this into method Plugin.Enable() - plugin.Enabled = "no" - plugin.Settings = None - else: - #print "self.ccdaemon.RegisterPlugin(%s)" % (model[path][model.get_n_columns()-1]) - self.ccdaemon.registerPlugin(plugin.getName()) - # FIXME: create class plugin and move this into method Plugin.Enable() - plugin.Enabled = "yes" - plugin.Settings = PluginSettings(self.ccdaemon.getPluginSettings(plugin.getName())) - model[path][1] = not model[path][1] - - def filter_plugins(self, model, miter, data): - return True - def hydrate(self): - #print "settings hydrate" - self.pluginsListStore.clear() - try: - pluginlist = getPluginInfoList(self.ccdaemon, refresh=True) - except Exception, e: - print e - #gui_error_message("Error while loading plugins info, please check if abrt daemon is running\n %s" % e) - plugin_rows = {} - for plugin_type in PluginInfo.types.keys(): - it = self.pluginsListStore.append(None, ["%s" % (PluginInfo.types[plugin_type]),0 , 0, 1,"gray", None]) - plugin_rows[plugin_type] = it - for entry in pluginlist: - n = self.pluginsListStore.append(plugin_rows[entry.getType()],["%s\n%s" % (entry.getName(), entry.Description), entry.Enabled == "yes", 1, 0, "white", entry]) - self.pluginlist.expand_all() - - def dehydrate(self): - # we have nothing to save, plugin's does the work - pass - - def show(self): - self.window.show() - #if result == gtk.RESPONSE_APPLY: - # self.dehydrate() - #self.window.destroy() - #return result - - def on_bConfigurePlugin_clicked(self, button, pluginview): - pluginsListStore, path = pluginview.get_selection().get_selected_rows() - if not path: - self.builder.get_object("lDescription").set_label(_("Can't get plugin description")) - return - # this should work until we keep the row object in the last position - pluginfo = pluginsListStore.get_value(pluginsListStore.get_iter(path[0]), pluginsListStore.get_n_columns()-1) - if pluginfo: - try: - ui = PluginSettingsUI(pluginfo) - except Exception, e: - gui_error_message(_("Error while opening plugin settings UI: \n\n%s" % e)) - return - ui.hydrate() - response = ui.run() - if response == gtk.RESPONSE_APPLY: - ui.dehydrate() - if pluginfo.Settings: - try: - self.ccdaemon.setPluginSettings(pluginfo.getName(), pluginfo.Settings) - except Exception, e: - gui_error_message(_("Can't save plugin settings:\n %s", e)) - #for key, val in pluginfo.Settings.iteritems(): - # print "%s:%s" % (key, val) - elif response == gtk.RESPONSE_CANCEL: - pass - else: - print _("unknown response from settings dialog") - ui.destroy() - - def on_bClose_clicked(self, button): - self.window.destroy() - - def on_tvDumps_cursor_changed(self, treeview): - pluginsListStore, path = treeview.get_selection().get_selected_rows() - if not path: - self.builder.get_object("lDescription").set_label("No description") - return - # this should work until we keep the row object in the last position - pluginfo = pluginsListStore.get_value(pluginsListStore.get_iter(path[0]), pluginsListStore.get_n_columns()-1) - if pluginfo: - self.builder.get_object("lPluginAuthor").set_text(pluginfo.Email) - self.builder.get_object("lPluginVersion").set_text(pluginfo.Version) - self.builder.get_object("lPluginWebSite").set_text(pluginfo.WWW) - self.builder.get_object("lPluginName").set_text(pluginfo.Name) - self.builder.get_object("lPluginDescription").set_text(pluginfo.Description) - # print (pluginfo.Enabled == "yes" and pluginfo.GTKBuilder != "") - self.builder.get_object("bConfigurePlugin").set_sensitive(pluginfo != None and pluginfo.Enabled == "yes" and pluginfo.GTKBuilder != "") diff --git a/src/Gui/ccgui.glade b/src/Gui/ccgui.glade index 7b8dd244..67bf6fa3 100644 --- a/src/Gui/ccgui.glade +++ b/src/Gui/ccgui.glade @@ -148,6 +148,13 @@ Zdenek Prikryl <zprikryl@redhat.com> True + + + True + Global settings + True + + diff --git a/src/Gui/settings.GtkBuilder b/src/Gui/settings.GtkBuilder index 575b77c6..676f3907 100644 --- a/src/Gui/settings.GtkBuilder +++ b/src/Gui/settings.GtkBuilder @@ -2,7 +2,7 @@ - + Settings True 450 @@ -214,4 +214,262 @@ + + Global Settings + True + 450 + 400 + + + True + vertical + + + True + True + + + True + 3 + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + Common + + + False + + + + + True + vertical + + + True + True + automatic + automatic + + + True + queue + + + True + vertical + + + + + + + + + + 0 + + + + + True + True + + + True + + + + + + 0 + + + + + True + + + + + + 1 + + + + + gtk-add + True + True + True + True + + + 2 + + + + + False + 1 + + + + + 1 + + + + + True + Cron + + + 1 + False + + + + + True + 3 + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + True + Analyzers, Actions, Reporters + + + 2 + False + + + + + 0 + + + + + True + True + + + True + + + + + + 0 + + + + + True + 14 + True + + + gtk-cancel + True + True + True + True + + + False + 0 + + + + + gtk-ok + True + True + True + True + + + False + 1 + + + + + 1 + + + + + False + False + 1 + + + + + -- cgit