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