[Gnucash-changes] Hook the file history list into gconf.
David Hampton
hampton at cvs.gnucash.org
Sun Apr 24 18:25:28 EDT 2005
Log Message:
-----------
Hook the file history list into gconf.
Tags:
----
gnucash-gnome2-dev
Modified Files:
--------------
gnucash:
configure.in
gnucash/src/app-file:
Makefile.am
gnc-file-history.c
gnc-file-history.h
gnc-file-p.h
gw-app-file-spec.scm
gnucash/src/gnome:
gnc-plugin-file-history.c
gnc-plugin-file-history.h
gnucash/src/gnome/ui:
gnc-plugin-file-history-ui.xml
Added Files:
-----------
gnucash/src/app-file/schemas:
.cvsignore
Makefile.am
apps_gnucash_history.schemas
Revision Data
-------------
Index: configure.in
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/configure.in,v
retrieving revision 1.359.2.46
retrieving revision 1.359.2.47
diff -Lconfigure.in -Lconfigure.in -u -r1.359.2.46 -r1.359.2.47
--- configure.in
+++ configure.in
@@ -1190,6 +1190,7 @@
src/app-file/Makefile
src/app-file/test/Makefile
src/app-file/gnome/Makefile
+ src/app-file/schemas/Makefile
src/app-utils/Makefile
src/app-utils/test/Makefile
src/backend/Makefile
Index: gw-app-file-spec.scm
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-file/gw-app-file-spec.scm,v
retrieving revision 1.4.4.1
retrieving revision 1.4.4.2
diff -Lsrc/app-file/gw-app-file-spec.scm -Lsrc/app-file/gw-app-file-spec.scm -u -r1.4.4.1 -r1.4.4.2
--- src/app-file/gw-app-file-spec.scm
+++ src/app-file/gw-app-file-spec.scm
@@ -54,7 +54,7 @@
(gw:wrap-function
ws
'gnc:history-get-last
- '(<gw:mchars> callee-owned const)
+ '(<gw:mchars> caller-owned)
"gnc_history_get_last"
'()
"Get the last file opened by the user.")
Index: gnc-file-p.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-file/gnc-file-p.h,v
retrieving revision 1.2.6.1
retrieving revision 1.2.6.2
diff -Lsrc/app-file/gnc-file-p.h -Lsrc/app-file/gnc-file-p.h -u -r1.2.6.1 -r1.2.6.2
--- src/app-file/gnc-file-p.h
+++ src/app-file/gnc-file-p.h
@@ -25,7 +25,7 @@
void gnc_file_init (void);
typedef void (*GNCHistoryAddFileFunc) (const char *filename);
-typedef const char * (*GNCHistoryGetLastFunc) (void);
+typedef char * (*GNCHistoryGetLastFunc) (void);
typedef char * (*GNCFileDialogFunc) (const char * title,
const char * filter,
Index: gnc-file-history.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-file/gnc-file-history.h,v
retrieving revision 1.1.6.1
retrieving revision 1.1.6.2
diff -Lsrc/app-file/gnc-file-history.h -Lsrc/app-file/gnc-file-history.h -u -r1.1.6.1 -r1.1.6.2
--- src/app-file/gnc-file-history.h
+++ src/app-file/gnc-file-history.h
@@ -1,6 +1,7 @@
/********************************************************************\
* gnc-file-history.h -- functions to maintain file-history menu *
* Copyright (C) 2000 Robby Stephenson *
+ * Copyright (C) 2005 David Hampton *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@@ -23,14 +24,14 @@
#ifndef GNC_FILE_HISTORY_H
#define GNC_FILE_HISTORY_H
-#define MAX_HISTORY_FILES 4 /* May be any number up to 10 */
+#define MAX_HISTORY_FILES 10 /* May be any number up to 10 */
+#define HISTORY_STRING_SECTION "history"
+#define HISTORY_STRING_MAXFILES "maxfiles"
+#define HISTORY_STRING_FILE_N "file%d"
-typedef void (*gnc_history_changed_cb) (void);
-
-void gnc_history_set_callback (gnc_history_changed_cb cb);
-void gnc_history_init_list (void);
void gnc_history_add_file (const char *filename);
-const char * gnc_history_get_last (void);
-const GList * gnc_history_get_file_list (void);
+char * gnc_history_get_last (void);
+gchar *gnc_history_gconf_index_to_key (guint index);
+gint gnc_history_gconf_key_to_index (const gchar *fullkey);
#endif
Index: gnc-file-history.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-file/Attic/gnc-file-history.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -Lsrc/app-file/gnc-file-history.c -Lsrc/app-file/gnc-file-history.c -u -r1.1.2.1 -r1.1.2.2
--- src/app-file/gnc-file-history.c
+++ src/app-file/gnc-file-history.c
@@ -1,6 +1,7 @@
/********************************************************************\
* gnc-file-history.c -- functions to maintain file history menu *
* Copyright (C) 2000 Robby Stephenson *
+ * Copyright (C) 2005 David Hampton *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@@ -26,135 +27,100 @@
#include <gnome.h>
#include "gnc-file.h"
#include "gnc-file-history.h"
+#include "gnc-gconf-utils.h"
-#define HISTORY_SECTION "/GnuCash/History/"
-
-static GList *history_list = NULL;
-static gnc_history_changed_cb history_changed_cb = NULL;
-
-void
-gnc_history_set_callback (gnc_history_changed_cb cb)
+gchar *
+gnc_history_gconf_index_to_key (guint index)
{
- history_changed_cb = cb;
+ return g_strdup_printf(HISTORY_STRING_FILE_N, index);
}
-static void
-gnc_history_config_write (void)
+gint
+gnc_history_gconf_key_to_index (const gchar *fullkey)
{
- guint num_files, i;
- char key[20];
- GList *tmp;
-
- if (history_list == NULL)
- return;
-
- num_files = g_list_length(history_list);
- if (num_files == 0)
- return;
-
- gnome_config_clean_section (HISTORY_SECTION);
- gnome_config_push_prefix (HISTORY_SECTION);
- gnome_config_set_int ("MaxFiles", num_files);
-
- for (tmp = history_list, i = 0; tmp != NULL; tmp = g_list_next(tmp), i++)
- {
- g_sprintf(key, "File%d", i);
- gnome_config_set_string (key, tmp->data);
- }
+ char *key;
+ gint index, result;
- gnome_config_pop_prefix ();
- gnome_config_sync ();
+ key = rindex(fullkey, '/');
+ result = sscanf(key+1, HISTORY_STRING_FILE_N, &index);
+ return (result == 1) ? index : -1;
}
-
-void
-gnc_history_init_list (void)
-{
- int num_files, i;
- char key[20], *filename;
-
- gnome_config_push_prefix (HISTORY_SECTION);
-
- g_sprintf (key, "MaxFiles=%d", MAX_HISTORY_FILES);
- num_files = gnome_config_get_int (key);
- if (num_files > MAX_HISTORY_FILES)
- num_files = MAX_HISTORY_FILES;
-
- for (i = 0; i < num_files; i++)
- {
- g_sprintf (key, "File%d", i);
- filename = gnome_config_get_string (key);
- if (filename == NULL)
- continue;
- if (!g_utf8_validate(filename, -1, NULL))
- return;
- history_list = g_list_append (history_list, filename);
- }
-
- gnome_config_pop_prefix ();
-}
-
-
void
gnc_history_add_file (const char *newfile)
{
- GList *tmp;
+ gchar *filename, *from, *to;
+ gint i, last;
if (newfile == NULL)
return;
if (!g_utf8_validate(newfile, -1, NULL))
return;
- if (history_list == NULL)
- gnc_history_init_list ();
+ /*
+ * Look for the filename in gconf.
+ */
+ last = MAX_HISTORY_FILES - 1;
+ for (i = 0; i < MAX_HISTORY_FILES; i++) {
+ from = g_strdup_printf(HISTORY_STRING_FILE_N, i);
+ filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, from, NULL);
+ g_free(from);
- /* See if its already there. If so, move to the top. */
- for (tmp = history_list; tmp; tmp = g_list_next(tmp)) {
- if (g_utf8_collate (newfile, tmp->data) == 0) {
- history_list = g_list_remove_link (history_list, tmp);
- history_list = g_list_concat (tmp, history_list);
+ if (!filename) {
+ last = i;
break;
}
+ if (g_utf8_collate(newfile, filename) == 0) {
+ g_free(filename);
+ last = i;
+ break;
+ }
+ g_free(filename);
}
- /* If not there, add a new item at the top. */
- if (tmp == NULL) {
- history_list = g_list_prepend (history_list, g_strdup(newfile));
- }
-
- /* Trim the list if necessary*/
- if (g_list_length(history_list) > MAX_HISTORY_FILES) {
- tmp = g_list_last(history_list);
- g_free(tmp->data);
- history_list = g_list_delete_link(history_list, tmp);
+ /*
+ * Shuffle filenames upward through gconf.
+ */
+ to = g_strdup_printf(HISTORY_STRING_FILE_N, last);
+ for (i = last - 1; i >= 0; i--) {
+ from = g_strdup_printf(HISTORY_STRING_FILE_N, i);
+ filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, from, NULL);
+ if (filename) {
+ gnc_gconf_set_string(HISTORY_STRING_SECTION, to, filename, NULL);
+ g_free(filename);
+ } else {
+ gnc_gconf_unset(HISTORY_STRING_SECTION, to, NULL);
+ }
+ g_free(to);
+ to = from;
}
- /* Write the new list to disk */
- gnc_history_config_write ();
-
- /* Update the menus actions */
- if (history_changed_cb)
- history_changed_cb();
+ /*
+ * Store the new zero entry.
+ */
+ gnc_gconf_set_string(HISTORY_STRING_SECTION, to, newfile, NULL);
}
-const GList *
-gnc_history_get_file_list (void)
-{
- if (history_list == NULL)
- gnc_history_init_list ();
-
- return history_list;
-}
-
-const char *
+char *
gnc_history_get_last (void)
{
- if (history_list == NULL)
- gnc_history_init_list ();
+ static char *filename = NULL;
+ char *key;
+
+ /* The static string supports the current signature of this
+ * function. At some point this should be changed to pass the
+ * allocated string up to the caller and make them responsible for
+ * freeing irt, but that change percolates up into the scheme code
+ * and requires changing that as well. */
+ if (filename) {
+ g_free(filename);
+ filename = NULL;
+ }
- if (history_list == NULL)
- return NULL;
+ key = g_strdup_printf(HISTORY_STRING_FILE_N, 0);
+ filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, key, NULL);
+ g_free(key);
- return g_list_last(history_list)->data;
+ return filename;
}
Index: Makefile.am
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-file/Makefile.am,v
retrieving revision 1.15.4.3
retrieving revision 1.15.4.4
diff -Lsrc/app-file/Makefile.am -Lsrc/app-file/Makefile.am -u -r1.15.4.3 -r1.15.4.4
--- src/app-file/Makefile.am
+++ src/app-file/Makefile.am
@@ -1,9 +1,10 @@
-SUBDIRS = gnome . test
+SUBDIRS = gnome schemas . test
PWD := $(shell pwd)
pkglib_LTLIBRARIES = libgncmod-app-file.la libgw-app-file.la
AM_CFLAGS = \
+ -I${top_srcdir}/src/core-utils \
-I${top_srcdir}/src/gnc-module \
-I${top_srcdir}/src \
-I${top_srcdir}/src/engine \
@@ -32,6 +33,7 @@
libgncmod_app_file_la_LDFLAGS = -module
libgncmod_app_file_la_LIBADD = \
+ ../core-utils/libcore-utils.la \
../gnc-module/libgncmodule.la \
../engine/libgncmod-engine.la \
../gnome-utils/libgncmod-gnome-utils.la \
--- /dev/null
+++ src/app-file/schemas/.cvsignore
@@ -0,0 +1,8 @@
+*.diff
+*.la
+*.lo
+.deps
+.libs
+.scm-links
+Makefile
+Makefile.in
--- /dev/null
+++ src/app-file/schemas/apps_gnucash_history.schemas
@@ -0,0 +1,58 @@
+<gconfschemafile>
+ <schemalist>
+ <schema>
+ <key>/schemas/apps/gnucash/history/maxfiles</key>
+ <applyto>/apps/gnucash/history/maxfiles</applyto>
+ <owner>gnucash</owner>
+ <type>int</type>
+ <default>4</default>
+ <locale name="C">
+ <short>Number of files in history</short>
+ <long>
+ This key contains the number of files to keep in the
+ Recently Opened Files menu. This value may be set to zero to
+ disable the file history. This number has a maximum value
+ of 10.
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
+ <key>/schemas/apps/gnucash/history/first_file</key>
+ <applyto>/apps/gnucash/history/file0</applyto>
+ <owner>gnucash</owner>
+ <type>string</type>
+ <default></default>
+ <locale name="C">
+ <short>Most recently opened file</short>
+ <long>
+ This key contains the full path of the most recently opened file.
+ </long>
+ </locale>
+ </schema>
+
+
+ <schema>
+ <key>/schemas/apps/gnucash/history/other_files</key>
+ <applyto>/apps/gnucash/history/file1</applyto>
+ <applyto>/apps/gnucash/history/file2</applyto>
+ <applyto>/apps/gnucash/history/file3</applyto>
+ <applyto>/apps/gnucash/history/file4</applyto>
+ <applyto>/apps/gnucash/history/file5</applyto>
+ <applyto>/apps/gnucash/history/file6</applyto>
+ <applyto>/apps/gnucash/history/file7</applyto>
+ <applyto>/apps/gnucash/history/file8</applyto>
+ <applyto>/apps/gnucash/history/file9</applyto>
+ <owner>gnucash</owner>
+ <type>string</type>
+ <default></default>
+ <locale name="C">
+ <short>Next most recently opened file</short>
+ <long>
+ This key contains the full path of the next most recently opened file.
+ </long>
+ </locale>
+ </schema>
+
+ </schemalist>
+</gconfschemafile>
--- /dev/null
+++ src/app-file/schemas/Makefile.am
@@ -0,0 +1,14 @@
+schemadir = @GCONF_SCHEMA_FILE_DIR@
+schema_DATA = \
+ apps_gnucash_history.schemas
+
+install-data-local:
+if GCONF_SCHEMAS_INSTALL
+ -GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) gconftool-2 --makefile-install-rule $(srcdir)/$(schema_DATA)
+endif
+
+uninstall-local:
+if GCONF_SCHEMAS_INSTALL
+ -GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) gconftool-2 --makefile-uninstall-rule $(srcdir)/$(schema_DATA)
+endif
+
Index: gnc-plugin-file-history.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/Attic/gnc-plugin-file-history.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -Lsrc/gnome/gnc-plugin-file-history.h -Lsrc/gnome/gnc-plugin-file-history.h -u -r1.1.2.2 -r1.1.2.3
--- src/gnome/gnc-plugin-file-history.h
+++ src/gnome/gnc-plugin-file-history.h
@@ -1,6 +1,6 @@
/*
* gnc-plugin-file-history.h --
- * Copyright (C) 2003 David Hampton <hampton at employees.org>
+ * Copyright (C) 2003,2005 David Hampton <hampton at employees.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -20,6 +20,13 @@
* Boston, MA 02111-1307, USA gnu at gnu.org
*/
+/** @addtogroup GUI
+ @{ */
+/** @file gnc-plugin-file-history.h
+ @brief Utility functions for writing import modules.
+ @author Copyright (C) 2002 David Hampton <hampton at empployees.org>
+*/
+
#ifndef __GNC_PLUGIN_FILE_HISTORY_H
#define __GNC_PLUGIN_FILE_HISTORY_H
@@ -51,10 +58,23 @@
} GncPluginFileHistoryClass;
/* function prototypes */
+
+
+/** Get the type of a file history plugin.
+ *
+ * @return A GType.
+ */
GType gnc_plugin_file_history_get_type (void);
+/** Create a new file history plugin. This plugin attaches the file
+ * history menu to any window that is opened.
+ *
+ * @return A pointer to the new object.
+ */
GncPlugin *gnc_plugin_file_history_new (void);
G_END_DECLS
#endif /* __GNC_PLUGIN_FILE_HISTORY_H */
+
+/** @} */
Index: gnc-plugin-file-history.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/Attic/gnc-plugin-file-history.c,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -Lsrc/gnome/gnc-plugin-file-history.c -Lsrc/gnome/gnc-plugin-file-history.c -u -r1.1.2.6 -r1.1.2.7
--- src/gnome/gnc-plugin-file-history.c
+++ src/gnome/gnc-plugin-file-history.c
@@ -1,6 +1,6 @@
/*
* gnc-plugin-file-history.c --
- * Copyright (C) 2003 David Hampton hampton at employees.org>
+ * Copyright (C) 2003,2005 David Hampton hampton at employees.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -20,6 +20,14 @@
* Boston, MA 02111-1307, USA gnu at gnu.org
*/
+/** @addtogroup GUI
+ @{ */
+/** @internal
+ @file gnc-plugin-file-history.h
+ @brief Utility functions for writing import modules.
+ @author Copyright (C) 2002 David Hampton <hampton at empployees.org>
+*/
+
#include "config.h"
#include <string.h>
@@ -31,7 +39,9 @@
#include "gnc-main-window.h"
#include "gnc-plugin-file-history.h"
#include "gnc-window.h"
+#include "gnc-trace.h"
#include "messages.h"
+#include "gnc-gconf-utils.h"
static GList *active_plugins = NULL;
static GObjectClass *parent_class = NULL;
@@ -43,9 +53,12 @@
static void gnc_plugin_file_history_finalize (GObject *object);
static void gnc_plugin_file_history_add_to_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
+static void gnc_plugin_file_history_remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
+
+static short module = MOD_GUI;
/* Command callbacks */
-static void gnc_plugin_file_history_cmd_open_file (GtkAction *action, GncPlugin *plugin);
+static void gnc_plugin_file_history_cmd_open_file (GtkAction *action, GncMainWindowActionData *data);
#define PLUGIN_ACTIONS_NAME "gnc-plugin-file-history-actions"
@@ -77,7 +90,15 @@
* Other Functions *
************************************************************/
-/* Caller is responsible for g_free'ing returned memory */
+/** This routine takes a filename and modifies it so that it will
+ * display correctly in a GtkLabel. It also adds a mnemonic to
+ * the start of the menu item.
+ *
+ * @filename A pointer to the filename to mangle.
+ *
+ * @return A pointer to the mangled filename. The Caller is
+ * responsible for freeing this memory.
+ */
static gchar *
gnc_history_generate_label (int index, const gchar *filename)
{
@@ -88,7 +109,7 @@
/* raw byte length, not num characters */
result = g_malloc(strlen(filename) * 2);
- dst = result + g_sprintf(result, "_%d ", index % 10);
+ dst = result + g_sprintf(result, "_%d ", index);
for (src = filename; *src; src = g_utf8_next_char(src)) {
unichar = g_utf8_get_char(src);
dst += g_unichar_to_utf8 (unichar, dst);
@@ -101,66 +122,129 @@
return result;
}
+
+/** Update one entry in the file history menu. This function is
+ * called by either the gnc_plugin_history_list_changed function or
+ * the gnc_history_update_menus function. It updates the specified
+ * file history item in the specified window.
+ *
+ * This routine attaches the actual filename to the menu_item (via
+ * g_object_set_data) for later retrieval. It also massages the
+ * filename so that it will display correctly in the menu, and also
+ * add a mnemonic for the menu item.
+ *
+ * @window A pointer to window whose file history should be updated.
+ *
+ * @index Update this item in the menu (base-0).
+ *
+ * @filename The new filename to associate with this menu item.
+ */
static void
-gnc_history_update_menus (GncPlugin *plugin)
+gnc_history_update_action (GncMainWindow *window,
+ gint index,
+ const gchar *filename)
{
- GncMainWindow *window;
GtkActionGroup *action_group;
GtkAction *action;
- gchar action_name[40], *label_name, *old_filename;
- const GList *history_list, *tmp;
- GValue label = { 0 };
- guint i;
-
- /* Get the history list */
- history_list = gnc_history_get_file_list();
- if (history_list == NULL)
- return;
+ gchar *action_name, *label_name, *old_filename;
+ ENTER("window %p, index %d, filename %s", window, index, filename);
/* Get the action group */
- window = GNC_MAIN_WINDOW(plugin->window);
action_group =
gnc_main_window_get_action_group(window, PLUGIN_ACTIONS_NAME);
- /* Build the menu */
- g_value_init (&label, G_TYPE_STRING);
- for (tmp = history_list, i = 1; tmp; tmp = g_list_next(tmp), i++) {
- /* Find or create the action object */
- g_sprintf(action_name, "RecentFile%dAction", i % 10);
- action = gtk_action_group_get_action (action_group, action_name);
+ action_name = g_strdup_printf("RecentFile%dAction", index);
+ action = gtk_action_group_get_action (action_group, action_name);
+ if (filename && (strlen(filename) > 0)) {
/* set the menu label (w/accelerator) */
- label_name = gnc_history_generate_label(i, tmp->data);
- g_value_set_string (&label, label_name);
- g_object_set_property (G_OBJECT(action), "label", &label);
+ label_name = gnc_history_generate_label(index, filename);
+ g_object_set(G_OBJECT(action), "label", label_name, "visible", TRUE, NULL);
g_free(label_name);
/* set the filename for the callback function */
old_filename = g_object_get_data(G_OBJECT(action), FILENAME_STRING);
if (old_filename)
g_free(old_filename);
- g_object_set_data(G_OBJECT(action), FILENAME_STRING, g_strdup(tmp->data));
+ g_object_set_data(G_OBJECT(action), FILENAME_STRING, g_strdup(filename));
+ } else {
+ g_object_set(G_OBJECT(action), "visible", FALSE, NULL);
}
- g_value_unset(&label);
-
- gnc_main_window_actions_updated (window);
+ g_free(action_name);
+ LEAVE("");
}
+
+/** Update an entry in the file history menu because a gconf entry
+ * changed. This function is called whenever an item in the gconf
+ * history section is changed. It is responsible for updating the
+ * menu item that corresponds to that key.
+ *
+ * @client A pointer to gconf client that noticed an entry change.
+ *
+ * @cnxn_id Unused.
+ *
+ * @entry A pointer to gconf entry that changed.
+ *
+ * @user_data A pointer to the window that this gconf client is
+ * associated with.
+ */
static void
-gnc_plugin_file_history_update_helper (GncPlugin *plugin,
- gpointer user_data)
+gnc_plugin_history_list_changed (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ gpointer user_data)
{
- gnc_history_update_menus (plugin);
+ GncMainWindow *window;
+ GConfValue *value;
+ const gchar *key, *filename;
+ gint index;
+
+ ENTER("");
+ key = gconf_entry_get_key(entry);
+ index = gnc_history_gconf_key_to_index(key);
+ if (index < 0)
+ return;
+
+ window = GNC_MAIN_WINDOW(user_data);
+ value = gconf_entry_get_value(entry);
+ if (!value) {
+ LEAVE("No gconf value");
+ return;
+ }
+ filename = gconf_value_get_string(value);
+ gnc_history_update_action (window, index, filename);
+
+ gnc_main_window_actions_updated (window);
+ LEAVE("");
}
+/** Update the file history menu for a window. This function walks
+ * the list of all possible gconf keys for the file history and
+ * forces a read/menu update on each key. It should only be called
+ * once when the window is created.
+ *
+ * @window A pointer to the window whose file history menu should be
+ * updated.
+ */
static void
-gnc_plugin_file_history_update_all (void)
+gnc_history_update_menus (GncMainWindow *window)
{
- g_list_foreach(active_plugins,
- (GFunc)gnc_plugin_file_history_update_helper,
- NULL);
+ gchar *filename, *key;
+ guint i;
+
+ ENTER("");
+ for (i = 0; i < MAX_HISTORY_FILES; i++) {
+ key = g_strdup_printf(HISTORY_STRING_FILE_N, i);
+ filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, key, NULL);
+ gnc_history_update_action(window, i, filename);
+ g_free(filename);
+ g_free(key);
+ }
+ LEAVE("");
}
+
/************************************************************
* Object Implementation *
************************************************************/
@@ -221,6 +305,7 @@
/* function overrides */
plugin_class->add_to_window = gnc_plugin_file_history_add_to_window;
+ plugin_class->remove_from_window = gnc_plugin_file_history_remove_from_window;
/* widget addition/removal */
plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
@@ -228,8 +313,8 @@
plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME;
- /* hook in callback functions */
- gnc_history_set_callback (gnc_plugin_file_history_update_all);
+ plugin_class->gconf_section = HISTORY_STRING_SECTION;
+ plugin_class->gconf_notifications = gnc_plugin_history_list_changed;
#if DEBUG_REFERENCE_COUNTING
gtk_quit_add (0,
@@ -241,9 +326,11 @@
static void
gnc_plugin_file_history_init (GncPluginFileHistory *plugin)
{
+ ENTER("plugin %p", plugin);
plugin->priv = g_new0 (GncPluginFileHistoryPrivate, 1);
active_plugins = g_list_append (active_plugins, plugin);
+ LEAVE("");
}
static void
@@ -254,15 +341,14 @@
g_return_if_fail (GNC_IS_PLUGIN_FILE_HISTORY (object));
plugin = GNC_PLUGIN_FILE_HISTORY (object);
+ ENTER("plugin %p", plugin);
active_plugins = g_list_remove (active_plugins, plugin);
g_return_if_fail (plugin->priv != NULL);
-
g_free (plugin->priv);
- active_plugins = g_list_remove (active_plugins, plugin);
-
G_OBJECT_CLASS (parent_class)->finalize (object);
+ LEAVE("");
}
GncPlugin *
@@ -270,39 +356,95 @@
{
GncPlugin *plugin_page = NULL;
+ ENTER("");
plugin_page = GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_FILE_HISTORY, NULL));
return plugin_page;
+ LEAVE("plugin %p", plugin_page);
}
/************************************************************
* Plugin Function Implementation *
************************************************************/
+/** Initialize the file history menu for a window. This function is
+ * called as part of the initialization of a window, after all the
+ * plugin menu items have been added to the menu structure. Its job
+ * is to correctly initialize the file history menu. It does this by
+ * first calling a function that initializes the menu to the current
+ * as maintained in gconf. It then creates a gconf client that will
+ * listens for any changes to the file history menu, and will update
+ * the meny when they are signalled.
+ *
+ * @param plugin A pointer to the gnc-plugin object responsible for
+ * adding/removing the file history menu.
+ *
+ * @param window A pointer the gnc-main-window that is being initialized.
+ *
+ * @param type Unused
+ */
static void
gnc_plugin_file_history_add_to_window (GncPlugin *plugin,
GncMainWindow *window,
GQuark type)
{
- gnc_history_update_menus (plugin);
+ gnc_history_update_menus(window);
+}
+
+
+/** Finalize the file history menu for this window. This function is
+ * called as part of the destruction of a window.
+ *
+ * @param plugin A pointer to the gnc-plugin object responsible for
+ * adding/removing the file history menu. It stops the gconf
+ * notifications for this window, and destroys the gconf client
+ * object.
+ *
+ * @param window A pointer the gnc-main-window that is being destroyed.
+ *
+ * @param type Unused
+ */
+static void
+gnc_plugin_file_history_remove_from_window (GncPlugin *plugin,
+ GncMainWindow *window,
+ GQuark type)
+{
}
/************************************************************
* Command Callbacks *
************************************************************/
+/** The user has selected one of the items in the File History menu.
+ * Close down the current session and start up a new one with the
+ * requested file.
+ *
+ * @param action A pointer to the action selected by the user. This
+ * action represents one of the items in the file history menu.
+ *
+ * @param data A pointer to the gnc-main-window data to be used by
+ * this function. This is mainly to find out which window it was
+ * that had a menu selected. That's not really important for this
+ * function and we're about to close all the windows anyway.
+ */
static void
gnc_plugin_file_history_cmd_open_file (GtkAction *action,
- GncPlugin *plugin)
+ GncMainWindowActionData *data)
{
gchar *filename;
g_return_if_fail(GTK_IS_ACTION(action));
- g_return_if_fail(GNC_IS_PLUGIN(plugin));
+ g_return_if_fail(data != NULL);
+ /* DRH - Do we need to close all open windows but the first?
+ * Which progressbar should we be using? One in a window, or
+ * in a new "file loading" dialog???
+ */
filename = g_object_get_data(G_OBJECT(action), FILENAME_STRING);
- gnc_window_set_progressbar_window (GNC_WINDOW(plugin->window));
+ gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
gnc_file_open_file (filename); /* also opens new account page */
gnc_window_set_progressbar_window (NULL);
- gnc_main_window_update_title (plugin->window);
+ gnc_main_window_update_title (data->window);
/* FIXME GNOME 2 Port (update the title etc.) */
}
+
+/** @} */
Index: gnc-plugin-file-history-ui.xml
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/ui/Attic/gnc-plugin-file-history-ui.xml,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -Lsrc/gnome/ui/gnc-plugin-file-history-ui.xml -Lsrc/gnome/ui/gnc-plugin-file-history-ui.xml -u -r1.1.2.1 -r1.1.2.2
--- src/gnome/ui/gnc-plugin-file-history-ui.xml
+++ src/gnome/ui/gnc-plugin-file-history-ui.xml
@@ -3,6 +3,7 @@
<menu name="File" action="FileAction">
<placeholder name="FileOpenRecentPlaceholder">
<menu name="FileOpenRecent" action="FileOpenRecentAction">
+ <menuitem name="RecentFile0" action="RecentFile0Action"/>
<menuitem name="RecentFile1" action="RecentFile1Action"/>
<menuitem name="RecentFile2" action="RecentFile2Action"/>
<menuitem name="RecentFile3" action="RecentFile3Action"/>
@@ -12,7 +13,6 @@
<menuitem name="RecentFile7" action="RecentFile7Action"/>
<menuitem name="RecentFile8" action="RecentFile8Action"/>
<menuitem name="RecentFile9" action="RecentFile9Action"/>
- <menuitem name="RecentFile0" action="RecentFile0Action"/>
</menu>
</placeholder>
</menu>
More information about the gnucash-changes
mailing list