cremefraiche 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +114 -0
  3. data/bin/cremefraiche +117 -0
  4. data/bin/cremefraicheGui +26 -0
  5. data/cremefraiche.gemspec +24 -0
  6. data/doc/gui_howto.pdf +0 -0
  7. data/lib/LANG +1 -0
  8. data/lib/basic_logging.rb +170 -0
  9. data/lib/busy_indicator/.busy_function_test.rb.swp +0 -0
  10. data/lib/busy_indicator/.busy_indicator.rb.swp +0 -0
  11. data/lib/busy_indicator/.color_output.rb.swp +0 -0
  12. data/lib/busy_indicator/busy_function_test.rb +50 -0
  13. data/lib/busy_indicator/busy_indicator.rb +89 -0
  14. data/lib/busy_indicator/color_output.rb +45 -0
  15. data/lib/cfprawn.rb +387 -0
  16. data/lib/confcheck.rb +103 -0
  17. data/lib/config +187 -0
  18. data/lib/configuration.rb +234 -0
  19. data/lib/configuration.rb~ +247 -0
  20. data/lib/cremefraiche.rb +181 -0
  21. data/lib/emlfile.rb +136 -0
  22. data/lib/file_checking.rb +82 -0
  23. data/lib/gui/.ButtonLabel.rb.swp +0 -0
  24. data/lib/gui/.conf_value.rb.swp +0 -0
  25. data/lib/gui/.cremefraicheGui.rb.swp +0 -0
  26. data/lib/gui/.message_dialog.rb.swp +0 -0
  27. data/lib/gui/AboutDialog.rb +63 -0
  28. data/lib/gui/ButtonLabel.rb +41 -0
  29. data/lib/gui/ConfDialog.rb +610 -0
  30. data/lib/gui/HowtoDialog.rb +183 -0
  31. data/lib/gui/conf_option.rb +274 -0
  32. data/lib/gui/conf_value.rb +58 -0
  33. data/lib/gui/cremefraicheGui.rb +568 -0
  34. data/lib/gui/gtk-about.xpm +90 -0
  35. data/lib/gui/gtk-close.xpm +90 -0
  36. data/lib/gui/gtk-execute.xpm +118 -0
  37. data/lib/gui/gtk-open.xpm +147 -0
  38. data/lib/gui/gtk-properties.xpm +378 -0
  39. data/lib/gui/gtk-quit.xpm +352 -0
  40. data/lib/gui/gtk-remove.xpm +123 -0
  41. data/lib/gui/gtk-save.xpm +214 -0
  42. data/lib/gui/gtk-stop.xpm +344 -0
  43. data/lib/gui/help.xpm +463 -0
  44. data/lib/gui/icon.xpm +300 -0
  45. data/lib/gui/message_dialog.rb +34 -0
  46. data/lib/gui/okay.xpm +49 -0
  47. data/lib/gui/preferences-color.xpm +252 -0
  48. data/lib/gui/view.xpm +75 -0
  49. data/lib/html2text.rb +195 -0
  50. data/lib/icon/icon.xpm +300 -0
  51. data/lib/icon/icon_big.xpm +661 -0
  52. data/lib/license.rb +38 -0
  53. data/lib/log.conf +65 -0
  54. data/lib/tag_munging.rb +89 -0
  55. data/lib/translating.rb +78 -0
  56. data/lib/translations +609 -0
  57. data/lib/version.rb +25 -0
  58. metadata +221 -0
