2006-06-27 [ticho] 2.3.1cvs24
authorAndrej Kacian <ticho@claws-mail.org>
Tue, 27 Jun 2006 12:46:42 +0000 (12:46 +0000)
committerAndrej Kacian <ticho@claws-mail.org>
Tue, 27 Jun 2006 12:46:42 +0000 (12:46 +0000)
* src/prefs_account.c
* src/prefs_common.c
* src/prefs_common.h
* src/prefs_ext_prog.c
* src/textview.c
add a preference (Preferences/External programs)
to allow "Display as text" to be done via a script
(patch by H.Merijn Brand)

ChangeLog
PATCHSETS
configure.ac
src/prefs_account.c
src/prefs_common.c
src/prefs_common.h
src/prefs_ext_prog.c
src/textview.c

index 36c2222..9eba33a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-06-27 [ticho]     2.3.1cvs24
+
+       * src/prefs_account.c
+       * src/prefs_common.c
+       * src/prefs_common.h
+       * src/prefs_ext_prog.c
+       * src/textview.c
+       add a preference (Preferences/External programs)
+       to allow "Display as text" to be done via a script
+       (patch by H.Merijn Brand)
+
 2006-06-27 [paul]      2.3.1cvs23
 
        * src/mbox.c
index 3f7059d..3d76738 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.28.2.18 -r 1.28.2.19 src/mbox.c;  cvs diff -u -r 1.36.2.67 -r 1.36.2.68 src/common/utils.c;  cvs diff -u -r 1.5.2.30 -r 1.5.2.31 src/gtk/gtkutils.c;  ) > 2.3.1cvs21.patchset
 ( cvs diff -u -r 1.28.2.19 -r 1.28.2.20 src/mbox.c;  ) > 2.3.1cvs22.patchset
 ( 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
index 94a0259..d80da86 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=3
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=23
+EXTRA_VERSION=24
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index afa4c6e..66c959d 100644 (file)
@@ -54,6 +54,7 @@
 #include "imap.h"
 #include "remotefolder.h"
 #include "base64.h"
+#include "combobox.h"
 
 static gboolean cancelled;
 static gboolean new_account;
@@ -220,11 +221,10 @@ static struct Advanced {
        GtkWidget *trash_folder_entry;
 } advanced;
 
-static void prefs_account_fix_size                     (void);
-
 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam);
 static void prefs_account_protocol_set_optmenu         (PrefParam *pparam);
-static void prefs_account_protocol_activated           (GtkMenuItem *menuitem);
+static void prefs_account_protocol_activated           (GtkComboBox *combobox,
+                                                       gpointer data);
 
 static void prefs_account_set_string_from_optmenu      (PrefParam *pparam);
 static void prefs_account_set_optmenu_from_string      (PrefParam *pparam);
@@ -709,12 +709,6 @@ static void create_widget_func(PrefsPage * _page,
                        gtk_entry_set_text(GTK_ENTRY(basic.org_entry),
                                           def_ac->organization ? def_ac->organization : "");
                }
-               menu_set_sensitive_all
-                       (GTK_MENU_SHELL
-                               (gtk_option_menu_get_menu
-                                       (GTK_OPTION_MENU
-                                               (basic.protocol_optmenu))),
-                        TRUE);
        } else
                prefs_set_dialog(param);
 
@@ -1028,34 +1022,6 @@ static void prefs_account_create(void)
 #endif /* USE_OPENSSL */
        prefs_account_advanced_create();
        SET_NOTEBOOK_LABEL(notebook, _("A_dvanced"), page++);
