[Gnucash-changes] Move the summary bar to the body of the page, just below the account

David Hampton hampton at cvs.gnucash.org
Sun Apr 24 19:40:28 EDT 2005


Log Message:
-----------
Move the summary bar to the body of the page, just below the account
tree.  Implement support for changing the summary bar when the page
is changed, since the register page has a different summary bar.
Hook the main window in to use standard desktop gconf key to decide
if the toolbar is show as text/icons/both.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash/src/gnome:
        gnc-main-window.c
        gnc-plugin-page-account-tree.c
        gnc-plugin-page.c
        gnc-plugin-page.h
        window-main-summarybar.c

Revision Data
-------------
Index: gnc-plugin-page.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/Attic/gnc-plugin-page.c,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -Lsrc/gnome/gnc-plugin-page.c -Lsrc/gnome/gnc-plugin-page.c -u -r1.1.2.11 -r1.1.2.12
--- src/gnome/gnc-plugin-page.c
+++ src/gnome/gnc-plugin-page.c
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2003 Jan Arne Petersen
  * Author: Jan Arne Petersen <jpetersen at uni-bonn.de>
+ * 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
@@ -249,6 +250,7 @@
 	plugin_page->uri         = NULL;
 
 	plugin_page->window      = NULL;
+	plugin_page->summarybar  = NULL;
 }
 
 static void
@@ -279,6 +281,10 @@
   g_free (priv);
   page->priv = NULL;
 
+  if (page->summarybar) {
+    g_object_unref(G_OBJECT(page->summarybar));
+    page->summarybar = NULL;
+  }
   page->window = NULL; // Don't need to free it.
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
Index: gnc-plugin-page-account-tree.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/Attic/gnc-plugin-page-account-tree.c,v
retrieving revision 1.1.2.36
retrieving revision 1.1.2.37
diff -Lsrc/gnome/gnc-plugin-page-account-tree.c -Lsrc/gnome/gnc-plugin-page-account-tree.c -u -r1.1.2.36 -r1.1.2.37
--- src/gnome/gnc-plugin-page-account-tree.c
+++ src/gnome/gnc-plugin-page-account-tree.c
@@ -51,6 +51,7 @@
 #include "option-util.h"
 #include "window-reconcile.h"
 #include "window-register.h"
+#include "window-main-summarybar.h"
 
 #include "messages.h"
 #include "gnc-engine-util.h"
@@ -470,10 +471,12 @@
 static void
 gnc_plugin_page_account_tree_close_cb (gpointer user_data)
 {
-  GncPluginPage *page;
+  GncPluginPage *plugin_page;
+  GncPluginPageAccountTree *page;
 
-  page = GNC_PLUGIN_PAGE(user_data);
-  gnc_main_window_close_page (GNC_MAIN_WINDOW(page->window), page);
+  plugin_page = GNC_PLUGIN_PAGE(user_data);
+  page = GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page);
+  gnc_main_window_close_page(GNC_MAIN_WINDOW(plugin_page->window), plugin_page);
 }
 
 static GtkWidget *
@@ -527,6 +530,9 @@
 	gnc_gui_component_set_session (page->priv->component_id,
 				       gnc_get_current_session());
 
+	plugin_page->summarybar = gnc_main_window_summary_new();
+	gtk_widget_show(plugin_page->summarybar);
+
 	LEAVE("widget = %p", page->priv->widget);
 	return page->priv->widget;
 }
@@ -548,6 +554,11 @@
 	  page->priv->component_id = 0;
 	}
 
+	if (plugin_page->summarybar) {
+	  g_object_unref(G_OBJECT(plugin_page->summarybar));
+	  plugin_page->summarybar = NULL;
+	}
+
 	LEAVE("widget destroyed");
 }
 
Index: window-main-summarybar.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/window-main-summarybar.c,v
retrieving revision 1.12.4.3
retrieving revision 1.12.4.4
diff -Lsrc/gnome/window-main-summarybar.c -Lsrc/gnome/window-main-summarybar.c -u -r1.12.4.3 -r1.12.4.4
--- src/gnome/window-main-summarybar.c
+++ src/gnome/window-main-summarybar.c
@@ -622,7 +622,8 @@
 }
 
 static void
