2ce29d52ec9b2c6c4723a7940034369037f31f8c
[clawsker.git] / clawsker
1 #!/usr/bin/perl -w
2 #
3 # Clawsker :: A Claws Mail Tweaker
4 # $Id$
5 #
6 use strict;
7 use encoding 'utf8';
8 use Glib qw(TRUE FALSE);
9 use Gtk2 -init;
10 use POSIX qw(setlocale);
11 use Locale::gettext;
12
13 my $NAME = 'clawsker';
14 my $PREFIX = '@PREFIX@';
15 my $LIBDIR = '@LIBDIR@';
16 my $VERSION = '@VERSION@';
17 my $VERBOSE = FALSE;
18 my $CLAWSV = undef;
19 my $main_window = undef;
20
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));
25 textdomain ($NAME);
26
27 my $SHOWHINTS = FALSE;
28 $SHOWHINTS = TRUE if ($Gtk2::VERSION >= 1.040 and Gtk2->CHECK_VERSION (2, 12, 0));
29
30 sub _ {
31     my $str = shift;
32     my %par = @_;
33     my $xla = gettext ($str);
34     if (scalar(keys(%par)) > 0) {
35         foreach my $key (keys %par) {
36             $xla =~ s/\{$key\}/$par{$key}/g;
37         }
38     }
39     return $xla;
40 }
41
42 # default messages
43 %xl::s = (
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:'),
49
50     tab_colours => _('Colours'),
51     tab_behaviour => _('Behaviour'),
52     tab_gui => _('GUI'),
53     tab_other => _('Other'),
54     tab_winpos => _('Windows'),
55
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'),
67
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.'),
76     
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.'),
104
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.'),
129
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.'),
142
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.'),
151
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.'),
156
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.'),
164 );
165
166 # all preferences read by load_preferences
167 my %PREFS = ();
168 # values of all preferences handled by clawsker
169 my %HPVALUE = ();
170 # default config dir and file name
171 my $ALTCONFIGDIR = FALSE;
172 my $CONFIGDIR = $ENV{HOME} . '/.claws-mail/';
173 my $CONFIGRC = 'clawsrc';
174
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
183
184 # constants for GUI spacing
185 use constant HBOX_SPC => 5;
186 use constant FRAME_SPC => 2;
187 use constant PAGE_SPC => 5;
188
189 # version functions
190
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');
197   }
198   my $idx = 0;
199   while (($idx <= $#refvers) 
200          and (int ($version[$idx]) == int ($refvers[$idx]))) {
201     ++$idx;
202   }
203   return TRUE if (($idx > $#refvers) 
204                or (int ($version[$idx]) >= int ($refvers[$idx])));
205   return FALSE;
206 }
207
208 sub get_claws_version() {
209     my @cmbin = (
210         'claws-mail',
211     );
212     my $res = "";
213     foreach my $bin (@cmbin) {
214         $_ = qx/which $bin/;
215         chomp;
216         last if ($_ ne "");
217     }
218     return "" unless ($_); # not installed
219     $_ = qx/$_ -v/;
220     chomp;
221     my @fver = split (/ /);
222     die "Invalid version string" unless ($fver[2] eq "version");
223     my @ver = split (/\./, $fver[3]);
224     $res .= "$ver[0].";
225     $res .= "$ver[1].";
226     if ($ver[2] =~ /(\d+)cvs(\d+)/) {
227         $res .= "$1.$2";
228     }
229     else {
230         $res .= "$ver[2].0";
231     }
232     return $res;
233 }
234
235 # data handlers and auxiliar functions
236
237 sub handle_bool_value {
238     my ($widget, $event, $dataref) = @_;
239     $$dataref = ($widget->get_active ())? '1': '0';
240 }
241
242 sub handle_int_value {
243     my ($widget, $event, $dataref) = @_;
244     $_ = $widget->get_text ();
245     s/^\s+//;
246     s/\s+$//;
247     if (/^[0-9]+$/) {
248         $$dataref = $_;
249         $widget->set_text ($_);
250     }
251     else {
252         $widget->set_text ($$dataref);
253     }
254 }
255
256 sub handle_string_value {
257     my ($widget, $event, $dataref) = @_;
258     $$dataref = $widget->get_text ();
259 }
260
261 sub gdk_color_from_str {
262     my ($str) = @_;
263     my ($rr, $gg, $bb) = (0, 0 ,0);
264     $_ = uc ($str);
265     if (/\#([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])/) {
266         $rr = hex($1) * 256;
267         $gg = hex($2) * 256; 
268         $bb = hex($3) * 256;
269     }
270     my $color = Gtk2::Gdk::Color->new ($rr, $gg, $bb);
271     return $color;
272 }
273
274 sub str_from_gdk_color {
275     my ($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);
280     return $str;
281 }
282
283 sub handle_color_value {
284     my ($widget, $event, $dataref) = @_;
285     my $newcol = $widget->get_color;
286     $$dataref = &str_from_gdk_color ($newcol);
287 }
288
289 sub handle_selection_value {
290     my ($widget, $event, $dataref) = @_;
291     $$dataref = $widget->get_active;
292 }
293
294 sub get_rc_filename {
295     return $CONFIGDIR . $CONFIGRC;
296 }
297
298 sub set_rc_filename {
299     my ($fullname) = @_;
300     my @parts = split ('/', $fullname);
301     $CONFIGRC = $parts[$#parts];
302     $parts[$#parts] = '';
303     $CONFIGDIR = join ('/', @parts);
304 }
305
306 sub log_message {
307     my ($mesg, $fatal) = @_;
308     if (defined($fatal) && $fatal eq 'die') {
309         die "$NAME: $mesg\n";
310     }
311     if ($VERBOSE) {
312         print "$NAME: $mesg\n";
313     }
314 }
315
316 sub error_dialog {
317     my ($emsg) = @_;
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'));
321     $errordlg->run;
322     $errordlg->destroy;
323 }
324
325 sub check_claws_not_running() {
326     my $socket = (not $ALTCONFIGDIR)? "/tmp/": $CONFIGDIR;
327     $socket .= "claws-mail-$<";
328     -S $socket and do {
329         my $emsg = "$xl::s{e_error}$xl::s{e_running}";
330         log_message ($emsg);
331         error_dialog ($emsg);
332         return FALSE;
333      };
334
335      return TRUE;
336 }
337
338 sub check_rc_file() {
339     my ($rcfile) = @_;
340     (defined($rcfile) && -f $rcfile) or do {
341        my $emsg = "$xl::s{e_error}$xl::s{e_noclawsrc}\n";
342         log_message ($emsg);
343         error_dialog ($emsg);
344         return FALSE;
345     };
346
347     return TRUE;
348 }
349
350 sub set_widget_hint() {
351     if ($SHOWHINTS) {
352         my ($wdgt, $hint) = @_;    
353         $wdgt->set_tooltip_text ($hint);
354         $wdgt->set_has_tooltip (TRUE);
355     }
356 }
357
358 sub set_widget_sens() {
359     my ($wdgt, $minver) = @_;
360     $wdgt->set_sensitive (&version_greater_or_equal ($CLAWSV, $minver));
361 }
362
363 # graphic element creation 
364
365 sub new_check_button_for {
366     my ($hash, $key) = @_;
367     my $name = $$hash{$key}[NAME];
368     my $label = $$hash{$key}[LABEL];
369     #
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');
375     }
376     $cb->signal_connect (clicked => sub {
377             my ($w, $e) = @_;
378             &handle_bool_value($w, $e, \$HPVALUE{$name});
379         });
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);
383     #
384     return $hbox;
385 }
386
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); 
393     #
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 {
401             my ($w, $e) = @_;
402             &handle_int_value($w, $e, \$HPVALUE{$name});
403         });
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);
409     #
410     return $hbox;
411 }
412
413 sub new_color_button_for {
414     my ($hash, $key) = @_;
415     my $name = $$hash{$key}[NAME];
416     my $label = $$hash{$key}[LABEL];
417     #
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 {
426             my ($w, $e) = @_;
427             &handle_color_value($w, $e, \$HPVALUE{$name}); 
428         });
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);
434     #
435     return $hbox;
436 }
437
438 sub new_selection_box_for {
439     my ($hash, $key) = @_;
440     my $name = $$hash{$key}[NAME];
441     my $label = $$hash{$key}[LABEL];
442     #
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});
451     }
452     $combo->signal_connect ('changed' => sub {
453             my ($w, $e) = @_;
454             &handle_selection_value($w, $e, \$HPVALUE{$name});
455         });
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);
462     #
463     return $hbox;
464 }
465
466 # more graphic helpers
467
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);
473     }
474     return $hbox;
475 }    
476
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);
482     }
483     return $vbox;
484 }    
485
486 sub new_subpage_frame () {
487     my ($box, $title, $notpacked) = @_;
488     my $frame = Gtk2::Frame->new ($title);
489     $frame->add ($box);    
490     return &new_vbox_pack ($frame) unless defined ($notpacked);
491     return $frame;
492 }
493
494 # preference maps and corresponding page creation subs
495
496 %pr::oth = ( # other preferences
497     use_dlg => [ 
498         'addressbook_use_editaddress_dialog',
499         $xl::s{l_oth_use_dlg},
500         $xl::s{h_oth_use_dlg},
501         'bool',
502         '2.7.0',
503         '0',
504         undef,
505     ],
506     max_use => [
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
511         '0.0.0',
512         '4096',
513         undef,
514     ],
515     min_time => [
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
520         '0.0.0',
521         '15',
522         undef,
523     ],
524     use_netm => [
525         'use_networkmanager',
526         $xl::s{l_oth_use_netm},
527         $xl::s{h_oth_use_netm},
528         'bool',
529         '3.3.1',
530         '1',
531         undef,
532     ],
533 );
534
535 sub new_other_page() {
536     return &new_vbox_pack (
537                &new_subpage_frame (
538                    &new_vbox_pack (
539                        &new_check_button_for(\%pr::oth, 'use_dlg')),
540                    $xl::s{ab_frame}, 'not-packed'),
541                &new_subpage_frame (
542                    &new_vbox_pack (
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'),
546                &new_subpage_frame (
547                    &new_vbox_pack (
548                        &new_check_button_for(\%pr::oth, 'use_netm')),
549                    $xl::s{netm_frame}, 'not-packed')
550            );
551 }
552
553 %pr::gui = ( # gui bells and whistles
554     b_unread => [ 
555         'bold_unread',
556         $xl::s{l_gui_b_unread},
557         $xl::s{h_gui_b_unread},
558         'bool',
559         '0.0.0',
560         '1',
561         undef,
562     ],
563     no_markup => [
564         'compose_no_markup',
565         $xl::s{l_gui_no_markup},
566         $xl::s{h_gui_no_markup},
567         'bool',
568         '0.0.0',
569         '0',
570         undef,
571     ],
572     dot_lines => [
573         'enable_dotted_lines',
574         $xl::s{l_gui_dot_lines},
575         $xl::s{h_gui_dot_lines},
576         'bool',
577         '0.0.0',
578         '0',
579         undef,
580     ],
581     h_scroll => [
582         'enable_hscrollbar',
583         $xl::s{l_gui_h_scroll},
584         $xl::s{h_gui_h_scroll},
585         'bool',
586         '0.0.0',
587         '1',
588         undef,
589     ],
590     swp_from => [
591         'enable_swap_from',
592         $xl::s{l_gui_swp_from},
593         $xl::s{h_gui_swp_from},
594         'bool',
595         '0.0.0',
596         '0',
597         undef,
598     ],
599     v_scroll => [
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',
604         '0.0.0',
605         '0',
606         undef,
607     ],
608     strip_off => [
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
613         '0.0.0',
614         '4000',
615         undef,
616     ],
617     cursor_v => [
618         'textview_cursor_visible',
619         $xl::s{l_gui_cursor_v},
620         $xl::s{h_gui_cursor_v},
621         'bool',
622         '0.0.0',
623         '0',
624         undef,
625     ],
626     toolbar_d => [
627         'toolbar_detachable',
628         $xl::s{l_gui_toolbar_d},
629         $xl::s{h_gui_toolbar_d},
630         'bool',
631         '0.0.0',
632         '0',
633         undef,
634     ],
635     strip_all => [
636         'use_stripes_everywhere',
637         $xl::s{l_gui_strip_all},
638         $xl::s{h_gui_strip_all},
639         'bool',
640         '0.0.0',
641         '1',
642         undef,
643     ],
644     strip_sum => [
645         'use_stripes_in_summaries',
646         $xl::s{l_gui_strip_sum},
647         $xl::s{h_gui_strip_sum},
648         'bool',
649         '0.0.0',
650         '1',
651         undef,
652     ],
653     two_linev => [
654         'two_line_vertical',
655         $xl::s{l_gui_two_line_v},
656         $xl::s{h_gui_two_line_v},
657         'bool',
658         '3.4.0.7',
659         '0',
660         undef,
661     ],
662 );
663
664 sub new_gui_page() {
665     my $gf = Gtk2::VBox->new (FALSE, 5);
666     $gf->set_border_width (PAGE_SPC);
667
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');
673
674     $gf->pack_start (&new_subpage_frame (
675                          &new_vbox_pack (
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 (
682                          &new_vbox_pack (
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 (
693                          &new_vbox_pack (
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);
698
699     return $gf;
700 }
701
702 %pr::beh = ( # tweak some behaviour
703     hover_t => [
704         'hover_timeout',
705         $xl::s{l_beh_hover_t},
706         $xl::s{h_beh_hover_t},
707         'int,100,3000', # 0.1 seconds - 3 seconds
708         '0.0.0',
709         '500',
710         undef,
711     ],
712     dangerous => [
713         'live_dangerously',
714         $xl::s{l_beh_dangerous},
715         $xl::s{h_beh_dangerous},
716         'bool',
717         '0.0.0',
718         '0',
719         undef,
720     ],
721     flowed => [
722         'respect_flowed_format',
723         $xl::s{l_beh_flowed},
724         $xl::s{h_beh_flowed},
725         'bool',
726         '0.0.0',
727         '0',
728         undef,
729     ],
730     parts_rw => [
731         'save_parts_readwrite',
732         $xl::s{l_beh_parts_rw},
733         $xl::s{h_beh_parts_rw},
734         'bool',
735         '0.0.0',
736         '0',
737         undef,
738     ],
739     skip_ssl => [
740         'skip_ssl_cert_check',
741         $xl::s{l_beh_skip_ssl},
742         $xl::s{h_beh_skip_ssl},
743         'bool',
744         '0.0.0',
745         '0',
746         undef,
747     ],
748     up_step => [
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
753         '0.0.0',
754         '10',
755         undef,
756     ],
757     thread_a => [
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
762         '0.0.0',
763         '10',
764         undef,
765     ],
766     unsafe_ssl => [
767         'unsafe_ssl_certs',
768         $xl::s{l_beh_unsafe_ssl},
769         $xl::s{h_beh_unsafe_ssl},
770         'bool',
771         '0.0.0',
772         '0',
773         undef,
774     ],
775     use_utf8 => [
776         'utf8_instead_of_locale_for_broken_mail',
777         $xl::s{l_beh_use_utf8},
778         $xl::s{h_beh_use_utf8},
779         'bool',
780         '0.0.0',
781         '0',
782         undef,
783     ],
784     warn_dnd => [
785         'warn_dnd',
786         $xl::s{l_beh_warn_dnd},
787         $xl::s{h_beh_warn_dnd},
788         'bool',
789         '0.0.0',
790         '1',
791         undef,
792     ],
793     out_ascii => [
794         'outgoing_fallback_to_ascii',
795         $xl::s{l_beh_out_ascii},
796         $xl::s{h_beh_out_ascii},
797         'bool',
798         '3.4.0.37',
799         '1',
800         undef,
801     ],
802     pp_unsel => [
803         'primary_paste_unselects',
804         $xl::s{l_beh_pp_unsel},
805         $xl::s{h_beh_pp_unsel},
806         'bool',
807         '3.6.1.35',
808         '0',
809         undef,
810     ],
811 );
812
813 sub new_behaviour_page() {
814     my $bf = Gtk2::VBox->new (FALSE, 5);
815     $bf->set_border_width (PAGE_SPC);
816
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');
819
820     $bf->pack_start (&new_subpage_frame (
821                          &new_vbox_pack (
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 (
827                          &new_hbox_pack (
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 (
835                          &new_vbox_pack (
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);
844
845     return $bf;
846 }
847
848 %pr::col = ( # a variety of colours
849     emphasis => [
850         'emphasis_color',
851         $xl::s{l_col_emphasis},
852         $xl::s{h_col_emphasis},
853         'color',
854         '0.0.0',
855         '#0000cf',
856         undef,
857     ],
858     log_err => [
859         'log_error_color',
860         $xl::s{l_col_log_err},
861         $xl::s{h_col_log_err},
862         'color',
863         '0.0.0',
864         '#af0000',
865         undef,
866     ],
867     log_in => [
868         'log_in_color',
869         $xl::s{l_col_log_in},
870         $xl::s{h_col_log_in},
871         'color',
872         '0.0.0',
873         '#000000',
874         undef,
875     ],
876     log_msg => [
877         'log_msg_color',
878         $xl::s{l_col_log_msg},
879         $xl::s{h_col_log_msg},
880         'color',
881         '0.0.0',
882         '#00af00',
883         undef,
884     ],
885     log_out => [
886         'log_out_color',
887         $xl::s{l_col_log_out},
888         $xl::s{h_col_log_out},
889         'color',
890         '0.0.0',
891         '#0000ef',
892         undef,
893     ],
894     log_warn => [
895         'log_warn_color',
896         $xl::s{l_col_log_warn},
897         $xl::s{h_col_log_warn},
898         'color',
899         '0.0.0',
900         '#af0000',
901         undef,
902     ],
903 );
904
905 sub new_colours_page() {
906     return &new_vbox_pack (
907                &new_subpage_frame (
908                    &new_vbox_pack (
909                        &new_color_button_for (\%pr::col, 'emphasis')),
910                    $xl::s{msgview_frame}, 'not-packed'),
911                &new_subpage_frame (
912                    &new_vbox_pack (
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')
919            );
920 }
921
922 %pr::win = ( # tweak window positions and/or sizes
923     main_x => [
924         'mainwin_x',
925         $xl::s{l_win_x},
926         $xl::s{h_win_x},
927         'int,0,3000', # 0 pixels - 3000 pixels
928         '0.0.0',
929         '16',
930         undef,
931     ],
932     main_y => [
933         'mainwin_y',
934         $xl::s{l_win_y},
935         $xl::s{h_win_y},
936         'int,0,3000', # 0 pixels - 3000 pixels
937         '0.0.0',
938         '16',
939         undef,
940     ],
941     main_w => [
942         'mainwin_width',
943         $xl::s{l_win_w},
944         $xl::s{h_win_w},
945         'int,0,3000', # 0 pixels - 3000 pixels
946         '0.0.0',
947         '779',
948         undef,
949     ],
950     main_h => [
951         'mainwin_height',
952         $xl::s{l_win_h},
953         $xl::s{h_win_h},
954         'int,0,3000', # 0 pixels - 3000 pixels
955         '0.0.0',
956         '568',
957         undef,
958     ],
959     main_mx => [
960         'mainwin_maximised',
961         $xl::s{l_win_main_mx},
962         $xl::s{h_win_main_mx},
963         'bool',
964         '0.0.0',
965         '0',
966         undef,
967     ],
968     main_fs => [
969         'mainwin_fullscreen',
970         $xl::s{l_win_main_fs},
971         $xl::s{h_win_main_fs},
972         'bool',
973         '0.0.0',
974         '0',
975         undef,
976     ],
977     msgs_x => [
978         'main_messagewin_x',
979         $xl::s{l_win_x},
980         $xl::s{h_win_x},
981         'int,0,3000', # 0 pixels - 3000 pixels
982         '0.0.0',
983         '256',
984         undef,
985     ],
986     msgs_y => [
987         'main_messagewin_y',
988         $xl::s{l_win_y},
989         $xl::s{h_win_y},
990         'int,0,3000', # 0 pixels - 3000 pixels
991         '0.0.0',
992         '210',
993         undef,
994     ],
995     msgs_w => [
996         'messagewin_width',
997         $xl::s{l_win_w},
998         $xl::s{h_win_w},
999         'int,0,3000', # 0 pixels - 3000 pixels
1000         '0.0.0',
1001         '600',
1002         undef,
1003     ],
1004     msgs_h => [
1005         'messagewin_height',
1006         $xl::s{l_win_h},
1007         $xl::s{h_win_h},
1008         'int,0,3000', # 0 pixels - 3000 pixels
1009         '0.0.0',
1010         '540',
1011         undef,
1012     ],
1013     send_w => [
1014         'sendwin_width',
1015         $xl::s{l_win_w},
1016         $xl::s{h_win_w},
1017         'int,0,3000', # 0 pixels - 3000 pixels
1018         '0.0.0',
1019         '460',
1020         undef,
1021     ],
1022     send_h => [
1023         'sendwin_height',
1024         $xl::s{l_win_h},
1025         $xl::s{h_win_h},
1026         'int,0,3000', # 0 pixels - 3000 pixels
1027         '0.0.0',
1028         '-1',
1029         undef,
1030     ],
1031     recv_w => [
1032         'receivewin_width',
1033         $xl::s{l_win_w},
1034         $xl::s{h_win_w},
1035         'int,0,3000', # 0 pixels - 3000 pixels
1036         '0.0.0',
1037         '460',
1038         undef,
1039     ],
1040     recv_h => [
1041         'receivewin_height',
1042         $xl::s{l_win_h},
1043         $xl::s{h_win_h},
1044         'int,0,3000', # 0 pixels - 3000 pixels
1045         '0.0.0',
1046         '-1',
1047         undef,
1048     ],
1049     fold_x => [
1050         'folderwin_x',
1051         $xl::s{l_win_x},
1052         $xl::s{h_win_x},
1053         'int,0,3000', # 0 pixels - 3000 pixels
1054         '0.0.0',
1055         '16',
1056         undef,
1057     ],
1058     fold_y => [
1059         'folderwin_y',
1060         $xl::s{l_win_y},
1061         $xl::s{h_win_y},
1062         'int,0,3000', # 0 pixels - 3000 pixels
1063         '0.0.0',
1064         '16',
1065         undef,
1066     ],
1067     fold_w => [
1068         'folderitemwin_width',
1069         $xl::s{l_win_w},
1070         $xl::s{h_win_w},
1071         'int,0,3000', # 0 pixels - 3000 pixels
1072         '0.0.0',
1073         '500',
1074         undef,
1075     ],
1076     fold_h => [
1077         'folderitemwin_height',
1078         $xl::s{l_win_h},
1079         $xl::s{h_win_h},
1080         'int,0,3000', # 0 pixels - 3000 pixels
1081         '0.0.0',
1082         '-1',
1083         undef,
1084     ],
1085     fsel_w => [
1086         'folderselwin_width',
1087         $xl::s{l_win_w},
1088         $xl::s{h_win_w},
1089         'int,0,3000', # 0 pixels - 3000 pixels
1090         '0.0.0',
1091         '300',
1092         undef,
1093     ],
1094     fsel_h => [
1095         'folderselwin_height',
1096         $xl::s{l_win_h},
1097         $xl::s{h_win_h},
1098         'int,0,3000', # 0 pixels - 3000 pixels
1099         '0.0.0',
1100         '-1',
1101         undef,
1102     ],
1103     sour_w => [
1104         'sourcewin_width',
1105         $xl::s{l_win_w},
1106         $xl::s{h_win_w},
1107         'int,0,3000', # 0 pixels - 3000 pixels
1108         '0.0.0',
1109         '600',
1110         undef,
1111     ],
1112     sour_h => [
1113         'sourcewin_height',
1114         $xl::s{l_win_h},
1115         $xl::s{h_win_h},
1116         'int,0,3000', # 0 pixels - 3000 pixels
1117         '0.0.0',
1118         '500',
1119         undef,
1120     ],
1121     addr_w => [
1122         'addressbookwin_width',
1123         $xl::s{l_win_w},
1124         $xl::s{h_win_w},
1125         'int,0,3000', # 0 pixels - 3000 pixels
1126         '0.0.0',
1127         '520',
1128         undef,
1129     ],
1130     addr_h => [
1131         'addressbookwin_height',
1132         $xl::s{l_win_h},
1133         $xl::s{h_win_h},
1134         'int,0,3000', # 0 pixels - 3000 pixels
1135         '0.0.0',
1136         '-1',
1137         undef,
1138     ],
1139     adep_w => [
1140         'addressbookeditpersonwin_width',
1141         $xl::s{l_win_w},
1142         $xl::s{h_win_w},
1143         'int,0,3000', # 0 pixels - 3000 pixels
1144         '0.0.0',
1145         '640',
1146         undef,
1147     ],
1148     adep_h => [
1149         'addressbookeditpersonwin_height',
1150         $xl::s{l_win_h},
1151         $xl::s{h_win_h},
1152         'int,0,3000', # 0 pixels - 3000 pixels
1153         '0.0.0',
1154         '320',
1155         undef,
1156     ],
1157     adeg_w => [
1158         'addressbookeditgroupwin_width',
1159         $xl::s{l_win_w},
1160         $xl::s{h_win_w},
1161         'int,0,3000', # 0 pixels - 3000 pixels
1162         '0.0.0',
1163         '580',
1164         undef,
1165     ],
1166     adeg_h => [
1167         'addressbookeditgroupwin_height',
1168         $xl::s{l_win_h},
1169         $xl::s{h_win_h},
1170         'int,0,3000', # 0 pixels - 3000 pixels
1171         '0.0.0',
1172         '340',
1173         undef,
1174     ],
1175     adda_w => [
1176         'addressaddwin_width',
1177         $xl::s{l_win_w},
1178         $xl::s{h_win_w},
1179         'int,0,3000', # 0 pixels - 3000 pixels
1180         '0.0.0',
1181         '300',
1182         undef,
1183     ],
1184     adda_h => [
1185         'addressaddwin_height',
1186         $xl::s{l_win_h},
1187         $xl::s{h_win_h},
1188         'int,0,3000', # 0 pixels - 3000 pixels
1189         '0.0.0',
1190         '-1',
1191         undef,
1192     ],
1193     addf_w => [
1194         'addressbook_folderselwin_width',
1195         $xl::s{l_win_w},
1196         $xl::s{h_win_w},
1197         'int,0,3000', # 0 pixels - 3000 pixels
1198         '0.0.0',
1199         '300',
1200         undef,
1201     ],
1202     addf_h => [
1203         'addressbook_folderselwin_height',
1204         $xl::s{l_win_h},
1205         $xl::s{h_win_h},
1206         'int,0,3000', # 0 pixels - 3000 pixels
1207         '0.0.0',
1208         '-1',
1209         undef,
1210     ],
1211     acce_w => [
1212         'editaccountwin_width',
1213         $xl::s{l_win_w},
1214         $xl::s{h_win_w},
1215         'int,0,3000', # 0 pixels - 3000 pixels
1216         '0.0.0',
1217         '500',
1218         undef,
1219     ],
1220     acce_h => [
1221         'editaccountwin_height',
1222         $xl::s{l_win_h},
1223         $xl::s{h_win_h},
1224         'int,0,3000', # 0 pixels - 3000 pixels
1225         '0.0.0',
1226         '-1',
1227         undef,
1228     ],
1229     acco_w => [
1230         'accountswin_width',
1231         $xl::s{l_win_w},
1232         $xl::s{h_win_w},
1233         'int,0,3000', # 0 pixels - 3000 pixels
1234         '0.0.0',
1235         '500',
1236         undef,
1237     ],
1238     acco_h => [
1239         'accountswin_height',
1240         $xl::s{l_win_h},
1241         $xl::s{h_win_h},
1242         'int,0,3000', # 0 pixels - 3000 pixels
1243         '0.0.0',
1244         '-1',
1245         undef,
1246     ],
1247     filt_w => [
1248         'filteringwin_width',
1249         $xl::s{l_win_w},
1250         $xl::s{h_win_w},
1251         'int,0,3000', # 0 pixels - 3000 pixels
1252         '0.0.0',
1253         '500',
1254         undef,
1255     ],
1256     filt_h => [
1257         'filteringwin_height',
1258         $xl::s{l_win_h},
1259         $xl::s{h_win_h},
1260         'int,0,3000', # 0 pixels - 3000 pixels
1261         '0.0.0',
1262         '-1',
1263         undef,
1264     ],
1265     fila_w => [
1266         'filteringactionwin_width',
1267         $xl::s{l_win_w},
1268         $xl::s{h_win_w},
1269         'int,0,3000', # 0 pixels - 3000 pixels
1270         '0.0.0',
1271         '490',
1272         undef,
1273     ],
1274     fila_h => [
1275         'filteringactionwin_height',
1276         $xl::s{l_win_h},
1277         $xl::s{h_win_h},
1278         'int,0,3000', # 0 pixels - 3000 pixels
1279         '0.0.0',
1280         '-1',
1281         undef,
1282     ],
1283     fild_w => [
1284         'filtering_debugwin_width',
1285         $xl::s{l_win_w},
1286         $xl::s{h_win_w},
1287         'int,0,3000', # 0 pixels - 3000 pixels
1288         '0.0.0',
1289         '600',
1290         undef,
1291     ],
1292     fild_h => [
1293         'filtering_debugwin_height',
1294         $xl::s{l_win_h},
1295         $xl::s{h_win_h},
1296         'int,0,3000', # 0 pixels - 3000 pixels
1297         '0.0.0',
1298         '-1',
1299         undef,
1300     ],
1301     matc_w => [
1302         'matcherwin_width',
1303         $xl::s{l_win_w},
1304         $xl::s{h_win_w},
1305         'int,0,3000', # 0 pixels - 3000 pixels
1306         '0.0.0',
1307         '520',
1308         undef,
1309     ],
1310     matc_h => [
1311         'matcherwin_height',
1312         $xl::s{l_win_h},
1313         $xl::s{h_win_h},
1314         'int,0,3000', # 0 pixels - 3000 pixels
1315         '0.0.0',
1316         '-1',
1317         undef,
1318     ],
1319     pref_w => [
1320         'prefswin_width',
1321         $xl::s{l_win_w},
1322         $xl::s{h_win_w},
1323         'int,0,3000', # 0 pixels - 3000 pixels
1324         '0.0.0',
1325         '600',
1326         undef,
1327     ],
1328     pref_h => [
1329         'prefswin_height',
1330         $xl::s{l_win_h},
1331         $xl::s{h_win_h},
1332         'int,0,3000', # 0 pixels - 3000 pixels
1333         '0.0.0',
1334         '-1',
1335         undef,
1336     ],
1337     temp_w => [
1338         'templateswin_width',
1339         $xl::s{l_win_w},
1340         $xl::s{h_win_w},
1341         'int,0,3000', # 0 pixels - 3000 pixels
1342         '0.0.0',
1343         '480',
1344         undef,
1345     ],
1346     temp_h => [
1347         'templateswin_height',
1348         $xl::s{l_win_h},
1349         $xl::s{h_win_h},
1350         'int,0,3000', # 0 pixels - 3000 pixels
1351         '0.0.0',
1352         '-1',
1353         undef,
1354     ],
1355     acti_w => [
1356         'actionswin_width',
1357         $xl::s{l_win_w},
1358         $xl::s{h_win_w},
1359         'int,0,3000', # 0 pixels - 3000 pixels
1360         '0.0.0',
1361         '486',
1362         undef,
1363     ],
1364     acti_h => [
1365         'actionswin_height',
1366         $xl::s{l_win_h},
1367         $xl::s{h_win_h},
1368         'int,0,3000', # 0 pixels - 3000 pixels
1369         '0.0.0',
1370         '-1',
1371         undef,
1372     ],
1373     tags_w => [
1374         'tagswin_width',
1375         $xl::s{l_win_w},
1376         $xl::s{h_win_w},
1377         'int,0,3000', # 0 pixels - 3000 pixels
1378         '0.0.0',
1379         '486',
1380         undef,
1381     ],
1382     tags_h => [
1383         'tagswin_height',
1384         $xl::s{l_win_h},
1385         $xl::s{h_win_h},
1386         'int,0,3000', # 0 pixels - 3000 pixels
1387         '0.0.0',
1388         '-1',
1389         undef,
1390     ],
1391     plug_w => [
1392         'pluginswin_width',
1393         $xl::s{l_win_w},
1394         $xl::s{h_win_w},
1395         'int,0,3000', # 0 pixels - 3000 pixels
1396         '0.0.0',
1397         '-1',
1398         undef,
1399     ],
1400     plug_h => [
1401         'pluginswin_height',
1402         $xl::s{l_win_h},
1403         $xl::s{h_win_h},
1404         'int,0,3000', # 0 pixels - 3000 pixels
1405         '0.0.0',
1406         '-1',
1407         undef,
1408     ],
1409     logw_w => [
1410         'logwin_width',
1411         $xl::s{l_win_w},
1412         $xl::s{h_win_w},
1413         'int,0,3000', # 0 pixels - 3000 pixels
1414         '0.0.0',
1415         '520',
1416         undef,
1417     ],
1418     logw_h => [
1419         'logwin_height',
1420         $xl::s{l_win_h},
1421         $xl::s{h_win_h},
1422         'int,0,3000', # 0 pixels - 3000 pixels
1423         '0.0.0',
1424         '-1',
1425         undef,
1426     ],
1427     prin_w => [
1428         'print_previewwin_width',
1429         $xl::s{l_win_w},
1430         $xl::s{h_win_w},
1431         'int,0,3000', # 0 pixels - 3000 pixels
1432         '0.0.0',
1433         '600',
1434         undef,
1435     ],
1436     prin_h => [
1437         'print_previewwin_height',
1438         $xl::s{l_win_h},
1439         $xl::s{h_win_h},
1440         'int,0,3000', # 0 pixels - 3000 pixels
1441         '0.0.0',
1442         '-1',
1443         undef,
1444     ],
1445 );
1446
1447 sub new_winpos_subpage_main() {
1448     return &new_subpage_frame (
1449                &new_vbox_pack (
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'), 
1454                    &new_hbox_pack (
1455                        &new_check_button_for (\%pr::win, 'main_fs'), 
1456                        &new_check_button_for (\%pr::win, 'main_mx'))),
1457                _('Main window')
1458            );
1459 }
1460
1461 sub new_winpos_subpage_msgs() {
1462     return &new_subpage_frame (
1463                &new_vbox_pack (
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')),
1468                _('Message window')
1469            );
1470 }
1471
1472 sub new_winpos_subpage_sendrecv() {
1473     return &new_vbox_pack (
1474                &new_subpage_frame (
1475                    &new_vbox_pack (
1476                        &new_hbox_pack (
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 (
1481                    &new_vbox_pack (
1482                        &new_hbox_pack (
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')
1486            );
1487 }
1488
1489 sub new_winpos_subpage_fold() {
1490     return &new_vbox_pack (
1491                &new_subpage_frame (
1492                    &new_vbox_pack (
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 (
1499                    &new_vbox_pack (
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')
1503            );
1504 }
1505
1506 sub new_winpos_subpage_addrbook() {
1507     return &new_vbox_pack (
1508                 &new_subpage_frame (
1509                      &new_vbox_pack (
1510                           &new_hbox_pack (
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 (
1515                      &new_vbox_pack (
1516                           &new_hbox_pack (
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 (
1521                      &new_vbox_pack (
1522                           &new_hbox_pack (
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 (
1527                      &new_vbox_pack (
1528                           &new_hbox_pack (
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 (
1533                      &new_vbox_pack (
1534                           &new_hbox_pack (
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')
1538            );
1539 }
1540
1541 sub new_winpos_subpage_accounts() {
1542     return &new_vbox_pack (
1543                 &new_subpage_frame (
1544                      &new_vbox_pack (
1545                           &new_hbox_pack (
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 (
1550                      &new_vbox_pack (
1551                           &new_hbox_pack (
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')
1555            );
1556 }
1557
1558 sub new_winpos_subpage_filtering() {
1559     return &new_vbox_pack (
1560                 &new_subpage_frame (
1561                      &new_vbox_pack (
1562                           &new_hbox_pack (
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 (
1567                      &new_vbox_pack (
1568                           &new_hbox_pack (
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 (
1573                      &new_vbox_pack (
1574                           &new_hbox_pack (
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 (
1579                      &new_vbox_pack (
1580                           &new_hbox_pack (
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')
1584            );
1585 }
1586
1587 sub new_winpos_subpage_prefs() {
1588     return &new_vbox_pack (
1589                 &new_subpage_frame (
1590                      &new_vbox_pack (
1591                           &new_hbox_pack (
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 (
1596                      &new_vbox_pack (
1597                           &new_hbox_pack (
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 (
1602                      &new_vbox_pack (
1603                           &new_hbox_pack (
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 (
1608                      &new_vbox_pack (
1609                           &new_hbox_pack (
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 (
1614                      &new_vbox_pack (
1615                           &new_hbox_pack (
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')
1619            );
1620 }
1621
1622 sub new_winpos_subpage_misc() {
1623     return &new_vbox_pack (
1624                 &new_subpage_frame (
1625                      &new_vbox_pack (
1626                           &new_hbox_pack (
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 (
1631                      &new_vbox_pack (
1632                           &new_hbox_pack (
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 (
1637                      &new_vbox_pack (
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')
1641            );
1642 }
1643
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'));
1656     return $winbook;
1657 }
1658
1659 # version info
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);
1669     }
1670     print "\n";
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);
1676     }
1677     print "\n";
1678     my $clawsver = ($CLAWSV eq "") ? 
1679                 _("was not found!") : 
1680                 (_("returned version ") . $CLAWSV);
1681     print "Claws Mail " . $clawsver . "\n";
1682 }
1683
1684 # the command line help
1685 sub print_help() {
1686     my $line = '-' x length ($xl::s{about_title}) . "\n";
1687     print $line;
1688     print $xl::s{about_title} . "\n";
1689     print $line;
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");
1698 }
1699
1700 # handle errors which don't allow to run
1701 sub command_line_fatal() {
1702     my $reason = shift;
1703     my $emsg = $xl::s{e_error} . $reason;
1704     error_dialog ($emsg);
1705     log_message ("$emsg", 'die');
1706 }
1707
1708 # parse the command line
1709 sub parse_command_line() {
1710     $CLAWSV = &get_claws_version;
1711     my $arg = 0;
1712     while (defined($ARGV[$arg])) {
1713         for ($ARGV[$arg]) {
1714             /--help/ && do { 
1715                 &print_help; 
1716                 return FALSE;
1717             };
1718             /--version/ && do { 
1719                 &print_version; 
1720                 return FALSE;
1721             };
1722             /--verbose/ && do {
1723                 $VERBOSE = TRUE;
1724                 last;
1725             };
1726             /--use-claws-version/ && do {
1727                 ++$arg;
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];
1733                 last;
1734             };
1735             /--alternate-config-dir/ && do {
1736                 ++$arg;
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];
1742                 $CONFIGDIR .= "/" 
1743                     unless ($CONFIGDIR =~ /.*\/$/);
1744                 $ALTCONFIGDIR = TRUE;
1745                 last;
1746             };
1747             /--clawsrc/ && do {
1748                 ++$arg;
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]);
1754                 last;
1755             };
1756             /.*/ && &command_line_fatal (
1757                         _("unknown option '{opt}'.\n", opt => $ARGV[$arg]));
1758         }
1759         ++$arg;
1760     }
1761     # eveything continues...
1762     return TRUE;
1763 }
1764
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]};
1770         }
1771     }
1772     return TRUE;
1773 }
1774
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;
1781     open (RCF, "<$rc");
1782     while (<RCF>) {
1783         chomp;
1784         if (/^([8a-z_]+)=(.*)$/) {
1785             $PREFS{$1} = "$2";
1786         }
1787     }
1788     close (RCF);
1789     return TRUE;
1790 }
1791
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);
1800     open (RCF, ">$rc");
1801     open (RCB, "<$rcbak");
1802     while (<RCB>) {
1803         chomp;
1804         if (/^([8a-z_]+)=(.*)$/) {
1805             if (defined($HPVALUE{$1})) {
1806                 print RCF $1 . "=" . $HPVALUE{$1} . "\n";
1807             }
1808             else {
1809                 print RCF $_ . "\n";
1810             }
1811         }
1812         else {
1813             print RCF $_ . "\n";
1814         }
1815     }
1816     close (RCB);
1817     close (RCF);
1818     return TRUE;
1819 }
1820
1821 # create notebook
1822 sub new_notebook() {
1823     my $nb = Gtk2::Notebook->new;
1824     # 
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});
1830
1831     return $nb;
1832 }
1833
1834 # create an about dialog
1835 sub new_about_dialog() {
1836     my ($parent) = @_;
1837     my $title = $xl::s{about_title};
1838     my $lic = $xl::s{about_license};
1839     my $vers = $xl::s{about_version} . " $VERSION";
1840     my $license = 
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.
1845
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.
1850
1851 You should have received a copy of the GNU General Public License
1852 along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.";
1853     my $year = "2007-2009";
1854     my $holder = "Ricardo Mones &lt;ricardo\@mones.org&gt;";
1855     my $url = "http://www.claws-mail.org/clawsker";
1856
1857     my $dialog = Gtk2::MessageDialog->new_with_markup ($parent, 
1858                     [qw/modal destroy-with-parent/], 
1859                     'info', 'close', 
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});
1867     #
1868     return $dialog;
1869 }
1870
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);
1880     # signal handlers 
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 });
1885     # package them
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);
1890     #
1891     return $hbox;
1892 }
1893
1894 # initialise
1895 $main_window = Gtk2::Window->new ('toplevel');
1896 exit unless &parse_command_line;
1897 exit unless &load_preferences;
1898 exit unless &init_hidden_preferences;
1899 # create main GUI
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;
1909 Gtk2->main;
1910