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));
45 my $SHOWHINTS = FALSE;
46 $SHOWHINTS = TRUE if ($Gtk3::VERSION >= 1.040 and Gtk3->CHECK_VERSION (2, 12, 0));
51 my $xla = gettext ($str);
52 if (scalar(keys(%par)) > 0) {
53 foreach my $key (keys %par) {
54 $xla =~ s/\{$key\}/$par{$key}/g;
57 return decode_utf8($xla);
62 win_title => _('Claws Mail Hidden Preferences'),
63 about => _('About...'),
64 about_title => _('Clawsker :: A Claws Mail Tweaker'),
65 about_license => _('License:'),
66 about_version => _('Version:'),
68 error_title => _('Clawsker error'),
70 exit_title => _('Clawsker warning'),
71 exit_fact => _('There are unapplied modifications.'),
72 exit_question => _('Do you really want to quit?'),
74 tab_colours => _('Colours'),
75 tab_behaviour => _('Behaviour'),
77 tab_other => _('Other'),
78 tab_winpos => _('Windows'),
79 tab_accounts => _('Accounts'),
80 tab_plugins => _('Plugins'),
81 tab_hotkeys => _('Hotkeys'),
82 tab_info => _('Info'),
84 ab_frame => _('Addressbook'),
85 mem_frame => _('Memory'),
86 msgview_frame => _('Message View'),
87 log_frame => _('Log window'),
88 dnd_frame => _('Drag \'n\' drop'),
89 ssl_frame => _('Secure Sockets Layer'),
90 msgs_frame => _('Messages'),
91 swc_frame => _('Completion'),
92 stripes_frame => _('Coloured stripes'),
93 sbar_frame => _('Scroll bars'),
94 mlist_frame => _('Message List'),
95 mview_frame => _('Message View'),
96 compo_frame => _('Compose window'),
97 netm_frame => _('NetworkManager'),
98 diff_frame => _('Viewing patches'),
99 mpass_frame => _('Master passphrase'),
100 compose_frame => _('Compose window'),
101 qs_frame => _('Quick search'),
103 l_oth_use_dlg => _('Use detached address book edit dialogue'),
104 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.'),
105 l_oth_max_use => _('Maximum memory for message cache'),
106 l_oth_max_use_units => _('kilobytes'),
107 h_oth_max_use => _('The maximum amount of memory to use to cache messages, in kilobytes.'),
108 l_oth_min_time => _('Minimun time for cache elements'),
109 l_oth_min_time_units => _('minutes'),
110 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.'),
111 l_oth_use_netm => _('Use NetworkManager'),
112 h_oth_use_netm => _('Use NetworkManager to switch offline automatically.'),
113 l_oth_mp_rounds => _('Rounds for PBKDF2 function'),
114 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.'),
116 l_gui_b_unread => _('Show unread messages with bold font'),
117 h_gui_b_unread => _('Show unread messages in the Message List using a bold font.'),
118 l_gui_no_markup => _('Don\'t use markup'),
119 h_gui_no_markup => _('Don\'t use bold and italic text in Compose dialogue\'s account selector.'),
120 l_gui_dot_lines => _('Use dotted lines in tree view components'),
121 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.'),
122 l_gui_h_scroll => _('Enable horizontal scrollbar'),
123 h_gui_h_scroll => _('Enable the horizontal scrollbar in the Message List.'),
124 l_gui_swp_from => _('Display To column instead From column in Sent folder'),
125 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.'),
126 l_gui_v_scroll => _('Folder List scrollbar behaviour'),
127 h_gui_v_scroll => _('Specify the policy of vertical scrollbar of Folder List: show always, automatic or hide always.'),
128 l_gui_v_scroll_show => _('Show always'),
129 l_gui_v_scroll_auto => _('Automatic'),
130 l_gui_v_scroll_hide => _('Hide always'),
131 l_gui_from_show => _('From column displays'),
132 h_gui_from_show => _('Selects the data displayed in the From column of the Message List: name, address or both.'),
133 l_gui_from_show_name => _('Name only'),
134 l_gui_from_show_addr => _('Address only'),
135 l_gui_from_show_both => _('Both name and address'),
136 l_gui_strip_off => _('Coloured lines contrast'),
137 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.'),
138 l_gui_cursor_v => _('Show cursor'),
139 h_gui_cursor_v => _('Display the cursor in the Message View.'),
140 l_gui_toolbar_d => _('Detachable toolbars'),
141 h_gui_toolbar_d => _('Show handles in the toolbars.'),
142 l_gui_strip_all => _('Use stripes in all tree view components'),
143 h_gui_strip_all => _('Enable alternately coloured lines in all tree view components.'),
144 l_gui_strip_sum => _('Use stripes in Folder List and Message List'),
145 h_gui_strip_sum => _('Enable alternately coloured lines in Message List and Folder List.'),
146 l_gui_two_line_v => _('2 lines per Message List item in 3-column layout'),
147 h_gui_two_line_v => _('Spread Message List information over two lines when using the three column mode.'),
148 l_gui_margin_co => _('Show margin'),
149 h_gui_margin_co => _('Shows a small margin in the Compose View.'),
150 l_gui_mview_date => _('Don\'t display localized date'),
151 h_gui_mview_date => _('Toggles localization of date format in Message View.'),
152 l_gui_zero_char => _('Zero replacement character'),
153 h_gui_zero_char => _('Replaces \'0\' with the given character in Folder List.'),
154 l_gui_type_any => _('Editable headers'),
155 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.'),
156 l_gui_warn_send_multi => _('Warn when sending to more than'),
157 l_gui_warn_send_multi_units => _('recipients'),
158 h_gui_warn_send_multi => _('Show a warning dialogue when sending to more recipients than specified. Use 0 to disable this check.'),
159 l_gui_next_del => _('Select next message on delete'),
160 h_gui_next_del => _('When deleting a message, toggles between selecting the next one (newer message) or the previous one (older message).'),
162 l_beh_hover_t => _('Drag \'n\' drop hover timeout'),
163 l_beh_hover_t_units => _('milliseconds'),
164 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.'),
165 l_beh_dangerous => _('Don\'t confirm deletions (dangerous!)'),
166 h_beh_dangerous => _('Don\'t ask for confirmation before definitive deletion of emails.'),
167 l_beh_flowed => _('Respect format=flowed in messages'),
168 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.'),
169 l_beh_parts_rw => _('Allow writable temporary files'),
170 h_beh_parts_rw => _('Saves temporary files when opening attachment with write bit set.'),
171 l_beh_skip_ssl => _('Don\'t check SSL certificates'),
172 h_beh_skip_ssl => _('Disables the verification of SSL certificates.'),
173 l_beh_up_step => _('Progress bar update step every'),
174 l_beh_up_step_units => _('items'),
175 h_beh_up_step => _('Update stepping in progress bars.'),
176 l_beh_thread_a => _('Maximum age when threading by subject'),
177 l_beh_thread_a_units => _('days'),
178 h_beh_thread_a => _('Number of days to include a message in a thread when using "Thread using subject in addition to standard headers".'),
179 l_beh_unsafe_ssl => _('Allow unsafe SSL certificates'),
180 h_beh_unsafe_ssl => _('Allows Claws Mail to remember multiple SSL certificates for a given server/port.'),
181 l_beh_use_utf8 => _('Force UTF-8 for broken mails'),
182 h_beh_use_utf8 => _('Use UTF-8 encoding for broken mails instead of current locale.'),
183 l_beh_warn_dnd => _('Warn on drag \'n\' drop'),
184 h_beh_warn_dnd => _('Display a confirmation dialogue on drag \'n\' drop of folders.'),
185 l_beh_out_ascii => _('Outgoing messages fallback to ASCII'),
186 h_beh_out_ascii => _('If allowed by content, ASCII will be used to encode outgoing messages, otherwise the user-defined encoding is always enforced.'),
187 l_beh_pp_unsel => _('Primary paste unselects selection'),
188 h_beh_pp_unsel => _('Controls how pasting using middle-click changes the selected text and insertion point.'),
189 l_beh_inline_at => _('Show inline attachments'),
190 h_beh_inline_at => _('Allows to hide inline attachments already shown in mail structure view.'),
191 l_beh_addr_swc => _('Address search in compose window matches any'),
192 h_beh_addr_swc => _('On Tab-key completion, address text will match any part of the string or only from the start.'),
193 l_beh_fold_swc => _('Folder search in folder selector matches any'),
194 h_beh_fold_swc => _('On folder name completion text will match any part of the string or only from the start.'),
195 l_beh_rewrite_ff => _('Rewrite first \'From\' using QP encoding'),
196 h_beh_rewrite_ff => _('Workaround some servers which convert first \'From\' to \'>From\' by using Quoted-Printable transfer encoding instead of 7bit/8bit encoding.'),
198 l_col_emphasis => _('X-Mailer header'),
199 h_col_emphasis => _('The colour used for the X-Mailer line when its value is Claws Mail.'),
200 l_col_log_err => _('Error messages'),
201 h_col_log_err => _('Colour for error messages in log window.'),
202 l_col_log_in => _('Server messages'),
203 h_col_log_in => _('Colour for messages received from servers in log window.'),
204 l_col_log_msg => _('Standard messages'),
205 h_col_log_msg => _('Colour for messages in log window.'),
206 l_col_log_out => _('Client messages'),
207 h_col_log_out => _('Colour for messages sent to servers in log window.'),
208 l_col_log_warn => _('Warning messages'),
209 h_col_log_warn => _('Colour for warning messages in log window.'),
211 l_col_tags_bg => _('Tags background'),
212 h_col_tags_bg => _('Background colour for tags in message view.'),
213 l_col_tags_text => _('Tags text'),
214 h_col_tags_text => _('Text colour for tags in message view.'),
216 l_col_default_header_bg => _('Default headers background'),
217 h_col_default_header_bg => _('Background colour for default headers in compose window.'),
218 l_col_default_header_text => _('Default headers text'),
219 h_col_default_header_text => _('Text colour for default headers in compose window.'),
221 l_col_qs_active_bg => _('Active quick search background'),
222 h_col_qs_active_bg => _('Background colour for active quick search.'),
223 l_col_qs_active_text => _('Active quick search text'),
224 h_col_qs_active_text => _('Text colour for active quick search.'),
225 l_col_qs_error_bg => _('Quick search error background'),
226 h_col_qs_error_bg => _('Background colour for quick search error.'),
227 l_col_qs_error_text => _('Quick search error text'),
228 h_col_qs_error_text => _('Text colour for quick search error.'),
230 l_col_diff_add => _('Added lines'),
231 h_col_diff_add => _('Colour for added lines in patches.'),
232 l_col_diff_del => _('Deleted lines'),
233 h_col_diff_del => _('Colour for deleted lines in patches.'),
234 l_col_diff_hunk => _('Hunk lines'),
235 h_col_diff_hunk => _('Colour for hunk headers in patches.'),
237 l_win_x => _('X position'),
238 h_win_x => _('X coordinate for window\'s top-left corner.'),
239 l_win_y => _('Y position'),
240 h_win_y => _('Y coordinate for window\'s top-left corner.'),
241 l_win_w => _('Width'),
242 h_win_w => _('Window\'s width in pixels.'),
243 l_win_h => _('Height'),
244 h_win_h => _('Window\'s height in pixels.'),
246 l_win_main_mx => _('Maximized'),
247 h_win_main_mx => _('Changes window maximized status.'),
248 l_win_main_fs => _('Full-screen'),
249 h_win_main_fs => _('Changes full screen status.'),
251 l_acc_gtls_set => _('Use custom GnuTLS priority'),
252 h_acc_gtls_set => _('Enables using user provided GnuTLS priority string.'),
253 l_acc_gtls_pri => _('GnuTLS priority'),
254 h_acc_gtls_pri => _('Value to use as GnuTLS priority string if custom priority check is enabled. Otherwise this value is ignored.'),
256 l_plu_gpg_alimit => _('Autocompletion limit'),
257 h_plu_gpg_alimit => _('Limits the number of addresses obtained from keyring through autocompletion. Use 0 to get all matches.'),
258 l_plu_lav_burl => _('Base URL'),
259 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.'),
260 l_plu_prl_flvb => _('Log level'),
261 h_plu_prl_flvb => _('Verbosity level of log, accumulative.'),
262 l_plu_prl_none => _('None'),
263 l_plu_prl_manual => _('Manual'),
264 l_plu_prl_action => _('Actions'),
265 l_plu_prl_match => _('Matches'),
268 # data and metadata of resource files
273 # all preferences read by load_preferences
277 # values of all preferences handled by clawsker
281 # default config dir and file name
282 my $ALTCONFIGDIR = FALSE;
283 my $CONFIGDIR = $ENV{HOME} . '/.claws-mail/';
284 my $CONFIGRC = 'clawsrc';
285 my $ACCOUNTRC = 'accountrc';
286 # supported and available plugins lists
287 my @PLUGINS = qw(AttRemover GPG ManageSieve Libravatar PerlPlugin);
289 # loaded hotkeys from load_menurc
291 # current tree selection
298 # index constants for preference arrays
299 use constant NAME => 0; # the name on the rc file
300 use constant LABEL => 1; # the label on the GUI
301 use constant DESC => 2; # the description for the hint/help
302 use constant TYPE => 3; # data type: bool, int, float, string, color
303 use constant CMVER => 4; # lowest[,highest] Claws Mail version(s) the feature exists
304 use constant CMDEF => 5; # default value for the preference in Claws Mail
305 use constant PLUGIN => 6; # plugin section (only in plugin preferences)
307 # constants for GUI spacing
308 use constant HBOX_PAD => 5;
309 use constant FRAME_SPC => 2;
310 use constant PAGE_SPC => 5;
312 # for data references indexing
313 use constant VALUE => 0;
314 use constant IVALUE => 1;
318 sub version_greater_or_equal {
319 my ($version, $refvers) = @_;
320 return TRUE if (length($version) == 0 and length($refvers) >= 0);
321 return FALSE if (length($version) >= 0 and length($refvers) == 0);
322 return TRUE if (version->parse($version) >= version->parse($refvers));
326 sub get_claws_version {
327 $_ = qx/which claws-mail/;
329 return "" unless ($_); # not installed
333 my @fver = split (/ /);
334 die "Invalid version string" unless ($fver[2] eq "version");
335 my @ver = split (/\./, $fver[3]);
338 if ($ver[2] =~ /(\d+)git(\d+)/) {
347 # data handlers and auxiliar functions
349 sub handle_bool_value {
350 my ($widget, $event, $dataref) = @_;
351 $$dataref->[VALUE] = ($widget->get_active ())? '1': '0';
352 $MODIFIED += $$dataref->[VALUE] != $$dataref->[IVALUE]? 1: -1
353 if defined $$dataref->[IVALUE];
356 sub handle_int_value {
357 my ($widget, $event, $dataref) = @_;
358 $_ = $widget->get_text ();
362 $$dataref->[VALUE] = $_;
363 $widget->set_text ($_);
366 $widget->set_text ($$dataref->[VALUE]);
368 $MODIFIED += $$dataref->[VALUE] != $$dataref->[IVALUE]? 1: -1
369 if defined $$dataref->[IVALUE];
372 sub handle_string_value {
373 my ($widget, $event, $dataref) = @_;
374 $$dataref->[VALUE] = $widget->get_text ();
375 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
376 if defined $$dataref->[IVALUE];
379 sub handle_nchar_value {
380 my ($widget, $event, $dataref, $minlen, $maxlen) = @_;
381 $_ = substr ($widget->get_text (), 0, $maxlen);
382 $widget->set_text ($_);
383 $$dataref->[VALUE] = $_;
384 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
385 if defined $$dataref->[IVALUE];
388 sub gdk_rgba_from_str {
390 my ($rr, $gg, $bb) = (0, 0 ,0);
392 if (/\#([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])/) {
397 my $color = Gtk3::Gdk::RGBA->new ($rr, $gg, $bb, 1.0);
401 sub str_from_gdk_rgba {
403 my $rr = $color->red * 256;
404 my $gg = $color->green * 256;
405 my $bb = $color->blue * 256;
406 my $str = sprintf ("#%.2x%.2x%.2x", $rr, $gg, $bb);
410 sub handle_color_value {
411 my ($widget, $event, $dataref) = @_;
412 my $newcol = $widget->get_rgba;
413 $$dataref->[VALUE] = str_from_gdk_rgba ($newcol);
414 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
415 if defined $$dataref->[IVALUE];
418 sub handle_selection_value {
419 my ($widget, $event, $dataref) = @_;
420 $$dataref->[VALUE] = $widget->get_active;
421 $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
422 if defined $$dataref->[IVALUE];
425 sub get_rc_filename {
426 return $CONFIGDIR . $CONFIGRC;
429 sub get_ac_rc_filename {
430 return $CONFIGDIR . $ACCOUNTRC;
433 sub get_menurc_filename {
434 return $CONFIGDIR . "menurc";
437 sub set_rc_filename {
439 my @parts = split ('/', $fullname);
440 $CONFIGRC = $parts[$#parts];
441 $parts[$#parts] = '';
442 $CONFIGDIR = join ('/', @parts);
446 my ($mesg, $fatal) = @_;
447 if (defined($fatal) && $fatal eq 'die') {
448 die "$NAME: $mesg\n";
451 print "$NAME: $mesg\n";
456 my ($parent, $title, $markup, $type, $buttons) = @_;
457 my $flags = [qw/modal destroy-with-parent/];
458 my $dialog = Gtk3::Dialog->new_with_buttons (
459 $title, $parent, $flags, @$buttons
461 my $label = Gtk3::Label->new;
462 $label->set_markup ($markup);
464 if ($type eq 'error') {
465 $icon = Gtk3::Image->new_from_icon_name('dialog-error', 'GTK_ICON_SIZE_DIALOG');
466 } elsif ($type eq 'warning') {
467 $icon = Gtk3::Image->new_from_icon_name('dialog-warning', 'GTK_ICON_SIZE_DIALOG');
468 } elsif ($type eq 'question') {
469 $icon = Gtk3::Image->new_from_icon_name('dialog-question', 'GTK_ICON_SIZE_DIALOG');
471 my $hbox = Gtk3::Box->new ('horizontal', 5);
472 $hbox->pack_start ($icon, FALSE, FALSE, 5) if defined $icon;
473 $hbox->pack_start ($label, FALSE, FALSE, 5);
474 my $dialogbox = $dialog->get_content_area;
475 $dialogbox->add ($hbox);
476 $dialogbox->show_all;
482 my $markup = "<span weight=\"bold\" size=\"large\">" . $emsg . "</span>";
483 my $errordlg = message_dialog (
484 $main_window, $xl::s{error_title}, $markup, 'error', [ 'gtk-cancel', 0 ]
490 sub claws_is_running {
491 my $emsg = _('Error: seems Claws Mail is currently running, close it first.');
493 error_dialog ($emsg);
497 sub check_claws_not_running {
498 return TRUE if $READONLY;
499 my $tmpdir = (defined $ENV{TMPDIR})? $ENV{TMPDIR}: '/tmp';
500 $tmpdir = '/tmp' if ($tmpdir eq '');
501 my $lockdir = "$tmpdir/claws-mail-$<";
505 my $socket = "$lockdir/" . md5_hex ($_);
506 -S $socket and return claws_is_running ();
513 (defined($rcfile) && -f $rcfile) or do {
514 my $emsg = _('Error: resource file for Claws Mail was not found.');
516 error_dialog ($emsg);
522 sub set_widget_hint {
524 my ($wdgt, $hint) = @_;
525 $wdgt->set_tooltip_text ($hint);
526 $wdgt->set_has_tooltip (TRUE);
530 sub set_widget_sens {
531 my ($wdgt, $versions) = @_;
532 my @ver = split(/,/, $versions);
534 $wdgt->set_sensitive (
535 version_greater_or_equal ($CLAWSV, $ver[0])
536 and version_greater_or_equal ($ver[1], $CLAWSV)
539 $wdgt->set_sensitive (version_greater_or_equal ($CLAWSV, $ver[0]));
543 # graphic element creation
545 sub new_hbox_spaced_pack {
546 my $hbox = Gtk3::HBox->new (FALSE);
548 $hbox->pack_start ($_, FALSE, FALSE, HBOX_PAD);
553 sub new_check_button_for($$$) {
554 my ($hash, $key, $vhash) = @_;
555 my $name = $$hash{$key}[NAME];
556 my $label = $$hash{$key}[LABEL];
558 my $cb = Gtk3::CheckButton->new ($label);
559 my $value = $$vhash{$name}[VALUE];
560 $value //= $$hash{$key}[CMDEF];
561 $cb->set_active ($value eq '1');
562 $cb->signal_connect (clicked => sub {
564 handle_bool_value ($w, $e, \$$vhash{$name});
566 set_widget_hint ($cb, $$hash{$key}[DESC]);
567 set_widget_sens ($cb, $$hash{$key}[CMVER]);
569 return new_hbox_spaced_pack ($cb);
572 sub new_text_box_for_int($$$) {
573 my ($hash, $key, $vhash) = @_;
574 my $name = $$hash{$key}[NAME];
575 my $label = $$hash{$key}[LABEL];
576 my @type = split (/,/, $$hash{$key}[TYPE]);
577 push (@type, 0), push (@type, 10000) unless ($#type > 0);
580 if (ref $label eq 'ARRAY') {
581 $gunits = Gtk3::Label->new ($label->[1]);
582 $label = $label->[0];
584 my $glabel = Gtk3::Label->new ($label);
585 my $pagei = int (($type[2] - $type[1]) / 10);
586 my $gentry = Gtk3::SpinButton->new_with_range ($type[1], $type[2], $pagei);
587 my $value = $$vhash{$name}[VALUE];
588 $value //= $$hash{$key}[CMDEF];
589 $gentry->set_numeric (TRUE);
590 $gentry->set_value ($value);
591 $gentry->signal_connect('value-changed' => sub {
593 handle_int_value ($w, $e, \$$vhash{$name});
595 set_widget_hint ($gentry, $$hash{$key}[DESC]);
596 set_widget_sens ($gentry, $$hash{$key}[CMVER]);
597 $glabel->set_sensitive ($gentry->get_sensitive);
598 $gunits->set_sensitive ($gentry->get_sensitive) if ($gunits);
600 return new_hbox_spaced_pack ($glabel, $gentry, $gunits) if ($gunits);
601 return new_hbox_spaced_pack ($glabel, $gentry);
604 sub new_text_box_for_nchar($$$) {
605 my ($hash, $key, $vhash) = @_;
606 my $name = $$hash{$key}[NAME];
607 my $label = $$hash{$key}[LABEL];
608 my @type = split (/,/, $$hash{$key}[TYPE]); # char,minlen,maxlen,width
609 my $glabel = Gtk3::Label->new ($label);
610 my $gentry = Gtk3::Entry->new ();
611 $gentry->set_max_length($type[2]) if defined ($type[2]);
612 my $width = $type[3];
614 $gentry->set_width_chars(int ($width) + 2) if defined ($width);
615 my $value = $$vhash{$name}[VALUE];
616 $value //= $$hash{$key}[CMDEF];
617 $gentry->set_text ($value);
618 $gentry->signal_connect('key-release-event' => sub {
620 handle_nchar_value ($w, $e, \$$vhash{$name}, $type[1], $type[2]);
622 set_widget_hint ($gentry, $$hash{$key}[DESC]);
623 set_widget_sens ($gentry, $$hash{$key}[CMVER]);
624 $glabel->set_sensitive ($gentry->get_sensitive);
626 return new_hbox_spaced_pack ($glabel, $gentry);
629 sub new_color_button_for($$$) {
630 my ($hash, $key, $vhash) = @_;
631 my $name = $$hash{$key}[NAME];
632 my $label = $$hash{$key}[LABEL];
634 my $value = $$vhash{$name}[VALUE];
635 $value //= $$hash{$key}[CMDEF];
636 my $col = gdk_rgba_from_str ($value);
637 my $glabel = Gtk3::Label->new ($label);
638 my $button = Gtk3::ColorButton->new_with_rgba ($col);
639 $button->set_title ($label);
640 $button->set_relief ('none');
641 $button->signal_connect ('color-set' => sub {
643 handle_color_value ($w, $e, \$$vhash{$name});
645 set_widget_hint ($button, $$hash{$key}[DESC]);
646 set_widget_sens ($button, $$hash{$key}[CMVER]);
647 $glabel->set_sensitive ($button->get_sensitive);
649 return new_hbox_spaced_pack ($button, $glabel);
652 sub new_selection_box_for($$$) {
653 my ($hash, $key, $vhash) = @_;
654 my $name = $$hash{$key}[NAME];
655 my $label = $$hash{$key}[LABEL];
657 my $glabel = Gtk3::Label->new ($label);
658 my $combo = Gtk3::ComboBoxText->new;
659 my @options = split (';', $$hash{$key}[TYPE]);
660 foreach my $opt (@options) {
661 my ($index, $textkey) = split ('=', $opt);
662 $combo->insert (-1, $index, $xl::s{$textkey});
664 $combo->signal_connect ('changed' => sub {
666 handle_selection_value ($w, $e, \$$vhash{$name});
668 my $value = $$vhash{$name}[VALUE];
669 $value //= $$hash{$key}[CMDEF];
670 $combo->set_active ($value);
671 set_widget_hint ($combo, $$hash{$key}[DESC]);
672 set_widget_sens ($combo, $$hash{$key}[CMVER]);
673 $glabel->set_sensitive ($combo->get_sensitive);
675 return new_hbox_spaced_pack ($glabel, $combo);
678 # more graphic helpers
681 my $hbox = Gtk3::HBox->new (FALSE);
682 $hbox->set_border_width (PAGE_SPC);
684 $hbox->pack_start ($_, FALSE, FALSE, 0);
689 sub new_hbox_pack_compact {
690 my $hbox = Gtk3::HBox->new (FALSE);
691 $hbox->set_border_width (0);
693 $hbox->pack_start ($_, FALSE, FALSE, 0);
699 my $vbox = Gtk3::VBox->new (FALSE, 5);
700 $vbox->set_border_width (PAGE_SPC);
702 $vbox->pack_start ($_, FALSE, FALSE, 0);
707 sub new_vbox_pack_compact {
708 my $vbox = Gtk3::VBox->new (FALSE, 0);
709 $vbox->set_border_width (0);
711 $vbox->pack_start ($_, FALSE, FALSE, 0);
716 sub new_subpage_frame {
717 my ($box, $title, $notpacked) = @_;
718 my $frame = Gtk3::Frame->new ($title);
720 return new_vbox_pack ($frame) unless defined ($notpacked);
724 # preference maps and corresponding page creation subs
726 %pr::oth = ( # other preferences
728 'addressbook_use_editaddress_dialog',
729 $xl::s{l_oth_use_dlg},
730 $xl::s{h_oth_use_dlg},
736 'cache_max_mem_usage',
737 [ $xl::s{l_oth_max_use}, $xl::s{l_oth_max_use_units} ],
738 $xl::s{h_oth_max_use},
739 'int,0,524288', # 0 Kb - 512 Mb
744 'cache_min_keep_time',
745 [ $xl::s{l_oth_min_time}, $xl::s{l_oth_min_time_units} ],
746 $xl::s{h_oth_min_time},
747 'int,0,120', # 0 minutes - 2 hours
752 'use_networkmanager',
753 $xl::s{l_oth_use_netm},
754 $xl::s{h_oth_use_netm},
760 'master_passphrase_pbkdf2_rounds',
761 $xl::s{l_oth_mp_rounds},
762 $xl::s{h_oth_mp_rounds},
769 sub new_other_page() {
770 return new_vbox_pack (
773 new_check_button_for(\%pr::oth, 'use_dlg', \%HPVALUE)),
774 $xl::s{ab_frame}, 'not-packed'),
777 new_text_box_for_int(\%pr::oth, 'max_use', \%HPVALUE),
778 new_text_box_for_int(\%pr::oth, 'min_time', \%HPVALUE)),
779 $xl::s{mem_frame}, 'not-packed'),
782 new_check_button_for(\%pr::oth, 'use_netm', \%HPVALUE)),
783 $xl::s{netm_frame}, 'not-packed'),
786 new_text_box_for_int(\%pr::oth, 'mp_rounds', \%HPVALUE)),
787 $xl::s{mpass_frame}, 'not-packed')
791 %pr::gui = ( # gui bells and whistles
794 $xl::s{l_gui_b_unread},
795 $xl::s{h_gui_b_unread},
802 $xl::s{l_gui_no_markup},
803 $xl::s{h_gui_no_markup},
809 'enable_dotted_lines',
810 $xl::s{l_gui_dot_lines},
811 $xl::s{h_gui_dot_lines},
813 '2.4.0.115,3.7.10.44',
818 $xl::s{l_gui_h_scroll},
819 $xl::s{h_gui_h_scroll},
826 $xl::s{l_gui_swp_from},
827 $xl::s{h_gui_swp_from},
833 'folderview_vscrollbar_policy',
834 $xl::s{l_gui_v_scroll},
835 $xl::s{h_gui_v_scroll},
836 '0=l_gui_v_scroll_show;1=l_gui_v_scroll_auto;2=l_gui_v_scroll_hide',
842 $xl::s{l_gui_from_show},
843 $xl::s{h_gui_from_show},
844 '0=l_gui_from_show_name;1=l_gui_from_show_addr;2=l_gui_from_show_both',
849 'stripes_color_offset',
850 $xl::s{l_gui_strip_off},
851 $xl::s{h_gui_strip_off},
852 'int,0,40000', # no idea what this number means
857 'textview_cursor_visible',
858 $xl::s{l_gui_cursor_v},
859 $xl::s{h_gui_cursor_v},
865 'toolbar_detachable',
866 $xl::s{l_gui_toolbar_d},
867 $xl::s{h_gui_toolbar_d},
873 'use_stripes_everywhere',
874 $xl::s{l_gui_strip_all},
875 $xl::s{h_gui_strip_all},
881 'use_stripes_in_summaries',
882 $xl::s{l_gui_strip_sum},
883 $xl::s{h_gui_strip_sum},
890 $xl::s{l_gui_two_line_v},
891 $xl::s{h_gui_two_line_v},
897 'show_compose_margin',
898 $xl::s{l_gui_margin_co},
899 $xl::s{h_gui_margin_co},
905 'msgview_date_format',
906 $xl::s{l_gui_mview_date},
907 $xl::s{h_gui_mview_date},
913 'zero_replacement_char',
914 $xl::s{l_gui_zero_char},
915 $xl::s{h_gui_zero_char},
922 $xl::s{l_gui_type_any},
923 $xl::s{h_gui_type_any},
929 'warn_sending_many_recipients_num',
930 [ $xl::s{l_gui_warn_send_multi}, $xl::s{l_gui_warn_send_multi_units} ],
931 $xl::s{h_gui_warn_send_multi},
938 $xl::s{l_gui_next_del},
939 $xl::s{h_gui_next_del},
947 my $gf = Gtk3::VBox->new (FALSE, 5);
948 $gf->set_border_width (PAGE_SPC);
950 my $cb_dot_lines = new_check_button_for (\%pr::gui, 'dot_lines', \%HPVALUE);
951 my $cb_toolbar_d = new_check_button_for (\%pr::gui, 'toolbar_d', \%HPVALUE);
952 my $tb_zero_char = new_text_box_for_nchar (\%pr::gui, 'zero_char', \%HPVALUE);
954 $gf->pack_start (new_subpage_frame (
956 new_check_button_for (\%pr::gui, 'strip_all', \%HPVALUE),
957 new_check_button_for (\%pr::gui, 'strip_sum', \%HPVALUE),
958 new_text_box_for_int (\%pr::gui, 'strip_off', \%HPVALUE)),
959 $xl::s{stripes_frame}, 'not-packed'),
960 FALSE, FALSE, FRAME_SPC);
961 $gf->pack_start (new_subpage_frame (
963 new_check_button_for (\%pr::gui, 'b_unread', \%HPVALUE),
964 new_check_button_for (\%pr::gui, 'swp_from', \%HPVALUE),
965 new_check_button_for (\%pr::gui, 'two_linev', \%HPVALUE),
966 new_check_button_for (\%pr::gui, 'next_del', \%HPVALUE),
967 new_selection_box_for (\%pr::gui, 'from_show', \%HPVALUE)),
968 $xl::s{mlist_frame}, 'not-packed'),
969 FALSE, FALSE, FRAME_SPC);
970 $gf->pack_start (new_subpage_frame (
972 new_check_button_for (\%pr::gui, 'cursor_v', \%HPVALUE),
973 new_check_button_for (\%pr::gui, 'mview_date', \%HPVALUE)),
974 $xl::s{mview_frame}, 'not-packed'),
975 FALSE, FALSE, FRAME_SPC);
976 $gf->pack_start (new_subpage_frame (
978 new_hbox_pack_compact (
979 new_check_button_for (\%pr::gui, 'no_markup', \%HPVALUE),
980 new_check_button_for (\%pr::gui, 'margin_co', \%HPVALUE),
981 new_check_button_for (\%pr::gui, 'type_any', \%HPVALUE)),
982 new_text_box_for_int (\%pr::gui, 'warn_send_multi', \%HPVALUE)),
983 $xl::s{compo_frame}, 'not-packed'),
984 FALSE, FALSE, FRAME_SPC);
985 $gf->pack_start ($cb_dot_lines, FALSE, FALSE, 0);
986 $gf->pack_start ($cb_toolbar_d, FALSE, FALSE, 0);
987 $gf->pack_start (new_subpage_frame (
989 new_check_button_for (\%pr::gui, 'h_scroll', \%HPVALUE),
990 new_selection_box_for (\%pr::gui, 'v_scroll', \%HPVALUE)),
991 $xl::s{sbar_frame}, 'not-packed'),
992 FALSE, FALSE, FRAME_SPC);
993 $gf->pack_start ($tb_zero_char, FALSE, FALSE, 0);
998 %pr::beh = ( # tweak some behaviour
1001 [ $xl::s{l_beh_hover_t}, $xl::s{l_beh_hover_t_units} ],
1002 $xl::s{h_beh_hover_t},
1003 'int,100,3000', # 0.1 seconds - 3 seconds
1009 $xl::s{l_beh_dangerous},
1010 $xl::s{h_beh_dangerous},
1016 'respect_flowed_format',
1017 $xl::s{l_beh_flowed},
1018 $xl::s{h_beh_flowed},
1024 'save_parts_readwrite',
1025 $xl::s{l_beh_parts_rw},
1026 $xl::s{h_beh_parts_rw},
1032 'skip_ssl_cert_check',
1033 $xl::s{l_beh_skip_ssl},
1034 $xl::s{h_beh_skip_ssl},
1040 'statusbar_update_step',
1041 [ $xl::s{l_beh_up_step}, $xl::s{l_beh_up_step_units} ],
1042 $xl::s{h_beh_up_step},
1043 'int,1,200', # 1 item - 200 items
1048 'thread_by_subject_max_age',
1049 [ $xl::s{l_beh_thread_a}, $xl::s{l_beh_thread_a_units} ],
1050 $xl::s{h_beh_thread_a},
1051 'int,1,30', # 1 day - 30 days
1057 $xl::s{l_beh_unsafe_ssl},
1058 $xl::s{h_beh_unsafe_ssl},
1064 'utf8_instead_of_locale_for_broken_mail',
1065 $xl::s{l_beh_use_utf8},
1066 $xl::s{h_beh_use_utf8},
1073 $xl::s{l_beh_warn_dnd},
1074 $xl::s{h_beh_warn_dnd},
1080 'outgoing_fallback_to_ascii',
1081 $xl::s{l_beh_out_ascii},
1082 $xl::s{h_beh_out_ascii},
1088 'primary_paste_unselects',
1089 $xl::s{l_beh_pp_unsel},
1090 $xl::s{h_beh_pp_unsel},
1096 'show_inline_attachments',
1097 $xl::s{l_beh_inline_at},
1098 $xl::s{h_beh_inline_at},
1104 'address_search_wildcard',
1105 $xl::s{l_beh_addr_swc},
1106 $xl::s{h_beh_addr_swc},
1112 'folder_search_wildcard',
1113 $xl::s{l_beh_fold_swc},
1114 $xl::s{h_beh_fold_swc},
1120 'rewrite_first_from',
1121 $xl::s{l_beh_rewrite_ff},
1122 $xl::s{h_beh_rewrite_ff},
1129 sub new_behaviour_page() {
1130 my $bf = Gtk3::VBox->new (FALSE, 5);
1131 $bf->set_border_width (PAGE_SPC);
1133 my $tb_up_step = new_text_box_for_int (\%pr::beh, 'up_step', \%HPVALUE);
1134 my $tb_thread_a = new_text_box_for_int (\%pr::beh, 'thread_a', \%HPVALUE);
1136 $bf->pack_start (new_subpage_frame (
1138 new_text_box_for_int (\%pr::beh, 'hover_t', \%HPVALUE),
1139 new_check_button_for (\%pr::beh, 'warn_dnd', \%HPVALUE)),
1140 $xl::s{dnd_frame}, 'not-packed'),
1141 FALSE, FALSE, FRAME_SPC);
1142 $bf->pack_start (new_subpage_frame (
1144 new_check_button_for (\%pr::beh, 'skip_ssl', \%HPVALUE),
1145 new_check_button_for (\%pr::beh, 'unsafe_ssl', \%HPVALUE)),
1146 $xl::s{ssl_frame}, 'not-packed'),
1147 FALSE, FALSE, FRAME_SPC);
1148 $bf->pack_start ($tb_up_step, FALSE, FALSE, 0);
1149 $bf->pack_start ($tb_thread_a, FALSE, FALSE, 0);
1150 $bf->pack_start (new_subpage_frame (
1152 new_check_button_for (\%pr::beh, 'flowed', \%HPVALUE),
1153 new_check_button_for (\%pr::beh, 'parts_rw', \%HPVALUE),
1154 new_check_button_for (\%pr::beh, 'use_utf8', \%HPVALUE),
1155 new_check_button_for (\%pr::beh, 'dangerous', \%HPVALUE),
1156 new_check_button_for (\%pr::beh, 'out_ascii', \%HPVALUE),
1157 new_check_button_for (\%pr::beh, 'pp_unsel', \%HPVALUE),
1158 new_check_button_for (\%pr::beh, 'inline_at', \%HPVALUE),
1159 new_check_button_for (\%pr::beh, 'rewrite_ff', \%HPVALUE)),
1160 $xl::s{msgs_frame}, 'not-packed'),
1161 FALSE, FALSE, FRAME_SPC);
1162 $bf->pack_start (new_subpage_frame (
1164 new_check_button_for (\%pr::beh, 'addr_swc', \%HPVALUE),
1165 new_check_button_for (\%pr::beh, 'fold_swc', \%HPVALUE)),
1166 $xl::s{swc_frame}, 'not-packed'),
1167 FALSE, FALSE, FRAME_SPC);
1171 %pr::col = ( # a variety of colours
1174 $xl::s{l_col_emphasis},
1175 $xl::s{h_col_emphasis},
1182 $xl::s{l_col_log_err},
1183 $xl::s{h_col_log_err},
1190 $xl::s{l_col_log_in},
1191 $xl::s{h_col_log_in},
1198 $xl::s{l_col_log_msg},
1199 $xl::s{h_col_log_msg},
1206 $xl::s{l_col_log_out},
1207 $xl::s{h_col_log_out},
1214 $xl::s{l_col_log_warn},
1215 $xl::s{h_col_log_warn},
1222 $xl::s{l_col_diff_add},
1223 $xl::s{h_col_diff_add},
1229 'diff_deleted_color',
1230 $xl::s{l_col_diff_del},
1231 $xl::s{h_col_diff_del},
1238 $xl::s{l_col_diff_hunk},
1239 $xl::s{h_col_diff_hunk},
1246 $xl::s{l_col_tags_bg},
1247 $xl::s{h_col_tags_bg},
1254 $xl::s{l_col_tags_text},
1255 $xl::s{h_col_tags_text},
1260 default_header_bg => [
1261 'default_header_bgcolor',
1262 $xl::s{l_col_default_header_bg},
1263 $xl::s{h_col_default_header_bg},
1268 default_header_text => [
1269 'default_header_color',
1270 $xl::s{l_col_default_header_text},
1271 $xl::s{h_col_default_header_text},
1277 'qs_active_bgcolor',
1278 $xl::s{l_col_qs_active_bg},
1279 $xl::s{h_col_qs_active_bg},
1286 $xl::s{l_col_qs_active_text},
1287 $xl::s{h_col_qs_active_text},
1294 $xl::s{l_col_qs_error_bg},
1295 $xl::s{h_col_qs_error_bg},
1302 $xl::s{l_col_qs_error_text},
1303 $xl::s{h_col_qs_error_text},
1310 sub new_colours_page() {
1311 return new_vbox_pack (
1314 new_color_button_for (\%pr::col, 'emphasis', \%HPVALUE),
1315 new_hbox_pack_compact (
1316 new_color_button_for (\%pr::col, 'tags_text', \%HPVALUE),
1317 new_color_button_for (\%pr::col, 'tags_bg', \%HPVALUE))),
1318 $xl::s{msgview_frame}, 'not-packed'),
1321 new_vbox_pack_compact (
1322 new_color_button_for (\%pr::col, 'log_err', \%HPVALUE),
1323 new_color_button_for (\%pr::col, 'log_warn', \%HPVALUE),
1324 new_color_button_for (\%pr::col, 'log_msg', \%HPVALUE)),
1325 new_vbox_pack_compact (
1326 new_color_button_for (\%pr::col, 'log_in', \%HPVALUE),
1327 new_color_button_for (\%pr::col, 'log_out', \%HPVALUE))),
1328 $xl::s{log_frame}, 'not-packed'),
1331 new_color_button_for (\%pr::col, 'diff_add', \%HPVALUE),
1332 new_color_button_for (\%pr::col, 'diff_del', \%HPVALUE),
1333 new_color_button_for (\%pr::col, 'diff_hunk', \%HPVALUE)),
1334 $xl::s{diff_frame}, 'not-packed'),
1337 new_color_button_for (\%pr::col, 'default_header_text', \%HPVALUE),
1338 new_color_button_for (\%pr::col, 'default_header_bg', \%HPVALUE)),
1339 $xl::s{compose_frame}, 'not-packed'),
1342 new_vbox_pack_compact (
1343 new_color_button_for (\%pr::col, 'qs_active_text', \%HPVALUE),
1344 new_color_button_for (\%pr::col, 'qs_error_text', \%HPVALUE)),
1345 new_vbox_pack_compact (
1346 new_color_button_for (\%pr::col, 'qs_active_bg', \%HPVALUE),
1347 new_color_button_for (\%pr::col, 'qs_error_bg', \%HPVALUE))),
1348 $xl::s{qs_frame}, 'not-packed')
1352 %pr::win = ( # tweak window positions and/or sizes
1357 'int,0,3000', # 0 pixels - 3000 pixels
1365 'int,0,3000', # 0 pixels - 3000 pixels
1373 'int,0,3000', # 0 pixels - 3000 pixels
1381 'int,0,3000', # 0 pixels - 3000 pixels
1386 'mainwin_maximised',
1387 $xl::s{l_win_main_mx},
1388 $xl::s{h_win_main_mx},
1394 'mainwin_fullscreen',
1395 $xl::s{l_win_main_fs},
1396 $xl::s{h_win_main_fs},
1402 'main_messagewin_x',
1405 'int,0,3000', # 0 pixels - 3000 pixels
1410 'main_messagewin_y',
1413 'int,0,3000', # 0 pixels - 3000 pixels
1421 'int,0,3000', # 0 pixels - 3000 pixels
1426 'messagewin_height',
1429 'int,0,3000', # 0 pixels - 3000 pixels
1437 'int,0,3000', # 0 pixels - 3000 pixels
1445 'int,0,3000', # 0 pixels - 3000 pixels
1453 'int,0,3000', # 0 pixels - 3000 pixels
1458 'receivewin_height',
1461 'int,0,3000', # 0 pixels - 3000 pixels
1469 'int,0,3000', # 0 pixels - 3000 pixels
1477 'int,0,3000', # 0 pixels - 3000 pixels
1482 'folderitemwin_width',
1485 'int,0,3000', # 0 pixels - 3000 pixels
1490 'folderitemwin_height',
1493 'int,0,3000', # 0 pixels - 3000 pixels
1498 'folderselwin_width',
1501 'int,0,3000', # 0 pixels - 3000 pixels
1506 'folderselwin_height',
1509 'int,0,3000', # 0 pixels - 3000 pixels
1517 'int,0,3000', # 0 pixels - 3000 pixels
1525 'int,0,3000', # 0 pixels - 3000 pixels
1530 'addressbookwin_width',
1533 'int,0,3000', # 0 pixels - 3000 pixels
1538 'addressbookwin_height',
1541 'int,0,3000', # 0 pixels - 3000 pixels
1546 'addressbookeditpersonwin_width',
1549 'int,0,3000', # 0 pixels - 3000 pixels
1554 'addressbookeditpersonwin_height',
1557 'int,0,3000', # 0 pixels - 3000 pixels
1562 'addressbookeditgroupwin_width',
1565 'int,0,3000', # 0 pixels - 3000 pixels
1570 'addressbookeditgroupwin_height',
1573 'int,0,3000', # 0 pixels - 3000 pixels
1578 'addressaddwin_width',
1581 'int,0,3000', # 0 pixels - 3000 pixels
1586 'addressaddwin_height',
1589 'int,0,3000', # 0 pixels - 3000 pixels
1594 'addressbook_folderselwin_width',
1597 'int,0,3000', # 0 pixels - 3000 pixels
1602 'addressbook_folderselwin_height',
1605 'int,0,3000', # 0 pixels - 3000 pixels
1610 'editaccountwin_width',
1613 'int,0,3000', # 0 pixels - 3000 pixels
1618 'editaccountwin_height',
1621 'int,0,3000', # 0 pixels - 3000 pixels
1626 'accountswin_width',
1629 'int,0,3000', # 0 pixels - 3000 pixels
1634 'accountswin_height',
1637 'int,0,3000', # 0 pixels - 3000 pixels
1642 'filteringwin_width',
1645 'int,0,3000', # 0 pixels - 3000 pixels
1650 'filteringwin_height',
1653 'int,0,3000', # 0 pixels - 3000 pixels
1658 'filteringactionwin_width',
1661 'int,0,3000', # 0 pixels - 3000 pixels
1666 'filteringactionwin_height',
1669 'int,0,3000', # 0 pixels - 3000 pixels
1674 'filtering_debugwin_width',
1677 'int,0,3000', # 0 pixels - 3000 pixels
1682 'filtering_debugwin_height',
1685 'int,0,3000', # 0 pixels - 3000 pixels
1693 'int,0,3000', # 0 pixels - 3000 pixels
1698 'matcherwin_height',
1701 'int,0,3000', # 0 pixels - 3000 pixels
1709 'int,0,3000', # 0 pixels - 3000 pixels
1717 'int,0,3000', # 0 pixels - 3000 pixels
1722 'templateswin_width',
1725 'int,0,3000', # 0 pixels - 3000 pixels
1730 'templateswin_height',
1733 'int,0,3000', # 0 pixels - 3000 pixels
1741 'int,0,3000', # 0 pixels - 3000 pixels
1746 'actionswin_height',
1749 'int,0,3000', # 0 pixels - 3000 pixels
1754 'actionsiodialog_width',
1757 'int,0,3000', # 0 pixels - 3000 pixels
1762 'actionsiodialog_height',
1765 'int,0,3000', # 0 pixels - 3000 pixels
1773 'int,0,3000', # 0 pixels - 3000 pixels
1781 'int,0,3000', # 0 pixels - 3000 pixels
1789 'int,0,3000', # 0 pixels - 3000 pixels
1794 'pluginswin_height',
1797 'int,0,3000', # 0 pixels - 3000 pixels
1805 'int,0,3000', # 0 pixels - 3000 pixels
1813 'int,0,3000', # 0 pixels - 3000 pixels
1818 'print_previewwin_width',
1821 'int,0,3000', # 0 pixels - 3000 pixels
1826 'print_previewwin_height',
1829 'int,0,3000', # 0 pixels - 3000 pixels
1835 sub new_winpos_subpage_main() {
1836 return new_subpage_frame (
1837 new_vbox_pack_compact (
1839 new_text_box_for_int (\%pr::win, 'main_x', \%HPVALUE),
1840 new_text_box_for_int (\%pr::win, 'main_y', \%HPVALUE)),
1842 new_text_box_for_int (\%pr::win, 'main_w', \%HPVALUE),
1843 new_text_box_for_int (\%pr::win, 'main_h', \%HPVALUE)),
1845 new_check_button_for (\%pr::win, 'main_fs', \%HPVALUE),
1846 new_check_button_for (\%pr::win, 'main_mx', \%HPVALUE))),
1851 sub new_winpos_subpage_msgs() {
1852 return new_subpage_frame (
1853 new_vbox_pack_compact (
1855 new_text_box_for_int (\%pr::win, 'msgs_x', \%HPVALUE),
1856 new_text_box_for_int (\%pr::win, 'msgs_y', \%HPVALUE)),
1858 new_text_box_for_int (\%pr::win, 'msgs_w', \%HPVALUE),
1859 new_text_box_for_int (\%pr::win, 'msgs_h', \%HPVALUE))),
1864 sub new_winpos_subpage_sendrecv() {
1865 return new_vbox_pack (
1868 new_text_box_for_int (\%pr::win, 'send_w', \%HPVALUE),
1869 new_text_box_for_int (\%pr::win, 'send_h', \%HPVALUE)),
1870 _('Send window'), 'not-packed'),
1873 new_text_box_for_int (\%pr::win, 'recv_w', \%HPVALUE),
1874 new_text_box_for_int (\%pr::win, 'recv_h', \%HPVALUE)),
1875 _('Receive window'), 'not-packed')
1879 sub new_winpos_subpage_fold() {
1880 return new_vbox_pack (
1882 new_vbox_pack_compact (
1884 new_text_box_for_int (\%pr::win, 'fold_x', \%HPVALUE),
1885 new_text_box_for_int (\%pr::win, 'fold_y', \%HPVALUE)),
1887 new_text_box_for_int (\%pr::win, 'fold_w', \%HPVALUE),
1888 new_text_box_for_int (\%pr::win, 'fold_h', \%HPVALUE))),
1889 _('Folder window'), 'not-packed'),
1892 new_text_box_for_int (\%pr::win, 'fsel_w', \%HPVALUE),
1893 new_text_box_for_int (\%pr::win, 'fsel_h', \%HPVALUE)),
1894 _('Folder selection window'), 'not-packed')
1898 sub new_winpos_subpage_addrbook() {
1899 return new_vbox_pack (
1902 new_text_box_for_int (\%pr::win, 'addr_w', \%HPVALUE),
1903 new_text_box_for_int (\%pr::win, 'addr_h', \%HPVALUE)),
1904 _('Addressbook main window'), 'not-packed'),
1907 new_text_box_for_int (\%pr::win, 'adep_w', \%HPVALUE),
1908 new_text_box_for_int (\%pr::win, 'adep_h', \%HPVALUE)),
1909 _('Edit person window'), 'not-packed'),
1912 new_text_box_for_int (\%pr::win, 'adeg_w', \%HPVALUE),
1913 new_text_box_for_int (\%pr::win, 'adeg_h', \%HPVALUE)),
1914 _('Edit group window'), 'not-packed'),
1917 new_text_box_for_int (\%pr::win, 'adda_w', \%HPVALUE),
1918 new_text_box_for_int (\%pr::win, 'adda_h', \%HPVALUE)),
1919 _('Add address window'), 'not-packed'),
1922 new_text_box_for_int (\%pr::win, 'addf_w', \%HPVALUE),
1923 new_text_box_for_int (\%pr::win, 'addf_h', \%HPVALUE)),
1924 _('Folder select window'), 'not-packed')
1928 sub new_winpos_subpage_accounts() {
1929 return new_vbox_pack (
1932 new_text_box_for_int (\%pr::win, 'acco_w', \%HPVALUE),
1933 new_text_box_for_int (\%pr::win, 'acco_h', \%HPVALUE)),
1934 _('Accounts window'), 'not-packed'),
1937 new_text_box_for_int (\%pr::win, 'acce_w', \%HPVALUE),
1938 new_text_box_for_int (\%pr::win, 'acce_h', \%HPVALUE)),
1939 _('Edit account window'), 'not-packed')
1943 sub new_winpos_subpage_filtering() {
1944 return new_vbox_pack (
1947 new_text_box_for_int (\%pr::win, 'filt_w', \%HPVALUE),
1948 new_text_box_for_int (\%pr::win, 'filt_h', \%HPVALUE)),
1949 _('Filtering window'), 'not-packed'),
1952 new_text_box_for_int (\%pr::win, 'fila_w', \%HPVALUE),
1953 new_text_box_for_int (\%pr::win, 'fila_h', \%HPVALUE)),
1954 _('Filtering actions window'), 'not-packed'),
1957 new_text_box_for_int (\%pr::win, 'fild_w', \%HPVALUE),
1958 new_text_box_for_int (\%pr::win, 'fild_h', \%HPVALUE)),
1959 _('Filtering debug window'), 'not-packed'),
1962 new_text_box_for_int (\%pr::win, 'matc_w', \%HPVALUE),
1963 new_text_box_for_int (\%pr::win, 'matc_h', \%HPVALUE)),
1964 _('Matcher window'), 'not-packed')
1968 sub new_winpos_subpage_useractions() {
1969 return new_vbox_pack (
1972 new_text_box_for_int (\%pr::win, 'acti_w', \%HPVALUE),
1973 new_text_box_for_int (\%pr::win, 'acti_h', \%HPVALUE)),
1974 _('User Actions prefs window'), 'not-packed'),
1977 new_text_box_for_int (\%pr::win, 'acio_w', \%HPVALUE),
1978 new_text_box_for_int (\%pr::win, 'acio_h', \%HPVALUE)),
1979 _('User Actions I/O window'), 'not-packed')
1983 sub new_winpos_subpage_prefs() {
1984 return new_vbox_pack (
1987 new_text_box_for_int (\%pr::win, 'pref_w', \%HPVALUE),
1988 new_text_box_for_int (\%pr::win, 'pref_h', \%HPVALUE)),
1989 _('Preferences window'), 'not-packed'),
1992 new_text_box_for_int (\%pr::win, 'temp_w', \%HPVALUE),
1993 new_text_box_for_int (\%pr::win, 'temp_h', \%HPVALUE)),
1994 _('Templates window'), 'not-packed'),
1997 new_text_box_for_int (\%pr::win, 'tags_w', \%HPVALUE),
1998 new_text_box_for_int (\%pr::win, 'tags_h', \%HPVALUE)),
1999 _('Tags window'), 'not-packed'),
2002 new_text_box_for_int (\%pr::win, 'plug_w', \%HPVALUE),
2003 new_text_box_for_int (\%pr::win, 'plug_h', \%HPVALUE)),
2004 _('Plugins window'), 'not-packed')
2008 sub new_winpos_subpage_misc() {
2009 return new_vbox_pack (
2012 new_text_box_for_int (\%pr::win, 'logw_w', \%HPVALUE),
2013 new_text_box_for_int (\%pr::win, 'logw_h', \%HPVALUE)),
2014 _('Log window'), 'not-packed'),
2017 new_text_box_for_int (\%pr::win, 'prin_w', \%HPVALUE),
2018 new_text_box_for_int (\%pr::win, 'prin_h', \%HPVALUE)),
2019 _('Print preview window'), 'not-packed'),
2022 new_text_box_for_int (\%pr::win, 'sour_w', \%HPVALUE),
2023 new_text_box_for_int (\%pr::win, 'sour_h', \%HPVALUE)),
2024 _('View source window'), 'not-packed')
2028 sub new_winpos_page() {
2029 my $winbook = Gtk3::Notebook->new;
2030 $winbook->set_tab_pos ('right');
2031 $winbook->append_page (new_winpos_subpage_main,
2032 Gtk3::Label->new (_('Main')));
2033 $winbook->append_page (new_winpos_subpage_msgs,
2034 Gtk3::Label->new (_('Message')));
2035 $winbook->append_page (new_winpos_subpage_sendrecv,
2036 Gtk3::Label->new (_('Send/Receive')));
2037 $winbook->append_page (new_winpos_subpage_fold,
2038 Gtk3::Label->new (_('Folder')));
2039 $winbook->append_page (new_winpos_subpage_addrbook,
2040 Gtk3::Label->new (_('Addressbook')));
2041 $winbook->append_page (new_winpos_subpage_accounts,
2042 Gtk3::Label->new (_('Accounts')));
2043 $winbook->append_page (new_winpos_subpage_filtering,
2044 Gtk3::Label->new (_('Filtering')));
2045 $winbook->append_page (new_winpos_subpage_useractions,
2046 Gtk3::Label->new (_('User Actions')));
2047 $winbook->append_page (new_winpos_subpage_prefs,
2048 Gtk3::Label->new (_('Preferences')));
2049 $winbook->append_page (new_winpos_subpage_misc,
2050 Gtk3::Label->new (_('Other')));
2054 %pr::acc = ( # per account hidden preferences
2056 'gnutls_set_priority',
2057 $xl::s{l_acc_gtls_set},
2058 $xl::s{h_acc_gtls_set},
2065 $xl::s{l_acc_gtls_pri},
2066 $xl::s{h_acc_gtls_pri},
2073 sub new_account_subpage($) {
2075 return new_vbox_pack (
2078 new_check_button_for (\%pr::acc, 'tls_set', $ACHPVALUE{$akey}),
2079 new_text_box_for_nchar (\%pr::acc, 'tls_pri', $ACHPVALUE{$akey})),
2080 _('GnuTLS priority'), 'not-packed')
2084 sub new_accounts_page() {
2085 my $accbook = Gtk3::Notebook->new;
2086 $accbook->set_tab_pos ('right');
2088 $ACPREFS{$a}{'account_name'} cmp $ACPREFS{$b}{'account_name'}
2091 my $name = $ACPREFS{$_}{'account_name'};
2092 my $isdef = ($ACPREFS{$_}{'is_default'} eq '1');
2093 my $page = new_account_subpage ($_);
2094 $accbook->append_page ($page,
2095 Gtk3::Label->new ($isdef? '<b>' . $name . '</b>': $name));
2097 my $label = $accbook->get_tab_label ($page);
2098 $label->set_use_markup (TRUE);
2101 $accbook->set_scrollable (TRUE);
2105 %pr::plu = ( # plugins hidden preferences
2111 'int,0,3000', # 0 pixels - 3000 pixels
2120 'int,0,3000', # 0 pixels - 3000 pixels
2127 'autocompletion_limit',
2128 $xl::s{l_plu_gpg_alimit},
2129 $xl::s{h_plu_gpg_alimit},
2137 'manager_win_width',
2140 'int,0,3000', # 0 pixels - 3000 pixels
2146 'manager_win_height',
2149 'int,0,3000', # 0 pixels - 3000 pixels
2157 $xl::s{l_plu_lav_burl},
2158 $xl::s{h_plu_lav_burl},
2161 'http://cdn.libravatar.org/avatar',
2166 'filter_log_verbosity',
2167 $xl::s{l_plu_prl_flvb},
2168 $xl::s{h_plu_prl_flvb},
2169 '0=l_plu_prl_none;1=l_plu_prl_manual;2=l_plu_prl_action;3=l_plu_prl_match',
2176 sub new_plugins_page() {
2178 $frame{'AttRemover'} =
2181 new_text_box_for_int (\%pr::plu, 'arm_winw', $PLHPVALUE{'AttRemover'}),
2182 new_text_box_for_int (\%pr::plu, 'arm_winh', $PLHPVALUE{'AttRemover'})),
2183 _('Attachment remover'), 'not-packed');
2187 new_text_box_for_int (\%pr::plu, 'gpg_alimit', $PLHPVALUE{'GPG'})),
2188 _('GPG'), 'not-packed');
2189 $frame{'ManageSieve'} =
2192 new_text_box_for_int (\%pr::plu, 'msv_winw', $PLHPVALUE{'ManageSieve'}),
2193 new_text_box_for_int (\%pr::plu, 'msv_winh', $PLHPVALUE{'ManageSieve'})),
2194 _('Sieve manager'), 'not-packed');
2195 $frame{'Libravatar'} =
2198 new_text_box_for_nchar (\%pr::plu, 'lav_burl', $PLHPVALUE{'Libravatar'})),
2199 _('Libravatar'), 'not-packed');
2200 $frame{'PerlPlugin'} =
2203 new_selection_box_for (\%pr::plu, 'prl_flvb', $PLHPVALUE{'PerlPlugin'})),
2204 _('Perl'), 'not-packed');
2205 foreach (@PLUGINS) {
2206 $frame{$_}->set_sensitive (defined $PLHPVALUE{$_});
2208 return new_vbox_pack (
2209 $frame{'AttRemover'},
2211 $frame{'ManageSieve'},
2212 $frame{'Libravatar'},
2213 $frame{'PerlPlugin'});
2223 BG_LIGHTER => '#ffffff',
2224 BG_DARKER => '#eeeeee'
2227 sub new_hotkeys_list_label {
2228 my $renderer = Gtk3::CellRendererText->new ();
2229 $renderer->set_property('alignment' => 'left');
2230 $renderer->set_property('editable' => FALSE);
2234 sub new_hotkeys_list_hotkey {
2235 my $renderer = Gtk3::CellRendererAccel->new ();
2236 $renderer->set_property ('accel-mode' => 'gtk');
2237 $renderer->set_property ('editable' => TRUE);
2238 $renderer->signal_connect ('accel-edited' => sub {
2239 my ($w, $path, $key, $mods, $keycode) = @_;
2240 my $accel = Gtk3::Accelerator->name ($key, $mods);
2241 my ($model, $iter) = $SELHOTKEY->get_selected ();
2242 $model->set($iter, C_HOTKEY, "\"$accel\"");
2243 my $gkey = $model->get_value ($iter, C_GROUP);
2244 my $akey = $model->get_value ($iter, C_ACCEL);
2245 my $data = $HOTKEYS->{$gkey}->{$akey};
2246 $data->{'key'} = "\"$accel\"";
2247 $data->{'enabled'} = TRUE;
2249 $renderer->signal_connect ('accel-cleared' => sub {
2250 my ($w, $path) = @_;
2251 my ($model, $iter) = $SELHOTKEY->get_selected ();
2252 $model->set($iter, C_HOTKEY, "\"\"");
2253 my $gkey = $model->get_value ($iter, C_GROUP);
2254 my $akey = $model->get_value ($iter, C_ACCEL);
2255 my $data = $HOTKEYS->{$gkey}->{$akey};
2256 $data->{'key'} = "\"\"";
2257 $data->{'enabled'} = FALSE;
2262 sub new_hotkeys_list {
2263 my ($gkey, $group) = @_;
2264 my $store = Gtk3::ListStore->new(
2265 qw/Glib::String Glib::String Glib::String Glib::String Glib::String/);
2267 foreach my $akey (sort keys %$group) {
2268 my $iter = $store->append ();
2269 my $hotkey = $group->{$akey}->{'key'};
2271 $label =~ s/[<>]//g; # <rrsyl> and <IMAPFolder> !?
2272 my $bgcol = $even ? BG_DARKER: BG_LIGHTER;
2273 $store->set ($iter, C_LABEL, $label, C_HOTKEY, $hotkey,
2274 C_GROUP, $gkey, C_ACCEL, $akey, C_BCOLOR, $bgcol);
2277 my $treeview = Gtk3::TreeView->new_with_model ($store);
2279 $treeview->insert_column_with_data_func (
2280 0, _("Menu path"), new_hotkeys_list_label (),
2282 my ($col, $renderer, $model, $iter, $data) = @_;
2283 $renderer->set_property (
2284 'markup' => '<span size="smaller">'
2285 . $model->get_value ($iter, C_LABEL)
2287 $renderer->set_property (
2288 'background' => $model->get_value ($iter, C_BCOLOR));
2292 $treeview->insert_column_with_data_func (
2293 1, _('Hotkey'), new_hotkeys_list_hotkey (),
2295 my ($col, $renderer, $model, $iter, $data) = @_;
2296 my $hkey = $model->get_value ($iter, C_HOTKEY);
2298 my ($acckey, $accmod) = Gtk3::accelerator_parse ($hkey);
2299 $renderer->set_property ('accel-key' => $acckey);
2300 $renderer->set_property ('accel-mods' => $accmod);
2301 $renderer->set_property (
2302 'background' => $model->get_value ($iter, C_BCOLOR));
2305 # callback for saving current selection
2306 my $selection = $treeview->get_selection ();
2307 $selection->signal_connect ('changed' => sub { $SELHOTKEY = shift });
2311 sub new_hotkeys_page() {
2312 my $swin = Gtk3::ScrolledWindow->new ();
2313 my $vbox = Gtk3::VBox->new (FALSE, 5);
2314 foreach my $gkey (sort keys %$HOTKEYS) {
2315 my $group = $HOTKEYS->{$gkey};
2317 my $glabel = Gtk3::Label->new ('<b>' . $gkey . '</b>');
2318 $glabel->set_use_markup (TRUE);
2319 $glabel->set_alignment (0, 0.5);
2320 $glabel->set_padding (5, 1);
2321 $vbox->pack_start ($glabel, FALSE, FALSE, 0);
2323 my $keylist = new_hotkeys_list ($gkey, $group);
2324 $vbox->pack_start ($keylist, FALSE, FALSE, 0);
2326 $swin->set_border_width (5);
2327 $swin->set_shadow_type ('none');
2328 $swin->set_policy ('automatic', 'always');
2329 $swin->add_with_viewport ($vbox);
2333 sub new_info_page() {
2334 my $t0 = Gtk3::Table->new (7, 2, FALSE);
2335 my $v = get_toolkit_versions ();
2337 'glib' => 'Perl-GLib',
2338 'glib-r' => _('GLib runtime'),
2339 'glib-b' => _('GLib built'),
2340 'gtk2' => 'Perl-GTK2',
2341 'gtk2-r' => _('GTK2 runtime'),
2342 'gtk2-b' => _('GTK2 built'),
2345 foreach (sort keys %$v) {
2346 if (defined $v->{$_}) {
2347 my $label = Gtk3::Label->new ($labels{$_});
2348 my $value = Gtk3::Label->new ('<b>' . $v->{$_} . '</b>');
2349 $label->set_alignment (0, 0.5);
2350 $value->set_alignment (0, 0.5);
2351 $value->set_use_markup (TRUE);
2352 $t0->attach ($label, 0, 1, $row, $row + 1, 'fill', 'shrink', 8, 6);
2353 $t0->attach ($value, 1, 2, $row, $row + 1, 'fill', 'shrink', 8, 6);
2357 my $t1 = Gtk3::Table->new (2, 2, FALSE);
2358 my @lbl = map { $_->set_alignment (0, 0.5); $_ } (
2359 Gtk3::Label->new (_('Binary')),
2360 Gtk3::Label->new (_('Configuration'))
2362 my $cfgv = $CONFIGDATA->{'Common'}{'config_version'};
2364 my @val = map { $_->set_alignment (0, 0.5); $_->set_use_markup (TRUE); $_ } (
2365 Gtk3::Label->new ('<b>' . $CLAWSV . '</b>'),
2366 Gtk3::Label->new ('<b>' . $cfgv . '</b>')
2368 for (my $i = 0; $i <= $#lbl; ++$i) {
2369 $t1->attach ($lbl[$i], 0, 1, $i, $i + 1, 'fill', 'shrink', 8, 6);
2370 $t1->attach ($val[$i], 1, 2, $i, $i + 1, 'fill', 'shrink', 8, 6);
2372 return new_vbox_pack (
2373 new_subpage_frame ($t0, _('Library versions'), 'not-packed'),
2374 new_subpage_frame ($t1, _('Claws Mail versions'), 'not-packed'));
2378 sub get_toolkit_versions {
2380 $versions{'glib'} = $Glib::VERSION;
2381 # version info stuff appeared in 1.040
2382 if ($Glib::VERSION >= 1.040) {
2383 $versions{'glib-b'} = join('.', Glib->GET_VERSION_INFO);
2384 $versions{'glib-r'} = join('.',
2385 &Glib::major_version, &Glib::minor_version, &Glib::micro_version);
2387 $versions{'gtk2'} = $Gtk3::VERSION;
2388 if ($Gtk3::VERSION >= 1.040) {
2389 $versions{'gtk2-b'} = join('.', Gtk3->GET_VERSION_INFO);
2390 $versions{'gtk2-r'} = join('.',
2391 &Gtk3::major_version, &Gtk3::minor_version, &Gtk3::micro_version);
2396 sub print_version() {
2397 print $xl::s{about_title} . "\n";
2398 print $xl::s{about_version} . " $VERSION\n";
2399 my $v = get_toolkit_versions ();
2400 if ($v->{'glib-b'}) {
2401 print _("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 print _("Perl-GLib version {glibv}.", glibv => $v->{'glib'});
2409 if ($v->{'gtk2-b'}) {
2410 print _("Perl-GTK2 version {gtkv}, built for {gtkb}, running with {gtkr}.",
2411 gtkv => $v->{'gtk2'},
2412 gtkb => $v->{'gtk2-b'},
2413 gtkr => $v->{'gtk2-r'});
2415 print _("Perl-GTK2 version {gtkv}.", gtkv => $v->{'gtk2'});
2418 my $clawsver = ($CLAWSV eq "") ?
2419 _("Claws Mail was not found!") :
2420 _("Claws Mail returned version {cmv}.", cmv => $CLAWSV);
2421 print $clawsver . "\n";
2424 # the command line help
2426 my $line = '-' x length ($xl::s{about_title});
2428 say $xl::s{about_title};
2432 _(" clawsker [options]"),
2434 _(" -a|--alternate-config-dir <dir> Uses <dir> as Claws Mail configuration."),
2435 _(" -b|--verbose More messages on standard output."),
2436 _(" -c|--clawsrc <file> Uses <file> as full resource name."),
2437 _(" -h|--help Prints this help screen and exits."),
2438 _(" -r|--read-only Disables writing changes to disk."),
2439 _(" -v|--version Prints version information and exits.")
2441 foreach (@help) { say $_ }
2444 sub parse_command_line {
2446 $CLAWSV = get_claws_version ();
2448 GetOptions('h|help' => sub { print_help (); $cont = FALSE },
2449 'v|version' => sub { print_version (); $cont = FALSE },
2450 'b|verbose' => sub { $VERBOSE = TRUE },
2451 'r|read-only' => sub { $READONLY = TRUE },
2452 'u|use-claws-version=s' => \&opt_use_claws_version,
2453 'a|alternate-config-dir=s' => \&opt_alternate_config_dir,
2454 'c|clawsrc=s' => \&opt_clawsrc)
2455 or die _("try -h or --help for syntax.\n");
2458 my $msg = _("Error in options: {msg}\n", msg => $@);
2459 if (defined $ENV{'DISPLAY'} and $ENV{'DISPLAY'} ne '') {
2460 eval { Gtk3->init };
2461 error_dialog ($msg) unless $@;
2468 sub opt_use_claws_version {
2469 my ($name, $value) = @_;
2470 die _("Error: {opt} requires a dotted numeric value argument\n", opt => $name)
2471 unless ($value =~ /^[\d\.]+$/);
2475 sub opt_alternate_config_dir {
2476 my ($name, $value) = @_;
2477 die _("Error: '{dir}' is not a directory or does not exist\n", dir => $value)
2479 $CONFIGDIR = $value;
2480 $CONFIGDIR .= "/" unless ($CONFIGDIR =~ /.*\/$/);
2481 $ALTCONFIGDIR = TRUE;
2485 my ($name, $value) = @_;
2486 die _("Error: '{value}' is not a file or does not exist\n", value => $value)
2488 set_rc_filename ($value);
2491 # update the hidden preferences status from loaded values
2492 sub init_hidden_preferences {
2493 foreach my $hash (\%pr::beh, \%pr::col, \%pr::gui, \%pr::oth, \%pr::win) {
2494 foreach my $key (keys %$hash) {
2495 $HPVALUE{${$hash}{$key}[NAME]}[VALUE] = $PREFS{${$hash}{$key}[NAME]};
2496 $HPVALUE{${$hash}{$key}[NAME]}[IVALUE] = $PREFS{${$hash}{$key}[NAME]};
2499 foreach my $akey (keys %ACPREFS) {
2500 foreach my $key (keys %pr::acc) {
2501 my $pname = $pr::acc{$key}[NAME];
2502 $ACHPVALUE{$akey}{$pname}[VALUE] = $ACPREFS{$akey}{$pname};
2503 $ACHPVALUE{$akey}{$pname}[IVALUE] = $ACPREFS{$akey}{$pname};
2506 foreach my $key (keys %pr::plu) {
2507 my $plugin = $pr::plu{$key}[PLUGIN];
2508 my $pname = $pr::plu{$key}[NAME];
2509 if (defined $PLPREFS{$plugin}) {
2510 $PLHPVALUE{$plugin}{$pname}[VALUE] = $PLPREFS{$plugin}{$pname};
2511 $PLHPVALUE{$plugin}{$pname}[IVALUE] = $PLPREFS{$plugin}{$pname};
2517 # generic load/save resource files
2523 open (RCF, '<:encoding(utf8)', $rc)
2524 or die _("Error: opening '{file}' for reading", file => $rc) . ": $!\n";
2525 my $section = '_'; # default unnamed section
2530 if (/^\[([^\]]+)\]$/) { # new section
2532 die _("Error: duplicate section '{sect}' in resource file '{file}'\n",
2533 sect => $section, file => $rc) if ($data{$section});
2534 $data{$section} = {};
2535 $meta{$section}{'#'} = $line;
2537 elsif (/^([0-9a-z_]+)=(.*)$/) { # key=value
2538 $data{$section}{$1} = $2;
2539 $meta{$section}{$1} = $line;
2541 elsif (/^(.*)$/) { # lone value
2542 push (@{$data{$section}{'_'}}, $1);
2546 return (\%data, \%meta);
2550 my ($rc, $data, $meta) = @_;
2551 open (RCF, '>:utf8', $rc)
2552 or die _("Error: opening '{file}' for writing", file => $rc) . ": $!\n";
2553 my @sections = keys %$data;
2554 if (defined $meta) {
2556 $meta->{$a}{'#'} <=> $meta->{$b}{'#'}
2559 foreach my $section (@sections) {
2560 say RCF "[$section]";
2561 if (ref ($data->{$section}{'_'}) eq 'ARRAY') {
2562 foreach my $val (@{$data->{$section}{'_'}}) {
2566 my @keys = keys %{$data->{$section}};
2567 if (defined $meta) {
2569 $meta->{$section}{$a} <=> $meta->{$section}{$b}
2572 foreach my $key (@keys) {
2573 my $val = $data->{$section}{$key};
2574 say RCF "$key=$val";
2582 sub backup_resource {
2584 my $rcbak = "$rc.backup";
2586 my $emsg = _("Unable to create backup file '{name}'\n", name => $rcbak);
2587 log_message ($emsg);
2588 error_dialog ($emsg);
2590 } unless rename ($rc, $rcbak);
2597 open (RCF, '<:encoding(utf8)', $rc)
2598 or die _("Error: opening '{file}' for reading", file => $rc) . ": $!\n";
2603 if (/^; \(gtk_accel_path "<([A-Za-z]+)>([^"]+)" ([^\)]+)\)$/) {
2604 my %data = ('key' => $3, 'enabled' => FALSE, 'line' => $line);
2605 $groups{$1}{$2} = \%data;
2606 # say "group -> $1 | path -> $2 | key -> $3";
2607 } elsif (/^\(gtk_accel_path "<([A-Za-z]+)>([^"]+)" ([^\)]+)\)$/) {
2608 my %data = ('key' => $3, 'enabled' => TRUE, 'line' => $line);
2609 $groups{$1}{$2} = \%data;
2610 # say "group -> $1 | path -> $2 | key -> $3";
2619 my ($rc, $groups) = @_;
2621 foreach my $gkey (keys %$groups) {
2622 my $group = $groups->{$gkey};
2623 foreach my $akey (keys %$group) {
2624 my $data = $group->{$akey};
2625 my $key = $data->{'key'};
2626 my $line = $data->{'line'};
2627 $lines[$line] = ($data->{'enabled'})? '': '; ';
2628 $lines[$line] .= '(gtk_accel_path "<'
2629 . $gkey . '>' . $akey . '" ' . $key . ')';
2632 open (RCF, '>:utf8', $rc)
2633 or die _("Error: opening '{file}' for writing", file => $rc) . ": $!\n";
2634 say RCF '; claws-mail GtkAccelMap rc-file -*- scheme -*-';
2635 say RCF '; this file is an automated accelerator map dump';
2637 foreach (@lines) { say RCF $_ if $_ }
2641 # load current status from disc
2642 sub load_rc_preferences {
2643 my $rc = get_rc_filename ();
2644 log_message ("Loading preferences from $rc\n");
2645 return FALSE unless check_rc_file ($rc);
2646 ($CONFIGDATA, $CONFIGMETA) = load_resource ($rc);
2647 foreach (keys %{$CONFIGDATA->{'Common'}}) {
2648 $PREFS{$_} = $CONFIGDATA->{'Common'}{$_};
2650 foreach my $plugin (@PLUGINS) {
2651 if (defined $CONFIGDATA->{$plugin}) {
2652 push (@AVPLUGINS, $plugin);
2653 foreach (keys %{$CONFIGDATA->{$plugin}}) {
2654 $PLPREFS{$plugin}{$_} = $CONFIGDATA->{$plugin}{$_};
2661 sub load_ac_preferences {
2662 my $rc = get_ac_rc_filename ();
2663 log_message ("Loading account preferences from $rc\n");
2664 return FALSE unless check_rc_file ($rc);
2665 ($ACCOUNTDATA, $ACCOUNTMETA) = load_resource ($rc);
2666 foreach my $asect (keys %$ACCOUNTDATA) {
2667 if ($asect =~ /^Account: (\d+)$/) {
2668 foreach (keys %{$ACCOUNTDATA->{$asect}}) {
2669 $ACPREFS{$1}{$_} = $ACCOUNTDATA->{$asect}{$_};
2676 sub load_hk_preferences {
2677 my $rc = get_menurc_filename ();
2678 return FALSE unless check_rc_file ($rc);
2679 $HOTKEYS = load_menurc ($rc);
2683 sub load_preferences {
2684 return FALSE unless check_claws_not_running ();
2685 return (load_rc_preferences ()
2686 and load_ac_preferences ()
2687 and load_hk_preferences ()
2691 # save current preferences to disc
2692 sub save_rc_preferences {
2693 my $rc = get_rc_filename ();
2694 log_message ("Saving preferences to $rc\n");
2695 return FALSE unless check_rc_file ($rc);
2696 return FALSE unless check_claws_not_running ();
2697 return FALSE unless backup_resource ($rc);
2698 foreach (keys %PREFS) {
2699 if (defined $HPVALUE{$_}) {
2700 $CONFIGDATA->{'Common'}{$_} = $HPVALUE{$_}[VALUE];
2703 foreach my $plugin (@AVPLUGINS) {
2704 foreach (keys %{$CONFIGDATA->{$plugin}}) {
2705 if (defined $PLHPVALUE{$plugin}{$_}) {
2706 $CONFIGDATA->{$plugin}{$_} = $PLHPVALUE{$plugin}{$_}[VALUE];
2710 save_resource ($rc, $CONFIGDATA, $CONFIGMETA);
2714 sub save_ac_preferences {
2715 my $rc = get_ac_rc_filename ();
2716 log_message ("Saving account 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 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 check_claws_not_running ();
2738 return FALSE unless backup_resource ($rc);
2739 save_menurc ($rc, $HOTKEYS);
2743 sub save_preferences {
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 (),
2756 Gtk3::Label->new ($xl::s{tab_behaviour}));
2757 $nb->append_page (new_colours_page (),
2758 Gtk3::Label->new ($xl::s{tab_colours}));
2759 $nb->append_page (new_gui_page (),
2760 Gtk3::Label->new ($xl::s{tab_gui}));
2761 $nb->append_page (new_other_page (),
2762 Gtk3::Label->new ($xl::s{tab_other}));
2763 $nb->append_page (new_winpos_page (),
2764 Gtk3::Label->new ($xl::s{tab_winpos}));
2765 $nb->append_page (new_accounts_page (),
2766 Gtk3::Label->new ($xl::s{tab_accounts}));
2767 $nb->append_page (new_plugins_page (),
2768 Gtk3::Label->new ($xl::s{tab_plugins}));
2769 $nb->append_page (new_hotkeys_page (),
2770 Gtk3::Label->new ($xl::s{tab_hotkeys}));
2771 $nb->append_page (new_info_page (),
2772 Gtk3::Label->new ($xl::s{tab_info}));
2777 # create an about dialog
2778 sub new_about_dialog {
2780 my $title = $xl::s{about_title};
2781 my $lic = $xl::s{about_license};
2782 my $vers = $xl::s{about_version} . " $VERSION";
2784 "This program is free software: you can redistribute it and/or modify
2785 it under the terms of the GNU General Public License as published by
2786 the Free Software Foundation, either version 3 of the License, or
2787 (at your option) any later version.
2789 This program is distributed in the hope that it will be useful,
2790 but WITHOUT ANY WARRANTY; without even the implied warranty of
2791 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2792 GNU General Public License for more details.
2794 You should have received a copy of the GNU General Public License
2795 along with this program. If not, see <http://www.gnu.org/licenses/>.";
2796 my $year = "2007-2018";
2797 my $holder = "Ricardo Mones <ricardo\@mones.org>";
2798 my $url = "http://www.claws-mail.org/clawsker.php";
2800 my $dialog = Gtk3::MessageDialog->new ($parent,
2801 [qw/modal destroy-with-parent/], 'info', 'close');
2802 $dialog->set_markup (
2803 "<span size=\"x-large\" weight=\"bold\">$title</span>\n"
2804 . "<span size=\"large\">$vers</span>\n\n"
2805 . "<span color=\"blue\" size=\"large\">$url</span>\n\n"
2806 . "<span>Copyright $year by $holder</span>\n\n"
2807 . "<span size=\"large\">$lic</span>\n\n"
2808 . "<span size=\"small\">$license</span>");
2809 $dialog->set_title ($xl::s{about});
2810 if (Gtk3->CHECK_VERSION (2, 10, 0)) {
2811 my @icons = get_app_icons ();
2812 my $image = Gtk3::Image->new_from_pixbuf ($icons[-1]);
2814 $image->set_alignment (0, 0);
2815 $dialog->set_image ($image);
2823 if ($MODIFIED != 0 and not $READONLY) {
2824 my $markup = "<span>" . $xl::s{exit_fact} . "</span>\n\n"
2825 . "<span weight=\"bold\">" . $xl::s{exit_question} . "</span>\n";
2826 my $dialog = message_dialog (
2827 $parent, $xl::s{exit_title}, $markup, 'question',
2828 [ 'gtk-no', 1, 'gtk-yes', 0 ]
2830 my $resp = $dialog->run;
2832 return TRUE if ($resp == 1);
2837 # create buttons box
2838 sub new_button_box {
2839 my ($parent, $adlg) = @_;
2840 my $b_about = Gtk3::Button->new_from_stock ('gtk-about');
2841 my $b_exit = Gtk3::Button->new_from_stock ('gtk-quit');
2842 my $b_apply = Gtk3::Button->new_from_stock ('gtk-apply');
2843 # disable button until is really implemented
2844 # my $b_undo = Gtk3::Button->new_from_stock ('gtk-undo');
2845 my $hbox = Gtk3::HBox->new (FALSE, 5);
2847 $b_exit->signal_connect (clicked => sub { exit_handler($parent) });
2848 $b_apply->set_sensitive (not $READONLY);
2849 $b_apply->signal_connect (clicked => sub { save_preferences($parent) });
2850 # $b_undo->signal_connect (clicked => sub { undo_current_changes });
2851 $b_about->signal_connect (clicked => sub { $adlg->run; $adlg->hide });
2853 $hbox->pack_end ($b_apply, FALSE, FALSE, 0);
2854 $hbox->pack_end ($b_exit, FALSE, FALSE, 0);
2855 # $hbox->pack_end ($b_undo, FALSE, FALSE, 0);
2856 $hbox->pack_start ($b_about, FALSE, FALSE, 0);
2862 return \@APPICONS if (@APPICONS);
2864 if (-d $DATADIR) { # installed
2865 my $dir = $DATADIR . '/icons/hicolor';
2867 join ('/', ($dir, $_ . 'x' . $_, 'apps', $NAME . '.png'))
2869 } else { # unpacked tarball or git clone
2871 join ('/', ('./icons', $NAME . '-' . $_ . '.png'));
2876 $icon = Gtk3::Gdk::Pixbuf->new_from_file($_) if (-f $_);
2877 push @APPICONS, $icon if ($icon);
2882 sub escape_key_handler {
2883 my ($widget, $event) = @_;
2884 if ($event->keyval == Gtk3::Gdk::keyval_from_name('Escape')) {
2885 exit_handler($widget);
2890 exit unless parse_command_line ();
2892 $main_window = Gtk3::Window->new ('toplevel');
2893 exit unless load_preferences ();
2894 exit unless init_hidden_preferences ();
2896 my $box = Gtk3::VBox->new (FALSE, 5);
2897 $box->set_border_width(3);
2898 my $about = new_about_dialog ($main_window);
2899 $box->pack_start (new_notebook (), TRUE, TRUE, 0);
2900 $box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
2901 $main_window->signal_connect (delete_event => sub { exit_handler($main_window) });
2902 $main_window->signal_connect (key_press_event => \&escape_key_handler);
2903 $main_window->set_title ($xl::s{win_title});
2904 $main_window->set_icon_list (get_app_icons ());
2905 $main_window->add ($box);
2906 $main_window->show_all;