2006-06-27 [colin] 2.3.1cvs26
authorColin Leroy <colin@colino.net>
Tue, 27 Jun 2006 16:10:22 +0000 (16:10 +0000)
committerColin Leroy <colin@colino.net>
Tue, 27 Jun 2006 16:10:22 +0000 (16:10 +0000)
* src/compose.c
Fix Esc handling in insert/attach dialog
Don't show this dialog if dragging something
else than text/uri-list
Thanks to Fabien Vantard
* tools/textviewer.pl
Filter script to display stuff as text
by H. Merijn Brand

ChangeLog
PATCHSETS
configure.ac
src/compose.c
tools/textviewer.pl [new file with mode: 0644]

index 9100b8e..36e1825 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-06-27 [colin]     2.3.1cvs26
+
+       * src/compose.c
+               Fix Esc handling in insert/attach dialog
+               Don't show this dialog if dragging something
+               else than text/uri-list
+               Thanks to Fabien Vantard
+       * tools/textviewer.pl
+               Filter script to display stuff as text
+               by H. Merijn Brand
+
 2006-06-27 [wwp]       2.3.1cvs25
 
        * src/messageview.c
index 77504de..8460053 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.28.2.20 -r 1.28.2.21 src/mbox.c;  ) > 2.3.1cvs23.patchset
 ( cvs diff -u -r 1.105.2.57 -r 1.105.2.58 src/prefs_account.c;  cvs diff -u -r 1.204.2.91 -r 1.204.2.92 src/prefs_common.c;  cvs diff -u -r 1.103.2.53 -r 1.103.2.54 src/prefs_common.h;  cvs diff -u -r 1.3.2.7 -r 1.3.2.8 src/prefs_ext_prog.c;  cvs diff -u -r 1.96.2.118 -r 1.96.2.119 src/textview.c;  ) > 2.3.1cvs24.patchset
 ( cvs diff -u -r 1.94.2.89 -r 1.94.2.90 src/messageview.c;  ) > 2.3.1cvs25.patchset
