summaryrefslogtreecommitdiffstats
path: root/src/Gui/PluginSettingsUI.py
blob: 8c24fde3a023b80fbc091bdb9d0eb9703c6c6acc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import gtk
from abrt_utils import _, log, log1, log2

class PluginSettingsUI():
    def __init__(self, pluginfo, parent=None):
        #print "Init PluginSettingsUI"
        self.plugin_name = pluginfo.Name
        self.Settings = pluginfo.Settings
        self.pluginfo = pluginfo
        self.plugin_gui = None

        if pluginfo.getGUI():
            self.plugin_gui = gtk.Builder()
            self.plugin_gui.add_from_file(pluginfo.getGUI())
            self.dialog = self.plugin_gui.get_object("PluginDialog")
            if not self.dialog:
                raise Exception(_("Can't find PluginDialog widget in UI description!"))
            self.dialog.set_title("%s" % pluginfo.getName())
            if parent:
                self.dialog.set_transient_for(parent)
        else:
            # we shouldn't get here, but just to be safe
            log1("No UI for plugin %s" % pluginfo)

        if parent:
            self.dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
            self.dialog.set_transient_for(parent)
            self.dialog.set_modal(True)

    def on_show_pass_toggled(self, button, entry=None):
        if entry:
            entry.set_visibility(button.get_active())

    def hydrate(self):
        if self.plugin_gui:
            if self.pluginfo.Enabled == "yes":
                if self.Settings:
                    #print "Hydrating %s" % self.plugin_name
                    for key, value in self.Settings.iteritems():
                        #print "%s:%s" % (key,value)
                        widget = self.plugin_gui.get_object("conf_%s" % key)
                        if type(widget) == gtk.Entry:
                            widget.set_text(value)
                            if widget.get_visibility() == False:
                                # if we find toggle button called the same name as entry and entry has
                                # visibility set to False, connect set_visible to it
                                # coz I guess it's toggle for revealing the password
                                button = self.plugin_gui.get_object("cb_%s" % key)
                                if type(button) == gtk.CheckButton:
                                    button.connect("toggled", self.on_show_pass_toggled, widget)
                        elif type(widget) == gtk.CheckButton:
                            widget.set_active(value == "yes")
                        elif type(widget) == gtk.ComboBox:
                            print _("combo box is not implemented")
                else:
                    #print "Plugin %s has no configuration." % self.plugin_name
                    pass
            else:
                #print "Plugin %s is disabled." % self.plugin_name
                pass

        else:
            print _("Nothing to hydrate!")

    def dehydrate(self):
        #print "dehydrating %s" % self.pluginfo.getName()
        if self.Settings:
            for key in self.Settings.keys():
                #print key
                #print "%s:%s" % (key,value)
                widget = self.plugin_gui.get_object("conf_%s" % key)
                if type(widget) == gtk.Entry:
                    self.Settings[key] = widget.get_text()
                elif type(widget) == gtk.CheckButton:
                    if widget.get_active():
                        self.Settings[key] = "yes"
                    else:
                        self.Settings[key] = "no"
                elif type(widget) == gtk.ComboBox:
                    print _("combo box is not implemented")

    def destroy(self):
        self.dialog.destroy()

    def run(self):
        return self.dialog.run()