-
-       prefs_account_fix_size();
-}
-
-/**
- * prefs_account_fix_size:
- * 
- * Fix the window size after creating widgets by selecting "Local"
- * protocol (currently it has the largest size of parameter widgets).
- * Without this the window gets too large.
- **/
-static void prefs_account_fix_size(void)
-{
-       GtkOptionMenu *optmenu = GTK_OPTION_MENU (basic.protocol_optmenu);
-       GtkWidget *menu;
-       GtkWidget *menuitem;
-
-       gtk_option_menu_set_history (optmenu, 4); /* local */
-       menu = gtk_option_menu_get_menu (optmenu);
-       menuitem = gtk_menu_get_active (GTK_MENU (menu));
-       gtk_menu_item_activate (GTK_MENU_ITEM (menuitem));
-}
-
-#define SET_ACTIVATE(menuitem) \
-{ \
-       g_signal_connect(G_OBJECT(menuitem), "activate", \
-                        G_CALLBACK(prefs_account_protocol_activated), \
-                        NULL); \
 }
 
 #define TABLE_YPAD 2
@@ -1076,8 +1042,7 @@ static void prefs_account_basic_create(void)
        GtkWidget *serv_frame;
        GtkWidget *vbox2;
        GtkWidget *optmenu;
-       GtkWidget *optmenu_menu;
-       GtkWidget *menuitem;
+       GtkListStore *optmenu_menu;
        GtkWidget *serv_table;
        GtkWidget *recvserv_label;
        GtkWidget *smtpserv_label;
@@ -1179,24 +1144,17 @@ static void prefs_account_basic_create(void)
        gtk_widget_show (label);
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
-       optmenu = gtk_option_menu_new ();
+       /* We will only create the combobox here, and we will fill it later in
+        * prefs_account_protocol_set_optmenu().
+        */
+       optmenu = gtkut_sc_combobox_create(NULL, FALSE);
        gtk_widget_show (optmenu);
        gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
 
-       optmenu_menu = gtk_menu_new ();
+       optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
 
-       MENUITEM_ADD (optmenu_menu, menuitem, _("POP3"),  A_POP3);
-       SET_ACTIVATE (menuitem);
-       MENUITEM_ADD (optmenu_menu, menuitem, _("IMAP4"), A_IMAP4);
-       SET_ACTIVATE (menuitem);
-       MENUITEM_ADD (optmenu_menu, menuitem, _("News (NNTP)"), A_NNTP);
-       SET_ACTIVATE (menuitem);
-       MENUITEM_ADD (optmenu_menu, menuitem, _("Local mbox file"), A_LOCAL);
-       SET_ACTIVATE (menuitem);
-       MENUITEM_ADD (optmenu_menu, menuitem, _("None (SMTP only)"), A_NONE);
-       SET_ACTIVATE (menuitem);
-
-       gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
+       g_signal_connect(G_OBJECT(optmenu), "changed",
+                       G_CALLBACK(prefs_account_protocol_activated), NULL);
 
        serv_table = gtk_table_new (6, 4, FALSE);
        gtk_widget_show (serv_table);