-gnc_main_window_summary_destroy_cb(GtkObject * obj, gpointer data) {
+gnc_main_window_summary_destroy_cb(GtkObject * obj, gpointer data)
+{
   GNCMainSummary * summary = data;
   gnc_unregister_option_change_callback_id(summary->callback_id);
   gnc_unregister_gui_component(summary->component_id);
@@ -631,19 +632,22 @@
 }
 
 static void
-summarybar_refresh_handler(GHashTable * changes, gpointer user_data) {
+summarybar_refresh_handler(GHashTable * changes, gpointer user_data)
+{
   GNCMainSummary * summary = user_data;
   gnc_main_window_summary_refresh(summary);
 }
 
 static void
-summarybar_option_change_handler(gpointer user_data) {
+summarybar_option_change_handler(gpointer user_data)
+{
   GNCMainSummary * summary = user_data;
   gnc_main_window_summary_refresh(summary);
 }
 
 GtkWidget *
-gnc_main_window_summary_new (void) {
+gnc_main_window_summary_new (void)
+{
   GNCMainSummary  * retval = g_new0(GNCMainSummary, 1);
   GNCCurrencyItem * def_item;
   gnc_commodity   * default_currency = gnc_default_report_currency ();
Index: gnc-main-window.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/Attic/gnc-main-window.c,v
retrieving revision 1.1.2.38
retrieving revision 1.1.2.39
diff -Lsrc/gnome/gnc-main-window.c -Lsrc/gnome/gnc-main-window.c -u -r1.1.2.38 -r1.1.2.39
--- src/gnome/gnc-main-window.c
+++ src/gnome/gnc-main-window.c
@@ -3,7 +3,7 @@
  *	GnuCash main window.
  *
  * Copyright (C) 2003 Jan Arne Petersen <jpetersen at uni-bonn.de>
- * 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
@@ -54,10 +54,10 @@
 #include "gnc-version.h"
 #include "gnc-window.h"
 #include "window-main.h"
-#include "window-main-summarybar.h"
 #include "messages.h"
 #include "druid-merge.h"
 #include "dialog-chart-export.h"
+#include "gnc-gconf-utils.h"
 // +JSLED
 #include "gnc-html.h"
 
@@ -68,6 +68,9 @@
 };
 
 
+#define DESKTOP_GNOME_INTERFACE "/desktop/gnome/interface"
+#define TOOLBAR_STYLE "/desktop/gnome/interface/toolbar_style"
+
 /** Static Globals *******************************************************/
 static short module = MOD_GUI;
 static GList *active_windows = NULL;
@@ -133,8 +136,9 @@
 	GtkWidget *notebook;
 	GtkWidget *statusbar;
 	GtkWidget *progressbar;
-	
-	GtkWidget *gncSummaryBar;
+
+	GtkWidget *summarybar_dock;
+	gboolean   show_summarybar;
 
 	GtkActionGroup *action_group;
 
@@ -711,6 +715,8 @@
 
 	g_return_if_fail (window->priv != NULL);
 
+	gnc_gconf_remove_notification(G_OBJECT(window), DESKTOP_GNOME_INTERFACE);
+
 	gnc_engine_unregister_event_handler(window->priv->event_handler_id);
 	g_hash_table_destroy (window->priv->merged_actions_table);
 	g_free (window->priv);
@@ -744,6 +750,61 @@
 }
 
 static void
+gnc_main_window_update_toolbar (GncMainWindow *window,
+				const gchar *style)
+{
+	GEnumClass   *enum_class;
+	GEnumValue   *enum_value;
+	GSList       *list, *tmp;
+
+	ENTER("window %p, style %s", window, style);
+	enum_class = g_type_class_ref (GTK_TYPE_TOOLBAR_STYLE);
+	enum_value = g_enum_get_value_by_nick (enum_class, style);
+	if (!enum_value) {
+	  char *pre;
+
+	  pre = index(style, '_');
+	  if (pre == NULL)
+	    return;
+	  *pre = '-';
+	  enum_value = g_enum_get_value_by_nick (enum_class, style);
+	  if (!enum_value) {
+	    return;
+	  }
+	}
+
+	list = gtk_ui_manager_get_toplevels(window->ui_merge, GTK_UI_MANAGER_TOOLBAR);
+	for (tmp = list; tmp; tmp = tmp->next) {
+	  gtk_toolbar_set_style(GTK_TOOLBAR(tmp->data), enum_value->value);
+	}
+	g_slist_free(list);
+	LEAVE("");
+}
+
+static void
+gnc_main_window_gconf_changed (GConfClient *client,
+			       guint cnxn_id,
+			       GConfEntry *entry,
+			       gpointer user_data)
+{
+	GncMainWindow *window;
+	GConfValue *value;
+	const gchar *key;
+
+	window = GNC_MAIN_WINDOW(user_data);
+
+	key = gconf_entry_get_key(entry);
+	value = gconf_entry_get_value(entry);
+	if (!key || !value)
+	  return;
+
+	if (strcmp(key, TOOLBAR_STYLE) == 0) {
+	  gnc_main_window_update_toolbar(window, gconf_value_get_string(value));
+	  return;
+	}
+}
+
+static void
 gnc_main_window_setup_window (GncMainWindow *window)
 {
 	GncMainWindowPrivate *priv;
@@ -752,7 +813,7 @@
 	GncPluginManager *manager;
 	GList *plugins;
 	GError *error = NULL;
-	gchar *filename;
+	gchar *filename, *style;
 
 	/* Create widgets and add them to the window */
 	main_vbox = gtk_vbox_new (FALSE, 0);
@@ -774,18 +835,18 @@
 	gtk_box_pack_start (GTK_BOX (main_vbox), priv->notebook,
 			    TRUE, TRUE, 0);
 
+	priv->show_summarybar = TRUE;
+	priv->summarybar_dock = gtk_vbox_new (FALSE, 0);
+	gtk_widget_show (priv->summarybar_dock);
+	gtk_box_pack_start (GTK_BOX (main_vbox), priv->summarybar_dock,
+			    FALSE, TRUE, 0);
+
 	priv->statusbar = gtk_statusbar_new ();
 	gtk_widget_show (priv->statusbar);
 	gtk_box_pack_start (GTK_BOX (main_vbox), priv->statusbar,
 	                           FALSE, TRUE, 0);
         gtk_statusbar_set_has_resize_grip( GTK_STATUSBAR(priv->statusbar), TRUE );
 
-        priv->gncSummaryBar = gnc_main_window_summary_new();
-        gtk_widget_show( priv->gncSummaryBar );
-        gtk_box_pack_start( GTK_BOX(priv->statusbar), priv->gncSummaryBar, FALSE, TRUE, 0 );
-        // re-position at the beginning of the status area.
-        gtk_box_reorder_child( GTK_BOX(priv->statusbar), priv->gncSummaryBar, 0 );
-
 	priv->progressbar = gtk_progress_bar_new ();
 	gtk_widget_show (priv->progressbar);
 	gtk_box_pack_start (GTK_BOX (priv->statusbar), priv->progressbar,
@@ -824,6 +885,12 @@
 	  g_assert(merge_id != 0);
 	}
 
+	gnc_gconf_add_notification(G_OBJECT(window), DESKTOP_GNOME_INTERFACE,
+				   gnc_main_window_gconf_changed);
+	style = gnc_gconf_get_string(TOOLBAR_STYLE, NULL, NULL);
+	gnc_main_window_update_toolbar(window, style);
+	g_free(style);
+
         /* Testing */
         {
                 guint new_merge_id;
@@ -880,11 +947,18 @@
 }
 
 static void
+container_remove(GtkWidget *widget, gpointer data)
+{
+  gtk_container_remove(GTK_CONTAINER(data), widget);
+}
+
+
+static void
 gnc_main_window_switch_page_internal (GtkNotebook *notebook,
 				      gint pos,
 				      GncMainWindow *window)
 {
-	GtkWidget *child;
+	GtkWidget *child, *summarybar, *summarybar_dock;
 	GncPluginPage *page;
 
 	g_return_if_fail (GNC_IS_MAIN_WINDOW (window));
@@ -901,7 +975,34 @@
 	window->priv->current_page = page;
 
 	if (page != NULL) {
+		/* Update the user interface (e.g. menus and toolbars */
 		gnc_plugin_page_merge_actions (page, window->ui_merge);
+
+		/* Remove summarybar for old page */
+		summarybar_dock = window->priv->summarybar_dock;
+		gtk_container_foreach(GTK_CONTAINER(summarybar_dock),
+				      (GtkCallback)container_remove,
+				      summarybar_dock);
+
+		/* install new summarybar (if any) */
+		summarybar = page->summarybar;
+		if (summarybar) {
+		  if (GTK_OBJECT_FLOATING(summarybar)) {
+		    /* Own this object. This will prevent it from being deleted by
+		     * gtk when it is removed from the summarybar. */
+		    g_object_ref (summarybar);
+		    gtk_object_sink (GTK_OBJECT (summarybar));
+		  }
+
+		  if (window->priv->show_summarybar)
+		    gtk_widget_show(summarybar);
+		  else
+		    gtk_widget_hide(summarybar);
+		  gtk_box_pack_start(GTK_BOX(summarybar_dock), summarybar,
+				     FALSE, TRUE, 0 );
+		}
+
+		/* Allow page specific actions */
 		gnc_plugin_page_selected (page);
 		gnc_window_update_status (GNC_WINDOW(window), page);
 	}
@@ -1164,6 +1265,11 @@
 static void
 gnc_main_window_cmd_view_summary (GtkAction *action, GncMainWindow *window)
 {
+	if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))) {
+		gtk_widget_show (window->priv->summarybar_dock);
+	} else {
+		gtk_widget_hide (window->priv->summarybar_dock);
+	}
 }
 
 static void
Index: gnc-plugin-page.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/Attic/gnc-plugin-page.h,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -Lsrc/gnome/gnc-plugin-page.h -Lsrc/gnome/gnc-plugin-page.h -u -r1.1.2.13 -r1.1.2.14
--- src/gnome/gnc-plugin-page.h
+++ src/gnome/gnc-plugin-page.h
@@ -3,7 +3,7 @@
  *	GnuCash main window.
  *
  * Copyright (C) 2003 Jan Arne Petersen <jpetersen at uni-bonn.de>
- * 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
@@ -48,6 +48,7 @@
 
 	GtkWidget *window;
 	GtkWidget *notebook_page;
+	GtkWidget *summarybar;
 
 	gchar *title;
 	gchar *tab_name;


More information about the gnucash-changes mailing list