3 # Clawsker :: A Claws Mail Tweaker
4 # Copyright 2007-2018 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.
15 binmode STDOUT, ":encoding(utf8)";
21 use Glib qw(TRUE FALSE);
23 use POSIX qw(setlocale);
26 use Digest::MD5 qw(md5_hex);
29 my $NAME = 'clawsker';
30 my $PREFIX = '@PREFIX@';
31 my $LIBDIR = '@LIBDIR@';
32 my $DATADIR = '@DATADIR@';
33 my $VERSION = '@VERSION@';
37 my $main_window = undef;
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));
48 my $xla = gettext ($str);
49 if (scalar(keys(%par)) > 0) {
50 foreach my $key (keys %par) {
51 $xla =~ s/\{$key\}/$par{$key}/g;
54 return decode_utf8($xla);
59 win_title => _('Claws Mail Hidden Preferences'),
60 about_title => _('Clawsker :: A Claws Mail Tweaker'),
61 about_web_label => _("Visit Clawsker's web page"),
63 error_title => _('Clawsker error'),
65 exit_title => _('Clawsker warning'),
66 exit_fact => _('There are unapplied modifications.'),
67 exit_question => _('Do you really want to quit?'),
69 tab_colours => _('Colours'),
70 tab_behaviour => _('Behaviour'),
72 tab_other => _('Other'),
73 tab_winpos => _('Windows'),
74 tab_accounts => _('Accounts'),
75 tab_plugins => _('Plugins'),
76 tab_hotkeys => _('Hotkeys'),
77 tab_info => _('Info'),
79 ab_frame => _('Addressbook'),
80 mem_frame => _('Memory'),
81 msgview_frame => _('Message View'),
82 log_frame => _('Log window'),
83 dnd_frame => _('Drag \'n\' drop'),
84 ssl_frame => _('Secure Sockets Layer'),
85 msgs_frame => _('Messages'),
86 swc_frame => _('Completion'),
87 stripes_frame => _('Coloured stripes'),
88 sbar_frame => _('Scroll bars'),
89 mlist_frame => _('Message List'),
90 mview_frame => _('Message View'),
91 compo_frame => _('Compose window'),
92 netm_frame => _('NetworkManager'),
93 diff_frame => _('Viewing patches'),
94 mpass_frame => _('Master passphrase'),
95 compose_frame => _('Compose window'),
96 qs_frame => _('Quick search'),
98 l_oth_use_dlg => _('Use detached address book edit dialogue'),
99 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.'),
100 l_oth_max_use => _('Maximum memory for message cache'),
101 l_oth_max_use_units => _('kilobytes'),
102 h_oth_max_use => _('The maximum amount of memory to use to cache messages, in kilobytes.'),
103 l_oth_min_time => _('Minimun time for cache elements'),
104 l_oth_min_time_units => _('minutes'),
105 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.'),
106 l_oth_use_netm => _('Use NetworkManager'),
107 h_oth_use_netm => _('Use NetworkManager to switch offline automatically.'),
108 l_oth_mp_rounds => _('Rounds for PBKDF2 function'),
109 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.'),
111 l_gui_b_unread => _('Show unread messages with bold font'),
112 h_gui_b_unread => _('Show unread messages in the Message List using a bold font.'),
113 l_gui_no_markup => _('Don\'t use markup'),
114 h_gui_no_markup => _('Don\'t use bold and italic text in Compose dialogue\'s account selector.'),
115 l_gui_dot_lines => _('Use dotted lines in tree view components'),
116 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.'),
117 l_gui_h_scroll => _('Enable horizontal scrollbar'),
118 h_gui_h_scroll => _('Enable the horizontal scrollbar in the Message List.'),
119 l_gui_swp_from => _('Display To column instead From column in Sent folder'),
120 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.'),
121 l_gui_v_scroll => _('Folder List scrollbar behaviour'),
122 h_gui_v_scroll => _('Specify the policy of vertical scrollbar of Folder List: show always, automatic or hide always.'),
123 l_gui_v_scroll_show => _('Show always'),
124 l_gui_v_scroll_auto => _('Automatic'),
125 l_gui_v_scroll_hide => _('Hide always'),
126 l_gui_from_show => _('From column displays'),
127 h_gui_from_show => _('Selects the data displayed in the From column of the Message List: name, address or both.'),
128 l_gui_from_show_name => _('Name only'),
129 l_gui_from_show_addr => _('Address only'),
130 l_gui_from_show_both => _('Both name and address'),
131 l_gui_strip_off => _('Coloured lines contrast'),
132 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.'),
133 l_gui_cursor_v => _('Show cursor'),
134 h_gui_cursor_v => _('Display the cursor in the Message View.'),
135 l_gui_toolbar_d => _('Detachable toolbars'),
136 h_gui_toolbar_d => _('Show handles in the toolbars.'),
137 l_gui_strip_all => _('Use stripes in all tree view components'),
138 h_gui_strip_all => _('Enable alternately coloured lines in all tree view components.'),
139 l_gui_strip_sum => _('Use stripes in Folder List and Message List'),
140 h_gui_strip_sum => _('Enable alternately coloured lines in Message List and Folder List.'),
141 l_gui_two_line_v => _('2 lines per Message List item in 3-column layout'),
142 h_gui_two_line_v => _('Spread Message List information over two lines when using the three column mode.'),
143 l_gui_margin_co => _('Show margin'),
144 h_gui_margin_co => _('Shows a small margin in the Compose View.'),
145 l_gui_mview_date => _('Don\'t display localized date'),
146 h_gui_mview_date => _('Toggles localization of date format in Message View.'),
147 l_gui_zero_char => _('Zero replacement character'),
148 h_gui_zero_char => _('Replaces \'0\' with the given character in Folder List.'),
149 l_gui_type_any => _('Editable headers'),
150 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.'),
151 l_gui_warn_send_multi => _('Warn when sending to more than'),
152 l_gui_warn_send_multi_units => _('recipients'),
153 h_gui_warn_send_multi => _('Show a warning dialogue when sending to more recipients than specified. Use 0 to disable this check.'),
154 l_gui_next_del => _('Select next message on delete'),
155 h_gui_next_del => _('When deleting a message, toggles between selecting the next one (newer message) or the previous one (older message).'),
157 l_beh_hover_t => _('Drag \'n\' drop hover timeout'),
158 l_beh_hover_t_units => _('milliseconds'),
159 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.'),
160 l_beh_dangerous => _('Don\'t confirm deletions (dangerous!)'),
161 h_beh_dangerous => _('Don\'t ask for confirmation before definitive deletion of emails.'),
162 l_beh_flowed => _('Respect format=flowed in messages'),
163 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.'),
164 l_beh_parts_rw => _('Allow writable temporary files'),
165 h_beh_parts_rw => _('Saves temporary files when opening attachment with write bit set.'),
166 l_beh_skip_ssl => _('Don\'t check SSL certificates'),
167 h_beh_skip_ssl => _('Disables the verification of SSL certificates.'),
168 l_beh_up_step => _('Progress bar update step every'),
169 l_beh_up_step_units => _('items'),
170 h_beh_up_step => _('Update stepping in progress bars.'),
171 l_beh_thread_a => _('Maximum age when threading by subject'),
172 l_beh_thread_a_units => _('days'),
173 h_beh_thread_a => _('Number of days to include a message in a thread when using "Thread using subject in addition to standard headers".'),
174 l_beh_unsafe_ssl => _('Allow unsafe SSL certificates'),
175 h_beh_unsafe_ssl => _('Allows Claws Mail to remember multiple SSL certificates for a given server/port.'),
176 l_beh_use_utf8 => _('Force UTF-8 for broken mails'),
177 h_beh_use_utf8 => _('Use UTF-8 encoding for broken mails instead of current locale.'),
178 l_beh_warn_dnd => _('Warn on drag \'n\' drop'),
179 h_beh_warn_dnd => _('Display a confirmation dialogue on drag \'n\' drop of folders.'),
180 l_beh_out_ascii => _('Outgoing messages fallback to ASCII'),
181 h_beh_out_ascii => _('If allowed by content, ASCII will be used to encode outgoing messages, otherwise the user-defined encoding is always enforced.'),
182 l_beh_pp_unsel => _('Primary paste unselects selection'),
183 h_beh_pp_unsel => _('Controls how pasting using middle-click changes the selected text and insertion point.'),
184 l_beh_inline_at => _('Show inline attachments'),
185 h_beh_inline_at => _('Allows to hide inline attachments already shown in mail structure view.'),
186 l_beh_addr_swc => _('Address search in compose window matches any'),
187 h_beh_addr_swc => _('On Tab-key completion, address text will match any part of the string or only from the start.'),
188 l_beh_fold_swc => _('Folder search in folder selector matches any'),
189 h_beh_fold_swc => _('On folder name completion text will match any part of the string or only from the start.'),
190 l_beh_rewrite_ff => _('Rewrite first \'From\' using QP encoding'),
191 h_beh_rewrite_ff => _('Workaround some servers which convert first \'From\' to \'>From\' by using Quoted-Printable transfer encoding instead of 7bit/8bit encoding.'),
193 l_col_emphasis => _('X-Mailer header'),
194 h_col_emphasis => _('The colour used for the X-Mailer line when its value is Claws Mail.'),
195 l_col_log_err => _('Error messages'),
196 h_col_log_err => _('Colour for error messages in log window.'),
197 l_col_log_in => _('Server messages'),
198 h_col_log_in => _('Colour for messages received from servers in log window.'),
199 l_col_log_msg => _('Standard messages'),
200 h_col_log_msg => _('Colour for messages in log window.'),
201 l_col_log_out => _('Client messages'),
202 h_col_log_out => _('Colour for messages sent to servers in log window.'),
203 l_col_log_warn => _('Warning messages'),
204 h_col_log_warn => _('Colour for warning messages in log window.'),
206 l_col_tags_bg => _('Tags background'),
207 h_col_tags_bg => _('Background colour for tags in message view.'),
208 l_col_tags_text => _('Tags text'),
209 h_col_tags_text => _('Text colour for tags in message view.'),
211 l_col_default_header_bg => _('Default headers background'),
212 h_col_default_header_bg => _('Background colour for default headers in compose window.'),
213 l_col_default_header_text => _('Default headers text'),
214 h_col_default_header_text => _('Text colour for default headers in compose window.'),
216 l_col_qs_active_bg => _('Active quick search background'),
217 h_col_qs_active_bg => _('Background colour for active quick search.'),
218 l_col_qs_active_text => _('Active quick search text'),
219 h_col_qs_active_text => _('Text colour for active quick search.'),
220 l_col_qs_error_bg => _('Quick search error background'),
221 h_col_qs_error_bg => _('Background colour for quick search error.'),
222 l_col_qs_error_text => _('Quick search error text'),
223 h_col_qs_error_text => _('Text colour for quick search error.'),
225 l_col_diff_add => _('Added lines'),
226 h_col_diff_add => _('Colour for added lines in patches.'),
227 l_col_diff_del => _('Deleted lines'),
228 h_col_diff_del => _('Colour for deleted lines in patches.'),
229 l_col_diff_hunk => _('Hunk lines'),
230 h_col_diff_hunk => _('Colour for hunk headers in patches.'),
232 l_win_x => _('X position'),
233 h_win_x => _('X coordinate for window\'s top-left corner.'),
234 l_win_y => _('Y position'),
235 h_win_y => _('Y coordinate for window\'s top-left corner.'),
236 l_win_w => _('Width'),
237 h_win_w => _('Window\'s width in pixels.'),
238 l_win_h => _('Height'),
239 h_win_h => _('Window\'s height in pixels.'),
241 l_win_main_mx => _('Maximized'),
242 h_win_main_mx => _('Changes window maximized status.'),
243 l_win_main_fs => _('Full-screen'),
244 h_win_main_fs => _('Changes full screen status.'),
246 l_acc_gtls_set => _('Use custom GnuTLS priority'),
247 h_acc_gtls_set => _('Enables using user provided GnuTLS priority string.'),
248 l_acc_gtls_pri => _('GnuTLS priority'),
249 h_acc_gtls_pri => _('Value to use as GnuTLS priority string if custom priority check is enabled. Otherwise this value is ignored.'),
251 l_plu_gpg_alimit => _('Autocompletion limit'),
252 h_plu_gpg_alimit => _('Limits the number of addresses obtained from keyring through autocompletion. Use 0 to get all matches.'),
253 l_plu_lav_burl => _('Base URL'),
254 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.'),
255 l_plu_prl_flvb => _('Log level'),
256 h_plu_prl_flvb => _('Verbosity level of log, accumulative.'),
257 l_plu_prl_none => _('None'),
258 l_plu_prl_manual => _('Manual'),
259 l_plu_prl_action => _('Actions'),
260 l_plu_prl_match => _('Matches'),
263 # data and metadata of resource files
268 # all preferences read by load_preferences
272 # values of all preferences handled by clawsker
276 # default config dir and file name
277 my $ALTCONFIGDIR = FALSE;
278 my $CONFIGDIR = $ENV{HOME} . '/.claws-mail/';
279 my $CONFIGRC = 'clawsrc';
280 my $ACCOUNTRC = 'accountrc';
281 # supported and available plugins lists
282 my @PLUGINS = qw(AttRemover GPG ManageSieve Libravatar PerlPlugin);
284 # loaded hotkeys from load_menurc
286 # current tree selection
293 # index constants for preference arrays
294 use constant NAME => 0; # the name on the rc file
295 use constant LABEL => 1; # the label on the GUI
296 use constant DESC => 2; # the description for the hint/help
297 use constant TYPE => 3; # data type: bool, int, float, string, color
298 use constant CMVER => 4; # lowest[,highest] Claws Mail version(s) the feature exists
299 use constant CMDEF => 5; # default value for the preference in Claws Mail
300 use constant PLUGIN => 6; # plugin section (only in plugin preferences)
302 # constants for GUI spacing
303 use constant HBOX_PAD => 5;
304 use constant FRAME_SPC => 2;
305 use constant PAGE_SPC => 5;
307 # for data references indexing
308 use constant VALUE => 0;
309 use constant IVALUE => 1;
313 sub version_greater_or_equal {
314 my ($version, $refvers) = @_;
315 return TRUE if (length($version) == 0 and length($refvers) >= 0);
316 return FALSE if (length($version) >= 0 and length($refvers) == 0);
317 return TRUE if (version->parse($version) >= version->parse($refvers));
321 sub get_claws_version {
322 $_ = qx/which claws-mail/;
324 return "" unless ($_); # not installed
328 my @fver = split (/ /);
329 die "Invalid version string" unless ($fver[2] eq "version");
330 my @ver = split (/\./, $fver[3]);
333 if ($ver[2] =~ /(\d+)git(\d+)/) {
342 # data handlers and auxiliar functions
344 sub handle_bool_value {
345 my ($widget, $event, $dataref) = @_;
346 $$dataref->[VALUE] = ($widget->get_active ())? '1': '0';
347 $MODIFIED += $$dataref->[VALUE] != $$dataref->[IVALUE]? 1: -1
348 if defined $$dataref->[IVALUE];
351 sub handle_int_value {
352 my ($widget, $event, $dataref) = @_;
353 $_ = $widget->get_text ();
357 $$dataref->[VALUE] = $_;
358 $widget->set_text ($_);
361 $widget->set_text ($$dataref->[VALUE]);
363 $MODIFIED += $$dataref->[VALUE] != $$dataref->[IVALUE]? 1: -1
364 if defined $$dataref->[IVALUE];
367 sub handle_string_value {
368 my ($widget, $event, $dataref) = @_;
369 $$dataref->[VALUE] = $widget->get_text ();
370 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
371 if defined $$dataref->[IVALUE];
374 sub handle_nchar_value {
375 my ($widget, $event, $dataref, $minlen, $maxlen) = @_;
376 $_ = substr ($widget->get_text (), 0, $maxlen);
377 $widget->set_text ($_);
378 $$dataref->[VALUE] = $_;
379 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
380 if defined $$dataref->[IVALUE];
383 sub gdk_rgba_from_str {
385 my ($rr, $gg, $bb) = (0, 0 ,0);
387 if (/\#([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])/) {
392 my $color = Gtk3::Gdk::RGBA->new ($rr, $gg, $bb, 1.0);
396 sub str_from_gdk_rgba {
398 my $rr = $color->red * 256;
399 my $gg = $color->green * 256;
400 my $bb = $color->blue * 256;
401 my $str = sprintf ("#%.2x%.2x%.2x", $rr, $gg, $bb);
405 sub handle_color_value {
406 my ($widget, $event, $dataref) = @_;
407 my $newcol = $widget->get_rgba;
408 $$dataref->[VALUE] = str_from_gdk_rgba ($newcol);
409 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
410 if defined $$dataref->[IVALUE];
413 sub handle_selection_value {
414 my ($widget, $event, $dataref) = @_;
415 $$dataref->[VALUE] = $widget->get_active;
416 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
417 if defined $$dataref->[IVALUE];
420 sub get_rc_filename {
421 return $CONFIGDIR . $CONFIGRC;
424 sub get_ac_rc_filename {
425 return $CONFIGDIR . $ACCOUNTRC;
428 sub get_menurc_filename {
429 return $CONFIGDIR . "menurc";
432 sub set_rc_filename {
434 my @parts = split ('/', $fullname);
435 $CONFIGRC = $parts[$#parts];
436 $parts[$#parts] = '';
437 $CONFIGDIR = join ('/', @parts);
441 my ($mesg, $fatal) = @_;
442 if (defined($fatal) && $fatal eq 'die') {
443 die "$NAME: $mesg\n";
446 print "$NAME: $mesg\n";
451 my ($parent, $title, $markup, $type, $buttons) = @_;
452 my $flags = [qw/modal destroy-with-parent/];
453 my $dialog = Gtk3::Dialog->new_with_buttons (
454 $title, $parent, $flags, @$buttons
456 my $label = Gtk3::Label->new;
457 $label->set_markup ($markup);
459 if ($type eq 'error') {
460 $icon = Gtk3::Image->new_from_icon_name('dialog-error', 'GTK_ICON_SIZE_DIALOG');
461 } elsif ($type eq 'warning') {
462 $icon = Gtk3::Image->new_from_icon_name('dialog-warning', 'GTK_ICON_SIZE_DIALOG');
463 } elsif ($type eq 'question') {
464 $icon = Gtk3::Image->new_from_icon_name('dialog-question', 'GTK_ICON_SIZE_DIALOG');
466 my $hbox = Gtk3::Box->new ('horizontal', 5);
467 $hbox->pack_start ($icon, FALSE, FALSE, 5) if defined $icon;
468 $hbox->pack_start ($label, FALSE, FALSE, 5);
469 my $dialogbox = $dialog->get_content_area;
470 $dialogbox->add ($hbox);
471 $dialogbox->show_all;
477 my $markup = "<span weight=\"bold\" size=\"large\">" . $emsg . "</span>";
478 my $errordlg = message_dialog (
479 $main_window, $xl::s{error_title}, $markup, 'error', [ 'gtk-cancel', 0 ]
485 sub claws_is_running {
486 my $emsg = _('Error: seems Claws Mail is currently running, close it first.');
488 error_dialog ($emsg);
492 sub check_claws_not_running {
493 return TRUE if $READONLY;
494 my $tmpdir = (defined $ENV{TMPDIR})? $ENV{TMPDIR}: '/tmp';
495 $tmpdir = '/tmp' if ($tmpdir eq '');
496 my $lockdir = "$tmpdir/claws-mail-$<";
500 my $socket = "$lockdir/" . md5_hex ($_);
501 -S $socket and return claws_is_running ();
508 (defined($rcfile) && -f $rcfile) or do {
509 my $emsg = _('Error: resource file for Claws Mail was not found.');
511 error_dialog ($emsg);
517 sub set_widget_hint {
518 my ($wdgt, $hint) = @_;
519 $wdgt->set_tooltip_text ($hint);
520 $wdgt->set_has_tooltip (TRUE);
523 sub set_widget_sens {
524 my ($wdgt, $versions) = @_;
525 my @ver = split(/,/, $versions);
527 $wdgt->set_sensitive (
528 version_greater_or_equal ($CLAWSV, $ver[0])
529 and version_greater_or_equal ($ver[1], $CLAWSV)
532 $wdgt->set_sensitive (version_greater_or_equal ($CLAWSV, $ver[0]));
536 # graphic element creation
538 sub new_hbox_spaced_pack {
539 my $hbox = Gtk3::HBox->new (FALSE);
541 $hbox->pack_start ($_, FALSE, FALSE, HBOX_PAD);
546 sub new_check_button_for($$$) {
547 my ($hash, $key, $vhash) = @_;
548 my $name = $$hash{$key}[NAME];
549 my $label = $$hash{$key}[LABEL];
551 my $cb = Gtk3::CheckButton->new ($label);
552 my $value = $$vhash{$name}[VALUE];
553 $value //= $$hash{$key}[CMDEF];
554 $cb->set_active ($value eq '1');
555 $cb->signal_connect (clicked => sub {
557 handle_bool_value ($w, $e, \$$vhash{$name});
559 set_widget_hint ($cb, $$hash{$key}[DESC]);
560 set_widget_sens ($cb, $$hash{$key}[CMVER]);
562 return new_hbox_spaced_pack ($cb);
565 sub new_text_box_for_int($$$) {
566 my ($hash, $key, $vhash) = @_;
567 my $name = $$hash{$key}[NAME];
568 my $label = $$hash{$key}[LABEL];
569 my @type = split (/,/, $$hash{$key}[TYPE]);
570 push (@type, 0), push (@type, 10000) unless ($#type > 0);
573 if (ref $label eq 'ARRAY') {
574 $gunits = Gtk3::Label->new ($label->[1]);
575 $label = $label->[0];
577 my $glabel = Gtk3::Label->new ($label);
578 my $pagei = int (($type[2] - $type[1]) / 10);
579 my $gentry = Gtk3::SpinButton->new_with_range ($type[1], $type[2], $pagei);
580 my $value = $$vhash{$name}[VALUE];
581 $value //= $$hash{$key}[CMDEF];
582 $gentry->set_numeric (TRUE);
583 $gentry->set_value ($value);
584 $gentry->signal_connect('value-changed' => sub {
586 handle_int_value ($w, $e, \$$vhash{$name});
588 set_widget_hint ($gentry, $$hash{$key}[DESC]);
589 set_widget_sens ($gentry, $$hash{$key}[CMVER]);
590 $glabel->set_sensitive ($gentry->get_sensitive);
591 $gunits->set_sensitive ($gentry->get_sensitive) if ($gunits);
593 return new_hbox_spaced_pack ($glabel, $gentry, $gunits) if ($gunits);
594 return new_hbox_spaced_pack ($glabel, $gentry);
597 sub new_text_box_for_nchar($$$) {
598 my ($hash, $key, $vhash) = @_;
599 my $name = $$hash{$key}[NAME];
600 my $label = $$hash{$key}[LABEL];
601 my @type = split (/,/, $$hash{$key}[TYPE]); # char,minlen,maxlen,width
602 my $glabel = Gtk3::Label->new ($label);
603 my $gentry = Gtk3::Entry->new ();
604 $gentry->set_max_length($type[2]) if defined ($type[2]);
605 my $width = $type[3];
607 $gentry->set_width_chars(int ($width) + 2) if defined ($width);
608 my $value = $$vhash{$name}[VALUE];
609 $value //= $$hash{$key}[CMDEF];
610 $gentry->set_text ($value);
611 $gentry->signal_connect('key-release-event' => sub {
613 handle_nchar_value ($w, $e, \$$vhash{$name}, $type[1], $type[2]);
615 set_widget_hint ($gentry, $$hash{$key}[DESC]);
616 set_widget_sens ($gentry, $$hash{$key}[CMVER]);
617 $glabel->set_sensitive ($gentry->get_sensitive);
619 return new_hbox_spaced_pack ($glabel, $gentry);
622 sub new_color_button_for($$$) {
623 my ($hash, $key, $vhash) = @_;
624 my $name = $$hash{$key}[NAME];
625 my $label = $$hash{$key}[LABEL];
627 my $value = $$vhash{$name}[VALUE];
628 $value //= $$hash{$key}[CMDEF];
629 my $col = gdk_rgba_from_str ($value);
630 my $glabel = Gtk3::Label->new ($label);
631 my $button = Gtk3::ColorButton->new_with_rgba ($col);
632 $button->set_title ($label);
633 $button->set_relief ('none');
634 $button->signal_connect ('color-set' => sub {
636 handle_color_value ($w, $e, \$$vhash{$name});
638 set_widget_hint ($button, $$hash{$key}[DESC]);
639 set_widget_sens ($button, $$hash{$key}[CMVER]);
640 $glabel->set_sensitive ($button->get_sensitive);
642 return new_hbox_spaced_pack ($button, $glabel);
645 sub new_selection_box_for($$$) {
646 my ($hash, $key, $vhash) = @_;
647 my $name = $$hash{$key}[NAME];
648 my $label = $$hash{$key}[LABEL];
650 my $glabel = Gtk3::Label->new ($label);
651 my $combo = Gtk3::ComboBoxText->new;
652 my @options = split (';', $$hash{$key}[TYPE]);
653 foreach my $opt (@options) {
654 my ($index, $textkey) = split ('=', $opt);
655 $combo->insert (-1, $index, $xl::s{$textkey});
657 $combo->signal_connect ('changed' => sub {
659 handle_selection_value ($w, $e, \$$vhash{$name});
661 my $value = $$vhash{$name}[VALUE];
662 $value //= $$hash{$key}[CMDEF];
663 $combo->set_active ($value);
664 set_widget_hint ($combo, $$hash{$key}[DESC]);
665 set_widget_sens ($combo, $$hash{$key}[CMVER]);
666 $glabel->set_sensitive ($combo->get_sensitive);
668 return new_hbox_spaced_pack ($glabel, $combo);
671 # more graphic helpers
674 my $hbox = Gtk3::HBox->new (FALSE);
675 $hbox->set_border_width (PAGE_SPC);
677 $hbox->pack_start ($_, FALSE, FALSE, 0);
682 sub new_hbox_pack_compact {
683 my $hbox = Gtk3::HBox->new (FALSE);
684 $hbox->set_border_width (0);
686 $hbox->pack_start ($_, FALSE, FALSE, 0);
692 my $vbox = Gtk3::VBox->new (FALSE, 5);
693 $vbox->set_border_width (PAGE_SPC);
695 $vbox->pack_start ($_, FALSE, FALSE, 0);
700 sub new_vbox_pack_compact {
701 my $vbox = Gtk3::VBox->new (FALSE, 0);
702 $vbox->set_border_width (0);
704 $vbox->pack_start ($_, FALSE, FALSE, 0);
709 sub new_subpage_frame {
710 my ($box, $title, $notpacked) = @_;
711 my $frame = Gtk3::Frame->new ($title);
713 return new_vbox_pack ($frame) unless defined ($notpacked);
718 my ($border_w, $row_s, $col_s) = @_;
722 my $grid = Gtk3::Grid->new;
723 $grid->set_border_width ($border_w);
724 $grid->set_row_spacing ($row_s);
725 $grid->set_column_spacing ($col_s);
732 my $label = Gtk3::Label->new ($text);
733 $label->set_alignment (0, 0.5);
740 my $label = Gtk3::Label->new ('<b>' . $text . '</b>');
741 $label->set_use_markup (TRUE);
742 $label->set_alignment (0, 0.5);
747 my ($width, $height, $widget) = @_;
748 my $grid = new_grid ();
749 $grid->set_column_homogeneous (TRUE);
750 for (my $i = 0; $i < $width; ++$i) {
751 for (my $j = 0; $j < $height; ++$j) {
752 my $wid = $widget->[$j]->[$i];
753 next unless defined $wid;
754 my $ww = (($i + 1 < $width) and (defined $widget->[$j]->[$i + 1]))
758 $grid->attach ($wid, $i, $j, $ww, 1);
759 } else { # not a widget
760 if ('--' eq $wid) { # a separator
761 $grid->attach (Gtk3::Separator->new ('horizontal'),
763 } else { # or a title
764 $grid->attach (new_title ($wid),
773 # preference maps and corresponding page creation subs
775 %pr::oth = ( # other preferences
777 'addressbook_use_editaddress_dialog',
778 $xl::s{l_oth_use_dlg},
779 $xl::s{h_oth_use_dlg},
785 'cache_max_mem_usage',
786 [ $xl::s{l_oth_max_use}, $xl::s{l_oth_max_use_units} ],
787 $xl::s{h_oth_max_use},
788 'int,0,524288', # 0 Kb - 512 Mb
793 'cache_min_keep_time',
794 [ $xl::s{l_oth_min_time}, $xl::s{l_oth_min_time_units} ],
795 $xl::s{h_oth_min_time},
796 'int,0,120', # 0 minutes - 2 hours
801 'use_networkmanager',
802 $xl::s{l_oth_use_netm},
803 $xl::s{h_oth_use_netm},
809 'master_passphrase_pbkdf2_rounds',
810 $xl::s{l_oth_mp_rounds},
811 $xl::s{h_oth_mp_rounds},
818 sub new_other_page() {
819 return new_vbox_pack (
822 new_check_button_for(\%pr::oth, 'use_dlg', \%HPVALUE)),
823 $xl::s{ab_frame}, 'not-packed'),
826 new_text_box_for_int(\%pr::oth, 'max_use', \%HPVALUE),
827 new_text_box_for_int(\%pr::oth, 'min_time', \%HPVALUE)),
828 $xl::s{mem_frame}, 'not-packed'),
831 new_check_button_for(\%pr::oth, 'use_netm', \%HPVALUE)),
832 $xl::s{netm_frame}, 'not-packed'),
835 new_text_box_for_int(\%pr::oth, 'mp_rounds', \%HPVALUE)),
836 $xl::s{mpass_frame}, 'not-packed')
840 %pr::gui = ( # gui bells and whistles
843 $xl::s{l_gui_b_unread},
844 $xl::s{h_gui_b_unread},
851 $xl::s{l_gui_no_markup},
852 $xl::s{h_gui_no_markup},
858 'enable_dotted_lines',
859 $xl::s{l_gui_dot_lines},
860 $xl::s{h_gui_dot_lines},
862 '2.4.0.115,3.7.10.44',
867 $xl::s{l_gui_h_scroll},
868 $xl::s{h_gui_h_scroll},
875 $xl::s{l_gui_swp_from},
876 $xl::s{h_gui_swp_from},
882 'folderview_vscrollbar_policy',
883 $xl::s{l_gui_v_scroll},
884 $xl::s{h_gui_v_scroll},
885 '0=l_gui_v_scroll_show;1=l_gui_v_scroll_auto;2=l_gui_v_scroll_hide',
891 $xl::s{l_gui_from_show},
892 $xl::s{h_gui_from_show},
893 '0=l_gui_from_show_name;1=l_gui_from_show_addr;2=l_gui_from_show_both',
898 'stripes_color_offset',
899 $xl::s{l_gui_strip_off},
900 $xl::s{h_gui_strip_off},
901 'int,0,40000', # no idea what this number means
906 'textview_cursor_visible',
907 $xl::s{l_gui_cursor_v},
908 $xl::s{h_gui_cursor_v},
914 'toolbar_detachable',
915 $xl::s{l_gui_toolbar_d},
916 $xl::s{h_gui_toolbar_d},
922 'use_stripes_everywhere',
923 $xl::s{l_gui_strip_all},
924 $xl::s{h_gui_strip_all},
930 'use_stripes_in_summaries',
931 $xl::s{l_gui_strip_sum},
932 $xl::s{h_gui_strip_sum},
939 $xl::s{l_gui_two_line_v},
940 $xl::s{h_gui_two_line_v},
946 'show_compose_margin',
947 $xl::s{l_gui_margin_co},
948 $xl::s{h_gui_margin_co},
954 'msgview_date_format',
955 $xl::s{l_gui_mview_date},
956 $xl::s{h_gui_mview_date},
962 'zero_replacement_char',
963 $xl::s{l_gui_zero_char},
964 $xl::s{h_gui_zero_char},
971 $xl::s{l_gui_type_any},
972 $xl::s{h_gui_type_any},
978 'warn_sending_many_recipients_num',
979 [ $xl::s{l_gui_warn_send_multi}, $xl::s{l_gui_warn_send_multi_units} ],
980 $xl::s{h_gui_warn_send_multi},
987 $xl::s{l_gui_next_del},
988 $xl::s{h_gui_next_del},
996 my $gf = Gtk3::VBox->new (FALSE, 5);
997 $gf->set_border_width (PAGE_SPC);
999 my $cb_dot_lines = new_check_button_for (\%pr::gui, 'dot_lines', \%HPVALUE);
1000 my $cb_toolbar_d = new_check_button_for (\%pr::gui, 'toolbar_d', \%HPVALUE);
1001 my $tb_zero_char = new_text_box_for_nchar (\%pr::gui, 'zero_char', \%HPVALUE);
1003 $gf->pack_start (new_subpage_frame (
1005 new_check_button_for (\%pr::gui, 'strip_all', \%HPVALUE),
1006 new_check_button_for (\%pr::gui, 'strip_sum', \%HPVALUE),
1007 new_text_box_for_int (\%pr::gui, 'strip_off', \%HPVALUE)),
1008 $xl::s{stripes_frame}, 'not-packed'),
1009 FALSE, FALSE, FRAME_SPC);
1010 $gf->pack_start (new_subpage_frame (
1012 new_check_button_for (\%pr::gui, 'b_unread', \%HPVALUE),
1013 new_check_button_for (\%pr::gui, 'swp_from', \%HPVALUE),
1014 new_check_button_for (\%pr::gui, 'two_linev', \%HPVALUE),
1015 new_check_button_for (\%pr::gui, 'next_del', \%HPVALUE),
1016 new_selection_box_for (\%pr::gui, 'from_show', \%HPVALUE)),
1017 $xl::s{mlist_frame}, 'not-packed'),
1018 FALSE, FALSE, FRAME_SPC);
1019 $gf->pack_start (new_subpage_frame (
1021 new_check_button_for (\%pr::gui, 'cursor_v', \%HPVALUE),
1022 new_check_button_for (\%pr::gui, 'mview_date', \%HPVALUE)),
1023 $xl::s{mview_frame}, 'not-packed'),
1024 FALSE, FALSE, FRAME_SPC);
1025 $gf->pack_start (new_subpage_frame (
1027 new_hbox_pack_compact (
1028 new_check_button_for (\%pr::gui, 'no_markup', \%HPVALUE),
1029 new_check_button_for (\%pr::gui, 'margin_co', \%HPVALUE),
1030 new_check_button_for (\%pr::gui, 'type_any', \%HPVALUE)),
1031 new_text_box_for_int (\%pr::gui, 'warn_send_multi', \%HPVALUE)),
1032 $xl::s{compo_frame}, 'not-packed'),
1033 FALSE, FALSE, FRAME_SPC);
1034 $gf->pack_start ($cb_dot_lines, FALSE, FALSE, 0);
1035 $gf->pack_start ($cb_toolbar_d, FALSE, FALSE, 0);
1036 $gf->pack_start (new_subpage_frame (
1038 new_check_button_for (\%pr::gui, 'h_scroll', \%HPVALUE),
1039 new_selection_box_for (\%pr::gui, 'v_scroll', \%HPVALUE)),
1040 $xl::s{sbar_frame}, 'not-packed'),
1041 FALSE, FALSE, FRAME_SPC);
1042 $gf->pack_start ($tb_zero_char, FALSE, FALSE, 0);
1047 %pr::beh = ( # tweak some behaviour
1050 [ $xl::s{l_beh_hover_t}, $xl::s{l_beh_hover_t_units} ],
1051 $xl::s{h_beh_hover_t},
1052 'int,100,3000', # 0.1 seconds - 3 seconds
1058 $xl::s{l_beh_dangerous},
1059 $xl::s{h_beh_dangerous},
1065 'respect_flowed_format',
1066 $xl::s{l_beh_flowed},
1067 $xl::s{h_beh_flowed},
1073 'save_parts_readwrite',
1074 $xl::s{l_beh_parts_rw},
1075 $xl::s{h_beh_parts_rw},
1081 'skip_ssl_cert_check',
1082 $xl::s{l_beh_skip_ssl},
1083 $xl::s{h_beh_skip_ssl},
1089 'statusbar_update_step',
1090 [ $xl::s{l_beh_up_step}, $xl::s{l_beh_up_step_units} ],
1091 $xl::s{h_beh_up_step},
1092 'int,1,200', # 1 item - 200 items
1097 'thread_by_subject_max_age',
1098 [ $xl::s{l_beh_thread_a}, $xl::s{l_beh_thread_a_units} ],
1099 $xl::s{h_beh_thread_a},
1100 'int,1,30', # 1 day - 30 days
1106 $xl::s{l_beh_unsafe_ssl},
1107 $xl::s{h_beh_unsafe_ssl},
1113 'utf8_instead_of_locale_for_broken_mail',
1114 $xl::s{l_beh_use_utf8},
1115 $xl::s{h_beh_use_utf8},
1122 $xl::s{l_beh_warn_dnd},
1123 $xl::s{h_beh_warn_dnd},
1129 'outgoing_fallback_to_ascii',
1130 $xl::s{l_beh_out_ascii},
1131 $xl::s{h_beh_out_ascii},
1137 'primary_paste_unselects',
1138 $xl::s{l_beh_pp_unsel},
1139 $xl::s{h_beh_pp_unsel},
1145 'show_inline_attachments',
1146 $xl::s{l_beh_inline_at},
1147 $xl::s{h_beh_inline_at},
1153 'address_search_wildcard',
1154 $xl::s{l_beh_addr_swc},
1155 $xl::s{h_beh_addr_swc},
1161 'folder_search_wildcard',
1162 $xl::s{l_beh_fold_swc},
1163 $xl::s{h_beh_fold_swc},
1169 'rewrite_first_from',
1170 $xl::s{l_beh_rewrite_ff},
1171 $xl::s{h_beh_rewrite_ff},
1178 sub new_behaviour_page() {
1179 my $bf = Gtk3::VBox->new (FALSE, 5);
1180 $bf->set_border_width (PAGE_SPC);
1182 my $tb_up_step = new_text_box_for_int (\%pr::beh, 'up_step', \%HPVALUE);
1183 my $tb_thread_a = new_text_box_for_int (\%pr::beh, 'thread_a', \%HPVALUE);
1185 $bf->pack_start (new_subpage_frame (
1187 new_text_box_for_int (\%pr::beh, 'hover_t', \%HPVALUE),
1188 new_check_button_for (\%pr::beh, 'warn_dnd', \%HPVALUE)),
1189 $xl::s{dnd_frame}, 'not-packed'),
1190 FALSE, FALSE, FRAME_SPC);
1191 $bf->pack_start (new_subpage_frame (
1193 new_check_button_for (\%pr::beh, 'skip_ssl', \%HPVALUE),
1194 new_check_button_for (\%pr::beh, 'unsafe_ssl', \%HPVALUE)),
1195 $xl::s{ssl_frame}, 'not-packed'),
1196 FALSE, FALSE, FRAME_SPC);
1197 $bf->pack_start ($tb_up_step, FALSE, FALSE, 0);
1198 $bf->pack_start ($tb_thread_a, FALSE, FALSE, 0);
1199 $bf->pack_start (new_subpage_frame (
1201 new_check_button_for (\%pr::beh, 'flowed', \%HPVALUE),
1202 new_check_button_for (\%pr::beh, 'parts_rw', \%HPVALUE),
1203 new_check_button_for (\%pr::beh, 'use_utf8', \%HPVALUE),
1204 new_check_button_for (\%pr::beh, 'dangerous', \%HPVALUE),
1205 new_check_button_for (\%pr::beh, 'out_ascii', \%HPVALUE),
1206 new_check_button_for (\%pr::beh, 'pp_unsel', \%HPVALUE),
1207 new_check_button_for (\%pr::beh, 'inline_at', \%HPVALUE),
1208 new_check_button_for (\%pr::beh, 'rewrite_ff', \%HPVALUE)),
1209 $xl::s{msgs_frame}, 'not-packed'),
1210 FALSE, FALSE, FRAME_SPC);
1211 $bf->pack_start (new_subpage_frame (
1213 new_check_button_for (\%pr::beh, 'addr_swc', \%HPVALUE),
1214 new_check_button_for (\%pr::beh, 'fold_swc', \%HPVALUE)),
1215 $xl::s{swc_frame}, 'not-packed'),
1216 FALSE, FALSE, FRAME_SPC);
1220 %pr::col = ( # a variety of colours
1223 $xl::s{l_col_emphasis},
1224 $xl::s{h_col_emphasis},
1231 $xl::s{l_col_log_err},
1232 $xl::s{h_col_log_err},
1239 $xl::s{l_col_log_in},
1240 $xl::s{h_col_log_in},
1247 $xl::s{l_col_log_msg},
1248 $xl::s{h_col_log_msg},
1255 $xl::s{l_col_log_out},
1256 $xl::s{h_col_log_out},
1263 $xl::s{l_col_log_warn},
1264 $xl::s{h_col_log_warn},
1271 $xl::s{l_col_diff_add},
1272 $xl::s{h_col_diff_add},
1278 'diff_deleted_color',
1279 $xl::s{l_col_diff_del},
1280 $xl::s{h_col_diff_del},
1287 $xl::s{l_col_diff_hunk},
1288 $xl::s{h_col_diff_hunk},
1295 $xl::s{l_col_tags_bg},
1296 $xl::s{h_col_tags_bg},
1303 $xl::s{l_col_tags_text},
1304 $xl::s{h_col_tags_text},
1309 default_header_bg => [
1310 'default_header_bgcolor',
1311 $xl::s{l_col_default_header_bg},
1312 $xl::s{h_col_default_header_bg},
1317 default_header_text => [
1318 'default_header_color',
1319 $xl::s{l_col_default_header_text},
1320 $xl::s{h_col_default_header_text},
1326 'qs_active_bgcolor',
1327 $xl::s{l_col_qs_active_bg},
1328 $xl::s{h_col_qs_active_bg},
1335 $xl::s{l_col_qs_active_text},
1336 $xl::s{h_col_qs_active_text},
1343 $xl::s{l_col_qs_error_bg},
1344 $xl::s{h_col_qs_error_bg},
1351 $xl::s{l_col_qs_error_text},
1352 $xl::s{h_col_qs_error_text},
1359 sub new_colours_page() {
1360 return new_vbox_pack (
1363 new_color_button_for (\%pr::col, 'emphasis', \%HPVALUE),
1364 new_hbox_pack_compact (
1365 new_color_button_for (\%pr::col, 'tags_text', \%HPVALUE),
1366 new_color_button_for (\%pr::col, 'tags_bg', \%HPVALUE))),
1367 $xl::s{msgview_frame}, 'not-packed'),
1370 new_vbox_pack_compact (
1371 new_color_button_for (\%pr::col, 'log_err', \%HPVALUE),
1372 new_color_button_for (\%pr::col, 'log_warn', \%HPVALUE),
1373 new_color_button_for (\%pr::col, 'log_msg', \%HPVALUE)),
1374 new_vbox_pack_compact (
1375 new_color_button_for (\%pr::col, 'log_in', \%HPVALUE),
1376 new_color_button_for (\%pr::col, 'log_out', \%HPVALUE))),
1377 $xl::s{log_frame}, 'not-packed'),
1380 new_color_button_for (\%pr::col, 'diff_add', \%HPVALUE),
1381 new_color_button_for (\%pr::col, 'diff_del', \%HPVALUE),
1382 new_color_button_for (\%pr::col, 'diff_hunk', \%HPVALUE)),
1383 $xl::s{diff_frame}, 'not-packed'),
1386 new_color_button_for (\%pr::col, 'default_header_text', \%HPVALUE),
1387 new_color_button_for (\%pr::col, 'default_header_bg', \%HPVALUE)),
1388 $xl::s{compose_frame}, 'not-packed'),
1391 new_vbox_pack_compact (
1392 new_color_button_for (\%pr::col, 'qs_active_text', \%HPVALUE),
1393 new_color_button_for (\%pr::col, 'qs_error_text', \%HPVALUE)),
1394 new_vbox_pack_compact (
1395 new_color_button_for (\%pr::col, 'qs_active_bg', \%HPVALUE),
1396 new_color_button_for (\%pr::col, 'qs_error_bg', \%HPVALUE))),
1397 $xl::s{qs_frame}, 'not-packed')
1401 %pr::win = ( # tweak window positions and/or sizes
1406 'int,0,3000', # 0 pixels - 3000 pixels
1414 'int,0,3000', # 0 pixels - 3000 pixels
1422 'int,0,3000', # 0 pixels - 3000 pixels
1430 'int,0,3000', # 0 pixels - 3000 pixels
1435 'mainwin_maximised',
1436 $xl::s{l_win_main_mx},
1437 $xl::s{h_win_main_mx},
1443 'mainwin_fullscreen',
1444 $xl::s{l_win_main_fs},
1445 $xl::s{h_win_main_fs},
1451 'main_messagewin_x',
1454 'int,0,3000', # 0 pixels - 3000 pixels
1459 'main_messagewin_y',
1462 'int,0,3000', # 0 pixels - 3000 pixels
1470 'int,0,3000', # 0 pixels - 3000 pixels
1475 'messagewin_height',
1478 'int,0,3000', # 0 pixels - 3000 pixels
1486 'int,0,3000', # 0 pixels - 3000 pixels
1494 'int,0,3000', # 0 pixels - 3000 pixels
1502 'int,0,3000', # 0 pixels - 3000 pixels
1507 'receivewin_height',
1510 'int,0,3000', # 0 pixels - 3000 pixels
1518 'int,0,3000', # 0 pixels - 3000 pixels
1526 'int,0,3000', # 0 pixels - 3000 pixels
1531 'folderitemwin_width',
1534 'int,0,3000', # 0 pixels - 3000 pixels
1539 'folderitemwin_height',
1542 'int,0,3000', # 0 pixels - 3000 pixels
1547 'folderselwin_width',
1550 'int,0,3000', # 0 pixels - 3000 pixels
1555 'folderselwin_height',
1558 'int,0,3000', # 0 pixels - 3000 pixels
1566 'int,0,3000', # 0 pixels - 3000 pixels
1574 'int,0,3000', # 0 pixels - 3000 pixels
1579 'addressbookwin_width',
1582 'int,0,3000', # 0 pixels - 3000 pixels
1587 'addressbookwin_height',
1590 'int,0,3000', # 0 pixels - 3000 pixels
1595 'addressbookeditpersonwin_width',
1598 'int,0,3000', # 0 pixels - 3000 pixels
1603 'addressbookeditpersonwin_height',
1606 'int,0,3000', # 0 pixels - 3000 pixels
1611 'addressbookeditgroupwin_width',
1614 'int,0,3000', # 0 pixels - 3000 pixels
1619 'addressbookeditgroupwin_height',
1622 'int,0,3000', # 0 pixels - 3000 pixels
1627 'addressaddwin_width',
1630 'int,0,3000', # 0 pixels - 3000 pixels
1635 'addressaddwin_height',
1638 'int,0,3000', # 0 pixels - 3000 pixels
1643 'addressbook_folderselwin_width',
1646 'int,0,3000', # 0 pixels - 3000 pixels
1651 'addressbook_folderselwin_height',
1654 'int,0,3000', # 0 pixels - 3000 pixels
1659 'editaccountwin_width',
1662 'int,0,3000', # 0 pixels - 3000 pixels
1667 'editaccountwin_height',
1670 'int,0,3000', # 0 pixels - 3000 pixels
1675 'accountswin_width',
1678 'int,0,3000', # 0 pixels - 3000 pixels
1683 'accountswin_height',
1686 'int,0,3000', # 0 pixels - 3000 pixels
1691 'filteringwin_width',
1694 'int,0,3000', # 0 pixels - 3000 pixels
1699 'filteringwin_height',
1702 'int,0,3000', # 0 pixels - 3000 pixels
1707 'filteringactionwin_width',
1710 'int,0,3000', # 0 pixels - 3000 pixels
1715 'filteringactionwin_height',
1718 'int,0,3000', # 0 pixels - 3000 pixels
1723 'filtering_debugwin_width',
1726 'int,0,3000', # 0 pixels - 3000 pixels
1731 'filtering_debugwin_height',
1734 'int,0,3000', # 0 pixels - 3000 pixels
1742 'int,0,3000', # 0 pixels - 3000 pixels
1747 'matcherwin_height',
1750 'int,0,3000', # 0 pixels - 3000 pixels
1758 'int,0,3000', # 0 pixels - 3000 pixels
1766 'int,0,3000', # 0 pixels - 3000 pixels
1771 'templateswin_width',
1774 'int,0,3000', # 0 pixels - 3000 pixels
1779 'templateswin_height',
1782 'int,0,3000', # 0 pixels - 3000 pixels
1790 'int,0,3000', # 0 pixels - 3000 pixels
1795 'actionswin_height',
1798 'int,0,3000', # 0 pixels - 3000 pixels
1803 'actionsiodialog_width',
1806 'int,0,3000', # 0 pixels - 3000 pixels
1811 'actionsiodialog_height',
1814 'int,0,3000', # 0 pixels - 3000 pixels
1822 'int,0,3000', # 0 pixels - 3000 pixels
1830 'int,0,3000', # 0 pixels - 3000 pixels
1838 'int,0,3000', # 0 pixels - 3000 pixels
1843 'pluginswin_height',
1846 'int,0,3000', # 0 pixels - 3000 pixels
1854 'int,0,3000', # 0 pixels - 3000 pixels
1862 'int,0,3000', # 0 pixels - 3000 pixels
1867 'print_previewwin_width',
1870 'int,0,3000', # 0 pixels - 3000 pixels
1875 'print_previewwin_height',
1878 'int,0,3000', # 0 pixels - 3000 pixels
1884 sub new_winpos_subpage_main() {
1885 return new_subpage_frame (
1886 new_vbox_pack_compact (
1888 new_text_box_for_int (\%pr::win, 'main_x', \%HPVALUE),
1889 new_text_box_for_int (\%pr::win, 'main_y', \%HPVALUE)),
1891 new_text_box_for_int (\%pr::win, 'main_w', \%HPVALUE),
1892 new_text_box_for_int (\%pr::win, 'main_h', \%HPVALUE)),
1894 new_check_button_for (\%pr::win, 'main_fs', \%HPVALUE),
1895 new_check_button_for (\%pr::win, 'main_mx', \%HPVALUE))),
1900 sub new_winpos_subpage_msgs() {
1901 return new_subpage_frame (
1902 new_vbox_pack_compact (
1904 new_text_box_for_int (\%pr::win, 'msgs_x', \%HPVALUE),
1905 new_text_box_for_int (\%pr::win, 'msgs_y', \%HPVALUE)),
1907 new_text_box_for_int (\%pr::win, 'msgs_w', \%HPVALUE),
1908 new_text_box_for_int (\%pr::win, 'msgs_h', \%HPVALUE))),
1913 sub new_winpos_subpage_sendrecv() {
1914 return new_vbox_pack (
1917 new_text_box_for_int (\%pr::win, 'send_w', \%HPVALUE),
1918 new_text_box_for_int (\%pr::win, 'send_h', \%HPVALUE)),
1919 _('Send window'), 'not-packed'),
1922 new_text_box_for_int (\%pr::win, 'recv_w', \%HPVALUE),
1923 new_text_box_for_int (\%pr::win, 'recv_h', \%HPVALUE)),
1924 _('Receive window'), 'not-packed')
1928 sub new_winpos_subpage_fold() {
1929 return new_vbox_pack (
1931 new_vbox_pack_compact (
1933 new_text_box_for_int (\%pr::win, 'fold_x', \%HPVALUE),
1934 new_text_box_for_int (\%pr::win, 'fold_y', \%HPVALUE)),
1936 new_text_box_for_int (\%pr::win, 'fold_w', \%HPVALUE),
1937 new_text_box_for_int (\%pr::win, 'fold_h', \%HPVALUE))),
1938 _('Folder window'), 'not-packed'),
1941 new_text_box_for_int (\%pr::win, 'fsel_w', \%HPVALUE),
1942 new_text_box_for_int (\%pr::win, 'fsel_h', \%HPVALUE)),
1943 _('Folder selection window'), 'not-packed')
1947 sub new_winpos_subpage_addrbook() {
1948 return new_vbox_pack (
1951 new_text_box_for_int (\%pr::win, 'addr_w', \%HPVALUE),
1952 new_text_box_for_int (\%pr::win, 'addr_h', \%HPVALUE)),
1953 _('Addressbook main window'), 'not-packed'),
1956 new_text_box_for_int (\%pr::win, 'adep_w', \%HPVALUE),
1957 new_text_box_for_int (\%pr::win, 'adep_h', \%HPVALUE)),
1958 _('Edit person window'), 'not-packed'),
1961 new_text_box_for_int (\%pr::win, 'adeg_w', \%HPVALUE),
1962 new_text_box_for_int (\%pr::win, 'adeg_h', \%HPVALUE)),
1963 _('Edit group window'), 'not-packed'),
1966 new_text_box_for_int (\%pr::win, 'adda_w', \%HPVALUE),
1967 new_text_box_for_int (\%pr::win, 'adda_h', \%HPVALUE)),
1968 _('Add address window'), 'not-packed'),
1971 new_text_box_for_int (\%pr::win, 'addf_w', \%HPVALUE),
1972 new_text_box_for_int (\%pr::win, 'addf_h', \%HPVALUE)),
1973 _('Folder select window'), 'not-packed')
1977 sub new_winpos_subpage_accounts() {
1978 return new_vbox_pack (
1981 new_text_box_for_int (\%pr::win, 'acco_w', \%HPVALUE),
1982 new_text_box_for_int (\%pr::win, 'acco_h', \%HPVALUE)),
1983 _('Accounts window'), 'not-packed'),
1986 new_text_box_for_int (\%pr::win, 'acce_w', \%HPVALUE),
1987 new_text_box_for_int (\%pr::win, 'acce_h', \%HPVALUE)),
1988 _('Edit account window'), 'not-packed')
1992 sub new_winpos_subpage_filtering() {
1993 return new_vbox_pack (
1996 new_text_box_for_int (\%pr::win, 'filt_w', \%HPVALUE),
1997 new_text_box_for_int (\%pr::win, 'filt_h', \%HPVALUE)),
1998 _('Filtering window'), 'not-packed'),
2001 new_text_box_for_int (\%pr::win, 'fila_w', \%HPVALUE),
2002 new_text_box_for_int (\%pr::win, 'fila_h', \%HPVALUE)),
2003 _('Filtering actions window'), 'not-packed'),
2006 new_text_box_for_int (\%pr::win, 'fild_w', \%HPVALUE),
2007 new_text_box_for_int (\%pr::win, 'fild_h', \%HPVALUE)),
2008 _('Filtering debug window'), 'not-packed'),
2011 new_text_box_for_int (\%pr::win, 'matc_w', \%HPVALUE),
2012 new_text_box_for_int (\%pr::win, 'matc_h', \%HPVALUE)),
2013 _('Matcher window'), 'not-packed')
2017 sub new_winpos_subpage_useractions() {
2018 return new_vbox_pack (
2021 new_text_box_for_int (\%pr::win, 'acti_w', \%HPVALUE),
2022 new_text_box_for_int (\%pr::win, 'acti_h', \%HPVALUE)),
2023 _('User Actions prefs window'), 'not-packed'),
2026 new_text_box_for_int (\%pr::win, 'acio_w', \%HPVALUE),
2027 new_text_box_for_int (\%pr::win, 'acio_h', \%HPVALUE)),
2028 _('User Actions I/O window'), 'not-packed')
2032 sub new_winpos_subpage_prefs() {
2033 return new_vbox_pack (
2036 new_text_box_for_int (\%pr::win, 'pref_w', \%HPVALUE),
2037 new_text_box_for_int (\%pr::win, 'pref_h', \%HPVALUE)),
2038 _('Preferences window'), 'not-packed'),
2041 new_text_box_for_int (\%pr::win, 'temp_w', \%HPVALUE),
2042 new_text_box_for_int (\%pr::win, 'temp_h', \%HPVALUE)),
2043 _('Templates window'), 'not-packed'),
2046 new_text_box_for_int (\%pr::win, 'tags_w', \%HPVALUE),
2047 new_text_box_for_int (\%pr::win, 'tags_h', \%HPVALUE)),
2048 _('Tags window'), 'not-packed'),
2051 new_text_box_for_int (\%pr::win, 'plug_w', \%HPVALUE),
2052 new_text_box_for_int (\%pr::win, 'plug_h', \%HPVALUE)),
2053 _('Plugins window'), 'not-packed')
2057 sub new_winpos_subpage_misc() {
2058 return new_vbox_pack (
2061 new_text_box_for_int (\%pr::win, 'logw_w', \%HPVALUE),
2062 new_text_box_for_int (\%pr::win, 'logw_h', \%HPVALUE)),
2063 _('Log window'), 'not-packed'),
2066 new_text_box_for_int (\%pr::win, 'prin_w', \%HPVALUE),
2067 new_text_box_for_int (\%pr::win, 'prin_h', \%HPVALUE)),
2068 _('Print preview window'), 'not-packed'),
2071 new_text_box_for_int (\%pr::win, 'sour_w', \%HPVALUE),
2072 new_text_box_for_int (\%pr::win, 'sour_h', \%HPVALUE)),
2073 _('View source window'), 'not-packed')
2077 sub new_winpos_page() {
2078 my $winbook = Gtk3::Notebook->new;
2079 $winbook->set_tab_pos ('right');
2080 $winbook->append_page (new_winpos_subpage_main,
2081 Gtk3::Label->new (_('Main')));
2082 $winbook->append_page (new_winpos_subpage_msgs,
2083 Gtk3::Label->new (_('Message')));
2084 $winbook->append_page (new_winpos_subpage_sendrecv,
2085 Gtk3::Label->new (_('Send/Receive')));
2086 $winbook->append_page (new_winpos_subpage_fold,
2087 Gtk3::Label->new (_('Folder')));
2088 $winbook->append_page (new_winpos_subpage_addrbook,
2089 Gtk3::Label->new (_('Addressbook')));
2090 $winbook->append_page (new_winpos_subpage_accounts,
2091 Gtk3::Label->new (_('Accounts')));
2092 $winbook->append_page (new_winpos_subpage_filtering,
2093 Gtk3::Label->new (_('Filtering')));
2094 $winbook->append_page (new_winpos_subpage_useractions,
2095 Gtk3::Label->new (_('User Actions')));
2096 $winbook->append_page (new_winpos_subpage_prefs,
2097 Gtk3::Label->new (_('Preferences')));
2098 $winbook->append_page (new_winpos_subpage_misc,
2099 Gtk3::Label->new (_('Other')));
2103 %pr::acc = ( # per account hidden preferences
2105 'gnutls_set_priority',
2106 $xl::s{l_acc_gtls_set},
2107 $xl::s{h_acc_gtls_set},
2114 $xl::s{l_acc_gtls_pri},
2115 $xl::s{h_acc_gtls_pri},
2122 sub new_account_subpage($) {
2124 return new_grid_pack (1, 3, [
2125 [ _('GnuTLS priority') ],
2126 [ new_check_button_for (\%pr::acc, 'tls_set', $ACHPVALUE{$akey}) ],
2127 [ new_text_box_for_nchar (\%pr::acc, 'tls_pri', $ACHPVALUE{$akey}) ]
2131 sub new_accounts_page() {
2132 my $accbook = Gtk3::Notebook->new;
2133 $accbook->set_tab_pos ('right');
2135 $ACPREFS{$a}{'account_name'} cmp $ACPREFS{$b}{'account_name'}
2138 my $name = $ACPREFS{$_}{'account_name'};
2139 my $isdef = ($ACPREFS{$_}{'is_default'} eq '1');
2140 my $page = new_account_subpage ($_);
2141 my $label = new_label ($isdef? '<u>' . $name . '</u>': $name);
2142 $label->set_use_markup (TRUE);
2143 $accbook->append_page ($page, $label);
2145 $accbook->set_scrollable (TRUE);
2149 %pr::plu = ( # plugins hidden preferences
2155 'int,0,3000', # 0 pixels - 3000 pixels
2164 'int,0,3000', # 0 pixels - 3000 pixels
2171 'autocompletion_limit',
2172 $xl::s{l_plu_gpg_alimit},
2173 $xl::s{h_plu_gpg_alimit},
2181 'manager_win_width',
2184 'int,0,3000', # 0 pixels - 3000 pixels
2190 'manager_win_height',
2193 'int,0,3000', # 0 pixels - 3000 pixels
2201 $xl::s{l_plu_lav_burl},
2202 $xl::s{h_plu_lav_burl},
2205 'http://cdn.libravatar.org/avatar',
2210 'filter_log_verbosity',
2211 $xl::s{l_plu_prl_flvb},
2212 $xl::s{h_plu_prl_flvb},
2213 '0=l_plu_prl_none;1=l_plu_prl_manual;2=l_plu_prl_action;3=l_plu_prl_match',
2220 sub new_plugins_page() {
2223 new_text_box_for_int (\%pr::plu, 'arm_winw', $PLHPVALUE{'AttRemover'}),
2224 new_text_box_for_int (\%pr::plu, 'arm_winh', $PLHPVALUE{'AttRemover'})
2227 new_text_box_for_int (\%pr::plu, 'gpg_alimit', $PLHPVALUE{'GPG'})
2230 new_text_box_for_int (\%pr::plu, 'msv_winw', $PLHPVALUE{'ManageSieve'}),
2231 new_text_box_for_int (\%pr::plu, 'msv_winh', $PLHPVALUE{'ManageSieve'})
2234 new_text_box_for_nchar (\%pr::plu, 'lav_burl', $PLHPVALUE{'Libravatar'})
2237 new_selection_box_for (\%pr::plu, 'prl_flvb', $PLHPVALUE{'PerlPlugin'})
2240 foreach my $pk (@PLUGINS) {
2241 foreach my $wg (@{$widget{$pk}}) {
2242 $wg->set_sensitive (defined $PLHPVALUE{$pk});
2245 return new_grid_pack (3, 14, [
2246 [ _('Attachment remover') ], $widget{'AttRemover'}, [ '--' ],
2247 [ _('GPG') ], $widget{'GPG'}, [ '--' ],
2248 [ _('Sieve manager') ], $widget{'ManageSieve'}, [ '--' ],
2249 [ _('Libravatar') ], $widget{'Libravatar'}, [ '--' ],
2250 [ _('Perl') ], $widget{'PerlPlugin'}
2262 sub new_hotkeys_list_label {
2263 my $renderer = Gtk3::CellRendererText->new ();
2264 $renderer->set_property('alignment' => 'left');
2265 $renderer->set_property('editable' => FALSE);
2269 sub new_hotkeys_list_hotkey {
2270 my $renderer = Gtk3::CellRendererAccel->new ();
2271 $renderer->set_property ('accel-mode' => 'gtk');
2272 $renderer->set_property ('editable' => TRUE);
2273 $renderer->signal_connect ('accel-edited' => sub {
2274 my ($w, $path, $key, $mods, $keycode) = @_;
2275 my $accel = Gtk3::Accelerator->name ($key, $mods);
2276 my ($model, $iter) = $SELHOTKEY->get_selected ();
2277 $model->set($iter, C_HOTKEY, "\"$accel\"");
2278 my $gkey = $model->get_value ($iter, C_GROUP);
2279 my $akey = $model->get_value ($iter, C_ACCEL);
2280 my $data = $HOTKEYS->{$gkey}->{$akey};
2281 $data->{'key'} = "\"$accel\"";
2282 $data->{'enabled'} = TRUE;
2284 $renderer->signal_connect ('accel-cleared' => sub {
2285 my ($w, $path) = @_;
2286 my ($model, $iter) = $SELHOTKEY->get_selected ();
2287 $model->set($iter, C_HOTKEY, "\"\"");
2288 my $gkey = $model->get_value ($iter, C_GROUP);
2289 my $akey = $model->get_value ($iter, C_ACCEL);
2290 my $data = $HOTKEYS->{$gkey}->{$akey};
2291 $data->{'key'} = "\"\"";
2292 $data->{'enabled'} = FALSE;
2297 sub row_background_color {
2298 my ($column, $isodd) = @_;
2299 my $treeview = $column->get_tree_view;
2300 my $stylectx = $treeview->get_style_context;
2302 ? $stylectx->get_background_color ('normal')
2303 : $stylectx->get_background_color ('insensitive');
2306 sub new_hotkeys_list {
2307 my ($gkey, $group) = @_;
2308 my $store = Gtk3::ListStore->new(
2309 qw/Glib::String Glib::String Glib::String Glib::String Glib::Boolean/);
2311 foreach my $akey (sort keys %$group) {
2312 my $iter = $store->append ();
2313 my $hotkey = $group->{$akey}->{'key'};
2315 $label =~ s/[<>]//g; # <rrsyl> and <IMAPFolder> !?
2316 $store->set ($iter, C_LABEL, $label, C_HOTKEY, $hotkey,
2317 C_GROUP, $gkey, C_ACCEL, $akey, C_ODDITY, $even);
2320 my $treeview = Gtk3::TreeView->new_with_model ($store);
2322 $treeview->insert_column_with_data_func (
2323 0, _("Menu path"), new_hotkeys_list_label (),
2325 my ($col, $renderer, $model, $iter, $data) = @_;
2326 $renderer->set_property (
2327 'markup' => '<span size="smaller">'
2328 . $model->get_value ($iter, C_LABEL)
2330 my $bgcol = row_background_color (
2331 $col, $model->get_value ($iter, C_ODDITY));
2332 $renderer->set_property ('cell-background-rgba' => $bgcol);
2336 $treeview->insert_column_with_data_func (
2337 1, _('Hotkey'), new_hotkeys_list_hotkey (),
2339 my ($col, $renderer, $model, $iter, $data) = @_;
2340 my $hkey = $model->get_value ($iter, C_HOTKEY);
2342 my ($acckey, $accmod) = Gtk3::accelerator_parse ($hkey);
2343 $renderer->set_property ('accel-key' => $acckey);
2344 $renderer->set_property ('accel-mods' => $accmod);
2345 my $bgcol = row_background_color (
2346 $col, $model->get_value ($iter, C_ODDITY));
2347 $renderer->set_property ('cell-background-rgba' => $bgcol);
2350 # callback for saving current selection
2351 my $selection = $treeview->get_selection ();
2352 $selection->signal_connect ('changed' => sub { $SELHOTKEY = shift });
2356 sub new_hotkeys_page() {
2357 my $swin = Gtk3::ScrolledWindow->new ();
2358 my $vbox = Gtk3::VBox->new (FALSE, 5);
2359 foreach my $gkey (sort keys %$HOTKEYS) {
2360 my $group = $HOTKEYS->{$gkey};
2362 my $glabel = Gtk3::Label->new ('<b>' . $gkey . '</b>');
2363 $glabel->set_use_markup (TRUE);
2364 $glabel->set_alignment (0, 0.5);
2365 $glabel->set_padding (5, 1);
2366 $vbox->pack_start ($glabel, FALSE, FALSE, 0);
2368 my $keylist = new_hotkeys_list ($gkey, $group);
2369 $vbox->pack_start ($keylist, FALSE, FALSE, 0);
2371 $swin->set_border_width (5);
2372 $swin->set_shadow_type ('none');
2373 $swin->set_policy ('automatic', 'always');
2374 $swin->add_with_viewport ($vbox);
2378 sub new_info_page() {
2379 my $v = get_toolkit_versions ();
2380 my $cfgv = $CONFIGDATA->{'Common'}{'config_version'};
2382 return new_grid_pack (4, 11, [
2383 [ _('Library versions') ],
2384 [ new_label ('Perl-GLib'), new_title ($v->{'glib'}) ],
2385 [ new_label (_('GLib runtime')), new_title ($v->{'glib-r'}) ],
2386 [ new_label (_('GLib built')), new_title ($v->{'glib-b'}) ],
2387 [ new_label ('Perl-GTK3'), new_title ($v->{'gtk'}) ],
2388 [ new_label (_('GTK3 runtime')), new_title ($v->{'gtk-r'}) ],
2389 [ new_label (_('GTK3 built')), new_title ($v->{'gtk-b'}) ],
2391 [ _('Claws Mail versions') ],
2392 [ new_label (_('Binary')), new_title ($CLAWSV) ],
2393 [ new_label (_('Configuration')), new_title ($cfgv) ]
2398 sub get_toolkit_versions {
2400 $versions{'glib'} = $Glib::VERSION;
2401 # version info stuff appeared in 1.040
2402 if ($Glib::VERSION >= 1.040) {
2403 $versions{'glib-b'} = join('.', Glib->GET_VERSION_INFO);
2404 $versions{'glib-r'} = join('.',
2405 &Glib::major_version, &Glib::minor_version, &Glib::micro_version);
2407 $versions{'gtk'} = $Gtk3::VERSION;
2408 if ($Gtk3::VERSION >= 0.034) {
2409 $versions{'gtk-b'} = &Gtk3::GET_VERSION_INFO
2411 $versions{'gtk-b'} = _('Not available')
2413 $versions{'gtk-r'} = join('.',
2414 &Gtk3::get_major_version, &Gtk3::get_minor_version, &Gtk3::get_micro_version);
2418 sub print_version() {
2419 print $xl::s{about_title} . "\n";
2420 print $xl::s{about_version} . " $VERSION\n";
2421 my $v = get_toolkit_versions ();
2422 if ($v->{'glib-b'}) {
2423 print _("Perl-GLib version {glibv}, built for {glibb}, running with {glibr}.",
2424 glibv => $v->{'glib'},
2425 glibb => $v->{'glib-b'},
2426 glibr => $v->{'glib-r'});
2428 print _("Perl-GLib version {glibv}.", glibv => $v->{'glib'});
2431 if ($v->{'gtk-b'}) {
2432 print _("Perl-GTK3 version {gtkv}, built for {gtkb}, running with {gtkr}.",
2433 gtkv => $v->{'gtk'},
2434 gtkb => $v->{'gtk-b'},
2435 gtkr => $v->{'gtk-r'});
2437 print _("Perl-GTK3 version {gtkv}.", gtkv => $v->{'gtk'});
2440 my $clawsver = ($CLAWSV eq "") ?
2441 _("Claws Mail was not found!") :
2442 _("Claws Mail returned version {cmv}.", cmv => $CLAWSV);
2443 print $clawsver . "\n";
2446 # the command line help
2448 my $line = '-' x length ($xl::s{about_title});
2450 say $xl::s{about_title};
2454 _(" clawsker [options]"),
2456 _(" -a|--alternate-config-dir <dir> Uses <dir> as Claws Mail configuration."),
2457 _(" -b|--verbose More messages on standard output."),
2458 _(" -c|--clawsrc <file> Uses <file> as full resource name."),
2459 _(" -h|--help Prints this help screen and exits."),
2460 _(" -r|--read-only Disables writing changes to disk."),
2461 _(" -v|--version Prints version information and exits.")
2463 foreach (@help) { say $_ }
2466 sub parse_command_line {
2468 $CLAWSV = get_claws_version ();
2470 GetOptions('h|help' => sub { print_help (); $cont = FALSE },
2471 'v|version' => sub { print_version (); $cont = FALSE },
2472 'b|verbose' => sub { $VERBOSE = TRUE },
2473 'r|read-only' => sub { $READONLY = TRUE },
2474 'u|use-claws-version=s' => \&opt_use_claws_version,
2475 'a|alternate-config-dir=s' => \&opt_alternate_config_dir,
2476 'c|clawsrc=s' => \&opt_clawsrc)
2477 or die _("try -h or --help for syntax.\n");
2480 my $msg = _("Error in options: {msg}\n", msg => $@);
2481 if (defined $ENV{'DISPLAY'} and $ENV{'DISPLAY'} ne '') {
2482 eval { Gtk3->init };
2483 error_dialog ($msg) unless $@;
2490 sub opt_use_claws_version {
2491 my ($name, $value) = @_;
2492 die _("Error: {opt} requires a dotted numeric value argument\n", opt => $name)
2493 unless ($value =~ /^[\d\.]+$/);
2497 sub opt_alternate_config_dir {
2498 my ($name, $value) = @_;
2499 die _("Error: '{dir}' is not a directory or does not exist\n", dir => $value)
2501 $CONFIGDIR = $value;
2502 $CONFIGDIR .= "/" unless ($CONFIGDIR =~ /.*\/$/);
2503 $ALTCONFIGDIR = TRUE;
2507 my ($name, $value) = @_;
2508 die _("Error: '{value}' is not a file or does not exist\n", value => $value)
2510 set_rc_filename ($value);
2513 # update the hidden preferences status from loaded values
2514 sub init_hidden_preferences {
2515 foreach my $hash (\%pr::beh, \%pr::col, \%pr::gui, \%pr::oth, \%pr::win) {
2516 foreach my $key (keys %$hash) {
2517 $HPVALUE{${$hash}{$key}[NAME]}[VALUE] = $PREFS{${$hash}{$key}[NAME]};
2518 $HPVALUE{${$hash}{$key}[NAME]}[IVALUE] = $PREFS{${$hash}{$key}[NAME]};
2521 foreach my $akey (keys %ACPREFS) {
2522 foreach my $key (keys %pr::acc) {
2523 my $pname = $pr::acc{$key}[NAME];
2524 $ACHPVALUE{$akey}{$pname}[VALUE] = $ACPREFS{$akey}{$pname};
2525 $ACHPVALUE{$akey}{$pname}[IVALUE] = $ACPREFS{$akey}{$pname};
2528 foreach my $key (keys %pr::plu) {
2529 my $plugin = $pr::plu{$key}[PLUGIN];
2530 my $pname = $pr::plu{$key}[NAME];
2531 if (defined $PLPREFS{$plugin}) {
2532 $PLHPVALUE{$plugin}{$pname}[VALUE] = $PLPREFS{$plugin}{$pname};
2533 $PLHPVALUE{$plugin}{$pname}[IVALUE] = $PLPREFS{$plugin}{$pname};
2539 # generic load/save resource files
2545 open (RCF, '<:encoding(utf8)', $rc)
2546 or die _("Error: opening '{file}' for reading", file => $rc) . ": $!\n";
2547 my $section = '_'; # default unnamed section
2552 if (/^\[([^\]]+)\]$/) { # new section
2554 die _("Error: duplicate section '{sect}' in resource file '{file}'\n",
2555 sect => $section, file => $rc) if ($data{$section});
2556 $data{$section} = {};
2557 $meta{$section}{'#'} = $line;
2559 elsif (/^([0-9a-z_]+)=(.*)$/) { # key=value
2560 $data{$section}{$1} = $2;
2561 $meta{$section}{$1} = $line;
2563 elsif (/^(.*)$/) { # lone value
2564 push (@{$data{$section}{'_'}}, $1);
2568 return (\%data, \%meta);
2572 my ($rc, $data, $meta) = @_;
2573 open (RCF, '>:utf8', $rc)
2574 or die _("Error: opening '{file}' for writing", file => $rc) . ": $!\n";
2575 my @sections = keys %$data;
2576 if (defined $meta) {
2578 $meta->{$a}{'#'} <=> $meta->{$b}{'#'}
2581 foreach my $section (@sections) {
2582 say RCF "[$section]";
2583 if (ref ($data->{$section}{'_'}) eq 'ARRAY') {
2584 foreach my $val (@{$data->{$section}{'_'}}) {
2588 my @keys = keys %{$data->{$section}};
2589 if (defined $meta) {
2591 $meta->{$section}{$a} <=> $meta->{$section}{$b}
2594 foreach my $key (@keys) {
2595 my $val = $data->{$section}{$key};
2596 say RCF "$key=$val";
2604 sub backup_resource {
2606 my $rcbak = "$rc.backup";
2608 my $emsg = _("Unable to create backup file '{name}'\n", name => $rcbak);
2609 log_message ($emsg);
2610 error_dialog ($emsg);
2612 } unless rename ($rc, $rcbak);
2619 open (RCF, '<:encoding(utf8)', $rc)
2620 or die _("Error: opening '{file}' for reading", file => $rc) . ": $!\n";
2625 if (/^; \(gtk_accel_path "<([A-Za-z]+)>([^"]+)" ([^\)]+)\)$/) {
2626 my %data = ('key' => $3, 'enabled' => FALSE, 'line' => $line);
2627 $groups{$1}{$2} = \%data;
2628 # say "group -> $1 | path -> $2 | key -> $3";
2629 } elsif (/^\(gtk_accel_path "<([A-Za-z]+)>([^"]+)" ([^\)]+)\)$/) {
2630 my %data = ('key' => $3, 'enabled' => TRUE, 'line' => $line);
2631 $groups{$1}{$2} = \%data;
2632 # say "group -> $1 | path -> $2 | key -> $3";
2641 my ($rc, $groups) = @_;
2643 foreach my $gkey (keys %$groups) {
2644 my $group = $groups->{$gkey};
2645 foreach my $akey (keys %$group) {
2646 my $data = $group->{$akey};
2647 my $key = $data->{'key'};
2648 my $line = $data->{'line'};
2649 $lines[$line] = ($data->{'enabled'})? '': '; ';
2650 $lines[$line] .= '(gtk_accel_path "<'
2651 . $gkey . '>' . $akey . '" ' . $key . ')';
2654 open (RCF, '>:utf8', $rc)
2655 or die _("Error: opening '{file}' for writing", file => $rc) . ": $!\n";
2656 say RCF '; claws-mail GtkAccelMap rc-file -*- scheme -*-';
2657 say RCF '; this file is an automated accelerator map dump';
2659 foreach (@lines) { say RCF $_ if $_ }
2663 # load current status from disc
2664 sub load_rc_preferences {
2665 my $rc = get_rc_filename ();
2666 log_message ("Loading preferences from $rc\n");
2667 return FALSE unless check_rc_file ($rc);
2668 ($CONFIGDATA, $CONFIGMETA) = load_resource ($rc);
2669 foreach (keys %{$CONFIGDATA->{'Common'}}) {
2670 $PREFS{$_} = $CONFIGDATA->{'Common'}{$_};
2672 foreach my $plugin (@PLUGINS) {
2673 if (defined $CONFIGDATA->{$plugin}) {
2674 push (@AVPLUGINS, $plugin);
2675 foreach (keys %{$CONFIGDATA->{$plugin}}) {
2676 $PLPREFS{$plugin}{$_} = $CONFIGDATA->{$plugin}{$_};
2683 sub load_ac_preferences {
2684 my $rc = get_ac_rc_filename ();
2685 log_message ("Loading account preferences from $rc\n");
2686 return FALSE unless check_rc_file ($rc);
2687 ($ACCOUNTDATA, $ACCOUNTMETA) = load_resource ($rc);
2688 foreach my $asect (keys %$ACCOUNTDATA) {
2689 if ($asect =~ /^Account: (\d+)$/) {
2690 foreach (keys %{$ACCOUNTDATA->{$asect}}) {
2691 $ACPREFS{$1}{$_} = $ACCOUNTDATA->{$asect}{$_};
2698 sub load_hk_preferences {
2699 my $rc = get_menurc_filename ();
2700 return FALSE unless check_rc_file ($rc);
2701 $HOTKEYS = load_menurc ($rc);
2705 sub load_preferences {
2706 return FALSE unless check_claws_not_running ();
2707 return (load_rc_preferences ()
2708 and load_ac_preferences ()
2709 and load_hk_preferences ()
2713 # save current preferences to disc
2714 sub save_rc_preferences {
2715 my $rc = get_rc_filename ();
2716 log_message ("Saving preferences to $rc\n");
2717 return FALSE unless check_rc_file ($rc);
2718 return FALSE unless check_claws_not_running ();
2719 return FALSE unless backup_resource ($rc);
2720 foreach (keys %PREFS) {
2721 if (defined $HPVALUE{$_}) {
2722 $CONFIGDATA->{'Common'}{$_} = $HPVALUE{$_}[VALUE];
2725 foreach my $plugin (@AVPLUGINS) {
2726 foreach (keys %{$CONFIGDATA->{$plugin}}) {
2727 if (defined $PLHPVALUE{$plugin}{$_}) {
2728 $CONFIGDATA->{$plugin}{$_} = $PLHPVALUE{$plugin}{$_}[VALUE];
2732 save_resource ($rc, $CONFIGDATA, $CONFIGMETA);
2736 sub save_ac_preferences {
2737 my $rc = get_ac_rc_filename ();
2738 log_message ("Saving account preferences to $rc\n");
2739 return FALSE unless check_rc_file ($rc);
2740 return FALSE unless check_claws_not_running ();
2741 return FALSE unless backup_resource ($rc);
2742 foreach my $asect (keys %$ACCOUNTDATA) {
2743 if ($asect =~ /^Account: (\d+)$/) {
2744 foreach (keys %{$ACCOUNTDATA->{$asect}}) {
2745 if (defined $ACHPVALUE{$1}{$_}) {
2746 $ACCOUNTDATA->{$asect}{$_} = $ACHPVALUE{$1}{$_}[VALUE];
2751 save_resource ($rc, $ACCOUNTDATA, $ACCOUNTMETA);
2755 sub save_hk_preferences {
2756 my $rc = get_menurc_filename ();
2757 log_message ("Saving hotkey preferences to $rc\n");
2758 return FALSE unless check_rc_file ($rc);
2759 return FALSE unless check_claws_not_running ();
2760 return FALSE unless backup_resource ($rc);
2761 save_menurc ($rc, $HOTKEYS);
2765 sub save_preferences {
2766 my $result = save_rc_preferences ()
2767 and save_ac_preferences ()
2768 and save_hk_preferences ();
2769 $MODIFIED = 0 if $result;
2775 my $nb = Gtk3::Notebook->new;
2777 $nb->append_page (new_behaviour_page (),
2778 Gtk3::Label->new ($xl::s{tab_behaviour}));
2779 $nb->append_page (new_colours_page (),
2780 Gtk3::Label->new ($xl::s{tab_colours}));
2781 $nb->append_page (new_gui_page (),
2782 Gtk3::Label->new ($xl::s{tab_gui}));
2783 $nb->append_page (new_other_page (),
2784 Gtk3::Label->new ($xl::s{tab_other}));
2785 $nb->append_page (new_winpos_page (),
2786 Gtk3::Label->new ($xl::s{tab_winpos}));
2787 $nb->append_page (new_accounts_page (),
2788 Gtk3::Label->new ($xl::s{tab_accounts}));
2789 $nb->append_page (new_plugins_page (),
2790 Gtk3::Label->new ($xl::s{tab_plugins}));
2791 $nb->append_page (new_hotkeys_page (),
2792 Gtk3::Label->new ($xl::s{tab_hotkeys}));
2793 $nb->append_page (new_info_page (),
2794 Gtk3::Label->new ($xl::s{tab_info}));
2799 # create an about dialog
2800 sub new_about_dialog {
2802 my $year = '2007-2018';
2803 my $holder = 'Ricardo Mones <ricardo@mones.org>';
2804 my $url = 'http://www.claws-mail.org/clawsker.php';
2805 my $icons = &get_app_icons;
2807 my $dialog = Gtk3::AboutDialog->new;
2808 $dialog->set_transient_for ($parent);
2809 $dialog->set_program_name ('Clawsker');
2810 $dialog->set_version ($VERSION);
2811 $dialog->set_copyright ("Copyright © $year $holder");
2812 $dialog->set_license_type ('gpl-3-0');
2813 $dialog->set_website ($url);
2814 $dialog->set_website_label ($xl::s{about_web_label});
2815 # committers, by number of commits
2816 $dialog->set_authors ([
2818 'Tristan Chabredier (wwp) <subscript@free.fr>',
2819 'Andreas Rönnquist <andreas@ronnquist.net>',
2820 'Christian Hesse <mail@eworm.de>',
2822 $dialog->set_artists ([
2823 'Jesper Schultz <jesper@schultz-net.dk>',
2826 $dialog->set_documenters ([
2828 'Paul Mangan <paul@claws-mail.org>',
2830 # active translators, in alphabetical order
2831 $dialog->set_translator_credits (join ("\n",
2832 'Andreas Rönnquist <andreas@ronnquist.net>',
2833 'Axel Köllhofer <AxelKoellhofer@web.de>',
2834 'David Medina <opensusecatala@gmail.com>',
2835 'Erik P. Olsen <erik@epo.dk>',
2836 'Frederico Goncalves Guimaraes <frederico@teia.bio.br>',
2837 'Marcel Pol <marcel@timelord.nl>',
2838 'Mark Chang <mark.cyj@gmail.com>',
2839 'M. Sulchan Darmawan <bleketux@gmail.com>',
2840 'Numan Demirdöğen <if.gnu.linux@gmail.com>',
2841 'Petter Adsen <petter@synth.no>',
2843 'Tristan Chabredier (wwp) <subscript@free.fr>',
2845 $dialog->set_title ($xl::s{about_title});
2846 $dialog->set_logo ($icons->[-1]);
2853 if ($MODIFIED != 0 and not $READONLY) {
2854 my $markup = "<span>" . $xl::s{exit_fact} . "</span>\n\n"
2855 . "<span weight=\"bold\">" . $xl::s{exit_question} . "</span>\n";
2856 my $dialog = message_dialog (
2857 $parent, $xl::s{exit_title}, $markup, 'question',
2858 [ 'gtk-no', 1, 'gtk-yes', 0 ]
2860 my $resp = $dialog->run;
2862 return TRUE if ($resp == 1);
2867 # create buttons box
2868 sub new_button_box {
2869 my ($parent, $adlg) = @_;
2870 my $b_about = Gtk3::Button->new_from_stock ('gtk-about');
2871 my $b_exit = Gtk3::Button->new_from_stock ('gtk-quit');
2872 my $b_apply = Gtk3::Button->new_from_stock ('gtk-apply');
2873 # disable button until is really implemented
2874 # my $b_undo = Gtk3::Button->new_from_stock ('gtk-undo');
2875 my $hbox = Gtk3::HBox->new (FALSE, 5);
2877 $b_exit->signal_connect (clicked => sub { exit_handler($parent) });
2878 $b_apply->set_sensitive (not $READONLY);
2879 $b_apply->signal_connect (clicked => sub { save_preferences($parent) });
2880 # $b_undo->signal_connect (clicked => sub { undo_current_changes });
2881 $b_about->signal_connect (clicked => sub { $adlg->run; $adlg->hide });
2883 $hbox->pack_end ($b_apply, FALSE, FALSE, 0);
2884 $hbox->pack_end ($b_exit, FALSE, FALSE, 0);
2885 # $hbox->pack_end ($b_undo, FALSE, FALSE, 0);
2886 $hbox->pack_start ($b_about, FALSE, FALSE, 0);
2892 return \@APPICONS if (@APPICONS);
2894 if (-d $DATADIR) { # installed
2895 my $dir = $DATADIR . '/icons/hicolor';
2897 join ('/', ($dir, $_ . 'x' . $_, 'apps', $NAME . '.png'))
2899 } else { # unpacked tarball or git clone
2901 join ('/', ('./icons', $NAME . '-' . $_ . '.png'));
2906 $icon = Gtk3::Gdk::Pixbuf->new_from_file($_) if (-f $_);
2907 push @APPICONS, $icon if ($icon);
2912 sub escape_key_handler {
2913 my ($widget, $event) = @_;
2914 if ($event->keyval == Gtk3::Gdk::keyval_from_name('Escape')) {
2915 exit_handler($widget);
2920 exit unless parse_command_line ();
2922 $main_window = Gtk3::Window->new ('toplevel');
2923 exit unless load_preferences ();
2924 exit unless init_hidden_preferences ();
2926 my $box = Gtk3::VBox->new (FALSE, 5);
2927 $box->set_border_width(3);
2928 my $about = new_about_dialog ($main_window);
2929 $box->pack_start (new_notebook (), TRUE, TRUE, 0);
2930 $box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
2931 $main_window->signal_connect (delete_event => sub { exit_handler($main_window) });
2932 $main_window->signal_connect (key_press_event => \&escape_key_handler);
2933 $main_window->set_title ($xl::s{win_title});
2934 $main_window->set_icon_list (get_app_icons ());
2935 $main_window->add ($box);
2936 $main_window->show_all;