0.8.11claws13
authorChristoph Hohmann <reboot@gmx.ch>
Fri, 14 Mar 2003 23:58:57 +0000 (23:58 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Fri, 14 Mar 2003 23:58:57 +0000 (23:58 +0000)
* src/imap.c
        don't query imap folder for attributes because we already
        for them from imap_status

* src/mimeview.[ch]
        add support for plugable MimeViewers (unloading Viewers
        not yet complete)

* src/plugins/Makefile.am
* src/plugins/mathml_viewer/.cvsignore          ** NEW **
* src/plugins/mathml_viewer/Makefile.am         ** NEW **
* src/plugins/mathml_viewer/mathml_viewer.c     ** NEW **
        add MathML Viewer (Content-Type text/mathml) using GtkMathView
        widget from http://helm.cs.unibo.it/mml-widget/

ChangeLog.claws
configure.ac
src/imap.c
src/mimeview.c
src/mimeview.h
src/plugins/Makefile.am
src/plugins/mathml_viewer/.cvsignore [new file with mode: 0644]
src/plugins/mathml_viewer/Makefile.am [new file with mode: 0644]
src/plugins/mathml_viewer/mathml_viewer.c [new file with mode: 0644]

index a07d243..8a2722c 100644 (file)
@@ -1,3 +1,20 @@
+2003-03-15 [christoph] 0.8.11claws13
+
+       * src/imap.c
+               don't query imap folder for attributes because we already
+               for them from imap_status
+
+       * src/mimeview.[ch]
+               add support for plugable MimeViewers (unloading Viewers
+               not yet complete)
+
+       * src/plugins/Makefile.am
+       * src/plugins/mathml_viewer/.cvsignore          ** NEW **
+       * src/plugins/mathml_viewer/Makefile.am         ** NEW **
+       * src/plugins/mathml_viewer/mathml_viewer.c     ** NEW **
+               add MathML Viewer (Content-Type text/mathml) using GtkMathView
+               widget from http://helm.cs.unibo.it/mml-widget/
+
 2003-03-14 [christoph] 0.8.11claws12
 
        * src/folder.[ch]
index ef7a126..f8931a9 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=11
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws12
+EXTRA_VERSION=claws13
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
@@ -395,6 +395,19 @@ if test x"$ac_cv_enable_spamassassin_plugin" = xyes; then
        AC_DEFINE(USE_SPAMASSASSIN, 1, Define if you use the SpamAssassin plugin)
 fi
 
+AC_ARG_ENABLE(mathml-viewer-plugin,
+       [  --enable-mathml-viewer-plugin    Build MarhML-Viewer plugin [default=no]],
+       [ac_cv_enable_mathml_viewer_plugin=$enableval], [ac_cv_enable_mathml-viewer_plugin=no])
+AM_CONDITIONAL(BUILD_MATHML_VIEWER_PLUGIN, test x"$ac_cv_enable_mathml_viewer_plugin" = xyes)
+if test x"$ac_cv_enable_mathml_viewer_plugin" = xyes; then
+       GTK_MATH_VIEW_CFLAGS=$( gtkmathview-config --cflags )
+       GTK_MATH_VIEW_LIBS=$( gtkmathview-config --libs )
+       AC_SUBST(GTK_MATH_VIEW_CFLAGS)
+       AC_SUBST(GTK_MATH_VIEW_LIBS)
+
+       PLUGINS="mathml-viewer $PLUGINS"
+fi
+
 dnl ****************************
 dnl ** Final configure output **
 dnl ****************************
@@ -413,6 +426,7 @@ src/gtk/Makefile
 src/plugins/Makefile
 src/plugins/demo/Makefile
 src/plugins/spamassassin/Makefile
+src/plugins/mathml_viewer/Makefile
 faq/Makefile
 faq/de/Makefile
 faq/en/Makefile
index 5eb74f2..70dda6b 100644 (file)
@@ -3350,7 +3350,7 @@ gint imap_get_num_list(Folder *folder, FolderItem *_item, GSList **msgnum_list)
        }
 
        ok = imap_select(session, IMAP_FOLDER(folder), item->item.path,
-                        &exists, &recent, &unseen, &uid_val);
+                        NULL, NULL, NULL, NULL);
        if (ok != IMAP_SUCCESS)
                return -1;
 
