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