[PATCH] Ported Simon Ward's Session Manager extension from Python =



---
 configure.ac                                       |    7 +-
 extensions/session-manager/Makefile.am             |   38 +++
 .../ephy-session-manager-extension.c               |  264 ++++++++++++++++=
++++
 .../ephy-session-manager-extension.h               |   56 ++++
 extensions/session-manager/extension.c             |   44 ++++
 .../session-manager.ephy-extension.in.in           |   10 +
 6 files changed, 416 insertions(+), 3 deletions(-)
 create mode 100644 extensions/session-manager/Makefile.am
 create mode 100644 extensions/session-manager/ephy-session-manager-extensi=
on.c
 create mode 100644 extensions/session-manager/ephy-session-manager-extensi=
on.h
 create mode 100644 extensions/session-manager/extension.c
 create mode 100644 extensions/session-manager/session-manager.ephy-extensi=
on.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" =
=3D "xyes"])
=20
 AC_MSG_CHECKING([which extensions to build])
=20
-ALL_EXTENSIONS=3D"actions adblock auto-reload auto-scroller certificates e=
rror-viewer extensions-manager-ui gestures greasemonkey java-console liveht=
tpheaders page-info permissions push-scroller rss sample select-stylesheet =
sidebar smart-bookmarks soup-fly tab-groups tab-states"
-USEFUL_EXTENSIONS=3D"actions adblock auto-reload auto-scroller certificate=
s error-viewer extensions-manager-ui java-console page-info push-scroller s=
elect-stylesheet smart-bookmarks soup-fly tab-groups tab-states"
+ALL_EXTENSIONS=3D"actions adblock auto-reload auto-scroller certificates e=
rror-viewer extensions-manager-ui gestures greasemonkey java-console liveht=
tpheaders page-info permissions push-scroller rss sample select-stylesheet =
sidebar smart-bookmarks soup-fly tab-groups tab-states session-manager"
+USEFUL_EXTENSIONS=3D"actions adblock auto-reload auto-scroller certificate=
s error-viewer extensions-manager-ui java-console page-info push-scroller s=
elect-stylesheet smart-bookmarks soup-fly tab-groups tab-states session-man=
ager"
 DEFAULT_EXTENSIONS=3D"actions adblock auto-scroller certificates error-vie=
wer extensions-manager-ui java-console page-info push-scroller select-style=
sheet smart-bookmarks soup-fly tab-groups tab-states greasemonkey"
=20
 MOZILLA_ALL_EXTENSIONS=3D"error-viewer java-console livehttpheaders page-i=
