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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
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 _
#FIXME: create a better struct, to automatize hydrate/dehydrate process
settings_dict = { "Common":
{"OpenGPGCheck":bool,
"Database":object,
"EnabledPlugins": list,
"BlackList": list,
"MaxCrashReportsSize": int,
"OpenGPGPublicKeys": list,
},
}
class SettingsDialog:
def __init__(self, parent, daemon):
builderfile = "%s%ssettings.glade" % (sys.path[0],"/")
self.ccdaemon = daemon
self.builder = gtk.Builder()
self.builder.add_from_file(builderfile)
self.window = self.builder.get_object("wGlobalSettings")
self.builder.get_object("bSaveSettings").connect("clicked", self.on_ok_clicked)
self.builder.get_object("bCancelSettings").connect("clicked", self.on_cancel_clicked)
self.builder.get_object("bAddCronJob").connect("clicked", self.on_bAddCronJob_clicked)
# action plugin list for Cron tab
self.actionPluginsListStore = gtk.ListStore(str, object)
self.actionPluginsListStore.append([_("<b>Select plugin</b>"), None])
# database plugin list
self.databasePluginsListStore = gtk.ListStore(str, object)
self.databasePluginsListStore.append([_("<b>Select database backend</b>"), None])
self.dbcombo = self.builder.get_object("cbDatabase")
self.dbcombo.set_model(self.databasePluginsListStore)
cell = gtk.CellRendererText()
self.dbcombo.pack_start(cell)
self.dbcombo.add_attribute(cell, "markup", 0)
# blacklist edit
self.builder.get_object("bEditBlackList").connect("clicked", self.on_blacklistEdit_clicked)
self.builder.get_object("bOpenGPGPublicKeys").connect("clicked", self.on_GPGKeysEdit_clicked)
self.builder.get_object("bAddAction").connect("clicked", self.on_bAddAction_clicked)
# AnalyzerActionsAndReporters
self.analyzerPluginsListStore = gtk.ListStore(str, object)
self.analyzerPluginsListStore.append([_("<b>Select plugin</b>"), None])
# GPG keys
self.wGPGKeys = self.builder.get_object("wGPGKeys")
self.GPGKeysListStore = gtk.ListStore(str)
self.tvGPGKeys = self.builder.get_object("tvGPGKeys")
self.tvGPGKeys.set_model(self.GPGKeysListStore)
self.builder.get_object("bCancelGPGKeys").connect("clicked", self.on_bCancelGPGKeys_clicked)
self.builder.get_object("bSaveGPGKeys").connect("clicked", self.on_bSaveGPGKeys_clicked)
gpg_column = gtk.TreeViewColumn()
cell = gtk.CellRendererText()
gpg_column.pack_start(cell)
gpg_column.add_attribute(cell, "text", 0)
self.tvGPGKeys.append_column(gpg_column)
def filter_settings(self, model, miter, data):
return True
def hydrate(self):
try:
self.settings = self.ccdaemon.getSettings()
except Exception, e:
# FIXME: this should be error gui message!
print e
try:
self.pluginlist = getPluginInfoList(self.ccdaemon, refresh=True)
except Exception, e:
print e
## hydrate cron jobs:
for key,val in self.settings["Cron"].iteritems():
# actionas are separated by ','
actions = val.split(',')
self.settings["Cron"][key] = actions
for plugin in self.pluginlist.getActionPlugins():
it = self.actionPluginsListStore.append([plugin.getName(), plugin])
for key,val in self.settings["Cron"].iteritems():
if plugin.getName() in val:
cron_job = (key,it)
self.add_CronJob(cron_job)
self.settings["Cron"][key].remove(plugin.getName())
# hydrate common
common = self.settings["Common"]
## gpgcheck
self.builder.get_object("cbOpenGPGCheck").set_active(common["OpenGPGCheck"] == 'yes')
## database
for dbplugin in self.pluginlist.getDatabasePlugins():
it = self.databasePluginsListStore.append([dbplugin.getName(), dbplugin])
if common["Database"] == dbplugin.getName():
self.dbcombo.set_active_iter(it)
## MaxCrashSize
self.builder.get_object("sbMaxCrashReportsSize").set_value(float(common["MaxCrashReportsSize"]))
## GPG keys
self.builder.get_object("eOpenGPGPublicKeys").set_text(common["OpenGPGPublicKeys"])
self.gpgkeys = common["OpenGPGPublicKeys"].split(',')
for gpgkey in self.gpgkeys:
self.GPGKeysListStore.append([gpgkey])
## blacklist
self.builder.get_object("eBlacklist").set_text(common["BlackList"])
# hydrate AnalyzerActionsAndReporters
AnalyzerActionsAndReporters = self.settings["AnalyzerActionsAndReporters"]
for analplugin in self.pluginlist.getAnalyzerPlugins():
it = self.analyzerPluginsListStore.append([analplugin.getName(), analplugin])
if AnalyzerActionsAndReporters.has_key(analplugin.getName()):
action = (AnalyzerActionsAndReporters[analplugin.getName()], it)
self.add_AnalyzerAction(action)
def on_bCancelGPGKeys_clicked(self, button):
print "cancel"
self.wGPGKeys.hide()
def on_bSaveGPGKeys_clicked(self, button):
print "save"
self.wGPGKeys.hide()
def on_bAddGPGKey_clicked(self, button):
print "add GPG key"
def on_bRemoveGPGKey_clicked(self, button):
print "add GPG key"
def on_blacklistEdit_clicked(self, button):
print "edit blacklist"
def on_GPGKeysEdit_clicked(self, button):
self.wGPGKeys.show()
def on_ok_clicked(self, button):
self.dehydrate()
self.window.hide()
def on_cancel_clicked(self, button):
self.window.hide()
def on_remove_CronJob_clicked(self, button, job_hbox):
self.removeHBoxWihtChildren(job_hbox)
def on_remove_Action_clicked(self, button, binding_hbox):
self.removeHBoxWihtChildren(binding_hbox)
def removeHBoxWihtChildren(self, job_hbox):
job_hbox.get_parent().remove(job_hbox)
for child in job_hbox.get_children():
child.destroy()
job_hbox.destroy()
def add_CronJob(self, job=None):
hbox = gtk.HBox()
time = gtk.Entry()
remove_image = gtk.Image()
remove_image.set_from_stock("gtk-remove",gtk.ICON_SIZE_MENU)
remove_button = gtk.Button()
remove_button.set_image(remove_image)
remove_button.set_tooltip_text(_("Remove this job"))
remove_button.connect("clicked", self.on_remove_CronJob_clicked, hbox)
plugins = gtk.ComboBox()
cell = gtk.CellRendererText()
plugins.pack_start(cell)
plugins.add_attribute(cell, 'markup', 0)
plugins.set_model(self.actionPluginsListStore)
if job:
time.set_text(job[0])
plugins.set_active_iter(job[1])
else:
plugins.set_active(0)
hbox.pack_start(plugins,True)
hbox.pack_start(time,True)
hbox.pack_start(remove_button,False)
self.builder.get_object("vbCronJobs").pack_start(hbox,False)
hbox.show_all()
def on_bAddCronJob_clicked(self, button):
self.add_CronJob()
print "add"
def on_bEditAction_clicked(self, button, data=None):
print "edit action"
def add_AnalyzerAction(self, action=None):
#print "add_AnalyzerAction"
hbox = gtk.HBox()
action_list = gtk.Entry()
edit_actions = gtk.Button()
edit_actions.set_tooltip_text("Edit actions")
edit_image = gtk.Image()
edit_image.set_from_stock("gtk-edit", gtk.ICON_SIZE_MENU)
edit_actions.set_image(edit_image)
edit_actions.connect("clicked", self.on_bEditAction_clicked)
remove_image = gtk.Image()
remove_image.set_from_stock("gtk-remove",gtk.ICON_SIZE_MENU)
remove_button = gtk.Button()
remove_button.set_image(remove_image)
remove_button.set_tooltip_text(_("Remove this action"))
remove_button.connect("clicked", self.on_remove_Action_clicked, hbox)
reporters = gtk.ComboBox()
cell = gtk.CellRendererText()
reporters.pack_start(cell)
reporters.add_attribute(cell, 'markup', 0)
reporters.set_model(self.analyzerPluginsListStore)
if action:
action_list.set_text(action[0])
reporters.set_active_iter(action[1])
else:
reporters.set_active(0)
hbox.pack_start(reporters,True)
hbox.pack_start(action_list,True)
hbox.pack_start(edit_actions,False)
hbox.pack_start(remove_button,False)
self.builder.get_object("vbActions").pack_start(hbox,False)
hbox.show_all()
def on_bAddAction_clicked(self, button):
self.add_AnalyzerAction()
def on_cancel_clicked(self,button):
self.window.hide()
def dehydrate(self):
self.ccdaemon.setSettings(self.settings)
def show(self):
self.window.show()
|