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,625 @@
|
|
1
|
+
#!/usr/local/bin/env ruby
|
2
|
+
#encoding: UTF-8
|
3
|
+
=begin
|
4
|
+
/***************************************************************************
|
5
|
+
* ©2012-2016, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
6
|
+
* *
|
7
|
+
* This program is free software; you can redistribute it and/or modify *
|
8
|
+
* it under the terms of the GNU General Public License as published by *
|
9
|
+
* the Free Software Foundation; either version 3 of the License, or *
|
10
|
+
* (at your option) any later version. *
|
11
|
+
* *
|
12
|
+
* This program is distributed in the hope that it will be useful, *
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
15
|
+
* GNU General Public License for more details. *
|
16
|
+
* *
|
17
|
+
* You should have received a copy of the GNU General Public License *
|
18
|
+
* along with this program; if not, write to the *
|
19
|
+
* Free Software Foundation, Inc., *
|
20
|
+
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
21
|
+
***************************************************************************/
|
22
|
+
=end
|
23
|
+
|
24
|
+
require_relative '../logging'
|
25
|
+
require_relative '../translating'
|
26
|
+
require_relative 'message_dialog'
|
27
|
+
require_relative '../cremefraiche'
|
28
|
+
|
29
|
+
CHECK_GEMS = false
|
30
|
+
|
31
|
+
if(CHECK_GEMS)
|
32
|
+
['nokogiri', 'prawn', 'mail', 'gtk3', 'escape'].each do |g|
|
33
|
+
begin
|
34
|
+
gem g
|
35
|
+
rescue LoadError
|
36
|
+
missing_gems = true
|
37
|
+
puts ' => ' << (Translating::trl("PSE wait, installing required gem '%s'") %g)
|
38
|
+
puts ' ' << Translating::trl('This may take some time') << ' ...'
|
39
|
+
begin
|
40
|
+
if !system 'gem install ' << g
|
41
|
+
exit false
|
42
|
+
end
|
43
|
+
rescue Exception => e
|
44
|
+
puts ' ' << (Translating::trl("Cannot install '%s'") %g) << ': ' << e.message
|
45
|
+
exit false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
Gem.clear_paths
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
require 'gtk3'
|
53
|
+
require 'ostruct'
|
54
|
+
require_relative '../file_checking'
|
55
|
+
require_relative 'ConfDialog'
|
56
|
+
require_relative 'HowtoDialog'
|
57
|
+
require_relative 'AboutDialog'
|
58
|
+
require_relative 'ButtonLabel'
|
59
|
+
|
60
|
+
|
61
|
+
DLG_ERROR = :error
|
62
|
+
DLG_INFO = :info
|
63
|
+
DLG_WARN = :warning
|
64
|
+
|
65
|
+
# maximum length of the file-names before they are clipped
|
66
|
+
MAX_FN_LEN = 35
|
67
|
+
|
68
|
+
HOME = ENV['HOME'].dup
|
69
|
+
|
70
|
+
# the list of eml-files is stored each time upon quitting
|
71
|
+
LIST_FILE = HOME << File::Separator << '.cremefraiche.lst'
|
72
|
+
|
73
|
+
# String-constants
|
74
|
+
CLICKED = 'clicked'
|
75
|
+
LN = "\n"
|
76
|
+
FIELD_SEPARATOR = '#'
|
77
|
+
LINE_SEPARATOR = nil
|
78
|
+
|
79
|
+
=begin
|
80
|
+
A simple user-interface for Crème Fraiche.
|
81
|
+
=end
|
82
|
+
|
83
|
+
class CremeFraicheGui
|
84
|
+
include Translating
|
85
|
+
include Logging
|
86
|
+
@@GD = File::expand_path(File::dirname(__FILE__) ) + File::Separator if !defined?(@@GD)
|
87
|
+
def initialize(args = nil)
|
88
|
+
init_logger( ($CONF.log_file ? $CONF.log_file : STDOUT), ($CONF.log_level ? $CONF.log_level : Logger::UNKNOWN) )
|
89
|
+
@log.info('$CONF is ' << $CONF.to_s)
|
90
|
+
@log.info('@log.level is ' << @log.level.to_s)
|
91
|
+
@log.debug('init gui')
|
92
|
+
prog_info = CremeFraiche::prog_info()
|
93
|
+
@eml_files = {}
|
94
|
+
|
95
|
+
@window = Gtk::Window.new(prog_info[:app_name])
|
96
|
+
@window.set_default_size(300, 100)
|
97
|
+
@window.set_icon($ICON_DIR + 'icon.xpm');
|
98
|
+
# populate the window
|
99
|
+
create
|
100
|
+
# prepare an object to collect the tooltips
|
101
|
+
@tooltips = Gtk::Tooltip.new
|
102
|
+
# create some static tool-tips for the static elements
|
103
|
+
set_tooltips
|
104
|
+
# connect the static buttons with the functionality
|
105
|
+
connect_buttons
|
106
|
+
# the transformations in progress
|
107
|
+
@threads = Array.new
|
108
|
+
# restore list of files from previous session
|
109
|
+
read_list
|
110
|
+
# make sure, that there will be only one file-dialog at a time.
|
111
|
+
@fdialog = nil
|
112
|
+
# display on screen
|
113
|
+
show
|
114
|
+
end
|
115
|
+
private
|
116
|
+
|
117
|
+
def show
|
118
|
+
@window.show
|
119
|
+
Gtk::main
|
120
|
+
end
|
121
|
+
|
122
|
+
def create
|
123
|
+
# layout-elements
|
124
|
+
top_vbox = Gtk::Box.new(:vertical, 5)
|
125
|
+
top_vbox.border_width = 5
|
126
|
+
|
127
|
+
eml_vbox = Gtk::Box.new(:vertical, 2)
|
128
|
+
|
129
|
+
eml_hbox = Gtk::Box.new(:horizontal, 5)
|
130
|
+
eml_hbox.border_width = 5
|
131
|
+
|
132
|
+
# the text-entry for the chosen file-names
|
133
|
+
@eml_input = Gtk::Entry.new
|
134
|
+
@eml_input.width_chars = 33
|
135
|
+
@eml_input.height_request = 25
|
136
|
+
# the button to add a file-name to the list
|
137
|
+
@eml_add_button = Gtk::Button.new
|
138
|
+
@eml_add_button.add(ButtonLabel.new( trl('Add _file') ))
|
139
|
+
@eml_add_button.height_request = 0.0
|
140
|
+
# a button to open a file-chooser
|
141
|
+
@eml_button = Gtk::Button.new()
|
142
|
+
@eml_button.add(ButtonLabel.new(trl('_Choose'), @@GD + "gtk-open.xpm"))
|
143
|
+
@eml_button.height_request = 0.0
|
144
|
+
# organize the above elements
|
145
|
+
eml_hbox.pack_start(@eml_button, :expand => false, :fill => false)
|
146
|
+
eml_hbox.pack_start(@eml_input, :expand => true, :fill => true)
|
147
|
+
eml_hbox.pack_end(@eml_add_button, :expand => false, :fill => false)
|
148
|
+
# a group of horizontally aligned buttons
|
149
|
+
button_box = Gtk::ButtonBox.new(:horizontal)
|
150
|
+
button_box.layout_style = Gtk::ButtonBoxStyle::START
|
151
|
+
|
152
|
+
@quit_button = Gtk::Button.new()
|
153
|
+
@quit_button.add(ButtonLabel.new(trl('_Quit'), @@GD + "gtk-quit.xpm" ))
|
154
|
+
@start_button = Gtk::Button.new()
|
155
|
+
@start_button.add(ButtonLabel.new(trl('Sta_rt'), @@GD + "gtk-execute.xpm"))
|
156
|
+
|
157
|
+
@stop_button = Gtk::Button.new()
|
158
|
+
@stop_button.add(ButtonLabel.new(trl('Sto_p'), @@GD + "gtk-stop.xpm") )
|
159
|
+
=begin
|
160
|
+
@save_button = Gtk::Button.new()
|
161
|
+
@save_button.add(ButtonLabel.new(trl('_Save'), @@GD + "gtk-save.xpm") )
|
162
|
+
=end
|
163
|
+
@config_button = Gtk::Button.new()
|
164
|
+
@config_button.add(ButtonLabel.new(trl('_Configure'), @@GD + "gtk-properties.xpm" ))
|
165
|
+
|
166
|
+
@about_button = Gtk::Button.new()
|
167
|
+
@about_button.add(ButtonLabel.new(trl('_About'), @@GD + "gtk-about.xpm"))
|
168
|
+
|
169
|
+
@howto_button = Gtk::Button.new()
|
170
|
+
@howto_button.add(ButtonLabel.new(trl('_Howto'), @@GD + "help.xpm"))
|
171
|
+
|
172
|
+
button_box.pack_start(@start_button, :expand => false, :fill => false)
|
173
|
+
button_box.pack_start(@stop_button, :expand => false, :fill => false)
|
174
|
+
# button_box.pack_start(@save_button, false)
|
175
|
+
button_box.pack_start(@quit_button, :expand => false, :fill => false)
|
176
|
+
button_box.pack_start(@config_button, :expand => false, :fill => false)
|
177
|
+
button_box.pack_start(@about_button, :expand => false, :fill => false)
|
178
|
+
button_box.pack_start(@howto_button, :expand => false, :fill => false)
|
179
|
+
# a table to show chosen file-names and some controls
|
180
|
+
@table = Gtk::Table.new(1,5)
|
181
|
+
tframe = Gtk::Frame.new()
|
182
|
+
tframe.add(@table)
|
183
|
+
# organize all of the above created elements on the window
|
184
|
+
eml_vbox.pack_start(eml_hbox, :expand => false)
|
185
|
+
eml_vbox.pack_end(tframe, :expand => false)
|
186
|
+
|
187
|
+
|
188
|
+
@status_label = Gtk::Label.new()
|
189
|
+
|
190
|
+
top_vbox.pack_start(eml_vbox)
|
191
|
+
top_vbox.pack_end(@status_label)
|
192
|
+
top_vbox.pack_end(button_box)
|
193
|
+
# initialize the table
|
194
|
+
refresh_table
|
195
|
+
# display all
|
196
|
+
top_vbox.show_all
|
197
|
+
@window.add(top_vbox)
|
198
|
+
@mthr = nil
|
199
|
+
end
|
200
|
+
|
201
|
+
=begin
|
202
|
+
creates and allocates some static tool-tips
|
203
|
+
=end
|
204
|
+
def set_tooltips
|
205
|
+
@eml_button.set_tooltip_text(trl('Choose an eml-file to transform') )
|
206
|
+
@eml_input.set_tooltip_text trl('Enter or choose an eml-file to transform')
|
207
|
+
@eml_add_button.set_tooltip_text trl('First choose an eml-file, then add it to the list')
|
208
|
+
@quit_button.set_tooltip_text trl('Quit program')
|
209
|
+
@start_button.set_tooltip_text trl('Transform the active files')
|
210
|
+
@stop_button.set_tooltip_text trl('Terminate all transformations in progress')
|
211
|
+
|
212
|
+
@about_button.set_tooltip_text trl('About this program')
|
213
|
+
@howto_button.set_tooltip_text trl('Howto Crème Fraiche GUI')
|
214
|
+
end
|
215
|
+
|
216
|
+
=begin
|
217
|
+
unused for the time.
|
218
|
+
=end
|
219
|
+
def review_configuration()
|
220
|
+
|
221
|
+
end
|
222
|
+
=begin
|
223
|
+
connect the existing buttons to their functionality
|
224
|
+
=end
|
225
|
+
def connect_buttons
|
226
|
+
@eml_button.signal_connect(CLICKED) do
|
227
|
+
eml = choose_eml
|
228
|
+
if(eml)
|
229
|
+
@eml_input.text = eml
|
230
|
+
else
|
231
|
+
status_message(trl('No file chosen'), 2)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
@eml_add_button.signal_connect(CLICKED) do
|
235
|
+
if @eml_input.text && !@eml_input.text.empty?
|
236
|
+
add_eml(@eml_input.text)
|
237
|
+
else
|
238
|
+
status_message(trl('No file chosen, none added'), 2 )
|
239
|
+
end
|
240
|
+
end
|
241
|
+
@quit_button.signal_connect(CLICKED) do
|
242
|
+
stop()
|
243
|
+
save()
|
244
|
+
Gtk::main_quit()
|
245
|
+
end
|
246
|
+
@window.signal_connect("destroy") do
|
247
|
+
stop()
|
248
|
+
save()
|
249
|
+
Gtk.main_quit
|
250
|
+
end
|
251
|
+
@about_button.signal_connect(CLICKED) do
|
252
|
+
@about_button.sensitive=false
|
253
|
+
db = Proc.new() { @about_button.sensitive=true }
|
254
|
+
ad = AboutDialog.new(:on_destroy => db)
|
255
|
+
end
|
256
|
+
@config_button.signal_connect(CLICKED) do
|
257
|
+
@config_button.sensitive=false
|
258
|
+
cb = Proc.new() do
|
259
|
+
@config_button.sensitive=true
|
260
|
+
review_configuration()
|
261
|
+
end
|
262
|
+
cd = ConfDialog.new(:on_destroy => cb)
|
263
|
+
end
|
264
|
+
@howto_button.signal_connect(CLICKED) do
|
265
|
+
@howto_button.sensitive=false
|
266
|
+
rb = Proc.new() { @howto_button.sensitive=true }
|
267
|
+
hd = HowtoDialog.new(:on_destroy => rb)
|
268
|
+
end
|
269
|
+
@start_button.signal_connect(CLICKED) do
|
270
|
+
@start_button.sensitive=false
|
271
|
+
@eml_files.each_value {|ctx| ctx.ok.set_file(nil)}
|
272
|
+
transform()
|
273
|
+
end
|
274
|
+
@stop_button.signal_connect(CLICKED) do
|
275
|
+
stop()
|
276
|
+
end
|
277
|
+
=begin
|
278
|
+
@save_button.signal_connect(CLICKED) do
|
279
|
+
save()
|
280
|
+
end
|
281
|
+
=end
|
282
|
+
end
|
283
|
+
|
284
|
+
=begin
|
285
|
+
terminate all running transformations
|
286
|
+
=end
|
287
|
+
def stop( pause = 2)
|
288
|
+
if(@threads && !@threads.empty?)
|
289
|
+
@threads.each do |th|
|
290
|
+
th.terminate
|
291
|
+
th.join
|
292
|
+
end
|
293
|
+
refresh_table
|
294
|
+
status_message(trl('transformation stopped'), 2)
|
295
|
+
@start_button.sensitive=true
|
296
|
+
else
|
297
|
+
status_message(trl('No transformations in progress'), 2)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
=begin
|
301
|
+
restore the list of eml-files to transform from a previously saved
|
302
|
+
file.
|
303
|
+
=end
|
304
|
+
def read_list
|
305
|
+
# BUGFIX: make sure, that the list-file exists already
|
306
|
+
lf = File.open(LIST_FILE, 'a+')
|
307
|
+
lf.close
|
308
|
+
# END BUGFIX
|
309
|
+
# BUGFIX: do not split into arbitrary chunks of text, DUMBO!
|
310
|
+
list = File.readlines(LIST_FILE)
|
311
|
+
entry = []
|
312
|
+
list.each do |line|
|
313
|
+
entry = line.chomp.split(FIELD_SEPARATOR)
|
314
|
+
add_eml(entry[0], entry[1] == true.to_s)
|
315
|
+
end
|
316
|
+
#end BUGFIX
|
317
|
+
end
|
318
|
+
|
319
|
+
=begin
|
320
|
+
Save the list of files for later transformations, overwrite
|
321
|
+
previous file-content.
|
322
|
+
=end
|
323
|
+
def save()
|
324
|
+
list = []
|
325
|
+
@eml_files.each_pair do |eml, ctx|
|
326
|
+
# Ensure, that there is not more than one FIELD_SEPARATOR in the list-entry.
|
327
|
+
list << (eml.dup.gsub(FIELD_SEPARATOR, '*') << FIELD_SEPARATOR << ctx.active.to_s)
|
328
|
+
end
|
329
|
+
File.write(LIST_FILE, list.join(LN))
|
330
|
+
end
|
331
|
+
=begin
|
332
|
+
re-construct the table from the list of chosen file-names
|
333
|
+
or show a message, if no files have ben chosen yet.
|
334
|
+
=end
|
335
|
+
def refresh_table
|
336
|
+
# remove all contents from the current table
|
337
|
+
@table.each {|w| @table.remove(w) }
|
338
|
+
if(!@eml_files.empty?)
|
339
|
+
# create a table header in the cells of the first row
|
340
|
+
[trl('active'), trl('Ok'), trl('file'), trl('size'), trl('remove')].each_with_index do |t, i|
|
341
|
+
label = Gtk::Label.new
|
342
|
+
label.set_markup("<b>#{t}</b>")
|
343
|
+
@table.attach(label, i, i + 1, 0, 1)
|
344
|
+
end
|
345
|
+
# fill the remainder of the table with file-names and
|
346
|
+
# control-elements
|
347
|
+
@eml_files.each_pair do |file, ctx|
|
348
|
+
text = file.dup
|
349
|
+
filename = File::basename(file)
|
350
|
+
# shorten file-names, if need be
|
351
|
+
if text.length > MAX_FN_LEN + 3
|
352
|
+
num_del = text.length - MAX_FN_LEN - 3
|
353
|
+
text = "..." + text[num_del, text.length]
|
354
|
+
end
|
355
|
+
fl = Gtk::Label.new(text)
|
356
|
+
fl.set_alignment( 1, 0)
|
357
|
+
# store the reference to the label
|
358
|
+
ctx.label = fl
|
359
|
+
# show the full file-path in the tool-tip to the text-label
|
360
|
+
fl.set_tooltip_text(file)
|
361
|
+
# a check-button to activate the transformation of the very file
|
362
|
+
cb = Gtk::CheckButton.new()
|
363
|
+
# set checkbox active or not
|
364
|
+
cb.set_active(ctx.active)
|
365
|
+
cb.set_tooltip_text trl("Controls whether the file '%s' is transformed or not.") %filename
|
366
|
+
# an image which will indicate success
|
367
|
+
ctx.ok = Gtk::Image.new()
|
368
|
+
# a button to remove the file from the list
|
369
|
+
rb = Gtk::Button.new
|
370
|
+
rb.height_request = 5
|
371
|
+
rb.add(ButtonLabel.new('', @@GD + "gtk-remove.xpm" ))
|
372
|
+
rb.set_tooltip_text trl("Remove the file '%s' from the list") %filename
|
373
|
+
begin
|
374
|
+
fs = Gtk::Label.new(readable_size(File::size(file)) )
|
375
|
+
fs.set_alignment(0.8,0)
|
376
|
+
fs.set_tooltip_text trl("Size of %s") %filename
|
377
|
+
# add the above elements to the table
|
378
|
+
@table.n_rows = @table.n_rows + 1
|
379
|
+
@table.attach(cb, 0, 1, @table.n_rows - 1, @table.n_rows, :shrink )
|
380
|
+
@table.attach(ctx.ok, 1, 2, @table.n_rows - 1, @table.n_rows )
|
381
|
+
@table.attach(fl, 2, 3, @table.n_rows - 1, @table.n_rows )
|
382
|
+
@table.attach(fs, 3, 4, @table.n_rows - 1, @table.n_rows )
|
383
|
+
@table.attach(rb, 4, 5, @table.n_rows - 1, @table.n_rows, :shrink )
|
384
|
+
# connect the 'remove' button to its functionality
|
385
|
+
rb.signal_connect(CLICKED) do
|
386
|
+
del_eml(file)
|
387
|
+
end
|
388
|
+
cb.signal_connect(CLICKED) do
|
389
|
+
toggle_active(file)
|
390
|
+
end
|
391
|
+
rescue Exception => ex
|
392
|
+
msg = trl("File %s cannot be handled! (%s)" %[file, ex.message] )
|
393
|
+
end
|
394
|
+
end
|
395
|
+
else
|
396
|
+
# no files have been chosen yet, report this fact.
|
397
|
+
mlabel = Gtk::Label.new()
|
398
|
+
mlabel.set_markup("<span background='#f0a0a0'>#{trl('No files have been chosen for transformation') }</span>" )
|
399
|
+
@table.attach(mlabel, 0, 3, 0, 1)
|
400
|
+
end
|
401
|
+
# display the table
|
402
|
+
@table.show_all
|
403
|
+
end
|
404
|
+
=begin
|
405
|
+
excempt a file from the transformation, but leave it in the list.
|
406
|
+
=end
|
407
|
+
def toggle_active(file = nil)
|
408
|
+
if(file)
|
409
|
+
isso = @eml_files[file].active
|
410
|
+
@eml_files[file].active = (isso ? false : true)
|
411
|
+
end
|
412
|
+
end
|
413
|
+
=begin
|
414
|
+
remove a file from the list of files that can be transformed.
|
415
|
+
=end
|
416
|
+
def del_eml(file = nil)
|
417
|
+
if(file )
|
418
|
+
@eml_files.delete_if {|f, context| f == file }
|
419
|
+
refresh_table
|
420
|
+
status_message(trl('File removed'), 2 )
|
421
|
+
end
|
422
|
+
end
|
423
|
+
=begin
|
424
|
+
add a file to the list of files that can be transformed
|
425
|
+
=end
|
426
|
+
def add_eml(file = nil, activate = true)
|
427
|
+
if(file )
|
428
|
+
if( !@eml_files.keys.include?(file) )
|
429
|
+
msg = File_Checking::file_check(file, :exist?, :file?, :readable?)
|
430
|
+
if !msg
|
431
|
+
file_ctx = OpenStruct.new
|
432
|
+
file_ctx.active = activate
|
433
|
+
@eml_files[file] = file_ctx
|
434
|
+
refresh_table
|
435
|
+
status_message(trl('File added'), 2)
|
436
|
+
else
|
437
|
+
msg = trl("Cannot add the file %s (%s)") %[file, msg]
|
438
|
+
@log.warn(msg)
|
439
|
+
msg_dialog(msg, DLG_ERROR)
|
440
|
+
end
|
441
|
+
else
|
442
|
+
status_message(trl('File is already in the list'))
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
=begin
|
447
|
+
open a file-chooser and allow the selection of a file for transformation.
|
448
|
+
=end
|
449
|
+
def choose_eml
|
450
|
+
# only if the dialog is not currently open
|
451
|
+
if(!@fdialog)
|
452
|
+
@fdialog = Gtk::FileChooserDialog.new(:title => trl("Choose EML-File"),
|
453
|
+
:parent => nil,
|
454
|
+
:action => :open,
|
455
|
+
:buttons => [[:cancel, :cancel],
|
456
|
+
[:open, :accept]])
|
457
|
+
if(@eml_input.text && ! @eml_input.text.empty?)
|
458
|
+
# start where the currently selected file has been located.
|
459
|
+
@fdialog.filename = @eml_input.text
|
460
|
+
else
|
461
|
+
# or start in the user's home-directory
|
462
|
+
@fdialog.filename = HOME
|
463
|
+
@fdialog.filename ||= Dir::pwd
|
464
|
+
end
|
465
|
+
# open the file-chooser, return the selected file-name
|
466
|
+
eml = (@fdialog.run == Gtk::ResponseType::ACCEPT ? @fdialog.filename : nil)
|
467
|
+
@fdialog.destroy
|
468
|
+
# verify that the file is useable
|
469
|
+
msg = File_Checking.file_check(eml, :exist?, :file?, :readable?)
|
470
|
+
if(msg)
|
471
|
+
@log.error(msg) if @log
|
472
|
+
msg_dialog(msg, DLG_ERROR)
|
473
|
+
eml = nil
|
474
|
+
end
|
475
|
+
@eml_add_button.set_tooltip_text( trl('Add file to the list of files to transform')) if eml
|
476
|
+
@fdialog = nil
|
477
|
+
# return the file-name
|
478
|
+
return eml
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
=begin
|
483
|
+
# Any message, related to the GUI and the user-input can be
|
484
|
+
# displayed. The second parameter determines, if it is
|
485
|
+
# an information or an error and makes the dialog choose its
|
486
|
+
# icon accordingly.
|
487
|
+
def msg_dialog(msg, type)
|
488
|
+
CremeFraicheGui::msg_dialog(msg, type)
|
489
|
+
end
|
490
|
+
|
491
|
+
def self::msg_dialog(msg, type)
|
492
|
+
nick = type && type.respond_to?(:nick) ? type.nick : type.to_s
|
493
|
+
msg_dialog(type, msg)
|
494
|
+
dialog = Gtk::MessageDialog.new(:parent => nil,
|
495
|
+
:flags => 0,
|
496
|
+
:destroy_with_parent,
|
497
|
+
:type => type,
|
498
|
+
:buttons => :close,
|
499
|
+
"%s: \"%s\"" %[Translating::trl(nick.to_s), msg])
|
500
|
+
dialog.set_title(DLG_INFO == type ? 'Info' : 'Error' )
|
501
|
+
dialog.run
|
502
|
+
dialog.destroy
|
503
|
+
return msg
|
504
|
+
end
|
505
|
+
=end
|
506
|
+
|
507
|
+
def status_wait(wait_message )
|
508
|
+
@mthr.terminate if @mthr
|
509
|
+
@mthr.join if @mthr
|
510
|
+
@mthr = Thread.new do
|
511
|
+
loop do
|
512
|
+
red = rand(0xe0...0xff)
|
513
|
+
green = rand(0xe0...0xff)
|
514
|
+
blue = 0xc0
|
515
|
+
@status_label.set_markup("<span background='#%02x%02x%02x'>#{wait_message}</span>" %[red, green, blue] )
|
516
|
+
sleep 0.3
|
517
|
+
end
|
518
|
+
end
|
519
|
+
end
|
520
|
+
def status_message(msg, time = 2)
|
521
|
+
@mthr.terminate if @mthr
|
522
|
+
@mthr.join if @mthr
|
523
|
+
@mthr = Thread.new do
|
524
|
+
@status_label.text = msg
|
525
|
+
if time && time > 0
|
526
|
+
sleep time
|
527
|
+
@status_label.text = ''
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
def transform()
|
533
|
+
if !@eml_files.empty?
|
534
|
+
status_message(trl("Transforming, wait..."), nil)
|
535
|
+
@threads.clear if @threads && !@threads.empty?
|
536
|
+
active_files = @eml_files.values.count {|ctx| ctx.active}
|
537
|
+
if(active_files > 0)
|
538
|
+
@eml_files.each_pair do |file, ctx|
|
539
|
+
if(ctx.active)
|
540
|
+
ctx.label.set_markup(file)
|
541
|
+
@threads << Thread.new do
|
542
|
+
wait_th = status_wait(trl("Transforming, wait..."))
|
543
|
+
cf = CremeFraiche.new(file)
|
544
|
+
if(cf.msg && !cf.msg.empty?)
|
545
|
+
msg_dialog(cf.msg, DLG_ERROR)
|
546
|
+
end
|
547
|
+
|
548
|
+
wait_th.terminate
|
549
|
+
wait_th = nil
|
550
|
+
active_files -= 1;
|
551
|
+
ctx.label.set_markup("<span background='#c0f0c0'><b>#{file}</b></span>")
|
552
|
+
ctx.ok.set_file(@@GD + 'okay.xpm')
|
553
|
+
#status_message( trl("file %s has been transformed.") %File::basename(file), 2)
|
554
|
+
if(active_files == 0)
|
555
|
+
status_message( trl("All done"), 5 )
|
556
|
+
@threads.clear
|
557
|
+
@start_button.sensitive=true
|
558
|
+
@eml_files.values.each{|ctx| ctx.label.set_markup(ctx.label.text) }
|
559
|
+
end
|
560
|
+
end
|
561
|
+
end
|
562
|
+
@table.show_all
|
563
|
+
end
|
564
|
+
else
|
565
|
+
status_message(trl('No files have been selected for transformation'), 2)
|
566
|
+
@start_button.sensitive=true
|
567
|
+
end
|
568
|
+
else
|
569
|
+
status_message(trl('Empty file-list! Doing nothing!'), 2)
|
570
|
+
@start_button.sensitive=true
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
def run_reader(br, file = nil)
|
575
|
+
msg = nil
|
576
|
+
if(br && ! br.empty?)
|
577
|
+
begin
|
578
|
+
fork_sym = (RUBY_PLATFORM =~ /win/) ? '' : ' &'
|
579
|
+
if(file)
|
580
|
+
exec_command = "%s %s%s" %[br, file, fork_sym]
|
581
|
+
else
|
582
|
+
exec_command = "%s %s" %[br, fork_sym]
|
583
|
+
end
|
584
|
+
@log.debug "exec-command will be %s" %exec_command if @log
|
585
|
+
hr = system exec_command
|
586
|
+
if(!hr)
|
587
|
+
msg = trl("Cannot open the PDF-reader!") << "\n"
|
588
|
+
msg << trl("Please verify, that %s is correctly spelled or use another reader.", %("\" << br << "\"") )
|
589
|
+
else
|
590
|
+
@hdialog.destroy
|
591
|
+
end
|
592
|
+
rescue Exception => ex
|
593
|
+
msg = trl("Cannot open the PDF-reader XX", ex)
|
594
|
+
end
|
595
|
+
else
|
596
|
+
msg = trl('No reader selected, skipping Howto.')
|
597
|
+
end
|
598
|
+
@log.error(msg) if @log && msg
|
599
|
+
@log.debug($?.to_s) if @log
|
600
|
+
msg_dialog(msg, DLG_ERROR) if msg
|
601
|
+
end
|
602
|
+
|
603
|
+
|
604
|
+
def readable_size(size)
|
605
|
+
n_size = size
|
606
|
+
symbol = 'b'
|
607
|
+
if(size && size.respond_to?(:to_f))
|
608
|
+
if(size >= 1000000000)
|
609
|
+
n_size = size.to_f/1000000000
|
610
|
+
symbol = 'G'
|
611
|
+
elsif(size >= 1000000)
|
612
|
+
n_size = size.to_f/1000000
|
613
|
+
symbol = 'M'
|
614
|
+
elsif(size >= 1000)
|
615
|
+
n_size = size.to_f/1000
|
616
|
+
symbol = 'K'
|
617
|
+
end
|
618
|
+
end
|
619
|
+
return n_size.round(1).to_s << symbol
|
620
|
+
end
|
621
|
+
end
|
622
|
+
|
623
|
+
# execute if this script is the argument to the ruby-interpreter.
|
624
|
+
# CremeFraicheGui.new(ARGV)
|
625
|
+
|