+( cvs diff -u -r 1.382.2.287 -r 1.382.2.288 src/compose.c;  diff -u /dev/null tools/textviewer.pl;  ) > 2.3.1cvs26.patchset
index a3cd5e0..3d45c03 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=3
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=25
+EXTRA_VERSION=26
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 3745196..4f2ceab 100644 (file)
@@ -8501,48 +8501,47 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
 {
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
-       AlertValue val = G_ALERTDEFAULT;
-
-       switch (prefs_common.compose_dnd_mode) {
-               case COMPOSE_DND_ASK:
-                       val = alertpanel_full(_("Insert or attach?"),
-                                _("Do you want to insert the contents of the file(s) "
-                                  "into the message body, or attach it to the email?"),
-                                 GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
-                                 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
-                       break;
-               case COMPOSE_DND_INSERT:
-                       val = G_ALERTALTERNATE;
-                       break;
-               case COMPOSE_DND_ATTACH:
-                       val = G_ALERTOTHER;
-                       break;
-               default:
-                       /* unexpected case */
-                       g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
-       }
-
-       if (val & G_ALERTDISABLE) {
-               val &= ~G_ALERTDISABLE;
-               /* remember what action to perform by default, only if we don't click Cancel */
-               if (val == G_ALERTALTERNATE)
-                       prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
-               else
-                       if (val == G_ALERTOTHER)
-                               prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
-       }
-       
-       if (val == G_ALERTDEFAULT) {
-               gtk_drag_finish(drag_context, FALSE, FALSE, time);
-               return;
-       } else if (val == G_ALERTOTHER) {
-               compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
-               return;
-       } 
 
        /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
         * does not work */
        if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
+               AlertValue val = G_ALERTDEFAULT;
+
+               switch (prefs_common.compose_dnd_mode) {
+                       case COMPOSE_DND_ASK:
+                               val = alertpanel_full(_("Insert or attach?"),
+                                        _("Do you want to insert the contents of the file(s) "
+                                          "into the message body, or attach it to the email?"),
+                                         GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
+                                         TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
+                               break;
+                       case COMPOSE_DND_INSERT:
+                               val = G_ALERTALTERNATE;
+                               break;
+                       case COMPOSE_DND_ATTACH:
+                               val = G_ALERTOTHER;
+                               break;
+                       default:
+                               /* unexpected case */
+                               g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
+               }
+
+               if (val & G_ALERTDISABLE) {
+                       val &= ~G_ALERTDISABLE;
+                       /* remember what action to perform by default, only if we don't click Cancel */
+                       if (val == G_ALERTALTERNATE)
+                               prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
+                       else if (val == G_ALERTOTHER)
+                                       prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
+               }
+
+               if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
+                       gtk_drag_finish(drag_context, FALSE, FALSE, time);
+                       return;
+               } else if (val == G_ALERTOTHER) {
+                       compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
+                       return;
+               } 
                list = uri_list_extract_filenames((const gchar *)data->data);
                for (tmp = list; tmp != NULL; tmp = tmp->next) {
                        compose_insert_file(compose, (const gchar *)tmp->data);
diff --git a/tools/textviewer.pl b/tools/textviewer.pl
new file mode 100644 (file)
index 0000000..dcf2fd4
--- /dev/null
@@ -0,0 +1,129 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+sub usage ($;$)
+{
+    my ($err, $str) = (@_, "");
+    $err and select STDERR;
+    print
+       "usage: $0 [--html] [--type=<type>] file\n",
+       "       --html    Generate HTML (if supported)\n",
+       "       --type=X  X as mimetype (msword => doc)\n";
+    $str and print "$str\n";
+    exit $err;
+    } # usage
+
+@ARGV == 1 and $ARGV[0] eq "-?" || $ARGV[0] =~ m/^-+help$/ and usage (0);
+
+use Getopt::Long qw(:config bundling nopermute);
+my $opt_v = 0;
+my $opt_t;
+my $opt_h = "text";
+GetOptions (
+    "v|verbose:1"      => \$opt_v,
+    "t|type|mimetype=s"        => \$opt_t,
+    "h|html"           => sub { $opt_h = "html" },
+    ) or usage (1);
+
+$opt_v and print STDERR "$0 @ARGV\n";
+
+my $file = shift or usage (1, "File argument is missing");
+-f $file         or usage (1, "File argument is not a plain file");
+-r $file         or usage (1, "File argument is not a readable file");
+-s $file         or usage (1, "File argument is an empty file");
+
+# anon-list contains all possible commands to show content
+# plain text is a reference to same type (alias)
+# %f will be replaced with file. If no %f, file will be the last arg
+my %fh = (
+    text => {
+       bin     => [ "strings"          ], # fallback for binary files
+
+       txt     => [ "cat"              ], # Plain text
+
+       html    => [ "txt2htm",
+                    "text2html"        ], # HTML
+
+       msword  => "doc",
+       doc     => [ "antiword -w 72"   ], # M$ Word
+       "vnd.ms-excel" => "xls",
+       "ms-excel"     => "xls",
+       xls     => [ "xlscat -L"        ], # M$ Excel
+#      ppt     => [ "ppthtml"          ], # M$ PowerPoint
+#                      ppthtml "$1" | html2text
+
+       rtf     => [ "rtf2text",
+                    "unrtf -t text"    ], # RTF
+       pdf     => [ "pdftotext %f -"   ], # Adobe PDF
+
+       sxc     => "xls",                  # OpenOffice spreadsheet
+       odt     => [ "ooo2txt"          ], # OpenOffice writer
+
+       pl      => [ "perltidy -st -se",
+                    "cat"              ], # Perl
+       pm      => "pl",
+
+       ( map { $_ => "txt" } qw(
+           diff
+           c h ic ec cc
+           sh sed awk
+           plain
+           )),
+
+       test    => [ \&test             ], # Internal
+       },
+
+    html => {
+       rtf     => [ "rtf2html"         ],
+       },
+    );
+
+my $ext = $file =~ m/\.(\w+)$/ ? lc $1 : "";
+$opt_t && exists $fh{text}{lc $opt_t} and $ext = lc$opt_t;
+unless (exists $fh{text}{$ext}) {
+    my $ftype = `file --brief $file`;
+    $ext =
+       $ftype =~ m/^pdf doc/i                                  ? "pdf" :
+       $ftype =~ m/^ascii( english)? text/i                    ? "txt" :
+       $ftype =~ m/^(utf-8 unicode|iso-\d+)( english)? text/i  ? "txt" :
+       $ftype =~ m/^xml doc/i                                  ? "xml" :
+       $ftype =~ m/^\w+ compress/i                             ? "bin" :
+                                                                 "bin" ;
+    # \w+ archive
+    # \w+ image
+    # ...
+    }
+$ext ||= "txt";
+exists $fh{$opt_h}{$ext} or $opt_h = "text";
+exists $fh{$opt_h}{$ext} or $ext   = "txt";
+my          $ref = $fh{$opt_h}{$ext};
+ref $ref or $ref = $fh{$opt_h}{$ref};
+
+$opt_v and print STDERR "[ @$ref ] $file\n";
+
+sub which ($)
+{
+    (my $cmd = shift) =~ s/\s.*//; # Only the command. Discard arguments here
+    foreach my $path (split m/:+/, $ENV{PATH}) {
+       -x "$path/$cmd" and return "$path/$cmd";
+       }
+    return 0;
+    } # which
+
+my $cmd = "cat -ve";
+foreach my $c (@$ref) {
+    if (ref $c) {
+       $c->($file);
+       exit;
+       }
+
+    my $cp = which ($c) or next;
+    $cmd = $c;
+    last;
+    }
+
+$cmd =~ s/%f\b/$file/g or $cmd .= " $file";
+$opt_v and print STDERR "$cmd\n";
+exec $cmd;