add --use-claws-version and set it as global
[clawsker.git] / clawsker
index 64831d60c120e37da1ce0859610bddc33eddee49..06ff51e789ef175a89e4315e0b794e947702f3ea 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -31,8 +31,11 @@ using Clawsker.
 --help
        Shows a brief help screen.
 
+--version
+       Show information about program, Claws Mail and Perl-GTK versions.
+
 --verbose
-       Tell more on the standard output.
+       Tells more on the standard output.
 
 --alternate-config-dir <dir>
        Uses <dir> as Claws Mail configuration dir.
@@ -85,6 +88,7 @@ my $PREFIX = '@PREFIX@';
 my $LIBDIR = '@LIBDIR@';
 my $VERSION = '@VERSION@';
 my $VERBOSE = FALSE;
+my $CLAWSV = undef;
 my $main_window = undef;
 
 my $locale = (defined($ENV{LC_MESSAGES}) ? $ENV{LC_MESSAGES} : $ENV{LANG});
@@ -130,13 +134,13 @@ sub _ {
     msgs_frame => _('Messages'),
     stripes_frame => _('Coloured stripes'),
     sbar_frame => _('Scroll bars'),
-    mlist_frame => _('Message list'),
+    mlist_frame => _('Message List'),
     netm_frame => _('NetworkManager'),
 
     l_oth_use_dlg => _('Use detached address book edit dialogue'),
     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.'),
-    l_oth_max_use => _('Maximum memory for message cache (Kb)'),
-    h_oth_max_use => _('The maximum amount of memory to use to cache messages, in kB.'),
+    l_oth_max_use => _('Maximum memory for message cache (kB)'),
+    h_oth_max_use => _('The maximum amount of memory to use to cache messages, in kilobytes.'),
     l_oth_min_time => _('Minimun time for cache elements (minutes)'),
     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.'),
     l_oth_use_netm => _('Use NetworkManager'),
@@ -146,18 +150,18 @@ sub _ {
     h_gui_b_unread => _('Show unread messages in the Message List using a bold font.'),
     l_gui_no_markup => _('Don\'t use markup in compose window'),
     h_gui_no_markup => _('Don\'t use bold and italic text in Compose dialogue\'s account selector.'),
-    l_gui_dot_lines => _('Use dotted lines in tree views'),
-    h_gui_dot_lines => _('Use the old dotted line look in the main window tree views (folder and message lists) instead of the modern lineless look.'),
+    l_gui_dot_lines => _('Use dotted lines in tree view components'),
+    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.'),
     l_gui_h_scroll => _('Enable horizontal scrollbar'),
     h_gui_h_scroll => _('Enable the horizontal scrollbar in the Message List.'),
-    l_gui_swp_from => _('Dislay To header in From field in Sent folder'),
-    h_gui_swp_from => _('Display the sender\'s email address in the To column of the Sent folder instead of the recipient\'s.'),
-    l_gui_v_scroll => _('Folder list scrollbar behaviour'),
+    l_gui_swp_from => _('Dislay To column instead From column in Sent folder'),
+    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.'),
+    l_gui_v_scroll => _('Folder List scrollbar behaviour'),
     h_gui_v_scroll => _('Specify the policy of vertical scrollbar of Folder List: show always, automatic or hide always.'),
     l_gui_v_scroll_show => _('Show always'),
     l_gui_v_scroll_auto => _('Automatic'),
     l_gui_v_scroll_hide => _('Hide always'),
-    l_gui_strip_off => _('Striped lines contrast'),
+    l_gui_strip_off => _('Coloured lines contrast'),
     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.'),
     l_gui_cursor_v => _('Show Cursor in message view'),
     h_gui_cursor_v => _('Display the cursor in the message view.'),
@@ -166,9 +170,9 @@ sub _ {
     l_gui_strip_all => _('Use stripes in all tree view components'),
     h_gui_strip_all => _('Enable alternately coloured lines in all tree view components.'),
     l_gui_strip_sum => _('Use stripes in Folder List and Message List'),
-    h_gui_strip_sum => _('Enable alternately coloured lines in message list and folder list'),
+    h_gui_strip_sum => _('Enable alternately coloured lines in Message list and Folder list.'),
     l_gui_two_line_v => _('2 lines per Message List item in 3-column layout'),
-    h_gui_two_line_v => _('Spread Message List information over two lines when using the three column mode'),
+    h_gui_two_line_v => _('Spread Message List information over two lines when using the three column mode.'),
 
     l_beh_hover_t => _('Drag \'n\' drop hover timeout (ms)'),
     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.'),
@@ -192,17 +196,19 @@ sub _ {
     h_beh_warn_dnd => _('Display a confirmation dialogue on drag \'n\' drop of folders.'),
     l_beh_out_ascii => _('Ougoing messages fallback to ASCII'),
     h_beh_out_ascii => _('If content allows, ASCII will be used to encode outgoing messages, otherwise the user-defined encoding is enforced always.'),
+    l_beh_pp_unsel => _('Primary paste unselects selection'),
+    h_beh_pp_unsel => _('Controls how pasting using middle-click changes the selected text and insertion point.'),
 
     l_col_emphasis => _('X-Mailer header'),
     h_col_emphasis => _('The colour used for the X-Mailer line when its value is Claws Mail.'),
     l_col_log_err => _('Error messages'),
     h_col_log_err => _('Colour for error messages in log window.'),
     l_col_log_in => _('Server messages'),
-    h_col_log_in => _('Colour for input messages in log window.'),
+    h_col_log_in => _('Colour for messages received from servers in log window.'),
     l_col_log_msg => _('Standard messages'),
     h_col_log_msg => _('Colour for messages in log window.'),
     l_col_log_out => _('Client messages'),
-    h_col_log_out => _('Colour for output messages in log window.'),
+    h_col_log_out => _('Colour for messages sent to servers in log window.'),
     l_col_log_warn => _('Warnings'),
     h_col_log_warn => _('Colour for warning messages in log window.'),
 
@@ -238,6 +244,52 @@ use constant HBOX_SPC => 5;
 use constant FRAME_SPC => 2;
 use constant PAGE_SPC => 5;
 
+# version functions
+
+sub version_greater() {
+  my ($version, $refvers) = @_;
+  my @version = split (/\./, $version);
+  my @refvers = split (/\./, $refvers);
+  while ($#version < $#refvers) {
+    push (@version, '0');
+  }
+  my $idx = 0;
+  while (($idx <= $#refvers) 
+         and (int ($version[$idx]) == int ($refvers[$idx]))) {
+    ++$idx;
+  }
+  return TRUE if (($idx > $#refvers) 
+               or (int ($version[$idx]) > int ($refvers[$idx])));
+  return FALSE;
+}
+
+sub get_claws_version() {
+    my @cmbin = (
+        'claws-mail',
+    );
+    my $res = "";
+    foreach my $bin (@cmbin) {
+        $_ = qx/which $bin/;
+        chomp;
+        last if ($_ ne "");
+    }
+    return "" unless ($_); # not installed
+    $_ = qx/$_ -v/;
+    chomp;
+    my @fver = split (/ /);
+    die "Invalid version string" unless ($fver[2] eq "version");
+    my @ver = split (/\./, $fver[3]);
+    $res .= "$ver[0].";
+    $res .= "$ver[1].";
+    if ($ver[2] =~ /(\d+)cvs(\d+)/) {
+        $res .= "$1.$2";
+    }
+    else {
+        $res .= "$ver[2].0";
+    }
+    return $res;
+}
+
 # data handlers and auxiliar functions
 
 sub handle_bool_value {
@@ -797,6 +849,15 @@ sub new_gui_page() {
        '1',
        undef,
     ],
+    pp_unsel => [
+        'primary_paste_unselects',
+        $xl::s{l_beh_pp_unsel},
+        $xl::s{h_beh_pp_unsel},
+        'bool',
+        '3.6.1.35',
+        '0',
+        undef,
+    ],
 );
 
 sub new_behaviour_page() {
@@ -830,6 +891,7 @@ sub new_behaviour_page() {
     my $cb_use_utf8 = &new_check_button_for (\%pr::beh, 'use_utf8');
     my $cb_dangerous = &new_check_button_for (\%pr::beh, 'dangerous');
     my $cb_out_ascii = &new_check_button_for (\%pr::beh, 'out_ascii');
+    my $cb_pp_unsel = &new_check_button_for (\%pr::beh, 'pp_unsel');
     my $vb2 = Gtk2::VBox->new (FALSE, 5);    
     $vb2->set_border_width (PAGE_SPC);
     $vb2->pack_start ($cb_flowed, FALSE, FALSE, 0);
@@ -837,6 +899,7 @@ sub new_behaviour_page() {
     $vb2->pack_start ($cb_use_utf8, FALSE, FALSE, 0);
     $vb2->pack_start ($cb_dangerous, FALSE, FALSE, 0);
     $vb2->pack_start ($cb_out_ascii, FALSE, FALSE, 0);
+    $vb2->pack_start ($cb_pp_unsel, FALSE, FALSE, 0);
     $msgs_frame->add ($vb2);
 
     $bf->pack_start ($dnd_frame, FALSE, FALSE, FRAME_SPC);
@@ -937,10 +1000,8 @@ sub new_colours_page() {
     return $cf;
 }
 
-# the command line help
-sub print_help() {
-    my $line = '-' x length ($xl::s{about_title}) . "\n";
-    print $line;
+# version info
+sub print_version() {
     print $xl::s{about_title} . "\n";
     print $xl::s{about_version} . " $VERSION\n";
     print "Perl-GLib " . $Glib::VERSION;
@@ -958,11 +1019,23 @@ sub print_help() {
                  &Gtk2::minor_version, &Gtk2::micro_version);
     }
     print "\n";
+    my $clawsver = ($CLAWSV eq "") ? 
+                _("was not found!") : 
+                (_("returned version ") . $CLAWSV);
+    print "Claws Mail " . $clawsver . "\n";
+}
+
+# the command line help
+sub print_help() {
+    my $line = '-' x length ($xl::s{about_title}) . "\n";
+    print $line;
+    print $xl::s{about_title} . "\n";
     print $line;
     print _("Syntax:\n");
     print _("    clawsker [options]\n");
     print _("Options:\n");
     print _("    --help                         Prints this help screen.\n");
+    print _("    --version                      Prints version infos.\n");
     print _("    --verbose                      More messages on standard output.\n");
     print _("    --alternate-config-dir <dir>   Uses <dir> as Claws Mail config dir.\n");
     print _("    --clawsrc <file>               Uses <file> as full resource name.\n");
@@ -978,6 +1051,7 @@ sub command_line_fatal() {
 
 # parse the command line
 sub parse_command_line() {
+    $CLAWSV = &get_claws_version;
     my $arg = 0;
     while (defined($ARGV[$arg])) {
         for ($ARGV[$arg]) {
@@ -985,10 +1059,22 @@ sub parse_command_line() {
                &print_help; 
                 return FALSE;
            };
+            /--version/ && do { 
+               &print_version; 
+                return FALSE;
+           };
            /--verbose/ && do {
                $VERBOSE = TRUE;
                last;
            };
+           /--use-claws-version/ && do {
+               ++$arg;
+               &command_line_fatal ("required version")
+                   unless defined($ARGV[$arg]);
+               &command_line_fatal ("required a dotted numeric value")
+                   unless ($ARGV[$arg] =~ /[\d\.]+/);
+               $CLAWSV = $ARGV[$arg];
+           };
            /--alternate-config-dir/ && do {
                ++$arg;
                &command_line_fatal ($xl::s{e_requireddir})