aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@it.gnome.org>2003-03-19 03:13:23 +0800
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2003-03-19 03:13:23 +0800
commitd012141a9d6dc6e0b374b4e992e18239b21501dd (patch)
tree430ad3fc3ab6fdda82d91afe2acaadc081ac8c1a
parentd248386941ce108b1e99d1a553682d5af791a628 (diff)
downloadgsoc2013-epiphany-d012141a9d6dc6e0b374b4e992e18239b21501dd.tar
gsoc2013-epiphany-d012141a9d6dc6e0b374b4e992e18239b21501dd.tar.gz
gsoc2013-epiphany-d012141a9d6dc6e0b374b4e992e18239b21501dd.tar.bz2
gsoc2013-epiphany-d012141a9d6dc6e0b374b4e992e18239b21501dd.tar.lz
gsoc2013-epiphany-d012141a9d6dc6e0b374b4e992e18239b21501dd.tar.xz
gsoc2013-epiphany-d012141a9d6dc6e0b374b4e992e18239b21501dd.tar.zst
gsoc2013-epiphany-d012141a9d6dc6e0b374b4e992e18239b21501dd.zip
Reimplement ephystate using xml and make it easier to use. -> remove some
2003-03-18 Marco Pesenti Gritti <marco@it.gnome.org> * lib/ephy-dialog.c: (setup_default_size): * lib/ephy-state.c: (ephy_states_load), (ephy_states_save), (find_by_name), (ensure_states), (ephy_state_window_set_size), (ephy_state_window_save_size), (window_configure_event_cb), (window_state_event_cb), (ephy_state_add_window), (ephy_state_save): * lib/ephy-state.h: * lib/ephy-types.h: * src/ephy-shell.c: (ephy_shell_finalize): * src/ephy-window.c: (setup_window), (ephy_window_init), (ephy_window_show): * src/prefs-dialog.c: (prefs_dialog_init): Reimplement ephystate using xml and make it easier to use. -> remove some duplicate code
-rw-r--r--ChangeLog18
-rw-r--r--lib/ephy-dialog.c19
-rw-r--r--lib/ephy-state.c302
-rw-r--r--lib/ephy-state.h22
-rw-r--r--lib/ephy-types.h3
-rw-r--r--src/ephy-shell.c2
-rw-r--r--src/ephy-window.c45
-rw-r--r--src/prefs-dialog.c19
8 files changed, 251 insertions, 179 deletions
diff --git a/ChangeLog b/ChangeLog
index ba7cc2131..98be586ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2003-03-18 Marco Pesenti Gritti <marco@it.gnome.org>
+
+ * lib/ephy-dialog.c: (setup_default_size):
+ * lib/ephy-state.c: (ephy_states_load), (ephy_states_save),
+ (find_by_name), (ensure_states), (ephy_state_window_set_size),
+ (ephy_state_window_save_size), (window_configure_event_cb),
+ (window_state_event_cb), (ephy_state_add_window),
+ (ephy_state_save):
+ * lib/ephy-state.h:
+ * lib/ephy-types.h:
+ * src/ephy-shell.c: (ephy_shell_finalize):
+ * src/ephy-window.c: (setup_window), (ephy_window_init),
+ (ephy_window_show):
+ * src/prefs-dialog.c: (prefs_dialog_init):
+
+ Reimplement ephystate using xml and make it easier to use.
+ -> remove some duplicate code
+
2003-03-17 Jon Svendsen <jon-sven@frisurf.no>
* lib/ephy-state.c: (ephy_state_save_window):
diff --git a/lib/ephy-dialog.c b/lib/ephy-dialog.c
index 8c8344dda..7262bc59c 100644
--- a/lib/ephy-dialog.c
+++ b/lib/ephy-dialog.c
@@ -837,26 +837,11 @@ impl_get_value (EphyDialog *dialog,
}
}
-static gboolean
-ephy_dialog_configure_event_cb (GtkWidget *widget,
- GdkEventConfigure *event,
- EphyDialog *dialog)
-{
- ephy_state_save_window (widget, dialog->priv->name);
-
- return FALSE;
-}
-
static void
setup_default_size (EphyDialog *dialog)
{
- ephy_state_load_window (dialog->priv->dialog,
- dialog->priv->name, -1, -1, FALSE);
-
- g_signal_connect (dialog->priv->dialog,
- "configure_event",
- G_CALLBACK (ephy_dialog_configure_event_cb),
- dialog);
+ ephy_state_add_window (dialog->priv->dialog,
+ dialog->priv->name, -1, -1);
}
static gint
diff --git a/lib/ephy-state.c b/lib/ephy-state.c
index 9bf28ebdc..5debe8cf5 100644
--- a/lib/ephy-state.c
+++ b/lib/ephy-state.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2001 Matthew Mueller
* (C) 2002 Jorn Baayen <jorn@nl.linux.org>
+ * (C) 2003 Marco Pesenti Gritti <mpeseng@tin.it>
*
* 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
@@ -16,142 +17,263 @@
* 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 <stdio.h>
-#include <stdlib.h>
+#include "ephy-state.h"
+#include "ephy-file-helpers.h"
+#include "ephy-node.h"
+#include "ephy-types.h"
+
#include <string.h>
-#include <gtk/gtkpaned.h>
#include <gtk/gtkwindow.h>
-#include <gtk/gtktreeview.h>
-#include <libgnomeui/gnome-app.h>
-#include <bonobo/bonobo-dock.h>
-#include <bonobo/bonobo-dock-layout.h>
-#include "ephy-state.h"
-#include "eel-gconf-extensions.h"
+#define STATES_FILE "states.xml"
+
+enum
+{
+ EPHY_NODE_STATE_PROP_NAME = 2,
+ EPHY_NODE_STATE_PROP_WIDTH = 3,
+ EPHY_NODE_STATE_PROP_HEIGHT = 4,
+ EPHY_NODE_STATE_PROP_MAXIMIZE = 5
+};
-#define CONF_GUL_STATE_PATH "/apps/epiphany/state"
+static EphyNode *states;
static void
-window_save_size (GtkWidget *window, const gchar *name)
+ephy_states_load (void)
{
- int width, height;
- gchar *buf;
+ xmlDocPtr doc;
+ xmlNodePtr root, child;
+ char *xml_file;
- gtk_window_get_size (GTK_WINDOW(window),
- &width, &height);
+ xml_file = g_build_filename (ephy_dot_dir (),
+ STATES_FILE,
+ NULL);
+
+ if (g_file_test (xml_file, G_FILE_TEST_EXISTS) == FALSE)
+ return;
- buf = g_strdup_printf (CONF_GUL_STATE_PATH "/%s/width",name);
- eel_gconf_set_integer (buf, width);
- g_free (buf);
+ doc = xmlParseFile (xml_file);
+ g_assert (doc != NULL);
- buf = g_strdup_printf (CONF_GUL_STATE_PATH "/%s/height",name);
- eel_gconf_set_integer (buf, height);
- g_free (buf);
+ root = xmlDocGetRootElement (doc);
+
+ for (child = root->children; child != NULL; child = child->next)
+ {
+ EphyNode *node;
+
+ node = ephy_node_new_from_xml (child);
+ }
+
+ xmlFreeDoc (doc);
+
+ g_free (xml_file);
}
-/**
- * ephy_state_save_window: save the window dimensions
- */
-void
-ephy_state_save_window (GtkWidget *window,
- const gchar *name)
+static void
+ephy_states_save (void)
{
- GdkWindowState state;
- gboolean maximized;
- gchar *buf;
+ xmlDocPtr doc;
+ xmlNodePtr root;
+ GPtrArray *children;
+ int i;
+ char *xml_file;
- state = gdk_window_get_state (GTK_WIDGET (window)->window);
- maximized = ((state & GDK_WINDOW_STATE_MAXIMIZED) > 0);
-
- buf = g_strdup_printf (CONF_GUL_STATE_PATH "/%s/maximized",name);
- eel_gconf_set_boolean (buf, maximized);
- g_free (buf);
+ xml_file = g_build_filename (ephy_dot_dir (),
+ STATES_FILE,
+ NULL);
+
+ /* save nodes to xml */
+ xmlIndentTreeOutput = TRUE;
+ doc = xmlNewDoc ("1.0");
- if (!maximized)
+ root = xmlNewDocNode (doc, NULL, "ephy_bookmarks", NULL);
+ xmlDocSetRootElement (doc, root);
+
+ children = ephy_node_get_children (states);
+ for (i = 0; i < children->len; i++)
{
- window_save_size (window, name);
+ EphyNode *kid;
+
+ kid = g_ptr_array_index (children, i);
+
+ ephy_node_save_to_xml (kid, root);
}
+ ephy_node_thaw (states);
+
+ xmlSaveFormatFile (xml_file, doc, 1);
+ g_free (xml_file);
}
-/**
- * ephy_window_load_state: load the window state
- */
-void
-ephy_state_load_window (GtkWidget *window,
- const gchar *name,
- int default_width,
- int default_height,
- gboolean position)
+static EphyNode *
+find_by_name (const char *name)
{
- gchar *buf;
- gint width, height;
- gboolean maximized;
+ EphyNode *result = NULL;
+ GPtrArray *children;
+ int i;
- buf = g_strdup_printf (CONF_GUL_STATE_PATH "/%s/maximized",name);
- maximized = eel_gconf_get_boolean (buf);
- g_free (buf);
+ children = ephy_node_get_children (states);
+ for (i = 0; i < children->len; i++)
+ {
+ EphyNode *kid;
+ const char *node_name;
+
+ kid = g_ptr_array_index (children, i);
- buf = g_strdup_printf (CONF_GUL_STATE_PATH "/%s/width",name);
- width = eel_gconf_get_integer (buf);
- g_free (buf);
+ node_name = ephy_node_get_property_string
+ (kid, EPHY_NODE_STATE_PROP_NAME);
+ if (strcmp (node_name, name) == 0)
+ {
+ result = kid;
+ }
+ }
+ ephy_node_thaw (states);
- buf = g_strdup_printf (CONF_GUL_STATE_PATH "/%s/height",name);
- height = eel_gconf_get_integer (buf);
- g_free (buf);
+ return result;
+}
- /* try default size */
- if (width == 0 && height == 0 &&
- default_width != -1 && default_height != -1)
+static void
+ensure_states (void)
+{
+ if (states == NULL)
{
- width = default_width;
- height = default_height;
+ states = ephy_node_new_with_id (STATES_NODE_ID);
+ ephy_states_load ();
}
+}
+
+static void
+ephy_state_window_set_size (GtkWidget *window, EphyNode *node)
+{
+ int width;
+ int height;
+ gboolean maximize;
+
+ width = ephy_node_get_property_int (node, EPHY_NODE_STATE_PROP_WIDTH);
+ height = ephy_node_get_property_int (node, EPHY_NODE_STATE_PROP_HEIGHT);
+ maximize = ephy_node_get_property_boolean (node, EPHY_NODE_STATE_PROP_MAXIMIZE);
- if (width != 0 && height != 0)
+ if (width > 0 && height > 0)
{
gtk_window_set_default_size
(GTK_WINDOW (window), width, height);
}
- if (maximized)
+ if (maximize)
{
- gtk_window_maximize (GTK_WINDOW(window));
+ gtk_window_maximize (GTK_WINDOW (window));
}
}
-/**
- * ephy_state_load_pane_pos: load the paned position
- */
-void
-ephy_state_load_pane_pos (GtkWidget *pane,
- const gchar *name)
+static void
+ephy_state_window_save_size (GtkWidget *window, EphyNode *node)
{
- if (pane != NULL)
+ int width, height;
+ gboolean maximize;
+ GdkWindowState state;
+ GValue value = { 0, };
+
+ state = gdk_window_get_state (GTK_WIDGET (window)->window);
+ maximize = ((state & GDK_WINDOW_STATE_MAXIMIZED) > 0);
+
+ gtk_window_get_size (GTK_WINDOW(window),
+ &width, &height);
+
+ if (!maximize)
{
- gint pane_pos;
- gchar *buf = g_strdup_printf (CONF_GUL_STATE_PATH "/%s", name);
- pane_pos = eel_gconf_get_integer (buf);
- g_free (buf);
+ g_value_init (&value, G_TYPE_INT);
+ g_value_set_int (&value, width);
+ ephy_node_set_property (node, EPHY_NODE_STATE_PROP_WIDTH,
+ &value);
+ g_value_unset (&value);
- if (pane_pos != -1)
- gtk_paned_set_position (GTK_PANED (pane), pane_pos);
+ g_value_init (&value, G_TYPE_INT);
+ g_value_set_int (&value, height);
+ ephy_node_set_property (node, EPHY_NODE_STATE_PROP_HEIGHT,
+ &value);
+ g_value_unset (&value);
}
+
+ g_value_init (&value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&value, maximize);
+ ephy_node_set_property (node, EPHY_NODE_STATE_PROP_MAXIMIZE,
+ &value);
+ g_value_unset (&value);
+}
+
+static gboolean
+window_configure_event_cb (GtkWidget *widget,
+ GdkEventConfigure *event,
+ EphyNode *node)
+{
+ ephy_state_window_save_size (widget, node);
+ return FALSE;
+}
+
+static gboolean
+window_state_event_cb (GtkWidget *widget,
+ GdkEventWindowState *event,
+ EphyNode *node)
+{
+ ephy_state_window_save_size (widget, node);
+ return FALSE;
}
-/**
- * gul_state_save_pane_pos: save the paned position
- */
void
-ephy_state_save_pane_pos (GtkWidget *pane,
- const gchar *name)
+ephy_state_add_window (GtkWidget *window,
+ const char *name,
+ int default_width,
+ int default_height)
{
- if (pane != NULL)
+ EphyNode *node;
+
+ ensure_states ();
+
+ node = find_by_name (name);
+ if (node == NULL)
{
- gchar *buf = g_strdup_printf (CONF_GUL_STATE_PATH "/%s", name);
- eel_gconf_set_integer (buf, GTK_PANED (pane)->child1_size);
- g_free (buf);
+ GValue value = { 0, };
+
+ node = ephy_node_new ();
+ ephy_node_add_child (states, node);
+
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, name);
+ ephy_node_set_property (node, EPHY_NODE_STATE_PROP_NAME,
+ &value);
+ g_value_unset (&value);
+
+ g_value_init (&value, G_TYPE_INT);
+ g_value_set_int (&value, default_width);
+ ephy_node_set_property (node, EPHY_NODE_STATE_PROP_WIDTH,
+ &value);
+ g_value_unset (&value);
+
+ g_value_init (&value, G_TYPE_INT);
+ g_value_set_int (&value, default_height);
+ ephy_node_set_property (node, EPHY_NODE_STATE_PROP_HEIGHT,
+ &value);
+ g_value_unset (&value);
+
+ g_value_init (&value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&value, FALSE);
+ ephy_node_set_property (node, EPHY_NODE_STATE_PROP_MAXIMIZE,
+ &value);
+ g_value_unset (&value);
}
+
+ ephy_state_window_set_size (window, node);
+
+ g_signal_connect_object (window, "configure_event",
+ G_CALLBACK (window_configure_event_cb), node, 0);
+ g_signal_connect_object (window, "window_state_event",
+ G_CALLBACK (window_state_event_cb), node, 0);
+}
+
+void
+ephy_state_save (void)
+{
+ ephy_states_save ();
+ ephy_node_unref (states);
+ states = NULL;
}
diff --git a/lib/ephy-state.h b/lib/ephy-state.h
index 508e986be..7e05e6106 100644
--- a/lib/ephy-state.h
+++ b/lib/ephy-state.h
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2001 Matthew Mueller
* (C) 2002 Jorn Baayen <jorn@nl.linux.org>
+ * (C) 2003 Marco Pesenti Gritti <mpeseng@tin.it>
*
* 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
@@ -15,29 +16,22 @@
* 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_STATE_H
#define EPHY_STATE_H
-G_BEGIN_DECLS
+#include "gtk/gtkwidget.h"
-void ephy_state_save_window (GtkWidget *window,
- const gchar *name);
+G_BEGIN_DECLS
-void ephy_state_load_window (GtkWidget *window,
- const gchar *name,
+void ephy_state_add_window (GtkWidget *window,
+ const char *name,
int default_width,
- int default_heigth,
- gboolean position);
-
-void ephy_state_save_pane_pos (GtkWidget *pane,
- const gchar *name);
+ int default_heigth);
-void ephy_state_load_pane_pos (GtkWidget *pane,
- const gchar *name);
+void ephy_state_save (void);
G_END_DECLS
diff --git a/lib/ephy-types.h b/lib/ephy-types.h
index 4b3652527..3d8b6be06 100644
--- a/lib/ephy-types.h
+++ b/lib/ephy-types.h
@@ -37,9 +37,10 @@ enum
BOOKMARKS_NODE_ID = 0,
KEYWORDS_NODE_ID = 1,
FAVORITES_NODE_ID = 2,
+ STATES_NODE_ID = 4,
HOSTS_NODE_ID = 5,
PAGES_NODE_ID = 6,
- ICONS_NODE_ID = 9,
+ ICONS_NODE_ID = 9
};
G_END_DECLS
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 69af9e562..4fc7e26f3 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -21,6 +21,7 @@
#endif
#include "ephy-shell.h"
+#include "ephy-state.h"
#include "ephy-embed-shell.h"
#include "eel-gconf-extensions.h"
#include "ephy-prefs.h"
@@ -324,6 +325,7 @@ ephy_shell_finalize (GObject *object)
g_free (gs->priv);
+ ephy_state_save ();
ephy_file_helpers_shutdown ();
ephy_node_system_shutdown ();
diff --git a/src/ephy-window.c b/src/ephy-window.c
index c0df5980f..5355d75f9 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -268,7 +268,6 @@ struct EphyWindowPrivate
EphyDialog *history_dialog;
EphyDialog *history_sidebar;
EmbedChromeMask chrome_mask;
- gboolean has_default_size;
gboolean closing;
};
@@ -378,36 +377,6 @@ ephy_window_selection_received_cb (GtkWidget *widget,
}
static void
-save_window_state (GtkWidget *win)
-{
- EphyWindow *window = EPHY_WINDOW (win);
-
- if (!(window->priv->chrome_mask & EMBED_CHROME_OPENASPOPUP) &&
- !(window->priv->chrome_mask & EMBED_CHROME_OPENASFULLSCREEN))
- {
- ephy_state_save_window (win, "main_window");
- }
-}
-
-static gboolean
-ephy_window_configure_event_cb (GtkWidget *widget,
- GdkEventConfigure *event,
- gpointer data)
-{
- save_window_state (widget);
- return FALSE;
-}
-
-static gboolean
-ephy_window_state_event_cb (GtkWidget *widget,
- GdkEventWindowState *event,
- gpointer data)
-{
- save_window_state (widget);
- return FALSE;
-}
-
-static void
add_widget (EggMenuMerge *merge, GtkWidget *widget, EphyWindow *window)
{
if (GTK_IS_MENU_SHELL (widget))
@@ -478,10 +447,6 @@ setup_window (EphyWindow *window)
"key-press-event",
G_CALLBACK(ephy_window_key_press_event_cb),
window);
- g_signal_connect (window, "configure_event",
- G_CALLBACK (ephy_window_configure_event_cb), NULL);
- g_signal_connect (window, "window_state_event",
- G_CALLBACK (ephy_window_state_event_cb), NULL);
g_signal_connect (window,
"selection-received",
G_CALLBACK (ephy_window_selection_received_cb),
@@ -530,7 +495,6 @@ ephy_window_init (EphyWindow *window)
window->priv->active_tab = NULL;
window->priv->chrome_mask = 0;
window->priv->closing = FALSE;
- window->priv->has_default_size = FALSE;
window->priv->ppview_toolbar = NULL;
window->priv->toolbars = NULL;
@@ -973,12 +937,13 @@ ephy_window_show (GtkWidget *widget)
tab = ephy_window_get_active_tab (window);
if (tab) ephy_tab_get_size (tab, &w, &h);
- if (!window->priv->has_default_size && w == -1 && h == -1)
+ if (!(window->priv->chrome_mask & EMBED_CHROME_OPENASPOPUP) &&
+ !(window->priv->chrome_mask & EMBED_CHROME_OPENASFULLSCREEN) &&
+ !GTK_WIDGET_VISIBLE (widget))
{
- ephy_state_load_window (GTK_WIDGET(window),
+ ephy_state_add_window (GTK_WIDGET(window),
"main_window",
- 600, 500, TRUE);
- window->priv->has_default_size = TRUE;
+ 600, 500);
}
GTK_WIDGET_CLASS (parent_class)->show (widget);
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 813821cb6..c94998d60 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -298,16 +298,6 @@ prefs_build_notebook (PrefsDialog *pd)
}
}
-static gboolean
-prefs_dialog_configure_event_cb (GtkWidget *widget,
- GdkEventConfigure *event,
- gpointer data)
-{
- ephy_state_save_window (widget, "prefs_dialog");
-
- return FALSE;
-}
-
static void
prefs_dialog_init (PrefsDialog *pd)
{
@@ -316,13 +306,8 @@ prefs_dialog_init (PrefsDialog *pd)
gtk_window_set_title (GTK_WINDOW(pd), _("Preferences"));
gtk_dialog_set_has_separator (GTK_DIALOG(pd), FALSE);
- ephy_state_load_window (GTK_WIDGET(pd),
- "prefs_dialog", -1, -1, FALSE);
-
- g_signal_connect (pd,
- "configure_event",
- G_CALLBACK (prefs_dialog_configure_event_cb),
- NULL);
+ ephy_state_add_window (GTK_WIDGET(pd),
+ "prefs_dialog", -1, -1);
prefs_build_notebook (pd);
}