index 3a65ed1..d823ad1 100644 (file)
@@ -37,7 +37,8 @@
 #include <gtk/gtkselection.h>
 #include <stdio.h>
 #include <unistd.h>
-
+#include <fnmatch.h>
 #include "intl.h"
 #include "main.h"
 #include "mimeview.h"
@@ -128,6 +129,8 @@ static GtkTargetEntry mimeview_mime_types[] =
        {"text/uri-list", 0, 0}
 };
 
+GSList *mimeviewer_factories;
+
 MimeView *mimeview_create(void)
 {
        MimeView *mimeview;
@@ -346,6 +349,14 @@ void mimeview_show_message(MimeView *mimeview, MimeInfo *mimeinfo,
 
 void mimeview_destroy(MimeView *mimeview)
 {
+       GSList *cur;
+       
+       for (cur = mimeview->viewers; cur != NULL; cur = g_slist_next(cur)) {
+               MimeViewer *viewer = (MimeViewer *) cur->data;
+               viewer->destroy_viewer(viewer);
+       }
+       g_slist_free(mimeview->viewers);
+
        procmime_mimeinfo_free_all(mimeview->mimeinfo);
        g_free(mimeview->file);
        g_free(mimeview);
@@ -491,13 +502,66 @@ static void mimeview_show_image_part(MimeView *mimeview, MimeInfo *partinfo)
        g_free(filename);
 }
 
+static MimeViewer *get_viewer_for_content_type(MimeView *mimeview, const gchar *content_type)
+{
+       GSList *cur;
+       MimeViewerFactory *factory = NULL;
+       MimeViewer *viewer = NULL;
+       
+       for (cur = mimeviewer_factories; cur != NULL; cur = g_slist_next(cur)) {
+               MimeViewerFactory *curfactory = cur->data;
+
+               if(!fnmatch(curfactory->content_type, content_type, 0)) {
+                       factory = curfactory;
+                       break;
+               }
+       }
+       if (factory == NULL)
+               return NULL;
+
+       for (cur = mimeview->viewers; cur != NULL; cur = g_slist_next(cur)) {
+               MimeViewer *curviewer = cur->data;
+               
+               if (curviewer->factory == factory)
+                       return curviewer;
+       }
+       viewer = factory->create_viewer();
+       mimeview->viewers = g_slist_append(mimeview->viewers, viewer);
+
+       return viewer;
+}
+
+static gboolean mimeview_show_part(MimeView *mimeview, MimeInfo *partinfo)
+{
+       MimeViewer *viewer;
+       
+       viewer = get_viewer_for_content_type(mimeview, partinfo->content_type);
+       if (viewer == NULL) {
+               if (mimeview->mimeviewer != NULL)
+                       mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
+               mimeview->mimeviewer = NULL;
+               return FALSE;
+       }
+
+       if (mimeview->mimeviewer != viewer) {
+               if (mimeview->mimeviewer != NULL)
+                       mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
+               mimeview->mimeviewer = viewer;
+               mimeview_change_view_type(mimeview, MIMEVIEW_VIEWER);
+       }
+       viewer->show_mimepart(viewer, mimeview->file, partinfo);
+
+       return TRUE;
+}
+
 static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
 {
        TextView  *textview  = mimeview->textview;
        ImageView *imageview = mimeview->imageview;
        GList *children;
 
-       if (mimeview->type == type) return;
+       if ((mimeview->type != MIMEVIEW_VIEWER) && 
+           (mimeview->type == type)) return;
 
        children = gtk_container_children(GTK_CONTAINER(mimeview->mime_vbox));
        if (children) {
@@ -515,6 +579,10 @@ static void mimeview_change_view_type(MimeView *mimeview, MimeViewType type)
                gtk_container_add(GTK_CONTAINER(mimeview->mime_vbox),
                                  GTK_WIDGET_PTR(textview));
                break;
+       case MIMEVIEW_VIEWER:
+               gtk_container_add(GTK_CONTAINER(mimeview->mime_vbox),
+                                 GTK_WIDGET(mimeview->mimeviewer->get_widget(mimeview->mimeviewer)));
+               break;
        default:
                return;
        }
@@ -532,6 +600,8 @@ static void mimeview_clear(MimeView *mimeview)
        gtk_clist_clear(clist);
        textview_clear(mimeview->textview);
        imageview_clear(mimeview->imageview);
+       if (mimeview->mimeviewer != NULL)
+               mimeview->mimeviewer->clear_viewer(mimeview->mimeviewer);
 
        mimeview->opened = NULL;
 
@@ -562,38 +632,40 @@ static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
        
        mimeview->textview->default_text = FALSE;
        
-       switch (partinfo->mime_type) {
-       case MIME_TEXT:
-       case MIME_TEXT_HTML:
-       case MIME_TEXT_ENRICHED:
-       case MIME_MESSAGE_RFC822:
-       case MIME_MULTIPART:
-               mimeview_show_message_part(mimeview, partinfo);
+       if (!mimeview_show_part(mimeview, partinfo)) {
+               switch (partinfo->mime_type) {
+               case MIME_TEXT:
+               case MIME_TEXT_HTML:
+               case MIME_TEXT_ENRICHED:
+               case MIME_MESSAGE_RFC822:
+               case MIME_MULTIPART:
+                       mimeview_show_message_part(mimeview, partinfo);
                
-               break;
+                       break;
 #if (HAVE_GDK_PIXBUF || HAVE_GDK_IMLIB)
-       case MIME_IMAGE:
-               mimeview->textview->default_text = TRUE;        
-               if (prefs_common.display_img)
-                       mimeview_show_image_part(mimeview, partinfo);
-               else {
-                       mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
-                       textview_show_mime_part(mimeview->textview, partinfo);
-               }
-               break;
+               case MIME_IMAGE:
+                       mimeview->textview->default_text = TRUE;        
+                       if (prefs_common.display_img)
+                               mimeview_show_image_part(mimeview, partinfo);
+                       else {
+                               mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
+                               textview_show_mime_part(mimeview->textview, partinfo);
+                       }
+                       break;
 #endif
-       default:
-               mimeview->textview->default_text = TRUE;        
-               mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
+               default:
+                       mimeview->textview->default_text = TRUE;        
+                       mimeview_change_view_type(mimeview, MIMEVIEW_TEXT);
 #if USE_GPGME
-               if (g_strcasecmp(partinfo->content_type,
-                                "application/pgp-signature") == 0)
-                       textview_show_signature_part(mimeview->textview,
-                                                    partinfo);
-               else
+                       if (g_strcasecmp(partinfo->content_type,
+                                        "application/pgp-signature") == 0)
+                               textview_show_signature_part(mimeview->textview,
+                                                            partinfo);
+                       else
 #endif
-                       textview_show_mime_part(mimeview->textview, partinfo);
-               break;
+                               textview_show_mime_part(mimeview->textview, partinfo);
+                       break;
+               }
        }
 }
 
@@ -1111,3 +1183,13 @@ void mimeview_check_signature(MimeView *mimeview)
                              mimeview->file);
 }
 #endif /* USE_GPGME */
+
+void mimeview_register_viewer_factory(MimeViewerFactory *factory)
+{
+       mimeviewer_factories = g_slist_append(mimeviewer_factories, factory);
+}
+
+void mimeview_unregister_viewer_factory(MimeViewerFactory *factory)
+{
+       mimeviewer_factories = g_slist_remove(mimeviewer_factories, factory);
+}
index b128b0a..46d89d2 100644 (file)
@@ -25,7 +25,9 @@
 #include <gtk/gtkwidget.h>
 #include <gtk/gtkctree.h>
 
-typedef struct _MimeView       MimeView;
+typedef struct _MimeView               MimeView;
+typedef struct _MimeViewerFactory      MimeViewerFactory;
+typedef struct _MimeViewer             MimeViewer;
 
 #include "textview.h"
 #include "imageview.h"
@@ -35,7 +37,8 @@ typedef struct _MimeView      MimeView;
 typedef enum
 {
        MIMEVIEW_TEXT,
-       MIMEVIEW_IMAGE
+       MIMEVIEW_IMAGE,
+       MIMEVIEW_VIEWER,
 } MimeViewType;
 
 struct _MimeView
@@ -57,12 +60,33 @@ struct _MimeView
 
        TextView *textview;
        ImageView *imageview;
+       MimeViewer *mimeviewer;
 
        MessageView *messageview;
 
        MimeInfo *mimeinfo;
 
        gchar *file;
+
+       GSList *viewers;
+};
+
+struct _MimeViewerFactory
+{
+       gchar *content_type;
+       gint priority;
+       
+       MimeViewer *(*create_viewer) ();
+};
+
+struct _MimeViewer
+{
+       MimeViewerFactory *factory;
+    
+       GtkWidget       *(*get_widget)          (MimeViewer *);
+       void            (*show_mimepart)        (MimeViewer *, const gchar *infile, MimeInfo *);
+       void            (*clear_viewer)         (MimeViewer *);
+       void            (*destroy_viewer)       (MimeViewer *);
 };
 
 MimeView *mimeview_create      (void);
