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