cremefraiche 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of cremefraiche might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/bin/cremefraiche +25 -0
- data/bin/cremefraicheGui +26 -0
- data/cremefraiche.gemspec +24 -0
- data/lib/LANG +1 -0
- data/lib/busy_indicator/busy_function_test.rb +56 -0
- data/lib/busy_indicator/busy_indicator.rb +95 -0
- data/lib/busy_indicator/color_output.rb +51 -0
- data/lib/cfprawn.rb +394 -0
- data/lib/confcheck.rb +112 -0
- data/lib/config +192 -0
- data/lib/configuration.rb +259 -0
- data/lib/cremefraiche.rb +341 -0
- data/lib/emlfile.rb +140 -0
- data/lib/file_checking.rb +87 -0
- data/lib/gui/AboutDialog.rb +64 -0
- data/lib/gui/ButtonLabel.rb +49 -0
- data/lib/gui/ConfDialog.rb +618 -0
- data/lib/gui/HowtoDialog.rb +184 -0
- data/lib/gui/conf_option.rb +279 -0
- data/lib/gui/conf_value.rb +65 -0
- data/lib/gui/cremefraicheGui.rb +625 -0
- data/lib/gui/gtk-about.xpm +90 -0
- data/lib/gui/gtk-close.xpm +90 -0
- data/lib/gui/gtk-execute.xpm +118 -0
- data/lib/gui/gtk-open.xpm +147 -0
- data/lib/gui/gtk-properties.xpm +378 -0
- data/lib/gui/gtk-quit.xpm +352 -0
- data/lib/gui/gtk-remove.xpm +123 -0
- data/lib/gui/gtk-save.xpm +214 -0
- data/lib/gui/gtk-stop.xpm +344 -0
- data/lib/gui/help.xpm +463 -0
- data/lib/gui/icon.xpm +300 -0
- data/lib/gui/message_dialog.rb +34 -0
- data/lib/gui/okay.xpm +49 -0
- data/lib/gui/preferences-color.xpm +252 -0
- data/lib/gui/view.xpm +75 -0
- data/lib/html2text.rb +177 -0
- data/lib/icon/icon.xpm +300 -0
- data/lib/icon/icon_big.xpm +661 -0
- data/lib/license.rb +705 -0
- data/lib/log.conf +65 -0
- data/lib/logging.rb +193 -0
- data/lib/tag_munging.rb +97 -0
- data/lib/translating.rb +78 -0
- data/lib/translations +598 -0
- data/lib/version.rb +26 -0
- metadata +213 -0
@@ -0,0 +1,618 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
/***************************************************************************
|
4
|
+
* ©2012-2020, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
5
|
+
* *
|
6
|
+
* This program is free software; you can redistribute it and/or modify *
|
7
|
+
* it under the terms of the GNU General Public License as published by *
|
8
|
+
* the Free Software Foundation; either version 3 of the License, or *
|
9
|
+
* (at your option) any later version. *
|
10
|
+
* *
|
11
|
+
* This program is distributed in the hope that it will be useful, *
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
14
|
+
* GNU General Public License for more details. *
|
15
|
+
* *
|
16
|
+
* You should have received a copy of the GNU General Public License *
|
17
|
+
* along with this program; if not, write to the *
|
18
|
+
* Free Software Foundation, Inc., *
|
19
|
+
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
20
|
+
***************************************************************************/
|
21
|
+
=end
|
22
|
+
require 'gtk3'
|
23
|
+
require_relative 'ButtonLabel'
|
24
|
+
require_relative 'conf_option'
|
25
|
+
require_relative '../configuration'
|
26
|
+
require_relative '../confcheck'
|
27
|
+
require_relative '../translating'
|
28
|
+
require_relative '../file_checking'
|
29
|
+
require_relative '../logging'
|
30
|
+
require_relative 'message_dialog'
|
31
|
+
|
32
|
+
=begin
|
33
|
+
An object of this class opens a configuration-dialog
|
34
|
+
that displays and allows to modify all the options which are defined in
|
35
|
+
the currently used configuration-file.
|
36
|
+
=end
|
37
|
+
class ConfDialog
|
38
|
+
include Translating
|
39
|
+
include Logging
|
40
|
+
include File_Checking
|
41
|
+
|
42
|
+
self.extend(Logging)
|
43
|
+
@@log = init_logger($CONF.log_file ? $CONF.log_file : STDOUT, $CONF.log_level ? $CONF.log_level : Logger::UNKNOWN)
|
44
|
+
|
45
|
+
=begin
|
46
|
+
transforms the given hex-color into a Gdk::RGBA-object.
|
47
|
+
=end
|
48
|
+
def self::hex2rgba(hexc = 'ffffff')
|
49
|
+
rgba = Gdk::RGBA.new(1,1,1,1)
|
50
|
+
begin
|
51
|
+
rgba = Gdk::RGBA.new(hexc[0,2].hex/255.0, hexc[2,2].hex/255.0, hexc[4,2].hex/255.0, 1) if hexc.length == 6
|
52
|
+
rescue Exception => ex
|
53
|
+
msg = 'Invalid color-value ' << hexc << ': ' << ex.message
|
54
|
+
@log.error(msg)
|
55
|
+
end
|
56
|
+
return rgba
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
@@GD = File::expand_path(File::dirname(__FILE__) ) + File::Separator if !defined?(@@GD)
|
61
|
+
@@Error_color = ConfDialog::hex2rgba('c00000')
|
62
|
+
@@White = ConfDialog::hex2rgba('ffffff')
|
63
|
+
@@Black = ConfDialog::hex2rgba('000000')
|
64
|
+
|
65
|
+
def initialize(options = {})
|
66
|
+
@title = trl('Configuration')
|
67
|
+
@log = @@log
|
68
|
+
@cdialog = Gtk::Dialog.new(:title => @title, :parent => nil )
|
69
|
+
# font-settings are inter-dependent.
|
70
|
+
@fonts = Array.new
|
71
|
+
# create the controls of the dialog
|
72
|
+
create
|
73
|
+
@cdialog.signal_connect('response') do |dlg, resp|
|
74
|
+
@log.debug("response %i emitted" %resp) if @log
|
75
|
+
@cdialog.destroy if(Gtk::ResponseType::CANCEL == resp)
|
76
|
+
end
|
77
|
+
if(options && options.keys.include?(:on_destroy))
|
78
|
+
@cdialog.signal_connect('destroy') {options[:on_destroy].call() }
|
79
|
+
end
|
80
|
+
@cdialog.show
|
81
|
+
end
|
82
|
+
private
|
83
|
+
|
84
|
+
=begin
|
85
|
+
signal that a value has been changed in the dialog but is not yet
|
86
|
+
saved to the configuration-file.
|
87
|
+
=end
|
88
|
+
def mark_changed(label)
|
89
|
+
@labels = Array.new if !defined?(@labels)
|
90
|
+
if(label && !@labels.include?(label) )
|
91
|
+
@labels << label
|
92
|
+
@cdialog.title = @title + ' *'
|
93
|
+
label.set_markup("<b>* " << label.text << "</b>")
|
94
|
+
elsif(!label)
|
95
|
+
@cdialog.title = @title
|
96
|
+
@labels.each do |lb|
|
97
|
+
lb.set_markup("<b>" << lb.text.sub('* ', '') << "</b>")
|
98
|
+
end
|
99
|
+
@labels.clear
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
=begin
|
104
|
+
calls refresh_table to create the remainder of the
|
105
|
+
controls.
|
106
|
+
=end
|
107
|
+
def create
|
108
|
+
@cdialog.set_icon(@@GD + 'icon.xpm');
|
109
|
+
tbox = Gtk::Box.new(:vertical, 5)
|
110
|
+
# initialize the table
|
111
|
+
@table = Gtk::Table.new(1,5)
|
112
|
+
@table.set_row_spacings(2)
|
113
|
+
refresh_table
|
114
|
+
|
115
|
+
tframe = Gtk::Frame.new()
|
116
|
+
tframe.add(@table)
|
117
|
+
|
118
|
+
tbox.pack_start(tframe, :expand=>true)
|
119
|
+
tbox.pack_start(init_buttons, :expand => false)
|
120
|
+
tbox.show_all
|
121
|
+
@cdialog.child.pack_start(tbox)
|
122
|
+
end
|
123
|
+
|
124
|
+
=begin
|
125
|
+
creates the buttons to save values, close the
|
126
|
+
dialog or to reset the configuration to default-values
|
127
|
+
=end
|
128
|
+
def init_buttons
|
129
|
+
bbox = Gtk::Box.new(:horizontal, 5)
|
130
|
+
@save_button = Gtk::Button.new()
|
131
|
+
@save_button.add(ButtonLabel.new(trl('_Save'), @@GD + "gtk-save.xpm") )
|
132
|
+
@save_button.set_tooltip_text(trl("Save current values to the configuration-file %s") %($CONF.config_file) )
|
133
|
+
|
134
|
+
@okay_button = Gtk::Button.new()
|
135
|
+
@okay_button.add(ButtonLabel.new(trl('_Okay'), @@GD + "gtk-close.xpm") )
|
136
|
+
@okay_button.set_tooltip_text(trl('Close this dialog, lose any unsaved changes') )
|
137
|
+
|
138
|
+
@default_conf = Gtk::Button.new()
|
139
|
+
@default_conf.add(ButtonLabel.new(trl('_Defaults'), @@GD + "gtk-properties.xpm"))
|
140
|
+
@default_conf.set_tooltip_text(trl('Overwrite with default-settings'))
|
141
|
+
|
142
|
+
@save_button.signal_connect(CLICKED) do
|
143
|
+
save()
|
144
|
+
end
|
145
|
+
|
146
|
+
@okay_button.signal_connect(CLICKED) do
|
147
|
+
@cdialog.destroy
|
148
|
+
end
|
149
|
+
|
150
|
+
@default_conf.signal_connect(CLICKED) do
|
151
|
+
ConfCheck.new.write_user_conf
|
152
|
+
refresh_table
|
153
|
+
end
|
154
|
+
|
155
|
+
bbox.pack_start(@save_button, :expand => false, :fill => false)
|
156
|
+
bbox.pack_start(@okay_button, :expand => false, :fill => false)
|
157
|
+
bbox.pack_end(@default_conf, :expand => false, :fill => false)
|
158
|
+
return bbox
|
159
|
+
end
|
160
|
+
|
161
|
+
=begin
|
162
|
+
saves the currently displayed values to the configuration-file.
|
163
|
+
=end
|
164
|
+
def save()
|
165
|
+
@log.debug('new-conf is ' << @new_conf.to_s)
|
166
|
+
$CONF.save_config(@new_conf)
|
167
|
+
refresh_table
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
=begin
|
172
|
+
creates a tooltip-text for the given configuration-option.
|
173
|
+
=end
|
174
|
+
def tooltip(option)
|
175
|
+
d = option.default
|
176
|
+
if(false == d)
|
177
|
+
d = 'false'
|
178
|
+
elsif(true == d)
|
179
|
+
d = 'true'
|
180
|
+
else
|
181
|
+
d = d.to_s.chomp.strip if(d)
|
182
|
+
d = ((!d || d.empty?) ? trl('empty') : d )
|
183
|
+
end
|
184
|
+
|
185
|
+
option.doc.dup << "\n" << trl('Default') << ': ' << d
|
186
|
+
end
|
187
|
+
|
188
|
+
=begin
|
189
|
+
Creates a multiline text-widget for a multiline configuration-option.
|
190
|
+
ATTN: Stringlists can be altered by the user. Therefore, these values cannot be
|
191
|
+
translated and must be displayed in their original form.
|
192
|
+
=end
|
193
|
+
def stringlist(label, option)
|
194
|
+
value = option.value
|
195
|
+
|
196
|
+
vtext = Gtk::Frame.new
|
197
|
+
vtextView = Gtk::TextView.new(Gtk::TextBuffer.new() )
|
198
|
+
vtextView.buffer.signal_connect("changed") do |buf|
|
199
|
+
mark_changed(label)
|
200
|
+
@new_conf[option.name] = buf.text
|
201
|
+
end
|
202
|
+
v = ''
|
203
|
+
if(value.respond_to?(:to_ary) )
|
204
|
+
@log.debug('option value is array')
|
205
|
+
v = value.join("\n")
|
206
|
+
elsif (value.respond_to?(:to_str) )
|
207
|
+
@log.debug('option value is string')
|
208
|
+
v = value.split.join("\n")
|
209
|
+
else
|
210
|
+
v = value.to_s
|
211
|
+
end
|
212
|
+
vtextView.buffer.text = v
|
213
|
+
@new_conf[option.name] = vtextView.buffer.text
|
214
|
+
@log.debug('stringlist created')
|
215
|
+
|
216
|
+
# Okay, someone had the idea to make the add() function return
|
217
|
+
# an empty Hash, sometime between Gtk3-releases. So what, why
|
218
|
+
# not an elephant or something moist and warm..? Break my code,
|
219
|
+
# folks. Plenty of room for your creativity.
|
220
|
+
vtext.add(vtextView)
|
221
|
+
# This looks dumb because it is! Eat it. Why a Hash? What Hash?
|
222
|
+
vtext
|
223
|
+
end
|
224
|
+
=begin
|
225
|
+
creates a checkbox for a boolean configuration-option.
|
226
|
+
=end
|
227
|
+
def truefalse(label, option)
|
228
|
+
vtext = Gtk::CheckButton.new()
|
229
|
+
vtext.active = option.value
|
230
|
+
|
231
|
+
vtext.signal_connect(CLICKED) do |cb|
|
232
|
+
@log.debug(cb.class.name)
|
233
|
+
@new_conf[option.name] = cb.active?
|
234
|
+
mark_changed(label)
|
235
|
+
end
|
236
|
+
vtext
|
237
|
+
end
|
238
|
+
=begin
|
239
|
+
creates a simple text-entry field.
|
240
|
+
=end
|
241
|
+
def text_entry(label, option)
|
242
|
+
@log.debug('text_entry for ' << label.text << ", option is " << option.to_s)
|
243
|
+
display_value = option.display_value ? option.display_value : ''
|
244
|
+
vtext = Gtk::Entry.new()
|
245
|
+
vtext.signal_connect("changed") do |entry|
|
246
|
+
@new_conf[option.name] = entry.text
|
247
|
+
mark_changed(label)
|
248
|
+
end
|
249
|
+
@log.debug('setting value for ' << option.name << ' to ' << option.value.to_s)
|
250
|
+
vtext.text.clear
|
251
|
+
vtext.text = display_value
|
252
|
+
@new_conf[option.name] = option.value if option.value
|
253
|
+
return vtext
|
254
|
+
end
|
255
|
+
=begin
|
256
|
+
creates a dropdown-field for an option that allows
|
257
|
+
a choice from pre-defined values.
|
258
|
+
#TODO: translate choices and compare to translated
|
259
|
+
# values
|
260
|
+
=end
|
261
|
+
def choose_text(label, option)
|
262
|
+
vtext = Gtk::ComboBoxText.new
|
263
|
+
option.choices.each {|c| vtext.append_text(trl(c.to_s, false) )}
|
264
|
+
|
265
|
+
value = option.value
|
266
|
+
@log.debug('choose_text, value is ' << value.to_s)
|
267
|
+
if(value && ! value.to_s.empty?)
|
268
|
+
@log.debug('choose_text, value is ' << value.to_s)
|
269
|
+
valuestr = option.display_value
|
270
|
+
if(option.choices.include?(value.to_sym) )
|
271
|
+
index = option.choices.index(value.to_sym)
|
272
|
+
vtext.set_active(index) if index
|
273
|
+
else
|
274
|
+
msg = file_check(valuestr, :exist?, :directory?, :writable?)
|
275
|
+
@log.debug('is not a file: ' << valuestr)
|
276
|
+
if(!msg)
|
277
|
+
vtext.append_text(valuestr)
|
278
|
+
vtext.set_active(option.choices.size)
|
279
|
+
else
|
280
|
+
dmsg = (trl("The directory %s cannot be used for mail-attachments (%s)") %[valuestr, msg])
|
281
|
+
msg_dialog(dmsg, :WARNING)
|
282
|
+
@log.warn(dmsg)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
else
|
286
|
+
@log.debug('choose_text: no value')
|
287
|
+
end
|
288
|
+
vtext.signal_connect("changed") do
|
289
|
+
if('path' == vtext.active_text)
|
290
|
+
dir = choose_file(option, :action=>:select_folder)
|
291
|
+
vtext.append_text(dir) if dir
|
292
|
+
vtext.set_active(option.choices.size)
|
293
|
+
end
|
294
|
+
# Correlate index from combo-box with index from choices!
|
295
|
+
index = vtext.active
|
296
|
+
tx = option.choices[index]
|
297
|
+
if(!tx || tx.empty?)
|
298
|
+
tx = option.default.to_s
|
299
|
+
end
|
300
|
+
@new_conf[option.name] = tx
|
301
|
+
mark_changed(label)
|
302
|
+
end
|
303
|
+
vtext
|
304
|
+
end
|
305
|
+
|
306
|
+
=begin
|
307
|
+
creates a text-entry and a file-chooser button and inter-connects
|
308
|
+
the current option to all other font-options.
|
309
|
+
=end
|
310
|
+
def font(label, option)
|
311
|
+
vtext = file_path(label, option)
|
312
|
+
font_entry = vtext.children.first
|
313
|
+
if (!@fonts.include?(font_entry) )
|
314
|
+
@fonts << font_entry
|
315
|
+
end
|
316
|
+
verify_fonts(font_entry)
|
317
|
+
verify_font(font_entry, option)
|
318
|
+
|
319
|
+
font_entry.signal_connect('changed') do |entry|
|
320
|
+
set_widget_bg(entry, Gdk::RGBA.new(1, 1, 1, 1))
|
321
|
+
verify_fonts(entry)
|
322
|
+
verify_font(font_entry, option)
|
323
|
+
end
|
324
|
+
vtext
|
325
|
+
end
|
326
|
+
=begin
|
327
|
+
checks a currently set font-setting for validity
|
328
|
+
=end
|
329
|
+
def verify_font(entry, option)
|
330
|
+
msg = check_file_constraints(entry.text, option)
|
331
|
+
if(msg)
|
332
|
+
mark_entry(entry)
|
333
|
+
else
|
334
|
+
mark_entry(entry, false)
|
335
|
+
end
|
336
|
+
|
337
|
+
end
|
338
|
+
|
339
|
+
=begin
|
340
|
+
Makes sure, that none or all fonts are set.
|
341
|
+
=end
|
342
|
+
def verify_fonts(entry)
|
343
|
+
has_value = entry.text && !entry.text.empty?
|
344
|
+
@fonts.each do |f|
|
345
|
+
if(f != entry)
|
346
|
+
hv = f.text && !f.text.empty?
|
347
|
+
if(hv != has_value)
|
348
|
+
set_widget_bg(f, @@Error_color)
|
349
|
+
else
|
350
|
+
set_widget_bg(f, @@White)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
end
|
356
|
+
=begin
|
357
|
+
opens a file-chooser dialog and allows to choose files or directories,
|
358
|
+
depending on the option.
|
359
|
+
=end
|
360
|
+
def choose_file(option, args={})
|
361
|
+
file = nil
|
362
|
+
if(!@fdialog)
|
363
|
+
action = args[:action]
|
364
|
+
action ||= :open
|
365
|
+
item = (action == :open ? trl('file') : trl('folder') )
|
366
|
+
@fdialog = Gtk::FileChooserDialog.new(:title => trl("Choose a %s") %item,
|
367
|
+
:parent => nil,
|
368
|
+
:action => action,
|
369
|
+
:buttons => [[:cancel, :cancel], [:open, :accept]])
|
370
|
+
if(args[:start_path])
|
371
|
+
# start where the currently selected file has been located.
|
372
|
+
@fdialog.filename = args[:start_path]
|
373
|
+
else
|
374
|
+
# or start in the user's home-directory
|
375
|
+
@fdialog.filename = HOME
|
376
|
+
@fdialog.filename ||= Dir::pwd
|
377
|
+
end
|
378
|
+
# open the file-chooser, return the selected file-name
|
379
|
+
file = (@fdialog.run == Gtk::ResponseType::ACCEPT ? @fdialog.filename : nil)
|
380
|
+
@fdialog.destroy
|
381
|
+
@fdialog = nil
|
382
|
+
end
|
383
|
+
return file
|
384
|
+
|
385
|
+
end
|
386
|
+
=begin
|
387
|
+
creates a text-entry and a file-chooser button.
|
388
|
+
=end
|
389
|
+
def file_path(label, option)
|
390
|
+
vtext = Gtk::Box.new(:horizontal)
|
391
|
+
fpath = Gtk::Entry.new()
|
392
|
+
fpath.signal_connect("changed") do |entry|
|
393
|
+
@new_conf[option.name] = entry.text if entry.text
|
394
|
+
mark_changed(label)
|
395
|
+
msg = check_file_constraints(entry.text, option)
|
396
|
+
if(msg)
|
397
|
+
@log.debug('mark_entry ' << label.text << ' faulty' )
|
398
|
+
mark_entry(fpath)
|
399
|
+
end
|
400
|
+
end
|
401
|
+
vtext.pack_start(fpath)
|
402
|
+
fchoose = Gtk::Button.new( )
|
403
|
+
fchoose.add(ButtonLabel.new('', @@GD + "gtk-open.xpm"))
|
404
|
+
fpath.text.clear
|
405
|
+
fpath.text = option.value
|
406
|
+
vtext.pack_start(fchoose)
|
407
|
+
fchoose.signal_connect(CLICKED) do
|
408
|
+
file = choose_file(option, :start_path => fpath.text)
|
409
|
+
fpath.text = file if file
|
410
|
+
@new_conf[option.name] = file if file
|
411
|
+
msg = check_file_constraints(fpath.text, option)
|
412
|
+
if(msg)
|
413
|
+
mark_entry(fpath)
|
414
|
+
msg_dialog(msg, DLG_ERROR)
|
415
|
+
else
|
416
|
+
mark_entry(fpath, false)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
vtext
|
420
|
+
end
|
421
|
+
|
422
|
+
=begin
|
423
|
+
marks a text-entry widget as faulty or not.
|
424
|
+
=end
|
425
|
+
def mark_entry(entry, faulty = true)
|
426
|
+
entry.override_color(:NORMAL, faulty ? @@Error_color : @@Black )
|
427
|
+
end
|
428
|
+
=begin
|
429
|
+
compares file-properties to a given set of constraints.
|
430
|
+
=end
|
431
|
+
def check_file_constraints(file, option)
|
432
|
+
if(file && !file.empty? && option.constraints )
|
433
|
+
@log.debug('checking file ' << file)
|
434
|
+
msg = file_check(file, *option.constraints)
|
435
|
+
if(msg)
|
436
|
+
msg = trl("File %s is unuseable") %file << ": \"" << msg << "\""
|
437
|
+
@log.error(msg)
|
438
|
+
file = nil
|
439
|
+
return msg
|
440
|
+
end
|
441
|
+
end
|
442
|
+
return nil
|
443
|
+
end
|
444
|
+
|
445
|
+
=begin
|
446
|
+
creates a text-entry and a color-chooser button.
|
447
|
+
=end
|
448
|
+
def hexcolor(label, option)
|
449
|
+
ovalue = option.value
|
450
|
+
vtext = Gtk::Box.new(:horizontal)
|
451
|
+
color = Gtk::Entry.new()
|
452
|
+
color.text.clear
|
453
|
+
if(ovalue && !ovalue.to_s.strip.empty?)
|
454
|
+
color.text = ovalue.to_s
|
455
|
+
else
|
456
|
+
color.text = option.default
|
457
|
+
end
|
458
|
+
set_widget_bg(color, hex2rgba(color.text))
|
459
|
+
color.signal_connect("changed") do |entry|
|
460
|
+
@new_conf[option.name] = entry.text
|
461
|
+
set_widget_bg(entry, hex2rgba(entry.text))
|
462
|
+
mark_changed(label)
|
463
|
+
end
|
464
|
+
vtext.pack_start(color)
|
465
|
+
cchoose = Gtk::Button.new( )
|
466
|
+
cchoose.add(ButtonLabel.new('', @@GD + "preferences-color.xpm"))
|
467
|
+
vtext.pack_start(cchoose)
|
468
|
+
cchoose.signal_connect(CLICKED) do
|
469
|
+
if(!@coldlg)
|
470
|
+
#gtk3 sabotage fix
|
471
|
+
#
|
472
|
+
# @coldlg = Gtk::ColorSelectionDialog.new(:title => trl('Choose a color'))
|
473
|
+
@coldlg = Gtk::ColorChooserDialog.new(:title => trl('Choose a color'))
|
474
|
+
# @coldlg.color_selection.current_rgba = hex2rgba(color.text)
|
475
|
+
@coldlg.set_rgba( hex2rgba(color.text))
|
476
|
+
ncolor = (@coldlg.run == Gtk::ResponseType::OK ? @coldlg.rgba : nil)
|
477
|
+
if(ncolor)
|
478
|
+
hcolor = "%02x%02x%02x" %[ncolor.red * 255, ncolor.green * 255, ncolor.blue * 255]
|
479
|
+
@log.debug('original color : ' << ncolor.red.to_s << ', ' << ncolor.green.to_s << ', ' << ncolor.blue.to_s << ' : new hcolor is ' << hcolor)
|
480
|
+
@new_conf[option.name] = hcolor
|
481
|
+
color.text = hcolor
|
482
|
+
set_widget_bg(color, ncolor)
|
483
|
+
end
|
484
|
+
@coldlg.destroy
|
485
|
+
@coldlg = nil
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
vtext
|
490
|
+
end
|
491
|
+
=begin
|
492
|
+
transforms the given hex-color into a Gdk::RGBA-object.
|
493
|
+
=end
|
494
|
+
def hex2rgba(hexc = 'ffffff')
|
495
|
+
ConfDialog::hex2rgba(hexc)
|
496
|
+
end
|
497
|
+
=begin
|
498
|
+
Changes for the widget 'wg' its background-color to 'rgba', a Gdk::RGBA-object.
|
499
|
+
If the color is too dark for black foreground-text, also alters the text-color to white.
|
500
|
+
=end
|
501
|
+
def set_widget_bg(wg, rgba)
|
502
|
+
wg.override_background_color(:NORMAL, rgba)
|
503
|
+
colsum = rgba.red + rgba.green + rgba.blue
|
504
|
+
if(colsum < 176/255.0)
|
505
|
+
wg.override_color(:NORMAL, Gdk::RGBA.new(1,1,1,1) )
|
506
|
+
else
|
507
|
+
wg.override_color(:NORMAL, Gdk::RGBA.new(0,0,0,1) )
|
508
|
+
end
|
509
|
+
end
|
510
|
+
=begin
|
511
|
+
Creates and re-creates all the control-elements which set and change
|
512
|
+
configuration-options. For each option-type a specific method is called.
|
513
|
+
=end
|
514
|
+
def refresh_table()
|
515
|
+
$CONF.read_config
|
516
|
+
@log.debug('CONF is ' << $CONF.inspect)
|
517
|
+
sz = $CONF.size
|
518
|
+
@log.debug('configuration contains ' << sz.to_s << ' elements')
|
519
|
+
row = 0
|
520
|
+
@new_conf = Hash.new
|
521
|
+
@table.each {|w| @table.remove(w) }
|
522
|
+
#### TODO #########
|
523
|
+
# @log.error('TODO: use ConfValue where needed to replace value. Aborting!')
|
524
|
+
# exit false
|
525
|
+
#### END #########
|
526
|
+
|
527
|
+
$CONF.each_with_index do |pair, i|
|
528
|
+
begin
|
529
|
+
@log.debug('working on pair ' << pair.to_s << ', index #' << i.to_s)
|
530
|
+
key = pair[0].to_s
|
531
|
+
# store the current value to the 'new' configuration
|
532
|
+
option = ConfOption.new(key, pair[1])
|
533
|
+
@log.debug('option is ' << option.to_s)
|
534
|
+
# The option may set a different value, for some reason.
|
535
|
+
# store value to persist
|
536
|
+
@new_conf[key] = option.value.to_s
|
537
|
+
|
538
|
+
klbl = Gtk::Label.new()
|
539
|
+
klbl.set_markup('<b>' << option.display_name << ': </b>')
|
540
|
+
klbl.set_halign(2)
|
541
|
+
klbl.set_valign(1)
|
542
|
+
otype = option.type
|
543
|
+
ovalue = option.value if option.value
|
544
|
+
@log.debug('option-name is ' << key)
|
545
|
+
@log.debug('option-value is ' << ovalue.to_s)
|
546
|
+
@log.debug('option display-value is ' << option.display_value.to_s)
|
547
|
+
@log.debug('option-type is ' << otype.to_s)
|
548
|
+
case otype
|
549
|
+
when :stringlist
|
550
|
+
vtext = stringlist(klbl, option)
|
551
|
+
when :choose_text
|
552
|
+
vtext = choose_text(klbl, option)
|
553
|
+
when :file
|
554
|
+
vtext = file_path(klbl, option)
|
555
|
+
when :font
|
556
|
+
vtext = font(klbl, option)
|
557
|
+
when :bool
|
558
|
+
vtext = truefalse(klbl, option)
|
559
|
+
when :hexcolor
|
560
|
+
vtext = hexcolor(klbl, option)
|
561
|
+
else
|
562
|
+
@log.debug('default option type')
|
563
|
+
vtext = text_entry(klbl, option)
|
564
|
+
=begin
|
565
|
+
vtext = Gtk::Entry.new()
|
566
|
+
vtext.signal_connect("changed") do |entry|
|
567
|
+
@new_conf[key] = entry.text
|
568
|
+
mark_changed(klbl)
|
569
|
+
end
|
570
|
+
@log.debug('setting value for ' << key << ' to ' << ovalue.to_s)
|
571
|
+
vtext.text.clear
|
572
|
+
vtext.text = option.display_value.to_s if option.display_value
|
573
|
+
@new_conf[key] = ovalue if ovalue
|
574
|
+
=end
|
575
|
+
end
|
576
|
+
vtext.set_valign(1) if vtext && vtext.respond_to?(:set_valign)
|
577
|
+
|
578
|
+
ttip = tooltip(option)
|
579
|
+
|
580
|
+
klbl.set_tooltip_text(ttip)
|
581
|
+
vtext.set_tooltip_text(ttip) if vtext && vtext.respond_to?(:set_tooltip_text)
|
582
|
+
@log.debug('tooltip set for ' << klbl.text)
|
583
|
+
|
584
|
+
if( i % 2 == 0)
|
585
|
+
@table.attach(klbl, 0, 1, row, row + 1)
|
586
|
+
@log.debug('attaching text-entry ' << vtext.class.name)
|
587
|
+
@table.attach(vtext, 1, 2, row, row + 1) if vtext
|
588
|
+
@log.debug('left label and value set')
|
589
|
+
else
|
590
|
+
@log.debug('right')
|
591
|
+
@table.attach(klbl, 2, 3, row, row + 1)
|
592
|
+
@table.attach(vtext, 3, 4, row, row + 1) if vtext
|
593
|
+
@log.debug('right label and value set')
|
594
|
+
row += 1
|
595
|
+
@table.attach(Gtk::Separator.new(:horizontal), 0, 4, row, row + 1)
|
596
|
+
row += 1
|
597
|
+
end
|
598
|
+
rescue ConfOption::InvalidOptionError => ex
|
599
|
+
msg = ex.message << "\nIgnoring invalid option %s. Please save a valid configuration." %klbl.text
|
600
|
+
@log.error msg
|
601
|
+
msg_dialog(msg, :error)
|
602
|
+
rescue Exception => ex
|
603
|
+
if klbl
|
604
|
+
msg = klbl.text.dup << ": " << ex.message
|
605
|
+
else
|
606
|
+
msg = ex.message
|
607
|
+
end
|
608
|
+
@log.error( msg)
|
609
|
+
msg_dialog(msg, :error)
|
610
|
+
end
|
611
|
+
|
612
|
+
end
|
613
|
+
|
614
|
+
mark_changed(nil)
|
615
|
+
@table.show_all
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|