aboutsummaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorEttore Perazzoli <ettore@src.gnome.org>2000-06-29 15:37:55 +0800
committerEttore Perazzoli <ettore@src.gnome.org>2000-06-29 15:37:55 +0800
commit3bedc38a9480532b83e4bfeb386f4bbd7b611b38 (patch)
tree1a33af67a5949913ca02be4c39d4f8acde34c436 /shell
parent31e562c685d59c22fa1f241aa549bf8867042657 (diff)
downloadgsoc2013-evolution-3bedc38a9480532b83e4bfeb386f4bbd7b611b38.tar
gsoc2013-evolution-3bedc38a9480532b83e4bfeb386f4bbd7b611b38.tar.gz
gsoc2013-evolution-3bedc38a9480532b83e4bfeb386f4bbd7b611b38.tar.bz2
gsoc2013-evolution-3bedc38a9480532b83e4bfeb386f4bbd7b611b38.tar.lz
gsoc2013-evolution-3bedc38a9480532b83e4bfeb386f4bbd7b611b38.tar.xz
gsoc2013-evolution-3bedc38a9480532b83e4bfeb386f4bbd7b611b38.tar.zst
gsoc2013-evolution-3bedc38a9480532b83e4bfeb386f4bbd7b611b38.zip
Implement saving of configuration information. Now when you run
Evolution it will display the same folder as the last time, and will hide/show the shortcut/folder bars as the last time. This uses GConf so I also put a GConf check into configure.in. svn path=/trunk/; revision=3787
Diffstat (limited to 'shell')
-rw-r--r--shell/ChangeLog29
-rw-r--r--shell/Makefile.am4
-rw-r--r--shell/e-shell-view.c114
-rw-r--r--shell/e-shell-view.h7
-rw-r--r--shell/e-shell.c128
-rw-r--r--shell/e-shell.h10
-rw-r--r--shell/e-shortcuts.c2
-rw-r--r--shell/main.c24
8 files changed, 306 insertions, 12 deletions
diff --git a/shell/ChangeLog b/shell/ChangeLog
index 6c89d2f57f..99912fdfab 100644
--- a/shell/ChangeLog
+++ b/shell/ChangeLog
@@ -1,3 +1,32 @@
+2000-06-29 Ettore Perazzoli <ettore@helixcode.com>
+
+ * e-shortcuts.c (e_shortcuts_construct): Fix typo: @shortcuts
+ should unset `GTK_FLOATING', not @storage_set.
+
+ * e-shell-view.c (get_storage_set_path_from_uri): If @uri is NULL,
+ return NULL.
+
+ * main.c (idle_cb): Restore the shell from the settings. If this
+ fails, just create a new view.
+
+ * e-shell.c (e_shell_save_settings): New.
+ (e_shell_quit): Save settings before exiting.
+ (e_shell_restore_from_settings): New.
+
+ * e-shell-view.c (e_shell_view_save_settings): New.
+ (e_shell_view_load_settings): New.
+
+ * main.c (idle_cb): Initialize Gconf, create the GConfClient and
+ pass it to `e_shell_new()'.
+
+ * e-shell.c: New member `gconf_client' in `EShellPrivate'.
+ (destroy): Unref it if not NULL.
+ (init): Init to NULL.
+ (e_shell_new): New param @gconf_client.
+ (e_shell_construct): Likewise.
+
+ * Makefile.am (INCLUDES): Add `GCONF_CFLAGS'.
+
2000-06-27 Ettore Perazzoli <ettore@helixcode.com>
* e-shell-folder-title-bar.c (e_shell_folder_title_bar_construct):
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 149046412c..034403cc52 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -5,6 +5,7 @@ INCLUDES = \
-I$(top_srcdir)/widgets/misc \
-I$(top_srcdir) \
$(BONOBO_GNOME_CFLAGS) \
+ $(GCONF_CFLAGS) \
-DEVOLUTION_IMAGES=\""$(datadir)/images/evolution"\" \
-DEVOLUTION_VERSION=\""$(VERSION)"\" \
-DEVOLUTION_LOCALEDIR=\""$(datadir)/locale"\" \
@@ -105,7 +106,8 @@ evolution_LDADD = \
$(top_builddir)/widgets/e-text/libetext.a \
$(top_builddir)/widgets/misc/libemiscwidgets.a \
$(top_builddir)/e-util/libeutil.la \
- $(BONOBO_GNOME_LIBS)
+ $(BONOBO_GNOME_LIBS) \
+ $(GCONF_LIBS)
# Purify support
diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c
index e3b47c3d25..56ddd12b87 100644
--- a/shell/e-shell-view.c
+++ b/shell/e-shell-view.c
@@ -467,6 +467,9 @@ get_storage_set_path_from_uri (const char *uri)
{
const char *colon;
+ if (uri == NULL)
+ return NULL;
+
if (g_path_is_absolute (uri))
return NULL;
@@ -981,4 +984,115 @@ e_shell_view_get_current_uri (EShellView *shell_view)
}
+/**
+ * e_shell_view_save_settings:
+ * @shell_view:
+ * @gconf_client:
+ * @prefix:
+ *
+ * Save settings for @shell_view at the specified GConf @prefix through
+ * @gconf_client.
+ *
+ * Return value: TRUE if successful, FALSE if not.
+ **/
+gboolean
+e_shell_view_save_settings (EShellView *shell_view,
+ GConfClient *gconf_client,
+ const char *prefix)
+{
+ GConfError *err = NULL;
+ const char *uri;
+ char *path;
+
+ g_return_val_if_fail (shell_view != NULL, FALSE);
+ g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), FALSE);
+ g_return_val_if_fail (gconf_client != NULL, FALSE);
+ g_return_val_if_fail (GCONF_IS_CLIENT (gconf_client), FALSE);
+ g_return_val_if_fail (prefix != NULL, FALSE);
+ g_return_val_if_fail (g_path_is_absolute (prefix), FALSE);
+
+#define SET(type, key, value) \
+ path = g_strconcat (prefix, "/", (key), NULL); \
+ gconf_client_set_##type (gconf_client, path, (value), &err); \
+ g_free (path); \
+ if (err != NULL) { \
+ gconf_error_destroy (err); \
+ return FALSE; \
+ }
+
+ SET (int, "FolderBarMode", e_shell_view_get_folder_bar_mode (shell_view))
+ SET (int, "ShortcutBarMode", e_shell_view_get_shortcut_bar_mode (shell_view));
+
+ uri = e_shell_view_get_current_uri (shell_view);
+ if (uri != NULL) {
+ SET (string, "DisplayedURI", uri);
+ } else {
+ path = g_strconcat (prefix, "/", "DisplayedURI", NULL);
+ gconf_client_unset (gconf_client, path, &err);
+ g_free (path);
+
+ if (err != NULL) {
+ gconf_error_destroy (err);
+ return FALSE;
+ }
+ }
+
+#undef SET
+
+ return TRUE;
+}
+
+/**
+ * e_shell_view_load_settings:
+ * @shell_view:
+ * @gconf_client:
+ * @prefix:
+ *
+ * Load settings for @shell_view at the specified GConf @prefix through
+ * @gconf_client.
+ *
+ * Return value:
+ **/
+gboolean
+e_shell_view_load_settings (EShellView *shell_view,
+ GConfClient *gconf_client,
+ const char *prefix)
+{
+ gboolean val;
+ GConfError *err = NULL;
+ char *stringval;
+ char *path;
+
+ g_return_val_if_fail (shell_view != NULL, FALSE);
+ g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), FALSE);
+ g_return_val_if_fail (gconf_client != NULL, FALSE);
+ g_return_val_if_fail (GCONF_IS_CLIENT (gconf_client), FALSE);
+ g_return_val_if_fail (prefix != NULL, FALSE);
+ g_return_val_if_fail (g_path_is_absolute (prefix), FALSE);
+
+#define GET(type, key, value) \
+ path = g_strconcat (prefix, "/", (key), NULL); \
+ (value) = gconf_client_get_##type (gconf_client, path, &err); \
+ g_free (path); \
+ if (err != NULL) { \
+ gconf_error_destroy (err); \
+ return FALSE; \
+ }
+
+ GET (int, "FolderBarMode", val);
+ e_shell_view_set_folder_bar_mode (shell_view, val);
+
+ GET (int, "ShortcutBarMode", val);
+ e_shell_view_set_shortcut_bar_mode (shell_view, val);
+
+ GET (string, "DisplayedURI", stringval);
+ e_shell_view_display_uri (shell_view, stringval);
+ g_free (stringval);
+
+#undef GET
+
+ return TRUE;
+}
+
+
E_MAKE_TYPE (e_shell_view, "EShellView", EShellView, class_init, init, PARENT_TYPE)
diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h
index db066dd62e..603fe0ede0 100644
--- a/shell/e-shell-view.h
+++ b/shell/e-shell-view.h
@@ -91,6 +91,13 @@ BonoboUIHandler *e_shell_view_get_bonobo_ui_handler (EShellView
GtkWidget *e_shell_view_get_appbar (EShellView *shell_view);
const char *e_shell_view_get_current_uri (EShellView *shell_view);
+gboolean e_shell_view_save_settings (EShellView *shell_view,
+ GConfClient *gconf_client,
+ const char *prefix);
+gboolean e_shell_view_load_settings (EShellView *shell_view,
+ GConfClient *gconf_client,
+ const char *prefix);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/shell/e-shell.c b/shell/e-shell.c
index 85c76d20c1..81ebc368bd 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -59,6 +59,8 @@ struct _EShellPrivate {
EComponentRegistry *component_registry;
ECorbaStorageRegistry *corba_storage_registry;
+
+ GConfClient *gconf_client;
};
@@ -352,6 +354,9 @@ destroy (GtkObject *object)
if (priv->corba_storage_registry != NULL)
bonobo_object_unref (BONOBO_OBJECT (priv->corba_storage_registry));
+ if (priv->gconf_client != NULL)
+ gtk_object_unref (GTK_OBJECT (priv->gconf_client));
+
g_free (priv);
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
@@ -417,8 +422,9 @@ init (EShell *shell)
priv->storage_set = NULL;
priv->shortcuts = NULL;
priv->component_registry = NULL;
- priv->folder_type_registry = NULL;
+ priv->folder_type_registry = NULL;
priv->corba_storage_registry = NULL;
+ priv->gconf_client = NULL;
shell->priv = priv;
}
@@ -427,7 +433,8 @@ init (EShell *shell)
void
e_shell_construct (EShell *shell,
Evolution_Shell corba_object,
- const char *local_directory)
+ const char *local_directory,
+ GConfClient *gconf_client)
{
EShellPrivate *priv;
gchar *shortcut_path;
@@ -446,6 +453,9 @@ e_shell_construct (EShell *shell,
priv->folder_type_registry = e_folder_type_registry_new ();
priv->storage_set = e_storage_set_new (shell->priv->folder_type_registry);
+ gtk_object_ref (GTK_OBJECT (gconf_client));
+ priv->gconf_client = gconf_client;
+
/* CORBA storages must be set up before the components, because otherwise components
cannot register their own storages. */
if (! setup_corba_storages (shell))
@@ -472,7 +482,8 @@ e_shell_construct (EShell *shell,
}
EShell *
-e_shell_new (const char *local_directory)
+e_shell_new (const char *local_directory,
+ GConfClient *gconf_client)
{
EShell *new;
EShellPrivate *priv;
@@ -489,7 +500,7 @@ e_shell_new (const char *local_directory)
new = gtk_type_new (e_shell_get_type ());
corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (new), servant);
- e_shell_construct (new, corba_object, local_directory);
+ e_shell_construct (new, corba_object, local_directory, gconf_client);
priv = new->priv;
@@ -553,6 +564,113 @@ e_shell_get_folder_type_registry (EShell *shell)
}
+/**
+ * e_shell_save_settings:
+ * @shell:
+ *
+ * Save the settings for this shell.
+ *
+ * Return value: %TRUE if it worked, %FALSE otherwise. Even if %FALSE is
+ * returned, it is possible that at least part of the settings for the views
+ * have been saved.
+ **/
+gboolean
+e_shell_save_settings (EShell *shell)
+{
+ EShellPrivate *priv;
+ GList *p;
+ gboolean retval;
+ GConfError *err = NULL;
+ int i;
+
+ g_return_val_if_fail (shell != NULL, FALSE);
+ g_return_val_if_fail (E_IS_SHELL (shell), FALSE);
+
+ priv = shell->priv;
+
+ retval = TRUE;
+
+ for (p = priv->views, i = 0; p != NULL; p = p->next, i++) {
+ EShellView *view;
+ char *gconf_prefix;
+
+ view = E_SHELL_VIEW (p->data);
+
+ gconf_prefix = g_strdup_printf ("/app/Evolution/Shell/Views/%d", i);
+
+ if (! e_shell_view_save_settings (view, priv->gconf_client, gconf_prefix)) {
+ g_warning ("Cannot save settings for view -- %d", i);
+ retval = FALSE;
+ }
+
+ g_free (gconf_prefix);
+ }
+
+ gconf_client_set_int (priv->gconf_client, "/app/Evolution/Shell/NumberOfViews",
+ g_list_length (priv->views), &err);
+
+ return retval;
+}
+
+/**
+ * e_shell_restore_from_settings:
+ * @shell: An EShell object.
+ *
+ * Restore the existing views from the saved configuration. The shell must
+ * have no views for this to work.
+ *
+ * Return value: %FALSE if the shell has some open views or there is no saved
+ * configuration. %TRUE if the configuration could be restored successfully.
+ **/
+gboolean
+e_shell_restore_from_settings (EShell *shell)
+{
+ EShellPrivate *priv;
+ GConfError *err = NULL;
+ gboolean retval;
+ int num_views;
+ int i;
+
+ g_return_val_if_fail (shell != NULL, FALSE);
+ g_return_val_if_fail (E_IS_SHELL (shell), FALSE);
+ g_return_val_if_fail (shell->priv->views == NULL, FALSE);
+
+ priv = shell->priv;
+
+ num_views = gconf_client_get_int (priv->gconf_client, "/app/Evolution/Shell/NumberOfViews", &err);
+ if (err != NULL) {
+ gconf_error_destroy (err);
+ return FALSE;
+ }
+
+ retval = TRUE;
+
+ for (i = 0; i < num_views; i++) {
+ GtkWidget *view_widget;
+ char *gconf_prefix;
+
+ gconf_prefix = g_strdup_printf ("/app/Evolution/Shell/Views/%d", i);
+
+ /* FIXME restore the URI here. There should be an
+ e_shell_view_new_from_configuration() thingie. */
+ view_widget = e_shell_new_view (shell, NULL);
+
+ if (! e_shell_view_load_settings (E_SHELL_VIEW (view_widget), priv->gconf_client, gconf_prefix))
+ retval = FALSE;
+
+ g_free (gconf_prefix);
+ }
+
+ return retval;
+}
+
+/**
+ * e_shell_quit:
+ * @shell: An EShell.
+ *
+ * Make @shell quit. This will close all the associated views and destroy the
+ * object.
+ **/
void
e_shell_quit (EShell *shell)
{
@@ -562,6 +680,8 @@ e_shell_quit (EShell *shell)
g_return_if_fail (shell != NULL);
g_return_if_fail (E_IS_SHELL (shell));
+ e_shell_save_settings (shell);
+
priv = shell->priv;
for (p = priv->views; p != NULL; p = p->next) {
diff --git a/shell/e-shell.h b/shell/e-shell.h
index cf29daad9b..e9ccaa096f 100644
--- a/shell/e-shell.h
+++ b/shell/e-shell.h
@@ -29,6 +29,7 @@
#endif
#include <bonobo/bonobo-object.h>
+#include <gconf/gconf-client.h>
#include "Evolution.h"
#include "e-shortcuts.h"
@@ -65,9 +66,11 @@ struct _EShellClass {
GtkType e_shell_get_type (void);
void e_shell_construct (EShell *shell,
Evolution_Shell corba_object,
- const char *local_directory);
+ const char *local_directory,
+ GConfClient *gconf_client);
-EShell *e_shell_new (const char *local_directory);
+EShell *e_shell_new (const char *local_directory,
+ GConfClient *gconf_client);
GtkWidget *e_shell_new_view (EShell *shell,
const char *uri);
@@ -75,6 +78,9 @@ EShortcuts *e_shell_get_shortcuts (EShell *shell);
EStorageSet *e_shell_get_storage_set (EShell *shell);
EFolderTypeRegistry *e_shell_get_folder_type_registry (EShell *shell);
+gboolean e_shell_save_settings (EShell *shell);
+gboolean e_shell_restore_from_settings (EShell *shell);
+
void e_shell_quit (EShell *shell);
#ifdef __cplusplus
diff --git a/shell/e-shortcuts.c b/shell/e-shortcuts.c
index 4d3b51cc13..1828406df3 100644
--- a/shell/e-shortcuts.c
+++ b/shell/e-shortcuts.c
@@ -447,7 +447,7 @@ e_shortcuts_construct (EShortcuts *shortcuts,
g_return_if_fail (storage_set != NULL);
g_return_if_fail (E_IS_STORAGE_SET (storage_set));
- GTK_OBJECT_UNSET_FLAGS (GTK_OBJECT (storage_set), GTK_FLOATING);
+ GTK_OBJECT_UNSET_FLAGS (GTK_OBJECT (shortcuts), GTK_FLOATING);
priv = shortcuts->priv;
diff --git a/shell/main.c b/shell/main.c
index 974c0d210b..f40361cda0 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -157,11 +157,14 @@ static gint
idle_cb (gpointer data)
{
GtkWidget *view;
+ GConfClient *gconf_client;
char *evolution_directory;
evolution_directory = (char *) data;
- shell = e_shell_new (evolution_directory);
+ gconf_client = gconf_client_new ();
+
+ shell = e_shell_new (evolution_directory, gconf_client);
g_free (evolution_directory);
if (shell == NULL) {
@@ -175,19 +178,26 @@ idle_cb (gpointer data)
gtk_signal_connect (GTK_OBJECT (shell), "destroy",
GTK_SIGNAL_FUNC (destroy_cb), NULL);
- view = e_shell_new_view (shell, STARTUP_URI);
- gtk_signal_connect (GTK_OBJECT (view), "delete_event",
- GTK_SIGNAL_FUNC (view_delete_event_cb), shell);
+ if (! e_shell_restore_from_settings (shell)) {
+ view = e_shell_new_view (shell, STARTUP_URI);
+ /* FIXME: Do this for all the shell views even when the shell
+ is restored. */
+ gtk_signal_connect (GTK_OBJECT (view), "delete_event",
+ GTK_SIGNAL_FUNC (view_delete_event_cb), shell);
+ }
if (!getenv ("EVOLVE_ME_HARDER"))
development_warning ();
+ gtk_object_unref (GTK_OBJECT (gconf_client));
+
return FALSE;
}
int
main (int argc, char **argv)
{
+ GConfError *err = NULL;
char *evolution_directory;
bindtextdomain (PACKAGE, EVOLUTION_LOCALEDIR);
@@ -199,6 +209,12 @@ main (int argc, char **argv)
gnome_window_icon_set_default_from_file (EVOLUTION_IMAGES "/evolution-inbox.png");
+ if (! gconf_init (argc, argv, &err)) {
+ e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
+ _("Cannot initialize the configuration system."));
+ exit (1);
+ }
+
if (! bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL)) {
e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
_("Cannot initialize the Bonobo component system."));