Fix copyright years
[clawsker.git] / clawsker
index 736fae80c054d76e65d31747ee869704d7cbad96..7922ee69cfac06d12ab32c570c9d5c4d984b882d 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -31,6 +31,9 @@ using Clawsker.
 --help
        Shows a brief help screen.
 
+--version
+       Show information about program, Claws Mail and Perl-GTK versions.
+
 --verbose
        Tells more on the standard output.
 
@@ -56,7 +59,7 @@ Ricardo Mones E<lt>ricardo@mones.orgE<gt>
 
 =head1 LICENSE
 
-Copyright (c) 2007-2008 by Ricardo Mones Lastra
+Copyright (c) 2007-2009 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
@@ -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});
@@ -192,6 +196,8 @@ 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.'),
@@ -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})
@@ -1106,7 +1192,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.";
-    my $year = "2007";
+    my $year = "2007-2009";
     my $holder = "Ricardo Mones &lt;ricardo\@mones.org&gt;";
 
     my $dialog = Gtk2::MessageDialog->new_with_markup ($parent,