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