@@ -2481,15 +2439,10 @@ static void prefs_account_advanced_create(void)
 static gint prefs_account_apply(void)
 {
        RecvProtocol protocol;
-       GtkWidget *menu;
-       GtkWidget *menuitem;
        gchar *old_id = NULL;
        gchar *new_id = NULL;
        
-       menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(basic.protocol_optmenu));
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-       protocol = GPOINTER_TO_INT
-               (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
+       protocol = combobox_get_active_data(GTK_COMBO_BOX(basic.protocol_optmenu));
 
        if (*gtk_entry_get_text(GTK_ENTRY(basic.acname_entry)) == '\0') {
                alertpanel_error(_("Account name is not entered."));
@@ -2675,23 +2628,32 @@ static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam)
 static void prefs_account_protocol_set_optmenu(PrefParam *pparam)
 {
        RecvProtocol protocol;
-       GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
-       GtkWidget *menu;
-       GtkWidget *menuitem;
-       gint index;
+       GtkWidget *optmenu = *pparam->widget;
+       GtkListStore *menu;
+       GtkTreeIter iter;
 
        protocol = *((RecvProtocol *)pparam->data);
-       index = menu_find_option_menu_index
-               (optmenu, GINT_TO_POINTER(protocol), NULL);
-       if (index < 0) return;
-       gtk_option_menu_set_history(optmenu, index);
-
-       menu = gtk_option_menu_get_menu(optmenu);
-       menu_set_insensitive_all(GTK_MENU_SHELL(menu));
-
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-       gtk_widget_set_sensitive(menuitem, TRUE);
-       gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
+       menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
+
+       /* Clear all options and add them as necessary:
+        * - if we're creating a new account, add all of them
+        * - otherwise only add the correct one for this account
+        */
+       gtk_list_store_clear(menu);
+       if( new_account || protocol == A_POP3 )
+               COMBOBOX_ADD (menu, _("POP3"),  A_POP3);
+       if( new_account || protocol == A_IMAP4 )
+               COMBOBOX_ADD (menu, _("IMAP4"), A_IMAP4);
+       if( new_account || protocol == A_NNTP )
+               COMBOBOX_ADD (menu, _("News (NNTP)"), A_NNTP);
+       if( new_account || protocol == A_LOCAL )
+               COMBOBOX_ADD (menu, _("Local mbox file"), A_LOCAL);
+       if( new_account || protocol == A_NONE )
+               COMBOBOX_ADD (menu, _("None (SMTP only)"), A_NONE);
+
+       combobox_select_by_data(GTK_COMBO_BOX(optmenu), protocol);
+
+       gtk_widget_set_sensitive(optmenu, new_account);
 }
 
 static void prefs_account_imap_auth_type_set_data_from_optmenu(PrefParam *pparam)
@@ -2838,12 +2800,11 @@ static void prefs_account_set_optmenu_from_string(PrefParam *pparam)
        g_list_free(children);
 }
 
