3 # Clawsker :: A Claws Mail Tweaker
8 use Glib qw(TRUE FALSE);
10 use POSIX qw(setlocale);
13 my $NAME = 'clawsker';
14 my $PREFIX = '@PREFIX@';
15 my $LIBDIR = '@LIBDIR@';
16 my $VERSION = '@VERSION@';
19 my $main_window = undef;
21 my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
22 $locale = "C" unless defined($locale);
23 setlocale (LC_ALL, $locale);
24 bindtextdomain ($NAME, sprintf ('%s/share/locale', $PREFIX));
27 my $SHOWHINTS = FALSE;
28 $SHOWHINTS = TRUE if ($Gtk2::VERSION >= 1.040 and Gtk2->CHECK_VERSION (2, 12, 0));
33 my $xla = gettext ($str);
34 if (scalar(keys(%par)) > 0) {
35 foreach my $key (keys %par) {
36 $xla =~ s/\{$key\}/$par{$key}/g;
44 win_title => _('Claws Mail Hidden Preferences'),
45 about => _('About...'),
46 about_title => _('Clawsker :: A Claws Mail Tweaker'),
47 about_license => _('License:'),
48 about_version => _('Version:'),
50 tab_colours => _('Colours'),
51 tab_behaviour => _('Behaviour'),
53 tab_other => _('Other'),
54 tab_winpos => _('Windows'),
56 ab_frame => _('Addressbook'),
57 mem_frame => _('Memory'),
58 msgview_frame => _('Message view'),
59 log_frame => _('Log window'),
60 dnd_frame => _('Drag \'n\' drop'),
61 ssl_frame => _('Secure Sockets Layer'),
62 msgs_frame => _('Messages'),
63 stripes_frame => _('Coloured stripes'),
64 sbar_frame => _('Scroll bars'),
65 mlist_frame => _('Message List'),
66 netm_frame => _('NetworkManager'),
68 l_oth_use_dlg => _('Use detached address book edit dialogue'),
69 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.'),
70 l_oth_max_use => _('Maximum memory for message cache (kB)'),
71 h_oth_max_use => _('The maximum amount of memory to use to cache messages, in kilobytes.'),
72 l_oth_min_time => _('Minimun time for cache elements (minutes)'),
73 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.'),
74 l_oth_use_netm => _('Use NetworkManager'),
75 h_oth_use_netm => _('Use NetworkManager to switch offline automatically.'),
77 l_gui_b_unread => _('Show unread messages with bold font'),
78 h_gui_b_unread => _('Show unread messages in the Message List using a bold font.'),
79 l_gui_no_markup => _('Don\'t use markup in compose window'),
80 h_gui_no_markup => _('Don\'t use bold and italic text in Compose dialogue\'s account selector.'),
81 l_gui_dot_lines => _('Use dotted lines in tree view components'),
82 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.'),
83 l_gui_h_scroll => _('Enable horizontal scrollbar'),
84 h_gui_h_scroll => _('Enable the horizontal scrollbar in the Message List.'),
85 l_gui_swp_from => _('Display To column instead From column in Sent folder'),
86 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.'),
87 l_gui_v_scroll => _('Folder List scrollbar behaviour'),
88 h_gui_v_scroll => _('Specify the policy of vertical scrollbar of Folder List: show always, automatic or hide always.'),
89 l_gui_v_scroll_show => _('Show always'),
90 l_gui_v_scroll_auto => _('Automatic'),
91 l_gui_v_scroll_hide => _('Hide always'),
92 l_gui_strip_off => _('Coloured lines contrast'),
93 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.'),
94 l_gui_cursor_v => _('Show Cursor in message view'),
95 h_gui_cursor_v => _('Display the cursor in the message view.'),
96 l_gui_toolbar_d => _('Detachable toolbars'),
97 h_gui_toolbar_d => _('Show handles in the toolbars.'),
98 l_gui_strip_all => _('Use stripes in all tree view components'),
99 h_gui_strip_all => _('Enable alternately coloured lines in all tree view components.'),
100 l_gui_strip_sum => _('Use stripes in Folder List and Message List'),
101 h_gui_strip_sum => _('Enable alternately coloured lines in Message list and Folder list.'),
102 l_gui_two_line_v => _('2 lines per Message List item in 3-column layout'),
103 h_gui_two_line_v => _('Spread Message List information over two lines when using the three column mode.'),
105 l_beh_hover_t => _('Drag \'n\' drop hover timeout (ms)'),
106 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.'),
107 l_beh_dangerous => _('Don\'t confirm deletions (dangerous!)'),
108 h_beh_dangerous => _('Don\'t ask for confirmation before definitive deletion of emails.'),
109 l_beh_flowed => _('Respect format=flowed in messages'),
110 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.'),
111 l_beh_parts_rw => _('Allow writable temporary files'),
112 h_beh_parts_rw => _('Saves temporary files when opening attachment with write bit set.'),
113 l_beh_skip_ssl => _('Don\'t check SSL certificates'),
114 h_beh_skip_ssl => _('Disables the verification of SSL certificates.'),
115 l_beh_up_step => _('Progress bar update step (items)'),
116 h_beh_up_step => _('Update stepping in progress bars.'),
117 l_beh_thread_a => _('Maximum age when threading by subject (days)'),
118 h_beh_thread_a => _('Number of days to include a message in a thread when using "Thread using subject in addition to standard headers".'),
119 l_beh_unsafe_ssl => _('Allow unsafe SSL certificates'),
120 h_beh_unsafe_ssl => _('Allows Claws Mail to remember multiple SSL certificates for a given server/port.'),
121 l_beh_use_utf8 => _('Force UTF-8 for broken mails'),
122 h_beh_use_utf8 => _('Use UTF-8 encoding for broken mails instead of current locale.'),
123 l_beh_warn_dnd => _('Warn on drag \'n\' drop'),
124 h_beh_warn_dnd => _('Display a confirmation dialogue on drag \'n\' drop of folders.'),
125 l_beh_out_ascii => _('Ougoing messages fallback to ASCII'),
126 h_beh_out_ascii => _('If content allows, ASCII will be used to encode outgoing messages, otherwise the user-defined encoding is enforced always.'),
127 l_beh_pp_unsel => _('Primary paste unselects selection'),
128 h_beh_pp_unsel => _('Controls how pasting using middle-click changes the selected text and insertion point.'),
130 l_col_emphasis => _('X-Mailer header'),
131 h_col_emphasis => _('The colour used for the X-Mailer line when its value is Claws Mail.'),
132 l_col_log_err => _('Error messages'),
133 h_col_log_err => _('Colour for error messages in log window.'),
134 l_col_log_in => _('Server messages'),
135 h_col_log_in => _('Colour for messages received from servers in log window.'),
136 l_col_log_msg => _('Standard messages'),
137 h_col_log_msg => _('Colour for messages in log window.'),
138 l_col_log_out => _('Client messages'),
139 h_col_log_out => _('Colour for messages sent to servers in log window.'),
140 l_col_log_warn => _('Warnings'),
141 h_col_log_warn => _('Colour for warning messages in log window.'),
143 l_win_x => _('X position'),
144 h_win_x => _('X coordinate for window\'s top-left corner.'),
145 l_win_y => _('Y position'),
146 h_win_y => _('Y coordinate for window\'s top-left corner.'),
147 l_win_w => _('Width'),
148 h_win_w => _('Window\'s width in pixels.'),
149 l_win_h => _('Height'),
150 h_win_h => _('Window\'s height in pixels.'),
152 l_win_main_mx => _('Maximized'),
153 h_win_main_mx => _('Changes window maximized status.'),
154 l_win_main_fs => _('Full-screen'),
155 h_win_main_fs => _('Changes full screen status.'),
157 e_error => _('Error: '),
158 e_noclawsrc => _('resource file for Claws Mail was not found.'),
159 e_running => _('seems Claws Mail is currently running, close it first.'),
160 e_requireddir => _('option requires a directory name.'),
161 e_requiredfile => _('option requires a file name.'),
162 e_notadir => _('specified name is not a directory or does not exist.'),
163 e_notafile => _('specified name is not a file or does not exist.'),
166 # all preferences read by load_preferences
168 # values of all preferences handled by clawsker
170 # default config dir and file name
171 my $ALTCONFIGDIR = FALSE;
172 my $CONFIGDIR = $ENV{HOME} . '/.claws-mail/';
173 my $CONFIGRC = 'clawsrc';
175 # index constants for preference arrays
176 use constant NAME => 0; # the name on the rc file
177 use constant LABEL => 1; # the label on the GUI
178 use constant DESC => 2; # the description for the hint/help
179 use constant TYPE => 3; # data type: bool, int, float, string, color
180 use constant CMVER => 4; # lowest Claws Mail version the feature exists
181 use constant CMDEF => 5; # default value for the preference in Claws Mail
182 use constant GUI => 6; # GUI element
184 # constants for GUI spacing
185 use constant HBOX_SPC => 5;
186 use constant FRAME_SPC => 2;
187 use constant PAGE_SPC => 5;
191 sub version_greater_or_equal() {
192 my ($version, $refvers) = @_;
193 my @version = split (/\./, $version);
194 my @refvers = split (/\./, $refvers);
195 while ($#version < $#refvers) {
196 push (@version, '0');
199 while (($idx <= $#refvers)
200 and (int ($version[$idx]) == int ($refvers[$idx]))) {
203 return TRUE if (($idx > $#refvers)
204 or (int ($version[$idx]) >= int ($refvers[$idx])));
208 sub get_claws_version() {
213 foreach my $bin (@cmbin) {
218 return "" unless ($_); # not installed
221 my @fver = split (/ /);
222 die "Invalid version string" unless ($fver[2] eq "version");
223 my @ver = split (/\./, $fver[3]);
226 if ($ver[2] =~ /(\d+)cvs(\d+)/) {
235 # data handlers and auxiliar functions
237 sub handle_bool_value {
238 my ($widget, $event, $dataref) = @_;
239 $$dataref = ($widget->get_active ())? '1': '0';
242 sub handle_int_value {
243 my ($widget, $event, $dataref) = @_;
244 $_ = $widget->get_text ();
249 $widget->set_text ($_);
252 $widget->set_text ($$dataref);
256 sub handle_string_value {
257 my ($widget, $event, $dataref) = @_;
258 $$dataref = $widget->get_text ();
261 sub gdk_color_from_str {
263 my ($rr, $gg, $bb) = (0, 0 ,0);
265 if (/\#([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])/) {
270 my $color = Gtk2::Gdk::Color->new ($rr, $gg, $bb);
274 sub str_from_gdk_color {
276 my $rr = $color->red / 256;
277 my $gg = $color->green / 256;
278 my $bb = $color->blue / 256;
279 my $str = sprintf ("#%.2x%.2x%.2x", $rr, $gg, $bb);
283 sub handle_color_value {
284 my ($widget, $event, $dataref) = @_;
285 my $newcol = $widget->get_color;
286 $$dataref = &str_from_gdk_color ($newcol);
289 sub handle_selection_value {
290 my ($widget, $event, $dataref) = @_;
291 $$dataref = $widget->get_active;
294 sub get_rc_filename {
295 return $CONFIGDIR . $CONFIGRC;
298 sub set_rc_filename {
300 my @parts = split ('/', $fullname);
301 $CONFIGRC = $parts[$#parts];
302 $parts[$#parts] = '';
303 $CONFIGDIR = join ('/', @parts);
307 my ($mesg, $fatal) = @_;
308 if (defined($fatal) && $fatal eq 'die') {
309 die "$NAME: $mesg\n";
312 print "$NAME: $mesg\n";
318 my $markup = "<span weight=\"bold\" size=\"large\">" . $emsg . "</span>";
319 my $errordlg = Gtk2::MessageDialog->new_with_markup ($main_window, 'modal', 'error', 'cancel', $markup);
320 $errordlg->set_title (_('Error message'));
325 sub check_claws_not_running() {
326 my $socket = (not $ALTCONFIGDIR)? "/tmp/": $CONFIGDIR;
327 $socket .= "claws-mail-$<";
329 my $emsg = "$xl::s{e_error}$xl::s{e_running}";
331 error_dialog ($emsg);
338 sub check_rc_file() {
340 (defined($rcfile) && -f $rcfile) or do {
341 my $emsg = "$xl::s{e_error}$xl::s{e_noclawsrc}\n";
343 error_dialog ($emsg);
350 sub set_widget_hint() {
352 my ($wdgt, $hint) = @_;
353 $wdgt->set_tooltip_text ($hint);
354 $wdgt->set_has_tooltip (TRUE);
358 sub set_widget_sens() {
359 my ($wdgt, $minver) = @_;
360 $wdgt->set_sensitive (&version_greater_or_equal ($CLAWSV, $minver));
363 # graphic element creation
365 sub new_check_button_for {
366 my ($hash, $key) = @_;
367 my $name = $$hash{$key}[NAME];
368 my $label = $$hash{$key}[LABEL];
370 my $hbox = Gtk2::HBox->new (FALSE, 5);
371 my $cb = Gtk2::CheckButton->new ($label);
372 $$hash{$key}[GUI] = $cb;
373 if (defined ($HPVALUE{$name})) {
374 $cb->set_active ($HPVALUE{$name} eq '1');
376 $cb->signal_connect (clicked => sub {
378 &handle_bool_value($w, $e, \$HPVALUE{$name});
380 &set_widget_hint ($cb, $$hash{$key}[DESC]);
381 &set_widget_sens ($cb, $$hash{$key}[CMVER]);
382 $hbox->pack_start ($cb, FALSE, FALSE, HBOX_SPC);
387 sub new_text_box_for_int {
388 my ($hash, $key) = @_;
389 my $name = $$hash{$key}[NAME];
390 my $label = $$hash{$key}[LABEL];
391 my @type = split (/,/, $$hash{$key}[TYPE]);
392 push (@type, 0), push (@type, 10000) unless ($#type > 0);
394 my $hbox = Gtk2::HBox->new (FALSE, 5);
395 my $glabel = Gtk2::Label->new ($label);
396 my $pagei = int (($type[2] - $type[1]) / 10);
397 my $gentry = Gtk2::SpinButton->new_with_range ($type[1], $type[2], $pagei);
398 $gentry->set_numeric (TRUE);
399 $$hash{$key}[GUI] = $gentry;
400 $gentry->signal_connect('value-changed' => sub {
402 &handle_int_value($w, $e, \$HPVALUE{$name});
404 &set_widget_hint ($gentry, $$hash{$key}[DESC]);
405 &set_widget_sens ($gentry, $$hash{$key}[CMVER]);
406 $glabel->set_sensitive ($gentry->sensitive);
407 $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
408 $hbox->pack_start ($gentry, FALSE, FALSE, HBOX_SPC);
413 sub new_color_button_for {
414 my ($hash, $key) = @_;
415 my $name = $$hash{$key}[NAME];
416 my $label = $$hash{$key}[LABEL];
418 my $col = &gdk_color_from_str ($HPVALUE{$name});
419 my $hbox = Gtk2::HBox->new (FALSE, 5);
420 my $glabel = Gtk2::Label->new ($label);
421 my $button = Gtk2::ColorButton->new_with_color ($col);
422 $$hash{$key}[GUI] = $button;
423 $button->set_title ($label);
424 $button->set_relief ('none');
425 $button->signal_connect ('color-set' => sub {
427 &handle_color_value($w, $e, \$HPVALUE{$name});
429 &set_widget_hint ($button, $$hash{$key}[DESC]);
430 &set_widget_sens ($button, $$hash{$key}[CMVER]);
431 $glabel->set_sensitive ($button->sensitive);
432 $hbox->pack_start ($button, FALSE, FALSE, HBOX_SPC);
433 $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
438 sub new_selection_box_for {
439 my ($hash, $key) = @_;
440 my $name = $$hash{$key}[NAME];
441 my $label = $$hash{$key}[LABEL];
443 my $hbox = Gtk2::HBox->new (FALSE, 5);
444 my $glabel = Gtk2::Label->new ($label);
445 my $combo = Gtk2::ComboBox->new_text;
446 $$hash{$key}[GUI] = $combo;
447 my @options = split (';', $$hash{$key}[TYPE]);
448 foreach my $opt (@options) {
449 my ($index, $textkey) = split ('=', $opt);
450 $combo->insert_text ($index, $xl::s{$textkey});
452 $combo->signal_connect ('changed' => sub {
454 &handle_selection_value($w, $e, \$HPVALUE{$name});
456 $combo->set_active ($HPVALUE{$name});
457 &set_widget_hint ($combo, $$hash{$key}[DESC]);
458 &set_widget_sens ($combo, $$hash{$key}[CMVER]);
459 $glabel->set_sensitive ($combo->sensitive);
460 $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
461 $hbox->pack_start ($combo, FALSE, FALSE, HBOX_SPC);
466 # more graphic helpers
468 sub new_hbox_pack() {
469 my $hbox = Gtk2::HBox->new (FALSE, 5);
470 $hbox->set_border_width (PAGE_SPC);
471 foreach my $item (@_) {
472 $hbox->pack_start ($item, FALSE, FALSE, 0);
477 sub new_vbox_pack() {
478 my $vbox = Gtk2::VBox->new (FALSE, 5);
479 $vbox->set_border_width (PAGE_SPC);
480 foreach my $item (@_) {
481 $vbox->pack_start ($item, FALSE, FALSE, 0);
486 sub new_subpage_frame () {
487 my ($box, $title, $notpacked) = @_;
488 my $frame = Gtk2::Frame->new ($title);
490 return &new_vbox_pack ($frame) unless defined ($notpacked);
494 # preference maps and corresponding page creation subs
496 %pr::oth = ( # other preferences
498 'addressbook_use_editaddress_dialog',
499 $xl::s{l_oth_use_dlg},
500 $xl::s{h_oth_use_dlg},
507 'cache_max_mem_usage',
508 $xl::s{l_oth_max_use},
509 $xl::s{h_oth_max_use},
510 'int,0,262144', # 0 Kb - 256 Mb
516 'cache_min_keep_time',
517 $xl::s{l_oth_min_time},
518 $xl::s{h_oth_min_time},
519 'int,0,120', # 0 minutes - 2 hours
525 'use_networkmanager',
526 $xl::s{l_oth_use_netm},
527 $xl::s{h_oth_use_netm},
535 sub new_other_page() {
536 return &new_vbox_pack (
539 &new_check_button_for(\%pr::oth, 'use_dlg')),
540 $xl::s{ab_frame}, 'not-packed'),
543 &new_text_box_for_int(\%pr::oth, 'max_use'),
544 &new_text_box_for_int(\%pr::oth, 'min_time')),
545 $xl::s{mem_frame}, 'not-packed'),
548 &new_check_button_for(\%pr::oth, 'use_netm')),
549 $xl::s{netm_frame}, 'not-packed')
553 %pr::gui = ( # gui bells and whistles
556 $xl::s{l_gui_b_unread},
557 $xl::s{h_gui_b_unread},
565 $xl::s{l_gui_no_markup},
566 $xl::s{h_gui_no_markup},
573 'enable_dotted_lines',
574 $xl::s{l_gui_dot_lines},
575 $xl::s{h_gui_dot_lines},
583 $xl::s{l_gui_h_scroll},
584 $xl::s{h_gui_h_scroll},
592 $xl::s{l_gui_swp_from},
593 $xl::s{h_gui_swp_from},
600 'folderview_vscrollbar_policy',
601 $xl::s{l_gui_v_scroll},
602 $xl::s{h_gui_v_scroll},
603 '0=l_gui_v_scroll_show;1=l_gui_v_scroll_auto;2=l_gui_v_scroll_hide',
609 'stripes_color_offset',
610 $xl::s{l_gui_strip_off},
611 $xl::s{h_gui_strip_off},
612 'int,0,10000', # no idea what this number means
618 'textview_cursor_visible',
619 $xl::s{l_gui_cursor_v},
620 $xl::s{h_gui_cursor_v},
627 'toolbar_detachable',
628 $xl::s{l_gui_toolbar_d},
629 $xl::s{h_gui_toolbar_d},
636 'use_stripes_everywhere',
637 $xl::s{l_gui_strip_all},
638 $xl::s{h_gui_strip_all},
645 'use_stripes_in_summaries',
646 $xl::s{l_gui_strip_sum},
647 $xl::s{h_gui_strip_sum},
655 $xl::s{l_gui_two_line_v},
656 $xl::s{h_gui_two_line_v},
665 my $gf = Gtk2::VBox->new (FALSE, 5);
666 $gf->set_border_width (PAGE_SPC);
668 my $cb_no_markup = &new_check_button_for (\%pr::gui, 'no_markup');
669 my $cb_dot_lines = &new_check_button_for (\%pr::gui, 'dot_lines');
670 my $cb_cursor_v = &new_check_button_for (\%pr::gui, 'cursor_v');
671 my $cb_toolbar_d = &new_check_button_for (\%pr::gui, 'toolbar_d');
672 my $cb_two_linev = &new_check_button_for (\%pr::gui, 'two_linev');
674 $gf->pack_start (&new_subpage_frame (
676 &new_check_button_for (\%pr::gui, 'strip_all'),
677 &new_check_button_for (\%pr::gui, 'strip_sum'),
678 &new_text_box_for_int (\%pr::gui, 'strip_off')),
679 $xl::s{stripes_frame}, 'not-packed'),
680 FALSE, FALSE, FRAME_SPC);
681 $gf->pack_start (&new_subpage_frame (
683 &new_check_button_for (\%pr::gui, 'b_unread'),
684 &new_check_button_for (\%pr::gui, 'swp_from')),
685 $xl::s{mlist_frame}, 'not-packed'),
686 FALSE, FALSE, FRAME_SPC);
687 $gf->pack_start ($cb_no_markup, FALSE, FALSE, 0);
688 $gf->pack_start ($cb_dot_lines, FALSE, FALSE, 0);
689 $gf->pack_start ($cb_cursor_v, FALSE, FALSE, 0);
690 $gf->pack_start ($cb_toolbar_d, FALSE, FALSE, 0);
691 $gf->pack_start ($cb_two_linev, FALSE, FALSE, 0);
692 $gf->pack_start (&new_subpage_frame (
694 &new_check_button_for (\%pr::gui, 'h_scroll'),
695 &new_selection_box_for (\%pr::gui, 'v_scroll')),
696 $xl::s{sbar_frame}, 'not-packed'),
697 FALSE, FALSE, FRAME_SPC);
702 %pr::beh = ( # tweak some behaviour
705 $xl::s{l_beh_hover_t},
706 $xl::s{h_beh_hover_t},
707 'int,100,3000', # 0.1 seconds - 3 seconds
714 $xl::s{l_beh_dangerous},
715 $xl::s{h_beh_dangerous},
722 'respect_flowed_format',
723 $xl::s{l_beh_flowed},
724 $xl::s{h_beh_flowed},
731 'save_parts_readwrite',
732 $xl::s{l_beh_parts_rw},
733 $xl::s{h_beh_parts_rw},
740 'skip_ssl_cert_check',
741 $xl::s{l_beh_skip_ssl},
742 $xl::s{h_beh_skip_ssl},
749 'statusbar_update_step',
750 $xl::s{l_beh_up_step},
751 $xl::s{h_beh_up_step},
752 'int,1,200', # 1 item - 200 items
758 'thread_by_subject_max_age',
759 $xl::s{l_beh_thread_a},
760 $xl::s{h_beh_thread_a},
761 'int,1,30', # 1 day - 30 days
768 $xl::s{l_beh_unsafe_ssl},
769 $xl::s{h_beh_unsafe_ssl},
776 'utf8_instead_of_locale_for_broken_mail',
777 $xl::s{l_beh_use_utf8},
778 $xl::s{h_beh_use_utf8},
786 $xl::s{l_beh_warn_dnd},
787 $xl::s{h_beh_warn_dnd},
794 'outgoing_fallback_to_ascii',
795 $xl::s{l_beh_out_ascii},
796 $xl::s{h_beh_out_ascii},
803 'primary_paste_unselects',
804 $xl::s{l_beh_pp_unsel},
805 $xl::s{h_beh_pp_unsel},
813 sub new_behaviour_page() {
814 my $bf = Gtk2::VBox->new (FALSE, 5);
815 $bf->set_border_width (PAGE_SPC);
817 my $tb_up_step = &new_text_box_for_int (\%pr::beh, 'up_step');
818 my $tb_thread_a = &new_text_box_for_int (\%pr::beh, 'thread_a');
820 $bf->pack_start (&new_subpage_frame (
822 &new_text_box_for_int (\%pr::beh, 'hover_t'),
823 &new_check_button_for (\%pr::beh, 'warn_dnd')),
824 $xl::s{dnd_frame}, 'not-packed'),
825 FALSE, FALSE, FRAME_SPC);
826 $bf->pack_start (&new_subpage_frame (
828 &new_check_button_for (\%pr::beh, 'skip_ssl'),
829 &new_check_button_for (\%pr::beh, 'unsafe_ssl')),
830 $xl::s{ssl_frame}, 'not-packed'),
831 FALSE, FALSE, FRAME_SPC);
832 $bf->pack_start ($tb_up_step, FALSE, FALSE, 0);
833 $bf->pack_start ($tb_thread_a, FALSE, FALSE, 0);
834 $bf->pack_start (&new_subpage_frame (
836 &new_check_button_for (\%pr::beh, 'flowed'),
837 &new_check_button_for (\%pr::beh, 'parts_rw'),
838 &new_check_button_for (\%pr::beh, 'use_utf8'),
839 &new_check_button_for (\%pr::beh, 'dangerous'),
840 &new_check_button_for (\%pr::beh, 'out_ascii'),
841 &new_check_button_for (\%pr::beh, 'pp_unsel')),
842 $xl::s{msgs_frame}, 'not-packed'),
843 FALSE, FALSE, FRAME_SPC);
848 %pr::col = ( # a variety of colours
851 $xl::s{l_col_emphasis},
852 $xl::s{h_col_emphasis},
860 $xl::s{l_col_log_err},
861 $xl::s{h_col_log_err},
869 $xl::s{l_col_log_in},
870 $xl::s{h_col_log_in},
878 $xl::s{l_col_log_msg},
879 $xl::s{h_col_log_msg},
887 $xl::s{l_col_log_out},
888 $xl::s{h_col_log_out},
896 $xl::s{l_col_log_warn},
897 $xl::s{h_col_log_warn},
905 sub new_colours_page() {
906 return &new_vbox_pack (
909 &new_color_button_for (\%pr::col, 'emphasis')),
910 $xl::s{msgview_frame}, 'not-packed'),
913 &new_color_button_for (\%pr::col, 'log_err'),
914 &new_color_button_for (\%pr::col, 'log_in'),
915 &new_color_button_for (\%pr::col, 'log_msg'),
916 &new_color_button_for (\%pr::col, 'log_out'),
917 &new_color_button_for (\%pr::col, 'log_warn')),
918 $xl::s{log_frame}, 'not-packed')
922 %pr::win = ( # tweak window positions and/or sizes
927 'int,0,3000', # 0 pixels - 3000 pixels
936 'int,0,3000', # 0 pixels - 3000 pixels
945 'int,0,3000', # 0 pixels - 3000 pixels
954 'int,0,3000', # 0 pixels - 3000 pixels
961 $xl::s{l_win_main_mx},
962 $xl::s{h_win_main_mx},
969 'mainwin_fullscreen',
970 $xl::s{l_win_main_fs},
971 $xl::s{h_win_main_fs},
981 'int,0,3000', # 0 pixels - 3000 pixels
990 'int,0,3000', # 0 pixels - 3000 pixels
999 'int,0,3000', # 0 pixels - 3000 pixels
1005 'messagewin_height',
1008 'int,0,3000', # 0 pixels - 3000 pixels
1017 'int,0,3000', # 0 pixels - 3000 pixels
1026 'int,0,3000', # 0 pixels - 3000 pixels
1035 'int,0,3000', # 0 pixels - 3000 pixels
1041 'receivewin_height',
1044 'int,0,3000', # 0 pixels - 3000 pixels
1053 'int,0,3000', # 0 pixels - 3000 pixels
1062 'int,0,3000', # 0 pixels - 3000 pixels
1068 'folderitemwin_width',
1071 'int,0,3000', # 0 pixels - 3000 pixels
1077 'folderitemwin_height',
1080 'int,0,3000', # 0 pixels - 3000 pixels
1086 'folderselwin_width',
1089 'int,0,3000', # 0 pixels - 3000 pixels
1095 'folderselwin_height',
1098 'int,0,3000', # 0 pixels - 3000 pixels
1107 'int,0,3000', # 0 pixels - 3000 pixels
1116 'int,0,3000', # 0 pixels - 3000 pixels
1122 'addressbookwin_width',
1125 'int,0,3000', # 0 pixels - 3000 pixels
1131 'addressbookwin_height',
1134 'int,0,3000', # 0 pixels - 3000 pixels
1140 'addressbookeditpersonwin_width',
1143 'int,0,3000', # 0 pixels - 3000 pixels
1149 'addressbookeditpersonwin_height',
1152 'int,0,3000', # 0 pixels - 3000 pixels
1158 'addressbookeditgroupwin_width',
1161 'int,0,3000', # 0 pixels - 3000 pixels
1167 'addressbookeditgroupwin_height',
1170 'int,0,3000', # 0 pixels - 3000 pixels
1176 'addressaddwin_width',
1179 'int,0,3000', # 0 pixels - 3000 pixels
1185 'addressaddwin_height',
1188 'int,0,3000', # 0 pixels - 3000 pixels
1194 'addressbook_folderselwin_width',
1197 'int,0,3000', # 0 pixels - 3000 pixels
1203 'addressbook_folderselwin_height',
1206 'int,0,3000', # 0 pixels - 3000 pixels
1212 'editaccountwin_width',
1215 'int,0,3000', # 0 pixels - 3000 pixels
1221 'editaccountwin_height',
1224 'int,0,3000', # 0 pixels - 3000 pixels
1230 'accountswin_width',
1233 'int,0,3000', # 0 pixels - 3000 pixels
1239 'accountswin_height',
1242 'int,0,3000', # 0 pixels - 3000 pixels
1248 'filteringwin_width',
1251 'int,0,3000', # 0 pixels - 3000 pixels
1257 'filteringwin_height',
1260 'int,0,3000', # 0 pixels - 3000 pixels
1266 'filteringactionwin_width',
1269 'int,0,3000', # 0 pixels - 3000 pixels
1275 'filteringactionwin_height',
1278 'int,0,3000', # 0 pixels - 3000 pixels
1284 'filtering_debugwin_width',
1287 'int,0,3000', # 0 pixels - 3000 pixels
1293 'filtering_debugwin_height',
1296 'int,0,3000', # 0 pixels - 3000 pixels
1305 'int,0,3000', # 0 pixels - 3000 pixels
1311 'matcherwin_height',
1314 'int,0,3000', # 0 pixels - 3000 pixels
1323 'int,0,3000', # 0 pixels - 3000 pixels
1332 'int,0,3000', # 0 pixels - 3000 pixels
1338 'templateswin_width',
1341 'int,0,3000', # 0 pixels - 3000 pixels
1347 'templateswin_height',
1350 'int,0,3000', # 0 pixels - 3000 pixels
1359 'int,0,3000', # 0 pixels - 3000 pixels
1365 'actionswin_height',
1368 'int,0,3000', # 0 pixels - 3000 pixels
1377 'int,0,3000', # 0 pixels - 3000 pixels
1386 'int,0,3000', # 0 pixels - 3000 pixels
1395 'int,0,3000', # 0 pixels - 3000 pixels
1401 'pluginswin_height',
1404 'int,0,3000', # 0 pixels - 3000 pixels
1413 'int,0,3000', # 0 pixels - 3000 pixels
1422 'int,0,3000', # 0 pixels - 3000 pixels
1428 'print_previewwin_width',
1431 'int,0,3000', # 0 pixels - 3000 pixels
1437 'print_previewwin_height',
1440 'int,0,3000', # 0 pixels - 3000 pixels
1447 sub new_winpos_subpage_main() {
1448 return &new_subpage_frame (
1450 &new_text_box_for_int (\%pr::win, 'main_x'),
1451 &new_text_box_for_int (\%pr::win, 'main_y'),
1452 &new_text_box_for_int (\%pr::win, 'main_w'),
1453 &new_text_box_for_int (\%pr::win, 'main_h'),
1455 &new_check_button_for (\%pr::win, 'main_fs'),
1456 &new_check_button_for (\%pr::win, 'main_mx'))),
1461 sub new_winpos_subpage_msgs() {
1462 return &new_subpage_frame (
1464 &new_text_box_for_int (\%pr::win, 'msgs_x'),
1465 &new_text_box_for_int (\%pr::win, 'msgs_y'),
1466 &new_text_box_for_int (\%pr::win, 'msgs_w'),
1467 &new_text_box_for_int (\%pr::win, 'msgs_h')),
1472 sub new_winpos_subpage_sendrecv() {
1473 return &new_vbox_pack (
1474 &new_subpage_frame (
1477 &new_text_box_for_int (\%pr::win, 'send_w'),
1478 &new_text_box_for_int (\%pr::win, 'send_h'))),
1479 _('Send window'), 'not-packed'),
1480 &new_subpage_frame (
1483 &new_text_box_for_int (\%pr::win, 'recv_w'),
1484 &new_text_box_for_int (\%pr::win, 'recv_h'))),
1485 _('Receive window'), 'not-packed')
1489 sub new_winpos_subpage_fold() {
1490 return &new_vbox_pack (
1491 &new_subpage_frame (
1493 &new_text_box_for_int (\%pr::win, 'fold_x'),
1494 &new_text_box_for_int (\%pr::win, 'fold_y'),
1495 &new_text_box_for_int (\%pr::win, 'fold_w'),
1496 &new_text_box_for_int (\%pr::win, 'fold_h')),
1497 _('Folder window'), 'not-packed'),
1498 &new_subpage_frame (
1500 &new_text_box_for_int (\%pr::win, 'fsel_w'),
1501 &new_text_box_for_int (\%pr::win, 'fsel_h')),
1502 _('Folder selection window'), 'not-packed')
1506 sub new_winpos_subpage_addrbook() {
1507 return &new_vbox_pack (
1508 &new_subpage_frame (
1511 &new_text_box_for_int (\%pr::win, 'addr_w'),
1512 &new_text_box_for_int (\%pr::win, 'addr_h'))),
1513 _('Addressbook main window'), 'not-packed'),
1514 &new_subpage_frame (
1517 &new_text_box_for_int (\%pr::win, 'adep_w'),
1518 &new_text_box_for_int (\%pr::win, 'adep_h'))),
1519 _('Edit person window'), 'not-packed'),
1520 &new_subpage_frame (
1523 &new_text_box_for_int (\%pr::win, 'adeg_w'),
1524 &new_text_box_for_int (\%pr::win, 'adeg_h'))),
1525 _('Edit group window'), 'not-packed'),
1526 &new_subpage_frame (
1529 &new_text_box_for_int (\%pr::win, 'adda_w'),
1530 &new_text_box_for_int (\%pr::win, 'adda_h'))),
1531 _('Add address window'), 'not-packed'),
1532 &new_subpage_frame (
1535 &new_text_box_for_int (\%pr::win, 'addf_w'),
1536 &new_text_box_for_int (\%pr::win, 'addf_h'))),
1537 _('Folder select window'), 'not-packed')
1541 sub new_winpos_subpage_accounts() {
1542 return &new_vbox_pack (
1543 &new_subpage_frame (
1546 &new_text_box_for_int (\%pr::win, 'acco_w'),
1547 &new_text_box_for_int (\%pr::win, 'acco_h'))),
1548 _('Accounts window'), 'not-packed'),
1549 &new_subpage_frame (
1552 &new_text_box_for_int (\%pr::win, 'acce_w'),
1553 &new_text_box_for_int (\%pr::win, 'acce_h'))),
1554 _('Edit account window'), 'not-packed')
1558 sub new_winpos_subpage_filtering() {
1559 return &new_vbox_pack (
1560 &new_subpage_frame (
1563 &new_text_box_for_int (\%pr::win, 'filt_w'),
1564 &new_text_box_for_int (\%pr::win, 'filt_h'))),
1565 _('Filtering window'), 'not-packed'),
1566 &new_subpage_frame (
1569 &new_text_box_for_int (\%pr::win, 'fila_w'),
1570 &new_text_box_for_int (\%pr::win, 'fila_h'))),
1571 _('Filtering actions window'), 'not-packed'),
1572 &new_subpage_frame (
1575 &new_text_box_for_int (\%pr::win, 'fild_w'),
1576 &new_text_box_for_int (\%pr::win, 'fild_h'))),
1577 _('Filtering debug window'), 'not-packed'),
1578 &new_subpage_frame (
1581 &new_text_box_for_int (\%pr::win, 'matc_w'),
1582 &new_text_box_for_int (\%pr::win, 'matc_h'))),
1583 _('Matcher window'), 'not-packed')
1587 sub new_winpos_subpage_prefs() {
1588 return &new_vbox_pack (
1589 &new_subpage_frame (
1592 &new_text_box_for_int (\%pr::win, 'pref_w'),
1593 &new_text_box_for_int (\%pr::win, 'pref_h'))),
1594 _('Preferences window'), 'not-packed'),
1595 &new_subpage_frame (
1598 &new_text_box_for_int (\%pr::win, 'temp_w'),
1599 &new_text_box_for_int (\%pr::win, 'temp_h'))),
1600 _('Templates window'), 'not-packed'),
1601 &new_subpage_frame (
1604 &new_text_box_for_int (\%pr::win, 'acti_w'),
1605 &new_text_box_for_int (\%pr::win, 'acti_h'))),
1606 _('Actions window'), 'not-packed'),
1607 &new_subpage_frame (
1610 &new_text_box_for_int (\%pr::win, 'tags_w'),
1611 &new_text_box_for_int (\%pr::win, 'tags_h'))),
1612 _('Tags window'), 'not-packed'),
1613 &new_subpage_frame (
1616 &new_text_box_for_int (\%pr::win, 'plug_w'),
1617 &new_text_box_for_int (\%pr::win, 'plug_h'))),
1618 _('Plugins window'), 'not-packed')
1622 sub new_winpos_subpage_misc() {
1623 return &new_vbox_pack (
1624 &new_subpage_frame (
1627 &new_text_box_for_int (\%pr::win, 'logw_w'),
1628 &new_text_box_for_int (\%pr::win, 'logw_h'))),
1629 _('Log window'), 'not-packed'),
1630 &new_subpage_frame (
1633 &new_text_box_for_int (\%pr::win, 'prin_w'),
1634 &new_text_box_for_int (\%pr::win, 'prin_h'))),
1635 _('Print preview window'), 'not-packed'),
1636 &new_subpage_frame (
1638 &new_text_box_for_int (\%pr::win, 'sour_w'),
1639 &new_text_box_for_int (\%pr::win, 'sour_h')),
1640 _('View source window'), 'not-packed')
1644 sub new_winpos_page() {
1645 my $winbook = Gtk2::Notebook->new;
1646 $winbook->set_tab_pos ('right');
1647 $winbook->append_page (&new_winpos_subpage_main, _('Main'));
1648 $winbook->append_page (&new_winpos_subpage_msgs, _('Message'));
1649 $winbook->append_page (&new_winpos_subpage_sendrecv, _('Send/Receive'));
1650 $winbook->append_page (&new_winpos_subpage_fold, _('Folder'));
1651 $winbook->append_page (&new_winpos_subpage_addrbook, _('Addressbook'));
1652 $winbook->append_page (&new_winpos_subpage_accounts, _('Accounts'));
1653 $winbook->append_page (&new_winpos_subpage_filtering, _('Filtering'));
1654 $winbook->append_page (&new_winpos_subpage_prefs, _('Preferences'));
1655 $winbook->append_page (&new_winpos_subpage_misc, _('Other'));
1660 sub print_version() {
1661 print $xl::s{about_title} . "\n";
1662 print $xl::s{about_version} . " $VERSION\n";
1663 print "Perl-GLib " . $Glib::VERSION;
1664 # version info stuff appeared in 1.040
1665 if ($Glib::VERSION >= 1.040) {
1666 print _(", built for ") . join(".", Glib->GET_VERSION_INFO)
1667 . _(", running with ") . join(".", &Glib::major_version,
1668 &Glib::minor_version, &Glib::micro_version);
1671 print "Perl-GTK2 " . $Gtk2::VERSION;
1672 if ($Gtk2::VERSION >= 1.040) {
1673 print _(", built for ") . join(".", Gtk2->GET_VERSION_INFO)
1674 . _(", running with ") . join(".", &Gtk2::major_version,
1675 &Gtk2::minor_version, &Gtk2::micro_version);
1678 my $clawsver = ($CLAWSV eq "") ?
1679 _("was not found!") :
1680 (_("returned version ") . $CLAWSV);
1681 print "Claws Mail " . $clawsver . "\n";
1684 # the command line help
1686 my $line = '-' x length ($xl::s{about_title}) . "\n";
1688 print $xl::s{about_title} . "\n";
1690 print _("Syntax:\n");
1691 print _(" clawsker [options]\n");
1692 print _("Options:\n");
1693 print _(" --help Prints this help screen.\n");
1694 print _(" --version Prints version infos.\n");
1695 print _(" --verbose More messages on standard output.\n");
1696 print _(" --alternate-config-dir <dir> Uses <dir> as Claws Mail config dir.\n");
1697 print _(" --clawsrc <file> Uses <file> as full resource name.\n");
1700 # handle errors which don't allow to run
1701 sub command_line_fatal() {
1703 my $emsg = $xl::s{e_error} . $reason;
1704 error_dialog ($emsg);
1705 log_message ("$emsg", 'die');
1708 # parse the command line
1709 sub parse_command_line() {
1710 $CLAWSV = &get_claws_version;
1712 while (defined($ARGV[$arg])) {
1726 /--use-claws-version/ && do {
1728 &command_line_fatal ("required version")
1729 unless defined($ARGV[$arg]);
1730 &command_line_fatal ("required a dotted numeric value")
1731 unless ($ARGV[$arg] =~ /[\d\.]+/);
1732 $CLAWSV = $ARGV[$arg];
1735 /--alternate-config-dir/ && do {
1737 &command_line_fatal ($xl::s{e_requireddir})
1738 unless defined($ARGV[$arg]);
1739 &command_line_fatal ($xl::s{e_notadir})
1740 unless -d $ARGV[$arg];
1741 $CONFIGDIR = $ARGV[$arg];
1743 unless ($CONFIGDIR =~ /.*\/$/);
1744 $ALTCONFIGDIR = TRUE;
1749 &command_line_fatal($xl::s{e_requiredfile})
1750 unless defined($ARGV[$arg]);
1751 &command_line_fatal($xl::s{e_notafile})
1752 unless -f $ARGV[$arg];
1753 &set_rc_filename ($ARGV[$arg]);
1756 /.*/ && &command_line_fatal (
1757 _("unknown option '{opt}'.\n", opt => $ARGV[$arg]));
1761 # eveything continues...
1765 # update the hidden preferences status from loaded values
1766 sub init_hidden_preferences() {
1767 foreach my $hash (\%pr::beh, \%pr::col, \%pr::gui, \%pr::oth, \%pr::win) {
1768 foreach my $key (keys %$hash) {
1769 $HPVALUE{${$hash}{$key}[NAME]} = $PREFS{${$hash}{$key}[NAME]};
1775 # load current status from disc
1776 sub load_preferences() {
1777 my $rc = &get_rc_filename;
1778 &log_message ("Loading preferences from $rc\n");
1779 return FALSE unless &check_rc_file ($rc);
1780 return FALSE unless &check_claws_not_running;
1784 if (/^([8a-z_]+)=(.*)$/) {
1792 # save current preferences to disc
1793 sub save_preferences() {
1794 my $rc = &get_rc_filename;
1795 &log_message ("Saving preferences to $rc\n");
1796 return FALSE unless &check_rc_file ($rc);
1797 return FALSE unless &check_claws_not_running;
1798 my $rcbak = "$rc.backup";
1799 rename ($rc, $rcbak);
1801 open (RCB, "<$rcbak");
1804 if (/^([8a-z_]+)=(.*)$/) {
1805 if (defined($HPVALUE{$1})) {
1806 print RCF $1 . "=" . $HPVALUE{$1} . "\n";
1809 print RCF $_ . "\n";
1813 print RCF $_ . "\n";
1822 sub new_notebook() {
1823 my $nb = Gtk2::Notebook->new;
1825 $nb->append_page (&new_behaviour_page, $xl::s{tab_behaviour});
1826 $nb->append_page (&new_colours_page, $xl::s{tab_colours});
1827 $nb->append_page (&new_gui_page, $xl::s{tab_gui});
1828 $nb->append_page (&new_other_page, $xl::s{tab_other});
1829 $nb->append_page (&new_winpos_page, $xl::s{tab_winpos});
1834 # create an about dialog
1835 sub new_about_dialog() {
1837 my $title = $xl::s{about_title};
1838 my $lic = $xl::s{about_license};
1839 my $vers = $xl::s{about_version} . " $VERSION";
1841 "This program is free software: you can redistribute it and/or modify
1842 it under the terms of the GNU General Public License as published by
1843 the Free Software Foundation, either version 3 of the License, or
1844 (at your option) any later version.
1846 This program is distributed in the hope that it will be useful,
1847 but WITHOUT ANY WARRANTY; without even the implied warranty of
1848 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1849 GNU General Public License for more details.
1851 You should have received a copy of the GNU General Public License
1852 along with this program. If not, see <http://www.gnu.org/licenses/>.";
1853 my $year = "2007-2009";
1854 my $holder = "Ricardo Mones <ricardo\@mones.org>";
1855 my $url = "http://www.claws-mail.org/clawsker";
1857 my $dialog = Gtk2::MessageDialog->new_with_markup ($parent,
1858 [qw/modal destroy-with-parent/],
1860 "<span size=\"x-large\" weight=\"bold\">$title</span>\n"
1861 . "<span size=\"large\">$vers</span>\n\n"
1862 . "<span color=\"blue\" size=\"large\">$url</span>\n\n"
1863 . "<span>Copyright $year by $holder</span>\n\n"
1864 . "<span size=\"large\">$lic</span>\n\n"
1865 . "<span size=\"small\">$license</span>");
1866 $dialog->set_title ($xl::s{about});
1871 # create buttons box
1872 sub new_button_box() {
1873 my ($parent, $adlg) = @_;
1874 my $b_about = Gtk2::Button->new_from_stock ('gtk-about');
1875 my $b_exit = Gtk2::Button->new_from_stock ('gtk-quit');
1876 my $b_apply = Gtk2::Button->new_from_stock ('gtk-apply');
1877 # disable button until is really implemented
1878 # my $b_undo = Gtk2::Button->new_from_stock ('gtk-undo');
1879 my $hbox = Gtk2::HBox->new (FALSE, 5);
1881 $b_exit->signal_connect (clicked => sub { Gtk2->main_quit });
1882 $b_apply->signal_connect (clicked => sub { &save_preferences ($parent) });
1883 # $b_undo->signal_connect (clicked => sub { &undo_current_changes });
1884 $b_about->signal_connect (clicked => sub { $adlg->run; $adlg->hide });
1886 $hbox->pack_end ($b_apply, FALSE, FALSE, 0);
1887 $hbox->pack_end ($b_exit, FALSE, FALSE, 0);
1888 # $hbox->pack_end ($b_undo, FALSE, FALSE, 0);
1889 $hbox->pack_start ($b_about, FALSE, FALSE, 0);
1895 $main_window = Gtk2::Window->new ('toplevel');
1896 exit unless &parse_command_line;
1897 exit unless &load_preferences;
1898 exit unless &init_hidden_preferences;
1900 my $box = Gtk2::VBox->new (FALSE, 5);
1901 $box->set_border_width(3);
1902 my $about = &new_about_dialog;
1903 $box->pack_start (&new_notebook, FALSE, FALSE, 0);
1904 $box->pack_end (&new_button_box ($main_window, $about), FALSE, FALSE, 0);
1905 $main_window->signal_connect (delete_event => sub { Gtk2->main_quit });
1906 $main_window->set_title ($xl::s{win_title});
1907 $main_window->add ($box);
1908 $main_window->show_all;