nfo 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=3D$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-ma=
nager/Makefile.am
new file mode 100644
index 0000000..1537b2e
--- /dev/null
+++ b/extensions/session-manager/Makefile.am
@@ -0,0 +1,38 @@
+extensiondir =3D $(EXTENSIONS_DIR)
+extension_LTLIBRARIES =3D libsessionmanagerextension.la
+
+libsessionmanagerextension_la_SOURCES =3D \
+	ephy-session-manager-extension.c	\
+	ephy-session-manager-extension.h	\
+	extension.c
+=09
+libsessionmanagerextension_la_LDFLAGS =3D \
+	-module -avoid-version \
+	-export-symbols $(top_srcdir)/ephy-extension.symbols \
+	$(AM_LDFLAGS)
+
+libsessionmanagerextension_la_CPPFLAGS =3D \
+        -I$(top_srcdir)/include				\
+	-DSHARE_DIR=3D\"$(pkgdatadir)\"			\
+	-DEPHY_EXTENSIONS_LOCALEDIR=3D\"$(datadir)/locale\"  \
+	$(AM_CPPFLAGS)
+
+libsessionmanagerextension_la_CFLAGS =3D \
+	$(EPIPHANY_DEPENDENCY_CFLAGS)	\
+	$(AM_CFLAGS)
+
+extensioninidir =3D $(extensiondir)
+extensionini_in_files =3D session-manager.ephy-extension.in.in
+extensionini_DATA =3D $(extensionini_in_files:.ephy-extension.in.in=3D.eph=
y-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 =3D $(extensionini_DATA)
+DISTCLEANFILES =3D $(extensionini_DATA)
+
+EXTRA_DIST =3D $(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..2311788
--- /dev/null
+++ b/extensions/session-manager/ephy-session-manager-extension.c
@@ -0,0 +1,264 @@
+/*
+ *  Copyright =C2=A9 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_INSTANC=
E_GET_PRIVATE ((object), EPHY_TYPE_SESSION_MANAGER_EXTENSION, EphySessionMa=
nagerExtensionPrivate))
+
+#define WINDOW_DATA_KEY	"EphySessionManagerWindowData"
+
+#define UI_STR "<ui> \
+                  <menubar name=3D\"menubar\"> \
+                    <menu name=3D\"ToolsMenu\" action=3D\"Tools\"> \
+                      <separator/> \
+                      <menuitem name=3D\"SaveSession\" action=3D\"SaveSess=
ion\"/> \
+                      <menuitem name=3D\"LoadSession\" action=3D\"LoadSess=
ion\"/> \
+                      <separator/> \
+                    </menu> \
+                  </menubar> \
+                </ui>"
+
+
+static GObjectClass *parent_class =3D NULL;
+
+static GType type =3D 0;
+
+typedef struct
+{
+	GtkActionGroup *action_group;
+	guint ui_id;
+} WindowData;
+
+
+static GtkResponseType
+warn_on_overwrite(GtkWidget *parent, char *filename)
+{
+	GtkResponseType overwrite;
+	GtkWidget *dialog;
+	const gchar *msg =3D g_strconcat ("A file named '", filename,
+		"' does already exist. Do you want to overwrite it?", NULL);
+
+	dialog =3D gtk_message_dialog_new (GTK_WINDOW (parent),
+                                  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WI=
TH_PARENT,
+                                  GTK_MESSAGE_WARNING,
+                                  GTK_BUTTONS_YES_NO,
+                                  msg, NULL);
+	overwrite =3D gtk_dialog_run (GTK_DIALOG (dialog));
+
+	gtk_widget_destroy (dialog);
+	g_free((gpointer) msg);
+
+	return overwrite;
+}
+
+static gchar *
+show_file_chooser_dialog(gchar *title, GtkFileChooserAction action)
+{
+	gchar *filename =3D NULL;
+	GtkWidget *dialog;
+
+	dialog =3D 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)) =3D=3D GTK_RESPONSE_OK)
+	{
+		filename =3D gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+		if (action =3D=3D GTK_FILE_CHOOSER_ACTION_SAVE)
+		{
+			while (g_file_test (filename, G_FILE_TEST_EXISTS))
+			{
+				if (warn_on_overwrite(dialog, filename)	=3D=3D GTK_RESPONSE_YES)
+					break;
+				if (gtk_dialog_run (GTK_DIALOG (dialog)) !=3D GTK_RESPONSE_OK)
+					break;
+				filename =3D gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog))=
;
+			}
+		}
+
+	}
+
+	gtk_widget_destroy (dialog);
+
+	return filename;
+}
+
+static void
+save_session_cb(GtkAction *action, EphySession *session)
+{
+	gchar *filename =3D show_file_chooser_dialog(N_("Save Session"), GTK_FILE=
_CHOOSER_ACTION_SAVE);
+	if (filename !=3D NULL) {
+		ephy_session_save(session, filename);
+		g_free((gpointer) filename);
+	}
+}
+
+static void
+load_session_cb(GtkAction *action, EphySession *session)
+{
+	gchar *filename =3D show_file_chooser_dialog(N_("Load Session"), GTK_FILE=
_CHOOSER_ACTION_OPEN);
+	if (filename !=3D NULL) {
+		ephy_session_load(session, filename, 0);
+		g_free((gpointer) filename);
+	}
+}
+
+static void
+ephy_session_manager_extension_init (EphySessionManagerExtension *extensio=
n)
+{
+}
+
+static void
+ephy_session_manager_extension_finalize (GObject *object)
+{
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static const GtkActionEntry actions [] =3D
+{
+	{ "SaveSession",
+	  NULL,
+	  N_("_Save Session=E2=80=A6"),
+	  NULL,
+	  NULL,
+	  G_CALLBACK (save_session_cb) },
+	{ "LoadSession",
+	  NULL,
+	  N_("_Load Session=E2=80=A6"),
+	  NULL,
+	  NULL,
+	  G_CALLBACK (load_session_cb) }
+};
+
+static void
+impl_attach_window (EphyExtension *ext,
+		    EphyWindow *window)
+{
+	GtkUIManager *manager;
+	WindowData *data;
+
+	/* The window data */
+	data =3D g_new (WindowData, 1);
+
+	manager =3D  GTK_UI_MANAGER (ephy_window_get_ui_manager (window));
+	data->action_group =3D gtk_action_group_new ("EphySessionManagerExtension=
");
+	gtk_action_group_add_actions(data->action_group, actions, 2, ephy_shell_g=
et_session (ephy_shell));
+	gtk_ui_manager_insert_action_group (manager, data->action_group, -1);
+	g_object_unref (data->action_group);
+	data->ui_id =3D gtk_ui_manager_add_ui_from_string (manager, UI_STR, -1, N=
ULL);
+
+	g_object_set_data_full (G_OBJECT (window), WINDOW_DATA_KEY, data, (GDestr=
oyNotify) g_free);
+}
+
+static void
+impl_detach_window (EphyExtension *ext,
+		    EphyWindow *window)
+{
+	WindowData *data;
+	GtkUIManager *manager;
+
+	manager =3D  GTK_UI_MANAGER (ephy_window_get_ui_manager (window));
+	data =3D (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA=
_KEY);
+	g_return_if_fail (data !=3D NULL);
+
+	/* Remove the menu item */
+	gtk_ui_manager_remove_ui (manager, data->ui_id);
+	gtk_ui_manager_remove_action_group (manager, data->action_group);
+
+	/* 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 =3D impl_attach_window;
+	iface->detach_window =3D impl_detach_window;
+}
+
+static void
+ephy_session_manager_extension_class_init (EphySessionManagerExtensionClas=
s *klass)
+{
+	GObjectClass *object_class =3D G_OBJECT_CLASS (klass);
+	parent_class =3D g_type_class_peek_parent (klass);
+	object_class->finalize =3D 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 =3D
+	{
+		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 =3D
+	{
+		(GInterfaceInitFunc) ephy_session_manager_extension_iface_init,
+		NULL,
+		NULL
+	};
+
+	type =3D 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 =C2=A9 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_extens=
ion_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_TYP=
E ((k), EPHY_TYPE_SESSION_MANAGER_EXTENSION))
+#define EPHY_SESSION_MANAGER_EXTENSION_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_C=
LASS ((o), EPHY_TYPE_SESSION_MANAGER_EXTENSION, EphySessionManagerExtension=
Class))
+
+
+typedef struct _EphySessionManagerExtension	EphySessionManagerExtension;
+typedef struct _EphySessionManagerExtensionClass	EphySessionManagerExtensi=
onClass;
+
+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-ma=
nager/extension.c
new file mode 100644
index 0000000..7ee6437
--- /dev/null
+++ b/extensions/session-manager/extension.c
@@ -0,0 +1,44 @@
+/*
+ *  Copyright =C2=A9 2003 Marco Pesenti Gritti
+ *  Copyright =C2=A9 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.i=
n 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=3DSession Manager
+_Description=3DAdds the ability to save the current session to a file and =
restore saved sessions.
+Authors=3DSimon Ward <simon bleah co uk>, Klaus Trainer <klaus trainer web=
.de>;
+Version=3D0.2
+URL=3Dhttp://projects.gnome.org/epiphany/extensions
+
+[Loader]
+Type=3Dshlib
+Library=3D%EXTENSION_DIR%/%LIBRARY%
--=20
1.6.3.3


--=-LYljqLGILDDZ1fJ8imhD--



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]