fix warning when no LANG/LC_MESSAGES
[clawsker.git] / clawsker
index 7d25d0be0504ca8ccaf097e0feac4744b4d63f06..e7b56a8e0d4cdf9ed6a8be7c837c7a2288076edb 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -56,7 +56,7 @@ Ricardo Mones E<lt>ricardo@mones.orgE<gt>
 
 =head1 LICENSE
 
-Copyright (c) 2007 by Ricardo Mones
+Copyright (c) 2007-2008 by Ricardo Mones Lastra
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -87,10 +87,14 @@ my $VERBOSE = FALSE;
 my $main_window = undef;
 
 my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
+$locale = "C" unless defined($locale);
 setlocale (LC_ALL, $locale);
 bindtextdomain ($NAME, sprintf ('%s/share/locale', $PREFIX));
 textdomain ($NAME);
 
+my $SHOWHINTS = FALSE;
+$SHOWHINTS = TRUE if ($Gtk2::VERSION >= 1.040 and Gtk2->CHECK_VERSION (2, 12, 0));
+
 sub _ {
     my $str = shift;
     my %par = @_;
@@ -217,7 +221,9 @@ use constant NAME  => 0; # the name on the rc file
 use constant LABEL => 1; # the label on the GUI
 use constant DESC  => 2; # the description for the hint/help
 use constant TYPE  => 3; # data type: bool, int, float, string, color
-use constant GUI   => 4; # GUI element
+use constant CMVER => 4; # lowest Claws Mail version the feature exists
+use constant CMDEF => 5; # default value for the preference in Claws Mail
+use constant GUI   => 6; # GUI element
 
 # constants for GUI spacing
 use constant HBOX_SPC => 5;
@@ -297,18 +303,19 @@ sub set_rc_filename {
 
 sub log_message {
     my ($mesg, $fatal) = @_;
+    if (defined($fatal) && $fatal eq 'die') {
+        die "$NAME: $mesg\n";
+    }
     if ($VERBOSE) {
-        if (defined($fatal) && $fatal eq 'die') {
-          die "$NAME: $mesg\n";
-        }
         print "$NAME: $mesg\n";
     }
 }
 
 sub error_dialog {
     my ($emsg) = @_;
-    my $errordlg = Gtk2::MessageDialog->new ($main_window, 'modal', 'error', 'cancel', $emsg);
-    $errordlg->set_title (_('Error'));
+    my $markup = "<span weight=\"bold\" size=\"large\">" . $emsg . "</span>";
+    my $errordlg = Gtk2::MessageDialog->new_with_markup ($main_window, 'modal', 'error', 'cancel', $markup);
+    $errordlg->set_title (_('Error message'));
     $errordlg->run;
     $errordlg->destroy;
 }
@@ -338,6 +345,14 @@ sub check_rc_file() {
     return TRUE;
 }
 
+sub set_widget_hint() {
+    if ($SHOWHINTS) {
+        my ($wdgt, $hint) = @_;    
+        $wdgt->set_tooltip_text ($hint);
+        $wdgt->set_has_tooltip (TRUE);
+    }
+}
+
 # graphic element creation 
 
 sub new_check_button_for {
@@ -353,6 +368,7 @@ sub new_check_button_for {
             my ($w, $e) = @_;
            &handle_bool_value($w, $e, \$HPVALUE{$name});
         });
+    &set_widget_hint ($cb, $$hash{$key}[DESC]);
     $hbox->pack_start ($cb, FALSE, FALSE, HBOX_SPC);
     #
     return $hbox;
@@ -373,6 +389,7 @@ sub new_text_box_for {
             my ($w, $e) = @_;
            &handle_int_value($w, $e, \$HPVALUE{$name}); # FIXME int only
         });
+    &set_widget_hint ($gentry, $$hash{$key}[DESC]);
     $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
     $hbox->pack_start ($gentry, FALSE, FALSE, HBOX_SPC);
     #
@@ -395,6 +412,7 @@ sub new_color_button_for {
             my ($w, $e) = @_;
            &handle_color_value($w, $e, \$HPVALUE{$name}); 
         });
+    &set_widget_hint ($button, $$hash{$key}[DESC]);
     $hbox->pack_start ($button, FALSE, FALSE, HBOX_SPC);
     $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
     #
@@ -420,6 +438,7 @@ sub new_selection_box_for {
            &handle_selection_value($w, $e, \$HPVALUE{$name});
         });
     $combo->set_active ($HPVALUE{$name});