-static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
+static void prefs_account_protocol_activated(GtkComboBox *combobox, gpointer data)
 {
        RecvProtocol protocol;
 
-       protocol = GPOINTER_TO_INT
-               (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
+       protocol = combobox_get_active_data(combobox);
 
        switch(protocol) {
        case A_NNTP:
index 4d919f5..a519f0a 100644 (file)
@@ -111,10 +111,12 @@ static PrefParam param_os_specific[] = {
        /* MIME viewer */
        {"mime_image_viewer", NULL,
         &prefs_common.mime_image_viewer, P_STRING, NULL, NULL, NULL},
+       {"mime_textviewer", NULL,
+        &prefs_common.mime_textviewer,   P_STRING, NULL, NULL, NULL},
        {"mime_audio_player", NULL,
         &prefs_common.mime_audio_player, P_STRING, NULL, NULL, NULL},
        {"mime_open_command", "notepad '%s'",
-        &prefs_common.mime_open_cmd, P_STRING, NULL, NULL, NULL},
+        &prefs_common.mime_open_cmd,     P_STRING, NULL, NULL, NULL},
 
        /* Interface */
        {"pixmap_theme_path", DEFAULT_PIXMAP_THEME, 
@@ -583,11 +585,13 @@ static PrefParam param[] = {
 
        /* MIME viewer */
        {"mime_image_viewer", DEFAULT_IMAGE_VIEWER_CMD,
-        &SPECIFIC_PREFS.mime_image_viewer,     P_STRING, NULL, NULL, NULL},
+        &SPECIFIC_PREFS.mime_image_viewer, P_STRING, NULL, NULL, NULL},
+       {"mime_textviewer",   NULL,
+        &SPECIFIC_PREFS.mime_textviewer,   P_STRING, NULL, NULL, NULL},
        {"mime_audio_player", DEFAULT_AUDIO_PLAYER_CMD,
         &SPECIFIC_PREFS.mime_audio_player, P_STRING, NULL, NULL, NULL},
        {"mime_open_command", "gedit '%s'",
-        &SPECIFIC_PREFS.mime_open_cmd, P_STRING, NULL, NULL, NULL},
+        &SPECIFIC_PREFS.mime_open_cmd,     P_STRING, NULL, NULL, NULL},
 
        /* Interface */
        {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL,
index fbffd9e..95418f7 100644 (file)
@@ -279,6 +279,7 @@ struct _PrefsCommon
 
        /* MIME viewer */
        gchar *mime_image_viewer;
+       gchar *mime_textviewer;
        gchar *mime_audio_player;
        gchar *mime_open_cmd;
        gchar *attach_save_dir;
index 78930c2..f6d45eb 100644 (file)
@@ -59,6 +59,9 @@ typedef struct _ExtProgPage
 
        GtkWidget *image_viewer_label;
        GtkWidget *image_viewer_entry;
+       
+       GtkWidget *astextviewer_label;
+       GtkWidget *astextviewer_entry;
 
        GtkWidget *audio_player_label;
        GtkWidget *audio_player_entry;
@@ -83,6 +86,8 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
        GtkWidget *exteditor_entry;
        GtkWidget *image_viewer_label;
        GtkWidget *image_viewer_entry;
+       GtkWidget *astextviewer_label;
+       GtkWidget *astextviewer_entry;
        GtkWidget *audio_player_label;
        GtkWidget *audio_player_entry;
 
@@ -106,7 +111,7 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
        gtk_box_pack_start(GTK_BOX (vbox),
                           hint_label, FALSE, FALSE, 4);
 
-       table2 = gtk_table_new(5, 2, FALSE);
+       table2 = gtk_table_new(6, 2, FALSE);
        gtk_widget_show(table2);
        gtk_container_set_border_width(GTK_CONTAINER(table2), 8);
        gtk_table_set_row_spacings(GTK_TABLE(table2), 4);
@@ -206,10 +211,28 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
        gtk_entry_set_text(GTK_ENTRY(image_viewer_entry), 
                           prefs_common.mime_image_viewer ? prefs_common.mime_image_viewer : "");
 
+       astextviewer_label = gtk_label_new(_("View as text command"));
+       gtk_widget_show(astextviewer_label);
+
+       gtk_table_attach(GTK_TABLE (table2), astextviewer_label, 0, 1, 4, 5,
+                        (GtkAttachOptions) (GTK_FILL),
+                        (GtkAttachOptions) (0), 0, 2);
+       gtk_label_set_justify(GTK_LABEL (astextviewer_label), GTK_JUSTIFY_RIGHT);
+       gtk_misc_set_alignment(GTK_MISC (astextviewer_label), 1, 0.5);
+
+       astextviewer_entry = gtk_entry_new ();
+       gtk_widget_show(astextviewer_entry);
+       
+       gtk_table_attach(GTK_TABLE (table2), astextviewer_entry, 1, 2, 4, 5,
+                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+                        (GtkAttachOptions) (0), 0, 0);
+       gtk_entry_set_text(GTK_ENTRY(astextviewer_entry), 
+                          prefs_common.mime_textviewer ? prefs_common.mime_textviewer : "");
+
        audio_player_label = gtk_label_new (_("Audio player"));
        gtk_widget_show(audio_player_label);
 
-       gtk_table_attach(GTK_TABLE (table2), audio_player_label, 0, 1, 4, 5,
+       gtk_table_attach(GTK_TABLE (table2), audio_player_label, 0, 1, 5, 6,
                         (GtkAttachOptions) (GTK_FILL),
                         (GtkAttachOptions) (0), 0, 2);
        gtk_label_set_justify(GTK_LABEL (audio_player_label), GTK_JUSTIFY_RIGHT);
@@ -218,7 +241,7 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
        audio_player_entry = gtk_entry_new ();
        gtk_widget_show(audio_player_entry);
        
-       gtk_table_attach(GTK_TABLE (table2), audio_player_entry, 1, 2, 4, 5,
+       gtk_table_attach(GTK_TABLE (table2), audio_player_entry, 1, 2, 5, 6,
                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                         (GtkAttachOptions) (0), 0, 0);
        gtk_entry_set_text(GTK_ENTRY(audio_player_entry), 
@@ -229,6 +252,7 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
        prefs_ext_prog->printcmd_entry          = printcmd_entry;
        prefs_ext_prog->exteditor_entry         = exteditor_entry;
        prefs_ext_prog->image_viewer_entry      = image_viewer_entry;
+       prefs_ext_prog->astextviewer_entry      = astextviewer_entry;
        prefs_ext_prog->audio_player_entry      = audio_player_entry;
 
        prefs_ext_prog->page.widget = table;
@@ -246,6 +270,8 @@ void prefs_ext_prog_save(PrefsPage *_page)
                (GTK_EDITABLE(ext_prog->exteditor_entry), 0, -1);
        prefs_common.mime_image_viewer = gtk_editable_get_chars
                (GTK_EDITABLE(ext_prog->image_viewer_entry), 0, -1);
+       prefs_common.mime_textviewer = gtk_editable_get_chars
+               (GTK_EDITABLE(ext_prog->astextviewer_entry), 0, -1);
        prefs_common.mime_audio_player = gtk_editable_get_chars
                (GTK_EDITABLE(ext_prog->audio_player_entry), 0, -1);
 }
index e44716a..16d7fac 100644 (file)
@@ -34,6 +34,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
+#include <sys/wait.h>
 #if HAVE_LIBCOMPFACE
 #  include <compface.h>
 #endif
@@ -836,7 +837,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
        FILE *tmpfp;
        gchar buf[BUFFSIZE];
        CodeConverter *conv;
-       const gchar *charset;
+       const gchar *charset, *p, *cmd;
        
        if (textview->messageview->forced_charset)
                charset = textview->messageview->forced_charset;
@@ -876,7 +877,53 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        g_unlink(filename);
                }
                g_free(filename);
+       } else if ( g_ascii_strcasecmp(mimeinfo->subtype, "plain") &&
+                  (cmd = prefs_common.mime_textviewer) && *cmd &&
+                  (p = strchr(cmd, '%')) && *(p + 1) == 's') {
+               int pid, pfd[2];
+               const gchar *fname;
+
+               fname  = procmime_get_tmp_file_name(mimeinfo);
+               if (procmime_get_part(fname, mimeinfo)) goto textview_default;
+
+               g_snprintf(buf, sizeof(buf), cmd, fname);
+               debug_print("Viewing text content of type: %s (length: %d) "
+                       "using %s\n", mimeinfo->subtype, mimeinfo->length, buf);
+
+               if (pipe(pfd) < 0) {
+                       g_snprintf(buf, sizeof(buf),
+                               "pipe failed for textview\n\n%s\n", strerror(errno));
+                       textview_write_line(textview, buf, conv);
+                       goto textview_default;
+               }
+               pid = fork();
+               if (pid < 0) {
+                       g_snprintf(buf, sizeof(buf),
+                               "fork failed for textview\n\n%s\n", strerror(errno));
+                       textview_write_line(textview, buf, conv);
+                       close(pfd[0]);
+                       close(pfd[1]);
+                       goto textview_default;
+               }
+               if (pid == 0) { /* child */
+                       gchar **argv;
+                       argv = strsplit_with_quote(buf, " ", 0);
+                       close(1);
+                       close(pfd[0]);
+                       dup(pfd[1]);
+                       execvp(argv[0], argv);
+                       close(pfd[1]);
+                       exit(255);
+               }
+               close(pfd[1]);
+               tmpfp = fdopen(pfd[0], "rb");
+               while (fgets(buf, sizeof(buf), tmpfp))
+                       textview_write_line(textview, buf, conv);
+               fclose(tmpfp);
+               waitpid(pid, pfd, 0);
+               unlink(fname);
        } else {
+textview_default:
                tmpfp = g_fopen(mimeinfo->data.filename, "rb");
                fseek(tmpfp, mimeinfo->offset, SEEK_SET);
                debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);