@@ -78,4 +102,7 @@ void mimeview_check_signature        (MimeView       *mimeview);
 void mimeview_pass_key_press_event     (MimeView       *mimeview,
                                         GdkEventKey    *event);
 
+void mimeview_register_viewer_factory  (MimeViewerFactory *factory);
+void mimeview_unregister_viewer_factory        (MimeViewerFactory *factory);
+
 #endif /* __MIMEVIEW_H__ */
index ca47eb0..a6efe3b 100644 (file)
@@ -1,10 +1,14 @@
 if BUILD_DEMO_PLUGIN
-demodir = demo
+demo_dir = demo
 endif
 
 if BUILD_SPAMASSASSIN_PLUGIN
-spamassasssindir = spamassassin
+spamassasssin_dir = spamassassin
 endif
 
-SUBDIRS = $(demodir) $(spamassasssindir)
+if BUILD_MATHML_VIEWER_PLUGIN
+mathml_viewer_dir = mathml_viewer
+endif
+
+SUBDIRS = $(demo_dir) $(spamassasssin_dir) $(mathml_viewer_dir)
 
diff --git a/src/plugins/mathml_viewer/.cvsignore b/src/plugins/mathml_viewer/.cvsignore
new file mode 100644 (file)
index 0000000..9887868
--- /dev/null
@@ -0,0 +1,7 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.o
+*.la
+*.lo
\ No newline at end of file
diff --git a/src/plugins/mathml_viewer/Makefile.am b/src/plugins/mathml_viewer/Makefile.am
new file mode 100644 (file)
index 0000000..256661a
--- /dev/null
@@ -0,0 +1,22 @@
+plugindir = $(pkglibdir)/plugins
+
+plugin_LTLIBRARIES = mathml_viewer.la
+
+mathml_viewer_la_SOURCES = \
+       mathml_viewer.c
+
+mathml_viewer_la_LDFLAGS = \
+       -avoid-version -module \
+       $(GTK_LIBS) \
+       $(GTK_MATH_VIEW_LIBS)
+
+INCLUDES = \
+       -I../.. \
+       -I../../common \
+       -I../../gtk
+
+CPPFLAGS = \
+       $(ASPELL_CFLAGS) \
+       $(GLIB_CFLAGS) \
+       $(GTK_CFLAGS) \
+       $(GTK_MATH_VIEW_CFLAGS)
diff --git a/src/plugins/mathml_viewer/mathml_viewer.c b/src/plugins/mathml_viewer/mathml_viewer.c
new file mode 100644 (file)
index 0000000..acd2226
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto and the Sylpheed-Claws Team
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <unistd.h>
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gtkmathview/gtkmathview.h>
+
+#include "common/plugin.h"
+#include "common/utils.h"
+#include "mimeview.h"
+
+typedef struct _MathMLViewer MathMLViewer;
+
+struct _MathMLViewer
+{
+       MimeViewer mimeviewer;
+       
+       GtkScrolledWindow       *scrollwin;;
+       GtkMathView             *mathview;
+       gchar                   *filename;
+};
+
+static MimeViewerFactory mathml_viewer_factory;
+
+static GtkWidget *mathml_get_widget(MimeViewer *_viewer)
+{
+       MathMLViewer *viewer = (MathMLViewer *) _viewer;
+
+       debug_print("mathml_get_widget\n");
+
+       return GTK_WIDGET(viewer->scrollwin);
+}
+
+static void mathml_show_mimepart(MimeViewer *_viewer, const gchar *infile, MimeInfo *partinfo)
+{
+       MathMLViewer *viewer = (MathMLViewer *) _viewer;
+
+       debug_print("mathml_show_mimepart\n");
+
+       if (viewer->filename != NULL) {
+               unlink(viewer->filename);
+               g_free(viewer->filename);
+       }
+
+       viewer->filename = procmime_get_tmp_file_name(partinfo);
+       
+       if (!(procmime_get_part(viewer->filename, infile, partinfo) < 0)) {
+               gchar *uri;
+               
+               uri = g_strconcat("file://", viewer->filename, NULL);
+               gtk_math_view_load_uri(GTK_MATH_VIEW(viewer->mathview), uri);
+               g_free(uri);
+       }
+}
+
+static void mathml_clear_viewer(MimeViewer *_viewer)
+{
+       MathMLViewer *viewer = (MathMLViewer *) _viewer;
+
+       debug_print("mathml_clear_viewer\n");
+
+       gtk_math_view_unload(viewer->mathview);
+}
+
+static void mathml_destroy_viewer(MimeViewer *_viewer)
+{
+       MathMLViewer *viewer = (MathMLViewer *) _viewer;
+
+       debug_print("mathml_destroy_viewer\n");
+
+       gtk_widget_unref(GTK_WIDGET(viewer->scrollwin));
+       unlink(viewer->filename);
+       g_free(viewer->filename);
+       g_free(viewer);
+}
+
+static MimeViewer *mathml_viewer_create()
+{
+       MathMLViewer *viewer;
+
+       debug_print("mathml_viewer_create\n");
+       
+       viewer = g_new0(MathMLViewer, 1);
+       viewer->mimeviewer.factory = &mathml_viewer_factory;
+
+       viewer->mimeviewer.get_widget = mathml_get_widget;
+       viewer->mimeviewer.show_mimepart = mathml_show_mimepart;
+       viewer->mimeviewer.clear_viewer = mathml_clear_viewer;
+       viewer->mimeviewer.destroy_viewer = mathml_destroy_viewer;      
+
+       viewer->scrollwin = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
+       gtk_widget_show(GTK_WIDGET(viewer->scrollwin));
+       gtk_widget_ref(GTK_WIDGET(viewer->scrollwin));
+       gtk_scrolled_window_set_policy(viewer->scrollwin, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+       viewer->mathview = GTK_MATH_VIEW(gtk_math_view_new(NULL, NULL));
+       gtk_widget_show(GTK_WIDGET(viewer->mathview));
+       viewer->filename = NULL;
+       gtk_container_add(GTK_CONTAINER(viewer->scrollwin), GTK_WIDGET(viewer->mathview));
+
+       return (MimeViewer *) viewer;
+}
+
+static MimeViewerFactory mathml_viewer_factory =
+{
+       "text/mathml",
+       0,
+       
+       mathml_viewer_create,
+};
+
+gint plugin_init(gchar **error)
+{
+       mimeview_register_viewer_factory(&mathml_viewer_factory);
+       return 0;       
+}
+
+void plugin_done()
+{
+}
+
+const gchar *plugin_name()
+{
+       return "MathML Viewer";
+}
+
+const gchar *plugin_desc()
+{
+       return "";
+}