+    &set_widget_hint ($combo, $$hash{$key}[DESC]);
     $hbox->pack_start ($glabel, FALSE, FALSE, HBOX_SPC);
     $hbox->pack_start ($combo, FALSE, FALSE, HBOX_SPC);
     #
@@ -434,6 +453,8 @@ sub new_selection_box_for {
        $xl::s{l_oth_use_dlg},
         $xl::s{h_oth_use_dlg},
        'bool',
+       '2.7.0',
+       '0',
        undef,
     ],
     max_use => [
@@ -441,6 +462,8 @@ sub new_selection_box_for {
        $xl::s{l_oth_max_use},
        $xl::s{h_oth_max_use},
        'int',
+       '0.0.0',
+       '4096',
        undef,
     ],
     min_time => [
@@ -448,6 +471,8 @@ sub new_selection_box_for {
        $xl::s{l_oth_min_time},
        $xl::s{h_oth_min_time},
        'int',
+       '0.0.0',
+       '15',
        undef,
     ],
 );
@@ -484,13 +509,17 @@ sub new_other_page() {
         $xl::s{l_gui_b_unread},
         $xl::s{h_gui_b_unread},
        'bool',
+       '0.0.0',
+       '1',
        undef,
     ],
     no_markup => [
         'compose_no_markup',
         $xl::s{l_gui_no_markup},
         $xl::s{h_gui_no_markup},
-       'bool',
+        'bool',
+        '0.0.0',
+        '0',
        undef,
     ],
     dot_lines => [
@@ -498,6 +527,8 @@ sub new_other_page() {
         $xl::s{l_gui_dot_lines},
         $xl::s{h_gui_dot_lines},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     h_scroll => [
@@ -505,6 +536,8 @@ sub new_other_page() {
         $xl::s{l_gui_h_scroll},
         $xl::s{h_gui_h_scroll},
        'bool',
+       '0.0.0',
+       '1',
        undef,
     ],
     swp_from => [
@@ -512,6 +545,8 @@ sub new_other_page() {
         $xl::s{l_gui_swp_from},
         $xl::s{h_gui_swp_from},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     v_scroll => [
@@ -519,6 +554,8 @@ sub new_other_page() {
         $xl::s{l_gui_v_scroll},
         $xl::s{h_gui_v_scroll},
        '0=l_gui_v_scroll_show;1=l_gui_v_scroll_auto;2=l_gui_v_scroll_hide',
+       '0.0.0',
+       '0',
        undef,
     ],
     strip_off => [
@@ -526,6 +563,8 @@ sub new_other_page() {
        $xl::s{l_gui_strip_off},
        $xl::s{h_gui_strip_off},
        'int',
+       '0.0.0',
+       '4000',
        undef,
     ],
     cursor_v => [
@@ -533,6 +572,8 @@ sub new_other_page() {
         $xl::s{l_gui_cursor_v},
         $xl::s{h_gui_cursor_v},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     toolbar_d => [
@@ -540,6 +581,8 @@ sub new_other_page() {
         $xl::s{l_gui_toolbar_d},
         $xl::s{h_gui_toolbar_d},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     strip_all => [
@@ -547,6 +590,8 @@ sub new_other_page() {
         $xl::s{l_gui_strip_all},
         $xl::s{h_gui_strip_all},
        'bool',
+       '0.0.0',
+       '1',
        undef,
     ],
     strip_sum => [
@@ -554,6 +599,8 @@ sub new_other_page() {
         $xl::s{l_gui_strip_sum},
         $xl::s{h_gui_strip_sum},
        'bool',
+       '0.0.0',
+       '1',
        undef,
     ],
 );
@@ -613,6 +660,8 @@ sub new_gui_page() {
         $xl::s{l_beh_hover_t},
         $xl::s{h_beh_hover_t},
        'int',
+       '0.0.0',
+       '500',
        undef,
     ],
     dangerous => [
@@ -620,6 +669,8 @@ sub new_gui_page() {
         $xl::s{l_beh_dangerous},
         $xl::s{h_beh_dangerous},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     flowed => [
@@ -627,6 +678,8 @@ sub new_gui_page() {
         $xl::s{l_beh_flowed},
         $xl::s{h_beh_flowed},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     parts_rw => [
@@ -634,6 +687,8 @@ sub new_gui_page() {
         $xl::s{l_beh_parts_rw},
         $xl::s{h_beh_parts_rw},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     skip_ssl => [
@@ -641,6 +696,8 @@ sub new_gui_page() {
         $xl::s{l_beh_skip_ssl},
         $xl::s{h_beh_skip_ssl},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     up_step => [
@@ -648,6 +705,8 @@ sub new_gui_page() {
         $xl::s{l_beh_up_step},
         $xl::s{h_beh_up_step},
        'int',
+       '0.0.0',
+       '10',
        undef,
     ],
     thread_a => [
@@ -655,6 +714,8 @@ sub new_gui_page() {
         $xl::s{l_beh_thread_a},
         $xl::s{h_beh_thread_a},
        'int',
+       '0.0.0',
+       '10',
        undef,
     ],
     unsafe_ssl => [
@@ -662,6 +723,8 @@ sub new_gui_page() {
         $xl::s{l_beh_unsafe_ssl},
         $xl::s{h_beh_unsafe_ssl},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     use_utf8 => [
@@ -669,6 +732,8 @@ sub new_gui_page() {
         $xl::s{l_beh_use_utf8},
         $xl::s{h_beh_use_utf8},
        'bool',
+       '0.0.0',
+       '0',
        undef,
     ],
     warn_dnd => [
@@ -676,6 +741,8 @@ sub new_gui_page() {
         $xl::s{l_beh_warn_dnd},
         $xl::s{h_beh_warn_dnd},
        'bool',
+       '0.0.0',
+       '1',
        undef,
     ],
 );
@@ -733,6 +800,8 @@ sub new_behaviour_page() {
         $xl::s{l_col_emphasis},
         $xl::s{h_col_emphasis},
        'color',
+       '0.0.0',
+       '#0000cf',
        undef,
     ],
     log_err => [
@@ -740,6 +809,8 @@ sub new_behaviour_page() {
         $xl::s{l_col_log_err},
         $xl::s{h_col_log_err},
         'color',
+       '0.0.0',
+       '#af0000',
         undef,
     ],
     log_in => [
@@ -747,6 +818,8 @@ sub new_behaviour_page() {
         $xl::s{l_col_log_in},
         $xl::s{h_col_log_in},
         'color',
+       '0.0.0',
+       '#000000',
         undef,
     ],
     log_msg => [
@@ -754,6 +827,8 @@ sub new_behaviour_page() {
         $xl::s{l_col_log_msg},
         $xl::s{h_col_log_msg},
         'color',
+       '0.0.0',
+       '#00af00',
         undef,
     ],
     log_out => [
@@ -761,6 +836,8 @@ sub new_behaviour_page() {
         $xl::s{l_col_log_out},
         $xl::s{h_col_log_out},
         'color',
+       '0.0.0',
+       '#0000ef',
         undef,
     ],
     log_warn => [
@@ -768,6 +845,8 @@ sub new_behaviour_page() {
         $xl::s{l_col_log_warn},
         $xl::s{h_col_log_warn},
         'color',
+       '0.0.0',
+       '#af0000',
         undef,
     ],
 );
@@ -810,6 +889,21 @@ sub print_help() {
     print $line;
     print $xl::s{about_title} . "\n";
     print $xl::s{about_version} . " $VERSION\n";
+    print "Perl-GLib " . $Glib::VERSION;
+    # version info stuff appeared in 1.040
+    if ($Glib::VERSION >= 1.040) {
+        print _(", built for ") . join(".", Glib->GET_VERSION_INFO) 
+              . _(", running with ") . join(".", &Glib::major_version, 
+                 &Glib::minor_version, &Glib::micro_version);
+    }
+    print "\n";
+    print "Perl-GTK2 " . $Gtk2::VERSION;
+    if ($Gtk2::VERSION >= 1.040) {
+        print _(", built for ") . join(".", Gtk2->GET_VERSION_INFO)
+             . _(", running with ") . join(".", &Gtk2::major_version, 
+                 &Gtk2::minor_version, &Gtk2::micro_version);
+    }
+    print "\n";
     print $line;
     print _("Syntax:\n");
     print _("    clawsker [options]\n");
@@ -820,6 +914,14 @@ sub print_help() {
     print _("    --clawsrc <file>               Uses <file> as full resource name.\n");
 }
 
+# handle errors which don't allow to run
+sub command_line_fatal() {
+    my $reason = shift;
+    my $emsg = $xl::s{e_error} . $reason;
+    error_dialog ($emsg);
+    log_message ("$emsg", 'die');
+}
+
 # parse the command line
 sub parse_command_line() {
     my $arg = 0;
@@ -827,16 +929,17 @@ sub parse_command_line() {
         for ($ARGV[$arg]) {
             /--help/ && do { 
                &print_help; 
-                exit 0;
+                return FALSE;
            };
            /--verbose/ && do {
                $VERBOSE = TRUE;
+               last;
            };
            /--alternate-config-dir/ && do {
                ++$arg;
-               die "$xl::s{e_error}$xl::s{e_requireddir}\n" 
+               &command_line_fatal ($xl::s{e_requireddir})
                    unless defined($ARGV[$arg]);
-               die "$xl::s{e_error}$xl::s{e_notadir}\n" 
+               &command_line_fatal ($xl::s{e_notadir})
                    unless -d $ARGV[$arg];
                $CONFIGDIR = $ARGV[$arg];
                $ALTCONFIGDIR = TRUE;
@@ -844,18 +947,20 @@ sub parse_command_line() {
            };
            /--clawsrc/ && do {
                ++$arg;
-               die "$xl::s{e_error}$xl::s{e_requiredfile}\n" 
+               &command_line_fatal($xl::s{e_requiredfile}) 
                    unless defined($ARGV[$arg]);
-               die "$xl::s{e_error}$xl::s{e_notafile}\n" 
+               &command_line_fatal($xl::s{e_notafile}) 
                    unless -f $ARGV[$arg];
                &set_rc_filename ($ARGV[$arg]);
                last;
            };
-           /.*/ && die $xl::s{e_error} 
-                       . _("unknown option '{opt}'.\n", opt => $ARGV[$arg]);
+           /.*/ && &command_line_fatal (
+                       _("unknown option '{opt}'.\n", opt => $ARGV[$arg]));
        }
        ++$arg;
     }
+    # eveything continues...
+    return TRUE;
 }
 
 # update the hidden preferences status from loaded values
@@ -865,13 +970,15 @@ sub init_hidden_preferences() {
            $HPVALUE{${$hash}{$key}[NAME]} = $PREFS{${$hash}{$key}[NAME]};
         }
     }
+    return TRUE;
 }
 
 # load current status from disc
 sub load_preferences() {
     my $rc = &get_rc_filename;
-    &check_rc_file ($rc) or return;
-    &check_claws_not_running or return;
+    &log_message ("Loading preferences from $rc\n");
+    return FALSE unless &check_rc_file ($rc);
+    return FALSE unless &check_claws_not_running;
     open (RCF, "<$rc");
     while (<RCF>) {
        chomp;
@@ -880,13 +987,15 @@ sub load_preferences() {
         }
     }
     close (RCF);
+    return TRUE;
 }
 
 # save current preferences to disc
 sub save_preferences() {
     my $rc = &get_rc_filename;
-    &check_rc_file ($rc) or return;
-    &check_claws_not_running or return;
+    &log_message ("Saving preferences to $rc\n");
+    return FALSE unless &check_rc_file ($rc);
+    return FALSE unless &check_claws_not_running;
     my $rcbak = "$rc.backup";
     rename ($rc, $rcbak);
     open (RCF, ">$rc");
@@ -907,6 +1016,7 @@ sub save_preferences() {
     }
     close (RCB);
     close (RCF);
+    return TRUE;
 }
 
 # create notebook
@@ -971,8 +1081,8 @@ sub new_button_box() {
     # $b_undo->signal_connect (clicked => sub { &undo_current_changes });
     $b_about->signal_connect (clicked => sub { $adlg->run; $adlg->hide });
     # package them
-    $hbox->pack_end ($b_exit, FALSE, FALSE, 0);
     $hbox->pack_end ($b_apply, FALSE, FALSE, 0);
+    $hbox->pack_end ($b_exit, FALSE, FALSE, 0);
     # $hbox->pack_end ($b_undo, FALSE, FALSE, 0);
     $hbox->pack_start ($b_about, FALSE, FALSE, 0);
     #
@@ -981,9 +1091,9 @@ sub new_button_box() {
 
 # initialise
 $main_window = Gtk2::Window->new ('toplevel');
-&parse_command_line;
-&load_preferences;
-&init_hidden_preferences;
+exit unless &parse_command_line;
+exit unless &load_preferences;
+exit unless &init_hidden_preferences;
 # create main GUI
 my $box = Gtk2::VBox->new (FALSE, 5);
 $box->set_border_width(3);