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,184 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
/***************************************************************************
|
4
|
+
* ©2012-2016, 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 '../cremefraiche'
|
24
|
+
require_relative 'ButtonLabel'
|
25
|
+
require_relative '../translating'
|
26
|
+
require_relative '../file_checking'
|
27
|
+
require_relative '../logging'
|
28
|
+
|
29
|
+
|
30
|
+
class HowtoDialog
|
31
|
+
include Translating
|
32
|
+
include Logging
|
33
|
+
@@GD = File::expand_path(File::dirname(__FILE__) ) + File::Separator if !defined?(@@GD)
|
34
|
+
@@HOWTO = $PROG_DIR.dup << '../doc/gui_howto.html'
|
35
|
+
@@NAVIGATORS = %w"firefox opera epiphany-browser"
|
36
|
+
|
37
|
+
def initialize(options = {})
|
38
|
+
init_logger($CONF.log_file ? $CONF.log_file : STDOUT, $CONF.log_level ? $CONF.log_level : Logger::UNKNOWN)
|
39
|
+
@hdialog = Gtk::Dialog.new()
|
40
|
+
reader_frame = Gtk::Frame.new(trl('Howto'))
|
41
|
+
|
42
|
+
reader_vbox = Gtk::Box.new(:vertical, 5)
|
43
|
+
reader_vbox.border_width = 5
|
44
|
+
reader_hbox = Gtk::Box.new(:horizontal, 5)
|
45
|
+
reader_hbox.border_width = 5
|
46
|
+
|
47
|
+
bl_text = trl("Please name the command which starts your Web-Browser (e.g. firefox, opera, epiphany-browser ...).")
|
48
|
+
reader_label = Gtk::Label.new(bl_text)
|
49
|
+
reader_label.wrap = true
|
50
|
+
@reader_entry = Gtk::Entry.new
|
51
|
+
@reader_entry.width_chars = 33
|
52
|
+
@reader_entry.height_request = 25
|
53
|
+
# Sabotage fix. “We, the Gods of GTK approve of this failure”
|
54
|
+
# @reader_entry.text = $CONF.pdf_reader
|
55
|
+
@reader_entry.text = find_reader()
|
56
|
+
@bc_button = Gtk::Button.new()
|
57
|
+
@bc_button.add(ButtonLabel.new(trl('_Choose'), "%s/gtk-open.xpm" %@@GD))
|
58
|
+
|
59
|
+
reader_vbox.pack_start(reader_label, :expand => false)
|
60
|
+
|
61
|
+
reader_hbox.pack_start(@reader_entry, :expand => false)
|
62
|
+
reader_hbox.pack_start(@bc_button, :expand => false)
|
63
|
+
reader_vbox.pack_start(reader_hbox, :expand => false)
|
64
|
+
reader_frame.add(reader_vbox)
|
65
|
+
|
66
|
+
button_box = Gtk::ButtonBox.new(:horizontal)
|
67
|
+
button_box.layout_style = :start
|
68
|
+
@cancel_button = Gtk::Button.new()
|
69
|
+
@cancel_button.add(ButtonLabel.new(trl('_Cancel'), "%s/gtk-stop.xpm" %@@GD))
|
70
|
+
@ok_button = Gtk::Button.new()
|
71
|
+
@ok_button.add(ButtonLabel.new(trl('_Accept'), "%s/gtk-execute.xpm" %@@GD))
|
72
|
+
|
73
|
+
button_box.pack_start(@ok_button, :expand => false)
|
74
|
+
button_box.pack_start(@cancel_button, :expand => false)
|
75
|
+
|
76
|
+
@hdialog.child.pack_start(reader_frame)
|
77
|
+
@hdialog.child.pack_start(button_box)
|
78
|
+
|
79
|
+
@bc_button.set_tooltip_text trl('Choose a Web-Browser')
|
80
|
+
@reader_entry.set_tooltip_text trl('Command, which starts your Web-Browser')
|
81
|
+
@cancel_button.set_tooltip_text trl('Close dialog')
|
82
|
+
@ok_button.set_tooltip_text trl('Executes your Web-Browser and shows the Howto manual')
|
83
|
+
|
84
|
+
connect_buttons
|
85
|
+
@hdialog.set_title('HOWTO: ' << CremeFraiche::prog_info[:app_name])
|
86
|
+
@hdialog.child.show_all
|
87
|
+
@hdialog.signal_connect('response') do |dlg, resp|
|
88
|
+
@log.debug("response %i emitted" %resp) if @log
|
89
|
+
@adialog.destroy if(:cancel == resp)
|
90
|
+
end
|
91
|
+
if(options && options.keys.include?(:on_destroy))
|
92
|
+
@hdialog.signal_connect('destroy') {options[:on_destroy].call() }
|
93
|
+
end
|
94
|
+
|
95
|
+
@hdialog.show
|
96
|
+
end
|
97
|
+
|
98
|
+
def find_reader
|
99
|
+
@@NAVIGATORS.detect(''){|c| $Progs.include?(c)}
|
100
|
+
end
|
101
|
+
|
102
|
+
def choose_reader
|
103
|
+
dialog = Gtk::FileChooserDialog.new(:title => trl("set reader"),
|
104
|
+
:parent => nil,
|
105
|
+
:action => :open,
|
106
|
+
:buttons => [[:cancel, :cancel], [:accept, :accept]])
|
107
|
+
|
108
|
+
if(@reader_entry.text && ! @reader_entry.text.empty?)
|
109
|
+
@log.debug('reader is ' << @reader_entry.text)
|
110
|
+
dialog.filename = @reader_entry.text
|
111
|
+
end
|
112
|
+
ret = dialog.run
|
113
|
+
br = (ret == Gtk::ResponseType::ACCEPT ? dialog.filename : nil)
|
114
|
+
dialog.destroy
|
115
|
+
|
116
|
+
msg = File_Checking.file_check(br, [:exist?, :file?, :executable?]) if br
|
117
|
+
if(msg)
|
118
|
+
@log.error(msg) if @log
|
119
|
+
msg_dialog(msg, DLG_ERROR)
|
120
|
+
br = nil
|
121
|
+
end
|
122
|
+
return br
|
123
|
+
end
|
124
|
+
|
125
|
+
def connect_buttons
|
126
|
+
@bc_button.signal_connect("clicked") do
|
127
|
+
br = choose_reader
|
128
|
+
@reader_entry.text = br if br
|
129
|
+
end
|
130
|
+
|
131
|
+
@cancel_button.signal_connect("clicked") do
|
132
|
+
@hdialog.destroy
|
133
|
+
end
|
134
|
+
@ok_button.signal_connect("clicked") do
|
135
|
+
run_reader(@reader_entry.text) if @reader_entry.text
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def run_reader(br)
|
140
|
+
msg = nil
|
141
|
+
if(br && ! br.empty?)
|
142
|
+
begin
|
143
|
+
fork_sym = (RUBY_PLATFORM =~ /win/) ? '' : ' &'
|
144
|
+
exec_command = "%s %s%s" %[br, @@HOWTO, fork_sym]
|
145
|
+
@log.debug "exec-command will be %s" %exec_command if @log
|
146
|
+
hr = system exec_command
|
147
|
+
if(!hr)
|
148
|
+
msg = trl("Cannot open the Web-Browser!", "\n")
|
149
|
+
msg += trl("Please verify, that %s is correctly spelled or use another reader.", "\"#{br}\"")
|
150
|
+
else
|
151
|
+
@hdialog.destroy
|
152
|
+
end
|
153
|
+
rescue Exception => ex
|
154
|
+
msg = trl("Cannot open the Web-Browser %s", ex)
|
155
|
+
end
|
156
|
+
else
|
157
|
+
msg = trl('No reader selected, skipping Howto.')
|
158
|
+
end
|
159
|
+
@log.error(msg) if @log && msg
|
160
|
+
@log.debug($?.to_s) if @log
|
161
|
+
msg_dialog(msg, DLG_ERROR) if msg
|
162
|
+
end
|
163
|
+
|
164
|
+
def msg_dialog(msg, type)
|
165
|
+
dialog = Gtk::MessageDialog.new(
|
166
|
+
:parent => nil,
|
167
|
+
:flags => :destroy_with_parent,
|
168
|
+
:type => type,
|
169
|
+
:message => "%s: \"%s\"" %[Translating::trl(type.to_s.upcase), msg])
|
170
|
+
|
171
|
+
dialog.set_title(DLG_INFO == type ? 'Info' : 'Error' )
|
172
|
+
dialog.run
|
173
|
+
dialog.destroy
|
174
|
+
return msg
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
# execute if this script is the argument to the ruby-interpreter.
|
181
|
+
if __FILE__ == $0
|
182
|
+
HowtoDialog.new()
|
183
|
+
end
|
184
|
+
|
@@ -0,0 +1,279 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
/***************************************************************************
|
4
|
+
* ©2011-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
|
+
|
23
|
+
require_relative '../logging'
|
24
|
+
require_relative '../translating'
|
25
|
+
require_relative 'message_dialog'
|
26
|
+
require_relative 'conf_value'
|
27
|
+
|
28
|
+
require 'ostruct'
|
29
|
+
|
30
|
+
=begin
|
31
|
+
An object of this class represents a configuration-option.
|
32
|
+
It comprises the name, the value, the default-value, the data-type and the
|
33
|
+
documentation of such an option.
|
34
|
+
=end
|
35
|
+
|
36
|
+
class ConfOption
|
37
|
+
include Translating
|
38
|
+
include Logging
|
39
|
+
self::extend(Logging)
|
40
|
+
|
41
|
+
@@log = self::init_logger($CONF.log_file ? $CONF.log_file : STDOUT, $CONF.log_level ? $CONF.log_level : Logger::UNKNOWN)
|
42
|
+
|
43
|
+
@@Doc = {
|
44
|
+
:pdf_prefix => Translating::trl( "The PDF-prefix and -suffix are added to the name of an eml-file to create the name of a resulting PDF-file, potentially keeping a numerical prefix intact, like in prefix_[num_]eml_suffix.pdf, e.g. mail_3_eml_arch.pdf."),
|
45
|
+
|
46
|
+
:pdf_suffix => Translating::trl("The PDF-prefix and -suffix are added to the name of an eml-file to create the name of a resulting PDF-file, potentially keeping a numerical prefix intact, like in prefix_[num_]eml_suffix.pdf, e.g. mail_3_eml_arch.pdf."),
|
47
|
+
|
48
|
+
:log_level => Translating::trl("The log-level can be fatal, error, warn, info or debug.") << ' ' << Translating::trl('Restart the program for changes to this option to take effect.'),
|
49
|
+
|
50
|
+
:log_file => Translating::trl("Path to the protocol-file, where the logger-output will be directed, if configured. When left empty, stdout will be used."),
|
51
|
+
|
52
|
+
:page_size => Translating::trl("Page size, e.g. A4"),
|
53
|
+
|
54
|
+
:page_layout => Translating::trl("Page layout, one of portrait or landscape"),
|
55
|
+
|
56
|
+
:regular_font => Translating::trl("Font-file to use in the PDF-file. By default, the fonts used in the PDF are those supported by the Ruby-gem \"Prawn\", i.e. Courier, Times-Roman and Helvetica or the respective replacement font, which is valid on your system. The font-file, that you name here, will replace Helvetica and be used for the headers and the body of the email in PDF-format. ATTN! For your font-settings to take effect, you must name ALL four font-files!"),
|
57
|
+
|
58
|
+
:bold_font => Translating::trl("Font-file to use in the PDF-file. By default, the fonts used in the PDF are those supported by the Ruby-gem \"Prawn\", i.e. Courier, Times-Roman and Helvetica or the respective replacement font, which is valid on your system. The font-file, that you name here, will replace Helvetica and be used for the headers and the body of the email in PDF-format. ATTN! For your font-settings to take effect, you must name ALL four font-files!"),
|
59
|
+
|
60
|
+
:italic_font => Translating::trl("Font-file to use in the PDF-file. By default, the fonts used in the PDF are those supported by the Ruby-gem \"Prawn\", i.e. Courier, Times-Roman and Helvetica or the respective replacement font, which is valid on your system. The font-file, that you name here, will replace Helvetica and be used for the headers and the body of the email in PDF-format. ATTN! For your font-settings to take effect, you must name ALL four font-files!"),
|
61
|
+
|
62
|
+
:bold_italic_font => Translating::trl("Font-file to use in the PDF-file. By default, the fonts used in the PDF are those supported by the Ruby-gem \"Prawn\", i.e. Courier, Times-Roman and Helvetica or the respective replacement font, which is valid on your system. The font-file, that you name here, will replace Helvetica and be used for the headers and the body of the email in PDF-format. ATTN! For your font-settings to take effect, you must name ALL four font-files!"),
|
63
|
+
|
64
|
+
:visible_headers => Translating::trl("The visible headers will be shown in the final pdf. Headers which are noted here *and* also under hidden headers, will anyway be honored (*not* ignored)."),
|
65
|
+
|
66
|
+
:hidden_headers => Translating::trl("The hidden headers will be suppressed... they are still here for reference. Add more, as you stumble over new headers in your e-mail. Headers which are noted here *and* also under visible headers will anyway be honored (*not* ignored)."),
|
67
|
+
|
68
|
+
:show_content_type => Translating::trl("This option controls wether a visible body-part is preceded by a line indicating the content-type, like \"text/plain; charset=ISO-8859-1; format=flowed\""),
|
69
|
+
|
70
|
+
:content_type_color => Translating::trl("The color of the content-type"),
|
71
|
+
|
72
|
+
:replacement_color => Translating::trl("This is the color of a replacement-character, where a character cannot be converted to UTF-8."),
|
73
|
+
|
74
|
+
:replacement_char => Translating::trl("Symbols which will replace any character which cannot be converted to UTF-8."),
|
75
|
+
|
76
|
+
:link_color => Translating::trl("Color for hyper-links"),
|
77
|
+
|
78
|
+
:author => Translating::trl("Provided the pdftk-tool is installed and can be found in the environment path, the value of these variables will set the respective field in the meta-data of the resulting PDF-files. Leave empty to ignore..."),
|
79
|
+
|
80
|
+
:subject => Translating::trl("Provided the pdftk-tool is installed and can be found in the environment path, the value of these variables will set the respective field in the meta-data of the resulting PDF-files. Leave empty to ignore... Default subject is the subject-line of the original mail."),
|
81
|
+
|
82
|
+
:keywords => Translating::trl("Provided the pdftk-tool is installed and can be found in the environment path, the value of these variables will set the respective field in the meta-data of the resulting PDF-files. Leave empty to ignore..."),
|
83
|
+
|
84
|
+
:title => Translating::trl("Provided the pdftk-tool is installed and can be found in the environment path, the value of these variables will set the respective field in the meta-data of the resulting PDF-files. Leave empty to ignore..."),
|
85
|
+
|
86
|
+
:save_attachments => Translating::trl("If and where attachments shall be placed. Either 'pdf' to store files in the PDF (needs pdftk) or a directory path to store files in the given directory. A link to the file shall be provided in the PDF. The directory MUST EXIST, or 'false' to ignore the attachments"),
|
87
|
+
|
88
|
+
:attachment_link_color => Translating::trl("The color of the links to saved attachments, if \"save attachments\" is set to a file path, rather than 'pdf'"),
|
89
|
+
|
90
|
+
:pdf_reader => Translating::trl("A reader-application which can be used in different contexts to show a PDF-file."),
|
91
|
+
}
|
92
|
+
|
93
|
+
@@Default = {
|
94
|
+
:pdf_prefix => '',
|
95
|
+
:pdf_suffix => '',
|
96
|
+
:log_level => 'unknown',
|
97
|
+
:log_file => STDOUT,
|
98
|
+
:page_size => 'A4',
|
99
|
+
:page_layout => 'portrait',
|
100
|
+
:regular_font => '',
|
101
|
+
:bold_font => '',
|
102
|
+
:italic_font => '',
|
103
|
+
:bold_italic_font => '',
|
104
|
+
:visible_headers => 'All mail-headers',
|
105
|
+
:hidden_headers => '',
|
106
|
+
:show_content_type => false,
|
107
|
+
:content_type_color => '000080',
|
108
|
+
:replacement_color => 'f08080',
|
109
|
+
:replacement_char => '<?>',
|
110
|
+
:link_color => '700000',
|
111
|
+
:author => '',
|
112
|
+
:subject => 'mail-subject',
|
113
|
+
:keywords => '',
|
114
|
+
:title => '',
|
115
|
+
:save_attachments => 'pdf',
|
116
|
+
:attachment_link_color => '008000',
|
117
|
+
:pdf_reader => ''
|
118
|
+
}
|
119
|
+
|
120
|
+
@@Types = {
|
121
|
+
:pdf_prefix => :string,
|
122
|
+
:pdf_suffix => :string,
|
123
|
+
:log_level => :choose_text,
|
124
|
+
:log_file => :file,
|
125
|
+
:page_size => :choose_text,
|
126
|
+
:page_layout => :choose_text,
|
127
|
+
:regular_font => :font,
|
128
|
+
:bold_font => :font,
|
129
|
+
:italic_font => :font,
|
130
|
+
:bold_italic_font => :font,
|
131
|
+
:visible_headers => :stringlist,
|
132
|
+
:hidden_headers => :stringlist,
|
133
|
+
:show_content_type => :bool,
|
134
|
+
:content_type_color => :hexcolor,
|
135
|
+
:replacement_color => :hexcolor,
|
136
|
+
:replacement_char => :string,
|
137
|
+
:link_color => :hexcolor,
|
138
|
+
:author => :string,
|
139
|
+
:subject => :string,
|
140
|
+
:keywords => :string,
|
141
|
+
:title => :string,
|
142
|
+
:save_attachments => :choose_text,
|
143
|
+
:attachment_link_color => :hexcolor,
|
144
|
+
:pdf_reader => :file
|
145
|
+
}
|
146
|
+
=begin UNUSED
|
147
|
+
@@Pane_content = {
|
148
|
+
:show_content_type => :bool,
|
149
|
+
:regular_font => :file,
|
150
|
+
:bold_font => :file,
|
151
|
+
:italic_font => :file,
|
152
|
+
:bold_italic_font => :file,
|
153
|
+
:attachment_link_color => :hexcolor,
|
154
|
+
:visible_headers => :stringlist,
|
155
|
+
:hidden_headers => :stringlist,
|
156
|
+
:save_attachments => :choose_text,
|
157
|
+
:content_type_color => :hexcolor,
|
158
|
+
:replacement_color => :hexcolor,
|
159
|
+
:replacement_char => :string,
|
160
|
+
:link_color => :hexcolor,
|
161
|
+
|
162
|
+
}
|
163
|
+
@@Pane_pdf = {
|
164
|
+
:pdf_prefix => :string,
|
165
|
+
:pdf_suffix => :string,
|
166
|
+
:page_size => :choose_text,
|
167
|
+
:page_layout => :choose_text,
|
168
|
+
:author => :string,
|
169
|
+
:subject => :string,
|
170
|
+
:keywords => :string,
|
171
|
+
:title => :string,
|
172
|
+
}
|
173
|
+
@@Pane_program = {
|
174
|
+
:log_level => :choose_text,
|
175
|
+
:log_file => :file,
|
176
|
+
:pdf_reader => :file
|
177
|
+
}
|
178
|
+
=end
|
179
|
+
@@Choices = {
|
180
|
+
:log_level => [:unknown, :debug, :info, :error, :fatal, :warn],
|
181
|
+
:page_size => %w"4A0 2A0 A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 RA0 RA1 RA2 RA3 RA4 SRA0 SRA1 SRA3 SRA4 EXECUTIVE FOLIO LEGAL LETTER".collect{|ps| ps.to_sym},
|
182
|
+
:page_layout => [:portrait, :landscape],
|
183
|
+
:save_attachments => [:pdf, :path, :false]
|
184
|
+
}
|
185
|
+
|
186
|
+
@@Constraints = {
|
187
|
+
:pdf_reader => [:exist, :file, :executable],
|
188
|
+
:save_attachments => [:exist, :directory, :writable],
|
189
|
+
:bold_font => [:exist, :file, :readable],
|
190
|
+
:italic_font => [:exist, :file, :readable],
|
191
|
+
:bold_italic_font => [:exist, :file, :readable],
|
192
|
+
:regular_font => [:exist, :file, :readable],
|
193
|
+
}
|
194
|
+
|
195
|
+
class Error < RuntimeError
|
196
|
+
end
|
197
|
+
class InvalidOptionError < Error
|
198
|
+
end
|
199
|
+
class NoValueError < Error
|
200
|
+
end
|
201
|
+
|
202
|
+
def initialize(name, value = nil)
|
203
|
+
@log = @@log
|
204
|
+
keys = @@Types.keys
|
205
|
+
nkey = name.downcase.gsub(' ', '_').to_sym
|
206
|
+
@name = name
|
207
|
+
if(keys.include?(nkey))
|
208
|
+
@log.debug("configuring " << nkey.to_s << ", value is " << value.to_s)
|
209
|
+
|
210
|
+
@display_name = trl(name)
|
211
|
+
@type = @@Types[nkey]
|
212
|
+
@choices = @@Choices[nkey] if @@Choices.keys.include?(nkey)
|
213
|
+
@doc = @@Doc[nkey]
|
214
|
+
@default = @@Default[nkey]
|
215
|
+
@constraints = @@Constraints[nkey]
|
216
|
+
begin
|
217
|
+
if(!@constraints && @choices && !@choices.include?(value ? value.to_sym : ''.to_sym) )
|
218
|
+
message = trl("Value %s is not permitted for option %s!") %[(value && !value.empty? ? trl(value.to_s) : '(empty)') , name]
|
219
|
+
message << "\nSetting default-value %s" %(@default.to_s )
|
220
|
+
@log.warn(message)
|
221
|
+
msg_dialog(message, 'warning' )
|
222
|
+
|
223
|
+
@value = ConfValue.new(@name, @default)
|
224
|
+
else
|
225
|
+
@value = ConfValue.new(@name, value)
|
226
|
+
end
|
227
|
+
rescue Exception => ex
|
228
|
+
@log.error('Error in configuration-option ' << @name << ': ' << ex.message)
|
229
|
+
end
|
230
|
+
|
231
|
+
else
|
232
|
+
@doc = 'N I L'
|
233
|
+
@default = 'N I L'
|
234
|
+
msg = trl("Unknown configuration-option %s!") %name
|
235
|
+
@log.error(msg)
|
236
|
+
raise InvalidOptionError, "An option \"" << name << "\" does not exist!" ;
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
attr_reader :name, :display_name, :type, :default, :choices, :constraints
|
242
|
+
|
243
|
+
def to_s
|
244
|
+
self.class.name << ': name = ' << @name << ', value = ' << (@value ? @value.to_s : 'N I L') << ', default = ' << @default.to_s << ', doc = ' << @doc
|
245
|
+
end
|
246
|
+
|
247
|
+
def value=(value)
|
248
|
+
if @value
|
249
|
+
@value.value = value
|
250
|
+
else
|
251
|
+
@value = ConfValue.new(value)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def value
|
256
|
+
if (@type != :bool && !@value)
|
257
|
+
msg = trl("No value has been set for option %s.") %(@name)
|
258
|
+
@log.warn(msg)
|
259
|
+
nil
|
260
|
+
elsif @value
|
261
|
+
@value.value
|
262
|
+
else
|
263
|
+
nil
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
def display_value
|
268
|
+
@value.display_value
|
269
|
+
end
|
270
|
+
|
271
|
+
def doc
|
272
|
+
if !@doc
|
273
|
+
@log.error(trl("Option %s is missing a documentation.") %(@name) )
|
274
|
+
else
|
275
|
+
@doc
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
=begin
|
3
|
+
/***************************************************************************
|
4
|
+
* ©2016-2016 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
|
+
|
23
|
+
# An object of this type represents the value of a configuration-option in case
|
24
|
+
# that it needs to be translated for display in the GUI, but not for the
|
25
|
+
# persistent configuration.
|
26
|
+
#
|
27
|
+
# Not every value needs to be encapsulated in a ConfValue object. Test, if there
|
28
|
+
# is a translation to read with value.respond_to?(:display_value). In case that a
|
29
|
+
# translation exists, persist obj.value. Otherwise show and persist the value
|
30
|
+
# as is.
|
31
|
+
# Examples: 'A4', 'A5', 'letter' will not be translated, but used and displayed
|
32
|
+
# in the same way, as 'A4', 'A5' or 'letter'. You do not need a ConfValue in that
|
33
|
+
# case.
|
34
|
+
#
|
35
|
+
# 'landscape' and 'portrait' in contrast may be displayed as 'paysage' and
|
36
|
+
# 'portrait' in French, 'Hochformat' and 'Querformat' in the German locale, while
|
37
|
+
# the configuration file will only contain 'landscape' or 'portrait'.
|
38
|
+
#
|
39
|
+
# See conf_option.rb for actual uses.
|
40
|
+
|
41
|
+
require_relative '../translating'
|
42
|
+
|
43
|
+
class ConfValue
|
44
|
+
include Translating
|
45
|
+
def initialize(label, value)
|
46
|
+
@label = label
|
47
|
+
@value = value
|
48
|
+
@value ||= ''
|
49
|
+
if(value.respond_to?(:to_ary) )
|
50
|
+
@display_value = @value.map{|v| trl(v) }
|
51
|
+
else
|
52
|
+
@display_value = trl(value.to_s, false)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
def to_s
|
56
|
+
self.class.name << ': value = ' << @value.to_s << ', display_value = ' << @display_value.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
attr_accessor :value
|
60
|
+
attr_reader :display_value
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
# EOF
|
65
|
+
|