New: Dillo plugin preferences (patch by Dimitar Haralanov)
authorMelvin Hadasht <melvin.hadasht@free.fr>
Wed, 30 Apr 2003 14:57:20 +0000 (14:57 +0000)
committerMelvin Hadasht <melvin.hadasht@free.fr>
Wed, 30 Apr 2003 14:57:20 +0000 (14:57 +0000)
* src/plugins/dillo_viewer/dillo_prefs.[ch] *** NEW ***
Preferences for the dillo plugin
* src/plugins/dillo_viewer/dillo_viewer.c
Support for preferences
* src/plugins/dillo_viewer/Makefile.am
Added dillo_prefs.[ch]

ChangeLog.claws
configure.ac
src/plugins/dillo_viewer/Makefile.am
src/plugins/dillo_viewer/dillo_prefs.c [new file with mode: 0644]
src/plugins/dillo_viewer/dillo_prefs.h [new file with mode: 0644]
src/plugins/dillo_viewer/dillo_viewer.c

index 59eb7be98ec9766e0fdbb099933ef612c11ecb69..5ccf69070148d35391ff70c7a959c42069ab8851 100644 (file)
@@ -1,3 +1,14 @@
+2003-04-30 [melvin]    0.8.11claws132
+
+       New: Dillo plugin preferences (patch by Dimitar Haralanov)
+
+       * src/plugins/dillo_viewer/dillo_prefs.[ch]     *** NEW ***
+               Preferences for the dillo plugin
+       * src/plugins/dillo_viewer/dillo_viewer.c
+               Support for preferences
+       * src/plugins/dillo_viewer/Makefile.am
+               Added dillo_prefs.[ch]
+
 2003-04-30 [alfons]    0.8.11claws131
 
        * src/common/plugin.[ch]
 2003-04-30 [alfons]    0.8.11claws131
 
        * src/common/plugin.[ch]
index 37251be8e9feeaafea2a0dbff190dafa64c23be1..f7afdb56bfb45824a74a9ed10013de5ef90de572 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=11
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=11
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws131
+EXTRA_VERSION=claws132
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index cbe1c84e34925215398091662a8bc6bc4819e494..41ac79cd48a77d1be2fe7ce1d61632551591f178 100644 (file)
@@ -3,7 +3,8 @@ plugindir = $(pkglibdir)/plugins
 plugin_LTLIBRARIES = dillo_viewer.la
 
 dillo_viewer_la_SOURCES = \
 plugin_LTLIBRARIES = dillo_viewer.la
 
 dillo_viewer_la_SOURCES = \
-       dillo_viewer.c
+         dillo_viewer.c \
+         dillo_prefs.c
 
 dillo_viewer_la_LDFLAGS = \
        -avoid-version -module \
 
 dillo_viewer_la_LDFLAGS = \
        -avoid-version -module \
