Conform to current hidden preferences
[clawsker.git] / clawsker
1 #!/usr/bin/perl -w
2 #
3 # Clawsker :: A Claws Mail Tweaker
4 # Copyright 2007-2016 Ricardo Mones <ricardo@mones.org>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # See COPYING file for license details.
12 # See AUTHORS file for a complete list of contributors.
13 #
14
15 binmode STDOUT, ":encoding(utf8)";
16
17 use 5.010_000;
18 use strict;
19 use utf8;
20 use version 0.77;
21 use Glib qw(TRUE FALSE);
22 use Gtk2;
23 use POSIX qw(setlocale);
24 use Locale::gettext;
25 use Encode;
26 use Digest::MD5 qw(md5_hex);
27 use Getopt::Long;
28
29 my $NAME = 'clawsker';
30 my $PREFIX = '@PREFIX@';
31 my $LIBDIR = '@LIBDIR@';
32 my $DATADIR = '@DATADIR@';
33 my $VERSION = '@VERSION@';
34 my $VERBOSE = FALSE;
35 my $READONLY = FALSE;
36 my $CLAWSV = undef;
37 my $main_window = undef;
38
39 my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
40 $locale = "C" unless defined($locale);
41 setlocale (LC_ALL, $locale);
42 bindtextdomain ($NAME, sprintf ('%s/share/locale', $PREFIX));
43 textdomain ($NAME);
44
45 my $SHOWHINTS = FALSE;
46 $SHOWHINTS = TRUE if ($Gtk2::VERSION >= 1.040 and Gtk2->CHECK_VERSION (2, 12, 0));
47
48 sub _ {
49     my $str = shift;
50     my %par = @_;
51     my $xla = gettext ($str);
52     if (scalar(keys(%par)) > 0) {
53         foreach my $key (keys %par) {
54             $xla =~ s/\{$key\}/$par{$key}/g;
55         }
56     }
57     return decode_utf8($xla);
58 }
59
60 # default messages
61 %xl::s = (
62     win_title => _('Claws Mail Hidden Preferences'),
63     about => _('About...'),
64     about_title => _('Clawsker :: A Claws Mail Tweaker'),
65     about_license => _('License:'),
66     about_version => _('Version:'),
67
68     tab_colours => _('Colours'),
69     tab_behaviour => _('Behaviour'),
70     tab_gui => _('GUI'),
71     tab_other => _('Other'),
72     tab_winpos => _('Windows'),
73     tab_accounts => _('Accounts'),
74     tab_plugins => _('Plugins'),
75     tab_info => _('Info'),
76
77     ab_frame => _('Addressbook'),
78     mem_frame => _('Memory'),
79     msgview_frame => _('Message View'),
80     log_frame => _('Log window'),
81     dnd_frame => _('Drag \'n\' drop'),
82     ssl_frame => _('Secure Sockets Layer'),
83     msgs_frame => _('Messages'),
84     swc_frame => _('Completion'),
85     stripes_frame => _('Coloured stripes'),
86     sbar_frame => _('Scroll bars'),
87     mlist_frame => _('Message List'),
88     mview_frame => _('Message View'),
89     compo_frame => _('Compose window'),
90     netm_frame => _('NetworkManager'),
91     diff_frame => _('Viewing patches'),
92     mpass_frame => _('Master passphrase'),
93     compose_frame => _('Compose window'),
94     qs_frame => _('Quick search'),
95
96     l_oth_use_dlg => _('Use detached address book edit dialogue'),
97     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.'),
98     l_oth_max_use => _('Maximum memory for message cache (kB)'),
99     h_oth_max_use => _('The maximum amount of memory to use to cache messages, in kilobytes.'),
100     l_oth_min_time => _('Minimun time for cache elements (minutes)'),
101     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.'),
102     l_oth_use_netm => _('Use NetworkManager'),
103     h_oth_use_netm => _('Use NetworkManager to switch offline automatically.'),
104     l_oth_mp_rounds => _('Rounds for PBKDF2 function'),
105     h_oth_mp_rounds => _('Specify the number of iterations the key derivation function will be applied on master passphrase computation. Does not modify currently stored passphrase, only master passphrases computed after changing this value are affected.'),
106
107     l_gui_b_unread => _('Show unread messages with bold font'),
108     h_gui_b_unread => _('Show unread messages in the Message List using a bold font.'),
109     l_gui_no_markup => _('Don\'t use markup'),
110     h_gui_no_markup => _('Don\'t use bold and italic text in Compose dialogue\'s account selector.'),
111     l_gui_dot_lines => _('Use dotted lines in tree view components'),
112     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.'),
113     l_gui_h_scroll => _('Enable horizontal scrollbar'),
114     h_gui_h_scroll => _('Enable the horizontal scrollbar in the Message List.'),
115     l_gui_swp_from => _('Display To column instead From column in Sent folder'),
116     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.'),
117     l_gui_v_scroll => _('Folder List scrollbar behaviour'),
118     h_gui_v_scroll => _('Specify the policy of vertical scrollbar of Folder List: show always, automatic or hide always.'),
119     l_gui_v_scroll_show => _('Show always'),
120     l_gui_v_scroll_auto => _('Automatic'),
121     l_gui_v_scroll_hide => _('Hide always'),
122     l_gui_from_show => _('From column displays'),
123     h_gui_from_show => _('Selects the data displayed in the From column of the Message List: name, address or both.'),
124     l_gui_from_show_name => _('Name only'),
125     l_gui_from_show_addr => _('Address only'),
126     l_gui_from_show_both => _('Both name and address'),
127     l_gui_strip_off => _('Coloured lines contrast'),
128     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.'),
129     l_gui_cursor_v => _('Show cursor'),
130     h_gui_cursor_v => _('Display the cursor in the Message View.'),
131     l_gui_toolbar_d => _('Detachable toolbars'),
132     h_gui_toolbar_d => _('Show handles in the toolbars.'),
133     l_gui_strip_all => _('Use stripes in all tree view components'),
134     h_gui_strip_all => _('Enable alternately coloured lines in all tree view components.'),
135     l_gui_strip_sum => _('Use stripes in Folder List and Message List'),
136     h_gui_strip_sum => _('Enable alternately coloured lines in Message List and Folder List.'),
137     l_gui_two_line_v => _('2 lines per Message List item in 3-column layout'),
138     h_gui_two_line_v => _('Spread Message List information over two lines when using the three column mode.'),
139     l_gui_margin_co => _('Show margin'),
140     h_gui_margin_co => _('Shows a small margin in the Compose View.'),
141     l_gui_mview_date => _('Don\'t display localized date'),
142     h_gui_mview_date => _('Toggles localization of date format in Message View.'),
143     l_gui_zero_char => _('Zero replacement character'),
144     h_gui_zero_char => _('Replaces \'0\' with the given character in Folder List.'),
145     l_gui_type_any => _('Editable headers'),
146     h_gui_type_any => _('Allows to manually type any value in Compose Window header entries or just select from the available choices in the associated dropdown list.'),
147     l_gui_warn_send_multi => _('Warn when sending to more than'),
148     l_gui_warn_send_multi_units => _('recipients'),
149     h_gui_warn_send_multi => _('Show a warning dialogue when sending to more recipients than specified. Use 0 to disable this check.'),
150     l_gui_next_del => _('Select next message on delete'),
151     h_gui_next_del => _('When deleting a message, toggles between selecting the next one (newer message) or the previous one (older message).'),
152
153     l_beh_hover_t => _('Drag \'n\' drop hover timeout (ms)'),
154     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.'),
155     l_beh_dangerous => _('Don\'t confirm deletions (dangerous!)'),
156     h_beh_dangerous => _('Don\'t ask for confirmation before definitive deletion of emails.'),
157     l_beh_flowed => _('Respect format=flowed in messages'),
158     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.'),
159     l_beh_parts_rw => _('Allow writable temporary files'),
160     h_beh_parts_rw => _('Saves temporary files when opening attachment with write bit set.'),
161     l_beh_skip_ssl => _('Don\'t check SSL certificates'),
162     h_beh_skip_ssl => _('Disables the verification of SSL certificates.'),
163     l_beh_up_step => _('Progress bar update step (items)'),
164     h_beh_up_step => _('Update stepping in progress bars.'),
165     l_beh_thread_a => _('Maximum age when threading by subject (days)'),
166     h_beh_thread_a => _('Number of days to include a message in a thread when using "Thread using subject in addition to standard headers".'),
167     l_beh_unsafe_ssl => _('Allow unsafe SSL certificates'),
168     h_beh_unsafe_ssl => _('Allows Claws Mail to remember multiple SSL certificates for a given server/port.'),
169     l_beh_use_utf8 => _('Force UTF-8 for broken mails'),
170     h_beh_use_utf8 => _('Use UTF-8 encoding for broken mails instead of current locale.'),
171     l_beh_warn_dnd => _('Warn on drag \'n\' drop'),
172     h_beh_warn_dnd => _('Display a confirmation dialogue on drag \'n\' drop of folders.'),
173     l_beh_out_ascii => _('Outgoing messages fallback to ASCII'),
174     h_beh_out_ascii => _('If allowed by content, ASCII will be used to encode outgoing messages, otherwise the user-defined encoding is always enforced.'),
175     l_beh_pp_unsel => _('Primary paste unselects selection'),
176     h_beh_pp_unsel => _('Controls how pasting using middle-click changes the selected text and insertion point.'),
177     l_beh_inline_at => _('Show inline attachments'),
178     h_beh_inline_at => _('Allows to hide inline attachments already shown in mail structure view.'),
179     l_beh_addr_swc => _('Address search in compose window matches any'),
180     h_beh_addr_swc => _('On Tab-key completion, address text will match any part of the string or only from the start.'),
181     l_beh_fold_swc => _('Folder search in folder selector matches any'),
182     h_beh_fold_swc => _('On folder name completion text will match any part of the string or only from the start.'),
183     l_beh_rewrite_ff => _('Rewrite first \'From\' using QP encoding'),
184     h_beh_rewrite_ff => _('Workaround some servers which convert first \'From\' to \'>From\' by using Quoted-Printable transfer encoding instead of 7bit/8bit encoding.'),
185
186     l_col_emphasis => _('X-Mailer header'),
187     h_col_emphasis => _('The colour used for the X-Mailer line when its value is Claws Mail.'),
188     l_col_log_err => _('Error messages'),
189     h_col_log_err => _('Colour for error messages in log window.'),
190     l_col_log_in => _('Server messages'),
191     h_col_log_in => _('Colour for messages received from servers in log window.'),
192     l_col_log_msg => _('Standard messages'),
193     h_col_log_msg => _('Colour for messages in log window.'),
194     l_col_log_out => _('Client messages'),
195     h_col_log_out => _('Colour for messages sent to servers in log window.'),
196     l_col_log_warn => _('Warning messages'),
197     h_col_log_warn => _('Colour for warning messages in log window.'),
198
199     l_col_tags_bg => _('Tags background'),
200     h_col_tags_bg => _('Background colour for tags in message view.'),
201     l_col_tags_text => _('Tags text'),
202     h_col_tags_text => _('Text colour for tags in message view.'),
203
204     l_col_default_header_bg => _('Default headers background'),
205     h_col_default_header_bg => _('Background colour for default headers in compose window.'),
206     l_col_default_header_text => _('Default headers text'),
207     h_col_default_header_text => _('Text colour for default headers in compose window.'),
208
209     l_col_qs_active_bg => _('Active quick search background'),
210     h_col_qs_active_bg => _('Background colour for active quick search.'),
211     l_col_qs_active_text => _('Active quick search text'),
212     h_col_qs_active_text => _('Text colour for active quick search.'),
213     l_col_qs_error_bg => _('Quick search error background'),
214     h_col_qs_error_bg => _('Background colour for quick search error.'),
215     l_col_qs_error_text => _('Quick search error text'),
216     h_col_qs_error_text => _('Text colour for quick search error.'),
217
218     l_col_diff_add => _('Added lines'),
219     h_col_diff_add => _('Colour for added lines in patches.'),
220     l_col_diff_del => _('Deleted lines'),
221     h_col_diff_del => _('Colour for deleted lines in patches.'),
222     l_col_diff_hunk => _('Hunk lines'),
223     h_col_diff_hunk => _('Colour for hunk headers in patches.'),
224
225     l_win_x => _('X position'),
226     h_win_x => _('X coordinate for window\'s top-left corner.'),
227     l_win_y => _('Y position'),
228     h_win_y => _('Y coordinate for window\'s top-left corner.'),
229     l_win_w => _('Width'),
230     h_win_w => _('Window\'s width in pixels.'),
231     l_win_h => _('Height'),
232     h_win_h => _('Window\'s height in pixels.'),
233
234     l_win_main_mx => _('Maximized'),
235     h_win_main_mx => _('Changes window maximized status.'),
236     l_win_main_fs => _('Full-screen'),
237     h_win_main_fs => _('Changes full screen status.'),
238
239     l_acc_gtls_set => _('Use custom GnuTLS priority'),
240     h_acc_gtls_set => _('Enables using user provided GnuTLS priority string.'),
241     l_acc_gtls_pri => _('GnuTLS priority'),
242     h_acc_gtls_pri => _('Value to use as GnuTLS priority string if custom priority check is enabled. Otherwise this value is ignored.'),
243
244     l_plu_gpg_alimit => _('Autocompletion limit'),
245     h_plu_gpg_alimit => _('Limits the number of addresses obtained from keyring through autocompletion. Use 0 to get all matches.'),
246     l_plu_lav_burl => _('Base URL'),
247     h_plu_lav_burl => _('This is the URL where avatar requests are sent. You can use the one of your own libravatar server, if available.'),
248     l_plu_prl_flvb => _('Log level'),
249     h_plu_prl_flvb => _('Verbosity level of log, accumulative.'),
250     l_plu_prl_none => _('None'),
251     l_plu_prl_manual => _('Manual'),
252     l_plu_prl_action => _('Actions'),
253     l_plu_prl_match => _('Matches'),
254 );
255
256 # data and metadata of resource files
257 my $CONFIGDATA;
258 my $CONFIGMETA;
259 my $ACCOUNTDATA;
260 my $ACCOUNTMETA;
261 # all preferences read by load_preferences
262 my %PREFS = ();
263 my %ACPREFS = ();
264 my %PLPREFS = ();
265 # values of all preferences handled by clawsker
266 my %HPVALUE = ();
267 my %ACHPVALUE = ();
268 my %PLHPVALUE = ();
269 # default config dir and file name
270 my $ALTCONFIGDIR = FALSE;
271 my $CONFIGDIR = $ENV{HOME} . '/.claws-mail/';
272 my $CONFIGRC = 'clawsrc';
273 my $ACCOUNTRC = 'accountrc';
274 # supported and available plugins lists
275 my @PLUGINS = qw(AttRemover GPG ManageSieve Libravatar PerlPlugin);
276 my @AVPLUGINS = ();
277 # loaded icons
278 my @APPICONS = ();
279
280 # index constants for preference arrays
281 use constant NAME  => 0; # the name on the rc file
282 use constant LABEL => 1; # the label on the GUI
283 use constant DESC  => 2; # the description for the hint/help
284 use constant TYPE  => 3; # data type: bool, int, float, string, color
285 use constant CMVER => 4; # lowest[,highest] Claws Mail version(s) the feature exists
286 use constant CMDEF => 5; # default value for the preference in Claws Mail
287 use constant PLUGIN => 6; # plugin section (only in plugin preferences)
288
289 # constants for GUI spacing
290 use constant HBOX_PAD => 5;
291 use constant FRAME_SPC => 2;
292 use constant PAGE_SPC => 5;
293
294 # version functions
295
296 sub version_greater_or_equal {
297     my ($version, $refvers) = @_;
298     return TRUE if (length($version) == 0 and length($refvers) >= 0);
299     return FALSE if (length($version) >= 0 and length($refvers) == 0);
300     return TRUE if (version->parse($version) >= version->parse($refvers));
301     return FALSE;
302 }
303
304 sub get_claws_version {
305     $_ = qx/which claws-mail/;
306     chomp;
307     return "" unless ($_); # not installed
308     my $res = "";
309     $_ = qx/$_ -v/;
310     chomp;
311     my @fver = split (/ /);
312     die "Invalid version string" unless ($fver[2] eq "version");
313     my @ver = split (/\./, $fver[3]);
314     $res .= "$ver[0].";
315     $res .= "$ver[1].";
316     if ($ver[2] =~ /(\d+)git(\d+)/) {
317         $res .= "$1.$2";
318     }
319     else {
320         $res .= "$ver[2].0";
321     }
322     return $res;
323 }
324
325 # data handlers and auxiliar functions
326
327 sub handle_bool_value {
328     my ($widget, $event, $dataref) = @_;
329     $$dataref = ($widget->get_active ())? '1': '0';
330 }
331
332 sub handle_int_value {
333     my ($widget, $event, $dataref) = @_;
334     $_ = $widget->get_text ();
335     s/^\s+//;
336     s/\s+$//;
337     if (/^[0-9]+$/) {
338         $$dataref = $_;
339         $widget->set_text ($_);
340     }
341     else {
342         $widget->set_text ($$dataref);
343     }
344 }
345
346 sub handle_string_value {
347     my ($widget, $event, $dataref) = @_;
348     $$dataref = $widget->get_text ();
349 }
350
351 sub handle_nchar_value {
352     my ($widget, $event, $dataref, $minlen, $maxlen) = @_;
353     $_ = substr ($widget->get_text (), 0, $maxlen);
354     $widget->set_text ($_);
355     $$dataref = $_;
356 }
357
358 sub gdk_color_from_str {
359     my ($str) = @_;
360     my ($rr, $gg, $bb) = (0, 0 ,0);
361     $_ = uc ($str);
362     if (/\#([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])/) {
363         $rr = hex($1) * 256;
364         $gg = hex($2) * 256;
365         $bb = hex($3) * 256;
366     }
367     my $color = Gtk2::Gdk::Color->new ($rr, $gg, $bb);
368     return $color;
369 }
370
371 sub str_from_gdk_color {
372     my ($color) = @_;
373     my $rr = $color->red / 256;
374     my $gg = $color->green / 256;
375     my $bb = $color->blue / 256;
376     my $str = sprintf ("#%.2x%.2x%.2x", $rr, $gg, $bb);
377     return $str;
378 }
379
380 sub handle_color_value {
381     my ($widget, $event, $dataref) = @_;
382     my $newcol = $widget->get_color;
383     $$dataref = str_from_gdk_color ($newcol);
384 }
385
386 sub handle_selection_value {
387     my ($widget, $event, $dataref) = @_;
388     $$dataref = $widget->get_active;
389 }
390
391 sub get_rc_filename {
392     return $CONFIGDIR . $CONFIGRC;
393 }
394
395 sub get_ac_rc_filename {
396     return $CONFIGDIR . $ACCOUNTRC;
397 }
398
399 sub set_rc_filename {
400     my ($fullname) = @_;
401     my @parts = split ('/', $fullname);
402     $CONFIGRC = $parts[$#parts];
403     $parts[$#parts] = '';
404     $CONFIGDIR = join ('/', @parts);
405 }
406
407 sub log_message {
408     my ($mesg, $fatal) = @_;
409     if (defined($fatal) && $fatal eq 'die') {
410         die "$NAME: $mesg\n";
411     }
412     if ($VERBOSE) {
413         print "$NAME: $mesg\n";
414     }
415 }
416
417 sub error_dialog {
418     my ($emsg) = @_;
419     my $markup = "<span weight=\"bold\" size=\"large\">" . $emsg . "</span>";
420     my $errordlg = Gtk2::MessageDialog->new_with_markup ($main_window, 'modal', 'error', 'cancel', $markup);
421     $errordlg->set_title (_('Clawsker error'));
422     $errordlg->run;
423     $errordlg->destroy;
424 }
425
426 sub claws_is_running {
427     my $emsg = _('Error: seems Claws Mail is currently running, close it first.');
428     log_message ($emsg);
429     error_dialog ($emsg);
430     return FALSE;
431 }
432
433 sub check_claws_not_running {
434     return TRUE if $READONLY;
435     my $tmpdir = (defined $ENV{TMPDIR})? $ENV{TMPDIR}: '/tmp';
436     $tmpdir = '/tmp' if ($tmpdir eq '');
437     my $lockdir = "$tmpdir/claws-mail-$<";
438     -d $lockdir and do {
439         $_ = $CONFIGDIR;
440         s/\/$//;
441         my $socket = "$lockdir/" . md5_hex ($_);
442         -S $socket and return claws_is_running ();
443     };
444     return TRUE;
445 }
446
447 sub check_rc_file {
448     my ($rcfile) = @_;
449     (defined($rcfile) && -f $rcfile) or do {
450         my $emsg = _('Error: resource file for Claws Mail was not found.');
451         log_message ($emsg);
452         error_dialog ($emsg);
453         return FALSE;
454     };
455     return TRUE;
456 }
457
458 sub set_widget_hint {
459     if ($SHOWHINTS) {
460         my ($wdgt, $hint) = @_;
461         $wdgt->set_tooltip_text ($hint);
462         $wdgt->set_has_tooltip (TRUE);
463     }
464 }
465
466 sub set_widget_sens {
467     my ($wdgt, $versions) = @_;
468     my @ver = split(/,/, $versions);
469     if ($#ver == 1) {
470       $wdgt->set_sensitive (
471         version_greater_or_equal ($CLAWSV, $ver[0])
472         and version_greater_or_equal ($ver[1], $CLAWSV)
473       );
474     } else {
475         $wdgt->set_sensitive (version_greater_or_equal ($CLAWSV, $ver[0]));
476     }
477 }
478
479 # graphic element creation
480
481 sub new_hbox_spaced_pack {
482     my $hbox = Gtk2::HBox->new (FALSE);
483     foreach (@_) {
484         $hbox->pack_start ($_, FALSE, FALSE, HBOX_PAD);
485     }
486     return $hbox;
487 }
488
489 sub new_check_button_for($$$) {
490     my ($hash, $key, $vhash) = @_;
491     my $name = $$hash{$key}[NAME];
492     my $label = $$hash{$key}[LABEL];
493     #
494     my $cb = Gtk2::CheckButton->new ($label);
495     my $value = $$vhash{$name};
496     $value //= $$hash{$key}[CMDEF];
497     $cb->set_active ($value eq '1');
498     $cb->signal_connect (clicked => sub {
499             my ($w, $e) = @_;
500             handle_bool_value ($w, $e, \$$vhash{$name});
501         });
502     set_widget_hint ($cb, $$hash{$key}[DESC]);
503     set_widget_sens ($cb, $$hash{$key}[CMVER]);
504     #
505     return new_hbox_spaced_pack ($cb);
506 }
507
508 sub new_text_box_for_int($$$) {
509     my ($hash, $key, $vhash) = @_;
510     my $name = $$hash{$key}[NAME];
511     my $label = $$hash{$key}[LABEL];
512     my @type = split (/,/, $$hash{$key}[TYPE]);
513     push (@type, 0), push (@type, 10000) unless ($#type > 0);
514     #
515     my $gunits = undef;
516     if (ref $label eq 'ARRAY') {
517         $gunits = Gtk2::Label->new ($label->[1]);
518         $label = $label->[0];
519     }
520     my $glabel = Gtk2::Label->new ($label);
521     my $pagei = int (($type[2] - $type[1]) / 10);
522     my $gentry = Gtk2::SpinButton->new_with_range ($type[1], $type[2], $pagei);
523     my $value = $$vhash{$name};
524     $value //= $$hash{$key}[CMDEF];
525     $gentry->set_numeric (TRUE);
526     $gentry->set_value ($value);
527     $gentry->signal_connect('value-changed' => sub {
528             my ($w, $e) = @_;
529             handle_int_value ($w, $e, \$$vhash{$name});
530         });
531     set_widget_hint ($gentry, $$hash{$key}[DESC]);
532     set_widget_sens ($gentry, $$hash{$key}[CMVER]);
533     $glabel->set_sensitive ($gentry->sensitive);
534     $gunits->set_sensitive ($gentry->sensitive) if ($gunits);
535     #
536     return new_hbox_spaced_pack ($glabel, $gentry, $gunits) if ($gunits);
537     return new_hbox_spaced_pack ($glabel, $gentry);
538 }
539
540 sub new_text_box_for_nchar($$$) {
541     my ($hash, $key, $vhash) = @_;
542     my $name = $$hash{$key}[NAME];
543     my $label = $$hash{$key}[LABEL];
544     my @type = split (/,/, $$hash{$key}[TYPE]); # char,minlen,maxlen,width
545     my $glabel = Gtk2::Label->new ($label);
546     my $gentry = Gtk2::Entry->new ();
547     $gentry->set_max_length($type[2]) if defined ($type[2]);
548     my $width = $type[3];
549     $width //= $type[2];
550     $gentry->set_width_chars(int ($width) + 2) if defined ($width);
551     my $value = $$vhash{$name};
552     $value //= $$hash{$key}[CMDEF];
553     $gentry->set_text ($value);
554     $gentry->signal_connect('key-release-event' => sub {
555             my ($w, $e) = @_;
556             handle_nchar_value ($w, $e, \$$vhash{$name}, $type[1], $type[2]);
557         });
558     set_widget_hint ($gentry, $$hash{$key}[DESC]);
559     set_widget_sens ($gentry, $$hash{$key}[CMVER]);
560     $glabel->set_sensitive ($gentry->sensitive);
561     #
562     return new_hbox_spaced_pack ($glabel, $gentry);
563 }
564
565 sub new_color_button_for($$$) {
566     my ($hash, $key, $vhash) = @_;
567     my $name = $$hash{$key}[NAME];
568     my $label = $$hash{$key}[LABEL];
569     #
570     my $value = $$vhash{$name};
571     $value //= $$hash{$key}[CMDEF];
572     my $col = gdk_color_from_str ($value);
573     my $glabel = Gtk2::Label->new ($label);
574     my $button = Gtk2::ColorButton->new_with_color ($col);
575     $button->set_title ($label);
576     $button->set_relief ('none');
577     $button->signal_connect ('color-set' => sub {
578             my ($w, $e) = @_;
579             handle_color_value ($w, $e, \$$vhash{$name});
580         });
581     set_widget_hint ($button, $$hash{$key}[DESC]);
582     set_widget_sens ($button, $$hash{$key}[CMVER]);
583     $glabel->set_sensitive ($button->sensitive);
584     #
585     return new_hbox_spaced_pack ($button, $glabel);
586 }
587
588 sub new_selection_box_for($$$) {
589     my ($hash, $key, $vhash) = @_;
590     my $name = $$hash{$key}[NAME];
591     my $label = $$hash{$key}[LABEL];
592     #
593     my $glabel = Gtk2::Label->new ($label);
594     my $combo = Gtk2::ComboBox->new_text;
595     my @options = split (';', $$hash{$key}[TYPE]);
596     foreach my $opt (@options) {
597         my ($index, $textkey) = split ('=', $opt);
598         $combo->insert_text ($index, $xl::s{$textkey});
599     }
600     $combo->signal_connect ('changed' => sub {
601             my ($w, $e) = @_;
602             handle_selection_value ($w, $e, \$$vhash{$name});
603         });
604     my $value = $$vhash{$name};
605     $value //= $$hash{$key}[CMDEF];
606     $combo->set_active ($value);
607     set_widget_hint ($combo, $$hash{$key}[DESC]);
608     set_widget_sens ($combo, $$hash{$key}[CMVER]);
609     $glabel->set_sensitive ($combo->sensitive);
610     #
611     return new_hbox_spaced_pack ($glabel, $combo);
612 }
613
614 # more graphic helpers
615
616 sub new_hbox_pack {
617     my $hbox = Gtk2::HBox->new (FALSE);
618     $hbox->set_border_width (PAGE_SPC);
619     foreach (@_) {
620         $hbox->pack_start ($_, FALSE, FALSE, 0);
621     }
622     return $hbox;
623 }
624
625 sub new_hbox_pack_compact {
626     my $hbox = Gtk2::HBox->new (FALSE);
627     $hbox->set_border_width (0);
628     foreach (@_) {
629         $hbox->pack_start ($_, FALSE, FALSE, 0);
630     }
631     return $hbox;
632 }
633
634 sub new_vbox_pack {
635     my $vbox = Gtk2::VBox->new (FALSE, 5);
636     $vbox->set_border_width (PAGE_SPC);
637     foreach (@_) {
638         $vbox->pack_start ($_, FALSE, FALSE, 0);
639     }
640     return $vbox;
641 }
642
643 sub new_vbox_pack_compact {
644     my $vbox = Gtk2::VBox->new (FALSE, 0);
645     $vbox->set_border_width (0);
646     foreach (@_) {
647         $vbox->pack_start ($_, FALSE, FALSE, 0);
648     }
649     return $vbox;
650 }
651
652 sub new_subpage_frame {
653     my ($box, $title, $notpacked) = @_;
654     my $frame = Gtk2::Frame->new ($title);
655     $frame->add ($box);
656     return new_vbox_pack ($frame) unless defined ($notpacked);
657     return $frame;
658 }
659
660 # preference maps and corresponding page creation subs
661
662 %pr::oth = ( # other preferences
663     use_dlg => [
664         'addressbook_use_editaddress_dialog',
665         $xl::s{l_oth_use_dlg},
666         $xl::s{h_oth_use_dlg},
667         'bool',
668         '2.7.0',
669         '0',
670     ],
671     max_use => [
672         'cache_max_mem_usage',
673         $xl::s{l_oth_max_use},
674         $xl::s{h_oth_max_use},
675         'int,0,262144', # 0 Kb - 256 Mb
676         '0.7.8.36',
677         '4096',
678     ],
679     min_time => [
680         'cache_min_keep_time',
681         $xl::s{l_oth_min_time},
682         $xl::s{h_oth_min_time},
683         'int,0,120', # 0 minutes - 2 hours
684         '0.7.8.36',
685         '15',
686     ],
687     use_netm => [
688         'use_networkmanager',
689         $xl::s{l_oth_use_netm},
690         $xl::s{h_oth_use_netm},
691         'bool',
692         '3.3.1',
693         '1',
694     ],
695     mp_rounds => [
696         'master_passphrase_pbkdf2_rounds',
697         $xl::s{l_oth_mp_rounds},
698         $xl::s{h_oth_mp_rounds},
699         'int,50000,1000000',
700         '3.13.2.110',
701         '50000',
702     ],
703 );
704
705 sub new_other_page() {
706     return new_vbox_pack (
707                new_subpage_frame (
708                    new_vbox_pack (
709                        new_check_button_for(\%pr::oth, 'use_dlg', \%HPVALUE)),
710                    $xl::s{ab_frame}, 'not-packed'),
711                new_subpage_frame (
712                    new_vbox_pack (
713                        new_text_box_for_int(\%pr::oth, 'max_use', \%HPVALUE),
714                        new_text_box_for_int(\%pr::oth, 'min_time', \%HPVALUE)),
715                    $xl::s{mem_frame}, 'not-packed'),
716                new_subpage_frame (
717                    new_vbox_pack (
718                        new_check_button_for(\%pr::oth, 'use_netm', \%HPVALUE)),
719                    $xl::s{netm_frame}, 'not-packed'),
720                new_subpage_frame (
721                    new_vbox_pack (
722                        new_text_box_for_int(\%pr::oth, 'mp_rounds', \%HPVALUE)),
723                    $xl::s{mpass_frame}, 'not-packed')
724            );
725 }
726
727 %pr::gui = ( # gui bells and whistles
728     b_unread => [
729         'bold_unread',
730         $xl::s{l_gui_b_unread},
731         $xl::s{h_gui_b_unread},
732         'bool',
733         '0.5.3',
734         '1',
735     ],
736     no_markup => [
737         'compose_no_markup',
738         $xl::s{l_gui_no_markup},
739         $xl::s{h_gui_no_markup},
740         'bool',
741         '2.1.0.16',
742         '0',
743     ],
744     dot_lines => [
745         'enable_dotted_lines',
746         $xl::s{l_gui_dot_lines},
747         $xl::s{h_gui_dot_lines},
748         'bool',
749         '2.4.0.115,3.7.10.44',
750         '0',
751     ],
752     h_scroll => [
753         'enable_hscrollbar',
754         $xl::s{l_gui_h_scroll},
755         $xl::s{h_gui_h_scroll},
756         'bool',
757         '0.8.6.18',
758         '1',
759     ],
760     swp_from => [
761         'enable_swap_from',
762         $xl::s{l_gui_swp_from},
763         $xl::s{h_gui_swp_from},
764         'bool',
765         '1.9.13.40',
766         '0',
767     ],
768     v_scroll => [
769         'folderview_vscrollbar_policy',
770         $xl::s{l_gui_v_scroll},
771         $xl::s{h_gui_v_scroll},
772         '0=l_gui_v_scroll_show;1=l_gui_v_scroll_auto;2=l_gui_v_scroll_hide',
773         '0.7.8.14',
774         '0',
775     ],
776     from_show => [
777         'summary_from_show',
778         $xl::s{l_gui_from_show},
779         $xl::s{h_gui_from_show},
780         '0=l_gui_from_show_name;1=l_gui_from_show_addr;2=l_gui_from_show_both',
781         '3.7.10',
782         '0',
783     ],
784     strip_off => [
785         'stripes_color_offset',
786         $xl::s{l_gui_strip_off},
787         $xl::s{h_gui_strip_off},
788         'int,0,40000', # no idea what this number means
789         '2.4.0.186',
790         '4000',
791     ],
792     cursor_v => [
793         'textview_cursor_visible',
794         $xl::s{l_gui_cursor_v},
795         $xl::s{h_gui_cursor_v},
796         'bool',
797         '0.0.0',
798         '0',
799     ],
800     toolbar_d => [
801         'toolbar_detachable',
802         $xl::s{l_gui_toolbar_d},
803         $xl::s{h_gui_toolbar_d},
804         'bool',
805         '0.0.0',
806         '0',
807     ],
808     strip_all => [
809         'use_stripes_everywhere',
810         $xl::s{l_gui_strip_all},
811         $xl::s{h_gui_strip_all},
812         'bool',
813         '0.0.0',
814         '1',
815     ],
816     strip_sum => [
817         'use_stripes_in_summaries',
818         $xl::s{l_gui_strip_sum},
819         $xl::s{h_gui_strip_sum},
820         'bool',
821         '0.0.0',
822         '1',
823     ],
824     two_linev => [
825         'two_line_vertical',
826         $xl::s{l_gui_two_line_v},
827         $xl::s{h_gui_two_line_v},
828         'bool',
829         '3.4.0.7',
830         '0',
831     ],
832     margin_co => [
833         'show_compose_margin',
834         $xl::s{l_gui_margin_co},
835         $xl::s{h_gui_margin_co},
836         'bool',
837         '3.7.6.7',
838         '0',
839     ],
840     mview_date => [
841         'msgview_date_format',
842         $xl::s{l_gui_mview_date},
843         $xl::s{h_gui_mview_date},
844         'bool',
845         '3.7.8.42',
846         '0',
847     ],
848     zero_char => [
849         'zero_replacement_char',
850         $xl::s{l_gui_zero_char},
851         $xl::s{h_gui_zero_char},
852         'char,1,1',
853         '2.8.1.77',
854         '0',
855     ],
856     type_any => [
857         'type_any_header',
858         $xl::s{l_gui_type_any},
859         $xl::s{h_gui_type_any},
860         'bool',
861         '3.12.0.44',
862         '0',
863     ],
864     warn_send_multi => [
865         'warn_sending_many_recipients_num',
866         [$xl::s{l_gui_warn_send_multi},
867          $xl::s{l_gui_warn_send_multi_units}],
868         $xl::s{h_gui_warn_send_multi},
869         'int,0,1000',
870         '3.14.1.125',
871         '0',
872     ],
873     next_del => [
874         'next_on_delete',
875         $xl::s{l_gui_next_del},
876         $xl::s{h_gui_next_del},
877         'bool',
878         '3.13.0.5',
879         '0',
880     ],
881 );
882
883 sub new_gui_page() {
884     my $gf = Gtk2::VBox->new (FALSE, 5);
885     $gf->set_border_width (PAGE_SPC);
886
887     my $cb_dot_lines = new_check_button_for (\%pr::gui, 'dot_lines', \%HPVALUE);
888     my $cb_toolbar_d = new_check_button_for (\%pr::gui, 'toolbar_d', \%HPVALUE);
889     my $tb_zero_char = new_text_box_for_nchar (\%pr::gui, 'zero_char', \%HPVALUE);
890
891     $gf->pack_start (new_subpage_frame (
892                          new_vbox_pack (
893                              new_check_button_for (\%pr::gui, 'strip_all', \%HPVALUE),
894                              new_check_button_for (\%pr::gui, 'strip_sum', \%HPVALUE),
895                              new_text_box_for_int (\%pr::gui, 'strip_off', \%HPVALUE)),
896                          $xl::s{stripes_frame}, 'not-packed'),
897                      FALSE, FALSE, FRAME_SPC);
898     $gf->pack_start (new_subpage_frame (
899                          new_vbox_pack (
900                              new_check_button_for (\%pr::gui, 'b_unread', \%HPVALUE),
901                              new_check_button_for (\%pr::gui, 'swp_from', \%HPVALUE),
902                              new_check_button_for (\%pr::gui, 'two_linev', \%HPVALUE),
903                              new_check_button_for (\%pr::gui, 'next_del', \%HPVALUE),
904                              new_selection_box_for (\%pr::gui, 'from_show', \%HPVALUE)),
905                          $xl::s{mlist_frame}, 'not-packed'),
906                      FALSE, FALSE, FRAME_SPC);
907     $gf->pack_start (new_subpage_frame (
908                          new_hbox_pack (
909                              new_check_button_for (\%pr::gui, 'cursor_v', \%HPVALUE),
910                              new_check_button_for (\%pr::gui, 'mview_date', \%HPVALUE)),
911                          $xl::s{mview_frame}, 'not-packed'),
912                      FALSE, FALSE, FRAME_SPC);
913     $gf->pack_start (new_subpage_frame (
914                          new_vbox_pack (
915                              new_hbox_pack_compact (
916                                  new_check_button_for (\%pr::gui, 'no_markup', \%HPVALUE),
917                                  new_check_button_for (\%pr::gui, 'margin_co', \%HPVALUE),
918                                  new_check_button_for (\%pr::gui, 'type_any', \%HPVALUE)),
919                              new_text_box_for_int (\%pr::gui, 'warn_send_multi', \%HPVALUE)),
920                          $xl::s{compo_frame}, 'not-packed'),
921                      FALSE, FALSE, FRAME_SPC);
922     $gf->pack_start ($cb_dot_lines, FALSE, FALSE, 0);
923     $gf->pack_start ($cb_toolbar_d, FALSE, FALSE, 0);
924     $gf->pack_start (new_subpage_frame (
925                          new_vbox_pack (
926                              new_check_button_for (\%pr::gui, 'h_scroll', \%HPVALUE),
927                              new_selection_box_for (\%pr::gui, 'v_scroll', \%HPVALUE)),
928                          $xl::s{sbar_frame}, 'not-packed'),
929                      FALSE, FALSE, FRAME_SPC);
930     $gf->pack_start ($tb_zero_char, FALSE, FALSE, 0);
931
932     return $gf;
933 }
934
935 %pr::beh = ( # tweak some behaviour
936     hover_t => [
937         'hover_timeout',
938         $xl::s{l_beh_hover_t},
939         $xl::s{h_beh_hover_t},
940         'int,100,3000', # 0.1 seconds - 3 seconds
941         '0.0.0',
942         '500',
943     ],
944     dangerous => [
945         'live_dangerously',
946         $xl::s{l_beh_dangerous},
947         $xl::s{h_beh_dangerous},
948         'bool',
949         '0.0.0',
950         '0',
951     ],
952     flowed => [
953         'respect_flowed_format',
954         $xl::s{l_beh_flowed},
955         $xl::s{h_beh_flowed},
956         'bool',
957         '0.0.0',
958         '0',
959     ],
960     parts_rw => [
961         'save_parts_readwrite',
962         $xl::s{l_beh_parts_rw},
963         $xl::s{h_beh_parts_rw},
964         'bool',
965         '0.0.0',
966         '0',
967     ],
968     skip_ssl => [
969         'skip_ssl_cert_check',
970         $xl::s{l_beh_skip_ssl},
971         $xl::s{h_beh_skip_ssl},
972         'bool',
973         '0.0.0',
974         '0',
975     ],
976     up_step => [
977         'statusbar_update_step',
978         $xl::s{l_beh_up_step},
979         $xl::s{h_beh_up_step},
980         'int,1,200', # 1 item - 200 items
981         '0.0.0',
982         '10',
983     ],
984     thread_a => [
985         'thread_by_subject_max_age',
986         $xl::s{l_beh_thread_a},
987         $xl::s{h_beh_thread_a},
988         'int,1,30', # 1 day - 30 days
989         '0.0.0',
990         '10',
991     ],
992     unsafe_ssl => [
993         'unsafe_ssl_certs',
994         $xl::s{l_beh_unsafe_ssl},
995         $xl::s{h_beh_unsafe_ssl},
996         'bool',
997         '0.0.0',
998         '0',
999     ],
1000     use_utf8 => [
1001         'utf8_instead_of_locale_for_broken_mail',
1002         $xl::s{l_beh_use_utf8},
1003         $xl::s{h_beh_use_utf8},
1004         'bool',
1005         '1.9.14.49',
1006         '0',
1007     ],
1008     warn_dnd => [
1009         'warn_dnd',
1010         $xl::s{l_beh_warn_dnd},
1011         $xl::s{h_beh_warn_dnd},
1012         'bool',
1013         '0.0.0',
1014         '1',
1015     ],
1016     out_ascii => [
1017         'outgoing_fallback_to_ascii',
1018         $xl::s{l_beh_out_ascii},
1019         $xl::s{h_beh_out_ascii},
1020         'bool',
1021         '3.4.0.37',
1022         '1',
1023     ],
1024     pp_unsel => [
1025         'primary_paste_unselects',
1026         $xl::s{l_beh_pp_unsel},
1027         $xl::s{h_beh_pp_unsel},
1028         'bool',
1029         '3.6.1.35',
1030         '0',
1031     ],
1032     inline_at => [
1033         'show_inline_attachments',
1034         $xl::s{l_beh_inline_at},
1035         $xl::s{h_beh_inline_at},
1036         'bool',
1037         '3.7.8.48',
1038         '1',
1039     ],
1040     addr_swc => [
1041         'address_search_wildcard',
1042         $xl::s{l_beh_addr_swc},
1043         $xl::s{h_beh_addr_swc},
1044         'bool',
1045         '3.9.3.18',
1046         '0',
1047     ],
1048     fold_swc => [
1049         'folder_search_wildcard',
1050         $xl::s{l_beh_fold_swc},
1051         $xl::s{h_beh_fold_swc},
1052         'bool',
1053         '3.9.3.18',
1054         '0',
1055     ],
1056     rewrite_ff => [
1057         'rewrite_first_from',
1058         $xl::s{l_beh_rewrite_ff},
1059         $xl::s{h_beh_rewrite_ff},
1060         'bool',
1061         '3.14.0.94',
1062         '0',
1063     ],
1064 );
1065
1066 sub new_behaviour_page() {
1067     my $bf = Gtk2::VBox->new (FALSE, 5);
1068     $bf->set_border_width (PAGE_SPC);
1069
1070     my $tb_up_step = new_text_box_for_int (\%pr::beh, 'up_step', \%HPVALUE);
1071     my $tb_thread_a = new_text_box_for_int (\%pr::beh, 'thread_a', \%HPVALUE);
1072
1073     $bf->pack_start (new_subpage_frame (
1074                          new_vbox_pack (
1075                              new_text_box_for_int (\%pr::beh, 'hover_t', \%HPVALUE),
1076                              new_check_button_for (\%pr::beh, 'warn_dnd', \%HPVALUE)),
1077                          $xl::s{dnd_frame}, 'not-packed'),
1078                      FALSE, FALSE, FRAME_SPC);
1079     $bf->pack_start (new_subpage_frame (
1080                          new_hbox_pack (
1081                              new_check_button_for (\%pr::beh, 'skip_ssl', \%HPVALUE),
1082                              new_check_button_for (\%pr::beh, 'unsafe_ssl', \%HPVALUE)),
1083                          $xl::s{ssl_frame}, 'not-packed'),
1084                      FALSE, FALSE, FRAME_SPC);
1085     $bf->pack_start ($tb_up_step, FALSE, FALSE, 0);
1086     $bf->pack_start ($tb_thread_a, FALSE, FALSE, 0);
1087     $bf->pack_start (new_subpage_frame (
1088                          new_vbox_pack (
1089                              new_check_button_for (\%pr::beh, 'flowed', \%HPVALUE),
1090                              new_check_button_for (\%pr::beh, 'parts_rw', \%HPVALUE),
1091                              new_check_button_for (\%pr::beh, 'use_utf8', \%HPVALUE),
1092                              new_check_button_for (\%pr::beh, 'dangerous', \%HPVALUE),
1093                              new_check_button_for (\%pr::beh, 'out_ascii', \%HPVALUE),
1094                              new_check_button_for (\%pr::beh, 'pp_unsel', \%HPVALUE),
1095                              new_check_button_for (\%pr::beh, 'inline_at', \%HPVALUE),
1096                              new_check_button_for (\%pr::beh, 'rewrite_ff', \%HPVALUE)),
1097                          $xl::s{msgs_frame}, 'not-packed'),
1098                      FALSE, FALSE, FRAME_SPC);
1099     $bf->pack_start (new_subpage_frame (
1100                          new_vbox_pack (
1101                              new_check_button_for (\%pr::beh, 'addr_swc', \%HPVALUE),
1102                              new_check_button_for (\%pr::beh, 'fold_swc', \%HPVALUE)),
1103                          $xl::s{swc_frame}, 'not-packed'),
1104                      FALSE, FALSE, FRAME_SPC);
1105     return $bf;
1106 }
1107
1108 %pr::col = ( # a variety of colours
1109     emphasis => [
1110         'emphasis_color',
1111         $xl::s{l_col_emphasis},
1112         $xl::s{h_col_emphasis},
1113         'color',
1114         '0.0.0',
1115         '#0000cf',
1116     ],
1117     log_err => [
1118         'log_error_color',
1119         $xl::s{l_col_log_err},
1120         $xl::s{h_col_log_err},
1121         'color',
1122         '0.0.0',
1123         '#af0000',
1124     ],
1125     log_in => [
1126         'log_in_color',
1127         $xl::s{l_col_log_in},
1128         $xl::s{h_col_log_in},
1129         'color',
1130         '0.0.0',
1131         '#000000',
1132     ],
1133     log_msg => [
1134         'log_msg_color',
1135         $xl::s{l_col_log_msg},
1136         $xl::s{h_col_log_msg},
1137         'color',
1138         '0.0.0',
1139         '#00af00',
1140     ],
1141     log_out => [
1142         'log_out_color',
1143         $xl::s{l_col_log_out},
1144         $xl::s{h_col_log_out},
1145         'color',
1146         '0.0.0',
1147         '#0000ef',
1148     ],
1149     log_warn => [
1150         'log_warn_color',
1151         $xl::s{l_col_log_warn},
1152         $xl::s{h_col_log_warn},
1153         'color',
1154         '0.0.0',
1155         '#af0000',
1156     ],
1157     diff_add => [
1158         'diff_added_color',
1159         $xl::s{l_col_diff_add},
1160         $xl::s{h_col_diff_add},
1161         'color',
1162         '3.8.0.54',
1163         '#008b8b',
1164     ],
1165     diff_del => [
1166         'diff_deleted_color',
1167         $xl::s{l_col_diff_del},
1168         $xl::s{h_col_diff_del},
1169         'color',
1170         '3.8.0.54',
1171         '#6a5acd',
1172     ],
1173     diff_hunk => [
1174         'diff_hunk_color',
1175         $xl::s{l_col_diff_hunk},
1176         $xl::s{h_col_diff_hunk},
1177         'color',
1178         '3.8.0.54',
1179         '#a52a2a',
1180     ],
1181     tags_bg => [
1182         'tags_bgcolor',
1183         $xl::s{l_col_tags_bg},
1184         $xl::s{h_col_tags_bg},
1185         'color',
1186         '3.14.1.31',
1187         '#f5f6be',
1188     ],
1189     tags_text => [
1190         'tags_color',
1191         $xl::s{l_col_tags_text},
1192         $xl::s{h_col_tags_text},
1193         'color',
1194         '3.14.1.31',
1195         '#000000',
1196     ],
1197     default_header_bg => [
1198         'default_header_bgcolor',
1199         $xl::s{l_col_default_header_bg},
1200         $xl::s{h_col_default_header_bg},
1201         'color',
1202         '3.14.1.31',
1203         '#f5f6be',
1204     ],
1205     default_header_text => [
1206         'default_header_color',
1207         $xl::s{l_col_default_header_text},
1208         $xl::s{h_col_default_header_text},
1209         'color',
1210         '3.14.1.31',
1211         '#000000',
1212     ],
1213     qs_active_bg => [
1214         'qs_active_bgcolor',
1215         $xl::s{l_col_qs_active_bg},
1216         $xl::s{h_col_qs_active_bg},
1217         'color',
1218         '3.14.1.31',
1219         '#f5f6be',
1220     ],
1221     qs_active_text => [
1222         'qs_active_color',
1223         $xl::s{l_col_qs_active_text},
1224         $xl::s{h_col_qs_active_text},
1225         'color',
1226         '3.14.1.31',
1227         '#000000',
1228     ],
1229     qs_error_bg => [
1230         '',
1231         $xl::s{l_col_qs_error_bg},
1232         $xl::s{h_col_qs_error_bg},
1233         'qs_error_bgcolor',
1234         '3.14.1.31',
1235         '#ff7070',
1236     ],
1237     qs_error_text => [
1238         '',
1239         $xl::s{l_col_qs_error_text},
1240         $xl::s{h_col_qs_error_text},
1241         'qs_error_color',
1242         '3.14.1.31',
1243         '#000000',
1244     ],
1245 );
1246
1247 sub new_colours_page() {
1248     return new_vbox_pack (
1249                new_subpage_frame (
1250                    new_vbox_pack (
1251                        new_color_button_for (\%pr::col, 'emphasis', \%HPVALUE),
1252                        new_hbox_pack_compact (
1253                            new_color_button_for (\%pr::col, 'tags_text', \%HPVALUE),
1254                            new_color_button_for (\%pr::col, 'tags_bg', \%HPVALUE))),
1255                    $xl::s{msgview_frame}, 'not-packed'),
1256                new_subpage_frame (
1257                    new_hbox_pack (
1258                        new_vbox_pack_compact (
1259                            new_color_button_for (\%pr::col, 'log_err', \%HPVALUE),
1260                            new_color_button_for (\%pr::col, 'log_warn', \%HPVALUE),
1261                            new_color_button_for (\%pr::col, 'log_msg', \%HPVALUE)),
1262                        new_vbox_pack_compact (
1263                            new_color_button_for (\%pr::col, 'log_in', \%HPVALUE),
1264                            new_color_button_for (\%pr::col, 'log_out', \%HPVALUE))),
1265                    $xl::s{log_frame}, 'not-packed'),
1266                new_subpage_frame (
1267                    new_vbox_pack (
1268                        new_color_button_for (\%pr::col, 'diff_add', \%HPVALUE),
1269                        new_color_button_for (\%pr::col, 'diff_del', \%HPVALUE),
1270                        new_color_button_for (\%pr::col, 'diff_hunk', \%HPVALUE)),
1271                    $xl::s{diff_frame}, 'not-packed'),
1272                new_subpage_frame (
1273                    new_hbox_pack (
1274                        new_color_button_for (\%pr::col, 'default_header_text', \%HPVALUE),
1275                        new_color_button_for (\%pr::col, 'default_header_bg', \%HPVALUE)),
1276                    $xl::s{compose_frame}, 'not-packed'),
1277                new_subpage_frame (
1278                    new_hbox_pack (
1279                        new_vbox_pack_compact (
1280                            new_color_button_for (\%pr::col, 'qs_active_text', \%HPVALUE),
1281                            new_color_button_for (\%pr::col, 'qs_error_text', \%HPVALUE)),
1282                        new_vbox_pack_compact (
1283                            new_color_button_for (\%pr::col, 'qs_active_bg', \%HPVALUE),
1284                            new_color_button_for (\%pr::col, 'qs_error_bg', \%HPVALUE))),
1285                    $xl::s{qs_frame}, 'not-packed')
1286            );
1287 }
1288
1289 %pr::win = ( # tweak window positions and/or sizes
1290     main_x => [
1291         'mainwin_x',
1292         $xl::s{l_win_x},
1293         $xl::s{h_win_x},
1294         'int,0,3000', # 0 pixels - 3000 pixels
1295         '0.0.0',
1296         '16',
1297     ],
1298     main_y => [
1299         'mainwin_y',
1300         $xl::s{l_win_y},
1301         $xl::s{h_win_y},
1302         'int,0,3000', # 0 pixels - 3000 pixels
1303         '0.0.0',
1304         '16',
1305     ],
1306     main_w => [
1307         'mainwin_width',
1308         $xl::s{l_win_w},
1309         $xl::s{h_win_w},
1310         'int,0,3000', # 0 pixels - 3000 pixels
1311         '0.0.0',
1312         '779',
1313     ],
1314     main_h => [
1315         'mainwin_height',
1316         $xl::s{l_win_h},
1317         $xl::s{h_win_h},
1318         'int,0,3000', # 0 pixels - 3000 pixels
1319         '0.0.0',
1320         '568',
1321     ],
1322     main_mx => [
1323         'mainwin_maximised',
1324         $xl::s{l_win_main_mx},
1325         $xl::s{h_win_main_mx},
1326         'bool',
1327         '0.0.0',
1328         '0',
1329     ],
1330     main_fs => [
1331         'mainwin_fullscreen',
1332         $xl::s{l_win_main_fs},
1333         $xl::s{h_win_main_fs},
1334         'bool',
1335         '0.0.0',
1336         '0',
1337     ],
1338     msgs_x => [
1339         'main_messagewin_x',
1340         $xl::s{l_win_x},
1341         $xl::s{h_win_x},
1342         'int,0,3000', # 0 pixels - 3000 pixels
1343         '0.0.0',
1344         '256',
1345     ],
1346     msgs_y => [
1347         'main_messagewin_y',
1348         $xl::s{l_win_y},
1349         $xl::s{h_win_y},
1350         'int,0,3000', # 0 pixels - 3000 pixels
1351         '0.0.0',
1352         '210',
1353     ],
1354     msgs_w => [
1355         'messagewin_width',
1356         $xl::s{l_win_w},
1357         $xl::s{h_win_w},
1358         'int,0,3000', # 0 pixels - 3000 pixels
1359         '0.0.0',
1360         '600',
1361     ],
1362     msgs_h => [
1363         'messagewin_height',
1364         $xl::s{l_win_h},
1365         $xl::s{h_win_h},
1366         'int,0,3000', # 0 pixels - 3000 pixels
1367         '0.0.0',
1368         '540',
1369     ],
1370     send_w => [
1371         'sendwin_width',
1372         $xl::s{l_win_w},
1373         $xl::s{h_win_w},
1374         'int,0,3000', # 0 pixels - 3000 pixels
1375         '0.0.0',
1376         '460',
1377     ],
1378     send_h => [
1379         'sendwin_height',
1380         $xl::s{l_win_h},
1381         $xl::s{h_win_h},
1382         'int,0,3000', # 0 pixels - 3000 pixels
1383         '0.0.0',
1384         '-1',
1385     ],
1386     recv_w => [
1387         'receivewin_width',
1388         $xl::s{l_win_w},
1389         $xl::s{h_win_w},
1390         'int,0,3000', # 0 pixels - 3000 pixels
1391         '0.0.0',
1392         '460',
1393     ],
1394     recv_h => [
1395         'receivewin_height',
1396         $xl::s{l_win_h},
1397         $xl::s{h_win_h},
1398         'int,0,3000', # 0 pixels - 3000 pixels
1399         '0.0.0',
1400         '-1',
1401     ],
1402     fold_x => [
1403         'folderwin_x',
1404         $xl::s{l_win_x},
1405         $xl::s{h_win_x},
1406         'int,0,3000', # 0 pixels - 3000 pixels
1407         '0.0.0',
1408         '16',
1409     ],
1410     fold_y => [
1411         'folderwin_y',
1412         $xl::s{l_win_y},
1413         $xl::s{h_win_y},
1414         'int,0,3000', # 0 pixels - 3000 pixels
1415         '0.0.0',
1416         '16',
1417     ],
1418     fold_w => [
1419         'folderitemwin_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     ],
1426     fold_h => [
1427         'folderitemwin_height',
1428         $xl::s{l_win_h},
1429         $xl::s{h_win_h},
1430         'int,0,3000', # 0 pixels - 3000 pixels
1431         '0.0.0',
1432         '-1',
1433     ],
1434     fsel_w => [
1435         'folderselwin_width',
1436         $xl::s{l_win_w},
1437         $xl::s{h_win_w},
1438         'int,0,3000', # 0 pixels - 3000 pixels
1439         '0.0.0',
1440         '300',
1441     ],
1442     fsel_h => [
1443         'folderselwin_height',
1444         $xl::s{l_win_h},
1445         $xl::s{h_win_h},
1446         'int,0,3000', # 0 pixels - 3000 pixels
1447         '0.0.0',
1448         '-1',
1449     ],
1450     sour_w => [
1451         'sourcewin_width',
1452         $xl::s{l_win_w},
1453         $xl::s{h_win_w},
1454         'int,0,3000', # 0 pixels - 3000 pixels
1455         '0.0.0',
1456         '600',
1457     ],
1458     sour_h => [
1459         'sourcewin_height',
1460         $xl::s{l_win_h},
1461         $xl::s{h_win_h},
1462         'int,0,3000', # 0 pixels - 3000 pixels
1463         '0.0.0',
1464         '500',
1465     ],
1466     addr_w => [
1467         'addressbookwin_width',
1468         $xl::s{l_win_w},
1469         $xl::s{h_win_w},
1470         'int,0,3000', # 0 pixels - 3000 pixels
1471         '0.0.0',
1472         '520',
1473     ],
1474     addr_h => [
1475         'addressbookwin_height',
1476         $xl::s{l_win_h},
1477         $xl::s{h_win_h},
1478         'int,0,3000', # 0 pixels - 3000 pixels
1479         '0.0.0',
1480         '-1',
1481     ],
1482     adep_w => [
1483         'addressbookeditpersonwin_width',
1484         $xl::s{l_win_w},
1485         $xl::s{h_win_w},
1486         'int,0,3000', # 0 pixels - 3000 pixels
1487         '0.0.0',
1488         '640',
1489     ],
1490     adep_h => [
1491         'addressbookeditpersonwin_height',
1492         $xl::s{l_win_h},
1493         $xl::s{h_win_h},
1494         'int,0,3000', # 0 pixels - 3000 pixels
1495         '0.0.0',
1496         '320',
1497     ],
1498     adeg_w => [
1499         'addressbookeditgroupwin_width',
1500         $xl::s{l_win_w},
1501         $xl::s{h_win_w},
1502         'int,0,3000', # 0 pixels - 3000 pixels
1503         '0.0.0',
1504         '580',
1505     ],
1506     adeg_h => [
1507         'addressbookeditgroupwin_height',
1508         $xl::s{l_win_h},
1509         $xl::s{h_win_h},
1510         'int,0,3000', # 0 pixels - 3000 pixels
1511         '0.0.0',
1512         '340',
1513     ],
1514     adda_w => [
1515         'addressaddwin_width',
1516         $xl::s{l_win_w},
1517         $xl::s{h_win_w},
1518         'int,0,3000', # 0 pixels - 3000 pixels
1519         '0.0.0',
1520         '300',
1521     ],
1522     adda_h => [
1523         'addressaddwin_height',
1524         $xl::s{l_win_h},
1525         $xl::s{h_win_h},
1526         'int,0,3000', # 0 pixels - 3000 pixels
1527         '0.0.0',
1528         '-1',
1529     ],
1530     addf_w => [
1531         'addressbook_folderselwin_width',
1532         $xl::s{l_win_w},
1533         $xl::s{h_win_w},
1534         'int,0,3000', # 0 pixels - 3000 pixels
1535         '0.0.0',
1536         '300',
1537     ],
1538     addf_h => [
1539         'addressbook_folderselwin_height',
1540         $xl::s{l_win_h},
1541         $xl::s{h_win_h},
1542         'int,0,3000', # 0 pixels - 3000 pixels
1543         '0.0.0',
1544         '-1',
1545     ],
1546     acce_w => [
1547         'editaccountwin_width',
1548         $xl::s{l_win_w},
1549         $xl::s{h_win_w},
1550         'int,0,3000', # 0 pixels - 3000 pixels
1551         '0.0.0',
1552         '500',
1553     ],
1554     acce_h => [
1555         'editaccountwin_height',
1556         $xl::s{l_win_h},
1557         $xl::s{h_win_h},
1558         'int,0,3000', # 0 pixels - 3000 pixels
1559         '0.0.0',
1560         '-1',
1561     ],
1562     acco_w => [
1563         'accountswin_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         '500',
1569     ],
1570     acco_h => [
1571         'accountswin_height',
1572         $xl::s{l_win_h},
1573         $xl::s{h_win_h},
1574         'int,0,3000', # 0 pixels - 3000 pixels
1575         '0.0.0',
1576         '-1',
1577     ],
1578     filt_w => [
1579         'filteringwin_width',
1580         $xl::s{l_win_w},
1581         $xl::s{h_win_w},
1582         'int,0,3000', # 0 pixels - 3000 pixels
1583         '0.0.0',
1584         '500',
1585     ],
1586     filt_h => [
1587         'filteringwin_height',
1588         $xl::s{l_win_h},
1589         $xl::s{h_win_h},
1590         'int,0,3000', # 0 pixels - 3000 pixels
1591         '0.0.0',
1592         '-1',
1593     ],
1594     fila_w => [
1595         'filteringactionwin_width',
1596         $xl::s{l_win_w},
1597         $xl::s{h_win_w},
1598         'int,0,3000', # 0 pixels - 3000 pixels
1599         '0.0.0',
1600         '490',
1601     ],
1602     fila_h => [
1603         'filteringactionwin_height',
1604         $xl::s{l_win_h},
1605         $xl::s{h_win_h},
1606         'int,0,3000', # 0 pixels - 3000 pixels
1607         '0.0.0',
1608         '-1',
1609     ],
1610     fild_w => [
1611         'filtering_debugwin_width',
1612         $xl::s{l_win_w},
1613         $xl::s{h_win_w},
1614         'int,0,3000', # 0 pixels - 3000 pixels
1615         '0.0.0',
1616         '600',
1617     ],
1618     fild_h => [
1619         'filtering_debugwin_height',
1620         $xl::s{l_win_h},
1621         $xl::s{h_win_h},
1622         'int,0,3000', # 0 pixels - 3000 pixels
1623         '0.0.0',
1624         '-1',
1625     ],
1626     matc_w => [
1627         'matcherwin_width',
1628         $xl::s{l_win_w},
1629         $xl::s{h_win_w},
1630         'int,0,3000', # 0 pixels - 3000 pixels
1631         '0.0.0',
1632         '520',
1633     ],
1634     matc_h => [
1635         'matcherwin_height',
1636         $xl::s{l_win_h},
1637         $xl::s{h_win_h},
1638         'int,0,3000', # 0 pixels - 3000 pixels
1639         '0.0.0',
1640         '-1',
1641     ],
1642     pref_w => [
1643         'prefswin_width',
1644         $xl::s{l_win_w},
1645         $xl::s{h_win_w},
1646         'int,0,3000', # 0 pixels - 3000 pixels
1647         '0.0.0',
1648         '600',
1649     ],
1650     pref_h => [
1651         'prefswin_height',
1652         $xl::s{l_win_h},
1653         $xl::s{h_win_h},
1654         'int,0,3000', # 0 pixels - 3000 pixels
1655         '0.0.0',
1656         '-1',
1657     ],
1658     temp_w => [
1659         'templateswin_width',
1660         $xl::s{l_win_w},
1661         $xl::s{h_win_w},
1662         'int,0,3000', # 0 pixels - 3000 pixels
1663         '0.0.0',
1664         '480',
1665     ],
1666     temp_h => [
1667         'templateswin_height',
1668         $xl::s{l_win_h},
1669         $xl::s{h_win_h},
1670         'int,0,3000', # 0 pixels - 3000 pixels
1671         '0.0.0',
1672         '-1',
1673     ],
1674     acti_w => [
1675         'actionswin_width',
1676         $xl::s{l_win_w},
1677         $xl::s{h_win_w},
1678         'int,0,3000', # 0 pixels - 3000 pixels
1679         '0.0.0',
1680         '486',
1681     ],
1682     acti_h => [
1683         'actionswin_height',
1684         $xl::s{l_win_h},
1685         $xl::s{h_win_h},
1686         'int,0,3000', # 0 pixels - 3000 pixels
1687         '0.0.0',
1688         '-1',
1689     ],
1690     tags_w => [
1691         'tagswin_width',
1692         $xl::s{l_win_w},
1693         $xl::s{h_win_w},
1694         'int,0,3000', # 0 pixels - 3000 pixels
1695         '0.0.0',
1696         '486',
1697     ],
1698     tags_h => [
1699         'tagswin_height',
1700         $xl::s{l_win_h},
1701         $xl::s{h_win_h},
1702         'int,0,3000', # 0 pixels - 3000 pixels
1703         '0.0.0',
1704         '-1',
1705     ],
1706     plug_w => [
1707         'pluginswin_width',
1708         $xl::s{l_win_w},
1709         $xl::s{h_win_w},
1710         'int,0,3000', # 0 pixels - 3000 pixels
1711         '0.0.0',
1712         '-1',
1713     ],
1714     plug_h => [
1715         'pluginswin_height',
1716         $xl::s{l_win_h},
1717         $xl::s{h_win_h},
1718         'int,0,3000', # 0 pixels - 3000 pixels
1719         '0.0.0',
1720         '-1',
1721     ],
1722     logw_w => [
1723         'logwin_width',
1724         $xl::s{l_win_w},
1725         $xl::s{h_win_w},
1726         'int,0,3000', # 0 pixels - 3000 pixels
1727         '0.0.0',
1728         '520',
1729     ],
1730     logw_h => [
1731         'logwin_height',
1732         $xl::s{l_win_h},
1733         $xl::s{h_win_h},
1734         'int,0,3000', # 0 pixels - 3000 pixels
1735         '0.0.0',
1736         '-1',
1737     ],
1738     prin_w => [
1739         'print_previewwin_width',
1740         $xl::s{l_win_w},
1741         $xl::s{h_win_w},
1742         'int,0,3000', # 0 pixels - 3000 pixels
1743         '0.0.0',
1744         '600',
1745     ],
1746     prin_h => [
1747         'print_previewwin_height',
1748         $xl::s{l_win_h},
1749         $xl::s{h_win_h},
1750         'int,0,3000', # 0 pixels - 3000 pixels
1751         '0.0.0',
1752         '-1',
1753     ],
1754 );
1755
1756 sub new_winpos_subpage_main() {
1757     return new_subpage_frame (
1758                new_vbox_pack_compact (
1759                    new_vbox_pack (
1760                        new_text_box_for_int (\%pr::win, 'main_x', \%HPVALUE),
1761                        new_text_box_for_int (\%pr::win, 'main_y', \%HPVALUE)),
1762                    new_hbox_pack (
1763                        new_text_box_for_int (\%pr::win, 'main_w', \%HPVALUE),
1764                        new_text_box_for_int (\%pr::win, 'main_h', \%HPVALUE)),
1765                    new_vbox_pack (
1766                        new_check_button_for (\%pr::win, 'main_fs', \%HPVALUE),
1767                        new_check_button_for (\%pr::win, 'main_mx', \%HPVALUE))),
1768                _('Main window')
1769            );
1770 }
1771
1772 sub new_winpos_subpage_msgs() {
1773     return new_subpage_frame (
1774                new_vbox_pack_compact (
1775                    new_vbox_pack (
1776                        new_text_box_for_int (\%pr::win, 'msgs_x', \%HPVALUE),
1777                        new_text_box_for_int (\%pr::win, 'msgs_y', \%HPVALUE)),
1778                    new_hbox_pack (
1779                        new_text_box_for_int (\%pr::win, 'msgs_w', \%HPVALUE),
1780                        new_text_box_for_int (\%pr::win, 'msgs_h', \%HPVALUE))),
1781                _('Message window')
1782            );
1783 }
1784
1785 sub new_winpos_subpage_sendrecv() {
1786     return new_vbox_pack (
1787                new_subpage_frame (
1788                    new_hbox_pack (
1789                        new_text_box_for_int (\%pr::win, 'send_w', \%HPVALUE),
1790                        new_text_box_for_int (\%pr::win, 'send_h', \%HPVALUE)),
1791                    _('Send window'), 'not-packed'),
1792                new_subpage_frame (
1793                    new_hbox_pack (
1794                        new_text_box_for_int (\%pr::win, 'recv_w', \%HPVALUE),
1795                        new_text_box_for_int (\%pr::win, 'recv_h', \%HPVALUE)),
1796                    _('Receive window'), 'not-packed')
1797            );
1798 }
1799
1800 sub new_winpos_subpage_fold() {
1801     return new_vbox_pack (
1802                new_subpage_frame (
1803                    new_vbox_pack_compact (
1804                        new_vbox_pack (
1805                             new_text_box_for_int (\%pr::win, 'fold_x', \%HPVALUE),
1806                             new_text_box_for_int (\%pr::win, 'fold_y', \%HPVALUE)),
1807                        new_hbox_pack (
1808                            new_text_box_for_int (\%pr::win, 'fold_w', \%HPVALUE),
1809                            new_text_box_for_int (\%pr::win, 'fold_h', \%HPVALUE))),
1810                    _('Folder window'), 'not-packed'),
1811                new_subpage_frame (
1812                    new_hbox_pack (
1813                        new_text_box_for_int (\%pr::win, 'fsel_w', \%HPVALUE),
1814                        new_text_box_for_int (\%pr::win, 'fsel_h', \%HPVALUE)),
1815                    _('Folder selection window'), 'not-packed')
1816            );
1817 }
1818
1819 sub new_winpos_subpage_addrbook() {
1820     return new_vbox_pack (
1821                 new_subpage_frame (
1822                      new_hbox_pack (
1823                           new_text_box_for_int (\%pr::win, 'addr_w', \%HPVALUE),
1824                           new_text_box_for_int (\%pr::win, 'addr_h', \%HPVALUE)),
1825                      _('Addressbook main window'), 'not-packed'),
1826                 new_subpage_frame (
1827                      new_hbox_pack (
1828                           new_text_box_for_int (\%pr::win, 'adep_w', \%HPVALUE),
1829                           new_text_box_for_int (\%pr::win, 'adep_h', \%HPVALUE)),
1830                      _('Edit person window'), 'not-packed'),
1831                 new_subpage_frame (
1832                      new_hbox_pack (
1833                           new_text_box_for_int (\%pr::win, 'adeg_w', \%HPVALUE),
1834                           new_text_box_for_int (\%pr::win, 'adeg_h', \%HPVALUE)),
1835                      _('Edit group window'), 'not-packed'),
1836                 new_subpage_frame (
1837                      new_hbox_pack (
1838                           new_text_box_for_int (\%pr::win, 'adda_w', \%HPVALUE),
1839                           new_text_box_for_int (\%pr::win, 'adda_h', \%HPVALUE)),
1840                      _('Add address window'), 'not-packed'),
1841                 new_subpage_frame (
1842                      new_hbox_pack (
1843                           new_text_box_for_int (\%pr::win, 'addf_w', \%HPVALUE),
1844                           new_text_box_for_int (\%pr::win, 'addf_h', \%HPVALUE)),
1845                      _('Folder select window'), 'not-packed')
1846            );
1847 }
1848
1849 sub new_winpos_subpage_accounts() {
1850     return new_vbox_pack (
1851                 new_subpage_frame (
1852                      new_hbox_pack (
1853                           new_text_box_for_int (\%pr::win, 'acco_w', \%HPVALUE),
1854                           new_text_box_for_int (\%pr::win, 'acco_h', \%HPVALUE)),
1855                      _('Accounts window'), 'not-packed'),
1856                 new_subpage_frame (
1857                      new_hbox_pack (
1858                           new_text_box_for_int (\%pr::win, 'acce_w', \%HPVALUE),
1859                           new_text_box_for_int (\%pr::win, 'acce_h', \%HPVALUE)),
1860                      _('Edit account window'), 'not-packed')
1861            );
1862 }
1863
1864 sub new_winpos_subpage_filtering() {
1865     return new_vbox_pack (
1866                 new_subpage_frame (
1867                      new_hbox_pack (
1868                           new_text_box_for_int (\%pr::win, 'filt_w', \%HPVALUE),
1869                           new_text_box_for_int (\%pr::win, 'filt_h', \%HPVALUE)),
1870                      _('Filtering window'), 'not-packed'),
1871                 new_subpage_frame (
1872                      new_hbox_pack (
1873                           new_text_box_for_int (\%pr::win, 'fila_w', \%HPVALUE),
1874                           new_text_box_for_int (\%pr::win, 'fila_h', \%HPVALUE)),
1875                      _('Filtering actions window'), 'not-packed'),
1876                 new_subpage_frame (
1877                      new_hbox_pack (
1878                           new_text_box_for_int (\%pr::win, 'fild_w', \%HPVALUE),
1879                           new_text_box_for_int (\%pr::win, 'fild_h', \%HPVALUE)),
1880                      _('Filtering debug window'), 'not-packed'),
1881                 new_subpage_frame (
1882                      new_hbox_pack (
1883                           new_text_box_for_int (\%pr::win, 'matc_w', \%HPVALUE),
1884                           new_text_box_for_int (\%pr::win, 'matc_h', \%HPVALUE)),
1885                      _('Matcher window'), 'not-packed')
1886            );
1887 }
1888
1889 sub new_winpos_subpage_prefs() {
1890     return new_vbox_pack (
1891                 new_subpage_frame (
1892                      new_hbox_pack (
1893                           new_text_box_for_int (\%pr::win, 'pref_w', \%HPVALUE),
1894                           new_text_box_for_int (\%pr::win, 'pref_h', \%HPVALUE)),
1895                      _('Preferences window'), 'not-packed'),
1896                 new_subpage_frame (
1897                      new_hbox_pack (
1898                           new_text_box_for_int (\%pr::win, 'temp_w', \%HPVALUE),
1899                           new_text_box_for_int (\%pr::win, 'temp_h', \%HPVALUE)),
1900                      _('Templates window'), 'not-packed'),
1901                 new_subpage_frame (
1902                      new_hbox_pack (
1903                           new_text_box_for_int (\%pr::win, 'acti_w', \%HPVALUE),
1904                           new_text_box_for_int (\%pr::win, 'acti_h', \%HPVALUE)),
1905                      _('Actions window'), 'not-packed'),
1906                 new_subpage_frame (
1907                      new_hbox_pack (
1908                           new_text_box_for_int (\%pr::win, 'tags_w', \%HPVALUE),
1909                           new_text_box_for_int (\%pr::win, 'tags_h', \%HPVALUE)),
1910                      _('Tags window'), 'not-packed'),
1911                 new_subpage_frame (
1912                      new_hbox_pack (
1913                           new_text_box_for_int (\%pr::win, 'plug_w', \%HPVALUE),
1914                           new_text_box_for_int (\%pr::win, 'plug_h', \%HPVALUE)),
1915                      _('Plugins window'), 'not-packed')
1916            );
1917 }
1918
1919 sub new_winpos_subpage_misc() {
1920     return new_vbox_pack (
1921                 new_subpage_frame (
1922                      new_hbox_pack (
1923                           new_text_box_for_int (\%pr::win, 'logw_w', \%HPVALUE),
1924                           new_text_box_for_int (\%pr::win, 'logw_h', \%HPVALUE)),
1925                      _('Log window'), 'not-packed'),
1926                 new_subpage_frame (
1927                      new_hbox_pack (
1928                           new_text_box_for_int (\%pr::win, 'prin_w', \%HPVALUE),
1929                           new_text_box_for_int (\%pr::win, 'prin_h', \%HPVALUE)),
1930                      _('Print preview window'), 'not-packed'),
1931                 new_subpage_frame (
1932                      new_hbox_pack (
1933                           new_text_box_for_int (\%pr::win, 'sour_w', \%HPVALUE),
1934                           new_text_box_for_int (\%pr::win, 'sour_h', \%HPVALUE)),
1935                      _('View source window'), 'not-packed')
1936            );
1937 }
1938
1939 sub new_winpos_page() {
1940     my $winbook = Gtk2::Notebook->new;
1941     $winbook->set_tab_pos ('right');
1942     $winbook->append_page (new_winpos_subpage_main, _('Main'));
1943     $winbook->append_page (new_winpos_subpage_msgs, _('Message'));
1944     $winbook->append_page (new_winpos_subpage_sendrecv, _('Send/Receive'));
1945     $winbook->append_page (new_winpos_subpage_fold, _('Folder'));
1946     $winbook->append_page (new_winpos_subpage_addrbook, _('Addressbook'));
1947     $winbook->append_page (new_winpos_subpage_accounts, _('Accounts'));
1948     $winbook->append_page (new_winpos_subpage_filtering, _('Filtering'));
1949     $winbook->append_page (new_winpos_subpage_prefs, _('Preferences'));
1950     $winbook->append_page (new_winpos_subpage_misc, _('Other'));
1951     return $winbook;
1952 }
1953
1954 %pr::acc = ( # per account hidden preferences
1955     tls_set => [
1956         'gnutls_set_priority',
1957         $xl::s{l_acc_gtls_set},
1958         $xl::s{h_acc_gtls_set},
1959         'bool',
1960         '3.9.0.181',
1961         '0',
1962     ],
1963     tls_pri => [
1964         'gnutls_priority',
1965         $xl::s{l_acc_gtls_pri},
1966         $xl::s{h_acc_gtls_pri},
1967         'char,0,256,32',
1968         '3.9.0.181',
1969         '0',
1970     ],
1971 );
1972
1973 sub new_account_subpage($) {
1974     my ($akey) = @_;
1975     return new_vbox_pack (
1976                 new_subpage_frame (
1977                     new_vbox_pack (
1978                         new_check_button_for (\%pr::acc, 'tls_set', $ACHPVALUE{$akey}),
1979                         new_text_box_for_nchar (\%pr::acc, 'tls_pri', $ACHPVALUE{$akey})),
1980                     _('GnuTLS priority'), 'not-packed')
1981            );
1982 }
1983
1984 sub new_accounts_page() {
1985     my $accbook = Gtk2::Notebook->new;
1986     $accbook->set_tab_pos ('right');
1987     my @akeys = sort {
1988         $ACPREFS{$a}{'account_name'} cmp $ACPREFS{$b}{'account_name'}
1989     } keys %ACPREFS;
1990     foreach (@akeys) {
1991         my $name = $ACPREFS{$_}{'account_name'};
1992         my $isdef = ($ACPREFS{$_}{'is_default'} eq '1');
1993         my $page = new_account_subpage ($_);
1994         $accbook->append_page ($page, $isdef? '<b>' . $name . '</b>': $name);
1995         if ($isdef) {
1996             my $label = $accbook->get_tab_label ($page);
1997             $label->set_use_markup (TRUE);
1998         }
1999     }
2000     $accbook->set_scrollable (TRUE);
2001     return $accbook;
2002 }
2003
2004 %pr::plu = ( # plugins hidden preferences
2005     # att_remover
2006     arm_winw => [
2007         'win_width',
2008         $xl::s{l_win_w},
2009         $xl::s{h_win_w},
2010         'int,0,3000', # 0 pixels - 3000 pixels
2011         '3.9.0.74',
2012         '-1',
2013         'AttRemover',
2014     ],
2015     arm_winh => [
2016         'win_height',
2017         $xl::s{l_win_h},
2018         $xl::s{h_win_h},
2019         'int,0,3000', # 0 pixels - 3000 pixels
2020         '3.9.0.74',
2021         '-1',
2022         'AttRemover',
2023     ],
2024     # GPG
2025     gpg_alimit => [
2026         'autocompletion_limit',
2027         $xl::s{l_plu_gpg_alimit},
2028         $xl::s{h_plu_gpg_alimit},
2029         'int,0,100',
2030         '3.12.0.75',
2031         '0',
2032         'GPG',
2033     ],
2034     # managesieve
2035     msv_winw => [
2036         'manager_win_width',
2037         $xl::s{l_win_w},
2038         $xl::s{h_win_w},
2039         'int,0,3000', # 0 pixels - 3000 pixels
2040         '3.11.1.210',
2041         '-1',
2042         'ManageSieve',
2043     ],
2044     msv_winh => [
2045         'manager_win_height',
2046         $xl::s{l_win_h},
2047         $xl::s{h_win_h},
2048         'int,0,3000', # 0 pixels - 3000 pixels
2049         '3.11.1.210',
2050         '-1',
2051         'ManageSieve',
2052     ],
2053     # libravatar
2054     lav_burl => [
2055         'base_url',
2056         $xl::s{l_plu_lav_burl},
2057         $xl::s{h_plu_lav_burl},
2058         'char,0,1024,32',
2059         '3.9.3.32',
2060         'http://cdn.libravatar.org/avatar',
2061         'Libravatar',
2062     ],
2063     # perl
2064     prl_flvb => [
2065         'filter_log_verbosity',
2066         $xl::s{l_plu_prl_flvb},
2067         $xl::s{h_plu_prl_flvb},
2068         '0=l_plu_prl_none;1=l_plu_prl_manual;2=l_plu_prl_action;3=l_plu_prl_match',
2069         '3.9.0.75',
2070         '2',
2071         'PerlPlugin',
2072     ],
2073 );
2074
2075 sub new_plugins_page() {
2076     my %frame = ();
2077     $frame{'AttRemover'} =
2078                 new_subpage_frame (
2079                      new_hbox_pack (
2080                           new_text_box_for_int (\%pr::plu, 'arm_winw', $PLHPVALUE{'AttRemover'}),
2081                           new_text_box_for_int (\%pr::plu, 'arm_winh', $PLHPVALUE{'AttRemover'})),
2082                      _('Attachment remover'), 'not-packed');
2083     $frame{'GPG'} =
2084                 new_subpage_frame (
2085                      new_hbox_pack (
2086                           new_text_box_for_int (\%pr::plu, 'gpg_alimit', $PLHPVALUE{'GPG'})),
2087                      _('GPG'), 'not-packed');
2088     $frame{'ManageSieve'} =
2089                 new_subpage_frame (
2090                      new_hbox_pack (
2091                           new_text_box_for_int (\%pr::plu, 'msv_winw', $PLHPVALUE{'ManageSieve'}),
2092                           new_text_box_for_int (\%pr::plu, 'msv_winh', $PLHPVALUE{'ManageSieve'})),
2093                      _('Sieve manager'), 'not-packed');
2094     $frame{'Libravatar'} =
2095                 new_subpage_frame (
2096                      new_hbox_pack (
2097                           new_text_box_for_nchar (\%pr::plu, 'lav_burl', $PLHPVALUE{'Libravatar'})),
2098                      _('Libravatar'), 'not-packed');
2099     $frame{'PerlPlugin'} =
2100                 new_subpage_frame (
2101                      new_hbox_pack (
2102                           new_selection_box_for (\%pr::plu, 'prl_flvb', $PLHPVALUE{'PerlPlugin'})),
2103                      _('Perl'), 'not-packed');
2104     foreach (@PLUGINS) {
2105         $frame{$_}->set_sensitive (defined $PLHPVALUE{$_});
2106     }
2107     return new_vbox_pack (
2108                 $frame{'AttRemover'},
2109                 $frame{'GPG'},
2110                 $frame{'ManageSieve'},
2111                 $frame{'Libravatar'},
2112                 $frame{'PerlPlugin'});
2113 }
2114
2115 sub new_info_page() {
2116     my $t0 = Gtk2::Table->new (7, 2, FALSE);
2117     my $v = get_toolkit_versions ();
2118     my %labels = (
2119         'glib' => 'Perl-GLib',
2120         'glib-r' => _('GLib runtime'),
2121         'glib-b' => _('GLib built'),
2122         'gtk2' => 'Perl-GTK2',
2123         'gtk2-r' => _('GTK2 runtime'),
2124         'gtk2-b' => _('GTK2 built'),
2125     );
2126     my $row = 0;
2127     foreach (sort keys %$v) {
2128         if (defined $v->{$_}) {
2129             my $label = Gtk2::Label->new ($labels{$_});
2130             my $value = Gtk2::Label->new ('<b>' . $v->{$_} . '</b>');
2131             $label->set_alignment (0, 0.5);
2132             $value->set_alignment (0, 0.5);
2133             $value->set_use_markup (TRUE);
2134             $t0->attach ($label, 0, 1, $row, $row + 1, 'fill', 'shrink', 8, 6);
2135             $t0->attach ($value, 1, 2, $row, $row + 1, 'fill', 'shrink', 8, 6);
2136             ++$row;
2137         }
2138     }
2139     my $t1 = Gtk2::Table->new (2, 2, FALSE);
2140     my @lbl = map { $_->set_alignment (0, 0.5); $_ } (
2141         Gtk2::Label->new (_('Binary')),
2142         Gtk2::Label->new (_('Configuration'))
2143     );
2144     my $cfgv = $CONFIGDATA->{'Common'}{'config_version'};
2145     $cfgv //= '';
2146     my @val = map { $_->set_alignment (0, 0.5); $_->set_use_markup (TRUE); $_ } (
2147         Gtk2::Label->new ('<b>' . $CLAWSV . '</b>'),
2148         Gtk2::Label->new ('<b>' . $cfgv . '</b>')
2149     );
2150     for (my $i = 0; $i <= $#lbl; ++$i) {
2151         $t1->attach ($lbl[$i], 0, 1, $i, $i + 1, 'fill', 'shrink', 8, 6);
2152         $t1->attach ($val[$i], 1, 2, $i, $i + 1, 'fill', 'shrink', 8, 6);
2153     }
2154     return new_vbox_pack (
2155                 new_subpage_frame ($t0, _('Library versions'), 'not-packed'),
2156                 new_subpage_frame ($t1, _('Claws Mail versions'), 'not-packed'));
2157 }
2158
2159 # version info
2160 sub get_toolkit_versions {
2161     my %versions = ();
2162     $versions{'glib'} = $Glib::VERSION;
2163     # version info stuff appeared in 1.040
2164     if ($Glib::VERSION >= 1.040) {
2165         $versions{'glib-b'} = join('.', Glib->GET_VERSION_INFO);
2166         $versions{'glib-r'} = join('.',
2167             &Glib::major_version, &Glib::minor_version, &Glib::micro_version);
2168     }
2169     $versions{'gtk2'} = $Gtk2::VERSION;
2170     if ($Gtk2::VERSION >= 1.040) {
2171         $versions{'gtk2-b'} = join('.', Gtk2->GET_VERSION_INFO);
2172         $versions{'gtk2-r'} = join('.',
2173             &Gtk2::major_version, &Gtk2::minor_version, &Gtk2::micro_version);
2174     }
2175     return \%versions;
2176 }
2177
2178 sub print_version() {
2179     print $xl::s{about_title} . "\n";
2180     print $xl::s{about_version} . " $VERSION\n";
2181     my $v = get_toolkit_versions ();
2182     if ($v->{'glib-b'}) {
2183         print _("Perl-GLib version {glibv}, built for {glibb}, running with {glibr}.",
2184                 glibv => $v->{'glib'},
2185                 glibb => $v->{'glib-b'},
2186                 glibr => $v->{'glib-r'});
2187     } else {
2188         print _("Perl-GLib version {glibv}.", glibv => $v->{'glib'});
2189     }
2190     print "\n";
2191     if ($v->{'gtk2-b'}) {
2192         print _("Perl-GTK2 version {gtkv}, built for {gtkb}, running with {gtkr}.",
2193                 gtkv => $v->{'gtk2'},
2194                 gtkb => $v->{'gtk2-b'},
2195                 gtkr => $v->{'gtk2-r'});
2196     } else {
2197         print _("Perl-GTK2 version {gtkv}.", gtkv => $v->{'gtk2'});
2198     }
2199     print "\n";
2200     my $clawsver = ($CLAWSV eq "") ?
2201                 _("Claws Mail was not found!") :
2202                 _("Claws Mail returned version {cmv}.", cmv => $CLAWSV);
2203     print $clawsver . "\n";
2204 }
2205
2206 # the command line help
2207 sub print_help() {
2208     my $line = '-' x length ($xl::s{about_title});
2209     say $line;
2210     say $xl::s{about_title};
2211     say $line;
2212     my @help = (
2213         _("Syntax:"),
2214         _("  clawsker [options]"),
2215         _("Options:"),
2216         _("  -a|--alternate-config-dir <dir>  Uses <dir> as Claws Mail configuration."),
2217         _("  -b|--verbose                     More messages on standard output."),
2218         _("  -c|--clawsrc <file>              Uses <file> as full resource name."),
2219         _("  -h|--help                        Prints this help screen and exits."),
2220         _("  -r|--read-only                   Disables writing changes to disk."),
2221         _("  -v|--version                     Prints version information and exits.")
2222     );
2223     foreach (@help) { say $_ }
2224 }
2225
2226 sub parse_command_line {
2227     my $cont = TRUE;
2228     $CLAWSV = get_claws_version ();
2229     eval {
2230         GetOptions('h|help' => sub { print_help (); $cont = FALSE },
2231             'v|version' => sub { print_version (); $cont = FALSE },
2232             'b|verbose' => sub { $VERBOSE = TRUE },
2233             'r|read-only' => sub { $READONLY = TRUE },
2234             'u|use-claws-version=s' => \&opt_use_claws_version,
2235             'a|alternate-config-dir=s' => \&opt_alternate_config_dir,
2236             'c|clawsrc=s' => \&opt_clawsrc)
2237         or die _("try -h or --help for syntax.\n");
2238     };
2239     if ($@) {
2240         my $msg = _("Error in options: {msg}\n", msg => $@);
2241         if (defined $ENV{'DISPLAY'} and $ENV{'DISPLAY'} ne '') {
2242             eval { Gtk2->init };
2243             error_dialog ($msg) unless $@;
2244         }
2245         die $msg;
2246     }
2247     return $cont;
2248 }
2249
2250 sub opt_use_claws_version {
2251     my ($name, $value) = @_;
2252     die _("Error: {opt} requires a dotted numeric value argument\n", opt => $name)
2253         unless ($value =~ /^[\d\.]+$/);
2254     $CLAWSV = $value;
2255 }
2256
2257 sub opt_alternate_config_dir {
2258     my ($name, $value) = @_;
2259     die _("Error: '{dir}' is not a directory or does not exist\n", dir => $value)
2260         unless -d $value;
2261     $CONFIGDIR = $value;
2262     $CONFIGDIR .= "/" unless ($CONFIGDIR =~ /.*\/$/);
2263     $ALTCONFIGDIR = TRUE;
2264 }
2265
2266 sub opt_clawsrc {
2267     my ($name, $value) = @_;
2268     die _("Error: '{value}' is not a file or does not exist\n", value => $value)
2269         unless -f $value;
2270     set_rc_filename ($value);
2271 }
2272
2273 # update the hidden preferences status from loaded values
2274 sub init_hidden_preferences {
2275     foreach my $hash (\%pr::beh, \%pr::col, \%pr::gui, \%pr::oth, \%pr::win) {
2276         foreach my $key (keys %$hash) {
2277             $HPVALUE{${$hash}{$key}[NAME]} = $PREFS{${$hash}{$key}[NAME]};
2278         }
2279     }
2280     foreach my $akey (keys %ACPREFS) {
2281         foreach my $key (keys %pr::acc) {
2282             my $pname = $pr::acc{$key}[NAME];
2283             $ACHPVALUE{$akey}{$pname} = $ACPREFS{$akey}{$pname};
2284         }
2285     }
2286     foreach my $key (keys %pr::plu) {
2287         my $plugin = $pr::plu{$key}[PLUGIN];
2288         my $pname = $pr::plu{$key}[NAME];
2289         if (defined $PLPREFS{$plugin}) {
2290             $PLHPVALUE{$plugin}{$pname} = $PLPREFS{$plugin}{$pname};
2291         }
2292     }
2293     return TRUE;
2294 }
2295
2296 # generic load/save resource files
2297 sub load_resource {
2298     my $rc = shift;
2299     my %data = ();
2300     my %meta = ();
2301     my $line = 0;
2302     open (RCF, '<:encoding(utf8)', $rc)
2303         or die _("Error: opening '{file}' for reading", file => $rc) . ": $!\n";
2304     my $section = '_'; # default unnamed section
2305     while (<RCF>) {
2306         chomp;
2307         ++$line;
2308         next if (/^\s*$/);
2309         if (/^\[([^\]]+)\]$/) { # new section
2310             $section = $1;
2311             die _("Error: duplicate section '{sect}' in resource file '{file}'\n",
2312                 sect => $section, file => $rc) if ($data{$section});
2313             $data{$section} = {};
2314             $meta{$section}{'#'} = $line;
2315         }
2316         elsif (/^([0-9a-z_]+)=(.*)$/) { # key=value
2317             $data{$section}{$1} = $2;
2318             $meta{$section}{$1} = $line;
2319         }
2320         elsif (/^(.*)$/) { # lone value
2321             push (@{$data{$section}{'_'}}, $1);
2322         }
2323     }
2324     close (RCF);
2325     return (\%data, \%meta);
2326 }
2327
2328 sub save_resource {
2329     my ($rc, $data, $meta) = @_;
2330     open (RCF, '>:utf8', $rc)
2331         or die _("Error: opening '{file}' for writing", file => $rc) . ": $!\n";
2332     my @sections = keys %$data;
2333     if (defined $meta) {
2334         @sections = sort {
2335             $meta->{$a}{'#'} <=> $meta->{$b}{'#'}
2336         } @sections
2337     }
2338     foreach my $section (@sections) {
2339         say RCF "[$section]";
2340         if (ref ($data->{$section}{'_'}) eq 'ARRAY') {
2341             foreach my $val (@{$data->{$section}{'_'}}) {
2342                 say RCF $val;
2343             }
2344         } else {
2345             my @keys = keys %{$data->{$section}};
2346             if (defined $meta) {
2347                 @keys = sort {
2348                     $meta->{$section}{$a} <=> $meta->{$section}{$b}
2349                 } @keys
2350             }
2351             foreach my $key (@keys) {
2352                 my $val = $data->{$section}{$key};
2353                 say RCF "$key=$val";
2354             }
2355         }
2356         say RCF "";
2357     }
2358     close (RCF);
2359 }
2360
2361 # load current status from disc
2362 sub load_rc_preferences {
2363     my $rc = get_rc_filename ();
2364     log_message ("Loading preferences from $rc\n");
2365     return FALSE unless check_rc_file ($rc);
2366     ($CONFIGDATA, $CONFIGMETA) = load_resource ($rc);
2367     foreach (keys %{$CONFIGDATA->{'Common'}}) {
2368         $PREFS{$_} = $CONFIGDATA->{'Common'}{$_};
2369     }
2370     foreach my $plugin (@PLUGINS) {
2371         if (defined $CONFIGDATA->{$plugin}) {
2372             push (@AVPLUGINS, $plugin);
2373             foreach (keys %{$CONFIGDATA->{$plugin}}) {
2374                 $PLPREFS{$plugin}{$_} = $CONFIGDATA->{$plugin}{$_};
2375             }
2376         }
2377     }
2378     return TRUE;
2379 }
2380
2381 sub load_ac_preferences {
2382     my $rc = get_ac_rc_filename ();
2383     log_message ("Loading account preferences from $rc\n");
2384     return FALSE unless check_rc_file ($rc);
2385     ($ACCOUNTDATA, $ACCOUNTMETA) = load_resource ($rc);
2386     foreach my $asect (keys %$ACCOUNTDATA) {
2387         if ($asect =~ /^Account: (\d+)$/) {
2388             foreach (keys %{$ACCOUNTDATA->{$asect}}) {
2389                 $ACPREFS{$1}{$_} = $ACCOUNTDATA->{$asect}{$_};
2390             }
2391         }
2392     }
2393     return TRUE;
2394 }
2395
2396 sub load_preferences {
2397     return FALSE unless check_claws_not_running ();
2398     return (load_rc_preferences () and load_ac_preferences ());
2399 }
2400
2401 # save current preferences to disc
2402 sub save_preferences {
2403     my $rc = get_rc_filename ();
2404     log_message ("Saving preferences to $rc\n");
2405     return FALSE unless check_rc_file ($rc);
2406     return FALSE unless check_claws_not_running ();
2407     my $rcbak = "$rc.backup";
2408     rename ($rc, $rcbak);
2409     foreach (keys %PREFS) {
2410         if (defined $HPVALUE{$_}) {
2411             $CONFIGDATA->{'Common'}{$_} = $HPVALUE{$_};
2412         }
2413     }
2414     foreach my $plugin (@AVPLUGINS) {
2415         foreach (keys %{$CONFIGDATA->{$plugin}}) {
2416             if (defined $PLHPVALUE{$plugin}{$_}) {
2417                 $CONFIGDATA->{$plugin}{$_} = $PLHPVALUE{$plugin}{$_};
2418             }
2419         }
2420     }
2421     save_resource ($rc, $CONFIGDATA, $CONFIGMETA);
2422     return TRUE;
2423 }
2424
2425 sub save_ac_preferences {
2426     my $rc = get_ac_rc_filename ();
2427     log_message ("Saving account preferences to $rc\n");
2428     return FALSE unless check_rc_file ($rc);
2429     return FALSE unless check_claws_not_running ();
2430     my $rcbak = "$rc.backup";
2431     rename ($rc, $rcbak);
2432     foreach my $asect (keys %$ACCOUNTDATA) {
2433         if ($asect =~ /^Account: (\d+)$/) {
2434             foreach (keys %{$ACCOUNTDATA->{$asect}}) {
2435                 if (defined $ACHPVALUE{$1}{$_}) {
2436                     $ACCOUNTDATA->{$asect}{$_} = $ACHPVALUE{$1}{$_};
2437                 }
2438             }
2439         }
2440     }
2441     save_resource ($rc, $ACCOUNTDATA, $ACCOUNTMETA);
2442     return TRUE;
2443 }
2444
2445 # create notebook
2446 sub new_notebook {
2447     my $nb = Gtk2::Notebook->new;
2448     #
2449     $nb->append_page (new_behaviour_page (), $xl::s{tab_behaviour});
2450     $nb->append_page (new_colours_page (), $xl::s{tab_colours});
2451     $nb->append_page (new_gui_page (), $xl::s{tab_gui});
2452     $nb->append_page (new_other_page (), $xl::s{tab_other});
2453     $nb->append_page (new_winpos_page (), $xl::s{tab_winpos});
2454     $nb->append_page (new_accounts_page (), $xl::s{tab_accounts});
2455     $nb->append_page (new_plugins_page (), $xl::s{tab_plugins});
2456     $nb->append_page (new_info_page (), $xl::s{tab_info});
2457
2458     return $nb;
2459 }
2460
2461 # create an about dialog
2462 sub new_about_dialog {
2463     my ($parent) = @_;
2464     my $title = $xl::s{about_title};
2465     my $lic = $xl::s{about_license};
2466     my $vers = $xl::s{about_version} . " $VERSION";
2467     my $license =
2468 "This program is free software: you can redistribute it and/or modify
2469 it under the terms of the GNU General Public License as published by
2470 the Free Software Foundation, either version 3 of the License, or
2471 (at your option) any later version.
2472
2473 This program is distributed in the hope that it will be useful,
2474 but WITHOUT ANY WARRANTY; without even the implied warranty of
2475 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2476 GNU General Public License for more details.
2477
2478 You should have received a copy of the GNU General Public License
2479 along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.";
2480     my $year = "2007-2016";
2481     my $holder = "Ricardo Mones &lt;ricardo\@mones.org&gt;";
2482     my $url = "http://www.claws-mail.org/clawsker.php";
2483
2484     my $dialog = Gtk2::MessageDialog->new_with_markup ($parent,
2485                     [qw/modal destroy-with-parent/],
2486                     'info', 'close',
2487                     "<span size=\"x-large\" weight=\"bold\">$title</span>\n"
2488                     . "<span size=\"large\">$vers</span>\n\n"
2489                     . "<span color=\"blue\" size=\"large\">$url</span>\n\n"
2490                     . "<span>Copyright $year by $holder</span>\n\n"
2491                     . "<span size=\"large\">$lic</span>\n\n"
2492                     . "<span size=\"small\">$license</span>");
2493     $dialog->set_title ($xl::s{about});
2494     if (Gtk2->CHECK_VERSION (2, 10, 0)) {
2495         my @icons = get_app_icons ();
2496         my $image = Gtk2::Image->new_from_pixbuf ($icons[-1]);
2497         $image->show ();
2498         $image->set_alignment (0, 0);
2499         $dialog->set_image ($image);
2500     }
2501     #
2502     return $dialog;
2503 }
2504
2505 # create buttons box
2506 sub new_button_box {
2507     my ($parent, $adlg) = @_;
2508     my $b_about = Gtk2::Button->new_from_stock ('gtk-about');
2509     my $b_exit = Gtk2::Button->new_from_stock ('gtk-quit');
2510     my $b_apply = Gtk2::Button->new_from_stock ('gtk-apply');
2511     # disable button until is really implemented
2512     # my $b_undo = Gtk2::Button->new_from_stock ('gtk-undo');
2513     my $hbox = Gtk2::HBox->new (FALSE, 5);
2514     # signal handlers
2515     $b_exit->signal_connect (clicked => sub { Gtk2->main_quit });
2516     $b_apply->set_sensitive (not $READONLY);
2517     $b_apply->signal_connect (clicked => sub {
2518         save_preferences ($parent);
2519         save_ac_preferences ($parent);
2520     });
2521     # $b_undo->signal_connect (clicked => sub { undo_current_changes });
2522     $b_about->signal_connect (clicked => sub { $adlg->run; $adlg->hide });
2523     # package them
2524     $hbox->pack_end ($b_apply, FALSE, FALSE, 0);
2525     $hbox->pack_end ($b_exit, FALSE, FALSE, 0);
2526     # $hbox->pack_end ($b_undo, FALSE, FALSE, 0);
2527     $hbox->pack_start ($b_about, FALSE, FALSE, 0);
2528     #
2529     return $hbox;
2530 }
2531
2532 sub get_app_icons {
2533     return @APPICONS if (@APPICONS);
2534     my @names;
2535     if (-d $DATADIR) { # installed
2536         my $dir = $DATADIR . '/icons/hicolor';
2537         @names = map {
2538             join ('/', ($dir, $_ . 'x' . $_, 'apps', $NAME . '.png'))
2539         } (48, 64, 128);
2540     } else { # unpacked tarball or git clone
2541         @names = map {
2542             join ('/', ('./icons', $NAME . '-' . $_ . '.png'));
2543         } (48, 64, 128);
2544     }
2545     foreach (@names) {
2546         my $icon = undef;
2547         $icon = Gtk2::Gdk::Pixbuf->new_from_file($_) if (-f $_);
2548         push @APPICONS, $icon if ($icon);
2549     }
2550     return @APPICONS;
2551 }
2552
2553 # initialise
2554 exit unless parse_command_line ();
2555 Gtk2->init;
2556 $main_window = Gtk2::Window->new ('toplevel');
2557 exit unless load_preferences ();
2558 exit unless init_hidden_preferences ();
2559 # create main GUI
2560 my $box = Gtk2::VBox->new (FALSE, 5);
2561 $box->set_border_width(3);
2562 my $about = new_about_dialog ();
2563 $box->pack_start (new_notebook (), FALSE, FALSE, 0);
2564 $box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
2565 $main_window->signal_connect (delete_event => sub { Gtk2->main_quit });
2566 $main_window->set_title ($xl::s{win_title});
2567 $main_window->set_icon_list (get_app_icons ());
2568 $main_window->add ($box);
2569 $main_window->show_all;
2570 Gtk2->main;
2571