Hi all,
first I want to thank you for the great work on porting the rendering engine from Gecko to WebKit! I've never tried Epiphany with WebKit, before updating to Ubuntu Karmic Koala yesterday, so now I'm surprised how stable, fast and especially with way less memory usage it works. However I was disappointed that all the python plugins don't work anymore. One plugin I definitely cannot live without is the Session Manager. So after a night of coding, I've finally ported Simon Ward's Python version of the plugin, which I took from here: http://projects.bleah.co.uk/misc/browser/epiphany-session-manager to C. It looks like it works as well as the Python version; there is no difference in functionality. I've attached my patch that I've written against the current HEAD branch. I would be very happy if you applied the patch, so that in future more people than just me could easily use the extension. Please tell me if you have any criticism, questions or ideas on it! With kind regards, Klaus
>From cc6c988d6644c09aece3490c25c3767931820571 Mon Sep 17 00:00:00 2001 From: Klaus Trainer <klaus.trai...@web.de> Date: Tue, 3 Nov 2009 02:51:21 +0100 Subject: [PATCH] Ported Simon Ward's Session Manager extension from Python to C. --- configure.ac | 7 +- extensions/session-manager/Makefile.am | 38 +++ .../ephy-session-manager-extension.c | 260 ++++++++++++++++++++ .../ephy-session-manager-extension.h | 56 +++++ extensions/session-manager/extension.c | 44 ++++ .../session-manager.ephy-extension.in.in | 10 + 6 files changed, 412 insertions(+), 3 deletions(-) create mode 100644 extensions/session-manager/Makefile.am create mode 100644 extensions/session-manager/ephy-session-manager-extension.c create mode 100644 extensions/session-manager/ephy-session-manager-extension.h create mode 100644 extensions/session-manager/extension.c create mode 100644 extensions/session-manager/session-manager.ephy-extension.in.in diff --git a/configure.ac b/configure.ac index 6348370..4e192e4 100644 --- a/configure.ac +++ b/configure.ac @@ -171,8 +171,8 @@ AM_CONDITIONAL([HAVE_OPENSP],[test "x$enable_opensp" = "xyes"]) AC_MSG_CHECKING([which extensions to build]) -ALL_EXTENSIONS="actions adblock auto-reload auto-scroller certificates error-viewer extensions-manager-ui gestures greasemonkey java-console livehttpheaders page-info permissions push-scroller rss sample select-stylesheet sidebar smart-bookmarks soup-fly tab-groups tab-states" -USEFUL_EXTENSIONS="actions adblock auto-reload auto-scroller certificates error-viewer extensions-manager-ui java-console page-info push-scroller select-stylesheet smart-bookmarks soup-fly tab-groups tab-states" +ALL_EXTENSIONS="actions adblock auto-reload auto-scroller certificates error-viewer extensions-manager-ui gestures greasemonkey java-console livehttpheaders page-info permissions push-scroller rss sample select-stylesheet sidebar smart-bookmarks soup-fly tab-groups tab-states session-manager" +USEFUL_EXTENSIONS="actions adblock auto-reload auto-scroller certificates error-viewer extensions-manager-ui java-console page-info push-scroller select-stylesheet smart-bookmarks soup-fly tab-groups tab-states session-manager" DEFAULT_EXTENSIONS="actions adblock auto-scroller certificates error-viewer extensions-manager-ui java-console page-info push-scroller select-stylesheet smart-bookmarks soup-fly tab-groups tab-states greasemonkey" MOZILLA_ALL_EXTENSIONS="error-viewer java-console livehttpheaders page-info select-stylesheet smart-bookmarks" @@ -190,7 +190,7 @@ AC_ARG_WITH([extensions], certificates, error-viewer, extensions-manager-ui, gestures, greasemonkey, java-console, livehttpheaders, page-info, permissions, push-scroller, rss, sample, - select-stylesheet, sidebar, + select-stylesheet, session-manager, sidebar, smart-bookmarks, soup-fly, tab-groups, tab-states, as well as the aliases default, all, and really-all], [extensions=$with_extensions], @@ -314,6 +314,7 @@ extensions/rss/Makefile extensions/sample/Makefile extensions/select-stylesheet/Makefile extensions/select-stylesheet/mozilla/Makefile +extensions/session-manager/Makefile extensions/sidebar/Makefile extensions/smart-bookmarks/Makefile extensions/smart-bookmarks/mozilla/Makefile diff --git a/extensions/session-manager/Makefile.am b/extensions/session-manager/Makefile.am new file mode 100644 index 0000000..1537b2e --- /dev/null +++ b/extensions/session-manager/Makefile.am @@ -0,0 +1,38 @@ +extensiondir = $(EXTENSIONS_DIR) +extension_LTLIBRARIES = libsessionmanagerextension.la + +libsessionmanagerextension_la_SOURCES = \ + ephy-session-manager-extension.c \ + ephy-session-manager-extension.h \ + extension.c + +libsessionmanagerextension_la_LDFLAGS = \ + -module -avoid-version \ + -export-symbols $(top_srcdir)/ephy-extension.symbols \ + $(AM_LDFLAGS) + +libsessionmanagerextension_la_CPPFLAGS = \ + -I$(top_srcdir)/include \ + -DSHARE_DIR=\"$(pkgdatadir)\" \ + -DEPHY_EXTENSIONS_LOCALEDIR=\"$(datadir)/locale\" \ + $(AM_CPPFLAGS) + +libsessionmanagerextension_la_CFLAGS = \ + $(EPIPHANY_DEPENDENCY_CFLAGS) \ + $(AM_CFLAGS) + +extensioninidir = $(extensiondir) +extensionini_in_files = session-manager.ephy-extension.in.in +extensionini_DATA = $(extensionini_in_files:.ephy-extension.in.in=.ephy-extension) + +%.ephy-extension.in: %.ephy-extension.in.in $(extension_LTLIBRARIES) + sed -e "s|%LIBRARY%|`. ./$(extension_LTLIBRARIES) && echo $$dlname`|" \ + -e "s|%EXTENSION_DIR%|$(extensiondir)|" \ + $< > $@ + +...@epiphany_extension_rule@ + +CLEANFILES = $(extensionini_DATA) +DISTCLEANFILES = $(extensionini_DATA) + +EXTRA_DIST = $(extensionini_in_files) diff --git a/extensions/session-manager/ephy-session-manager-extension.c b/extensions/session-manager/ephy-session-manager-extension.c new file mode 100644 index 0000000..d45d40a --- /dev/null +++ b/extensions/session-manager/ephy-session-manager-extension.c @@ -0,0 +1,260 @@ +/* + * Copyright © 2009 Klaus Trainer + * + * 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, 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. + * + * $Id$ + */ + +#include "config.h" + +#include "ephy-session-manager-extension.h" +#include "ephy-debug.h" + +#include <epiphany/epiphany.h> + +#include <gtk/gtk.h> + +#include <glib/gi18n-lib.h> +#include <glib/gstdio.h> +#include <glib/gprintf.h> + +#include <gmodule.h> + +#define EPHY_SESSION_MANAGER_EXTENSION_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SESSION_MANAGER_EXTENSION, EphySessionManagerExtensionPrivate)) + +#define WINDOW_DATA_KEY "EphySessionManagerWindowData" + +#define UI_STR "<ui> \ + <menubar name=\"menubar\"> \ + <menu name=\"ToolsMenu\" action=\"Tools\"> \ + <separator/> \ + <menuitem name=\"SaveSession\" action=\"SaveSession\"/> \ + <menuitem name=\"LoadSession\" action=\"LoadSession\"/> \ + <separator/> \ + </menu> \ + </menubar> \ + </ui>" + + +static GObjectClass *parent_class = NULL; + +static GType type = 0; + +typedef struct +{ + GtkActionGroup *action_group; + guint ui_id; +} WindowData; + + +static GtkResponseType +warn_on_overwrite(GtkWidget *parent, char *filename) +{ + GtkWidget* dialog; + GtkResponseType overwrite; + const gchar *msg = g_strconcat ("A file named '", filename, + "' does already exist. Do you want to overwrite it?", NULL); + + dialog = gtk_message_dialog_new (GTK_WINDOW (parent), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_YES_NO, + msg, NULL); + overwrite = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + g_free((gpointer) msg); + return overwrite; +} + +static char * +show_file_chooser_dialog(char *title, GtkFileChooserAction action) +{ + char *filename = NULL; + GtkWidget *dialog; + dialog = gtk_file_chooser_dialog_new (title, + NULL, + action, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_FILE_CHOOSER_ACTION_SAVE ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, + GTK_RESPONSE_OK, + NULL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), "~"); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) + { + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + + if (action == GTK_FILE_CHOOSER_ACTION_SAVE) + { + while (g_file_test (filename, G_FILE_TEST_EXISTS)) + { + if (warn_on_overwrite(dialog, filename) == GTK_RESPONSE_YES) + break; + if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) + break; + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + } + } + + } + + gtk_widget_destroy (dialog); + return filename; +} + +static void +save_session_cb(GtkAction *action, EphySession *session) +{ + char *filename = show_file_chooser_dialog("Save Session", GTK_FILE_CHOOSER_ACTION_SAVE); + if (filename != NULL) + ephy_session_save(session, filename); +} + +static void +load_session_cb(GtkAction *action, EphySession *session) +{ + char *filename = show_file_chooser_dialog("Load Session", GTK_FILE_CHOOSER_ACTION_OPEN); + if (filename != NULL) + ephy_session_load(session, filename, 0); +} + +static void +ephy_session_manager_extension_init (EphySessionManagerExtension *extension) +{ +} + +static void +ephy_session_manager_extension_finalize (GObject *object) +{ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static const GtkActionEntry actions [] = +{ + { "SaveSession", + NULL, + N_("_Save Session…"), + NULL, + NULL, + G_CALLBACK (save_session_cb) }, + { "LoadSession", + NULL, + N_("_Load Session…"), + NULL, + NULL, + G_CALLBACK (load_session_cb) } +}; + +static void +impl_attach_window (EphyExtension *ext, + EphyWindow *window) +{ + GtkUIManager *manager; + WindowData *data; + + /* The window data */ + data = g_new (WindowData, 1); + + manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window)); + data->action_group = gtk_action_group_new ("EphySessionManagerExtension"); + gtk_action_group_add_actions(data->action_group, actions, 2, ephy_shell_get_session (ephy_shell)); + gtk_ui_manager_insert_action_group (manager, data->action_group, -1); + g_object_unref (data->action_group); + data->ui_id = gtk_ui_manager_add_ui_from_string (manager, UI_STR, -1, NULL); + + g_object_set_data_full (G_OBJECT (window), WINDOW_DATA_KEY, data, (GDestroyNotify) g_free); +} + +static void +impl_detach_window (EphyExtension *ext, + EphyWindow *window) +{ + WindowData *data; + GtkUIManager *manager; + + manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window)); + data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); + g_return_if_fail (data != NULL); + + /* Remove the menu item */ + gtk_ui_manager_remove_ui (manager, data->ui_id); + gtk_ui_manager_remove_action_group (manager, data->action_group); + gtk_ui_manager_ensure_update (manager); + + /* Destroy data */ + g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); +} + +static void +ephy_session_manager_extension_iface_init (EphyExtensionIface *iface) +{ + iface->attach_window = impl_attach_window; + iface->detach_window = impl_detach_window; +} + +static void +ephy_session_manager_extension_class_init (EphySessionManagerExtensionClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->finalize = ephy_session_manager_extension_finalize; +} + +GType +ephy_session_manager_extension_get_type (void) +{ + return type; +} + +GType +ephy_session_manager_extension_register_type (GTypeModule *module) +{ + const GTypeInfo our_info = + { + sizeof (EphySessionManagerExtensionClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) ephy_session_manager_extension_class_init, + NULL, + NULL, /* class_data */ + sizeof (EphySessionManagerExtension), + 0, /* n_preallocs */ + (GInstanceInitFunc) ephy_session_manager_extension_init + }; + + const GInterfaceInfo extension_info = + { + (GInterfaceInitFunc) ephy_session_manager_extension_iface_init, + NULL, + NULL + }; + + type = g_type_module_register_type (module, + G_TYPE_OBJECT, + "EphySessionManagerExtension", + &our_info, 0); + + g_type_module_add_interface (module, + type, + EPHY_TYPE_EXTENSION, + &extension_info); + + return type; +} diff --git a/extensions/session-manager/ephy-session-manager-extension.h b/extensions/session-manager/ephy-session-manager-extension.h new file mode 100644 index 0000000..13724ba --- /dev/null +++ b/extensions/session-manager/ephy-session-manager-extension.h @@ -0,0 +1,56 @@ +/* + * Copyright © 2009 Klaus Trainer + * + * 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, 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. + * + * $Id$ + */ + +#ifndef EPHY_SESSION_MANAGER_EXTENSION_H +#define EPHY_SESSION_MANAGER_EXTENSION_H + +#include <glib.h> +#include <glib-object.h> + +G_BEGIN_DECLS + +#define EPHY_TYPE_SESSION_MANAGER_EXTENSION (ephy_session_manager_extension_get_type ()) +#define EPHY_SESSION_MANAGER_EXTENSION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_SESSION_MANAGER_EXTENSION, EphySessionManagerExtension)) +#define EPHY_SESSION_MANAGER_EXTENSION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_SESSION_MANAGER_EXTENSION, EphySessionManagerExtensionClass)) +#define EPHY_IS_SESSION_MANAGER_EXTENSION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_SESSION_MANAGER_EXTENSION)) +#define EPHY_IS_SESSION_MANAGER_EXTENSION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_SESSION_MANAGER_EXTENSION)) +#define EPHY_SESSION_MANAGER_EXTENSION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_SESSION_MANAGER_EXTENSION, EphySessionManagerExtensionClass)) + + +typedef struct _EphySessionManagerExtension EphySessionManagerExtension; +typedef struct _EphySessionManagerExtensionClass EphySessionManagerExtensionClass; + +struct _EphySessionManagerExtensionClass +{ + GObjectClass parent_class; +}; + +struct _EphySessionManagerExtension +{ + GObject parent_instance; +}; + +GType ephy_session_manager_extension_get_type (void); + +GType ephy_session_manager_extension_register_type (GTypeModule *module); + +G_END_DECLS + +#endif diff --git a/extensions/session-manager/extension.c b/extensions/session-manager/extension.c new file mode 100644 index 0000000..7ee6437 --- /dev/null +++ b/extensions/session-manager/extension.c @@ -0,0 +1,44 @@ +/* + * Copyright © 2003 Marco Pesenti Gritti + * Copyright © 2003, 2004 Christian Persch + * + * 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, 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. + * + * $Id$ + */ + +#include "config.h" + +#include "ephy-session-manager-extension.h" +#include "ephy-debug.h" + +#include <glib/gi18n-lib.h> +#include <gmodule.h> + +G_MODULE_EXPORT GType register_module (GTypeModule *module); + +G_MODULE_EXPORT GType +register_module (GTypeModule *module) +{ + LOG ("Registering EphySessionManagerExtension"); + +#ifdef ENABLE_NLS + /* Initialise the i18n stuff */ + bindtextdomain (GETTEXT_PACKAGE, EPHY_EXTENSIONS_LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); +#endif /* ENABLE_NLS */ + + return ephy_session_manager_extension_register_type (module); +} diff --git a/extensions/session-manager/session-manager.ephy-extension.in.in b/extensions/session-manager/session-manager.ephy-extension.in.in new file mode 100644 index 0000000..1ca5870 --- /dev/null +++ b/extensions/session-manager/session-manager.ephy-extension.in.in @@ -0,0 +1,10 @@ +[Epiphany Extension] +_Name=Session Manager +_Description=Adds the ability to save the current session to a file and restore saved sessions. +Authors=Simon Ward <si...@bleah.co.uk>, Klaus Trainer <klaus.trai...@web.de>; +Version=0.2 +URL=http://projects.gnome.org/epiphany/extensions + +[Loader] +Type=shlib +Library=%EXTENSION_DIR%/%LIBRARY% -- 1.6.3.3
_______________________________________________ epiphany-list mailing list epiphany-list@gnome.org http://mail.gnome.org/mailman/listinfo/epiphany-list