diff --git a/src/plugins/dillo_viewer/dillo_prefs.c b/src/plugins/dillo_viewer/dillo_prefs.c
new file mode 100644 (file)
index 0000000..b432fa2
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * 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.
+ */
+
+/*
+ * The structure of this file has been borrowed from the structure of
+ * the image_viewer plugin file. I also used it as an example of how to
+ * build the preferences for the dillo plugin.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "intl.h"
+#include "common/utils.h"
+#include "prefs.h"
+#include "prefs_gtk.h"
+#include "prefswindow.h"
+
+#include "dillo_prefs.h"
+
+#define PREFS_BLOCK_NAME "Dillo"
+
+DilloBrowserPrefs_t dillo_prefs;
+
+typedef struct _DilloBrowserPage DilloBrowserPage_t;
+
+struct _DilloBrowserPage {
+        PrefsPage page;
+        GtkWidget *local;
+        GtkWidget *full;
+};
+
+static PrefParam param[] = {
+        {"local_browse", "TRUE", &dillo_prefs.local, P_BOOL, NULL, NULL, NULL},
+        {"full_window", "TRUE", &dillo_prefs.full, P_BOOL, NULL, NULL, NULL},
+        {0,0,0,0,0,0,0}
+};
+
+DilloBrowserPage_t prefs_page;
+
+static void create_dillo_prefs_page    (PrefsPage *, GtkWindow *, gpointer);
+static void destroy_dillo_prefs_page   (PrefsPage *);
+static void save_dillo_prefs           (PrefsPage *);
+
+void dillo_prefs_init(void)
+{
+        prefs_set_default(param);
+        prefs_read_config(param, PREFS_BLOCK_NAME, COMMON_RC);
+        
+        prefs_page.page.path = "Message View/Dillo Browser";
+        prefs_page.page.create_widget = create_dillo_prefs_page;
+        prefs_page.page.destroy_widget = destroy_dillo_prefs_page;
+        prefs_page.page.save_page = save_dillo_prefs;
+        
+        prefs_gtk_register_page((PrefsPage *) &prefs_page);
+}
+
+void dillo_prefs_done(void)
+{
+        prefs_gtk_unregister_page((PrefsPage *) &prefs_page);
+}
+
+static void create_dillo_prefs_page(PrefsPage *page,
+                                   GtkWindow *window,
+                                    gpointer data)
+{
+        DilloBrowserPage_t *prefs_page = (DilloBrowserPage_t *) page;
+
+        GtkWidget *vbox;
+        GtkWidget *local_checkbox;
+        GtkWidget *full_checkbox;
+        GtkWidget *label;
+
+        vbox = gtk_vbox_new(FALSE, 3);
+        gtk_widget_ref(vbox);
+        gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
+        gtk_widget_show(vbox);
+        
+        local_checkbox = gtk_check_button_new_with_label
+                               ("Don't Follow Links in Mails");
+        gtk_widget_ref(local_checkbox);
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(local_checkbox),
+                                     dillo_prefs.local);
+        gtk_box_pack_start(GTK_BOX(vbox), local_checkbox, FALSE, FALSE, 0);
+        gtk_widget_show(local_checkbox);
+        
+       label = gtk_label_new("(You can always allow following links\n"
+                             "by reloading the page)");
+        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+        gtk_widget_show(label);
+
+        full_checkbox = gtk_check_button_new_with_label("Full Screen Mode");
+        gtk_widget_ref(full_checkbox);
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(full_checkbox),
+                                      dillo_prefs.full);
+        gtk_box_pack_start(GTK_BOX(vbox), full_checkbox, FALSE, FALSE, 0);
+        gtk_widget_show(full_checkbox);
+        
+        prefs_page->local = local_checkbox;
+        prefs_page->full = full_checkbox;
+        prefs_page->page.widget = vbox;
+}
+
+static void destroy_dillo_prefs_page(PrefsPage *page)
+{
+        DilloBrowserPage_t *prefs_page = (DilloBrowserPage_t *) page;
+
+        gtk_widget_destroy(GTK_WIDGET(prefs_page->local));
+        gtk_widget_destroy(GTK_WIDGET(prefs_page->full));
+        gtk_widget_destroy(GTK_WIDGET(prefs_page->page.widget));
+}
+
+static void save_dillo_prefs(PrefsPage *page)
+{
+        DilloBrowserPage_t *prefs_page = (DilloBrowserPage_t *) page;
+        PrefFile *pref_file;
+        gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                                          COMMON_RC, NULL);
+        
+        dillo_prefs.local = gtk_toggle_button_get_active
+                               (GTK_TOGGLE_BUTTON(prefs_page->local));
+        dillo_prefs.full = gtk_toggle_button_get_active
+                               (GTK_TOGGLE_BUTTON(prefs_page->full));
+        
+        pref_file = prefs_write_open(rc_file_path);
+        g_free(rc_file_path);
+        
+        if (!(pref_file) ||
+           (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0))
+          return;
+        
+        if (prefs_write_param(param, pref_file->fp) < 0) {
+          g_warning("failed to write Dillo Plugin configuration\n");
+          prefs_file_close_revert(pref_file);
+          return;
+        }
+        fprintf(pref_file->fp, "\n");
+        prefs_file_close(pref_file);
+}
diff --git a/src/plugins/dillo_viewer/dillo_prefs.h b/src/plugins/dillo_viewer/dillo_prefs.h
new file mode 100644 (file)
index 0000000..5a90a93
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+/*
+ * The structure of this file has been borrowed from the structure of
+ * the image_viewer plugin file. I also used it as an example of how to
+ * build the preferences for the dillo plugin.
+ */
+
+#ifndef DILLORPREFS_H
+#define DILLOPREFS_H
+
+#include <glib.h>
+
+typedef struct _DilloBrowserPrefs DilloBrowserPrefs_t;
+
+struct _DilloBrowserPrefs
+{
+        gboolean        local;   // local browsing
+        gboolean        full;    // use full window
+};
+
+extern DilloBrowserPrefs_t dillo_prefs;
+
+void dillo_prefs_init();
+void dillo_prefs_done();
+
+#endif
index a166bd4c6a9f5a8d48400d0ecd3d933f5ab8e73a..4719ff51fdcae288c3b07e169049ac7165843062 100644 (file)
@@ -27,6 +27,8 @@
 #include "common/utils.h"
 #include "mimeview.h"
 
 #include "common/utils.h"
 #include "mimeview.h"
 
