Fix #3 (Global symbol "@ver" requires explicit package name)
[clawsker.git] / clawsker
1 #!/usr/bin/perl -w
2 #
3 # Clawsker :: A Claws Mail Tweaker
4 #
5 use strict;
6 use encoding 'utf8';
7 use Glib qw(TRUE FALSE);
8 use Gtk2 -init;
9 use POSIX qw(setlocale);
10 use Locale::gettext;
11 use Encode;
12 use Digest::MD5 qw(md5_hex);
13
14 my $NAME = 'clawsker';
15 my $PREFIX = '@PREFIX@';
16 my $LIBDIR = '@LIBDIR@';
17 my $VERSION = '@VERSION@';
18 my $VERBOSE = FALSE;
19 my $CLAWSV = undef;
20 my $main_window = undef;
21
22 my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
23 $locale = "C" unless defined($locale);
24 setlocale (LC_ALL, $locale);
25 bindtextdomain ($NAME, sprintf ('%s/share/locale', $PREFIX));
26 textdomain ($NAME);
27
28 my $SHOWHINTS = FALSE;
29 $SHOWHINTS = TRUE if ($Gtk2::VERSION >= 1.040 and Gtk2->CHECK_VERSION (2, 12, 0));
30
31 sub _ {
32     my $str = shift;
33     my %par = @_;
34     my $xla = gettext ($str);
35     if (scalar(keys(%par)) > 0) {
36         foreach my $key (keys %par) {
37             $xla =~ s/\{$key\}/$par{$key}/g;
38         }
39     }
40     return decode_utf8($xla);
41 }
42
43 # default messages
44 %xl::s = (
45     win_title => _('Claws Mail Hidden Preferences'),
46     about => _('About...'),
47     about_title => _('Clawsker :: A Claws Mail Tweaker'),
48     about_license => _('License:'),
49     about_version => _('Version:'),
50
51     tab_colours => _('Colours'),
52     tab_behaviour => _('Behaviour'),
53     tab_gui => _('GUI'),
54     tab_other => _('Other'),
55     tab_winpos => _('Windows'),
56
57     ab_frame => _('Addressbook'),
58     mem_frame => _('Memory'),
59     msgview_frame => _('Message View'),
60     log_frame => _('Log window'),
61     dnd_frame => _('Drag \'n\' drop'),
62     ssl_frame => _('Secure Sockets Layer'),
63     msgs_frame => _('Messages'),
64     stripes_frame => _('Coloured stripes'),
65     sbar_frame => _('Scroll bars'),
66     mlist_frame => _('Message List'),
67     mview_frame => _('Message View'),
68     compo_frame => _('Compose window'),
69     netm_frame => _('NetworkManager'),
70     diff_frame => _('Viewing patches'),
71
72     l_oth_use_dlg => _('Use detached address book edit dialogue'),
73     h_oth_use_dlg => _('If true use a separate dialogue to edit a person\'s details. Otherwise will use a form embedded in the address book\'s main window.'),
74     l_oth_max_use => _('Maximum memory for message cache (kB)'),
75     h_oth_max_use => _('The maximum amount of memory to use to cache messages, in kilobytes.'),
76     l_oth_min_time => _('Minimun time for cache elements (minutes)'),
77     h_oth_min_time => _('The minimum time in minutes to keep a cache in memory. Caches more recent than this time will not be freed, even if the memory usage is too high.'),
78     l_oth_use_netm => _('Use NetworkManager'),
79     h_oth_use_netm => _('Use NetworkManager to switch offline automatically.'),
80     
81     l_gui_b_unread => _('Show unread messages with bold font'),
82     h_gui_b_unread => _('Show unread messages in the Message List using a bold font.'),
83     l_gui_no_markup => _('Don\'t use markup in compose window'),
84     h_gui_no_markup => _('Don\'t use bold and italic text in Compose dialogue\'s account selector.'),
85     l_gui_dot_lines => _('Use dotted lines in tree view components'),
86     h_gui_dot_lines => _('Use the old dotted line look in the main window tree views (Folder, Message and other lists) instead of the modern lineless look.'),
87     l_gui_h_scroll => _('Enable horizontal scrollbar'),
88     h_gui_h_scroll => _('Enable the horizontal scrollbar in the Message List.'),
89     l_gui_swp_from => _('Display To column instead From column in Sent folder'),
90     h_gui_swp_from => _('Display the recipient\'s email address in a To column of the Sent folder instead of the originator\'s one in a From column.'),
91     l_gui_v_scroll => _('Folder List scrollbar behaviour'),
92     h_gui_v_scroll => _('Specify the policy of vertical scrollbar of Folder List: show always, automatic or hide always.'),
93     l_gui_v_scroll_show => _('Show always'),
94     l_gui_v_scroll_auto => _('Automatic'),
95     l_gui_v_scroll_hide => _('Hide always'),
96     l_gui_from_show => _('From column displays'),
97     h_gui_from_show => _('Selects the data displayed in the From column of the Message List: name, address or both'),
98     l_gui_from_show_name => _('Name only'),
99     l_gui_from_show_addr => _('Address only'),
100     l_gui_from_show_both => _('Both name and address'),
101     l_gui_strip_off => _('Coloured lines contrast'),
102     h_gui_strip_off => _('Specify the value to use when creating alternately coloured lines in tree view components. The smaller the value, the less visible the difference in the alternating colours of the lines.'),
103     l_gui_cursor_v => _('Show cursor'),
104     h_gui_cursor_v => _('Display the cursor in the Message View.'),
105     l_gui_toolbar_d => _('Detachable toolbars'),
106     h_gui_toolbar_d => _('Show handles in the toolbars.'),
107     l_gui_strip_all => _('Use stripes in all tree view components'),
108     h_gui_strip_all => _('Enable alternately coloured lines in all tree view components.'),
109     l_gui_strip_sum => _('Use stripes in Folder List and Message List'),
110     h_gui_strip_sum => _('Enable alternately coloured lines in Message List and Folder List.'),
111     l_gui_two_line_v => _('2 lines per Message List item in 3-column layout'),
112     h_gui_two_line_v => _('Spread Message List information over two lines when using the three column mode.'),
113     l_gui_margin_co => _('Show compose margin'),
114     h_gui_margin_co => _('Shows a small margin in the Compose View.'),
115     l_gui_mview_date => _('Don\'t display localized date'),
116     h_gui_mview_date => _('Toggles localization of date format in Message View'),
117     l_gui_zero_char => _('Zero replacement character'),
118     h_gui_zero_char => _('Replaces \'0\' with the given character in Folder List'),
119
120     l_beh_hover_t => _('Drag \'n\' drop hover timeout (ms)'),
121     h_beh_hover_t => _('Time in milliseconds that will cause a folder tree to expand when the mouse cursor is held over it during drag and drop.'),
122     l_beh_dangerous => _('Don\'t confirm deletions (dangerous!)'),
123     h_beh_dangerous => _('Don\'t ask for confirmation before definitive deletion of emails.'),
124     l_beh_flowed => _('Respect format=flowed in messages'),
125     h_beh_flowed => _('Respect format=flowed on text/plain message parts. This will cause some mails to have long lines, but will fix some URLs that would otherwise be wrapped.'),
126     l_beh_parts_rw => _('Allow writable temporary files'),
127     h_beh_parts_rw => _('Saves temporary files when opening attachment with write bit set.'),
128     l_beh_skip_ssl => _('Don\'t check SSL certificates'),
129     h_beh_skip_ssl => _('Disables the verification of SSL certificates.'),
130     l_beh_up_step => _('Progress bar update step (items)'),
131     h_beh_up_step => _('Update stepping in progress bars.'),
132     l_beh_thread_a => _('Maximum age when threading by subject (days)'),
133     h_beh_thread_a => _('Number of days to include a message in a thread when using "Thread using subject in addition to standard headers".'),
134     l_beh_unsafe_ssl => _('Allow unsafe SSL certificates'),
135     h_beh_unsafe_ssl => _('Allows Claws Mail to remember multiple SSL certificates for a given server/port.'),
136     l_beh_use_utf8 => _('Force UTF-8 for broken mails'),
137     h_beh_use_utf8 => _('Use UTF-8 encoding for broken mails instead of current locale.'),
138     l_beh_warn_dnd => _('Warn on drag \'n\' drop'),
139     h_beh_warn_dnd => _('Display a confirmation dialogue on drag \'n\' drop of folders.'),
140     l_beh_out_ascii => _('Outgoing messages fallback to ASCII'),
141     h_beh_out_ascii => _('If content allows, ASCII will be used to encode outgoing messages, otherwise the user-defined encoding is enforced always.'),
142     l_beh_pp_unsel => _('Primary paste unselects selection'),
143     h_beh_pp_unsel => _('Controls how pasting using middle-click changes the selected text and insertion point.'),
144     l_beh_inline_at => _('Show inline attachments'),
145     h_beh_inline_at => _('Allows hiding inline attachments already shown in mail structure view'),
146
147     l_col_emphasis => _('X-Mailer header'),
148     h_col_emphasis => _('The colour used for the X-Mailer line when its value is Claws Mail.'),
149     l_col_log_err => _('Error messages'),
150     h_col_log_err => _('Colour for error messages in log window.'),
151     l_col_log_in => _('Server messages'),
152     h_col_log_in => _('Colour for messages received from servers in log window.'),
153     l_col_log_msg => _('Standard messages'),
154     h_col_log_msg => _('Colour for messages in log window.'),
155     l_col_log_out => _('Client messages'),
156     h_col_log_out => _('Colour for messages sent to servers in log window.'),
157     l_col_log_warn => _('Warnings'),
158     h_col_log_warn => _('Colour for warning messages in log window.'),
159
160     l_col_diff_add => _('Added lines'),
161     h_col_diff_add => _('Colour for added lines in patches.'),
162     l_col_diff_del => _('Deleted lines'),
163     h_col_diff_del => _('Colour for deleted lines in patches.'),
164     l_col_diff_hunk => _('Hunk lines'),
165     h_col_diff_hunk => _('Color for hunk headers in patches.'),
166
167     l_win_x => _('X position'),
168     h_win_x => _('X coordinate for window\'s top-left corner.'),
169     l_win_y => _('Y position'),
170     h_win_y => _('Y coordinate for window\'s top-left corner.'),
171     l_win_w => _('Width'),
172     h_win_w => _('Window\'s width in pixels.'),
173     l_win_h => _('Height'),
174     h_win_h => _('Window\'s height in pixels.'),
175
176     l_win_main_mx => _('Maximized'),
177     h_win_main_mx => _('Changes window maximized status.'),
178     l_win_main_fs => _('Full-screen'),
179     h_win_main_fs => _('Changes full screen status.'),
180
181     e_error => _('Error: '),
182     e_noclawsrc => _('resource file for Claws Mail was not found.'),
183     e_running => _('seems Claws Mail is currently running, close it first.'),
184     e_requireddir => _('option requires a directory name.'),
185     e_requiredfile => _('option requires a file name.'),
186     e_notadir => _('specified name is not a directory or does not exist.'),
187     e_notafile => _('specified name is not a file or does not exist.'),
188 );
189
190 # all preferences read by load_preferences
191 my %PREFS = ();
192 # values of all preferences handled by clawsker
193 my %HPVALUE = ();
194 # default config dir and file name
195 my $ALTCONFIGDIR = FALSE;
196 my $CONFIGDIR = $ENV{HOME} . '/.claws-mail/';
197 my $CONFIGRC = 'clawsrc';
198
199 # index constants for preference arrays
200 use constant NAME  => 0; # the name on the rc file
201 use constant LABEL => 1; # the label on the GUI
202 use constant DESC  => 2; # the description for the hint/help
203 use constant TYPE  => 3; # data type: bool, int, float, string, color
204 use constant CMVER => 4; # lowest Claws Mail version the feature exists
205 use constant CMDEF => 5; # default value for the preference in Claws Mail
206 use constant GUI   => 6; # GUI element
207
208 # constants for GUI spacing
209 use constant HBOX_SPC => 5;
210 use constant FRAME_SPC => 2;
211 use constant PAGE_SPC => 5;
212
213 # version functions
214
215 sub version_greater_or_equal() {
216     my ($version, $refvers) = @_;
217     my @version = split (/\./, $version);
218     my @refvers = split (/\./, $refvers);
219     while ($#version < $#refvers) {
220         push (@version, '0');
221     }
222     my $idx = 0;
223     while (($idx <= $#refvers) 
224             and (int ($version[$idx]) == int ($refvers[$idx]))) {
225         ++$idx;
226     }
227     return TRUE if (($idx > $#refvers)
228         or (int ($version[$idx]) >= int ($refvers[$idx])));
229     return FALSE;
230 }
231
232 sub get_claws_version() {
233     my @cmbin = (
234         'claws-mail',
235     );
236     my $res = "";
237     foreach my $bin (@cmbin) {
238         $_ = qx/which $bin/;
239         chomp;
240         last if ($_ ne "");
241     }
242     return "" unless ($_); # not installed
243     $_ = qx/$_ -v/;
244     chomp;
245     my @fver = split (/ /);
246     die "Invalid version string" unless ($fver[2] eq "version");
247     my @ver = split (/\./, $fver[3]);
248     $res .= "$ver[0].";
249     $res .= "$ver[1].";
250     if ($ver[2] =~ /(\d+)cvs(\d+)/) {
251         $res .= "$1.$2";
252     }
253     else {
254         $res .= "$ver[2].0";
255     }
256     return $res;
257 }
258
259 # data handlers and auxiliar functions
260
261 sub handle_bool_value {
262     my ($widget, $event, $dataref) = @_;
263     $$dataref = ($widget->get_active ())? '1': '0';
264 }
265
266 sub handle_int_value {
267     my ($widget, $event, $dataref) = @_;
268     $_ = $widget->get_text ();
269     s/^\s+//;
270     s/\s+$//;
271     if (/^[0-9]+$/) {
272         $$dataref = $_;
273         $widget->set_text ($_);
274     }
275     else {
276         $widget->set_text ($$dataref);
277     }
278 }
279
280 sub handle_string_value {
281     my ($widget, $event, $dataref) = @_;
282     $$dataref = $widget->get_text ();
283 }
284
285 sub handle_nchar_value {
286     my ($widget, $event, $dataref, $minlen) = @_;
287     $_ = substr ($widget->get_text (), 0, $minlen);
288     $widget->set_text ($_);
289     $$dataref = $_;
290 }
291
292 sub gdk_color_from_str {
293     my ($str) = @_;
294     my ($rr, $gg, $bb) = (0, 0 ,0);
295     $_ = uc ($str);
296     if (/\#([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])/) {
297         $rr = hex($1) * 256;
298         $gg = hex($2) * 256; 
299         $bb = hex($3) * 256;
300     }
301     my $color = Gtk2::Gdk::Color->new ($rr, $gg, $bb);
302     return $color;
303 }
304
305 sub str_from_gdk_color {
306     my ($color) = @_;
307     my $rr = $color->red / 256;
308     my $gg = $color->green / 256;
309     my $bb = $color->blue / 256;
310     my $str = sprintf ("#%.2x%.2x%.2x", $rr, $gg, $bb);
311     return $str;
312 }
313
314 sub handle_color_value {
315     my ($widget, $event, $dataref) = @_;
316     my $newcol = $widget->get_color;
317     $$dataref = &str_from_gdk_color ($newcol);
318 }
319
320 sub handle_selection_value {
321     my ($widget, $event, $dataref) = @_;
322     $$dataref = $widget->get_active;
323 }
324
325 sub get_rc_filename {
326     return $CONFIGDIR . $CONFIGRC;
327 }
328
329 sub set_rc_filename {
330     my ($fullname) = @_;
331     my @parts = split ('/', $fullname);
332     $CONFIGRC = $parts[$#parts];
333     $parts[$#parts] = '';
334     $CONFIGDIR = join ('/', @parts);
335 }
336
337 sub log_message {
338     my ($mesg, $fatal) = @_;
339     if (defined($fatal) && $fatal eq 'die') {
340         die "$NAME: $mesg\n";
341     }
342     if ($VERBOSE) {
343         print "$NAME: $mesg\n";
344     }
345 }
346
347 sub error_dialog {
348     my ($emsg) = @_;
349     my $markup = "<span weight=\"bold\" size=\"large\">" . $emsg . "</span>";
350     my $errordlg = Gtk2::MessageDialog->new_with_markup ($main_window, 'modal', 'error', 'cancel', $markup);
351     $errordlg->set_title (_('Error message'));
352     $errordlg->run;
353     $errordlg->destroy;
354 }
355
356 sub claws_is_running() {
357     my $emsg = "$xl::s{e_error}$xl::s{e_running}";
358     log_message ($emsg);
359     error_dialog ($emsg);
360     return FALSE;
361 }
362
363 sub check_claws_not_running() {
364     my $socket = (not $ALTCONFIGDIR)? "/tmp/": $CONFIGDIR;
365     $socket .= "claws-mail-$<";
366     -S $socket and return &claws_is_running;
367     # since 3.9.0cvs36
368     my $lockdir = "/tmp/claws-mail-$<";
369     -d $lockdir and do { 
370         $_ = $CONFIGDIR;
371         s/\/$//;
372         $socket = "$lockdir/" . md5_hex($_);
373         -S $socket and return &claws_is_running;
374     };
375     return TRUE;
376 }
377
378 sub check_rc_file() {
379     my ($rcfile) = @_;
380     (defined($rcfile) && -f $rcfile) or do {
381        my $emsg = "$xl::s{e_error}$xl::s{e_noclawsrc}\n";
382         log_message ($emsg);
383         error_dialog ($emsg);
384         return FALSE;
385     };
386     return TRUE;
387 }
388
389 sub set_widget_hint() {
390     if ($SHOWHINTS) {
391         my ($wdgt, $hint) = @_;    
392         $wdgt->set_tooltip_text ($hint);
393         $wdgt->set_has_tooltip (TRUE);
394     }
395 }
396
397 sub set_widget_sens() {
398     my ($wdgt, $versions) = @_;
399     my @ver = split(/,/, $versions);
400     if ($#ver == 1) {
401       $wdgt->set_sensitive (
402         &version_greater_or_equal ($CLAWSV, $ver[0])
403         and &version_greater_or_equal ($ver[1], $CLAWSV)
404       );
405     } else {
406         $wdgt->set_sensitive (&version_greater_or_equal ($CLAWSV, $ver[0]));
407     }
408 }
409
410 # graphic element creation 
411
412 sub new_check_button_for {
413     my ($hash, $key) = @_;
414     my $name = $$hash{$key}[NAME];
415     my $label = $$hash{$key}[LABEL];
416     #
417     my $hbox = Gtk2::HBox->new (FALSE, 5);
418     my $cb = Gtk2::CheckButton->new ($label);
419     $$hash{$key}[GUI] = $cb;
420     if (defined ($HPVALUE{$name})) {
421         $cb->set_active ($HPVALUE{$name} eq '1');
422     }
423     $cb->signal_connect (clicked => sub {
424             my ($w, $e) = @_;
425             &handle_bool_value($w, $e, \$HPVALUE{$name});
426         });
427     &set_widget_hint ($cb, $$hash{$key}[DESC]);
428     &set_widget_sens ($cb, $$hash{$key}[CMVER]);
429     $hbox->pack_start ($cb, FALSE, FALSE, HBOX_SPC);
430     #
431     return $hbox;
432 }
433
434 sub new_text_box_for_int {
435     my ($hash, $key) = @_;
436     my $name = $$hash{$key}[NAME];
437     my $label = $$hash{$key}[LABEL];
438     my @type = split (/,/, $$hash{$key}[TYPE]);
439     push (@type, 0), push (@type, 10000) unless ($#type > 0); 
440     #
441     my $hbox = Gtk2::HBox->new (FALSE, 5);
442     my $glabel = Gtk2::Label->new ($label);
443     my $pagei = int (($type[2] - $type[1]) / 10);
444     my $gentry = Gtk2::SpinButton->new_with_range ($type[1], $type[2], $pagei);
445     $gentry->set_numeric (TRUE);
446     $gentry->set_value ($HPVALUE{$name});
447     $$hash{$key}[GUI] = $gentry;
448     $gentry->signal_connect('value-changed' => sub {
449             my ($w, $e) = @_;
450             &handle_int_value($w, $e, \$HPVALUE{$name});
451         });
452     &set_widget_hint ($gentry, $$hash{$key}[DESC]);
453     &set_widget_sens ($gentry, $$hash{$key}[CMVER]);
454     $glabel->set_sensitive ($gentry->sensitive);
455     $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
456     $hbox->pack_start ($gentry, FALSE, FALSE, HBOX_SPC);
457     #
458     return $hbox;
459 }
460
461 sub new_text_box_for_nchar {
462     my ($hash, $key) = @_;
463     my $name = $$hash{$key}[NAME];
464     my $label = $$hash{$key}[LABEL];
465     my @type = split (/,/, $$hash{$key}[TYPE]); # char,minlen,maxlen
466     my $hbox = Gtk2::HBox->new (FALSE, 5);
467     my $glabel = Gtk2::Label->new ($label);
468     my $gentry = Gtk2::Entry->new ();
469     $gentry->set_max_length($type[2]) if defined ($type[2]);
470     $gentry->set_width_chars(int ($type[2]) + 2) if defined ($type[2]);
471     $gentry->set_text ($HPVALUE{$name});
472     $$hash{$key}[GUI] = $gentry;
473     $gentry->signal_connect('key-release-event' => sub {
474             my ($w, $e) = @_;
475             &handle_nchar_value($w, $e, \$HPVALUE{$name}, $type[1]);
476         });
477     &set_widget_hint ($gentry, $$hash{$key}[DESC]);
478     &set_widget_sens ($gentry, $$hash{$key}[CMVER]);
479     $glabel->set_sensitive ($gentry->sensitive);
480     $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
481     $hbox->pack_start ($gentry, FALSE, FALSE, HBOX_SPC);
482     #
483     return $hbox;
484 }
485
486 sub new_color_button_for {
487     my ($hash, $key) = @_;
488     my $name = $$hash{$key}[NAME];
489     my $label = $$hash{$key}[LABEL];
490     #
491     my $col = &gdk_color_from_str ($HPVALUE{$name});
492     my $hbox = Gtk2::HBox->new (FALSE, 5);
493     my $glabel = Gtk2::Label->new ($label);
494     my $button = Gtk2::ColorButton->new_with_color ($col);
495     $$hash{$key}[GUI] = $button;
496     $button->set_title ($label);
497     $button->set_relief ('none');
498     $button->signal_connect ('color-set' => sub {
499             my ($w, $e) = @_;
500             &handle_color_value($w, $e, \$HPVALUE{$name}); 
501         });
502     &set_widget_hint ($button, $$hash{$key}[DESC]);
503     &set_widget_sens ($button, $$hash{$key}[CMVER]);
504     $glabel->set_sensitive ($button->sensitive);
505     $hbox->pack_start ($button, FALSE, FALSE, HBOX_SPC);
506     $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
507     #
508     return $hbox;
509 }
510
511 sub new_selection_box_for {
512     my ($hash, $key) = @_;
513     my $name = $$hash{$key}[NAME];
514     my $label = $$hash{$key}[LABEL];
515     #
516     my $hbox = Gtk2::HBox->new (FALSE, 5);
517     my $glabel = Gtk2::Label->new ($label);
518     my $combo = Gtk2::ComboBox->new_text;
519     $$hash{$key}[GUI] = $combo;
520     my @options = split (';', $$hash{$key}[TYPE]);
521     foreach my $opt (@options) {
522         my ($index, $textkey) = split ('=', $opt);
523         $combo->insert_text ($index, $xl::s{$textkey});
524     }
525     $combo->signal_connect ('changed' => sub {
526             my ($w, $e) = @_;
527             &handle_selection_value($w, $e, \$HPVALUE{$name});
528         });
529     $combo->set_active ($HPVALUE{$name});
530     &set_widget_hint ($combo, $$hash{$key}[DESC]);
531     &set_widget_sens ($combo, $$hash{$key}[CMVER]);
532     $glabel->set_sensitive ($combo->sensitive);
533     $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
534     $hbox->pack_start ($combo, FALSE, FALSE, HBOX_SPC);
535     #
536     return $hbox;
537 }
538
539 # more graphic helpers
540
541 sub new_hbox_pack() {
542     my $hbox = Gtk2::HBox->new (FALSE, 5);
543     $hbox->set_border_width (PAGE_SPC);
544     foreach my $item (@_) {
545         $hbox->pack_start ($item, FALSE, FALSE, 0);
546     }
547     return $hbox;
548 }    
549
550 sub new_vbox_pack() {
551     my $vbox = Gtk2::VBox->new (FALSE, 5);
552     $vbox->set_border_width (PAGE_SPC);
553     foreach my $item (@_) {
554         $vbox->pack_start ($item, FALSE, FALSE, 0);
555     }
556     return $vbox;
557 }    
558
559 sub new_vbox_pack_compact() {
560     my $vbox = Gtk2::VBox->new (FALSE, 0);
561     $vbox->set_border_width (0);
562     foreach my $item (@_) {
563         $vbox->pack_start ($item, FALSE, FALSE, 0);
564     }
565     return $vbox;
566 }    
567
568 sub new_subpage_frame () {
569     my ($box, $title, $notpacked) = @_;
570     my $frame = Gtk2::Frame->new ($title);
571     $frame->add ($box);    
572     return &new_vbox_pack ($frame) unless defined ($notpacked);
573     return $frame;
574 }
575
576 # preference maps and corresponding page creation subs
577
578 %pr::oth = ( # other preferences
579     use_dlg => [ 
580         'addressbook_use_editaddress_dialog',
581         $xl::s{l_oth_use_dlg},
582         $xl::s{h_oth_use_dlg},
583         'bool',
584         '2.7.0',
585         '0',
586         undef,
587     ],
588     max_use => [
589         'cache_max_mem_usage',
590         $xl::s{l_oth_max_use},
591         $xl::s{h_oth_max_use},
592         'int,0,262144', # 0 Kb - 256 Mb
593         '0.0.0',
594         '4096',
595         undef,
596     ],
597     min_time => [
598         'cache_min_keep_time',
599         $xl::s{l_oth_min_time},
600         $xl::s{h_oth_min_time},
601         'int,0,120', # 0 minutes - 2 hours
602         '0.0.0',
603         '15',
604         undef,
605     ],
606     use_netm => [
607         'use_networkmanager',
608         $xl::s{l_oth_use_netm},
609         $xl::s{h_oth_use_netm},
610         'bool',
611         '3.3.1',
612         '1',
613         undef,
614     ],
615 );
616
617 sub new_other_page() {
618     return &new_vbox_pack (
619                &new_subpage_frame (
620                    &new_vbox_pack (
621                        &new_check_button_for(\%pr::oth, 'use_dlg')),
622                    $xl::s{ab_frame}, 'not-packed'),
623                &new_subpage_frame (
624                    &new_vbox_pack (
625                        &new_text_box_for_int(\%pr::oth, 'max_use'),
626                        &new_text_box_for_int(\%pr::oth, 'min_time')),
627                    $xl::s{mem_frame}, 'not-packed'),
628                &new_subpage_frame (
629                    &new_vbox_pack (
630                        &new_check_button_for(\%pr::oth, 'use_netm')),
631                    $xl::s{netm_frame}, 'not-packed')
632            );
633 }
634
635 %pr::gui = ( # gui bells and whistles
636     b_unread => [ 
637         'bold_unread',
638         $xl::s{l_gui_b_unread},
639         $xl::s{h_gui_b_unread},
640         'bool',
641         '0.0.0',
642         '1',
643         undef,
644     ],
645     no_markup => [
646         'compose_no_markup',
647         $xl::s{l_gui_no_markup},
648         $xl::s{h_gui_no_markup},
649         'bool',
650         '0.0.0',
651         '0',
652         undef,
653     ],
654     dot_lines => [
655         'enable_dotted_lines',
656         $xl::s{l_gui_dot_lines},
657         $xl::s{h_gui_dot_lines},
658         'bool',
659         '0.0.0',
660         '0',
661         undef,
662     ],
663     h_scroll => [
664         'enable_hscrollbar',
665         $xl::s{l_gui_h_scroll},
666         $xl::s{h_gui_h_scroll},
667         'bool',
668         '0.0.0',
669         '1',
670         undef,
671     ],
672     swp_from => [
673         'enable_swap_from',
674         $xl::s{l_gui_swp_from},
675         $xl::s{h_gui_swp_from},
676         'bool',
677         '0.0.0',
678         '0',
679         undef,
680     ],
681     v_scroll => [
682         'folderview_vscrollbar_policy',
683         $xl::s{l_gui_v_scroll},
684         $xl::s{h_gui_v_scroll},
685         '0=l_gui_v_scroll_show;1=l_gui_v_scroll_auto;2=l_gui_v_scroll_hide',
686         '0.0.0',
687         '0',
688         undef,
689     ],
690     from_show => [
691         'summary_from_show',
692         $xl::s{l_gui_from_show},
693         $xl::s{h_gui_from_show},
694         '0=l_gui_from_show_name;1=l_gui_from_show_addr;2=l_gui_from_show_both',
695         '3.7.10',
696         '0',
697         undef,
698     ],
699     strip_off => [
700         'stripes_color_offset',
701         $xl::s{l_gui_strip_off},
702         $xl::s{h_gui_strip_off},
703         'int,0,40000', # no idea what this number means
704         '0.0.0',
705         '4000',
706         undef,
707     ],
708     cursor_v => [
709         'textview_cursor_visible',
710         $xl::s{l_gui_cursor_v},
711         $xl::s{h_gui_cursor_v},
712         'bool',
713         '0.0.0',
714         '0',
715         undef,
716     ],
717     toolbar_d => [
718         'toolbar_detachable',
719         $xl::s{l_gui_toolbar_d},
720         $xl::s{h_gui_toolbar_d},
721         'bool',
722         '0.0.0',
723         '0',
724         undef,
725     ],
726     strip_all => [
727         'use_stripes_everywhere',
728         $xl::s{l_gui_strip_all},
729         $xl::s{h_gui_strip_all},
730         'bool',
731         '0.0.0',
732         '1',
733         undef,
734     ],
735     strip_sum => [
736         'use_stripes_in_summaries',
737         $xl::s{l_gui_strip_sum},
738         $xl::s{h_gui_strip_sum},
739         'bool',
740         '0.0.0',
741         '1',
742         undef,
743     ],
744     two_linev => [
745         'two_line_vertical',
746         $xl::s{l_gui_two_line_v},
747         $xl::s{h_gui_two_line_v},
748         'bool',
749         '3.4.0.7',
750         '0',
751         undef,
752     ],
753     margin_co => [
754         'show_compose_margin',
755         $xl::s{l_gui_margin_co},
756         $xl::s{h_gui_margin_co},
757         'bool',
758         '3.7.6.7',
759         '0',
760         undef,
761     ],
762     mview_date => [
763         'msgview_date_format',
764         $xl::s{l_gui_mview_date},
765         $xl::s{h_gui_mview_date},
766         'bool',
767         '3.7.8.42',
768         '0',
769         undef,
770     ],
771     zero_char => [
772         'zero_replacement_char',
773         $xl::s{l_gui_zero_char},
774         $xl::s{h_gui_zero_char},
775         'char,1,1',
776         '2.8.1.77',
777         '0',
778         undef,
779     ],
780 );
781
782 sub new_gui_page() {
783     my $gf = Gtk2::VBox->new (FALSE, 5);
784     $gf->set_border_width (PAGE_SPC);
785
786     my $cb_dot_lines = &new_check_button_for (\%pr::gui, 'dot_lines'); 
787     my $cb_toolbar_d = &new_check_button_for (\%pr::gui, 'toolbar_d');
788     my $tb_zero_char = &new_text_box_for_nchar (\%pr::gui, 'zero_char');
789
790     $gf->pack_start (&new_subpage_frame (
791                          &new_vbox_pack (
792                              &new_check_button_for (\%pr::gui, 'strip_all'),
793                              &new_check_button_for (\%pr::gui, 'strip_sum'),
794                              &new_text_box_for_int (\%pr::gui, 'strip_off')),
795                          $xl::s{stripes_frame}, 'not-packed'),
796                      FALSE, FALSE, FRAME_SPC);
797     $gf->pack_start (&new_subpage_frame (
798                          &new_vbox_pack (
799                              &new_check_button_for (\%pr::gui, 'b_unread'),
800                              &new_check_button_for (\%pr::gui, 'swp_from'),
801                              &new_check_button_for (\%pr::gui, 'two_linev'),
802                              &new_selection_box_for (\%pr::gui, 'from_show')),
803                          $xl::s{mlist_frame}, 'not-packed'), 
804                      FALSE, FALSE, FRAME_SPC);
805     $gf->pack_start (&new_subpage_frame (
806                          &new_hbox_pack (
807                              &new_check_button_for (\%pr::gui, 'cursor_v'),
808                              &new_check_button_for (\%pr::gui, 'mview_date')),
809                          $xl::s{mview_frame}, 'not-packed'), 
810                      FALSE, FALSE, FRAME_SPC);
811     $gf->pack_start (&new_subpage_frame (
812                          &new_hbox_pack (
813                              &new_check_button_for (\%pr::gui, 'no_markup'),
814                              &new_check_button_for (\%pr::gui, 'margin_co')),
815                          $xl::s{compo_frame}, 'not-packed'), 
816                      FALSE, FALSE, FRAME_SPC);
817     $gf->pack_start ($cb_dot_lines, FALSE, FALSE, 0);
818     $gf->pack_start ($cb_toolbar_d, FALSE, FALSE, 0);
819     $gf->pack_start (&new_subpage_frame (
820                          &new_vbox_pack (
821                              &new_check_button_for (\%pr::gui, 'h_scroll'),
822                              &new_selection_box_for (\%pr::gui, 'v_scroll')),
823                          $xl::s{sbar_frame}, 'not-packed'),
824                      FALSE, FALSE, FRAME_SPC);
825     $gf->pack_start ($tb_zero_char, FALSE, FALSE, 0);
826
827     return $gf;
828 }
829
830 %pr::beh = ( # tweak some behaviour
831     hover_t => [
832         'hover_timeout',
833         $xl::s{l_beh_hover_t},
834         $xl::s{h_beh_hover_t},
835         'int,100,3000', # 0.1 seconds - 3 seconds
836         '0.0.0',
837         '500',
838         undef,
839     ],
840     dangerous => [
841         'live_dangerously',
842         $xl::s{l_beh_dangerous},
843         $xl::s{h_beh_dangerous},
844         'bool',
845         '0.0.0',
846         '0',
847         undef,
848     ],
849     flowed => [
850         'respect_flowed_format',
851         $xl::s{l_beh_flowed},
852         $xl::s{h_beh_flowed},
853         'bool',
854         '0.0.0',
855         '0',
856         undef,
857     ],
858     parts_rw => [
859         'save_parts_readwrite',
860         $xl::s{l_beh_parts_rw},
861         $xl::s{h_beh_parts_rw},
862         'bool',
863         '0.0.0',
864         '0',
865         undef,
866     ],
867     skip_ssl => [
868         'skip_ssl_cert_check',
869         $xl::s{l_beh_skip_ssl},
870         $xl::s{h_beh_skip_ssl},
871         'bool',
872         '0.0.0',
873         '0',
874         undef,
875     ],
876     up_step => [
877         'statusbar_update_step',
878         $xl::s{l_beh_up_step},
879         $xl::s{h_beh_up_step},
880         'int,1,200', # 1 item - 200 items
881         '0.0.0',
882         '10',
883         undef,
884     ],
885     thread_a => [
886         'thread_by_subject_max_age',
887         $xl::s{l_beh_thread_a},
888         $xl::s{h_beh_thread_a},
889         'int,1,30', # 1 day - 30 days
890         '0.0.0',
891         '10',
892         undef,
893     ],
894     unsafe_ssl => [
895         'unsafe_ssl_certs',
896         $xl::s{l_beh_unsafe_ssl},
897         $xl::s{h_beh_unsafe_ssl},
898         'bool',
899         '0.0.0',
900         '0',
901         undef,
902     ],
903     use_utf8 => [
904         'utf8_instead_of_locale_for_broken_mail',
905         $xl::s{l_beh_use_utf8},
906         $xl::s{h_beh_use_utf8},
907         'bool',
908         '0.0.0',
909         '0',
910         undef,
911     ],
912     warn_dnd => [
913         'warn_dnd',
914         $xl::s{l_beh_warn_dnd},
915         $xl::s{h_beh_warn_dnd},
916         'bool',
917         '0.0.0',
918         '1',
919         undef,
920     ],
921     out_ascii => [
922         'outgoing_fallback_to_ascii',
923         $xl::s{l_beh_out_ascii},
924         $xl::s{h_beh_out_ascii},
925         'bool',
926         '3.4.0.37',
927         '1',
928         undef,
929     ],
930     pp_unsel => [
931         'primary_paste_unselects',
932         $xl::s{l_beh_pp_unsel},
933         $xl::s{h_beh_pp_unsel},
934         'bool',
935         '3.6.1.35',
936         '0',
937         undef,
938     ],
939     inline_at => [
940         'show_inline_attachments',
941         $xl::s{l_beh_inline_at},
942         $xl::s{h_beh_inline_at},
943         'bool',
944         '3.7.8.48',
945         '1',
946         undef,
947     ],
948 );
949
950 sub new_behaviour_page() {
951     my $bf = Gtk2::VBox->new (FALSE, 5);
952     $bf->set_border_width (PAGE_SPC);
953
954     my $tb_up_step = &new_text_box_for_int (\%pr::beh, 'up_step');
955     my $tb_thread_a = &new_text_box_for_int (\%pr::beh, 'thread_a');
956
957     $bf->pack_start (&new_subpage_frame (
958                          &new_vbox_pack (
959                              &new_text_box_for_int (\%pr::beh, 'hover_t'),
960                              &new_check_button_for (\%pr::beh, 'warn_dnd')),
961                          $xl::s{dnd_frame}, 'not-packed'), 
962                      FALSE, FALSE, FRAME_SPC);
963     $bf->pack_start (&new_subpage_frame (
964                          &new_hbox_pack (
965                              &new_check_button_for (\%pr::beh, 'skip_ssl'),
966                              &new_check_button_for (\%pr::beh, 'unsafe_ssl')),
967                          $xl::s{ssl_frame}, 'not-packed'),
968                      FALSE, FALSE, FRAME_SPC);
969     $bf->pack_start ($tb_up_step, FALSE, FALSE, 0);
970     $bf->pack_start ($tb_thread_a, FALSE, FALSE, 0);
971     $bf->pack_start (&new_subpage_frame (
972                          &new_vbox_pack (
973                              &new_check_button_for (\%pr::beh, 'flowed'),
974                              &new_check_button_for (\%pr::beh, 'parts_rw'),
975                              &new_check_button_for (\%pr::beh, 'use_utf8'),
976                              &new_check_button_for (\%pr::beh, 'dangerous'),
977                              &new_check_button_for (\%pr::beh, 'out_ascii'),
978                              &new_check_button_for (\%pr::beh, 'pp_unsel'),
979                              &new_check_button_for (\%pr::beh, 'inline_at')),
980                          $xl::s{msgs_frame}, 'not-packed'),
981                      FALSE, FALSE, FRAME_SPC);
982
983     return $bf;
984 }
985
986 %pr::col = ( # a variety of colours
987     emphasis => [
988         'emphasis_color',
989         $xl::s{l_col_emphasis},
990         $xl::s{h_col_emphasis},
991         'color',
992         '0.0.0',
993         '#0000cf',
994         undef,
995     ],
996     log_err => [
997         'log_error_color',
998         $xl::s{l_col_log_err},
999         $xl::s{h_col_log_err},
1000         'color',
1001         '0.0.0',
1002         '#af0000',
1003         undef,
1004     ],
1005     log_in => [
1006         'log_in_color',
1007         $xl::s{l_col_log_in},
1008         $xl::s{h_col_log_in},
1009         'color',
1010         '0.0.0',
1011         '#000000',
1012         undef,
1013     ],
1014     log_msg => [
1015         'log_msg_color',
1016         $xl::s{l_col_log_msg},
1017         $xl::s{h_col_log_msg},
1018         'color',
1019         '0.0.0',
1020         '#00af00',
1021         undef,
1022     ],
1023     log_out => [
1024         'log_out_color',
1025         $xl::s{l_col_log_out},
1026         $xl::s{h_col_log_out},
1027         'color',
1028         '0.0.0',
1029         '#0000ef',
1030         undef,
1031     ],
1032     log_warn => [
1033         'log_warn_color',
1034         $xl::s{l_col_log_warn},
1035         $xl::s{h_col_log_warn},
1036         'color',
1037         '0.0.0',
1038         '#af0000',
1039         undef,
1040     ],
1041     diff_add => [
1042         'diff_added_color',
1043         $xl::s{l_col_diff_add},
1044         $xl::s{h_col_diff_add},
1045         'color',
1046         '3.8.0.54',
1047         '#008b8b',
1048         undef,
1049     ],
1050     diff_del => [
1051         'diff_deleted_color',
1052         $xl::s{l_col_diff_del},
1053         $xl::s{h_col_diff_del},
1054         'color',
1055         '3.8.0.54',
1056         '#6a5acd',
1057         undef,
1058     ],
1059     diff_hunk => [
1060         'diff_hunk_color',
1061         $xl::s{l_col_diff_hunk},
1062         $xl::s{h_col_diff_hunk},
1063         'color',
1064         '3.8.0.54',
1065         '#a52a2a',
1066         undef,
1067     ],
1068 );
1069
1070 sub new_colours_page() {
1071     return &new_vbox_pack (
1072                &new_subpage_frame (
1073                    &new_vbox_pack (
1074                        &new_color_button_for (\%pr::col, 'emphasis')),
1075                    $xl::s{msgview_frame}, 'not-packed'),
1076                &new_subpage_frame (
1077                    &new_vbox_pack (
1078                        &new_color_button_for (\%pr::col, 'log_err'),
1079                        &new_color_button_for (\%pr::col, 'log_in'),
1080                        &new_color_button_for (\%pr::col, 'log_msg'),
1081                        &new_color_button_for (\%pr::col, 'log_out'),
1082                        &new_color_button_for (\%pr::col, 'log_warn')),
1083                    $xl::s{log_frame}, 'not-packed'),
1084                &new_subpage_frame (
1085                    &new_vbox_pack (
1086                        &new_color_button_for (\%pr::col, 'diff_add'),
1087                        &new_color_button_for (\%pr::col, 'diff_del'),
1088                        &new_color_button_for (\%pr::col, 'diff_hunk')),
1089                    $xl::s{diff_frame}, 'not-packed')
1090            );
1091 }
1092
1093 %pr::win = ( # tweak window positions and/or sizes
1094     main_x => [
1095         'mainwin_x',
1096         $xl::s{l_win_x},
1097         $xl::s{h_win_x},
1098         'int,0,3000', # 0 pixels - 3000 pixels
1099         '0.0.0',
1100         '16',
1101         undef,
1102     ],
1103     main_y => [
1104         'mainwin_y',
1105         $xl::s{l_win_y},
1106         $xl::s{h_win_y},
1107         'int,0,3000', # 0 pixels - 3000 pixels
1108         '0.0.0',
1109         '16',
1110         undef,
1111     ],
1112     main_w => [
1113         'mainwin_width',
1114         $xl::s{l_win_w},
1115         $xl::s{h_win_w},
1116         'int,0,3000', # 0 pixels - 3000 pixels
1117         '0.0.0',
1118         '779',
1119         undef,
1120     ],
1121     main_h => [
1122         'mainwin_height',
1123         $xl::s{l_win_h},
1124         $xl::s{h_win_h},
1125         'int,0,3000', # 0 pixels - 3000 pixels
1126         '0.0.0',
1127         '568',
1128         undef,
1129     ],
1130     main_mx => [
1131         'mainwin_maximised',
1132         $xl::s{l_win_main_mx},
1133         $xl::s{h_win_main_mx},
1134         'bool',
1135         '0.0.0',
1136         '0',
1137         undef,
1138     ],
1139     main_fs => [
1140         'mainwin_fullscreen',
1141         $xl::s{l_win_main_fs},
1142         $xl::s{h_win_main_fs},
1143         'bool',
1144         '0.0.0',
1145         '0',
1146         undef,
1147     ],
1148     msgs_x => [
1149         'main_messagewin_x',
1150         $xl::s{l_win_x},
1151         $xl::s{h_win_x},
1152         'int,0,3000', # 0 pixels - 3000 pixels
1153         '0.0.0',
1154         '256',
1155         undef,
1156     ],
1157     msgs_y => [
1158         'main_messagewin_y',
1159         $xl::s{l_win_y},
1160         $xl::s{h_win_y},
1161         'int,0,3000', # 0 pixels - 3000 pixels
1162         '0.0.0',
1163         '210',
1164         undef,
1165     ],
1166     msgs_w => [
1167         'messagewin_width',
1168         $xl::s{l_win_w},
1169         $xl::s{h_win_w},
1170         'int,0,3000', # 0 pixels - 3000 pixels
1171         '0.0.0',
1172         '600',
1173         undef,
1174     ],
1175     msgs_h => [
1176         'messagewin_height',
1177         $xl::s{l_win_h},
1178         $xl::s{h_win_h},
1179         'int,0,3000', # 0 pixels - 3000 pixels
1180         '0.0.0',
1181         '540',
1182         undef,
1183     ],
1184     send_w => [
1185         'sendwin_width',
1186         $xl::s{l_win_w},
1187         $xl::s{h_win_w},
1188         'int,0,3000', # 0 pixels - 3000 pixels
1189         '0.0.0',
1190         '460',
1191         undef,
1192     ],
1193     send_h => [
1194         'sendwin_height',
1195         $xl::s{l_win_h},
1196         $xl::s{h_win_h},
1197         'int,0,3000', # 0 pixels - 3000 pixels
1198         '0.0.0',
1199         '-1',
1200         undef,
1201     ],
1202     recv_w => [
1203         'receivewin_width',
1204         $xl::s{l_win_w},
1205         $xl::s{h_win_w},
1206         'int,0,3000', # 0 pixels - 3000 pixels
1207         '0.0.0',
1208         '460',
1209         undef,
1210     ],
1211     recv_h => [
1212         'receivewin_height',
1213         $xl::s{l_win_h},
1214         $xl::s{h_win_h},
1215         'int,0,3000', # 0 pixels - 3000 pixels
1216         '0.0.0',
1217         '-1',
1218         undef,
1219     ],
1220     fold_x => [
1221         'folderwin_x',
1222         $xl::s{l_win_x},
1223         $xl::s{h_win_x},
1224         'int,0,3000', # 0 pixels - 3000 pixels
1225         '0.0.0',
1226         '16',
1227         undef,
1228     ],
1229     fold_y => [
1230         'folderwin_y',
1231         $xl::s{l_win_y},
1232         $xl::s{h_win_y},
1233         'int,0,3000', # 0 pixels - 3000 pixels
1234         '0.0.0',
1235         '16',
1236         undef,
1237     ],
1238     fold_w => [
1239         'folderitemwin_width',
1240         $xl::s{l_win_w},
1241         $xl::s{h_win_w},
1242         'int,0,3000', # 0 pixels - 3000 pixels
1243         '0.0.0',
1244         '500',
1245         undef,
1246     ],
1247     fold_h => [
1248         'folderitemwin_height',
1249         $xl::s{l_win_h},
1250         $xl::s{h_win_h},
1251         'int,0,3000', # 0 pixels - 3000 pixels
1252         '0.0.0',
1253         '-1',
1254         undef,
1255     ],
1256     fsel_w => [
1257         'folderselwin_width',
1258         $xl::s{l_win_w},
1259         $xl::s{h_win_w},
1260         'int,0,3000', # 0 pixels - 3000 pixels
1261         '0.0.0',
1262         '300',
1263         undef,
1264     ],
1265     fsel_h => [
1266         'folderselwin_height',
1267         $xl::s{l_win_h},
1268         $xl::s{h_win_h},
1269         'int,0,3000', # 0 pixels - 3000 pixels
1270         '0.0.0',
1271         '-1',
1272         undef,
1273     ],
1274     sour_w => [
1275         'sourcewin_width',
1276         $xl::s{l_win_w},
1277         $xl::s{h_win_w},
1278         'int,0,3000', # 0 pixels - 3000 pixels
1279         '0.0.0',
1280         '600',
1281         undef,
1282     ],
1283     sour_h => [
1284         'sourcewin_height',
1285         $xl::s{l_win_h},
1286         $xl::s{h_win_h},
1287         'int,0,3000', # 0 pixels - 3000 pixels
1288         '0.0.0',
1289         '500',
1290         undef,
1291     ],
1292     addr_w => [
1293         'addressbookwin_width',
1294         $xl::s{l_win_w},
1295         $xl::s{h_win_w},
1296         'int,0,3000', # 0 pixels - 3000 pixels
1297         '0.0.0',
1298         '520',
1299         undef,
1300     ],
1301     addr_h => [
1302         'addressbookwin_height',
1303         $xl::s{l_win_h},
1304         $xl::s{h_win_h},
1305         'int,0,3000', # 0 pixels - 3000 pixels
1306         '0.0.0',
1307         '-1',
1308         undef,
1309     ],
1310     adep_w => [
1311         'addressbookeditpersonwin_width',
1312         $xl::s{l_win_w},
1313         $xl::s{h_win_w},
1314         'int,0,3000', # 0 pixels - 3000 pixels
1315         '0.0.0',
1316         '640',
1317         undef,
1318     ],
1319     adep_h => [
1320         'addressbookeditpersonwin_height',
1321         $xl::s{l_win_h},
1322         $xl::s{h_win_h},
1323         'int,0,3000', # 0 pixels - 3000 pixels
1324         '0.0.0',
1325         '320',
1326         undef,
1327     ],
1328     adeg_w => [
1329         'addressbookeditgroupwin_width',
1330         $xl::s{l_win_w},
1331         $xl::s{h_win_w},
1332         'int,0,3000', # 0 pixels - 3000 pixels
1333         '0.0.0',
1334         '580',
1335         undef,
1336     ],
1337     adeg_h => [
1338         'addressbookeditgroupwin_height',
1339         $xl::s{l_win_h},
1340         $xl::s{h_win_h},
1341         'int,0,3000', # 0 pixels - 3000 pixels
1342         '0.0.0',
1343         '340',
1344         undef,
1345     ],
1346     adda_w => [
1347         'addressaddwin_width',
1348         $xl::s{l_win_w},
1349         $xl::s{h_win_w},
1350         'int,0,3000', # 0 pixels - 3000 pixels
1351         '0.0.0',
1352         '300',
1353         undef,
1354     ],
1355     adda_h => [
1356         'addressaddwin_height',
1357         $xl::s{l_win_h},
1358         $xl::s{h_win_h},
1359         'int,0,3000', # 0 pixels - 3000 pixels
1360         '0.0.0',
1361         '-1',
1362         undef,
1363     ],
1364     addf_w => [
1365         'addressbook_folderselwin_width',
1366         $xl::s{l_win_w},
1367         $xl::s{h_win_w},
1368         'int,0,3000', # 0 pixels - 3000 pixels
1369         '0.0.0',
1370         '300',
1371         undef,
1372     ],
1373     addf_h => [
1374         'addressbook_folderselwin_height',
1375         $xl::s{l_win_h},
1376         $xl::s{h_win_h},
1377         'int,0,3000', # 0 pixels - 3000 pixels
1378         '0.0.0',
1379         '-1',
1380         undef,
1381     ],
1382     acce_w => [
1383         'editaccountwin_width',
1384         $xl::s{l_win_w},
1385         $xl::s{h_win_w},
1386         'int,0,3000', # 0 pixels - 3000 pixels
1387         '0.0.0',
1388         '500',
1389         undef,
1390     ],
1391     acce_h => [
1392         'editaccountwin_height',
1393         $xl::s{l_win_h},
1394         $xl::s{h_win_h},
1395         'int,0,3000', # 0 pixels - 3000 pixels
1396         '0.0.0',
1397         '-1',
1398         undef,
1399     ],
1400     acco_w => [
1401         'accountswin_width',
1402         $xl::s{l_win_w},
1403         $xl::s{h_win_w},
1404         'int,0,3000', # 0 pixels - 3000 pixels
1405         '0.0.0',
1406         '500',
1407         undef,
1408     ],
1409     acco_h => [
1410         'accountswin_height',
1411         $xl::s{l_win_h},
1412         $xl::s{h_win_h},
1413         'int,0,3000', # 0 pixels - 3000 pixels
1414         '0.0.0',
1415         '-1',
1416         undef,
1417     ],
1418     filt_w => [
1419         'filteringwin_width',
1420         $xl::s{l_win_w},
1421         $xl::s{h_win_w},
1422         'int,0,3000', # 0 pixels - 3000 pixels
1423         '0.0.0',
1424         '500',
1425         undef,
1426     ],
1427     filt_h => [
1428         'filteringwin_height',
1429         $xl::s{l_win_h},
1430         $xl::s{h_win_h},
1431         'int,0,3000', # 0 pixels - 3000 pixels
1432         '0.0.0',
1433         '-1',
1434         undef,
1435     ],
1436     fila_w => [
1437         'filteringactionwin_width',
1438         $xl::s{l_win_w},
1439         $xl::s{h_win_w},
1440         'int,0,3000', # 0 pixels - 3000 pixels
1441         '0.0.0',
1442         '490',
1443         undef,
1444     ],
1445     fila_h => [
1446         'filteringactionwin_height',
1447         $xl::s{l_win_h},
1448         $xl::s{h_win_h},
1449         'int,0,3000', # 0 pixels - 3000 pixels
1450         '0.0.0',
1451         '-1',
1452         undef,
1453     ],
1454     fild_w => [
1455         'filtering_debugwin_width',
1456         $xl::s{l_win_w},
1457         $xl::s{h_win_w},
1458         'int,0,3000', # 0 pixels - 3000 pixels
1459         '0.0.0',
1460         '600',
1461         undef,
1462     ],
1463     fild_h => [
1464         'filtering_debugwin_height',
1465         $xl::s{l_win_h},
1466         $xl::s{h_win_h},
1467         'int,0,3000', # 0 pixels - 3000 pixels
1468         '0.0.0',
1469         '-1',
1470         undef,
1471     ],
1472     matc_w => [
1473         'matcherwin_width',
1474         $xl::s{l_win_w},
1475         $xl::s{h_win_w},
1476         'int,0,3000', # 0 pixels - 3000 pixels
1477         '0.0.0',
1478         '520',
1479         undef,
1480     ],
1481     matc_h => [
1482         'matcherwin_height',
1483         $xl::s{l_win_h},
1484         $xl::s{h_win_h},
1485         'int,0,3000', # 0 pixels - 3000 pixels
1486         '0.0.0',
1487         '-1',
1488         undef,
1489     ],
1490     pref_w => [
1491         'prefswin_width',
1492         $xl::s{l_win_w},
1493         $xl::s{h_win_w},
1494         'int,0,3000', # 0 pixels - 3000 pixels
1495         '0.0.0',
1496         '600',
1497         undef,
1498     ],
1499     pref_h => [
1500         'prefswin_height',
1501         $xl::s{l_win_h},
1502         $xl::s{h_win_h},
1503         'int,0,3000', # 0 pixels - 3000 pixels
1504         '0.0.0',
1505         '-1',
1506         undef,
1507     ],
1508     temp_w => [
1509         'templateswin_width',
1510         $xl::s{l_win_w},
1511         $xl::s{h_win_w},
1512         'int,0,3000', # 0 pixels - 3000 pixels
1513         '0.0.0',
1514         '480',
1515         undef,
1516     ],
1517     temp_h => [
1518         'templateswin_height',
1519         $xl::s{l_win_h},
1520         $xl::s{h_win_h},
1521         'int,0,3000', # 0 pixels - 3000 pixels
1522         '0.0.0',
1523         '-1',
1524         undef,
1525     ],
1526     acti_w => [
1527         'actionswin_width',
1528         $xl::s{l_win_w},
1529         $xl::s{h_win_w},
1530         'int,0,3000', # 0 pixels - 3000 pixels
1531         '0.0.0',
1532         '486',
1533         undef,
1534     ],
1535     acti_h => [
1536         'actionswin_height',
1537         $xl::s{l_win_h},
1538         $xl::s{h_win_h},
1539         'int,0,3000', # 0 pixels - 3000 pixels
1540         '0.0.0',
1541         '-1',
1542         undef,
1543     ],
1544     tags_w => [
1545         'tagswin_width',
1546         $xl::s{l_win_w},
1547         $xl::s{h_win_w},
1548         'int,0,3000', # 0 pixels - 3000 pixels
1549         '0.0.0',
1550         '486',
1551         undef,
1552     ],
1553     tags_h => [
1554         'tagswin_height',
1555         $xl::s{l_win_h},
1556         $xl::s{h_win_h},
1557         'int,0,3000', # 0 pixels - 3000 pixels
1558         '0.0.0',
1559         '-1',
1560         undef,
1561     ],
1562     plug_w => [
1563         'pluginswin_width',
1564         $xl::s{l_win_w},
1565         $xl::s{h_win_w},
1566         'int,0,3000', # 0 pixels - 3000 pixels
1567         '0.0.0',
1568         '-1',
1569         undef,
1570     ],
1571     plug_h => [
1572         'pluginswin_height',
1573         $xl::s{l_win_h},
1574         $xl::s{h_win_h},
1575         'int,0,3000', # 0 pixels - 3000 pixels
1576         '0.0.0',
1577         '-1',
1578         undef,
1579     ],
1580     logw_w => [
1581         'logwin_width',
1582         $xl::s{l_win_w},
1583         $xl::s{h_win_w},
1584         'int,0,3000', # 0 pixels - 3000 pixels
1585         '0.0.0',
1586         '520',
1587         undef,
1588     ],
1589     logw_h => [
1590         'logwin_height',
1591         $xl::s{l_win_h},
1592         $xl::s{h_win_h},
1593         'int,0,3000', # 0 pixels - 3000 pixels
1594         '0.0.0',
1595         '-1',
1596         undef,
1597     ],
1598     prin_w => [
1599         'print_previewwin_width',
1600         $xl::s{l_win_w},
1601         $xl::s{h_win_w},
1602         'int,0,3000', # 0 pixels - 3000 pixels
1603         '0.0.0',
1604         '600',
1605         undef,
1606     ],
1607     prin_h => [
1608         'print_previewwin_height',
1609         $xl::s{l_win_h},
1610         $xl::s{h_win_h},
1611         'int,0,3000', # 0 pixels - 3000 pixels
1612         '0.0.0',
1613         '-1',
1614         undef,
1615     ],
1616 );
1617
1618 sub new_winpos_subpage_main() {
1619     return &new_subpage_frame (
1620                &new_vbox_pack_compact (
1621                    &new_vbox_pack (
1622                        &new_text_box_for_int (\%pr::win, 'main_x'), 
1623                        &new_text_box_for_int (\%pr::win, 'main_y')), 
1624                    &new_hbox_pack (
1625                        &new_text_box_for_int (\%pr::win, 'main_w'), 
1626                        &new_text_box_for_int (\%pr::win, 'main_h')), 
1627                    &new_vbox_pack (
1628                        &new_check_button_for (\%pr::win, 'main_fs'), 
1629                        &new_check_button_for (\%pr::win, 'main_mx'))),
1630                _('Main window')
1631            );
1632 }
1633
1634 sub new_winpos_subpage_msgs() {
1635     return &new_subpage_frame (
1636                &new_vbox_pack_compact (
1637                    &new_vbox_pack (
1638                        &new_text_box_for_int (\%pr::win, 'msgs_x'),
1639                        &new_text_box_for_int (\%pr::win, 'msgs_y')),
1640                    &new_hbox_pack (
1641                        &new_text_box_for_int (\%pr::win, 'msgs_w'),
1642                        &new_text_box_for_int (\%pr::win, 'msgs_h'))),
1643                _('Message window')
1644            );
1645 }
1646
1647 sub new_winpos_subpage_sendrecv() {
1648     return &new_vbox_pack (
1649                &new_subpage_frame (
1650                    &new_hbox_pack (
1651                        &new_text_box_for_int (\%pr::win, 'send_w'),
1652                        &new_text_box_for_int (\%pr::win, 'send_h')),
1653                    _('Send window'), 'not-packed'),
1654                &new_subpage_frame (
1655                    &new_hbox_pack (
1656                        &new_text_box_for_int (\%pr::win, 'recv_w'),
1657                        &new_text_box_for_int (\%pr::win, 'recv_h')),
1658                    _('Receive window'), 'not-packed')
1659            );
1660 }
1661
1662 sub new_winpos_subpage_fold() {
1663     return &new_vbox_pack (
1664                &new_subpage_frame (
1665                    &new_vbox_pack_compact (
1666                        &new_vbox_pack (
1667                             &new_text_box_for_int (\%pr::win, 'fold_x'), 
1668                             &new_text_box_for_int (\%pr::win, 'fold_y')), 
1669                        &new_hbox_pack (
1670                            &new_text_box_for_int (\%pr::win, 'fold_w'), 
1671                            &new_text_box_for_int (\%pr::win, 'fold_h'))),
1672                    _('Folder window'), 'not-packed'),
1673                &new_subpage_frame (
1674                    &new_hbox_pack (
1675                        &new_text_box_for_int (\%pr::win, 'fsel_w'),
1676                        &new_text_box_for_int (\%pr::win, 'fsel_h')),
1677                    _('Folder selection window'), 'not-packed')
1678            );
1679 }
1680
1681 sub new_winpos_subpage_addrbook() {
1682     return &new_vbox_pack (
1683                 &new_subpage_frame (
1684                      &new_hbox_pack (
1685                           &new_text_box_for_int (\%pr::win, 'addr_w'),
1686                           &new_text_box_for_int (\%pr::win, 'addr_h')),
1687                      _('Addressbook main window'), 'not-packed'),
1688                 &new_subpage_frame (
1689                      &new_hbox_pack (
1690                           &new_text_box_for_int (\%pr::win, 'adep_w'),
1691                           &new_text_box_for_int (\%pr::win, 'adep_h')),
1692                      _('Edit person window'), 'not-packed'),
1693                 &new_subpage_frame (
1694                      &new_hbox_pack (
1695                           &new_text_box_for_int (\%pr::win, 'adeg_w'),
1696                           &new_text_box_for_int (\%pr::win, 'adeg_h')),
1697                      _('Edit group window'), 'not-packed'),
1698                 &new_subpage_frame (
1699                      &new_hbox_pack (
1700                           &new_text_box_for_int (\%pr::win, 'adda_w'),
1701                           &new_text_box_for_int (\%pr::win, 'adda_h')),
1702                      _('Add address window'), 'not-packed'),
1703                 &new_subpage_frame (
1704                      &new_hbox_pack (
1705                           &new_text_box_for_int (\%pr::win, 'addf_w'),
1706                           &new_text_box_for_int (\%pr::win, 'addf_h')),
1707                      _('Folder select window'), 'not-packed')
1708            );
1709 }
1710
1711 sub new_winpos_subpage_accounts() {
1712     return &new_vbox_pack (
1713                 &new_subpage_frame (
1714                      &new_hbox_pack (
1715                           &new_text_box_for_int (\%pr::win, 'acco_w'),
1716                           &new_text_box_for_int (\%pr::win, 'acco_h')),
1717                      _('Accounts window'), 'not-packed'),
1718                 &new_subpage_frame (
1719                      &new_hbox_pack (
1720                           &new_text_box_for_int (\%pr::win, 'acce_w'),
1721                           &new_text_box_for_int (\%pr::win, 'acce_h')),
1722                      _('Edit account window'), 'not-packed')
1723            );
1724 }
1725
1726 sub new_winpos_subpage_filtering() {
1727     return &new_vbox_pack (
1728                 &new_subpage_frame (
1729                      &new_hbox_pack (
1730                           &new_text_box_for_int (\%pr::win, 'filt_w'),
1731                           &new_text_box_for_int (\%pr::win, 'filt_h')),
1732                      _('Filtering window'), 'not-packed'),
1733                 &new_subpage_frame (
1734                      &new_hbox_pack (
1735                           &new_text_box_for_int (\%pr::win, 'fila_w'),
1736                           &new_text_box_for_int (\%pr::win, 'fila_h')),
1737                      _('Filtering actions window'), 'not-packed'),
1738                 &new_subpage_frame (
1739                      &new_hbox_pack (
1740                           &new_text_box_for_int (\%pr::win, 'fild_w'),
1741                           &new_text_box_for_int (\%pr::win, 'fild_h')),
1742                      _('Filtering debug window'), 'not-packed'),
1743                 &new_subpage_frame (
1744                      &new_hbox_pack (
1745                           &new_text_box_for_int (\%pr::win, 'matc_w'),
1746                           &new_text_box_for_int (\%pr::win, 'matc_h')),
1747                      _('Matcher window'), 'not-packed')
1748            );
1749 }
1750
1751 sub new_winpos_subpage_prefs() {
1752     return &new_vbox_pack (
1753                 &new_subpage_frame (
1754                      &new_hbox_pack (
1755                           &new_text_box_for_int (\%pr::win, 'pref_w'),
1756                           &new_text_box_for_int (\%pr::win, 'pref_h')),
1757                      _('Preferences window'), 'not-packed'),
1758                 &new_subpage_frame (
1759                      &new_hbox_pack (
1760                           &new_text_box_for_int (\%pr::win, 'temp_w'),
1761                           &new_text_box_for_int (\%pr::win, 'temp_h')),
1762                      _('Templates window'), 'not-packed'),
1763                 &new_subpage_frame (
1764                      &new_hbox_pack (
1765                           &new_text_box_for_int (\%pr::win, 'acti_w'),
1766                           &new_text_box_for_int (\%pr::win, 'acti_h')),
1767                      _('Actions window'), 'not-packed'),
1768                 &new_subpage_frame (
1769                      &new_hbox_pack (
1770                           &new_text_box_for_int (\%pr::win, 'tags_w'),
1771                           &new_text_box_for_int (\%pr::win, 'tags_h')),
1772                      _('Tags window'), 'not-packed'),
1773                 &new_subpage_frame (
1774                      &new_hbox_pack (
1775                           &new_text_box_for_int (\%pr::win, 'plug_w'),
1776                           &new_text_box_for_int (\%pr::win, 'plug_h')),
1777                      _('Plugins window'), 'not-packed')
1778            );
1779 }
1780
1781 sub new_winpos_subpage_misc() {
1782     return &new_vbox_pack (
1783                 &new_subpage_frame (
1784                      &new_hbox_pack (
1785                           &new_text_box_for_int (\%pr::win, 'logw_w'),
1786                           &new_text_box_for_int (\%pr::win, 'logw_h')),
1787                      _('Log window'), 'not-packed'),
1788                 &new_subpage_frame (
1789                      &new_hbox_pack (
1790                           &new_text_box_for_int (\%pr::win, 'prin_w'),
1791                           &new_text_box_for_int (\%pr::win, 'prin_h')),
1792                      _('Print preview window'), 'not-packed'),
1793                 &new_subpage_frame (
1794                      &new_hbox_pack (
1795                           &new_text_box_for_int (\%pr::win, 'sour_w'),
1796                           &new_text_box_for_int (\%pr::win, 'sour_h')),
1797                      _('View source window'), 'not-packed')
1798            );
1799 }
1800
1801 sub new_winpos_page() {
1802     my $winbook = Gtk2::Notebook->new;
1803     $winbook->set_tab_pos ('right');
1804     $winbook->append_page (&new_winpos_subpage_main, _('Main'));
1805     $winbook->append_page (&new_winpos_subpage_msgs, _('Message'));
1806     $winbook->append_page (&new_winpos_subpage_sendrecv, _('Send/Receive'));
1807     $winbook->append_page (&new_winpos_subpage_fold, _('Folder'));
1808     $winbook->append_page (&new_winpos_subpage_addrbook, _('Addressbook'));
1809     $winbook->append_page (&new_winpos_subpage_accounts, _('Accounts'));
1810     $winbook->append_page (&new_winpos_subpage_filtering, _('Filtering'));
1811     $winbook->append_page (&new_winpos_subpage_prefs, _('Preferences'));
1812     $winbook->append_page (&new_winpos_subpage_misc, _('Other'));
1813     return $winbook;
1814 }
1815
1816 # version info
1817 sub print_version() {
1818     print $xl::s{about_title} . "\n";
1819     print $xl::s{about_version} . " $VERSION\n";
1820     print "Perl-GLib " . $Glib::VERSION;
1821     # version info stuff appeared in 1.040
1822     if ($Glib::VERSION >= 1.040) {
1823         print _(", built for ") . join(".", Glib->GET_VERSION_INFO) 
1824               . _(", running with ") . join(".", &Glib::major_version, 
1825               &Glib::minor_version, &Glib::micro_version);
1826     }
1827     print "\n";
1828     print "Perl-GTK2 " . $Gtk2::VERSION;
1829     if ($Gtk2::VERSION >= 1.040) {
1830         print _(", built for ") . join(".", Gtk2->GET_VERSION_INFO)
1831               . _(", running with ") . join(".", &Gtk2::major_version, 
1832               &Gtk2::minor_version, &Gtk2::micro_version);
1833     }
1834     print "\n";
1835     my $clawsver = ($CLAWSV eq "") ? 
1836                 _("was not found!") : 
1837                 (_("returned version ") . $CLAWSV);
1838     print "Claws Mail " . $clawsver . "\n";
1839 }
1840
1841 # the command line help
1842 sub print_help() {
1843     my $line = '-' x length ($xl::s{about_title}) . "\n";
1844     print $line;
1845     print $xl::s{about_title} . "\n";
1846     print $line;
1847     print _("Syntax:\n");
1848     print _("    clawsker [options]\n");
1849     print _("Options:\n");
1850     print _("    --help                         Prints this help screen.\n");
1851     print _("    --version                      Prints version infos.\n");
1852     print _("    --verbose                      More messages on standard output.\n");
1853     print _("    --alternate-config-dir <dir>   Uses <dir> as Claws Mail config dir.\n");
1854     print _("    --clawsrc <file>               Uses <file> as full resource name.\n");
1855 }
1856
1857 # handle errors which don't allow to run
1858 sub command_line_fatal() {
1859     my $reason = shift;
1860     my $emsg = $xl::s{e_error} . $reason;
1861     error_dialog ($emsg);
1862     log_message ("$emsg", 'die');
1863 }
1864
1865 # parse the command line
1866 sub parse_command_line() {
1867     $CLAWSV = &get_claws_version;
1868     my $arg = 0;
1869     while (defined($ARGV[$arg])) {
1870         for ($ARGV[$arg]) {
1871             /--help/ && do { 
1872                 &print_help; 
1873                 return FALSE;
1874             };
1875             /--version/ && do { 
1876                 &print_version; 
1877                 return FALSE;
1878             };
1879             /--verbose/ && do {
1880                 $VERBOSE = TRUE;
1881                 last;
1882             };
1883             /--use-claws-version/ && do {
1884                 ++$arg;
1885                 &command_line_fatal ("required version")
1886                     unless defined($ARGV[$arg]);
1887                 &command_line_fatal ("required a dotted numeric value")
1888                     unless ($ARGV[$arg] =~ /[\d\.]+/);
1889                 $CLAWSV = $ARGV[$arg];
1890                 last;
1891             };
1892             /--alternate-config-dir/ && do {
1893                 ++$arg;
1894                 &command_line_fatal ($xl::s{e_requireddir})
1895                     unless defined($ARGV[$arg]);
1896                 &command_line_fatal ($xl::s{e_notadir})
1897                     unless -d $ARGV[$arg];
1898                 $CONFIGDIR = $ARGV[$arg];
1899                 $CONFIGDIR .= "/" 
1900                     unless ($CONFIGDIR =~ /.*\/$/);
1901                 $ALTCONFIGDIR = TRUE;
1902                 last;
1903             };
1904             /--clawsrc/ && do {
1905                 ++$arg;
1906                 &command_line_fatal($xl::s{e_requiredfile}) 
1907                     unless defined($ARGV[$arg]);
1908                 &command_line_fatal($xl::s{e_notafile}) 
1909                     unless -f $ARGV[$arg];
1910                 &set_rc_filename ($ARGV[$arg]);
1911                 last;
1912             };
1913             /.*/ && &command_line_fatal (
1914                 _("unknown option '{opt}'.\n", opt => $ARGV[$arg]));
1915         }
1916         ++$arg;
1917     }
1918     # eveything continues...
1919     return TRUE;
1920 }
1921
1922 # update the hidden preferences status from loaded values
1923 sub init_hidden_preferences() {
1924     foreach my $hash (\%pr::beh, \%pr::col, \%pr::gui, \%pr::oth, \%pr::win) {
1925         foreach my $key (keys %$hash) { 
1926             $HPVALUE{${$hash}{$key}[NAME]} = $PREFS{${$hash}{$key}[NAME]};
1927         }
1928     }
1929     return TRUE;
1930 }
1931
1932 # load current status from disc
1933 sub load_preferences() {
1934     my $rc = &get_rc_filename;
1935     &log_message ("Loading preferences from $rc\n");
1936     return FALSE unless &check_rc_file ($rc);
1937     return FALSE unless &check_claws_not_running;
1938     open (RCF, "<$rc");
1939     while (<RCF>) {
1940         chomp;
1941         if (/^([8a-z_]+)=(.*)$/) {
1942             $PREFS{$1} = "$2";
1943         }
1944     }
1945     close (RCF);
1946     return TRUE;
1947 }
1948
1949 # save current preferences to disc
1950 sub save_preferences() {
1951     my $rc = &get_rc_filename;
1952     &log_message ("Saving preferences to $rc\n");
1953     return FALSE unless &check_rc_file ($rc);
1954     return FALSE unless &check_claws_not_running;
1955     my $rcbak = "$rc.backup";
1956     rename ($rc, $rcbak);
1957     open (RCF, ">$rc");
1958     open (RCB, "<$rcbak");
1959     while (<RCB>) {
1960         chomp;
1961         if (/^([8a-z_]+)=(.*)$/) {
1962             if (defined($HPVALUE{$1})) {
1963                 print RCF $1 . "=" . $HPVALUE{$1} . "\n";
1964             }
1965             else {
1966                 print RCF $_ . "\n";
1967             }
1968         }
1969         else {
1970             print RCF $_ . "\n";
1971         }
1972     }
1973     close (RCB);
1974     close (RCF);
1975     return TRUE;
1976 }
1977
1978 # create notebook
1979 sub new_notebook() {
1980     my $nb = Gtk2::Notebook->new;
1981     # 
1982     $nb->append_page (&new_behaviour_page, $xl::s{tab_behaviour});
1983     $nb->append_page (&new_colours_page, $xl::s{tab_colours});
1984     $nb->append_page (&new_gui_page, $xl::s{tab_gui});
1985     $nb->append_page (&new_other_page, $xl::s{tab_other});
1986     $nb->append_page (&new_winpos_page, $xl::s{tab_winpos});
1987
1988     return $nb;
1989 }
1990
1991 # create an about dialog
1992 sub new_about_dialog() {
1993     my ($parent) = @_;
1994     my $title = $xl::s{about_title};
1995     my $lic = $xl::s{about_license};
1996     my $vers = $xl::s{about_version} . " $VERSION";
1997     my $license = 
1998 "This program is free software: you can redistribute it and/or modify
1999 it under the terms of the GNU General Public License as published by
2000 the Free Software Foundation, either version 3 of the License, or
2001 (at your option) any later version.
2002
2003 This program is distributed in the hope that it will be useful,
2004 but WITHOUT ANY WARRANTY; without even the implied warranty of
2005 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2006 GNU General Public License for more details.
2007
2008 You should have received a copy of the GNU General Public License
2009 along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.";
2010     my $year = "2007-2013";
2011     my $holder = "Ricardo Mones &lt;ricardo\@mones.org&gt;";
2012     my $url = "http://www.claws-mail.org/clawsker.php";
2013
2014     my $dialog = Gtk2::MessageDialog->new_with_markup ($parent, 
2015                     [qw/modal destroy-with-parent/], 
2016                     'info', 'close', 
2017                     "<span size=\"x-large\" weight=\"bold\">$title</span>\n"
2018                     . "<span size=\"large\">$vers</span>\n\n"
2019                     . "<span color=\"blue\" size=\"large\">$url</span>\n\n"
2020                     . "<span>Copyright $year by $holder</span>\n\n"
2021                     . "<span size=\"large\">$lic</span>\n\n"
2022                     . "<span size=\"small\">$license</span>");
2023     $dialog->set_title ($xl::s{about});
2024     #
2025     return $dialog;
2026 }
2027
2028 # create buttons box
2029 sub new_button_box() {
2030     my ($parent, $adlg) = @_;
2031     my $b_about = Gtk2::Button->new_from_stock ('gtk-about');
2032     my $b_exit = Gtk2::Button->new_from_stock ('gtk-quit');
2033     my $b_apply = Gtk2::Button->new_from_stock ('gtk-apply');
2034     # disable button until is really implemented
2035     # my $b_undo = Gtk2::Button->new_from_stock ('gtk-undo');
2036     my $hbox = Gtk2::HBox->new (FALSE, 5);
2037     # signal handlers 
2038     $b_exit->signal_connect (clicked => sub { Gtk2->main_quit });
2039     $b_apply->signal_connect (clicked => sub { &save_preferences ($parent) });
2040     # $b_undo->signal_connect (clicked => sub { &undo_current_changes });
2041     $b_about->signal_connect (clicked => sub { $adlg->run; $adlg->hide });
2042     # package them
2043     $hbox->pack_end ($b_apply, FALSE, FALSE, 0);
2044     $hbox->pack_end ($b_exit, FALSE, FALSE, 0);
2045     # $hbox->pack_end ($b_undo, FALSE, FALSE, 0);
2046     $hbox->pack_start ($b_about, FALSE, FALSE, 0);
2047     #
2048     return $hbox;
2049 }
2050
2051 # initialise
2052 $main_window = Gtk2::Window->new ('toplevel');
2053 exit unless &parse_command_line;
2054 exit unless &load_preferences;
2055 exit unless &init_hidden_preferences;
2056 # create main GUI
2057 my $box = Gtk2::VBox->new (FALSE, 5);
2058 $box->set_border_width(3);
2059 my $about = &new_about_dialog;
2060 $box->pack_start (&new_notebook, FALSE, FALSE, 0);
2061 $box->pack_end (&new_button_box ($main_window, $about), FALSE, FALSE, 0);
2062 $main_window->signal_connect (delete_event => sub { Gtk2->main_quit });
2063 $main_window->set_title ($xl::s{win_title});
2064 $main_window->add ($box);
2065 $main_window->show_all;
2066 Gtk2->main;
2067