@@ -0,0 +1,183 @@
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 '../basic_logging'
28
+
29
+
30
+ class HowtoDialog
31
+ include Translating
32
+ include BasicLogging
33
+ @@GD = File::expand_path(File::dirname(__FILE__) ) + File::Separator if !defined?(@@GD)
34
+ @@HOWTO = $PROG_DIR.dup << '../doc/gui_howto.pdf'
35
+ PDFViers = %w"firefox opera epiphany-browser"
36
+
37
+ def initialize(options = {})
38
+ @hdialog = Gtk::Dialog.new()
39
+ reader_frame = Gtk::Frame.new(trl('Howto'))
40
+
41
+ reader_vbox = Gtk::Box.new(:vertical, 5)
42
+ reader_vbox.border_width = 5
43
+ reader_hbox = Gtk::Box.new(:horizontal, 5)
44
+ reader_hbox.border_width = 5
45
+
46
+ bl_text = trl("Please name the command which starts your PDF viewer (e.g. qpdfview, acroread, evince, display ...).")
47
+ reader_label = Gtk::Label.new(bl_text)
48
+ reader_label.wrap = true
49
+ @reader_entry = Gtk::Entry.new
50
+ @reader_entry.width_chars = 33
51
+ @reader_entry.height_request = 25
52
+ # Sabotage fix. “We, the Gods of GTK approve of this failure”
53
+ # @reader_entry.text = $CONF.pdf_reader
54
+ @reader_entry.text = find_reader()
55
+ @bc_button = Gtk::Button.new()
56
+ @bc_button.add(ButtonLabel.new(trl('_Choose'), "%s/gtk-open.xpm" %@@GD))
57
+
58
+ reader_vbox.pack_start(reader_label, :expand => false)
59
+
60
+ reader_hbox.pack_start(@reader_entry, :expand => false)
61
+ reader_hbox.pack_start(@bc_button, :expand => false)
62
+ reader_vbox.pack_start(reader_hbox, :expand => false)
63
+ reader_frame.add(reader_vbox)
64
+
65
+ button_box = Gtk::ButtonBox.new(:horizontal)
66
+ button_box.layout_style = :start
67
+ @cancel_button = Gtk::Button.new()
68
+ @cancel_button.add(ButtonLabel.new(trl('_Cancel'), "%s/gtk-stop.xpm" %@@GD))
69
+ @ok_button = Gtk::Button.new()
70
+ @ok_button.add(ButtonLabel.new(trl('_Accept'), "%s/gtk-execute.xpm" %@@GD))
71
+
72
+ button_box.pack_start(@ok_button, :expand => false)
73
+ button_box.pack_start(@cancel_button, :expand => false)
74
+
75
+ @hdialog.child.pack_start(reader_frame)
76
+ @hdialog.child.pack_start(button_box)
77
+
78
+ @bc_button.set_tooltip_text trl('Choose a PDF viewer')
79
+ @reader_entry.set_tooltip_text trl('Command, which starts your PDF viewer')
80
+ @cancel_button.set_tooltip_text trl('Close dialog')
81
+ @ok_button.set_tooltip_text trl('Executes your PDF-viewer and shows the Howto manual')
82
+
83
+ connect_buttons
84
+ @hdialog.set_title('HOWTO: ' << CremeFraiche::prog_info[:app_name])
85
+ @hdialog.child.show_all
86
+ @hdialog.signal_connect('response') do |dlg, resp|
87
+ debug("response %i emitted" %resp)
88
+ @adialog.destroy if(:cancel == resp)
89
+ end
90
+ if(options && options.keys.include?(:on_destroy))
91
+ @hdialog.signal_connect('destroy') {options[:on_destroy].call() }
92
+ end
93
+
94
+ @hdialog.show
95
+ end
96
+
97
+ def find_reader
98
+ PDFViers.detect(''){|c| $Progs.include?(c)}
99
+ end
100
+
101
+ def choose_reader
102
+ dialog = Gtk::FileChooserDialog.new(:title => trl("set reader"),
103
+ :parent => nil,
104
+ :action => :open,
105
+ :buttons => [[:cancel, :cancel], [:accept, :accept]])
106
+
107
+ if(@reader_entry.text && ! @reader_entry.text.empty?)
108
+ debug('reader is ' << @reader_entry.text)
109
+ dialog.filename = @reader_entry.text
110
+ end
111
+ ret = dialog.run
112
+ br = (ret == Gtk::ResponseType::ACCEPT ? dialog.filename : nil)
113
+ dialog.destroy
114
+
115
+ msg = File_Checking.file_check(br, [:exist?, :file?, :executable?]) if br
116
+ if(msg)
117
+ error(msg)
118
+ msg_dialog(msg, DLG_ERROR)
119
+ br = nil
120
+ end
121
+ return br
122
+ end
123
+
124
+ def connect_buttons
125
+ @bc_button.signal_connect("clicked") do
126
+ br = choose_reader
127
+ @reader_entry.text = br if br
128
+ end
129
+
130
+ @cancel_button.signal_connect("clicked") do
131
+ @hdialog.destroy
132
+ end
133
+ @ok_button.signal_connect("clicked") do
134
+ run_reader(@reader_entry.text) if @reader_entry.text
135
+ end
136
+ end
137
+
138
+ def run_reader(br)
139
+ msg = nil
140
+ if(br && ! br.empty?)
141
+ begin
142
+ fork_sym = (RUBY_PLATFORM =~ /win/) ? '' : ' &'
143
+ exec_command = "%s %s%s" %[br, @@HOWTO, fork_sym]
144
+ debug "exec-command will be %s" %exec_command
145
+ hr = system exec_command
146
+ if(!hr)
147
+ msg = trl("Cannot open the PDF viewer!", "\n")
148
+ msg += trl("Please verify, that %s is correctly spelled or use another reader.", "\"#{br}\"")
149
+ else
150
+ @hdialog.destroy
151
+ end
152
+ rescue Exception => ex
153
+ msg = trl("Cannot open the PDF viewer %s", ex)
154
+ end
155
+ else
156
+ msg = trl('No reader selected, skipping Howto.')
157
+ end
158
+ error(msg) if msg
159
+ debug($?.to_s) if @log
160
+ msg_dialog(msg, DLG_ERROR) if msg
161
+ end
162
+
163
+ def msg_dialog(msg, type)
164
+ dialog = Gtk::MessageDialog.new(
165
+ :parent => nil,
166
+ :flags => :destroy_with_parent,
167
+ :type => type,
168
+ :message => "%s: \"%s\"" %[Translating::trl(type.to_s.upcase), msg])
169
+
170
+ dialog.set_title(DLG_INFO == type ? 'Info' : 'Error' )
171
+ dialog.run
172
+ dialog.destroy
173
+ return msg
174
+ end
175
+
176
+
177
+ end
178
+
179
+ # execute if this script is the argument to the ruby-interpreter.
180
+ if __FILE__ == $0
181
+ HowtoDialog.new()
182
+ end
183
+
@@ -0,0 +1,274 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2011-2023, 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 WTFPL 2.0 or later version of the LICENSE. *
8
+ * See https://wtfpl2.com/ for details. *
9
+ * *
10
+ * This program is distributed in the hope that it will be useful, *
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
13
+ * *
14
+ ***************************************************************************/
15
+ =end
16
+ require_relative '../basic_logging'
17
+ require_relative '../translating'
18
+ require_relative 'message_dialog'
19
+ require_relative 'conf_value'
20
+
21
+ require 'ostruct'
22
+
23
+ =begin
24
+ An object of this class represents a configuration-option.
25
+ It comprises the name, the value, the default-value, the data-type and the
26
+ documentation of such an option.
27
+ =end
28
+
29
+ class ConfOption
30
+ include Translating
31
+ include BasicLogging
32
+
33
+ @@Doc = {
34
+ :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."),
35
+
36
+ :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."),
37
+
38
+ :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.'),
39
+
40
+ :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."),
41
+
42
+ :page_size => Translating::trl("Page size, e.g. A4"),
43
+
44
+ :page_layout => Translating::trl("Page layout, one of portrait or landscape"),
45
+
46
+ :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!"),
47
+
48
+ :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!"),
49
+
50
+ :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!"),
51
+
52
+ :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!"),
53
+
54
+ :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)."),
55
+
56
+ :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)."),
57
+
58
+ :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\""),
59
+
60
+ :content_type_color => Translating::trl("The color of the content-type"),
61
+
62
+ :replacement_color => Translating::trl("This is the color of a replacement-character, where a character cannot be converted to UTF-8."),
63
+
64
+ :replacement_char => Translating::trl("Symbols which will replace any character which cannot be converted to UTF-8."),
65
+
66
+ :link_color => Translating::trl("Color for hyper-links"),
67
+
68
+ :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..."),
69
+
70
+ :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."),
71
+
72
+ :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..."),
73
+
74
+ :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..."),
75
+
76
+ :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"),
77
+
78
+ :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'"),
79
+
80
+ :pdf_reader => Translating::trl("A reader-application which can be used in different contexts to show a PDF-file."),
81
+ }
82
+
83
+ @@Default = {
84
+ :pdf_prefix => '',
85
+ :pdf_suffix => '',
86
+ :log_level => 'unknown',
87
+ :log_file => STDOUT,
88
+ :page_size => 'A4',
89
+ :page_layout => 'portrait',
90
+ :regular_font => '',
91
+ :bold_font => '',
92
+ :italic_font => '',
93
+ :bold_italic_font => '',
94
+ :visible_headers => 'All mail-headers',
95
+ :hidden_headers => '',
96
+ :show_content_type => false,
97
+ :content_type_color => '000080',
98
+ :replacement_color => 'f08080',
99
+ :replacement_char => '<?>',
100
+ :link_color => '700000',
101
+ :author => '',
102
+ :subject => 'mail-subject',
103
+ :keywords => '',
104
+ :title => '',
105
+ :save_attachments => 'pdf',
106
+ :attachment_link_color => '008000',
107
+ :pdf_reader => ''
108
+ }
109
+
110
+ @@Types = {
111
+ :pdf_prefix => :string,
112
+ :pdf_suffix => :string,
113
+ :log_level => :choose_text,
114
+ :log_file => :file,
115
+ :page_size => :choose_text,
116
+ :page_layout => :choose_text,
117
+ :regular_font => :font,
118
+ :bold_font => :font,
119
+ :italic_font => :font,
120
+ :bold_italic_font => :font,
121
+ :visible_headers => :stringlist,
122
+ :hidden_headers => :stringlist,
123
+ :show_content_type => :bool,
124
+ :content_type_color => :hexcolor,
125
+ :replacement_color => :hexcolor,
126
+ :replacement_char => :string,
127
+ :link_color => :hexcolor,
128
+ :author => :string,
129
+ :subject => :string,
130
+ :keywords => :string,
131
+ :title => :string,
132
+ :save_attachments => :choose_text,
133
+ :attachment_link_color => :hexcolor,
134
+ :pdf_reader => :file
135
+ }
136
+ =begin UNUSED
137
+ @@Pane_content = {
138
+ :show_content_type => :bool,
139
+ :regular_font => :file,
140
+ :bold_font => :file,
141
+ :italic_font => :file,
142
+ :bold_italic_font => :file,
143
+ :attachment_link_color => :hexcolor,
144
+ :visible_headers => :stringlist,
145
+ :hidden_headers => :stringlist,
146
+ :save_attachments => :choose_text,
147
+ :content_type_color => :hexcolor,
148
+ :replacement_color => :hexcolor,
149
+ :replacement_char => :string,
150
+ :link_color => :hexcolor,
151
+
152
+ }
153
+ @@Pane_pdf = {
154
+ :pdf_prefix => :string,
155
+ :pdf_suffix => :string,
156
+ :page_size => :choose_text,
157
+ :page_layout => :choose_text,
158
+ :author => :string,
159
+ :subject => :string,
160
+ :keywords => :string,
161
+ :title => :string,
162
+ }
163
+ @@Pane_program = {
164
+ :log_level => :choose_text,
165
+ :log_file => :file,
166
+ :pdf_reader => :file
167
+ }
168
+ =end
169
+ @@Choices = {
170
+ :log_level => [:unknown, :debug, :info, :error, :fatal, :warn],
171
+ :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},
172
+ :page_layout => [:portrait, :landscape],
173
+ :save_attachments => [:pdf, :path, :false]
174
+ }
175
+
176
+ @@Constraints = {
177
+ :pdf_reader => [:exist, :file, :executable],
178
+ :save_attachments => [:exist, :directory, :writable],
179
+ :bold_font => [:exist, :file, :readable],
180
+ :italic_font => [:exist, :file, :readable],
181
+ :bold_italic_font => [:exist, :file, :readable],
182
+ :regular_font => [:exist, :file, :readable],
183
+ }
184
+
185
+ class Error < RuntimeError
186
+ end
187
+ class InvalidOptionError < Error
188
+ end
189
+ class NoValueError < Error
190
+ end
191
+
192
+ def initialize(name, value = nil)
193
+ keys = @@Types.keys
194
+ nkey = name.downcase.gsub(' ', '_').to_sym
195
+ @name = name
196
+ if(keys.include?(nkey))
197
+ debug("configuring " << nkey.to_s << ", value is " << value.to_s)
198
+
199
+ @display_name = trl(name)
200
+ @otype = @@Types[nkey]
201
+ debug('set otype ' << @otype.to_s)
202
+
203
+ @choices = @@Choices[nkey] if @@Choices.keys.include?(nkey)
204
+ @doc = @@Doc[nkey]
205
+ @default = @@Default[nkey]
206
+ @constraints = @@Constraints[nkey]
207
+ begin
208
+ if(!@constraints && @choices && !@choices.include?(value ? value.to_sym : ''.to_sym) )
209
+ message = trl("Value %s is not permitted for option %s!") %[(value && !value.empty? ? trl(value.to_s) : '(empty)') , name]
210
+ message << "\nSetting default-value %s" %(@default.to_s )
211
+ warn(message)
212
+ msg_dialog(message, 'warning' )
213
+
214
+ @value = ConfValue.new(@name, @default)
215
+ else
216
+ @value = ConfValue.new(@name, value)
217
+ end
218
+ rescue Exception => ex
219
+ error('Error in configuration-option ' << @name << ': ' << ex.message)
220
+ end
221
+
222
+ else
223
+ @doc = 'N I L'
224
+ @default = 'N I L'
225
+ msg = trl("Unknown configuration-option %s!") %name
226
+ error(msg)
227
+ raise InvalidOptionError, "An option \"" << name << "\" does not exist!" ;
228
+ end
229
+ debug "Option #{name} is initialized"
230
+ end
231
+
232
+ attr_reader :name, :display_name, :type, :default, :choices, :constraints
233
+
234
+ def to_s
235
+ self.class.name.dup << ': name = ' << @name << ', value = ' << (@value ? @value.to_s : 'N I L') << ', default = ' << @default.to_s << ', doc = ' << @doc
236
+ end
237
+
238
+ def value=(value)
239
+ if @value
240
+ @value.value = value
241
+ else
242
+ @value = ConfValue.new(value)
243
+ end
244
+ end
245
+
246
+ def value
247
+ if (@otype != :bool && !@value)
248
+ msg = trl("No value has been set for option %s.") %(@name)
249
+ warn(msg)
250
+ nil
251
+ elsif @value
252
+ @value.value
253
+ else
254
+ nil
255
+ end
256
+ end
257
+
258
+ def type
259
+ @otype
260
+ end
261
+
262
+ def display_value
263
+ @value.display_value
264
+ end
265
+
266
+ def doc
267
+ if !@doc
268
+ error(trl("Option %s is missing a documentation.") %(@name) )
269
+ else
270
+ @doc
271
+ end
272
+ end
273
+ end
274
+
@@ -0,0 +1,58 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2011-2023, 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 WTFPL 2.0 or later version of the LICENSE. *
8
+ * See https://wtfpl2.com/ for details. *
9
+ * *
10
+ * This program is distributed in the hope that it will be useful, *
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
13
+ * *
14
+ ***************************************************************************/
15
+ =end
16
+ # An object of this type represents the value of a configuration-option in case
17
+ # that it needs to be translated for display in the GUI, but not for the
18
+ # persistent configuration.
19
+ #
20
+ # Not every value needs to be encapsulated in a ConfValue object. Test, if there
21
+ # is a translation to read with value.respond_to?(:display_value). In case that a
22
+ # translation exists, persist obj.value. Otherwise show and persist the value
23
+ # as is.
24
+ # Examples: 'A4', 'A5', 'letter' will not be translated, but used and displayed
25
+ # in the same way, as 'A4', 'A5' or 'letter'. You do not need a ConfValue in that
26
+ # case.
27
+ #
28
+ # 'landscape' and 'portrait' in contrast may be displayed as 'paysage' and
29
+ # 'portrait' in French, 'Hochformat' and 'Querformat' in the German locale, while
30
+ # the configuration file will only contain 'landscape' or 'portrait'.
31
+ #
32
+ # See conf_option.rb for actual uses.
33
+
34
+ require_relative '../translating'
35
+
36
+ class ConfValue
37
+ include Translating
38
+ def initialize(label, value)
39
+ @label = label
40
+ @value = value
41
+ @value ||= ''
42
+ if(value.respond_to?(:to_ary) )
43
+ @display_value = @value.map{|v| trl(v) }
44
+ else
45
+ @display_value = trl(value.to_s, false)
46
+ end
47
+ end
48
+ def to_s
49
+ self.class.name.dup << ': value = ' << @value.to_s << ', display_value = ' << @display_value.to_s
50
+ end
51
+
52
+ attr_accessor :value
53
+ attr_reader :display_value
54
+
55
+ end
56
+
57
+ # EOF
58
+