3 # Clawsker :: A Claws Mail Tweaker
4 # Copyright 2007-2021 Ricardo Mones <ricardo@mones.org>
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.
11 # See COPYING file for license details.
12 # See AUTHORS file for a complete list of contributors.
20 use Glib qw(TRUE FALSE);
23 use File::Spec::Functions;
24 use POSIX qw(setlocale);
27 use Digest::MD5 qw(md5_hex);
28 use Getopt::Long qw(GetOptionsFromArray);
30 my $NAME = 'clawsker';
31 my $PREFIX = '@PREFIX@';
32 my $LIBDIR = '@LIBDIR@';
33 my $DATADIR = '@DATADIR@';
34 my $VERSION = '@VERSION@';
39 my $main_window = undef;
42 binmode STDOUT, ":encoding(utf8)";
43 my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
44 $locale = "C" unless defined($locale);
45 setlocale (LC_ALL, $locale);
46 bindtextdomain ($NAME, catdir ($PREFIX, 'share', 'locale'));
54 my $xla = gettext ($str);
55 if (scalar(keys(%par)) > 0) {
56 foreach my $key (keys %par) {
57 $xla =~ s/\{$key\}/$par{$key}/g;
60 return decode_utf8($xla);
65 about_title => _('Clawsker :: A Claws Mail Tweaker'),
67 l_oth_use_dlg => _('Use detached address book edit dialogue'),
68 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.'),
69 l_oth_max_use => _('Maximum memory for message cache'),
70 l_oth_max_use_units => _('kilobytes'),
71 h_oth_max_use => _('The maximum amount of memory to use to cache messages, in kilobytes.'),
72 l_oth_min_time => _('Minimun time for cache elements'),
73 l_oth_min_time_units => _('minutes'),
74 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.'),
75 l_oth_use_netm => _('Use NetworkManager'),
76 h_oth_use_netm => _('Use NetworkManager to switch offline automatically.'),
77 l_oth_mp_rounds => _('Rounds for PBKDF2 function'),
78 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.'),
79 l_oth_imap_recl => _('Maximum depth scanning folders'),
80 h_oth_imap_recl => _('Maximum number of nested folders to be scanned on your configured IMAP servers.'),
82 l_gui_b_unread => _('Show unread messages with bold font'),
83 h_gui_b_unread => _('Show unread messages in the Message List using a bold font.'),
84 l_gui_no_markup => _('Don\'t use markup'),
85 h_gui_no_markup => _('Don\'t use bold and italic text in Compose dialogue\'s account selector.'),
86 l_gui_dot_lines => _('Use dotted lines in tree view components'),
87 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.'),
88 l_gui_h_scroll => _('Enable horizontal scrollbar'),
89 h_gui_h_scroll => _('Enable the horizontal scrollbar in the Message List.'),
90 l_gui_swp_from => _('Display To column instead From column in Sent folder'),
91 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.'),
92 l_gui_v_scroll => _('Folder List scrollbar behaviour'),
93 h_gui_v_scroll => _('Specify the policy of vertical scrollbar of Folder List: show always, automatic or hide always.'),
94 l_gui_v_scroll_show => _('Show always'),
95 l_gui_v_scroll_auto => _('Automatic'),
96 l_gui_v_scroll_hide => _('Hide always'),
97 l_gui_from_show => _('From column displays'),
98 h_gui_from_show => _('Selects the data displayed in the From column of the Message List: name, address or both.'),
99 l_gui_from_show_name => _('Name only'),
100 l_gui_from_show_addr => _('Address only'),
101 l_gui_from_show_both => _('Both name and address'),
102 l_gui_strip_off => _('Coloured lines contrast'),
103 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.'),
104 l_gui_cursor_v => _('Show cursor'),
105 h_gui_cursor_v => _('Display the cursor in the Message View.'),
106 l_gui_toolbar_d => _('Detachable toolbars'),
107 h_gui_toolbar_d => _('Show handles in the toolbars.'),
108 l_gui_strip_all => _('Use stripes in all tree view components'),
109 h_gui_strip_all => _('Enable alternately coloured lines in all tree view components.'),
110 l_gui_strip_sum => _('Use stripes in Folder List and Message List'),
111 h_gui_strip_sum => _('Enable alternately coloured lines in Message List and Folder List.'),
112 l_gui_two_line_v => _('2 lines per Message List item in 3-column layout'),
113 h_gui_two_line_v => _('Spread Message List information over two lines when using the three column mode.'),
114 l_gui_margin_co => _('Show margin'),
115 h_gui_margin_co => _('Shows a small margin in the Compose View.'),
116 l_gui_mview_date => _('Don\'t display localized date'),
117 h_gui_mview_date => _('Toggles localization of date format in Message View.'),
118 l_gui_zero_char => _('Zero replacement character'),
119 h_gui_zero_char => _('Replaces \'0\' with the given character in Folder List.'),
120 l_gui_type_any => _('Editable headers'),
121 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.'),
122 l_gui_warn_send_multi => _('Warn when sending to more than'),
123 l_gui_warn_send_multi_units => _('recipients'),
124 h_gui_warn_send_multi => _('Show a warning dialogue when sending to more recipients than specified. Use 0 to disable this check.'),
125 l_gui_next_del => _('Select next message on delete'),
126 h_gui_next_del => _('When deleting a message, toggles between selecting the next one (newer message) or the previous one (older message).'),
128 l_beh_hover_t => _('Drag \'n\' drop hover timeout'),
129 l_beh_hover_t_units => _('milliseconds'),
130 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.'),
131 l_beh_dangerous => _('Don\'t confirm deletions (dangerous!)'),
132 h_beh_dangerous => _('Don\'t ask for confirmation before definitive deletion of emails.'),
133 l_beh_flowed => _('Respect format=flowed in messages'),
134 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.'),
135 l_beh_parts_rw => _('Allow writable temporary files'),
136 h_beh_parts_rw => _('Saves temporary files when opening attachment with write bit set.'),
137 l_beh_skip_ssl => _('Don\'t check SSL certificates'),
138 h_beh_skip_ssl => _('Disables the verification of SSL certificates.'),
139 l_beh_up_step => _('Progress bar update step every'),
140 l_beh_up_step_units => _('items'),
141 h_beh_up_step => _('Update stepping in progress bars.'),
142 l_beh_thread_a => _('Maximum age when threading by subject'),
143 l_beh_thread_a_units => _('days'),
144 h_beh_thread_a => _('Number of days to include a message in a thread when using "Thread using subject in addition to standard headers".'),
145 l_beh_unsafe_ssl => _('Allow unsafe SSL certificates'),
146 h_beh_unsafe_ssl => _('Allows Claws Mail to remember multiple SSL certificates for a given server/port.'),
147 l_beh_use_utf8 => _('Force UTF-8 for broken mails'),
148 h_beh_use_utf8 => _('Use UTF-8 encoding for broken mails instead of current locale.'),
149 l_beh_warn_dnd => _('Warn on drag \'n\' drop'),
150 h_beh_warn_dnd => _('Display a confirmation dialogue on drag \'n\' drop of folders.'),
151 l_beh_out_ascii => _('Outgoing messages fallback to ASCII'),
152 h_beh_out_ascii => _('If allowed by content, ASCII will be used to encode outgoing messages, otherwise the user-defined encoding is always enforced.'),
153 l_beh_pp_unsel => _('Primary paste unselects selection'),
154 h_beh_pp_unsel => _('Controls how pasting using middle-click changes the selected text and insertion point.'),
155 l_beh_inline_at => _('Show inline attachments'),
156 h_beh_inline_at => _('Allows to hide inline attachments already shown in mail structure view.'),
157 l_beh_addr_swc => _('Address search in compose window matches any'),
158 h_beh_addr_swc => _('On Tab-key completion, address text will match any part of the string or only from the start.'),
159 l_beh_fold_swc => _('Folder search in folder selector matches any'),
160 h_beh_fold_swc => _('On folder name completion text will match any part of the string or only from the start.'),
161 l_beh_rewrite_ff => _('Rewrite first \'From\' using QP encoding'),
162 h_beh_rewrite_ff => _('Workaround some servers which convert first \'From\' to \'>From\' by using Quoted-Printable transfer encoding instead of 7bit/8bit encoding.'),
163 l_beh_hide_tz => _('Hide time zone information'),
164 h_beh_hide_tz => _('On outgoing messages, sets time zone of date headers to the unknown timezone value "-0000", as specified by RFC 5322'),
166 l_col_emphasis => _('X-Mailer header'),
167 h_col_emphasis => _('The colour used for the X-Mailer line when its value is Claws Mail.'),
168 l_col_log_err => _('Error messages'),
169 h_col_log_err => _('Colour for error messages in log window.'),
170 l_col_log_in => _('Server messages'),
171 h_col_log_in => _('Colour for messages received from servers in log window.'),
172 l_col_log_msg => _('Standard messages'),
173 h_col_log_msg => _('Colour for messages in log window.'),
174 l_col_log_out => _('Client messages'),
175 h_col_log_out => _('Colour for messages sent to servers in log window.'),
176 l_col_log_warn => _('Warning messages'),
177 h_col_log_warn => _('Colour for warning messages in log window.'),
179 l_col_tags_bg => _('Tags background'),
180 h_col_tags_bg => _('Background colour for tags in message view.'),
181 l_col_tags_text => _('Tags text'),
182 h_col_tags_text => _('Text colour for tags in message view.'),
184 l_col_default_header_bg => _('Default headers background'),
185 h_col_default_header_bg => _('Background colour for default headers in compose window.'),
186 l_col_default_header_text => _('Default headers text'),
187 h_col_default_header_text => _('Text colour for default headers in compose window.'),
189 l_col_qs_active_bg => _('Active quick search background'),
190 h_col_qs_active_bg => _('Background colour for active quick search.'),
191 l_col_qs_active_text => _('Active quick search text'),
192 h_col_qs_active_text => _('Text colour for active quick search.'),
193 l_col_qs_error_bg => _('Quick search error background'),
194 h_col_qs_error_bg => _('Background colour for quick search error.'),
195 l_col_qs_error_text => _('Quick search error text'),
196 h_col_qs_error_text => _('Text colour for quick search error.'),
198 l_col_diff_add => _('Added lines'),
199 h_col_diff_add => _('Colour for added lines in patches.'),
200 l_col_diff_del => _('Deleted lines'),
201 h_col_diff_del => _('Colour for deleted lines in patches.'),
202 l_col_diff_hunk => _('Hunk lines'),
203 h_col_diff_hunk => _('Colour for hunk headers in patches.'),
205 l_win_x => _('X position'),
206 h_win_x => _('X coordinate for window\'s top-left corner.'),
207 l_win_y => _('Y position'),
208 h_win_y => _('Y coordinate for window\'s top-left corner.'),
209 l_win_w => _('Width'),
210 h_win_w => _('Window\'s width in pixels.'),
211 l_win_h => _('Height'),
212 h_win_h => _('Window\'s height in pixels.'),
214 l_win_main_mx => _('Maximized'),
215 h_win_main_mx => _('Changes window maximized status.'),
216 l_win_main_fs => _('Full-screen'),
217 h_win_main_fs => _('Changes full screen status.'),
219 l_acc_gtls_set => _('Use custom GnuTLS priority'),
220 h_acc_gtls_set => _('Enables using user provided GnuTLS priority string.'),
221 l_acc_gtls_pri => _('GnuTLS priority'),
222 h_acc_gtls_pri => _('Value to use as GnuTLS priority string if custom priority check is enabled. Otherwise this value is ignored.'),
223 l_acc_tls_sni => _('Use TLS SNI extension'),
224 h_acc_tls_sni => _('Enables sending your hostname, if available, so the server can select the appropriate certificate for your domain. Useful for servers which host multiple domains on the same IP address.'),
226 l_plu_gpg_alimit => _('Autocompletion limit'),
227 h_plu_gpg_alimit => _('Limits the number of addresses obtained from keyring through autocompletion. Use 0 to get all matches.'),
228 l_plu_lav_burl => _('Base URL'),
229 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.'),
230 l_plu_lav_maxr => _('Default redirects'),
231 h_plu_lav_maxr => _('Maximum default value for HTTP redirects, if enabled'),
232 l_plu_lav_maxrmm => _('Mistery man redirects'),
233 h_plu_lav_maxrmm => _('Maximum value for HTTP redirects when using "Mistery man" mode.'),
234 l_plu_lav_maxrurl => _('Custom URL redirects'),
235 h_plu_lav_maxrurl => _('Maximum value for HTTP redirects when using a custom URL'),
237 l_plu_prl_flvb => _('Log level'),
238 h_plu_prl_flvb => _('Verbosity level of log, accumulative.'),
239 l_plu_prl_none => _('None'),
240 l_plu_prl_manual => _('Manual'),
241 l_plu_prl_action => _('Actions'),
242 l_plu_prl_match => _('Matches'),
245 # data and metadata of resource files
250 # all preferences read by load_preferences
254 # values of all preferences handled by clawsker
258 # default config dir and file name
259 my $ALTCONFIGDIR = FALSE;
260 my $CONFIGDIR = catdir ($ENV{HOME}, '.claws-mail');
261 my $CONFIGRC = 'clawsrc';
262 my $ACCOUNTRC = 'accountrc';
263 # supported and available plugins lists
264 my @PLUGINS = qw(AttRemover GPG ManageSieve Libravatar PerlPlugin);
266 # loaded hotkeys from load_menurc
268 # current tree selection
276 # index constants for preference arrays
277 NAME => 0, # the name on the rc file
278 LABEL => 1, # the label on the GUI
279 DESC => 2, # the description for the hint/help
280 TYPE => 3, # data type: bool, int, float, string, color
281 CMVER => 4, # lowest[,highest] Claws Mail version(s) the feature exists
282 CMDEF => 5, # default value for the preference in Claws Mail
283 PLUGIN => 6, # plugin section (only in plugin preferences)
284 # constants for GUI spacing
287 # for data references indexing
290 # hotkey list store columns
300 sub version_greater_or_equal {
301 my ($version, $refvers) = @_;
302 return TRUE if (length($version) == 0 and length($refvers) >= 0);
303 return FALSE if (length($version) >= 0 and length($refvers) == 0);
304 return TRUE if (version->parse($version) >= version->parse($refvers));
308 sub get_claws_version {
309 my $cm_path = which ('claws-mail') or return ""; # not found
310 open my $ph, "-|", $cm_path, "-v" or return ""; # no pipe
311 chomp (my $v = <$ph>);
313 # Claws Mail version 3.17.2git17
314 $v =~ m/\bversion\s+(\d[\w.]+)/ or die "Invalid version string: '$v'";
316 my @ver = split m/(?:\.|git)/, $cmv;
317 @ver < 4 and push @ver, 0;
318 return join ".", @ver;
321 # data handlers and auxiliar functions
323 sub handle_bool_value {
324 my ($widget, $event, $dataref) = @_;
325 $$dataref->[VALUE] = ($widget->get_active ())? '1': '0';
326 $MODIFIED += $$dataref->[VALUE] != $$dataref->[IVALUE]? 1: -1
327 if defined $$dataref->[IVALUE];
330 sub handle_int_value {
331 my ($widget, $event, $dataref) = @_;
332 $_ = $widget->get_text ();
336 $$dataref->[VALUE] = $_;
337 $widget->set_text ($_);
340 $widget->set_text ($$dataref->[VALUE]);
342 $MODIFIED += $$dataref->[VALUE] != $$dataref->[IVALUE]? 1: -1
343 if defined $$dataref->[IVALUE];
346 sub handle_nchar_value {
347 my ($widget, $event, $dataref, $minlen, $maxlen) = @_;
348 $_ = substr ($widget->get_text (), 0, $maxlen);
349 $widget->set_text ($_);
350 $$dataref->[VALUE] = $_;
351 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
352 if defined $$dataref->[IVALUE];
355 sub gdk_rgba_from_str {
357 my ($rr, $gg, $bb) = (0, 0 ,0);
359 if (/\#([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])/) {
364 my $color = Gtk3::Gdk::RGBA->new ($rr, $gg, $bb, 1.0);
368 sub str_from_gdk_rgba {
370 my $rr = $color->red * 256;
371 my $gg = $color->green * 256;
372 my $bb = $color->blue * 256;
373 my $str = sprintf ("#%.2x%.2x%.2x", $rr, $gg, $bb);
377 sub handle_color_value {
378 my ($widget, $event, $dataref) = @_;
379 my $newcol = $widget->get_rgba;
380 $$dataref->[VALUE] = str_from_gdk_rgba ($newcol);
381 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
382 if defined $$dataref->[IVALUE];
385 sub handle_selection_value {
386 my ($widget, $event, $dataref) = @_;
387 $$dataref->[VALUE] = $widget->get_active;
388 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
389 if defined $$dataref->[IVALUE];
392 sub get_rc_filename {
393 return catfile ($CONFIGDIR, $CONFIGRC);
396 sub get_ac_rc_filename {
397 return catfile ($CONFIGDIR, $ACCOUNTRC);
400 sub get_menurc_filename {
401 return catfile ($CONFIGDIR, "menurc");
404 sub set_rc_filename {
406 my @parts = splitpath ($fullname);
407 $CONFIGRC = $parts[$#parts];
408 $parts[$#parts] = '';
409 $CONFIGDIR = catpath (@parts);
413 my ($mesg, $fatal) = @_;
414 if (defined($fatal) && $fatal eq 'die') {
415 die "$NAME: $mesg\n";
418 print "$NAME: $mesg\n";
423 my ($parent, $title, $markup, $type, $buttons) = @_;
424 my $flags = [qw/modal destroy-with-parent/];
425 my $dialog = Gtk3::Dialog->new_with_buttons (
426 $title, $parent, $flags, @$buttons
428 my $label = Gtk3::Label->new;
429 $label->set_markup ($markup);
431 if ($type eq 'error') {
432 $icon = Gtk3::Image->new_from_icon_name('dialog-error', 'GTK_ICON_SIZE_DIALOG');
433 } elsif ($type eq 'warning') {
434 $icon = Gtk3::Image->new_from_icon_name('dialog-warning', 'GTK_ICON_SIZE_DIALOG');
435 } elsif ($type eq 'question') {
436 $icon = Gtk3::Image->new_from_icon_name('dialog-question', 'GTK_ICON_SIZE_DIALOG');
438 my $hbox = Gtk3::Box->new ('horizontal', 5);
439 $hbox->pack_start ($icon, FALSE, FALSE, 5) if defined $icon;
440 $hbox->pack_start ($label, FALSE, FALSE, 5);
441 my $dialogbox = $dialog->get_content_area;
442 $dialogbox->add ($hbox);
443 $dialogbox->show_all;
449 my $markup = "<span weight=\"bold\" size=\"large\">" . $emsg . "</span>";
450 my $errordlg = message_dialog (
451 $main_window, _('Clawsker error'), $markup, 'error', [ 'gtk-cancel', 0 ]
457 sub claws_is_running {
458 my $emsg = _('Error: seems Claws Mail is currently running, close it first.');
460 error_dialog ($emsg);
464 sub has_claws_socket {
469 my $socket = catfile ($lockdir, md5_hex ($_));
470 -S $socket and return TRUE;
475 sub check_claws_not_running {
476 return TRUE if $READONLY;
477 my $rundir = $ENV{XDG_RUNTIME_DIR} // $ENV{XDG_CACHE_HOME};
478 defined $rundir and do {
479 my $lockdir = catfile ($rundir, "claws-mail");
480 return claws_is_running () if has_claws_socket ($lockdir);
482 my $tmpdir = File::Spec->tmpdir ();
483 my $lockdir = catfile ($tmpdir, "claws-mail-$<");
484 return claws_is_running () if has_claws_socket ($lockdir);
490 (defined($rcfile) && -f $rcfile) or do {
491 my $emsg = _('Error: resource file for Claws Mail was not found.');
493 error_dialog ($emsg);
499 sub set_widget_hint {
500 my ($wdgt, $hint) = @_;
501 $wdgt->set_tooltip_text ($hint);
502 $wdgt->set_has_tooltip (TRUE);
505 sub set_widget_sens {
506 my ($wdgt, $versions) = @_;
508 my @ver = split(/,/, $versions);
510 $wdgt->set_sensitive (
511 version_greater_or_equal ($CLAWSV, $ver[0])
512 and version_greater_or_equal ($ver[1], $CLAWSV)
515 $wdgt->set_sensitive (version_greater_or_equal ($CLAWSV, $ver[0]));
519 # graphic element creation
521 sub new_hbox_spaced_pack {
522 my $hbox = Gtk3::HBox->new (FALSE);
524 $hbox->pack_start ($_, FALSE, FALSE, HBOX_PAD);
529 sub new_check_button_for($$$) {
530 my ($hash, $key, $vhash) = @_;
531 my $name = $$hash{$key}[NAME];
532 my $label = $$hash{$key}[LABEL];
534 my $cb = Gtk3::CheckButton->new ($label);
535 my $value = $$vhash{$name}[VALUE];
536 $value //= $$hash{$key}[CMDEF];
537 $cb->set_active ($value eq '1');
538 $cb->signal_connect (clicked => sub {
540 handle_bool_value ($w, $e, \$$vhash{$name});
542 set_widget_hint ($cb, $$hash{$key}[DESC]);
543 set_widget_sens ($cb, $$hash{$key}[CMVER]);
545 return new_hbox_spaced_pack ($cb);
548 sub new_text_box_for_int($$$) {
549 my ($hash, $key, $vhash) = @_;
550 my $name = $$hash{$key}[NAME];
551 my $label = $$hash{$key}[LABEL];
552 my @type = split (/,/, $$hash{$key}[TYPE]);
553 push (@type, 0), push (@type, 10000) unless ($#type > 0);
556 if (ref $label eq 'ARRAY') {
557 $gunits = Gtk3::Label->new ($label->[1]);
558 $label = $label->[0];
560 my $glabel = Gtk3::Label->new ($label);
561 my $pagei = int (($type[2] - $type[1]) / 10);
562 my $gentry = Gtk3::SpinButton->new_with_range ($type[1], $type[2], $pagei);
563 my $value = $$vhash{$name}[VALUE];
564 $value //= $$hash{$key}[CMDEF];
565 $gentry->set_numeric (TRUE);
566 $gentry->set_value ($value);
567 $gentry->signal_connect('value-changed' => sub {
569 handle_int_value ($w, $e, \$$vhash{$name});
571 set_widget_hint ($gentry, $$hash{$key}[DESC]);
572 set_widget_sens ($gentry, $$hash{$key}[CMVER]);
573 $glabel->set_sensitive ($gentry->get_sensitive);
574 $gunits->set_sensitive ($gentry->get_sensitive) if ($gunits);
576 return new_hbox_spaced_pack ($glabel, $gentry, $gunits) if ($gunits);
577 return new_hbox_spaced_pack ($glabel, $gentry);
580 sub new_text_box_for_nchar($$$) {
581 my ($hash, $key, $vhash) = @_;
582 my $name = $$hash{$key}[NAME];
583 my $label = $$hash{$key}[LABEL];
584 my @type = split (/,/, $$hash{$key}[TYPE]); # char,minlen,maxlen,width
585 my $glabel = Gtk3::Label->new ($label);
586 my $gentry = Gtk3::Entry->new;
587 $gentry->set_max_length($type[2]) if defined ($type[2]);
588 my $width = $type[3];
590 $gentry->set_width_chars(int ($width) + 2) if defined ($width);
591 my $value = $$vhash{$name}[VALUE];
592 $value //= $$hash{$key}[CMDEF];
593 $gentry->set_text ($value);
594 $gentry->signal_connect('key-release-event' => sub {
596 handle_nchar_value ($w, $e, \$$vhash{$name}, $type[1], $type[2]);
598 set_widget_hint ($gentry, $$hash{$key}[DESC]);
599 set_widget_sens ($gentry, $$hash{$key}[CMVER]);
600 $glabel->set_sensitive ($gentry->get_sensitive);
602 return new_hbox_spaced_pack ($glabel, $gentry);
605 sub new_color_button_for($$$) {
606 my ($hash, $key, $vhash) = @_;
607 my $name = $$hash{$key}[NAME];
608 my $label = $$hash{$key}[LABEL];
610 my $value = $$vhash{$name}[VALUE];
611 $value //= $$hash{$key}[CMDEF];
612 my $col = gdk_rgba_from_str ($value);
613 my $glabel = Gtk3::Label->new ($label);
614 my $button = Gtk3::ColorButton->new_with_rgba ($col);
615 $button->set_title ($label);
616 $button->set_relief ('none');
617 $button->signal_connect ('color-set' => sub {
619 handle_color_value ($w, $e, \$$vhash{$name});
621 set_widget_hint ($button, $$hash{$key}[DESC]);
622 set_widget_sens ($button, $$hash{$key}[CMVER]);
623 $glabel->set_sensitive ($button->get_sensitive);
625 return new_hbox_spaced_pack ($button, $glabel);
628 sub new_selection_box_for($$$) {
629 my ($hash, $key, $vhash) = @_;
630 my $name = $$hash{$key}[NAME];
631 my $label = $$hash{$key}[LABEL];
633 my $glabel = Gtk3::Label->new ($label);
634 my $combo = Gtk3::ComboBoxText->new;
635 my @options = split (';', $$hash{$key}[TYPE]);
636 foreach my $opt (@options) {
637 my ($index, $textkey) = split ('=', $opt);
638 $combo->insert (-1, $index, $xl::s{$textkey});
640 $combo->signal_connect ('changed' => sub {
642 handle_selection_value ($w, $e, \$$vhash{$name});
644 my $value = $$vhash{$name}[VALUE];
645 $value //= $$hash{$key}[CMDEF];
646 $combo->set_active ($value);
647 set_widget_hint ($combo, $$hash{$key}[DESC]);
648 set_widget_sens ($combo, $$hash{$key}[CMVER]);
649 $glabel->set_sensitive ($combo->get_sensitive);
651 return new_hbox_spaced_pack ($glabel, $combo);
654 # more graphic helpers
657 my ($border_w, $row_s, $col_s) = @_;
658 $border_w //= GRID_SPC;
661 my $grid = Gtk3::Grid->new;
662 $grid->set_border_width ($border_w);
663 $grid->set_row_spacing ($row_s);
664 $grid->set_column_spacing ($col_s);
671 my $label = Gtk3::Label->new ($text);
672 $label->set_alignment (0, 0.5);
679 my $label = Gtk3::Label->new ('<b>' . $text . '</b>');
680 $label->set_use_markup (TRUE);
681 $label->set_alignment (0, 0.5);
686 my ($width, $height, $widget) = @_;
687 my $grid = new_grid ();
688 $grid->set_column_homogeneous (TRUE);
689 for (my $i = 0; $i < $width; ++$i) {
690 for (my $j = 0; $j < $height; ++$j) {
691 my $wid = $widget->[$j]->[$i];
692 next unless defined $wid;
693 my $ww = (($i + 1 < $width) and (defined $widget->[$j]->[$i + 1]))
697 $grid->attach ($wid, $i, $j, $ww, 1);
698 } else { # not a widget
699 if ('--' eq $wid) { # a separator
700 $grid->attach (Gtk3::Separator->new ('horizontal'),
702 } else { # or a title
703 $grid->attach (new_title ($wid),
712 # preference maps and corresponding page creation subs
714 %pr::oth = ( # other preferences
716 'addressbook_use_editaddress_dialog',
717 $xl::s{l_oth_use_dlg},
718 $xl::s{h_oth_use_dlg},
724 'cache_max_mem_usage',
725 [ $xl::s{l_oth_max_use}, $xl::s{l_oth_max_use_units} ],
726 $xl::s{h_oth_max_use},
727 'int,0,524288', # 0 Kb - 512 Mb
732 'cache_min_keep_time',
733 [ $xl::s{l_oth_min_time}, $xl::s{l_oth_min_time_units} ],
734 $xl::s{h_oth_min_time},
735 'int,0,120', # 0 minutes - 2 hours
740 'use_networkmanager',
741 $xl::s{l_oth_use_netm},
742 $xl::s{h_oth_use_netm},
748 'master_passphrase_pbkdf2_rounds',
749 $xl::s{l_oth_mp_rounds},
750 $xl::s{h_oth_mp_rounds},
756 'imap_scan_tree_recurs_limit',
757 $xl::s{l_oth_imap_recl},
758 $xl::s{h_oth_imap_recl},
765 sub new_other_page() {
766 return new_grid_pack (1, 15, [
767 [ _('Addressbook') ],
768 [ new_check_button_for(\%pr::oth, 'use_dlg', \%HPVALUE) ],
771 [ new_text_box_for_int(\%pr::oth, 'max_use', \%HPVALUE) ],
772 [ new_text_box_for_int(\%pr::oth, 'min_time', \%HPVALUE) ],
774 [ _('NetworkManager') ],
775 [ new_check_button_for(\%pr::oth, 'use_netm', \%HPVALUE) ],
777 [ _('Master passphrase') ],
778 [ new_text_box_for_int(\%pr::oth, 'mp_rounds', \%HPVALUE) ],
781 [ new_text_box_for_int(\%pr::oth, 'imap_recl', \%HPVALUE) ]
785 %pr::gui = ( # gui bells and whistles
788 $xl::s{l_gui_b_unread},
789 $xl::s{h_gui_b_unread},
796 $xl::s{l_gui_no_markup},
797 $xl::s{h_gui_no_markup},
803 'enable_dotted_lines',
804 $xl::s{l_gui_dot_lines},
805 $xl::s{h_gui_dot_lines},
807 '2.4.0.115,3.7.10.44',
812 $xl::s{l_gui_h_scroll},
813 $xl::s{h_gui_h_scroll},
820 $xl::s{l_gui_swp_from},
821 $xl::s{h_gui_swp_from},
827 'folderview_vscrollbar_policy',
828 $xl::s{l_gui_v_scroll},
829 $xl::s{h_gui_v_scroll},
830 '0=l_gui_v_scroll_show;1=l_gui_v_scroll_auto;2=l_gui_v_scroll_hide',
836 $xl::s{l_gui_from_show},
837 $xl::s{h_gui_from_show},
838 '0=l_gui_from_show_name;1=l_gui_from_show_addr;2=l_gui_from_show_both',
843 'stripes_color_offset',
844 $xl::s{l_gui_strip_off},
845 $xl::s{h_gui_strip_off},
846 'int,0,40000', # no idea what this number means
851 'textview_cursor_visible',
852 $xl::s{l_gui_cursor_v},
853 $xl::s{h_gui_cursor_v},
859 'toolbar_detachable',
860 $xl::s{l_gui_toolbar_d},
861 $xl::s{h_gui_toolbar_d},
867 'use_stripes_everywhere',
868 $xl::s{l_gui_strip_all},
869 $xl::s{h_gui_strip_all},
875 'use_stripes_in_summaries',
876 $xl::s{l_gui_strip_sum},
877 $xl::s{h_gui_strip_sum},
884 $xl::s{l_gui_two_line_v},
885 $xl::s{h_gui_two_line_v},
891 'show_compose_margin',
892 $xl::s{l_gui_margin_co},
893 $xl::s{h_gui_margin_co},
899 'msgview_date_format',
900 $xl::s{l_gui_mview_date},
901 $xl::s{h_gui_mview_date},
907 'zero_replacement_char',
908 $xl::s{l_gui_zero_char},
909 $xl::s{h_gui_zero_char},
916 $xl::s{l_gui_type_any},
917 $xl::s{h_gui_type_any},
923 'warn_sending_many_recipients_num',
924 [ $xl::s{l_gui_warn_send_multi}, $xl::s{l_gui_warn_send_multi_units} ],
925 $xl::s{h_gui_warn_send_multi},
932 $xl::s{l_gui_next_del},
933 $xl::s{h_gui_next_del},
941 return new_grid_pack (2, 24, [
942 [ _('Coloured stripes') ],
943 [ new_check_button_for (\%pr::gui, 'strip_all', \%HPVALUE),
944 new_check_button_for (\%pr::gui, 'strip_sum', \%HPVALUE) ],
945 [ new_text_box_for_int (\%pr::gui, 'strip_off', \%HPVALUE) ],
947 [ _('Message List') ],
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) ],
954 [ _('Message View') ],
955 [ new_check_button_for (\%pr::gui, 'cursor_v', \%HPVALUE),
956 new_check_button_for (\%pr::gui, 'mview_date', \%HPVALUE) ],
958 [ _('Compose window') ],
959 [ new_check_button_for (\%pr::gui, 'no_markup', \%HPVALUE),
960 new_check_button_for (\%pr::gui, 'margin_co', \%HPVALUE) ],
961 [ new_check_button_for (\%pr::gui, 'type_any', \%HPVALUE),
962 new_text_box_for_int (\%pr::gui, 'warn_send_multi', \%HPVALUE) ],
964 [ _('Scroll bars') ],
965 [ new_check_button_for (\%pr::gui, 'h_scroll', \%HPVALUE),
966 new_selection_box_for (\%pr::gui, 'v_scroll', \%HPVALUE) ],
969 [ new_check_button_for (\%pr::gui, 'dot_lines', \%HPVALUE),
970 new_check_button_for (\%pr::gui, 'toolbar_d', \%HPVALUE) ],
971 [ new_text_box_for_nchar (\%pr::gui, 'zero_char', \%HPVALUE) ]
975 %pr::beh = ( # tweak some behaviour
978 [ $xl::s{l_beh_hover_t}, $xl::s{l_beh_hover_t_units} ],
979 $xl::s{h_beh_hover_t},
980 'int,100,3000', # 0.1 seconds - 3 seconds
986 $xl::s{l_beh_dangerous},
987 $xl::s{h_beh_dangerous},
993 'respect_flowed_format',
994 $xl::s{l_beh_flowed},
995 $xl::s{h_beh_flowed},
1001 'save_parts_readwrite',
1002 $xl::s{l_beh_parts_rw},
1003 $xl::s{h_beh_parts_rw},
1009 'skip_ssl_cert_check',
1010 $xl::s{l_beh_skip_ssl},
1011 $xl::s{h_beh_skip_ssl},
1017 'statusbar_update_step',
1018 [ $xl::s{l_beh_up_step}, $xl::s{l_beh_up_step_units} ],
1019 $xl::s{h_beh_up_step},
1020 'int,1,200', # 1 item - 200 items
1025 'thread_by_subject_max_age',
1026 [ $xl::s{l_beh_thread_a}, $xl::s{l_beh_thread_a_units} ],
1027 $xl::s{h_beh_thread_a},
1028 'int,1,30', # 1 day - 30 days
1034 $xl::s{l_beh_unsafe_ssl},
1035 $xl::s{h_beh_unsafe_ssl},
1041 'utf8_instead_of_locale_for_broken_mail',
1042 $xl::s{l_beh_use_utf8},
1043 $xl::s{h_beh_use_utf8},
1050 $xl::s{l_beh_warn_dnd},
1051 $xl::s{h_beh_warn_dnd},
1057 'outgoing_fallback_to_ascii',
1058 $xl::s{l_beh_out_ascii},
1059 $xl::s{h_beh_out_ascii},
1065 'primary_paste_unselects',
1066 $xl::s{l_beh_pp_unsel},
1067 $xl::s{h_beh_pp_unsel},
1073 'show_inline_attachments',
1074 $xl::s{l_beh_inline_at},
1075 $xl::s{h_beh_inline_at},
1081 'address_search_wildcard',
1082 $xl::s{l_beh_addr_swc},
1083 $xl::s{h_beh_addr_swc},
1089 'folder_search_wildcard',
1090 $xl::s{l_beh_fold_swc},
1091 $xl::s{h_beh_fold_swc},
1097 'rewrite_first_from',
1098 $xl::s{l_beh_rewrite_ff},
1099 $xl::s{h_beh_rewrite_ff},
1106 $xl::s{l_beh_hide_tz},
1107 $xl::s{h_beh_hide_tz},
1114 sub new_behaviour_page() {
1115 return new_grid_pack (2, 21, [
1116 [ _('Drag \'n\' drop') ],
1117 [ new_text_box_for_int (\%pr::beh, 'hover_t', \%HPVALUE) ],
1118 [ new_check_button_for (\%pr::beh, 'warn_dnd', \%HPVALUE) ],
1120 [ _('Secure Sockets Layer') ],
1121 [ new_check_button_for (\%pr::beh, 'skip_ssl', \%HPVALUE),
1122 new_check_button_for (\%pr::beh, 'unsafe_ssl', \%HPVALUE) ],
1125 [ new_check_button_for (\%pr::beh, 'flowed', \%HPVALUE),
1126 new_check_button_for (\%pr::beh, 'out_ascii', \%HPVALUE) ],
1127 [ new_check_button_for (\%pr::beh, 'parts_rw', \%HPVALUE),
1128 new_check_button_for (\%pr::beh, 'pp_unsel', \%HPVALUE) ],
1129 [ new_check_button_for (\%pr::beh, 'use_utf8', \%HPVALUE),
1130 new_check_button_for (\%pr::beh, 'inline_at', \%HPVALUE) ],
1131 [ new_check_button_for (\%pr::beh, 'dangerous', \%HPVALUE),
1132 new_check_button_for (\%pr::beh, 'rewrite_ff', \%HPVALUE) ],
1133 [ new_check_button_for (\%pr::beh, 'hide_tz', \%HPVALUE) ],
1135 [ _('Completion') ],
1136 [ new_check_button_for (\%pr::beh, 'addr_swc', \%HPVALUE) ],
1137 [ new_check_button_for (\%pr::beh, 'fold_swc', \%HPVALUE) ],
1140 [ new_text_box_for_int (\%pr::beh, 'up_step', \%HPVALUE) ],
1141 [ new_text_box_for_int (\%pr::beh, 'thread_a', \%HPVALUE) ]
1145 %pr::col = ( # a variety of colours
1148 $xl::s{l_col_emphasis},
1149 $xl::s{h_col_emphasis},
1156 $xl::s{l_col_log_err},
1157 $xl::s{h_col_log_err},
1164 $xl::s{l_col_log_in},
1165 $xl::s{h_col_log_in},
1172 $xl::s{l_col_log_msg},
1173 $xl::s{h_col_log_msg},
1180 $xl::s{l_col_log_out},
1181 $xl::s{h_col_log_out},
1188 $xl::s{l_col_log_warn},
1189 $xl::s{h_col_log_warn},
1196 $xl::s{l_col_diff_add},
1197 $xl::s{h_col_diff_add},
1199 '3.8.0.54,3.17.4.35',
1203 'diff_deleted_color',
1204 $xl::s{l_col_diff_del},
1205 $xl::s{h_col_diff_del},
1207 '3.8.0.54,3.17.4.35',
1212 $xl::s{l_col_diff_hunk},
1213 $xl::s{h_col_diff_hunk},
1215 '3.8.0.54,3.17.4.35',
1220 $xl::s{l_col_tags_bg},
1221 $xl::s{h_col_tags_bg},
1228 $xl::s{l_col_tags_text},
1229 $xl::s{h_col_tags_text},
1234 default_header_bg => [
1235 'default_header_bgcolor',
1236 $xl::s{l_col_default_header_bg},
1237 $xl::s{h_col_default_header_bg},
1242 default_header_text => [
1243 'default_header_color',
1244 $xl::s{l_col_default_header_text},
1245 $xl::s{h_col_default_header_text},
1251 'qs_active_bgcolor',
1252 $xl::s{l_col_qs_active_bg},
1253 $xl::s{h_col_qs_active_bg},
1260 $xl::s{l_col_qs_active_text},
1261 $xl::s{h_col_qs_active_text},
1268 $xl::s{l_col_qs_error_bg},
1269 $xl::s{h_col_qs_error_bg},
1276 $xl::s{l_col_qs_error_text},
1277 $xl::s{h_col_qs_error_text},
1284 sub new_colours_page() {
1285 return new_grid_pack (3, 18, [
1286 [ _('Message View') ],
1287 [ new_color_button_for (\%pr::col, 'emphasis', \%HPVALUE) ],
1288 [ new_color_button_for (\%pr::col, 'tags_text', \%HPVALUE) ,
1289 new_color_button_for (\%pr::col, 'tags_bg', \%HPVALUE) ],
1291 [ _('Log window') ],
1292 [ new_color_button_for (\%pr::col, 'log_err', \%HPVALUE) ,
1293 new_color_button_for (\%pr::col, 'log_in', \%HPVALUE) ],
1294 [ new_color_button_for (\%pr::col, 'log_warn', \%HPVALUE) ,
1295 new_color_button_for (\%pr::col, 'log_out', \%HPVALUE) ],
1296 [ new_color_button_for (\%pr::col, 'log_msg', \%HPVALUE) ],
1298 [ _('Viewing patches') ],
1299 [ new_color_button_for (\%pr::col, 'diff_add', \%HPVALUE) ,
1300 new_color_button_for (\%pr::col, 'diff_del', \%HPVALUE) ,
1301 new_color_button_for (\%pr::col, 'diff_hunk', \%HPVALUE) ],
1303 [ _('Compose window') ],
1304 [ new_color_button_for (\%pr::col, 'default_header_text', \%HPVALUE) ,
1305 new_color_button_for (\%pr::col, 'default_header_bg', \%HPVALUE) ],
1307 [ _('Quick search') ],
1308 [ new_color_button_for (\%pr::col, 'qs_active_text', \%HPVALUE) ,
1309 new_color_button_for (\%pr::col, 'qs_active_bg', \%HPVALUE) ],
1310 [ new_color_button_for (\%pr::col, 'qs_error_text', \%HPVALUE) ,
1311 new_color_button_for (\%pr::col, 'qs_error_bg', \%HPVALUE) ]
1315 %pr::win = ( # tweak window positions and/or sizes
1320 'int,0,3000', # 0 pixels - 3000 pixels
1328 'int,0,3000', # 0 pixels - 3000 pixels
1336 'int,0,3000', # 0 pixels - 3000 pixels
1344 'int,0,3000', # 0 pixels - 3000 pixels
1349 'mainwin_maximised',
1350 $xl::s{l_win_main_mx},
1351 $xl::s{h_win_main_mx},
1357 'mainwin_fullscreen',
1358 $xl::s{l_win_main_fs},
1359 $xl::s{h_win_main_fs},
1365 'main_messagewin_x',
1368 'int,0,3000', # 0 pixels - 3000 pixels
1373 'main_messagewin_y',
1376 'int,0,3000', # 0 pixels - 3000 pixels
1384 'int,0,3000', # 0 pixels - 3000 pixels
1389 'messagewin_height',
1392 'int,0,3000', # 0 pixels - 3000 pixels
1397 'uriopenerwin_width',
1400 'int,0,3000', # 0 pixels - 3000 pixels
1405 'uriopenerwin_height',
1408 'int,0,3000', # 0 pixels - 3000 pixels
1417 'int,0,3000', # 0 pixels - 3000 pixels
1425 'int,0,3000', # 0 pixels - 3000 pixels
1433 'int,0,3000', # 0 pixels - 3000 pixels
1438 'receivewin_height',
1441 'int,0,3000', # 0 pixels - 3000 pixels
1449 'int,0,3000', # 0 pixels - 3000 pixels
1457 'int,0,3000', # 0 pixels - 3000 pixels
1462 'folderitemwin_width',
1465 'int,0,3000', # 0 pixels - 3000 pixels
1470 'folderitemwin_height',
1473 'int,0,3000', # 0 pixels - 3000 pixels
1478 'folderselwin_width',
1481 'int,0,3000', # 0 pixels - 3000 pixels
1486 'folderselwin_height',
1489 'int,0,3000', # 0 pixels - 3000 pixels
1494 'foldersortwin_width',
1497 'int,0,3000', # 0 pixels - 3000 pixels
1502 'foldersortwin_height',
1505 'int,0,3000', # 0 pixels - 3000 pixels
1514 'int,0,3000', # 0 pixels - 3000 pixels
1522 'int,0,3000', # 0 pixels - 3000 pixels
1527 'addressbookwin_width',
1530 'int,0,3000', # 0 pixels - 3000 pixels
1535 'addressbookwin_height',
1538 'int,0,3000', # 0 pixels - 3000 pixels
1543 'addressbookeditpersonwin_width',
1546 'int,0,3000', # 0 pixels - 3000 pixels
1551 'addressbookeditpersonwin_height',
1554 'int,0,3000', # 0 pixels - 3000 pixels
1559 'addressbookeditgroupwin_width',
1562 'int,0,3000', # 0 pixels - 3000 pixels
1567 'addressbookeditgroupwin_height',
1570 'int,0,3000', # 0 pixels - 3000 pixels
1575 'addressaddwin_width',
1578 'int,0,3000', # 0 pixels - 3000 pixels
1583 'addressaddwin_height',
1586 'int,0,3000', # 0 pixels - 3000 pixels
1591 'addressbook_folderselwin_width',
1594 'int,0,3000', # 0 pixels - 3000 pixels
1599 'addressbook_folderselwin_height',
1602 'int,0,3000', # 0 pixels - 3000 pixels
1607 'editaccountwin_width',
1610 'int,0,3000', # 0 pixels - 3000 pixels
1615 'editaccountwin_height',
1618 'int,0,3000', # 0 pixels - 3000 pixels
1623 'accountswin_width',
1626 'int,0,3000', # 0 pixels - 3000 pixels
1631 'accountswin_height',
1634 'int,0,3000', # 0 pixels - 3000 pixels
1639 'filteringwin_width',
1642 'int,0,3000', # 0 pixels - 3000 pixels
1647 'filteringwin_height',
1650 'int,0,3000', # 0 pixels - 3000 pixels
1655 'filteringactionwin_width',
1658 'int,0,3000', # 0 pixels - 3000 pixels
1663 'filteringactionwin_height',
1666 'int,0,3000', # 0 pixels - 3000 pixels
1671 'filtering_debugwin_width',
1674 'int,0,3000', # 0 pixels - 3000 pixels
1679 'filtering_debugwin_height',
1682 'int,0,3000', # 0 pixels - 3000 pixels
1690 'int,0,3000', # 0 pixels - 3000 pixels
1695 'matcherwin_height',
1698 'int,0,3000', # 0 pixels - 3000 pixels
1706 'int,0,3000', # 0 pixels - 3000 pixels
1714 'int,0,3000', # 0 pixels - 3000 pixels
1719 'templateswin_width',
1722 'int,0,3000', # 0 pixels - 3000 pixels
1727 'templateswin_height',
1730 'int,0,3000', # 0 pixels - 3000 pixels
1738 'int,0,3000', # 0 pixels - 3000 pixels
1743 'actionswin_height',
1746 'int,0,3000', # 0 pixels - 3000 pixels
1751 'actionsiodialog_width',
1754 'int,0,3000', # 0 pixels - 3000 pixels
1759 'actionsiodialog_height',
1762 'int,0,3000', # 0 pixels - 3000 pixels
1770 'int,0,3000', # 0 pixels - 3000 pixels
1778 'int,0,3000', # 0 pixels - 3000 pixels
1786 'int,0,3000', # 0 pixels - 3000 pixels
1794 'int,0,3000', # 0 pixels - 3000 pixels
1802 'int,0,3000', # 0 pixels - 3000 pixels
1807 'pluginswin_height',
1810 'int,0,3000', # 0 pixels - 3000 pixels
1818 'int,0,3000', # 0 pixels - 3000 pixels
1826 'int,0,3000', # 0 pixels - 3000 pixels
1831 'print_previewwin_width',
1834 'int,0,3000', # 0 pixels - 3000 pixels
1839 'print_previewwin_height',
1842 'int,0,3000', # 0 pixels - 3000 pixels
1848 sub new_winpos_subpage_main() {
1849 return new_grid_pack (3, 7, [
1850 [ _('Main window'), undef ],
1851 [ new_text_box_for_int (\%pr::win, 'main_x', \%HPVALUE), undef ],
1852 [ new_text_box_for_int (\%pr::win, 'main_y', \%HPVALUE), undef ],
1853 [ new_text_box_for_int (\%pr::win, 'main_w', \%HPVALUE),
1854 new_text_box_for_int (\%pr::win, 'main_h', \%HPVALUE) ],
1855 [ new_check_button_for (\%pr::win, 'main_fs', \%HPVALUE), undef ],
1856 [ new_check_button_for (\%pr::win, 'main_mx', \%HPVALUE), undef ]
1860 sub new_winpos_subpage_msgs() {
1861 return new_grid_pack (3, 7, [
1862 [ _('Message window') ],
1863 [ new_text_box_for_int (\%pr::win, 'msgs_x', \%HPVALUE) ],
1864 [ new_text_box_for_int (\%pr::win, 'msgs_y', \%HPVALUE) ],
1865 [ new_text_box_for_int (\%pr::win, 'msgs_w', \%HPVALUE),
1866 new_text_box_for_int (\%pr::win, 'msgs_h', \%HPVALUE) ],
1868 [ _('Open URLs window') ],
1869 [ new_text_box_for_int (\%pr::win, 'urio_w', \%HPVALUE),
1870 new_text_box_for_int (\%pr::win, 'urio_h', \%HPVALUE) ]
1874 sub new_winpos_subpage_sendrecv() {
1875 return new_grid_pack (3, 5, [
1876 [ _('Send window') ],
1877 [ new_text_box_for_int (\%pr::win, 'send_w', \%HPVALUE),
1878 new_text_box_for_int (\%pr::win, 'send_h', \%HPVALUE) ],
1880 [ _('Receive window') ],
1881 [ new_text_box_for_int (\%pr::win, 'recv_w', \%HPVALUE),
1882 new_text_box_for_int (\%pr::win, 'recv_h', \%HPVALUE) ]
1886 sub new_winpos_subpage_fold() {
1887 return new_grid_pack (3, 10, [
1888 [ _('Folder window') ],
1889 [ new_text_box_for_int (\%pr::win, 'fold_x', \%HPVALUE) ],
1890 [ new_text_box_for_int (\%pr::win, 'fold_y', \%HPVALUE) ],
1891 [ new_text_box_for_int (\%pr::win, 'fold_w', \%HPVALUE),
1892 new_text_box_for_int (\%pr::win, 'fold_h', \%HPVALUE) ],
1894 [ _('Folder selection window') ],
1895 [ new_text_box_for_int (\%pr::win, 'fsel_w', \%HPVALUE),
1896 new_text_box_for_int (\%pr::win, 'fsel_h', \%HPVALUE) ],
1898 [ _('Folder sorting window') ],
1899 [ new_text_box_for_int (\%pr::win, 'fsor_w', \%HPVALUE),
1900 new_text_box_for_int (\%pr::win, 'fsor_h', \%HPVALUE) ],
1904 sub new_winpos_subpage_addrbook() {
1905 return new_grid_pack (3, 14, [
1906 [ _('Addressbook main window') ],
1907 [ new_text_box_for_int (\%pr::win, 'addr_w', \%HPVALUE),
1908 new_text_box_for_int (\%pr::win, 'addr_h', \%HPVALUE) ],
1910 [ _('Edit person window') ],
1911 [ new_text_box_for_int (\%pr::win, 'adep_w', \%HPVALUE),
1912 new_text_box_for_int (\%pr::win, 'adep_h', \%HPVALUE) ],
1914 [ _('Edit group window') ],
1915 [ new_text_box_for_int (\%pr::win, 'adeg_w', \%HPVALUE),
1916 new_text_box_for_int (\%pr::win, 'adeg_h', \%HPVALUE) ],
1918 [ _('Add address window') ],
1919 [ new_text_box_for_int (\%pr::win, 'adda_w', \%HPVALUE),
1920 new_text_box_for_int (\%pr::win, 'adda_h', \%HPVALUE) ],
1922 [ _('Folder select window') ],
1923 [ new_text_box_for_int (\%pr::win, 'addf_w', \%HPVALUE),
1924 new_text_box_for_int (\%pr::win, 'addf_h', \%HPVALUE) ]
1928 sub new_winpos_subpage_accounts() {
1929 return new_grid_pack (3, 5, [
1930 [ _('Accounts window') ],
1931 [ new_text_box_for_int (\%pr::win, 'acco_w', \%HPVALUE),
1932 new_text_box_for_int (\%pr::win, 'acco_h', \%HPVALUE) ],
1934 [ _('Edit account window') ],
1935 [ new_text_box_for_int (\%pr::win, 'acce_w', \%HPVALUE),
1936 new_text_box_for_int (\%pr::win, 'acce_h', \%HPVALUE) ]
1940 sub new_winpos_subpage_filtering() {
1941 return new_grid_pack (3, 11, [
1942 [ _('Filtering window') ],
1943 [ new_text_box_for_int (\%pr::win, 'filt_w', \%HPVALUE),
1944 new_text_box_for_int (\%pr::win, 'filt_h', \%HPVALUE) ],
1946 [ _('Filtering actions window') ],
1947 [ new_text_box_for_int (\%pr::win, 'fila_w', \%HPVALUE),
1948 new_text_box_for_int (\%pr::win, 'fila_h', \%HPVALUE) ],
1950 [ _('Filtering debug window') ],
1951 [ new_text_box_for_int (\%pr::win, 'fild_w', \%HPVALUE),
1952 new_text_box_for_int (\%pr::win, 'fild_h', \%HPVALUE) ],
1954 [ ('Matcher window') ],
1955 [ new_text_box_for_int (\%pr::win, 'matc_w', \%HPVALUE),
1956 new_text_box_for_int (\%pr::win, 'matc_h', \%HPVALUE) ]
1961 sub new_winpos_subpage_useractions() {
1962 return new_grid_pack (3, 5, [
1963 [ _('User Actions prefs window') ],
1964 [ new_text_box_for_int (\%pr::win, 'acti_w', \%HPVALUE),
1965 new_text_box_for_int (\%pr::win, 'acti_h', \%HPVALUE) ],
1967 [ _('User Actions I/O window') ],
1968 [ new_text_box_for_int (\%pr::win, 'acio_w', \%HPVALUE),
1969 new_text_box_for_int (\%pr::win, 'acio_h', \%HPVALUE) ]
1973 sub new_winpos_subpage_prefs() {
1974 return new_grid_pack (3, 11, [
1975 [ _('Preferences window') ],
1976 [ new_text_box_for_int (\%pr::win, 'pref_w', \%HPVALUE),
1977 new_text_box_for_int (\%pr::win, 'pref_h', \%HPVALUE) ],
1979 [ _('Templates window') ],
1980 [ new_text_box_for_int (\%pr::win, 'temp_w', \%HPVALUE),
1981 new_text_box_for_int (\%pr::win, 'temp_h', \%HPVALUE) ],
1983 [ _('Tags window') ],
1984 [ new_text_box_for_int (\%pr::win, 'tags_w', \%HPVALUE),
1985 new_text_box_for_int (\%pr::win, 'tags_h', \%HPVALUE) ],
1987 [ _('Plugins window') ],
1988 [ new_text_box_for_int (\%pr::win, 'plug_w', \%HPVALUE),
1989 new_text_box_for_int (\%pr::win, 'plug_h', \%HPVALUE) ]
1993 sub new_winpos_subpage_misc() {
1994 return new_grid_pack (4, 11, [
1995 [ _('Log window') ],
1996 [ new_text_box_for_int (\%pr::win, 'logw_w', \%HPVALUE),
1997 new_text_box_for_int (\%pr::win, 'logw_h', \%HPVALUE) ],
1999 [ _('SSL manager') ],
2000 [ new_text_box_for_int (\%pr::win, 'sslman_w', \%HPVALUE),
2001 new_text_box_for_int (\%pr::win, 'sslman_h', \%HPVALUE) ],
2003 [ _('Print preview window') ],
2004 [ new_text_box_for_int (\%pr::win, 'prin_w', \%HPVALUE),
2005 new_text_box_for_int (\%pr::win, 'prin_h', \%HPVALUE) ],
2007 [ _('View source window') ],
2008 [ new_text_box_for_int (\%pr::win, 'sour_w', \%HPVALUE),
2009 new_text_box_for_int (\%pr::win, 'sour_h', \%HPVALUE) ]
2013 sub new_winpos_page() {
2014 my $winbook = Gtk3::Notebook->new;
2015 $winbook->set_tab_pos ('right');
2016 $winbook->append_page (&new_winpos_subpage_main, new_label (_('Main')));
2017 $winbook->append_page (&new_winpos_subpage_msgs, new_label (_('Message')));
2018 $winbook->append_page (&new_winpos_subpage_sendrecv, new_label (_('Send/Receive')));
2019 $winbook->append_page (&new_winpos_subpage_fold, new_label (_('Folder')));
2020 $winbook->append_page (&new_winpos_subpage_addrbook, new_label (_('Addressbook')));
2021 $winbook->append_page (&new_winpos_subpage_accounts, new_label (_('Accounts')));
2022 $winbook->append_page (&new_winpos_subpage_filtering, new_label (_('Filtering')));
2023 $winbook->append_page (&new_winpos_subpage_useractions, new_label (_('User Actions')));
2024 $winbook->append_page (&new_winpos_subpage_prefs, new_label (_('Preferences')));
2025 $winbook->append_page (&new_winpos_subpage_misc, new_label (_('Other')));
2029 %pr::acc = ( # per account hidden preferences
2031 'gnutls_set_priority',
2032 $xl::s{l_acc_gtls_set},
2033 $xl::s{h_acc_gtls_set},
2040 $xl::s{l_acc_gtls_pri},
2041 $xl::s{h_acc_gtls_pri},
2048 $xl::s{l_acc_tls_sni},
2049 $xl::s{h_acc_tls_sni},
2056 sub new_account_subpage($) {
2058 return new_grid_pack (1, 5, [
2059 [ _('GnuTLS priority') ],
2060 [ new_check_button_for (\%pr::acc, 'tls_set', $ACHPVALUE{$akey}) ],
2061 [ new_text_box_for_nchar (\%pr::acc, 'tls_pri', $ACHPVALUE{$akey}) ],
2062 [ _('Server Name Indication') ],
2063 [ new_check_button_for (\%pr::acc, 'tls_sni', $ACHPVALUE{$akey}) ],
2067 sub new_accounts_page() {
2068 my $accbook = Gtk3::Notebook->new;
2069 $accbook->set_tab_pos ('right');
2071 $ACPREFS{$a}{'account_name'} cmp $ACPREFS{$b}{'account_name'}
2074 my $name = $ACPREFS{$_}{'account_name'};
2075 my $isdef = ($ACPREFS{$_}{'is_default'} eq '1');
2076 my $page = new_account_subpage ($_);
2077 my $label = new_label ($isdef? '<u>' . $name . '</u>': $name);
2078 $label->set_use_markup (TRUE);
2079 $accbook->append_page ($page, $label);
2081 $accbook->set_scrollable (TRUE);
2085 %pr::plu = ( # plugins hidden preferences
2091 'int,0,3000', # 0 pixels - 3000 pixels
2100 'int,0,3000', # 0 pixels - 3000 pixels
2107 'autocompletion_limit',
2108 $xl::s{l_plu_gpg_alimit},
2109 $xl::s{h_plu_gpg_alimit},
2117 'manager_win_width',
2120 'int,0,3000', # 0 pixels - 3000 pixels
2126 'manager_win_height',
2129 'int,0,3000', # 0 pixels - 3000 pixels
2137 $xl::s{l_plu_lav_burl},
2138 $xl::s{h_plu_lav_burl},
2141 'http://cdn.libravatar.org/avatar',
2146 $xl::s{l_plu_lav_maxr},
2147 $xl::s{h_plu_lav_maxr},
2155 $xl::s{l_plu_lav_maxrmm},
2156 $xl::s{h_plu_lav_maxrmm},
2163 'max_redirects_url',
2164 $xl::s{l_plu_lav_maxrurl},
2165 $xl::s{h_plu_lav_maxrurl},
2173 'filter_log_verbosity',
2174 $xl::s{l_plu_prl_flvb},
2175 $xl::s{h_plu_prl_flvb},
2176 '0=l_plu_prl_none;1=l_plu_prl_manual;2=l_plu_prl_action;3=l_plu_prl_match',
2183 'console_win_width',
2186 'int,0,3000', # 0 pixels - 3000 pixels
2192 'console_win_height',
2195 'int,0,3000', # 0 pixels - 3000 pixels
2202 sub new_plugins_page() {
2205 new_text_box_for_int (\%pr::plu, 'arm_winw', $PLHPVALUE{'AttRemover'}),
2206 new_text_box_for_int (\%pr::plu, 'arm_winh', $PLHPVALUE{'AttRemover'})
2209 new_text_box_for_int (\%pr::plu, 'gpg_alimit', $PLHPVALUE{'GPG'})
2212 new_text_box_for_int (\%pr::plu, 'msv_winw', $PLHPVALUE{'ManageSieve'}),
2213 new_text_box_for_int (\%pr::plu, 'msv_winh', $PLHPVALUE{'ManageSieve'})
2215 'Libravatar' => [new_grid_pack (2, 4, [
2216 [ new_text_box_for_nchar (\%pr::plu, 'lav_burl', $PLHPVALUE{'Libravatar'}) ],
2217 [ new_text_box_for_int (\%pr::plu, 'lav_maxr', $PLHPVALUE{'Libravatar'}) ],
2218 [ new_text_box_for_int (\%pr::plu, 'lav_maxrmm', $PLHPVALUE{'Libravatar'}) ],
2219 [ new_text_box_for_int (\%pr::plu, 'lav_maxrurl', $PLHPVALUE{'Libravatar'}) ]
2222 new_selection_box_for (\%pr::plu, 'prl_flvb', $PLHPVALUE{'PerlPlugin'})
2225 new_text_box_for_int (\%pr::plu, 'py_consw', $PLHPVALUE{'Python'}),
2226 new_text_box_for_int (\%pr::plu, 'py_consh', $PLHPVALUE{'Python'})
2229 foreach my $pk (@PLUGINS) {
2230 foreach my $wg (@{$widget{$pk}}) {
2231 $wg->set_sensitive (defined $PLHPVALUE{$pk});
2234 return new_grid_pack (3, 18, [
2235 [ _('Attachment remover') ], $widget{'AttRemover'}, [ '--' ],
2236 [ _('GPG') ], $widget{'GPG'}, [ '--' ],
2237 [ _('Sieve manager') ], $widget{'ManageSieve'}, [ '--' ],
2238 [ _('Libravatar') ], $widget{'Libravatar'}, [ '--' ],
2239 [ _('Perl') ], $widget{'PerlPlugin'}, [ '--' ],
2240 [ _('Python console') ], $widget{'Python'}
2244 sub new_hotkeys_list_label {
2245 my $renderer = Gtk3::CellRendererText->new;
2246 $renderer->set_property('alignment' => 'left');
2247 $renderer->set_property('editable' => FALSE);
2251 sub new_hotkeys_list_hotkey {
2252 my $renderer = Gtk3::CellRendererAccel->new;
2253 $renderer->set_property ('accel-mode' => 'gtk');
2254 $renderer->set_property ('editable' => TRUE);
2255 $renderer->signal_connect ('accel-edited' => sub {
2256 my ($w, $path, $key, $mods, $keycode) = @_;
2257 my $accel = Gtk3::accelerator_name ($key, $mods);
2258 my ($model, $iter) = $SELHOTKEY->get_selected ();
2259 $model->set($iter, C_HOTKEY, "\"$accel\"");
2260 my $gkey = $model->get_value ($iter, C_GROUP);
2261 my $akey = $model->get_value ($iter, C_ACCEL);
2262 my $data = $HOTKEYS->{$gkey}->{$akey};
2263 $data->{'key'} = "\"$accel\"";
2264 $data->{'enabled'} = TRUE;
2266 $renderer->signal_connect ('accel-cleared' => sub {
2267 my ($w, $path) = @_;
2268 my ($model, $iter) = $SELHOTKEY->get_selected ();
2269 $model->set($iter, C_HOTKEY, "\"\"");
2270 my $gkey = $model->get_value ($iter, C_GROUP);
2271 my $akey = $model->get_value ($iter, C_ACCEL);
2272 my $data = $HOTKEYS->{$gkey}->{$akey};
2273 $data->{'key'} = "\"\"";
2274 $data->{'enabled'} = FALSE;
2279 sub row_background_color {
2280 my ($column, $isodd) = @_;
2281 my $treeview = $column->get_tree_view;
2282 my $stylectx = $treeview->get_style_context;
2284 ? $stylectx->get_background_color ('normal')
2285 : $stylectx->get_background_color ('insensitive');
2288 sub new_hotkeys_list {
2289 my ($gkey, $group) = @_;
2290 my $store = Gtk3::ListStore->new(
2291 qw/Glib::String Glib::String Glib::String Glib::String Glib::Boolean/);
2293 foreach my $akey (sort keys %$group) {
2294 my $iter = $store->append ();
2295 my $hotkey = $group->{$akey}->{'key'};
2297 $label =~ s/[<>]//g; # <rrsyl> and <IMAPFolder> !?
2298 $store->set ($iter, C_LABEL, $label, C_HOTKEY, $hotkey,
2299 C_GROUP, $gkey, C_ACCEL, $akey, C_ODDITY, $even);
2302 my $treeview = Gtk3::TreeView->new_with_model ($store);
2304 $treeview->insert_column_with_data_func (
2305 0, _("Menu path"), new_hotkeys_list_label (),
2307 my ($col, $renderer, $model, $iter, $data) = @_;
2308 $renderer->set_property (
2309 'markup' => '<span size="smaller">'
2310 . $model->get_value ($iter, C_LABEL)
2312 my $bgcol = row_background_color (
2313 $col, $model->get_value ($iter, C_ODDITY));
2314 $renderer->set_property ('cell-background-rgba' => $bgcol);
2318 $treeview->insert_column_with_data_func (
2319 1, _('Hotkey'), new_hotkeys_list_hotkey (),
2321 my ($col, $renderer, $model, $iter, $data) = @_;
2322 my $hkey = $model->get_value ($iter, C_HOTKEY);
2324 my ($acckey, $accmod) = Gtk3::accelerator_parse ($hkey);
2325 $renderer->set_property ('accel-key' => $acckey);
2326 $renderer->set_property ('accel-mods' => $accmod);
2327 my $bgcol = row_background_color (
2328 $col, $model->get_value ($iter, C_ODDITY));
2329 $renderer->set_property ('cell-background-rgba' => $bgcol);
2332 # callback for saving current selection
2333 my $selection = $treeview->get_selection ();
2334 $selection->signal_connect ('changed' => sub { $SELHOTKEY = shift });
2338 sub new_hotkeys_page() {
2339 my $hkbook = Gtk3::Notebook->new;
2340 $hkbook->set_tab_pos ('right');
2341 foreach my $gkey (sort keys %$HOTKEYS) {
2342 my $group = $HOTKEYS->{$gkey};
2343 my $keylist = new_hotkeys_list ($gkey, $group);
2344 # prepare scrolled window
2345 my $swin = Gtk3::ScrolledWindow->new;
2346 $swin->set_border_width (5);
2347 $swin->set_shadow_type ('none');
2348 $swin->set_policy ('automatic', 'automatic');
2350 $swin->add ($keylist);
2351 $hkbook->append_page ($swin, new_label ($gkey));
2356 sub new_info_page() {
2357 my $v = get_toolkit_versions ();
2358 my $cfgv = $CONFIGDATA->{'Common'}{'config_version'};
2360 return new_grid_pack (4, 11, [
2361 [ _('Library versions') ],
2362 [ new_label ('Perl-GLib'), new_title ($v->{'glib'}) ],
2363 [ new_label (_('GLib runtime')), new_title ($v->{'glib-r'}) ],
2364 [ new_label (_('GLib built')), new_title ($v->{'glib-b'}) ],
2365 [ new_label ('Perl-GTK3'), new_title ($v->{'gtk'}) ],
2366 [ new_label (_('GTK3 runtime')), new_title ($v->{'gtk-r'}) ],
2367 [ new_label (_('GTK3 built')), new_title ($v->{'gtk-b'}) ],
2369 [ _('Claws Mail versions') ],
2370 [ new_label (_('Binary')), new_title ($CLAWSV) ],
2371 [ new_label (_('Configuration')), new_title ($cfgv) ]
2376 sub get_toolkit_versions {
2378 $versions{'glib'} = $Glib::VERSION;
2379 # version info stuff appeared in 1.040
2380 if ($Glib::VERSION >= 1.040) {
2381 $versions{'glib-b'} = join('.', Glib->GET_VERSION_INFO);
2382 $versions{'glib-r'} = join('.',
2383 &Glib::major_version, &Glib::minor_version, &Glib::micro_version);
2385 $versions{'gtk'} = $Gtk3::VERSION;
2386 if ($Gtk3::VERSION >= 0.034) {
2387 $versions{'gtk-b'} = &Gtk3::GET_VERSION_INFO
2389 $versions{'gtk-b'} = _('Not available')
2391 $versions{'gtk-r'} = join('.',
2392 &Gtk3::get_major_version, &Gtk3::get_minor_version, &Gtk3::get_micro_version);
2396 sub print_version() {
2397 say $xl::s{about_title};
2398 say _('Version:') . " $VERSION";
2399 my $v = get_toolkit_versions ();
2400 if ($v->{'glib-b'}) {
2401 say _("Perl-GLib version {glibv}, built for {glibb}, running with {glibr}.",
2402 glibv => $v->{'glib'},
2403 glibb => $v->{'glib-b'},
2404 glibr => $v->{'glib-r'});
2406 say _("Perl-GLib version {glibv}.", glibv => $v->{'glib'});
2408 if ($v->{'gtk-b'}) {
2409 say _("Perl-GTK3 version {gtkv}, built for {gtkb}, running with {gtkr}.",
2410 gtkv => $v->{'gtk'},
2411 gtkb => $v->{'gtk-b'},
2412 gtkr => $v->{'gtk-r'});
2414 say _("Perl-GTK3 version {gtkv}.", gtkv => $v->{'gtk'});
2416 my $clawsver = ($CLAWSV eq "") ?
2417 _("Claws Mail was not found!") :
2418 _("Claws Mail returned version {cmv}.", cmv => $CLAWSV);
2422 # the command line help
2424 my $line = '-' x length ($xl::s{about_title});
2426 say $xl::s{about_title};
2430 _(" clawsker [options]"),
2432 _(" -a|--alternate-config-dir <dir> Uses <dir> as Claws Mail configuration."),
2433 _(" -b|--verbose More messages on standard output."),
2434 _(" -c|--clawsrc <file> Uses <file> as full resource name."),
2435 _(" -h|--help Prints this help screen and exits."),
2436 _(" -i|--ignore-versions Allows setting almost everything."),
2437 _(" -r|--read-only Disables writing changes to disk."),
2438 _(" -u|--use-claws-version <ver> Uses <ver> instead of detected version."),
2439 _(" -v|--version Prints version information and exits.")
2441 foreach (@help) { say $_ }
2444 sub parse_command_line {
2447 $CLAWSV = get_claws_version ();
2449 GetOptionsFromArray($argv,
2450 'h|help' => sub { print_help (); $cont = FALSE },
2451 'v|version' => sub { print_version (); $cont = FALSE },
2452 'b|verbose' => sub { $VERBOSE = TRUE },
2453 'r|read-only' => sub { $READONLY = TRUE },
2454 'i|ignore-versions' => sub { $IGNOREV = TRUE },
2455 'u|use-claws-version=s' => \&opt_use_claws_version,
2456 'a|alternate-config-dir=s' => \&opt_alternate_config_dir,
2457 'c|clawsrc=s' => \&opt_clawsrc)
2458 or die _("try -h or --help for syntax.\n");
2461 my $msg = _("Error in options: {msg}\n", msg => $@);
2462 if (defined $ENV{'DISPLAY'} and $ENV{'DISPLAY'} ne '') {
2463 eval { Gtk3->init };
2464 error_dialog ($msg) unless $@;
2471 sub opt_use_claws_version {
2472 my ($name, $value) = @_;
2473 die _("Error: {opt} requires a dotted numeric value argument\n", opt => $name)
2474 unless ($value =~ /^[\d\.]+$/);
2478 sub opt_alternate_config_dir {
2479 my ($name, $value) = @_;
2480 die _("Error: '{dir}' is not a directory or does not exist\n", dir => $value)
2482 $CONFIGDIR = $value;
2483 $ALTCONFIGDIR = TRUE;
2487 my ($name, $value) = @_;
2488 die _("Error: '{value}' is not a file or does not exist\n", value => $value)
2490 set_rc_filename ($value);
2493 # update the hidden preferences status from loaded values
2494 sub init_hidden_preferences {
2495 foreach my $hash (\%pr::beh, \%pr::col, \%pr::gui, \%pr::oth, \%pr::win) {
2496 foreach my $key (keys %$hash) {
2497 $HPVALUE{${$hash}{$key}[NAME]}[VALUE] = $PREFS{${$hash}{$key}[NAME]};
2498 $HPVALUE{${$hash}{$key}[NAME]}[IVALUE] = $PREFS{${$hash}{$key}[NAME]};
2501 foreach my $akey (keys %ACPREFS) {
2502 foreach my $key (keys %pr::acc) {
2503 my $pname = $pr::acc{$key}[NAME];
2504 $ACHPVALUE{$akey}{$pname}[VALUE] = $ACPREFS{$akey}{$pname};
2505 $ACHPVALUE{$akey}{$pname}[IVALUE] = $ACPREFS{$akey}{$pname};
2508 foreach my $key (keys %pr::plu) {
2509 my $plugin = $pr::plu{$key}[PLUGIN];
2510 my $pname = $pr::plu{$key}[NAME];
2511 if (defined $PLPREFS{$plugin}) {
2512 $PLHPVALUE{$plugin}{$pname}[VALUE] = $PLPREFS{$plugin}{$pname};
2513 $PLHPVALUE{$plugin}{$pname}[IVALUE] = $PLPREFS{$plugin}{$pname};
2519 # generic load/save resource files
2525 open (RCF, '<:encoding(utf8)', $rc)
2526 or die _("Error: opening '{file}' for reading", file => $rc) . ": $!\n";
2527 my $section = '_'; # default unnamed section
2532 if (/^\[([^\]]+)\]$/) { # new section
2534 die _("Error: duplicate section '{sect}' in resource file '{file}'\n",
2535 sect => $section, file => $rc) if ($data{$section});
2536 $data{$section} = {};
2537 $meta{$section}{'#'} = $line;
2539 elsif (/^([0-9a-z_]+)=(.*)$/) { # key=value
2540 $data{$section}{$1} = $2;
2541 $meta{$section}{$1} = $line;
2543 elsif (/^(.*)$/) { # lone value
2544 push (@{$data{$section}{'_'}}, $1);
2548 return (\%data, \%meta);
2552 my ($rc, $data, $meta) = @_;
2553 open (RCF, '>:utf8', $rc)
2554 or die _("Error: opening '{file}' for writing", file => $rc) . ": $!\n";
2555 my @sections = keys %$data;
2556 if (defined $meta) {
2558 $meta->{$a}{'#'} <=> $meta->{$b}{'#'}
2561 foreach my $section (@sections) {
2562 say RCF "[$section]";
2563 if (ref ($data->{$section}{'_'}) eq 'ARRAY') {
2564 foreach my $val (@{$data->{$section}{'_'}}) {
2567 delete $data->{$section}{'_'};
2569 my @keys = keys %{$data->{$section}};
2570 if (defined $meta) {
2572 $meta->{$section}{$a} <=> $meta->{$section}{$b}
2575 foreach my $key (@keys) {
2576 my $val = $data->{$section}{$key};
2577 say RCF "$key=$val";
2584 sub backup_resource {
2586 my $rcbak = "$rc.backup";
2588 my $emsg = _("Unable to create backup file '{name}'\n", name => $rcbak);
2589 log_message ($emsg);
2590 error_dialog ($emsg);
2592 } unless rename ($rc, $rcbak);
2599 open (RCF, '<:encoding(utf8)', $rc)
2600 or die _("Error: opening '{file}' for reading", file => $rc) . ": $!\n";
2605 if (/^; \(gtk_accel_path "<([A-Za-z]+)>([^"]+)" ([^\)]+)\)$/) {
2606 my %data = ('key' => $3, 'enabled' => FALSE, 'line' => $line);
2607 $groups{$1}{$2} = \%data;
2608 # say "group -> $1 | path -> $2 | key -> $3";
2609 } elsif (/^\(gtk_accel_path "<([A-Za-z]+)>([^"]+)" ([^\)]+)\)$/) {
2610 my %data = ('key' => $3, 'enabled' => TRUE, 'line' => $line);
2611 $groups{$1}{$2} = \%data;
2612 # say "group -> $1 | path -> $2 | key -> $3";
2621 my ($rc, $groups) = @_;
2623 foreach my $gkey (keys %$groups) {
2624 my $group = $groups->{$gkey};
2625 foreach my $akey (keys %$group) {
2626 my $data = $group->{$akey};
2627 my $key = $data->{'key'};
2628 my $line = $data->{'line'};
2629 $lines[$line] = ($data->{'enabled'})? '': '; ';
2630 $lines[$line] .= '(gtk_accel_path "<'
2631 . $gkey . '>' . $akey . '" ' . $key . ')';
2634 open (RCF, '>:utf8', $rc)
2635 or die _("Error: opening '{file}' for writing", file => $rc) . ": $!\n";
2636 say RCF '; claws-mail GtkAccelMap rc-file -*- scheme -*-';
2637 say RCF '; this file is an automated accelerator map dump';
2639 foreach (@lines) { say RCF $_ if $_ }
2643 # load current status from disc
2644 sub load_rc_preferences {
2645 my $rc = get_rc_filename ();
2646 log_message ("Loading preferences from $rc\n");
2647 return FALSE unless check_rc_file ($rc);
2648 ($CONFIGDATA, $CONFIGMETA) = load_resource ($rc);
2649 foreach (keys %{$CONFIGDATA->{'Common'}}) {
2650 $PREFS{$_} = $CONFIGDATA->{'Common'}{$_};
2652 foreach my $plugin (@PLUGINS) {
2653 if (defined $CONFIGDATA->{$plugin}) {
2654 push (@AVPLUGINS, $plugin);
2655 foreach (keys %{$CONFIGDATA->{$plugin}}) {
2656 $PLPREFS{$plugin}{$_} = $CONFIGDATA->{$plugin}{$_};
2663 sub load_ac_preferences {
2664 my $rc = get_ac_rc_filename ();
2665 log_message ("Loading account preferences from $rc\n");
2666 return FALSE unless check_rc_file ($rc);
2667 ($ACCOUNTDATA, $ACCOUNTMETA) = load_resource ($rc);
2668 foreach my $asect (keys %$ACCOUNTDATA) {
2669 if ($asect =~ /^Account: (\d+)$/) {
2670 foreach (keys %{$ACCOUNTDATA->{$asect}}) {
2671 $ACPREFS{$1}{$_} = $ACCOUNTDATA->{$asect}{$_};
2678 sub load_hk_preferences {
2679 my $rc = get_menurc_filename ();
2680 return FALSE unless check_rc_file ($rc);
2681 $HOTKEYS = load_menurc ($rc);
2685 sub load_preferences {
2686 return FALSE unless check_claws_not_running ();
2687 return (load_rc_preferences ()
2688 and load_ac_preferences ()
2689 and load_hk_preferences ()
2693 # save current preferences to disc
2694 sub save_rc_preferences {
2695 my $rc = get_rc_filename ();
2696 log_message ("Saving preferences to $rc\n");
2697 return FALSE unless check_rc_file ($rc);
2698 return FALSE unless backup_resource ($rc);
2699 foreach (keys %PREFS) {
2700 if (defined $HPVALUE{$_}) {
2701 $CONFIGDATA->{'Common'}{$_} = $HPVALUE{$_}[VALUE];
2704 foreach my $plugin (@AVPLUGINS) {
2705 foreach (keys %{$CONFIGDATA->{$plugin}}) {
2706 if (defined $PLHPVALUE{$plugin}{$_}) {
2707 $CONFIGDATA->{$plugin}{$_} = $PLHPVALUE{$plugin}{$_}[VALUE];
2711 save_resource ($rc, $CONFIGDATA, $CONFIGMETA);
2715 sub save_ac_preferences {
2716 my $rc = get_ac_rc_filename ();
2717 log_message ("Saving account preferences to $rc\n");
2718 return FALSE unless check_rc_file ($rc);
2719 return FALSE unless backup_resource ($rc);
2720 foreach my $asect (keys %$ACCOUNTDATA) {
2721 if ($asect =~ /^Account: (\d+)$/) {
2722 foreach (keys %{$ACCOUNTDATA->{$asect}}) {
2723 if (defined $ACHPVALUE{$1}{$_}) {
2724 $ACCOUNTDATA->{$asect}{$_} = $ACHPVALUE{$1}{$_}[VALUE];
2729 save_resource ($rc, $ACCOUNTDATA, $ACCOUNTMETA);
2733 sub save_hk_preferences {
2734 my $rc = get_menurc_filename ();
2735 log_message ("Saving hotkey preferences to $rc\n");
2736 return FALSE unless check_rc_file ($rc);
2737 return FALSE unless backup_resource ($rc);
2738 save_menurc ($rc, $HOTKEYS);
2742 sub save_preferences {
2743 return FALSE unless check_claws_not_running ();
2744 my $result = save_rc_preferences ()
2745 and save_ac_preferences ()
2746 and save_hk_preferences ();
2747 $MODIFIED = 0 if $result;
2753 my $nb = Gtk3::Notebook->new;
2755 $nb->append_page (&new_behaviour_page, Gtk3::Label->new (_('Behaviour')));
2756 $nb->append_page (&new_colours_page, Gtk3::Label->new (_('Colours')));
2757 $nb->append_page (&new_gui_page, Gtk3::Label->new (_('GUI')));
2758 $nb->append_page (&new_other_page, Gtk3::Label->new (_('Other')));
2759 $nb->append_page (&new_winpos_page, Gtk3::Label->new (_('Windows')));
2760 $nb->append_page (&new_accounts_page, Gtk3::Label->new (_('Accounts')));
2761 $nb->append_page (&new_plugins_page, Gtk3::Label->new (_('Plugins')));
2762 $nb->append_page (&new_hotkeys_page, Gtk3::Label->new (_('Hotkeys')));
2763 $nb->append_page (&new_info_page, Gtk3::Label->new (_('Info')));
2768 # create an about dialog
2769 sub new_about_dialog {
2771 my $year = '2007-2021';
2772 my $holder = 'Ricardo Mones <ricardo@mones.org>';
2773 my $url = 'http://www.claws-mail.org/clawsker.php';
2774 my $icons = &get_app_icons;
2776 my $dialog = Gtk3::AboutDialog->new;
2777 $dialog->set_transient_for ($parent);
2778 $dialog->set_program_name ('Clawsker');
2779 $dialog->set_version ($VERSION);
2780 $dialog->set_copyright ("Copyright © $year $holder");
2781 $dialog->set_license_type ('gpl-3-0');
2782 $dialog->set_website ($url);
2783 $dialog->set_website_label (_("Visit Clawsker's web page"));
2784 # committers, by number of commits
2785 $dialog->set_authors ([
2787 'Tristan Chabredier (wwp) <subscript@free.fr>',
2788 'Andreas Rönnquist <andreas@ronnquist.net>',
2789 'Christian Hesse <mail@eworm.de>',
2791 $dialog->set_artists ([
2792 'Jesper Schultz <jesper@schultz-net.dk>',
2795 $dialog->set_documenters ([
2797 'Paul Mangan <paul@claws-mail.org>',
2799 # active translators, in alphabetical order
2800 $dialog->set_translator_credits (join ("\n",
2801 'Andreas Rönnquist <andreas@ronnquist.net>',
2802 'Axel Köllhofer <AxelKoellhofer@web.de>',
2803 'David Medina <opensusecatala@gmail.com>',
2804 'Erik P. Olsen <erik@epo.dk>',
2805 'Frederico Goncalves Guimaraes <frederico@teia.bio.br>',
2806 'Marcel Pol <marcel@timelord.nl>',
2807 'Mark Chang <mark.cyj@gmail.com>',
2808 'M. Sulchan Darmawan <bleketux@gmail.com>',
2809 'Numan Demirdöğen <if.gnu.linux@gmail.com>',
2810 'Pedro Albuquerque <pmra@gmx.com>',
2811 'Petter Adsen <petter@synth.no>',
2813 'Tristan Chabredier (wwp) <subscript@free.fr>',
2815 $dialog->set_title ($xl::s{about_title});
2816 $dialog->set_logo ($icons->[-1]);
2823 if ($MODIFIED != 0 and not $READONLY) {
2824 my $markup = "<span>" . _('There are unapplied modifications.')
2825 . "</span>\n\n<span weight=\"bold\">"
2826 . _('Do you really want to quit?') . "</span>\n";
2827 my $dialog = message_dialog (
2828 $parent, _('Clawsker warning'), $markup, 'question',
2829 [ 'gtk-no', 1, 'gtk-yes', 0 ]
2831 my $resp = $dialog->run;
2833 return TRUE if $resp;
2838 # create buttons box
2839 sub new_button_box {
2840 my ($parent, $adlg) = @_;
2841 my $b_about = Gtk3::Button->new_from_stock ('gtk-about');
2842 my $b_exit = Gtk3::Button->new_from_stock ('gtk-quit');
2843 my $b_apply = Gtk3::Button->new_from_stock ('gtk-apply');
2844 # disable button until is really implemented
2845 # my $b_undo = Gtk3::Button->new_from_stock ('gtk-undo');
2846 my $hbox = Gtk3::HBox->new (FALSE, 5);
2848 $b_exit->signal_connect (clicked => sub { exit_handler($parent) });
2849 $b_apply->set_sensitive (not $READONLY);
2850 $b_apply->signal_connect (clicked => sub { save_preferences($parent) });
2851 # $b_undo->signal_connect (clicked => sub { undo_current_changes });
2852 $b_about->signal_connect (clicked => sub { $adlg->run; $adlg->hide });
2854 $hbox->pack_end ($b_apply, FALSE, FALSE, 0);
2855 $hbox->pack_end ($b_exit, FALSE, FALSE, 0);
2856 # $hbox->pack_end ($b_undo, FALSE, FALSE, 0);
2857 $hbox->pack_start ($b_about, FALSE, FALSE, 0);
2863 return \@APPICONS if (@APPICONS);
2865 if (-d $DATADIR) { # installed
2866 my $dir = catdir ($DATADIR, 'icons', 'hicolor');
2868 catfile ($dir, $_ . 'x' . $_, 'apps', $NAME . '.png')
2870 } else { # unpacked tarball or git clone
2872 catfile ('.', 'icons', $NAME . '-' . $_ . '.png');
2877 $icon = Gtk3::Gdk::Pixbuf->new_from_file($_) if (-f $_);
2878 push @APPICONS, $icon if ($icon);
2883 sub escape_key_handler {
2884 my ($widget, $event) = @_;
2885 if ($event->keyval == Gtk3::Gdk::keyval_from_name('Escape')) {
2886 exit_handler($widget);
2892 exit unless parse_command_line ($args);
2894 $main_window = Gtk3::Window->new ('toplevel');
2895 exit unless load_preferences ();
2896 exit unless init_hidden_preferences ();
2898 my $box = Gtk3::VBox->new (FALSE, 5);
2899 $box->set_border_width(3);
2900 my $about = new_about_dialog ($main_window);
2901 $box->pack_start (new_notebook (), TRUE, TRUE, 0);
2902 $box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
2903 $main_window->signal_connect (delete_event => sub { exit_handler($main_window) });
2904 $main_window->signal_connect (key_press_event => \&escape_key_handler);
2905 $main_window->set_title (_('Claws Mail Hidden Preferences'));
2906 $main_window->set_icon_list (get_app_icons ());
2907 $main_window->add ($box);
2908 $main_window->show_all;
2914 exit Clawsker::main(\@ARGV) unless caller;