updated pot, spanish translation
[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     l_gui_margin_co => _('Show compose margin'),
105     h_gui_margin_co => _('Shows a small margin in the compose view.'),
106
107     l_beh_hover_t => _('Drag \'n\' drop hover timeout (ms)'),
108     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.'),
109     l_beh_dangerous => _('Don\'t confirm deletions (dangerous!)'),
110     h_beh_dangerous => _('Don\'t ask for confirmation before definitive deletion of emails.'),
111     l_beh_flowed => _('Respect format=flowed in messages'),
112     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.'),
113     l_beh_parts_rw => _('Allow writable temporary files'),
114     h_beh_parts_rw => _('Saves temporary files when opening attachment with write bit set.'),
115     l_beh_skip_ssl => _('Don\'t check SSL certificates'),
116     h_beh_skip_ssl => _('Disables the verification of SSL certificates.'),
117     l_beh_up_step => _('Progress bar update step (items)'),
118     h_beh_up_step => _('Update stepping in progress bars.'),
119     l_beh_thread_a => _('Maximum age when threading by subject (days)'),
120     h_beh_thread_a => _('Number of days to include a message in a thread when using "Thread using subject in addition to standard headers".'),
121     l_beh_unsafe_ssl => _('Allow unsafe SSL certificates'),
122     h_beh_unsafe_ssl => _('Allows Claws Mail to remember multiple SSL certificates for a given server/port.'),
123     l_beh_use_utf8 => _('Force UTF-8 for broken mails'),
124     h_beh_use_utf8 => _('Use UTF-8 encoding for broken mails instead of current locale.'),
125     l_beh_warn_dnd => _('Warn on drag \'n\' drop'),
126     h_beh_warn_dnd => _('Display a confirmation dialogue on drag \'n\' drop of folders.'),
127     l_beh_out_ascii => _('Ougoing messages fallback to ASCII'),
128     h_beh_out_ascii => _('If content allows, ASCII will be used to encode outgoing messages, otherwise the user-defined encoding is enforced always.'),
129     l_beh_pp_unsel => _('Primary paste unselects selection'),
130     h_beh_pp_unsel => _('Controls how pasting using middle-click changes the selected text and insertion point.'),
131
132     l_col_emphasis => _('X-Mailer header'),
133     h_col_emphasis => _('The colour used for the X-Mailer line when its value is Claws Mail.'),
134     l_col_log_err => _('Error messages'),
135     h_col_log_err => _('Colour for error messages in log window.'),
136     l_col_log_in => _('Server messages'),
137     h_col_log_in => _('Colour for messages received from servers in log window.'),
138     l_col_log_msg => _('Standard messages'),
139     h_col_log_msg => _('Colour for messages in log window.'),
140     l_col_log_out => _('Client messages'),
141     h_col_log_out => _('Colour for messages sent to servers in log window.'),
142     l_col_log_warn => _('Warnings'),
143     h_col_log_warn => _('Colour for warning messages in log window.'),
144
145     l_win_x => _('X position'),
146     h_win_x => _('X coordinate for window\'s top-left corner.'),
147     l_win_y => _('Y position'),
148     h_win_y => _('Y coordinate for window\'s top-left corner.'),
149     l_win_w => _('Width'),
150     h_win_w => _('Window\'s width in pixels.'),
151     l_win_h => _('Height'),
152     h_win_h => _('Window\'s height in pixels.'),
153
154     l_win_main_mx => _('Maximized'),
155     h_win_main_mx => _('Changes window maximized status.'),
156     l_win_main_fs => _('Full-screen'),
157     h_win_main_fs => _('Changes full screen status.'),
158
159     e_error => _('Error: '),
160     e_noclawsrc => _('resource file for Claws Mail was not found.'),
161     e_running => _('seems Claws Mail is currently running, close it first.'),
162     e_requireddir => _('option requires a directory name.'),
163     e_requiredfile => _('option requires a file name.'),
164     e_notadir => _('specified name is not a directory or does not exist.'),
165     e_notafile => _('specified name is not a file or does not exist.'),
166 );
167
168 # all preferences read by load_preferences
169 my %PREFS = ();
170 # values of all preferences handled by clawsker
171 my %HPVALUE = ();
172 # default config dir and file name
173 my $ALTCONFIGDIR = FALSE;
174 my $CONFIGDIR = $ENV{HOME} . '/.claws-mail/';
175 my $CONFIGRC = 'clawsrc';
176
177 # index constants for preference arrays
178 use constant NAME  => 0; # the name on the rc file
179 use constant LABEL => 1; # the label on the GUI
180 use constant DESC  => 2; # the description for the hint/help
181 use constant TYPE  => 3; # data type: bool, int, float, string, color
182 use constant CMVER => 4; # lowest Claws Mail version the feature exists
183 use constant CMDEF => 5; # default value for the preference in Claws Mail
184 use constant GUI   => 6; # GUI element
185
186 # constants for GUI spacing
187 use constant HBOX_SPC => 5;
188 use constant FRAME_SPC => 2;
189 use constant PAGE_SPC => 5;
190
191 # version functions
192
193 sub version_greater_or_equal() {
194     my ($version, $refvers) = @_;
195     my @version = split (/\./, $version);
196     my @refvers = split (/\./, $refvers);
197     while ($#version < $#refvers) {
198         push (@version, '0');
199     }
200     my $idx = 0;
201     while (($idx <= $#refvers) 
202             and (int ($version[$idx]) == int ($refvers[$idx]))) {
203         ++$idx;
204     }
205     return TRUE if (($idx > $#refvers)
206         or (int ($version[$idx]) >= int ($refvers[$idx])));
207     return FALSE;
208 }
209
210 sub get_claws_version() {
211     my @cmbin = (
212         'claws-mail',
213     );
214     my $res = "";
215     foreach my $bin (@cmbin) {
216         $_ = qx/which $bin/;
217         chomp;
218         last if ($_ ne "");
219     }
220     return "" unless ($_); # not installed
221     $_ = qx/$_ -v/;
222     chomp;
223     my @fver = split (/ /);
224     die "Invalid version string" unless ($fver[2] eq "version");
225     my @ver = split (/\./, $fver[3]);
226     $res .= "$ver[0].";
227     $res .= "$ver[1].";
228     if ($ver[2] =~ /(\d+)cvs(\d+)/) {
229         $res .= "$1.$2";
230     }
231     else {
232         $res .= "$ver[2].0";
233     }
234     return $res;
235 }
236
237 # data handlers and auxiliar functions
238
239 sub handle_bool_value {
240     my ($widget, $event, $dataref) = @_;
241     $$dataref = ($widget->get_active ())? '1': '0';
242 }
243
244 sub handle_int_value {
245     my ($widget, $event, $dataref) = @_;
246     $_ = $widget->get_text ();
247     s/^\s+//;
248     s/\s+$//;
249     if (/^[0-9]+$/) {
250         $$dataref = $_;
251         $widget->set_text ($_);
252     }
253     else {
254         $widget->set_text ($$dataref);
255     }
256 }
257
258 sub handle_string_value {
259     my ($widget, $event, $dataref) = @_;
260     $$dataref = $widget->get_text ();
261 }
262
263 sub gdk_color_from_str {
264     my ($str) = @_;
265     my ($rr, $gg, $bb) = (0, 0 ,0);
266     $_ = uc ($str);
267     if (/\#([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])/) {
268         $rr = hex($1) * 256;
269         $gg = hex($2) * 256; 
270         $bb = hex($3) * 256;
271     }
272     my $color = Gtk2::Gdk::Color->new ($rr, $gg, $bb);
273     return $color;
274 }
275
276 sub str_from_gdk_color {
277     my ($color) = @_;
278     my $rr = $color->red / 256;
279     my $gg = $color->green / 256;
280     my $bb = $color->blue / 256;
281     my $str = sprintf ("#%.2x%.2x%.2x", $rr, $gg, $bb);
282     return $str;
283 }
284
285 sub handle_color_value {
286     my ($widget, $event, $dataref) = @_;
287     my $newcol = $widget->get_color;
288     $$dataref = &str_from_gdk_color ($newcol);
289 }
290
291 sub handle_selection_value {
292     my ($widget, $event, $dataref) = @_;
293     $$dataref = $widget->get_active;
294 }
295
296 sub get_rc_filename {
297     return $CONFIGDIR . $CONFIGRC;
298 }
299
300 sub set_rc_filename {
301     my ($fullname) = @_;
302     my @parts = split ('/', $fullname);
303     $CONFIGRC = $parts[$#parts];
304     $parts[$#parts] = '';
305     $CONFIGDIR = join ('/', @parts);
306 }
307
308 sub log_message {
309     my ($mesg, $fatal) = @_;
310     if (defined($fatal) && $fatal eq 'die') {
311         die "$NAME: $mesg\n";
312     }
313     if ($VERBOSE) {
314         print "$NAME: $mesg\n";
315     }
316 }
317
318 sub error_dialog {
319     my ($emsg) = @_;
320     my $markup = "<span weight=\"bold\" size=\"large\">" . $emsg . "</span>";
321     my $errordlg = Gtk2::MessageDialog->new_with_markup ($main_window, 'modal', 'error', 'cancel', $markup);
322     $errordlg->set_title (_('Error message'));
323     $errordlg->run;
324     $errordlg->destroy;
325 }
326
327 sub check_claws_not_running() {
328     my $socket = (not $ALTCONFIGDIR)? "/tmp/": $CONFIGDIR;
329     $socket .= "claws-mail-$<";
330     -S $socket and do {
331         my $emsg = "$xl::s{e_error}$xl::s{e_running}";
332         log_message ($emsg);
333         error_dialog ($emsg);
334         return FALSE;
335      };
336      return TRUE;
337 }
338
339 sub check_rc_file() {
340     my ($rcfile) = @_;
341     (defined($rcfile) && -f $rcfile) or do {
342        my $emsg = "$xl::s{e_error}$xl::s{e_noclawsrc}\n";
343         log_message ($emsg);
344         error_dialog ($emsg);
345         return FALSE;
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_vbox_pack_compact() {
487     my $vbox = Gtk2::VBox->new (FALSE, 0);
488     $vbox->set_border_width (0);
489     foreach my $item (@_) {
490         $vbox->pack_start ($item, FALSE, FALSE, 0);
491     }
492     return $vbox;
493 }    
494
495 sub new_subpage_frame () {
496     my ($box, $title, $notpacked) = @_;
497     my $frame = Gtk2::Frame->new ($title);
498     $frame->add ($box);    
499     return &new_vbox_pack ($frame) unless defined ($notpacked);
500     return $frame;
501 }
502
503 # preference maps and corresponding page creation subs
504
505 %pr::oth = ( # other preferences
506     use_dlg => [ 
507         'addressbook_use_editaddress_dialog',
508         $xl::s{l_oth_use_dlg},
509         $xl::s{h_oth_use_dlg},
510         'bool',
511         '2.7.0',
512         '0',
513         undef,
514     ],
515     max_use => [
516         'cache_max_mem_usage',
517         $xl::s{l_oth_max_use},
518         $xl::s{h_oth_max_use},
519         'int,0,262144', # 0 Kb - 256 Mb
520         '0.0.0',
521         '4096',
522         undef,
523     ],
524     min_time => [
525         'cache_min_keep_time',
526         $xl::s{l_oth_min_time},
527         $xl::s{h_oth_min_time},
528         'int,0,120', # 0 minutes - 2 hours
529         '0.0.0',
530         '15',
531         undef,
532     ],
533     use_netm => [
534         'use_networkmanager',
535         $xl::s{l_oth_use_netm},
536         $xl::s{h_oth_use_netm},
537         'bool',
538         '3.3.1',
539         '1',
540         undef,
541     ],
542 );
543
544 sub new_other_page() {
545     return &new_vbox_pack (
546                &new_subpage_frame (
547                    &new_vbox_pack (
548                        &new_check_button_for(\%pr::oth, 'use_dlg')),
549                    $xl::s{ab_frame}, 'not-packed'),
550                &new_subpage_frame (
551                    &new_vbox_pack (
552                        &new_text_box_for_int(\%pr::oth, 'max_use'),
553                        &new_text_box_for_int(\%pr::oth, 'min_time')),
554                    $xl::s{mem_frame}, 'not-packed'),
555                &new_subpage_frame (
556                    &new_vbox_pack (
557                        &new_check_button_for(\%pr::oth, 'use_netm')),
558                    $xl::s{netm_frame}, 'not-packed')
559            );
560 }
561
562 %pr::gui = ( # gui bells and whistles
563     b_unread => [ 
564         'bold_unread',
565         $xl::s{l_gui_b_unread},
566         $xl::s{h_gui_b_unread},
567         'bool',
568         '0.0.0',
569         '1',
570         undef,
571     ],
572     no_markup => [
573         'compose_no_markup',
574         $xl::s{l_gui_no_markup},
575         $xl::s{h_gui_no_markup},
576         'bool',
577         '0.0.0',
578         '0',
579         undef,
580     ],
581     dot_lines => [
582         'enable_dotted_lines',
583         $xl::s{l_gui_dot_lines},
584         $xl::s{h_gui_dot_lines},
585         'bool',
586         '0.0.0',
587         '0',
588         undef,
589     ],
590     h_scroll => [
591         'enable_hscrollbar',
592         $xl::s{l_gui_h_scroll},
593         $xl::s{h_gui_h_scroll},
594         'bool',
595         '0.0.0',
596         '1',
597         undef,
598     ],
599     swp_from => [
600         'enable_swap_from',
601         $xl::s{l_gui_swp_from},
602         $xl::s{h_gui_swp_from},
603         'bool',
604         '0.0.0',
605         '0',
606         undef,
607     ],
608     v_scroll => [
609         'folderview_vscrollbar_policy',
610         $xl::s{l_gui_v_scroll},
611         $xl::s{h_gui_v_scroll},
612         '0=l_gui_v_scroll_show;1=l_gui_v_scroll_auto;2=l_gui_v_scroll_hide',
613         '0.0.0',
614         '0',
615         undef,
616     ],
617     strip_off => [
618         'stripes_color_offset',
619         $xl::s{l_gui_strip_off},
620         $xl::s{h_gui_strip_off},
621         'int,0,10000', # no idea what this number means
622         '0.0.0',
623         '4000',
624         undef,
625     ],
626     cursor_v => [
627         'textview_cursor_visible',
628         $xl::s{l_gui_cursor_v},
629         $xl::s{h_gui_cursor_v},
630         'bool',
631         '0.0.0',
632         '0',
633         undef,
634     ],
635     toolbar_d => [
636         'toolbar_detachable',
637         $xl::s{l_gui_toolbar_d},
638         $xl::s{h_gui_toolbar_d},
639         'bool',
640         '0.0.0',
641         '0',
642         undef,
643     ],
644     strip_all => [
645         'use_stripes_everywhere',
646         $xl::s{l_gui_strip_all},
647         $xl::s{h_gui_strip_all},
648         'bool',
649         '0.0.0',
650         '1',
651         undef,
652     ],
653     strip_sum => [
654         'use_stripes_in_summaries',
655         $xl::s{l_gui_strip_sum},
656         $xl::s{h_gui_strip_sum},
657         'bool',
658         '0.0.0',
659         '1',
660         undef,
661     ],
662     two_linev => [
663         'two_line_vertical',
664         $xl::s{l_gui_two_line_v},
665         $xl::s{h_gui_two_line_v},
666         'bool',
667         '3.4.0.7',
668         '0',
669         undef,
670     ],
671     margin_co => [
672         'show_compose_margin',
673         $xl::s{l_gui_margin_co},
674         $xl::s{h_gui_margin_co},
675         'bool',
676         '3.7.6.7',
677         '0',
678         undef,
679     ],
680 );
681
682 sub new_gui_page() {
683     my $gf = Gtk2::VBox->new (FALSE, 5);
684     $gf->set_border_width (PAGE_SPC);
685
686     my $cb_no_markup = &new_check_button_for (\%pr::gui, 'no_markup'); 
687     my $cb_dot_lines = &new_check_button_for (\%pr::gui, 'dot_lines'); 
688     my $cb_cursor_v = &new_check_button_for (\%pr::gui, 'cursor_v');
689     my $cb_toolbar_d = &new_check_button_for (\%pr::gui, 'toolbar_d');
690     my $cb_two_linev = &new_check_button_for (\%pr::gui, 'two_linev');
691     my $cb_margin_co = &new_check_button_for (\%pr::gui, 'margin_co');
692
693     $gf->pack_start (&new_subpage_frame (
694                          &new_vbox_pack (
695                              &new_check_button_for (\%pr::gui, 'strip_all'),
696                              &new_check_button_for (\%pr::gui, 'strip_sum'),
697                              &new_text_box_for_int (\%pr::gui, 'strip_off')),
698                          $xl::s{stripes_frame}, 'not-packed'),
699                      FALSE, FALSE, FRAME_SPC);
700     $gf->pack_start (&new_subpage_frame (
701                          &new_vbox_pack (
702                              &new_check_button_for (\%pr::gui, 'b_unread'),
703                              &new_check_button_for (\%pr::gui, 'swp_from')),
704                          $xl::s{mlist_frame}, 'not-packed'), 
705                      FALSE, FALSE, FRAME_SPC);
706     $gf->pack_start ($cb_no_markup, FALSE, FALSE, 0);
707     $gf->pack_start ($cb_dot_lines, FALSE, FALSE, 0);
708     $gf->pack_start ($cb_cursor_v, FALSE, FALSE, 0);
709     $gf->pack_start ($cb_toolbar_d, FALSE, FALSE, 0);
710     $gf->pack_start ($cb_two_linev, FALSE, FALSE, 0);
711     $gf->pack_start ($cb_margin_co, FALSE, FALSE, 0);
712     $gf->pack_start (&new_subpage_frame (
713                          &new_vbox_pack (
714                              &new_check_button_for (\%pr::gui, 'h_scroll'),
715                              &new_selection_box_for (\%pr::gui, 'v_scroll')),
716                          $xl::s{sbar_frame}, 'not-packed'),
717                      FALSE, FALSE, FRAME_SPC);
718
719     return $gf;
720 }
721
722 %pr::beh = ( # tweak some behaviour
723     hover_t => [
724         'hover_timeout',
725         $xl::s{l_beh_hover_t},
726         $xl::s{h_beh_hover_t},
727         'int,100,3000', # 0.1 seconds - 3 seconds
728         '0.0.0',
729         '500',
730         undef,
731     ],
732     dangerous => [
733         'live_dangerously',
734         $xl::s{l_beh_dangerous},
735         $xl::s{h_beh_dangerous},
736         'bool',
737         '0.0.0',
738         '0',
739         undef,
740     ],
741     flowed => [
742         'respect_flowed_format',
743         $xl::s{l_beh_flowed},
744         $xl::s{h_beh_flowed},
745         'bool',
746         '0.0.0',
747         '0',
748         undef,
749     ],
750     parts_rw => [
751         'save_parts_readwrite',
752         $xl::s{l_beh_parts_rw},
753         $xl::s{h_beh_parts_rw},
754         'bool',
755         '0.0.0',
756         '0',
757         undef,
758     ],
759     skip_ssl => [
760         'skip_ssl_cert_check',
761         $xl::s{l_beh_skip_ssl},
762         $xl::s{h_beh_skip_ssl},
763         'bool',
764         '0.0.0',
765         '0',
766         undef,
767     ],
768     up_step => [
769         'statusbar_update_step',
770         $xl::s{l_beh_up_step},
771         $xl::s{h_beh_up_step},
772         'int,1,200', # 1 item - 200 items
773         '0.0.0',
774         '10',
775         undef,
776     ],
777     thread_a => [
778         'thread_by_subject_max_age',
779         $xl::s{l_beh_thread_a},
780         $xl::s{h_beh_thread_a},
781         'int,1,30', # 1 day - 30 days
782         '0.0.0',
783         '10',
784         undef,
785     ],
786     unsafe_ssl => [
787         'unsafe_ssl_certs',
788         $xl::s{l_beh_unsafe_ssl},
789         $xl::s{h_beh_unsafe_ssl},
790         'bool',
791         '0.0.0',
792         '0',
793         undef,
794     ],
795     use_utf8 => [
796         'utf8_instead_of_locale_for_broken_mail',
797         $xl::s{l_beh_use_utf8},
798         $xl::s{h_beh_use_utf8},
799         'bool',
800         '0.0.0',
801         '0',
802         undef,
803     ],
804     warn_dnd => [
805         'warn_dnd',
806         $xl::s{l_beh_warn_dnd},
807         $xl::s{h_beh_warn_dnd},
808         'bool',
809         '0.0.0',
810         '1',
811         undef,
812     ],
813     out_ascii => [
814         'outgoing_fallback_to_ascii',
815         $xl::s{l_beh_out_ascii},
816         $xl::s{h_beh_out_ascii},
817         'bool',
818         '3.4.0.37',
819         '1',
820         undef,
821     ],
822     pp_unsel => [
823         'primary_paste_unselects',
824         $xl::s{l_beh_pp_unsel},
825         $xl::s{h_beh_pp_unsel},
826         'bool',
827         '3.6.1.35',
828         '0',
829         undef,
830     ],
831 );
832
833 sub new_behaviour_page() {
834     my $bf = Gtk2::VBox->new (FALSE, 5);
835     $bf->set_border_width (PAGE_SPC);
836
837     my $tb_up_step = &new_text_box_for_int (\%pr::beh, 'up_step');
838     my $tb_thread_a = &new_text_box_for_int (\%pr::beh, 'thread_a');
839
840     $bf->pack_start (&new_subpage_frame (
841                          &new_vbox_pack (
842                              &new_text_box_for_int (\%pr::beh, 'hover_t'),
843                              &new_check_button_for (\%pr::beh, 'warn_dnd')),
844                          $xl::s{dnd_frame}, 'not-packed'), 
845                      FALSE, FALSE, FRAME_SPC);
846     $bf->pack_start (&new_subpage_frame (
847                          &new_hbox_pack (
848                              &new_check_button_for (\%pr::beh, 'skip_ssl'),
849                              &new_check_button_for (\%pr::beh, 'unsafe_ssl')),
850                          $xl::s{ssl_frame}, 'not-packed'),
851                      FALSE, FALSE, FRAME_SPC);
852     $bf->pack_start ($tb_up_step, FALSE, FALSE, 0);
853     $bf->pack_start ($tb_thread_a, FALSE, FALSE, 0);
854     $bf->pack_start (&new_subpage_frame (
855                          &new_vbox_pack (
856                              &new_check_button_for (\%pr::beh, 'flowed'),
857                              &new_check_button_for (\%pr::beh, 'parts_rw'),
858                              &new_check_button_for (\%pr::beh, 'use_utf8'),
859                              &new_check_button_for (\%pr::beh, 'dangerous'),
860                              &new_check_button_for (\%pr::beh, 'out_ascii'),
861                              &new_check_button_for (\%pr::beh, 'pp_unsel')),
862                          $xl::s{msgs_frame}, 'not-packed'),
863                      FALSE, FALSE, FRAME_SPC);
864
865     return $bf;
866 }
867
868 %pr::col = ( # a variety of colours
869     emphasis => [
870         'emphasis_color',
871         $xl::s{l_col_emphasis},
872         $xl::s{h_col_emphasis},
873         'color',
874         '0.0.0',
875         '#0000cf',
876         undef,
877     ],
878     log_err => [
879         'log_error_color',
880         $xl::s{l_col_log_err},
881         $xl::s{h_col_log_err},
882         'color',
883         '0.0.0',
884         '#af0000',
885         undef,
886     ],
887     log_in => [
888         'log_in_color',
889         $xl::s{l_col_log_in},
890         $xl::s{h_col_log_in},
891         'color',
892         '0.0.0',
893         '#000000',
894         undef,
895     ],
896     log_msg => [
897         'log_msg_color',
898         $xl::s{l_col_log_msg},
899         $xl::s{h_col_log_msg},
900         'color',
901         '0.0.0',
902         '#00af00',
903         undef,
904     ],
905     log_out => [
906         'log_out_color',
907         $xl::s{l_col_log_out},
908         $xl::s{h_col_log_out},
909         'color',
910         '0.0.0',
911         '#0000ef',
912         undef,
913     ],
914     log_warn => [
915         'log_warn_color',
916         $xl::s{l_col_log_warn},
917         $xl::s{h_col_log_warn},
918         'color',
919         '0.0.0',
920         '#af0000',
921         undef,
922     ],
923 );
924
925 sub new_colours_page() {
926     return &new_vbox_pack (
927                &new_subpage_frame (
928                    &new_vbox_pack (
929                        &new_color_button_for (\%pr::col, 'emphasis')),
930                    $xl::s{msgview_frame}, 'not-packed'),
931                &new_subpage_frame (
932                    &new_vbox_pack (
933                        &new_color_button_for (\%pr::col, 'log_err'),
934                        &new_color_button_for (\%pr::col, 'log_in'),
935                        &new_color_button_for (\%pr::col, 'log_msg'),
936                        &new_color_button_for (\%pr::col, 'log_out'),
937                        &new_color_button_for (\%pr::col, 'log_warn')),
938                    $xl::s{log_frame}, 'not-packed')
939            );
940 }
941
942 %pr::win = ( # tweak window positions and/or sizes
943     main_x => [
944         'mainwin_x',
945         $xl::s{l_win_x},
946         $xl::s{h_win_x},
947         'int,0,3000', # 0 pixels - 3000 pixels
948         '0.0.0',
949         '16',
950         undef,
951     ],
952     main_y => [
953         'mainwin_y',
954         $xl::s{l_win_y},
955         $xl::s{h_win_y},
956         'int,0,3000', # 0 pixels - 3000 pixels
957         '0.0.0',
958         '16',
959         undef,
960     ],
961     main_w => [
962         'mainwin_width',
963         $xl::s{l_win_w},
964         $xl::s{h_win_w},
965         'int,0,3000', # 0 pixels - 3000 pixels
966         '0.0.0',
967         '779',
968         undef,
969     ],
970     main_h => [
971         'mainwin_height',
972         $xl::s{l_win_h},
973         $xl::s{h_win_h},
974         'int,0,3000', # 0 pixels - 3000 pixels
975         '0.0.0',
976         '568',
977         undef,
978     ],
979     main_mx => [
980         'mainwin_maximised',
981         $xl::s{l_win_main_mx},
982         $xl::s{h_win_main_mx},
983         'bool',
984         '0.0.0',
985         '0',
986         undef,
987     ],
988     main_fs => [
989         'mainwin_fullscreen',
990         $xl::s{l_win_main_fs},
991         $xl::s{h_win_main_fs},
992         'bool',
993         '0.0.0',
994         '0',
995         undef,
996     ],
997     msgs_x => [
998         'main_messagewin_x',
999         $xl::s{l_win_x},
1000         $xl::s{h_win_x},
1001         'int,0,3000', # 0 pixels - 3000 pixels
1002         '0.0.0',
1003         '256',
1004         undef,
1005     ],
1006     msgs_y => [
1007         'main_messagewin_y',
1008         $xl::s{l_win_y},
1009         $xl::s{h_win_y},
1010         'int,0,3000', # 0 pixels - 3000 pixels
1011         '0.0.0',
1012         '210',
1013         undef,
1014     ],
1015     msgs_w => [
1016         'messagewin_width',
1017         $xl::s{l_win_w},
1018         $xl::s{h_win_w},
1019         'int,0,3000', # 0 pixels - 3000 pixels
1020         '0.0.0',
1021         '600',
1022         undef,
1023     ],
1024     msgs_h => [
1025         'messagewin_height',
1026         $xl::s{l_win_h},
1027         $xl::s{h_win_h},
1028         'int,0,3000', # 0 pixels - 3000 pixels
1029         '0.0.0',
1030         '540',
1031         undef,
1032     ],
1033     send_w => [
1034         'sendwin_width',
1035         $xl::s{l_win_w},
1036         $xl::s{h_win_w},
1037         'int,0,3000', # 0 pixels - 3000 pixels
1038         '0.0.0',
1039         '460',
1040         undef,
1041     ],
1042     send_h => [
1043         'sendwin_height',
1044         $xl::s{l_win_h},
1045         $xl::s{h_win_h},
1046         'int,0,3000', # 0 pixels - 3000 pixels
1047         '0.0.0',
1048         '-1',
1049         undef,
1050     ],
1051     recv_w => [
1052         'receivewin_width',
1053         $xl::s{l_win_w},
1054         $xl::s{h_win_w},
1055         'int,0,3000', # 0 pixels - 3000 pixels
1056         '0.0.0',
1057         '460',
1058         undef,
1059     ],
1060     recv_h => [
1061         'receivewin_height',
1062         $xl::s{l_win_h},
1063         $xl::s{h_win_h},
1064         'int,0,3000', # 0 pixels - 3000 pixels
1065         '0.0.0',
1066         '-1',
1067         undef,
1068     ],
1069     fold_x => [
1070         'folderwin_x',
1071         $xl::s{l_win_x},
1072         $xl::s{h_win_x},
1073         'int,0,3000', # 0 pixels - 3000 pixels
1074         '0.0.0',
1075         '16',
1076         undef,
1077     ],
1078     fold_y => [
1079         'folderwin_y',
1080         $xl::s{l_win_y},
1081         $xl::s{h_win_y},
1082         'int,0,3000', # 0 pixels - 3000 pixels
1083         '0.0.0',
1084         '16',
1085         undef,
1086     ],
1087     fold_w => [
1088         'folderitemwin_width',
1089         $xl::s{l_win_w},
1090         $xl::s{h_win_w},
1091         'int,0,3000', # 0 pixels - 3000 pixels
1092         '0.0.0',
1093         '500',
1094         undef,
1095     ],
1096     fold_h => [
1097         'folderitemwin_height',
1098         $xl::s{l_win_h},
1099         $xl::s{h_win_h},
1100         'int,0,3000', # 0 pixels - 3000 pixels
1101         '0.0.0',
1102         '-1',
1103         undef,
1104     ],
1105     fsel_w => [
1106         'folderselwin_width',
1107         $xl::s{l_win_w},
1108         $xl::s{h_win_w},
1109         'int,0,3000', # 0 pixels - 3000 pixels
1110         '0.0.0',
1111         '300',
1112         undef,
1113     ],
1114     fsel_h => [
1115         'folderselwin_height',
1116         $xl::s{l_win_h},
1117         $xl::s{h_win_h},
1118         'int,0,3000', # 0 pixels - 3000 pixels
1119         '0.0.0',
1120         '-1',
1121         undef,
1122     ],
1123     sour_w => [
1124         'sourcewin_width',
1125         $xl::s{l_win_w},
1126         $xl::s{h_win_w},
1127         'int,0,3000', # 0 pixels - 3000 pixels
1128         '0.0.0',
1129         '600',
1130         undef,
1131     ],
1132     sour_h => [
1133         'sourcewin_height',
1134         $xl::s{l_win_h},
1135         $xl::s{h_win_h},
1136         'int,0,3000', # 0 pixels - 3000 pixels
1137         '0.0.0',
1138         '500',
1139         undef,
1140     ],
1141     addr_w => [
1142         'addressbookwin_width',
1143         $xl::s{l_win_w},
1144         $xl::s{h_win_w},
1145         'int,0,3000', # 0 pixels - 3000 pixels
1146         '0.0.0',
1147         '520',
1148         undef,
1149     ],
1150     addr_h => [
1151         'addressbookwin_height',
1152         $xl::s{l_win_h},
1153         $xl::s{h_win_h},
1154         'int,0,3000', # 0 pixels - 3000 pixels
1155         '0.0.0',
1156         '-1',
1157         undef,
1158     ],
1159     adep_w => [
1160         'addressbookeditpersonwin_width',
1161         $xl::s{l_win_w},
1162         $xl::s{h_win_w},
1163         'int,0,3000', # 0 pixels - 3000 pixels
1164         '0.0.0',
1165         '640',
1166         undef,
1167     ],
1168     adep_h => [
1169         'addressbookeditpersonwin_height',
1170         $xl::s{l_win_h},
1171         $xl::s{h_win_h},
1172         'int,0,3000', # 0 pixels - 3000 pixels
1173         '0.0.0',
1174         '320',
1175         undef,
1176     ],
1177     adeg_w => [
1178         'addressbookeditgroupwin_width',
1179         $xl::s{l_win_w},
1180         $xl::s{h_win_w},
1181         'int,0,3000', # 0 pixels - 3000 pixels
1182         '0.0.0',
1183         '580',
1184         undef,
1185     ],
1186     adeg_h => [
1187         'addressbookeditgroupwin_height',
1188         $xl::s{l_win_h},
1189         $xl::s{h_win_h},
1190         'int,0,3000', # 0 pixels - 3000 pixels
1191         '0.0.0',
1192         '340',
1193         undef,
1194     ],
1195     adda_w => [
1196         'addressaddwin_width',
1197         $xl::s{l_win_w},
1198         $xl::s{h_win_w},
1199         'int,0,3000', # 0 pixels - 3000 pixels
1200         '0.0.0',
1201         '300',
1202         undef,
1203     ],
1204     adda_h => [
1205         'addressaddwin_height',
1206         $xl::s{l_win_h},
1207         $xl::s{h_win_h},
1208         'int,0,3000', # 0 pixels - 3000 pixels
1209         '0.0.0',
1210         '-1',
1211         undef,
1212     ],
1213     addf_w => [
1214         'addressbook_folderselwin_width',
1215         $xl::s{l_win_w},
1216         $xl::s{h_win_w},
1217         'int,0,3000', # 0 pixels - 3000 pixels
1218         '0.0.0',
1219         '300',
1220         undef,
1221     ],
1222     addf_h => [
1223         'addressbook_folderselwin_height',
1224         $xl::s{l_win_h},
1225         $xl::s{h_win_h},
1226         'int,0,3000', # 0 pixels - 3000 pixels
1227         '0.0.0',
1228         '-1',
1229         undef,
1230     ],
1231     acce_w => [
1232         'editaccountwin_width',
1233         $xl::s{l_win_w},
1234         $xl::s{h_win_w},
1235         'int,0,3000', # 0 pixels - 3000 pixels
1236         '0.0.0',
1237         '500',
1238         undef,
1239     ],
1240     acce_h => [
1241         'editaccountwin_height',
1242         $xl::s{l_win_h},
1243         $xl::s{h_win_h},
1244         'int,0,3000', # 0 pixels - 3000 pixels
1245         '0.0.0',
1246         '-1',
1247         undef,
1248     ],
1249     acco_w => [
1250         'accountswin_width',
1251         $xl::s{l_win_w},
1252         $xl::s{h_win_w},
1253         'int,0,3000', # 0 pixels - 3000 pixels
1254         '0.0.0',
1255         '500',
1256         undef,
1257     ],
1258     acco_h => [
1259         'accountswin_height',
1260         $xl::s{l_win_h},
1261         $xl::s{h_win_h},
1262         'int,0,3000', # 0 pixels - 3000 pixels
1263         '0.0.0',
1264         '-1',
1265         undef,
1266     ],
1267     filt_w => [
1268         'filteringwin_width',
1269         $xl::s{l_win_w},
1270         $xl::s{h_win_w},
1271         'int,0,3000', # 0 pixels - 3000 pixels
1272         '0.0.0',
1273         '500',
1274         undef,
1275     ],
1276     filt_h => [
1277         'filteringwin_height',
1278         $xl::s{l_win_h},
1279         $xl::s{h_win_h},
1280         'int,0,3000', # 0 pixels - 3000 pixels
1281         '0.0.0',
1282         '-1',
1283         undef,
1284     ],
1285     fila_w => [
1286         'filteringactionwin_width',
1287         $xl::s{l_win_w},
1288         $xl::s{h_win_w},
1289         'int,0,3000', # 0 pixels - 3000 pixels
1290         '0.0.0',
1291         '490',
1292         undef,
1293     ],
1294     fila_h => [
1295         'filteringactionwin_height',
1296         $xl::s{l_win_h},
1297         $xl::s{h_win_h},
1298         'int,0,3000', # 0 pixels - 3000 pixels
1299         '0.0.0',
1300         '-1',
1301         undef,
1302     ],
1303     fild_w => [
1304         'filtering_debugwin_width',
1305         $xl::s{l_win_w},
1306         $xl::s{h_win_w},
1307         'int,0,3000', # 0 pixels - 3000 pixels
1308         '0.0.0',
1309         '600',
1310         undef,
1311     ],
1312     fild_h => [
1313         'filtering_debugwin_height',
1314         $xl::s{l_win_h},
1315         $xl::s{h_win_h},
1316         'int,0,3000', # 0 pixels - 3000 pixels
1317         '0.0.0',
1318         '-1',
1319         undef,
1320     ],
1321     matc_w => [
1322         'matcherwin_width',
1323         $xl::s{l_win_w},
1324         $xl::s{h_win_w},
1325         'int,0,3000', # 0 pixels - 3000 pixels
1326         '0.0.0',
1327         '520',
1328         undef,
1329     ],
1330     matc_h => [
1331         'matcherwin_height',
1332         $xl::s{l_win_h},
1333         $xl::s{h_win_h},
1334         'int,0,3000', # 0 pixels - 3000 pixels
1335         '0.0.0',
1336         '-1',
1337         undef,
1338     ],
1339     pref_w => [
1340         'prefswin_width',
1341         $xl::s{l_win_w},
1342         $xl::s{h_win_w},
1343         'int,0,3000', # 0 pixels - 3000 pixels
1344         '0.0.0',
1345         '600',
1346         undef,
1347     ],
1348     pref_h => [
1349         'prefswin_height',
1350         $xl::s{l_win_h},
1351         $xl::s{h_win_h},
1352         'int,0,3000', # 0 pixels - 3000 pixels
1353         '0.0.0',
1354         '-1',
1355         undef,
1356     ],
1357     temp_w => [
1358         'templateswin_width',
1359         $xl::s{l_win_w},
1360         $xl::s{h_win_w},
1361         'int,0,3000', # 0 pixels - 3000 pixels
1362         '0.0.0',
1363         '480',
1364         undef,
1365     ],
1366     temp_h => [
1367         'templateswin_height',
1368         $xl::s{l_win_h},
1369         $xl::s{h_win_h},
1370         'int,0,3000', # 0 pixels - 3000 pixels
1371         '0.0.0',
1372         '-1',
1373         undef,
1374     ],
1375     acti_w => [
1376         'actionswin_width',
1377         $xl::s{l_win_w},
1378         $xl::s{h_win_w},
1379         'int,0,3000', # 0 pixels - 3000 pixels
1380         '0.0.0',
1381         '486',
1382         undef,
1383     ],
1384     acti_h => [
1385         'actionswin_height',
1386         $xl::s{l_win_h},
1387         $xl::s{h_win_h},
1388         'int,0,3000', # 0 pixels - 3000 pixels
1389         '0.0.0',
1390         '-1',
1391         undef,
1392     ],
1393     tags_w => [
1394         'tagswin_width',
1395         $xl::s{l_win_w},
1396         $xl::s{h_win_w},
1397         'int,0,3000', # 0 pixels - 3000 pixels
1398         '0.0.0',
1399         '486',
1400         undef,
1401     ],
1402     tags_h => [
1403         'tagswin_height',
1404         $xl::s{l_win_h},
1405         $xl::s{h_win_h},
1406         'int,0,3000', # 0 pixels - 3000 pixels
1407         '0.0.0',
1408         '-1',
1409         undef,
1410     ],
1411     plug_w => [
1412         'pluginswin_width',
1413         $xl::s{l_win_w},
1414         $xl::s{h_win_w},
1415         'int,0,3000', # 0 pixels - 3000 pixels
1416         '0.0.0',
1417         '-1',
1418         undef,
1419     ],
1420     plug_h => [
1421         'pluginswin_height',
1422         $xl::s{l_win_h},
1423         $xl::s{h_win_h},
1424         'int,0,3000', # 0 pixels - 3000 pixels
1425         '0.0.0',
1426         '-1',
1427         undef,
1428     ],
1429     logw_w => [
1430         'logwin_width',
1431         $xl::s{l_win_w},
1432         $xl::s{h_win_w},
1433         'int,0,3000', # 0 pixels - 3000 pixels
1434         '0.0.0',
1435         '520',
1436         undef,
1437     ],
1438     logw_h => [
1439         'logwin_height',
1440         $xl::s{l_win_h},
1441         $xl::s{h_win_h},
1442         'int,0,3000', # 0 pixels - 3000 pixels
1443         '0.0.0',
1444         '-1',
1445         undef,
1446     ],
1447     prin_w => [
1448         'print_previewwin_width',
1449         $xl::s{l_win_w},
1450         $xl::s{h_win_w},
1451         'int,0,3000', # 0 pixels - 3000 pixels
1452         '0.0.0',
1453         '600',
1454         undef,
1455     ],
1456     prin_h => [
1457         'print_previewwin_height',
1458         $xl::s{l_win_h},
1459         $xl::s{h_win_h},
1460         'int,0,3000', # 0 pixels - 3000 pixels
1461         '0.0.0',
1462         '-1',
1463         undef,
1464     ],
1465 );
1466
1467 sub new_winpos_subpage_main() {
1468     return &new_subpage_frame (
1469                &new_vbox_pack_compact (
1470                    &new_vbox_pack (
1471                        &new_text_box_for_int (\%pr::win, 'main_x'), 
1472                        &new_text_box_for_int (\%pr::win, 'main_y')), 
1473                    &new_hbox_pack (
1474                        &new_text_box_for_int (\%pr::win, 'main_w'), 
1475                        &new_text_box_for_int (\%pr::win, 'main_h')), 
1476                    &new_vbox_pack (
1477                        &new_check_button_for (\%pr::win, 'main_fs'), 
1478                        &new_check_button_for (\%pr::win, 'main_mx'))),
1479                _('Main window')
1480            );
1481 }
1482
1483 sub new_winpos_subpage_msgs() {
1484     return &new_subpage_frame (
1485                &new_vbox_pack_compact (
1486                    &new_vbox_pack (
1487                        &new_text_box_for_int (\%pr::win, 'msgs_x'),
1488                        &new_text_box_for_int (\%pr::win, 'msgs_y')),
1489                    &new_hbox_pack (
1490                        &new_text_box_for_int (\%pr::win, 'msgs_w'),
1491                        &new_text_box_for_int (\%pr::win, 'msgs_h'))),
1492                _('Message window')
1493            );
1494 }
1495
1496 sub new_winpos_subpage_sendrecv() {
1497     return &new_vbox_pack (
1498                &new_subpage_frame (
1499                    &new_hbox_pack (
1500                        &new_text_box_for_int (\%pr::win, 'send_w'),
1501                        &new_text_box_for_int (\%pr::win, 'send_h')),
1502                    _('Send window'), 'not-packed'),
1503                &new_subpage_frame (
1504                    &new_hbox_pack (
1505                        &new_text_box_for_int (\%pr::win, 'recv_w'),
1506                        &new_text_box_for_int (\%pr::win, 'recv_h')),
1507                    _('Receive window'), 'not-packed')
1508            );
1509 }
1510
1511 sub new_winpos_subpage_fold() {
1512     return &new_vbox_pack (
1513                &new_subpage_frame (
1514                    &new_vbox_pack_compact (
1515                        &new_vbox_pack (
1516                             &new_text_box_for_int (\%pr::win, 'fold_x'), 
1517                             &new_text_box_for_int (\%pr::win, 'fold_y')), 
1518                        &new_hbox_pack (
1519                            &new_text_box_for_int (\%pr::win, 'fold_w'), 
1520                            &new_text_box_for_int (\%pr::win, 'fold_h'))),
1521                    _('Folder window'), 'not-packed'),
1522                &new_subpage_frame (
1523                    &new_hbox_pack (
1524                        &new_text_box_for_int (\%pr::win, 'fsel_w'),
1525                        &new_text_box_for_int (\%pr::win, 'fsel_h')),
1526                    _('Folder selection window'), 'not-packed')
1527            );
1528 }
1529
1530 sub new_winpos_subpage_addrbook() {
1531     return &new_vbox_pack (
1532                 &new_subpage_frame (
1533                      &new_hbox_pack (
1534                           &new_text_box_for_int (\%pr::win, 'addr_w'),
1535                           &new_text_box_for_int (\%pr::win, 'addr_h')),
1536                      _('Addressbook main window'), 'not-packed'),
1537                 &new_subpage_frame (
1538                      &new_hbox_pack (
1539                           &new_text_box_for_int (\%pr::win, 'adep_w'),
1540                           &new_text_box_for_int (\%pr::win, 'adep_h')),
1541                      _('Edit person window'), 'not-packed'),
1542                 &new_subpage_frame (
1543                      &new_hbox_pack (
1544                           &new_text_box_for_int (\%pr::win, 'adeg_w'),
1545                           &new_text_box_for_int (\%pr::win, 'adeg_h')),
1546                      _('Edit group window'), 'not-packed'),
1547                 &new_subpage_frame (
1548                      &new_hbox_pack (
1549                           &new_text_box_for_int (\%pr::win, 'adda_w'),
1550                           &new_text_box_for_int (\%pr::win, 'adda_h')),
1551                      _('Add address window'), 'not-packed'),
1552                 &new_subpage_frame (
1553                      &new_hbox_pack (
1554                           &new_text_box_for_int (\%pr::win, 'addf_w'),
1555                           &new_text_box_for_int (\%pr::win, 'addf_h')),
1556                      _('Folder select window'), 'not-packed')
1557            );
1558 }
1559
1560 sub new_winpos_subpage_accounts() {
1561     return &new_vbox_pack (
1562                 &new_subpage_frame (
1563                      &new_hbox_pack (
1564                           &new_text_box_for_int (\%pr::win, 'acco_w'),
1565                           &new_text_box_for_int (\%pr::win, 'acco_h')),
1566                      _('Accounts window'), 'not-packed'),
1567                 &new_subpage_frame (
1568                      &new_hbox_pack (
1569                           &new_text_box_for_int (\%pr::win, 'acce_w'),
1570                           &new_text_box_for_int (\%pr::win, 'acce_h')),
1571                      _('Edit account window'), 'not-packed')
1572            );
1573 }
1574
1575 sub new_winpos_subpage_filtering() {
1576     return &new_vbox_pack (
1577                 &new_subpage_frame (
1578                      &new_hbox_pack (
1579                           &new_text_box_for_int (\%pr::win, 'filt_w'),
1580                           &new_text_box_for_int (\%pr::win, 'filt_h')),
1581                      _('Filtering window'), 'not-packed'),
1582                 &new_subpage_frame (
1583                      &new_hbox_pack (
1584                           &new_text_box_for_int (\%pr::win, 'fila_w'),
1585                           &new_text_box_for_int (\%pr::win, 'fila_h')),
1586                      _('Filtering actions window'), 'not-packed'),
1587                 &new_subpage_frame (
1588                      &new_hbox_pack (
1589                           &new_text_box_for_int (\%pr::win, 'fild_w'),
1590                           &new_text_box_for_int (\%pr::win, 'fild_h')),
1591                      _('Filtering debug window'), 'not-packed'),
1592                 &new_subpage_frame (
1593                      &new_hbox_pack (
1594                           &new_text_box_for_int (\%pr::win, 'matc_w'),
1595                           &new_text_box_for_int (\%pr::win, 'matc_h')),
1596                      _('Matcher window'), 'not-packed')
1597            );
1598 }
1599
1600 sub new_winpos_subpage_prefs() {
1601     return &new_vbox_pack (
1602                 &new_subpage_frame (
1603                      &new_hbox_pack (
1604                           &new_text_box_for_int (\%pr::win, 'pref_w'),
1605                           &new_text_box_for_int (\%pr::win, 'pref_h')),
1606                      _('Preferences window'), 'not-packed'),
1607                 &new_subpage_frame (
1608                      &new_hbox_pack (
1609                           &new_text_box_for_int (\%pr::win, 'temp_w'),
1610                           &new_text_box_for_int (\%pr::win, 'temp_h')),
1611                      _('Templates window'), 'not-packed'),
1612                 &new_subpage_frame (
1613                      &new_hbox_pack (
1614                           &new_text_box_for_int (\%pr::win, 'acti_w'),
1615                           &new_text_box_for_int (\%pr::win, 'acti_h')),
1616                      _('Actions window'), 'not-packed'),
1617                 &new_subpage_frame (
1618                      &new_hbox_pack (
1619                           &new_text_box_for_int (\%pr::win, 'tags_w'),
1620                           &new_text_box_for_int (\%pr::win, 'tags_h')),
1621                      _('Tags window'), 'not-packed'),
1622                 &new_subpage_frame (
1623                      &new_hbox_pack (
1624                           &new_text_box_for_int (\%pr::win, 'plug_w'),
1625                           &new_text_box_for_int (\%pr::win, 'plug_h')),
1626                      _('Plugins window'), 'not-packed')
1627            );
1628 }
1629
1630 sub new_winpos_subpage_misc() {
1631     return &new_vbox_pack (
1632                 &new_subpage_frame (
1633                      &new_hbox_pack (
1634                           &new_text_box_for_int (\%pr::win, 'logw_w'),
1635                           &new_text_box_for_int (\%pr::win, 'logw_h')),
1636                      _('Log window'), 'not-packed'),
1637                 &new_subpage_frame (
1638                      &new_hbox_pack (
1639                           &new_text_box_for_int (\%pr::win, 'prin_w'),
1640                           &new_text_box_for_int (\%pr::win, 'prin_h')),
1641                      _('Print preview window'), 'not-packed'),
1642                 &new_subpage_frame (
1643                      &new_hbox_pack (
1644                           &new_text_box_for_int (\%pr::win, 'sour_w'),
1645                           &new_text_box_for_int (\%pr::win, 'sour_h')),
1646                      _('View source window'), 'not-packed')
1647            );
1648 }
1649
1650 sub new_winpos_page() {
1651     my $winbook = Gtk2::Notebook->new;
1652     $winbook->set_tab_pos ('right');
1653     $winbook->append_page (&new_winpos_subpage_main, _('Main'));
1654     $winbook->append_page (&new_winpos_subpage_msgs, _('Message'));
1655     $winbook->append_page (&new_winpos_subpage_sendrecv, _('Send/Receive'));
1656     $winbook->append_page (&new_winpos_subpage_fold, _('Folder'));
1657     $winbook->append_page (&new_winpos_subpage_addrbook, _('Addressbook'));
1658     $winbook->append_page (&new_winpos_subpage_accounts, _('Accounts'));
1659     $winbook->append_page (&new_winpos_subpage_filtering, _('Filtering'));
1660     $winbook->append_page (&new_winpos_subpage_prefs, _('Preferences'));
1661     $winbook->append_page (&new_winpos_subpage_misc, _('Other'));
1662     return $winbook;
1663 }
1664
1665 # version info
1666 sub print_version() {
1667     print $xl::s{about_title} . "\n";
1668     print $xl::s{about_version} . " $VERSION\n";
1669     print "Perl-GLib " . $Glib::VERSION;
1670     # version info stuff appeared in 1.040
1671     if ($Glib::VERSION >= 1.040) {
1672         print _(", built for ") . join(".", Glib->GET_VERSION_INFO) 
1673               . _(", running with ") . join(".", &Glib::major_version, 
1674               &Glib::minor_version, &Glib::micro_version);
1675     }
1676     print "\n";
1677     print "Perl-GTK2 " . $Gtk2::VERSION;
1678     if ($Gtk2::VERSION >= 1.040) {
1679         print _(", built for ") . join(".", Gtk2->GET_VERSION_INFO)
1680               . _(", running with ") . join(".", &Gtk2::major_version, 
1681               &Gtk2::minor_version, &Gtk2::micro_version);
1682     }
1683     print "\n";
1684     my $clawsver = ($CLAWSV eq "") ? 
1685                 _("was not found!") : 
1686                 (_("returned version ") . $CLAWSV);
1687     print "Claws Mail " . $clawsver . "\n";
1688 }
1689
1690 # the command line help
1691 sub print_help() {
1692     my $line = '-' x length ($xl::s{about_title}) . "\n";
1693     print $line;
1694     print $xl::s{about_title} . "\n";
1695     print $line;
1696     print _("Syntax:\n");
1697     print _("    clawsker [options]\n");
1698     print _("Options:\n");
1699     print _("    --help                         Prints this help screen.\n");
1700     print _("    --version                      Prints version infos.\n");
1701     print _("    --verbose                      More messages on standard output.\n");
1702     print _("    --alternate-config-dir <dir>   Uses <dir> as Claws Mail config dir.\n");
1703     print _("    --clawsrc <file>               Uses <file> as full resource name.\n");
1704 }
1705
1706 # handle errors which don't allow to run
1707 sub command_line_fatal() {
1708     my $reason = shift;
1709     my $emsg = $xl::s{e_error} . $reason;
1710     error_dialog ($emsg);
1711     log_message ("$emsg", 'die');
1712 }
1713
1714 # parse the command line
1715 sub parse_command_line() {
1716     $CLAWSV = &get_claws_version;
1717     my $arg = 0;
1718     while (defined($ARGV[$arg])) {
1719         for ($ARGV[$arg]) {
1720             /--help/ && do { 
1721                 &print_help; 
1722                 return FALSE;
1723             };
1724             /--version/ && do { 
1725                 &print_version; 
1726                 return FALSE;
1727             };
1728             /--verbose/ && do {
1729                 $VERBOSE = TRUE;
1730                 last;
1731             };
1732             /--use-claws-version/ && do {
1733                 ++$arg;
1734                 &command_line_fatal ("required version")
1735                     unless defined($ARGV[$arg]);
1736                 &command_line_fatal ("required a dotted numeric value")
1737                     unless ($ARGV[$arg] =~ /[\d\.]+/);
1738                 $CLAWSV = $ARGV[$arg];
1739                 last;
1740             };
1741             /--alternate-config-dir/ && do {
1742                 ++$arg;
1743                 &command_line_fatal ($xl::s{e_requireddir})
1744                     unless defined($ARGV[$arg]);
1745                 &command_line_fatal ($xl::s{e_notadir})
1746                     unless -d $ARGV[$arg];
1747                 $CONFIGDIR = $ARGV[$arg];
1748                 $CONFIGDIR .= "/" 
1749                     unless ($CONFIGDIR =~ /.*\/$/);
1750                 $ALTCONFIGDIR = TRUE;
1751                 last;
1752             };
1753             /--clawsrc/ && do {
1754                 ++$arg;
1755                 &command_line_fatal($xl::s{e_requiredfile}) 
1756                     unless defined($ARGV[$arg]);
1757                 &command_line_fatal($xl::s{e_notafile}) 
1758                     unless -f $ARGV[$arg];
1759                 &set_rc_filename ($ARGV[$arg]);
1760                 last;
1761             };
1762             /.*/ && &command_line_fatal (
1763                 _("unknown option '{opt}'.\n", opt => $ARGV[$arg]));
1764         }
1765         ++$arg;
1766     }
1767     # eveything continues...
1768     return TRUE;
1769 }
1770
1771 # update the hidden preferences status from loaded values
1772 sub init_hidden_preferences() {
1773     foreach my $hash (\%pr::beh, \%pr::col, \%pr::gui, \%pr::oth, \%pr::win) {
1774         foreach my $key (keys %$hash) { 
1775             $HPVALUE{${$hash}{$key}[NAME]} = $PREFS{${$hash}{$key}[NAME]};
1776         }
1777     }
1778     return TRUE;
1779 }
1780
1781 # load current status from disc
1782 sub load_preferences() {
1783     my $rc = &get_rc_filename;
1784     &log_message ("Loading preferences from $rc\n");
1785     return FALSE unless &check_rc_file ($rc);
1786     return FALSE unless &check_claws_not_running;
1787     open (RCF, "<$rc");
1788     while (<RCF>) {
1789         chomp;
1790         if (/^([8a-z_]+)=(.*)$/) {
1791             $PREFS{$1} = "$2";
1792         }
1793     }
1794     close (RCF);
1795     return TRUE;
1796 }
1797
1798 # save current preferences to disc
1799 sub save_preferences() {
1800     my $rc = &get_rc_filename;
1801     &log_message ("Saving preferences to $rc\n");
1802     return FALSE unless &check_rc_file ($rc);
1803     return FALSE unless &check_claws_not_running;
1804     my $rcbak = "$rc.backup";
1805     rename ($rc, $rcbak);
1806     open (RCF, ">$rc");
1807     open (RCB, "<$rcbak");
1808     while (<RCB>) {
1809         chomp;
1810         if (/^([8a-z_]+)=(.*)$/) {
1811             if (defined($HPVALUE{$1})) {
1812                 print RCF $1 . "=" . $HPVALUE{$1} . "\n";
1813             }
1814             else {
1815                 print RCF $_ . "\n";
1816             }
1817         }
1818         else {
1819             print RCF $_ . "\n";
1820         }
1821     }
1822     close (RCB);
1823     close (RCF);
1824     return TRUE;
1825 }
1826
1827 # create notebook
1828 sub new_notebook() {
1829     my $nb = Gtk2::Notebook->new;
1830     # 
1831     $nb->append_page (&new_behaviour_page, $xl::s{tab_behaviour});
1832     $nb->append_page (&new_colours_page, $xl::s{tab_colours});
1833     $nb->append_page (&new_gui_page, $xl::s{tab_gui});
1834     $nb->append_page (&new_other_page, $xl::s{tab_other});
1835     $nb->append_page (&new_winpos_page, $xl::s{tab_winpos});
1836
1837     return $nb;
1838 }
1839
1840 # create an about dialog
1841 sub new_about_dialog() {
1842     my ($parent) = @_;
1843     my $title = $xl::s{about_title};
1844     my $lic = $xl::s{about_license};
1845     my $vers = $xl::s{about_version} . " $VERSION";
1846     my $license = 
1847 "This program is free software: you can redistribute it and/or modify
1848 it under the terms of the GNU General Public License as published by
1849 the Free Software Foundation, either version 3 of the License, or
1850 (at your option) any later version.
1851
1852 This program is distributed in the hope that it will be useful,
1853 but WITHOUT ANY WARRANTY; without even the implied warranty of
1854 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1855 GNU General Public License for more details.
1856
1857 You should have received a copy of the GNU General Public License
1858 along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.";
1859     my $year = "2007-2010";
1860     my $holder = "Ricardo Mones &lt;ricardo\@mones.org&gt;";
1861     my $url = "http://www.claws-mail.org/clawsker";
1862
1863     my $dialog = Gtk2::MessageDialog->new_with_markup ($parent, 
1864                     [qw/modal destroy-with-parent/], 
1865                     'info', 'close', 
1866                     "<span size=\"x-large\" weight=\"bold\">$title</span>\n"
1867                     . "<span size=\"large\">$vers</span>\n\n"
1868                     . "<span color=\"blue\" size=\"large\">$url</span>\n\n"
1869                     . "<span>Copyright $year by $holder</span>\n\n"
1870                     . "<span size=\"large\">$lic</span>\n\n"
1871                     . "<span size=\"small\">$license</span>");
1872     $dialog->set_title ($xl::s{about});
1873     #
1874     return $dialog;
1875 }
1876
1877 # create buttons box
1878 sub new_button_box() {
1879     my ($parent, $adlg) = @_;
1880     my $b_about = Gtk2::Button->new_from_stock ('gtk-about');
1881     my $b_exit = Gtk2::Button->new_from_stock ('gtk-quit');
1882     my $b_apply = Gtk2::Button->new_from_stock ('gtk-apply');
1883     # disable button until is really implemented
1884     # my $b_undo = Gtk2::Button->new_from_stock ('gtk-undo');
1885     my $hbox = Gtk2::HBox->new (FALSE, 5);
1886     # signal handlers 
1887     $b_exit->signal_connect (clicked => sub { Gtk2->main_quit });
1888     $b_apply->signal_connect (clicked => sub { &save_preferences ($parent) });
1889     # $b_undo->signal_connect (clicked => sub { &undo_current_changes });
1890     $b_about->signal_connect (clicked => sub { $adlg->run; $adlg->hide });
1891     # package them
1892     $hbox->pack_end ($b_apply, FALSE, FALSE, 0);
1893     $hbox->pack_end ($b_exit, FALSE, FALSE, 0);
1894     # $hbox->pack_end ($b_undo, FALSE, FALSE, 0);
1895     $hbox->pack_start ($b_about, FALSE, FALSE, 0);
1896     #
1897     return $hbox;
1898 }
1899
1900 # initialise
1901 $main_window = Gtk2::Window->new ('toplevel');
1902 exit unless &parse_command_line;
1903 exit unless &load_preferences;
1904 exit unless &init_hidden_preferences;
1905 # create main GUI
1906 my $box = Gtk2::VBox->new (FALSE, 5);
1907 $box->set_border_width(3);
1908 my $about = &new_about_dialog;
1909 $box->pack_start (&new_notebook, FALSE, FALSE, 0);
1910 $box->pack_end (&new_button_box ($main_window, $about), FALSE, FALSE, 0);
1911 $main_window->signal_connect (delete_event => sub { Gtk2->main_quit });
1912 $main_window->set_title ($xl::s{win_title});
1913 $main_window->add ($box);
1914 $main_window->show_all;
1915 Gtk2->main;
1916