+#include "dillo_prefs.h"
+
 typedef struct _dilloViewer dilloViewer;
 
 struct _dilloViewer
 typedef struct _dilloViewer dilloViewer;
 
 struct _dilloViewer
@@ -34,7 +36,7 @@ struct _dilloViewer
        MimeViewer       mimeviewer;
        GtkWidget       *widget;        
        GtkWidget       *socket;
        MimeViewer       mimeviewer;
        GtkWidget       *widget;        
        GtkWidget       *socket;
-       gchar           *filename;
+       gchar           *filename;
 };
 
 static MimeViewerFactory dillo_viewer_factory;
 };
 
 static MimeViewerFactory dillo_viewer_factory;
@@ -56,7 +58,9 @@ static gboolean socket_destroy_cb(GtkObject *object, gpointer data)
        return FALSE;
 }
 
        return FALSE;
 }
 
-static void dillo_show_mimepart(MimeViewer *_viewer, const gchar *infile, MimeInfo *partinfo)
+static void dillo_show_mimepart(MimeViewer *_viewer,
+                               const gchar *infile,
+                               MimeInfo *partinfo)
 {
        dilloViewer *viewer = (dilloViewer *) _viewer;
 
 {
        dilloViewer *viewer = (dilloViewer *) _viewer;
 
@@ -71,6 +75,7 @@ static void dillo_show_mimepart(MimeViewer *_viewer, const gchar *infile, MimeIn
        
        if (!(procmime_get_part(viewer->filename, infile, partinfo) < 0)) {
                gchar *cmd;
        
        if (!(procmime_get_part(viewer->filename, infile, partinfo) < 0)) {
                gchar *cmd;
+
                if (viewer->socket)
                        gtk_widget_destroy(viewer->socket);
                viewer->socket = gtk_socket_new();
                if (viewer->socket)
                        gtk_widget_destroy(viewer->socket);
                viewer->socket = gtk_socket_new();
@@ -83,9 +88,13 @@ static void dillo_show_mimepart(MimeViewer *_viewer, const gchar *infile, MimeIn
                                   "destroy", 
                                   GTK_SIGNAL_FUNC(socket_destroy_cb),
                                   viewer);
                                   "destroy", 
                                   GTK_SIGNAL_FUNC(socket_destroy_cb),
                                   viewer);
-               cmd = g_strdup_printf("dillo -f -l -x %d \"%s\"", 
-                               (gint) GDK_WINDOW_XWINDOW(viewer->socket->window),
-                               viewer->filename);
+
+               cmd = g_strdup_printf("dillo %s%s-x %d \"%s\"",
+                                     (dillo_prefs.local ? "-l " : ""),
+                                     (dillo_prefs.full ? "-f " : ""),
+                                     (gint) GDK_WINDOW_XWINDOW(viewer->socket->window),
+                                     viewer->filename);
+
                execute_command_line(cmd, TRUE);
                g_free(cmd);
        }
                execute_command_line(cmd, TRUE);
                g_free(cmd);
        }
@@ -94,12 +103,13 @@ static void dillo_show_mimepart(MimeViewer *_viewer, const gchar *infile, MimeIn
 static void dillo_clear_viewer(MimeViewer *_viewer)
 {
        dilloViewer *viewer = (dilloViewer *) _viewer;
 static void dillo_clear_viewer(MimeViewer *_viewer)
 {
        dilloViewer *viewer = (dilloViewer *) _viewer;
+
        debug_print("dillo_clear_viewer\n");
        debug_print("Removing dillo socket %p\n", viewer->socket);
        debug_print("dillo_clear_viewer\n");
        debug_print("Removing dillo socket %p\n", viewer->socket);
+
        if (viewer->socket) {
                gtk_widget_destroy(viewer->socket);
        }
        if (viewer->socket) {
                gtk_widget_destroy(viewer->socket);
        }
-               
 }
 
 static void dillo_destroy_viewer(MimeViewer *_viewer)
 }
 
 static void dillo_destroy_viewer(MimeViewer *_viewer)
@@ -114,7 +124,7 @@ static void dillo_destroy_viewer(MimeViewer *_viewer)
        g_free(viewer);
 }
 
        g_free(viewer);
 }
 
-static MimeViewer *dillo_viewer_create()
+static MimeViewer *dillo_viewer_create(void)
 {
        dilloViewer *viewer;
 
 {
        dilloViewer *viewer;
 
@@ -122,13 +132,12 @@ static MimeViewer *dillo_viewer_create()
        
        viewer = g_new0(dilloViewer, 1);
        viewer->mimeviewer.factory = &dillo_viewer_factory;
        
        viewer = g_new0(dilloViewer, 1);
        viewer->mimeviewer.factory = &dillo_viewer_factory;
-
        viewer->mimeviewer.get_widget = dillo_get_widget;
        viewer->mimeviewer.show_mimepart = dillo_show_mimepart;
        viewer->mimeviewer.clear_viewer = dillo_clear_viewer;
        viewer->mimeviewer.destroy_viewer = dillo_destroy_viewer;       
        viewer->mimeviewer.get_widget = dillo_get_widget;
        viewer->mimeviewer.show_mimepart = dillo_show_mimepart;
        viewer->mimeviewer.clear_viewer = dillo_clear_viewer;
        viewer->mimeviewer.destroy_viewer = dillo_destroy_viewer;       
-
        viewer->widget = gtk_event_box_new();
        viewer->widget = gtk_event_box_new();
+
        gtk_widget_show(viewer->widget);
        gtk_widget_ref(viewer->widget);
 
        gtk_widget_show(viewer->widget);
        gtk_widget_ref(viewer->widget);
 
@@ -141,19 +150,24 @@ static MimeViewerFactory dillo_viewer_factory =
 {
        "text/html",
        0,
 {
        "text/html",
        0,
-       
-       dillo_viewer_create,
+
+       dillo_viewer_create
 };
 
 gint plugin_init(gchar **error)
 {
 };
 
 gint plugin_init(gchar **error)
 {
+        dillo_prefs_init();
+
        mimeview_register_viewer_factory(&dillo_viewer_factory);
        mimeview_register_viewer_factory(&dillo_viewer_factory);
+
        return 0;       
 }
 
 void plugin_done(void)
 {
        mimeview_unregister_viewer_factory(&dillo_viewer_factory);
        return 0;       
 }
 
 void plugin_done(void)
 {
        mimeview_unregister_viewer_factory(&dillo_viewer_factory);
+
+        dillo_prefs_done();
 }
 
 const gchar *plugin_name(void)
 }
 
 const gchar *plugin_name(void)