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