From eca687589d106ff87cd4fca7bf581cb0532caf96 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 5 Sep 2008 15:47:38 +0000 Subject: Saving progress. Lots of changes. Things are a bit broken at the moment. svn path=/branches/kill-bonobo/; revision=36260 --- shell/Makefile.am | 10 +- shell/e-shell-content.c | 217 ++++++++++ shell/e-shell-content.h | 66 +++ shell/e-shell-sidebar.c | 492 ++++++++++++++++++++++ shell/e-shell-sidebar.h | 79 ++++ shell/e-shell-switcher.c | 537 ++++++++++++++++++++++++ shell/e-shell-switcher.h | 76 ++++ shell/e-shell-view.c | 268 +++++------- shell/e-shell-view.h | 13 +- shell/e-shell-window-actions.c | 260 ++++++++++-- shell/e-shell-window-actions.h | 10 + shell/e-shell-window-private.c | 29 +- shell/e-shell-window-private.h | 10 +- shell/e-shell-window.c | 87 +--- shell/e-sidebar.c | 901 ----------------------------------------- shell/e-sidebar.h | 88 ---- shell/test/Makefile.am | 2 + shell/test/e-test-shell-view.c | 85 +--- 18 files changed, 1889 insertions(+), 1341 deletions(-) create mode 100644 shell/e-shell-content.c create mode 100644 shell/e-shell-content.h create mode 100644 shell/e-shell-sidebar.c create mode 100644 shell/e-shell-sidebar.h create mode 100644 shell/e-shell-switcher.c create mode 100644 shell/e-shell-switcher.h delete mode 100644 shell/e-sidebar.c delete mode 100644 shell/e-sidebar.h (limited to 'shell') diff --git a/shell/Makefile.am b/shell/Makefile.am index 0fc4fcab34..7bedc4e46d 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -4,6 +4,7 @@ endif INCLUDES = \ -I$(top_srcdir)/widgets \ + -I$(top_srcdir)/widgets/menus \ -I$(top_srcdir)/widgets/misc \ -I$(top_srcdir) \ -I$(top_srcdir)/shell \ @@ -56,7 +57,9 @@ eshellincludedir = $(privincludedir)/shell eshellinclude_HEADERS = \ e-shell-common.h \ + e-shell-content.h \ e-shell-module.h \ + e-shell-switcher.h \ e-shell-view.h \ e-shell-window.h \ e-shell-window-actions.h \ @@ -65,7 +68,9 @@ eshellinclude_HEADERS = \ libeshell_la_SOURCES = \ $(IDL_GENERATED) \ $(MARSHAL_GENERATED) \ + e-shell-content.c \ e-shell-module.c \ + e-shell-switcher.c \ e-shell-view.c \ e-shell-window.c \ e-shell-window-actions.c \ @@ -92,16 +97,17 @@ evolution_SOURCES = \ e-shell-importer.h \ e-shell-registry.c \ e-shell-registry.h \ + e-shell-sidebar.c \ + e-shell-sidebar.h \ e-shell-window-private.c \ e-shell-window-private.h \ - e-sidebar.c \ - e-sidebar.h \ es-event.c \ main.c evolution_LDADD = \ libeshell.la \ $(top_builddir)/widgets/e-timezone-dialog/libetimezonedialog.la \ + $(top_builddir)/widgets/menus/libmenus.la \ $(top_builddir)/widgets/misc/libemiscwidgets.la \ $(top_builddir)/e-util/libeutil.la \ $(TZDIALOG_LIBS) \ diff --git a/shell/e-shell-content.c b/shell/e-shell-content.c new file mode 100644 index 0000000000..22b2bc8af8 --- /dev/null +++ b/shell/e-shell-content.c @@ -0,0 +1,217 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-shell-shell_content.c + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "e-shell-content.h" + +#include + +#define E_SHELL_CONTENT_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_SHELL_CONTENT, EShellContentPrivate)) + +struct _EShellContentPrivate { + GtkWidget *search_bar; +}; + +static gpointer parent_class; + +static void +shell_content_dispose (GObject *object) +{ + EShellContentPrivate *priv; + + priv = E_SHELL_CONTENT_GET_PRIVATE (object); + + if (priv->search_bar != NULL) { + g_object_unref (priv->search_bar); + priv->search_bar = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +shell_content_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + EShellContentPrivate *priv; + GtkRequisition child_requisition; + GtkWidget *child; + + priv = E_SHELL_CONTENT_GET_PRIVATE (widget); + + requisition->width = 0; + requisition->height = 0; + + child = gtk_bin_get_child (GTK_BIN (widget)); + gtk_widget_size_request (child, requisition); + + child = priv->search_bar; + gtk_widget_size_request (child, &child_requisition); + requisition->width = MAX (requisition->width, child_requisition.width); + requisition->height += child_requisition.height; +} + +static void +shell_content_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + EShellContentPrivate *priv; + GtkAllocation child_allocation; + GtkRequisition child_requisition; + GtkWidget *child; + + priv = E_SHELL_CONTENT_GET_PRIVATE (widget); + + widget->allocation = *allocation; + + child = priv->search_bar; + gtk_widget_size_request (child, &child_requisition); + + child_allocation.x = allocation->x; + child_allocation.y = allocation->y; + child_allocation.width = allocation->width; + child_allocation.height = child_requisition.height; + + gtk_widget_size_allocate (child, &child_allocation); + + child_allocation.y += child_requisition.height; + child_allocation.height = allocation->height - child_allocation.y; + + child = gtk_bin_get_child (GTK_BIN (widget)); + if (child != NULL) + gtk_widget_size_allocate (child, &child_allocation); +} + +static void +shell_content_remove (GtkContainer *container, + GtkWidget *widget) +{ + EShellContentPrivate *priv; + + priv = E_SHELL_CONTENT_GET_PRIVATE (container); + + /* Look in the internal widgets first. */ + + if (widget == priv->search_bar) { + gtk_widget_unparent (priv->search_bar); + gtk_widget_queue_resize (GTK_WIDGET (container)); + return; + } + + /* Chain up to parent's remove() method. */ + GTK_CONTAINER_CLASS (parent_class)->remove (container, widget); +} + +static void +shell_content_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data) +{ + EShellContentPrivate *priv; + + priv = E_SHELL_CONTENT_GET_PRIVATE (container); + + if (include_internals) + callback (priv->search_bar, callback_data); + + /* Chain up to parent's forall() method. */ + GTK_CONTAINER_CLASS (parent_class)->forall ( + container, include_internals, callback, callback_data); +} + +static void +shell_content_class_init (EShellContentClass *class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + GtkContainerClass *container_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EShellContentPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->dispose = shell_content_dispose; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->size_request = shell_content_size_request; + widget_class->size_allocate = shell_content_size_allocate; + + container_class = GTK_CONTAINER_CLASS (class); + container_class->remove = shell_content_remove; + container_class->forall = shell_content_forall; +} + +static void +shell_content_init (EShellContent *shell_content) +{ + GtkWidget *widget; + + shell_content->priv = E_SHELL_CONTENT_GET_PRIVATE (shell_content); + + GTK_WIDGET_SET_FLAGS (shell_content, GTK_NO_WINDOW); + + widget = e_search_bar_new (); + gtk_widget_set_parent (widget, GTK_WIDGET (shell_content)); + shell_content->priv->search_bar = g_object_ref (widget); + gtk_widget_show (widget); +} + +GType +e_shell_content_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EShellContentClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) shell_content_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EShellContent), + 0, /* n_preallocs */ + (GInstanceInitFunc) shell_content_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_BIN, "EShellContent", &type_info, 0); + } + + return type; +} + +GtkWidget * +e_shell_content_new (void) +{ + return g_object_new (E_TYPE_SHELL_CONTENT, NULL); +} + +GtkWidget * +e_shell_content_get_search_bar (EShellContent *shell_content) +{ + g_return_val_if_fail (E_IS_SHELL_CONTENT (shell_content), NULL); + + return shell_content->priv->search_bar; +} diff --git a/shell/e-shell-content.h b/shell/e-shell-content.h new file mode 100644 index 0000000000..ce521d501f --- /dev/null +++ b/shell/e-shell-content.h @@ -0,0 +1,66 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-shell-content.h + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef E_SHELL_CONTENT_H +#define E_SHELL_CONTENT_H + +#include + +/* Standard GObject macros */ +#define E_TYPE_SHELL_CONTENT \ + (e_shell_content_get_type ()) +#define E_SHELL_CONTENT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_SHELL_CONTENT, EShellContent)) +#define E_SHELL_CONTENT_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_SHELL_CONTENT, EShellContentClass)) +#define E_IS_SHELL_CONTENT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_SHELL_CONTENT)) +#define E_IS_SHELL_CONTENT_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((obj), E_TYPE_SHELL_CONTENT)) +#define E_SHELL_CONTENT_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_SHELL_CONTENT, EShellContentClass)) + +G_BEGIN_DECLS + +typedef struct _EShellContent EShellContent; +typedef struct _EShellContentClass EShellContentClass; +typedef struct _EShellContentPrivate EShellContentPrivate; + +struct _EShellContent { + GtkBin parent; + EShellContentPrivate *priv; +}; + +struct _EShellContentClass { + GtkBinClass parent_class; +}; + +GType e_shell_content_get_type (void); +GtkWidget * e_shell_content_new (void); +GtkWidget * e_shell_content_get_search_bar (EShellContent *shell_content); + +G_END_DECLS + +#endif /* E_SHELL_CONTENT_H */ diff --git a/shell/e-shell-sidebar.c b/shell/e-shell-sidebar.c new file mode 100644 index 0000000000..30917fd25c --- /dev/null +++ b/shell/e-shell-sidebar.c @@ -0,0 +1,492 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-shell-shell_sidebar.c + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "e-shell-sidebar.h" + +#define E_SHELL_SIDEBAR_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_SHELL_SIDEBAR, EShellSidebarPrivate)) + +struct _EShellSidebarPrivate { + GtkWidget *event_box; + GtkWidget *image; + GtkWidget *primary_label; + GtkWidget *secondary_label; + GtkSizeGroup *size_group; + gchar *primary_text; + gchar *secondary_text; +}; + +enum { + PROP_0, + PROP_ICON_NAME, + PROP_PRIMARY_TEXT, + PROP_SECONDARY_TEXT +}; + +static gpointer parent_class; + +static void +shell_sidebar_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_ICON_NAME: + e_shell_sidebar_set_icon_name ( + E_SHELL_SIDEBAR (object), + g_value_get_string (value)); + return; + + case PROP_PRIMARY_TEXT: + e_shell_sidebar_set_primary_text ( + E_SHELL_SIDEBAR (object), + g_value_get_string (value)); + return; + + case PROP_SECONDARY_TEXT: + e_shell_sidebar_set_secondary_text ( + E_SHELL_SIDEBAR (object), + g_value_get_string (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +shell_sidebar_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_ICON_NAME: + g_value_set_string ( + value, e_shell_sidebar_get_icon_name ( + E_SHELL_SIDEBAR (object))); + return; + + case PROP_PRIMARY_TEXT: + g_value_set_string ( + value, e_shell_sidebar_get_primary_text ( + E_SHELL_SIDEBAR (object))); + return; + + case PROP_SECONDARY_TEXT: + g_value_set_string ( + value, e_shell_sidebar_get_secondary_text ( + E_SHELL_SIDEBAR (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +shell_sidebar_dispose (GObject *object) +{ + EShellSidebarPrivate *priv; + + priv = E_SHELL_SIDEBAR_GET_PRIVATE (object); + + if (priv->size_group != NULL) { + g_object_unref (priv->size_group); + priv->size_group = NULL; + } + + if (priv->event_box != NULL) { + g_object_unref (priv->event_box); + priv->event_box = NULL; + } + + if (priv->image != NULL) { + g_object_unref (priv->image); + priv->image = NULL; + } + + if (priv->primary_label != NULL) { + g_object_unref (priv->primary_label); + priv->primary_label = NULL; + } + + if (priv->secondary_label != NULL) { + g_object_unref (priv->secondary_label); + priv->secondary_label = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +shell_sidebar_finalize (GObject *object) +{ + EShellSidebarPrivate *priv; + + priv = E_SHELL_SIDEBAR_GET_PRIVATE (object); + + g_free (priv->primary_text); + g_free (priv->secondary_text); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +shell_sidebar_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + EShellSidebarPrivate *priv; + GtkRequisition child_requisition; + GtkWidget *child; + + priv = E_SHELL_SIDEBAR_GET_PRIVATE (widget); + + requisition->width = 0; + requisition->height = 0; + + child = gtk_bin_get_child (GTK_BIN (widget)); + gtk_widget_size_request (child, requisition); + + child = priv->event_box; + gtk_widget_size_request (child, &child_requisition); + requisition->width = MAX (requisition->width, child_requisition.width); + requisition->height += child_requisition.height; +} + +static void +shell_sidebar_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + EShellSidebarPrivate *priv; + GtkAllocation child_allocation; + GtkRequisition child_requisition; + GtkWidget *child; + + priv = E_SHELL_SIDEBAR_GET_PRIVATE (widget); + + widget->allocation = *allocation; + + child = priv->event_box; + gtk_widget_size_request (child, &child_requisition); + + child_allocation.x = allocation->x; + child_allocation.y = allocation->y; + child_allocation.width = allocation->width; + child_allocation.height = child_requisition.height; + + gtk_widget_size_allocate (child, &child_allocation); + + child_allocation.y += child_requisition.height; + child_allocation.height = allocation->height - child_allocation.y; + + child = gtk_bin_get_child (GTK_BIN (widget)); + if (child != NULL) + gtk_widget_size_allocate (child, &child_allocation); +} + +static void +shell_sidebar_remove (GtkContainer *container, + GtkWidget *widget) +{ + EShellSidebarPrivate *priv; + + priv = E_SHELL_SIDEBAR_GET_PRIVATE (container); + + /* Look in the internal widgets first. */ + + if (widget == priv->event_box) { + gtk_widget_unparent (priv->event_box); + gtk_widget_queue_resize (GTK_WIDGET (container)); + return; + } + + /* Chain up to parent's remove() method. */ + GTK_CONTAINER_CLASS (parent_class)->remove (container, widget); +} + +static void +shell_sidebar_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data) +{ + EShellSidebarPrivate *priv; + + priv = E_SHELL_SIDEBAR_GET_PRIVATE (container); + + if (include_internals) + callback (priv->event_box, callback_data); + + /* Chain up to parent's forall() method. */ + GTK_CONTAINER_CLASS (parent_class)->forall ( + container, include_internals, callback, callback_data); +} + +static void +shell_sidebar_class_init (EShellSidebarClass *class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + GtkContainerClass *container_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EShellSidebarPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = shell_sidebar_set_property; + object_class->get_property = shell_sidebar_get_property; + object_class->dispose = shell_sidebar_dispose; + object_class->finalize = shell_sidebar_finalize; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->size_request = shell_sidebar_size_request; + widget_class->size_allocate = shell_sidebar_size_allocate; + + container_class = GTK_CONTAINER_CLASS (class); + container_class->remove = shell_sidebar_remove; + container_class->forall = shell_sidebar_forall; + + g_object_class_install_property ( + object_class, + PROP_ICON_NAME, + g_param_spec_string ( + "icon-name", + NULL, + NULL, + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property ( + object_class, + PROP_PRIMARY_TEXT, + g_param_spec_string ( + "primary-text", + NULL, + NULL, + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property ( + object_class, + PROP_SECONDARY_TEXT, + g_param_spec_string ( + "secondary-text", + NULL, + NULL, + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); +} + +static void +shell_sidebar_init (EShellSidebar *shell_sidebar) +{ + GtkStyle *style; + GtkWidget *container; + GtkWidget *widget; + GtkSizeGroup *size_group; + const GdkColor *color; + + shell_sidebar->priv = E_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar); + + GTK_WIDGET_SET_FLAGS (shell_sidebar, GTK_NO_WINDOW); + + widget = gtk_event_box_new (); + style = gtk_widget_get_style (widget); + color = &style->bg[GTK_STATE_ACTIVE]; + gtk_container_set_border_width (GTK_CONTAINER (widget), 1); + gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, color); + gtk_widget_set_parent (widget, GTK_WIDGET (shell_sidebar)); + shell_sidebar->priv->event_box = g_object_ref (widget); + gtk_widget_show (widget); + + container = widget; + + widget = gtk_hbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (widget), 6); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); + + container = widget; + + widget = gtk_image_new (); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + shell_sidebar->priv->image = g_object_ref (widget); + gtk_widget_show (widget); + + widget = gtk_label_new (NULL); + gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_END); + gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + shell_sidebar->priv->primary_label = g_object_ref (widget); + gtk_widget_show (widget); + + widget = gtk_label_new (NULL); + gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_MIDDLE); + gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + shell_sidebar->priv->secondary_label = g_object_ref (widget); + gtk_widget_show (widget); + + size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL); + gtk_size_group_add_widget (size_group, shell_sidebar->priv->event_box); + shell_sidebar->priv->size_group = size_group; +} + +GType +e_shell_sidebar_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EShellSidebarClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) shell_sidebar_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EShellSidebar), + 0, /* n_preallocs */ + (GInstanceInitFunc) shell_sidebar_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_BIN, "EShellSidebar", &type_info, 0); + } + + return type; +} + +GtkWidget * +e_shell_sidebar_new (void) +{ + return g_object_new (E_TYPE_SHELL_SIDEBAR, NULL); +} + +const gchar * +e_shell_sidebar_get_icon_name (EShellSidebar *shell_sidebar) +{ + GtkImage *image; + const gchar *icon_name; + + g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), NULL); + + image = GTK_IMAGE (shell_sidebar->priv->image); + gtk_image_get_icon_name (image, &icon_name, NULL); + + return icon_name; +} + +void +e_shell_sidebar_set_icon_name (EShellSidebar *shell_sidebar, + const gchar *icon_name) +{ + GtkImage *image; + + g_return_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar)); + + if (icon_name == NULL) + icon_name = "image-missing"; + + image = GTK_IMAGE (shell_sidebar->priv->image); + gtk_image_set_from_icon_name (image, icon_name, GTK_ICON_SIZE_MENU); + + gtk_widget_queue_resize (GTK_WIDGET (shell_sidebar)); + g_object_notify (G_OBJECT (shell_sidebar), "icon-name"); +} + +const gchar * +e_shell_sidebar_get_primary_text (EShellSidebar *shell_sidebar) +{ + g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), NULL); + + return shell_sidebar->priv->primary_text; +} + +void +e_shell_sidebar_set_primary_text (EShellSidebar *shell_sidebar, + const gchar *primary_text) +{ + GtkLabel *label; + gchar *markup; + + g_return_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar)); + + g_free (shell_sidebar->priv->primary_text); + shell_sidebar->priv->primary_text = g_strdup (primary_text); + + if (primary_text == NULL) + primary_text = ""; + + label = GTK_LABEL (shell_sidebar->priv->primary_label); + markup = g_markup_printf_escaped ("%s", primary_text); + gtk_label_set_markup (label, markup); + g_free (markup); + + gtk_widget_queue_resize (GTK_WIDGET (shell_sidebar)); + g_object_notify (G_OBJECT (shell_sidebar), "primary-text"); +} + +const gchar * +e_shell_sidebar_get_secondary_text (EShellSidebar *shell_sidebar) +{ + g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), NULL); + + return shell_sidebar->priv->secondary_text; +} + +void +e_shell_sidebar_set_secondary_text (EShellSidebar *shell_sidebar, + const gchar *secondary_text) +{ + GtkLabel *label; + gchar *markup; + + g_return_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar)); + + g_free (shell_sidebar->priv->secondary_text); + shell_sidebar->priv->secondary_text = g_strdup (secondary_text); + + if (secondary_text == NULL) + secondary_text = ""; + + label = GTK_LABEL (shell_sidebar->priv->secondary_label); + markup = g_markup_printf_escaped ("%s", secondary_text); + gtk_label_set_markup (label, markup); + g_free (markup); + + gtk_widget_queue_resize (GTK_WIDGET (shell_sidebar)); + g_object_notify (G_OBJECT (shell_sidebar), "secondary-text"); +} + +GtkSizeGroup * +e_shell_sidebar_get_size_group (EShellSidebar *shell_sidebar) +{ + g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), NULL); + + return shell_sidebar->priv->size_group; +} diff --git a/shell/e-shell-sidebar.h b/shell/e-shell-sidebar.h new file mode 100644 index 0000000000..d674339ef7 --- /dev/null +++ b/shell/e-shell-sidebar.h @@ -0,0 +1,79 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-shell-sidebar.h + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef E_SHELL_SIDEBAR_H +#define E_SHELL_SIDEBAR_H + +#include + +/* Standard GObject macros */ +#define E_TYPE_SHELL_SIDEBAR \ + (e_shell_sidebar_get_type ()) +#define E_SHELL_SIDEBAR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_SHELL_SIDEBAR, EShellSidebar)) +#define E_SHELL_SIDEBAR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_SHELL_SIDEBAR, EShellSidebarClass)) +#define E_IS_SHELL_SIDEBAR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_SHELL_SIDEBAR)) +#define E_IS_SHELL_SIDEBAR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((obj), E_TYPE_SHELL_SIDEBAR)) +#define E_SHELL_SIDEBAR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_SHELL_SIDEBAR, EShellSidebarClass)) + +#define E_SHELL_SIDEBAR_DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH_HORIZ + +G_BEGIN_DECLS + +typedef struct _EShellSidebar EShellSidebar; +typedef struct _EShellSidebarClass EShellSidebarClass; +typedef struct _EShellSidebarPrivate EShellSidebarPrivate; + +struct _EShellSidebar { + GtkBin parent; + EShellSidebarPrivate *priv; +}; + +struct _EShellSidebarClass { + GtkBinClass parent_class; +}; + +GType e_shell_sidebar_get_type (void); +GtkWidget * e_shell_sidebar_new (void); +const gchar * e_shell_sidebar_get_icon_name (EShellSidebar *shell_sidebar); +void e_shell_sidebar_set_icon_name (EShellSidebar *shell_sidebar, + const gchar *icon_name); +const gchar * e_shell_sidebar_get_primary_text(EShellSidebar *shell_sidebar); +void e_shell_sidebar_set_primary_text(EShellSidebar *shell_sidebar, + const gchar *primary_text); +const gchar * e_shell_sidebar_get_secondary_text + (EShellSidebar *shell_sidebar); +void e_shell_sidebar_set_secondary_text + (EShellSidebar *shell_sidebar, + const gchar *secondary_text); +GtkSizeGroup * e_shell_sidebar_get_size_group (EShellSidebar *shell_sidebar); + +G_END_DECLS + +#endif /* E_SHELL_SIDEBAR_H */ diff --git a/shell/e-shell-switcher.c b/shell/e-shell-switcher.c new file mode 100644 index 0000000000..bfcae011bc --- /dev/null +++ b/shell/e-shell-switcher.c @@ -0,0 +1,537 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-shell-switcher.c + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "e-shell-switcher.h" + +#define E_SHELL_SWITCHER_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_SHELL_SWITCHER, EShellSwitcherPrivate)) + +#define H_PADDING 6 +#define V_PADDING 6 + +struct _EShellSwitcherPrivate { + GList *proxies; + gboolean style_set; + GtkToolbarStyle style; + GtkSettings *settings; + gulong settings_handler_id; +}; + +enum { + PROP_0, + PROP_TOOLBAR_STYLE +}; + +enum { + STYLE_CHANGED, + LAST_SIGNAL +}; + +static gpointer parent_class; +static guint signals[LAST_SIGNAL]; + +static void +switcher_layout_actions (EShellSwitcher *switcher) +{ + GtkAllocation *allocation = & GTK_WIDGET (switcher)->allocation; + gboolean icons_only; + int num_btns = g_list_length (switcher->priv->proxies), btns_per_row; + GList **rows, *p; + int row_number; + int max_width = 0, max_height = 0; + int row_last; + int x, y; + int i; + + if (num_btns == 0) + return; + + icons_only = (switcher->priv->style == GTK_TOOLBAR_ICONS); + + /* Figure out the max width and height. */ + for (p = switcher->priv->proxies; p != NULL; p = p->next) { + GtkWidget *widget = p->data; + GtkRequisition requisition; + + gtk_widget_size_request (widget, &requisition); + max_height = MAX (max_height, requisition.height); + max_width = MAX (max_width, requisition.width); + } + + /* Figure out how many rows and columns we'll use. */ + btns_per_row = MAX (1, allocation->width / (max_width + H_PADDING)); + if (!icons_only) { + /* If using text buttons, we want to try to have a + * completely filled-in grid, but if we can't, we want + * the odd row to have just a single button. */ + while (num_btns % btns_per_row > 1) + btns_per_row--; + } + + /* Assign buttons to rows. */ + rows = g_new0 (GList *, num_btns / btns_per_row + 1); + + if (!icons_only && num_btns % btns_per_row != 0) { + rows[0] = g_list_append (rows[0], switcher->priv->proxies->data); + + p = switcher->priv->proxies->next; + row_number = p ? 1 : 0; + } else { + p = switcher->priv->proxies; + row_number = 0; + } + + for (; p != NULL; p = p->next) { + GtkWidget *widget = p->data; + + if (g_list_length (rows[row_number]) == btns_per_row) + row_number++; + + rows[row_number] = g_list_append (rows[row_number], widget); + } + + row_last = row_number; + + /* Layout the buttons. */ + y = allocation->y; + for (i = 0; i < row_last + 1; i++) { + int len, extra_width; + + x = H_PADDING + allocation->x; + len = g_list_length (rows[i]); + if (!icons_only) + extra_width = (allocation->width - (len * max_width ) - (len * H_PADDING)) / len; + else + extra_width = 0; + for (p = rows [i]; p != NULL; p = p->next) { + GtkAllocation child_allocation; + + child_allocation.x = x; + child_allocation.y = y; + child_allocation.width = max_width + extra_width; + child_allocation.height = max_height; + + gtk_widget_size_allocate (GTK_WIDGET (p->data), &child_allocation); + + x += child_allocation.width + H_PADDING; + } + + y += max_height + V_PADDING; + } + + for (i = 0; i <= row_last; i ++) + g_list_free (rows [i]); + g_free (rows); +} + +static void +switcher_toolbar_style_changed_cb (EShellSwitcher *switcher) +{ + if (!switcher->priv->style_set) { + switcher->priv->style_set = TRUE; + e_shell_switcher_unset_style (switcher); + } +} + +static void +switcher_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_TOOLBAR_STYLE: + e_shell_switcher_set_style ( + E_SHELL_SWITCHER (object), + g_value_get_enum (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +switcher_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_TOOLBAR_STYLE: + g_value_set_enum ( + value, e_shell_switcher_get_style ( + E_SHELL_SWITCHER (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +switcher_dispose (GObject *object) +{ + EShellSwitcherPrivate *priv; + + priv = E_SHELL_SWITCHER_GET_PRIVATE (object); + + while (priv->proxies != NULL) { + GtkWidget *widget = priv->proxies->data; + gtk_container_remove (GTK_CONTAINER (object), widget); + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +switcher_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + EShellSwitcherPrivate *priv; + GList *iter; + + priv = E_SHELL_SWITCHER_GET_PRIVATE (widget); + + requisition->width = 0; + requisition->height = 0; + + for (iter = priv->proxies; iter != NULL; iter = iter->next) { + GtkWidget *widget = iter->data; + GtkRequisition child_requisition; + + gtk_widget_size_request (widget, &child_requisition); + + child_requisition.width += H_PADDING; + child_requisition.height += V_PADDING; + + requisition->width = MAX ( + requisition->width, child_requisition.width); + requisition->height += child_requisition.height; + } +} + +static void +switcher_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + EShellSwitcherPrivate *priv; + + priv = E_SHELL_SWITCHER_GET_PRIVATE (widget); + + widget->allocation = *allocation; + + switcher_layout_actions (E_SHELL_SWITCHER (widget)); +} + +static void +switcher_screen_changed (GtkWidget *widget, + GdkScreen *previous_screen) +{ + EShellSwitcherPrivate *priv; + GtkSettings *settings; + + priv = E_SHELL_SWITCHER_GET_PRIVATE (widget); + + if (gtk_widget_has_screen (widget)) + settings = gtk_widget_get_settings (widget); + else + settings = NULL; + + if (settings == priv->settings) + return; + + if (priv->settings != NULL) { + g_signal_handler_disconnect ( + priv->settings, priv->settings_handler_id); + g_object_unref (priv->settings); + } + + if (settings != NULL) { + priv->settings = g_object_ref (settings); + priv->settings_handler_id = g_signal_connect_swapped ( + settings, "notify::gtk-toolbar-style", + G_CALLBACK (switcher_toolbar_style_changed_cb), widget); + } else + priv->settings = NULL; + + switcher_toolbar_style_changed_cb (E_SHELL_SWITCHER (widget)); +} + +static void +switcher_remove (GtkContainer *container, + GtkWidget *widget) +{ + EShellSwitcherPrivate *priv; + GList *link; + + priv = E_SHELL_SWITCHER_GET_PRIVATE (container); + + /* Look in the internal widgets first. */ + + link = g_list_find (priv->proxies, widget); + if (link != NULL) { + GtkWidget *widget = link->data; + + gtk_widget_unparent (widget); + priv->proxies = g_list_delete_link (priv->proxies, link); + gtk_widget_queue_resize (GTK_WIDGET (container)); + return; + } + + /* Chain up to parent's remove() method. */ + GTK_CONTAINER_CLASS (parent_class)->remove (container, widget); +} + +static void +switcher_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data) +{ + EShellSwitcherPrivate *priv; + + priv = E_SHELL_SWITCHER_GET_PRIVATE (container); + + if (include_internals) + g_list_foreach ( + priv->proxies, (GFunc) callback, callback_data); + + /* Chain up to parent's forall() method. */ + GTK_CONTAINER_CLASS (parent_class)->forall ( + container, include_internals, callback, callback_data); +} + +static void +switcher_style_changed (EShellSwitcher *switcher, + GtkToolbarStyle style) +{ + if (switcher->priv->style == style) + return; + + switcher->priv->style = style; + + g_list_foreach ( + switcher->priv->proxies, + (GFunc) gtk_tool_item_toolbar_reconfigured, NULL); + + gtk_widget_queue_resize (GTK_WIDGET (switcher)); + g_object_notify (G_OBJECT (switcher), "toolbar-style"); +} + +static GtkIconSize +switcher_get_icon_size (GtkToolShell *shell) +{ + return GTK_ICON_SIZE_LARGE_TOOLBAR; +} + +static GtkOrientation +switcher_get_orientation (GtkToolShell *shell) +{ + return GTK_ORIENTATION_HORIZONTAL; +} + +static GtkToolbarStyle +switcher_get_style (GtkToolShell *shell) +{ + return e_shell_switcher_get_style (E_SHELL_SWITCHER (shell)); +} + +static GtkReliefStyle +switcher_get_relief_style (GtkToolShell *shell) +{ + /* XXX GTK+ 2.13.6 discards this value. + * http://bugzilla.gnome.org/show_bug.cgi?id=549943 */ + return GTK_RELIEF_NORMAL; +} + +static void +switcher_class_init (EShellSwitcherClass *class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + GtkContainerClass *container_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EShellSwitcherPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = switcher_set_property; + object_class->get_property = switcher_get_property; + object_class->dispose = switcher_dispose; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->size_request = switcher_size_request; + widget_class->size_allocate = switcher_size_allocate; + widget_class->screen_changed = switcher_screen_changed; + + container_class = GTK_CONTAINER_CLASS (class); + container_class->remove = switcher_remove; + container_class->forall = switcher_forall; + + class->style_changed = switcher_style_changed; + + g_object_class_install_property ( + object_class, + PROP_TOOLBAR_STYLE, + g_param_spec_enum ( + "toolbar-style", + NULL, + NULL, + GTK_TYPE_TOOLBAR_STYLE, + E_SHELL_SWITCHER_DEFAULT_TOOLBAR_STYLE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + signals[STYLE_CHANGED] = g_signal_new ( + "style-changed", + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EShellSwitcherClass, style_changed), + NULL, NULL, + g_cclosure_marshal_VOID__ENUM, + G_TYPE_NONE, 1, + GTK_TYPE_TOOLBAR_STYLE); +} + +static void +switcher_init (EShellSwitcher *switcher) +{ + switcher->priv = E_SHELL_SWITCHER_GET_PRIVATE (switcher); + + GTK_WIDGET_SET_FLAGS (switcher, GTK_NO_WINDOW); +} + +static void +switcher_tool_shell_iface_init (GtkToolShellIface *iface) +{ + iface->get_icon_size = switcher_get_icon_size; + iface->get_orientation = switcher_get_orientation; + iface->get_style = switcher_get_style; + iface->get_relief_style = switcher_get_relief_style; +} + +GType +e_shell_switcher_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EShellSwitcherClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) switcher_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EShellSwitcher), + 0, /* n_preallocs */ + (GInstanceInitFunc) switcher_init, + NULL /* value_table */ + }; + + static const GInterfaceInfo tool_shell_info = { + (GInterfaceInitFunc) switcher_tool_shell_iface_init, + (GInterfaceFinalizeFunc) NULL, + NULL /* interface_data */ + }; + + type = g_type_register_static ( + GTK_TYPE_BIN, "EShellSwitcher", &type_info, 0); + + g_type_add_interface_static ( + type, GTK_TYPE_TOOL_SHELL, &tool_shell_info); + } + + return type; +} + +GtkWidget * +e_shell_switcher_new (void) +{ + return g_object_new (E_TYPE_SHELL_SWITCHER, NULL); +} + +void +e_shell_switcher_add_action (EShellSwitcher *switcher, + GtkAction *action) +{ + GtkWidget *widget; + + g_return_if_fail (E_IS_SHELL_SWITCHER (switcher)); + g_return_if_fail (GTK_IS_ACTION (action)); + + g_object_ref (action); + widget = gtk_action_create_tool_item (action); + gtk_tool_item_set_is_important (GTK_TOOL_ITEM (widget), TRUE); + gtk_widget_show (widget); + + switcher->priv->proxies = g_list_append ( + switcher->priv->proxies, widget); + + gtk_widget_set_parent (widget, GTK_WIDGET (switcher)); + gtk_widget_queue_resize (GTK_WIDGET (switcher)); +} + +GtkToolbarStyle +e_shell_switcher_get_style (EShellSwitcher *switcher) +{ + g_return_val_if_fail ( + E_IS_SHELL_SWITCHER (switcher), + E_SHELL_SWITCHER_DEFAULT_TOOLBAR_STYLE); + + return switcher->priv->style; +} + +void +e_shell_switcher_set_style (EShellSwitcher *switcher, + GtkToolbarStyle style) +{ + g_return_if_fail (E_IS_SHELL_SWITCHER (switcher)); + + switcher->priv->style_set = TRUE; + g_signal_emit (switcher, signals[STYLE_CHANGED], 0, style); +} + +void +e_shell_switcher_unset_style (EShellSwitcher *switcher) +{ + GtkSettings *settings; + GtkToolbarStyle style; + + g_return_if_fail (E_IS_SHELL_SWITCHER (switcher)); + + if (!switcher->priv->style_set) + return; + + settings = switcher->priv->settings; + if (settings != NULL) + g_object_get (settings, "gtk-toolbar-style", &style, NULL); + else + style = E_SHELL_SWITCHER_DEFAULT_TOOLBAR_STYLE; + + if (style == GTK_TOOLBAR_BOTH) + style = GTK_TOOLBAR_BOTH_HORIZ; + + if (style != switcher->priv->style) + g_signal_emit (switcher, signals[STYLE_CHANGED], 0, style); + + switcher->priv->style_set = FALSE; +} diff --git a/shell/e-shell-switcher.h b/shell/e-shell-switcher.h new file mode 100644 index 0000000000..6d2995f99a --- /dev/null +++ b/shell/e-shell-switcher.h @@ -0,0 +1,76 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-shell-switcher.h + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef E_SHELL_SWITCHER_H +#define E_SHELL_SWITCHER_H + +#include + +/* Standard GObject macros */ +#define E_TYPE_SHELL_SWITCHER \ + (e_shell_switcher_get_type ()) +#define E_SHELL_SWITCHER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_SHELL_SWITCHER, EShellSwitcher)) +#define E_SHELL_SWITCHER_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_SHELL_SWITCHER, EShellSwitcherClass)) +#define E_IS_SHELL_SWITCHER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_SHELL_SWITCHER)) +#define E_IS_SHELL_SWITCHER_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((obj), E_TYPE_SHELL_SWITCHER)) +#define E_SHELL_SWITCHER_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_SHELL_SWITCHER, EShellSwitcherClass)) + +#define E_SHELL_SWITCHER_DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH_HORIZ + +G_BEGIN_DECLS + +typedef struct _EShellSwitcher EShellSwitcher; +typedef struct _EShellSwitcherClass EShellSwitcherClass; +typedef struct _EShellSwitcherPrivate EShellSwitcherPrivate; + +struct _EShellSwitcher { + GtkBin parent; + EShellSwitcherPrivate *priv; +}; + +struct _EShellSwitcherClass { + GtkBinClass parent_class; + + void (*style_changed) (EShellSwitcher *switcher, + GtkToolbarStyle style); +}; + +GType e_shell_switcher_get_type (void); +GtkWidget * e_shell_switcher_new (void); +void e_shell_switcher_add_action (EShellSwitcher *switcher, + GtkAction *action); +GtkToolbarStyle e_shell_switcher_get_style (EShellSwitcher *switcher); +void e_shell_switcher_set_style (EShellSwitcher *switcher, + GtkToolbarStyle style); +void e_shell_switcher_unset_style (EShellSwitcher *switcher); + +G_END_DECLS + +#endif /* E_SHELL_SWITCHER_H */ diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c index 6669aa4442..2cb2ec9f3c 100644 --- a/shell/e-shell-view.c +++ b/shell/e-shell-view.c @@ -23,29 +23,34 @@ #include #include -#include "e-shell-window.h" -#include "e-shell-window-actions.h" +#include + +#include +#include +#include +#include #define E_SHELL_VIEW_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), E_TYPE_SHELL_VIEW, EShellViewPrivate)) struct _EShellViewPrivate { - gchar *icon_name; - gchar *primary_text; - gchar *secondary_text; gchar *title; gint page_num; gpointer window; /* weak pointer */ + + GtkWidget *content; + GtkWidget *sidebar; + GtkWidget *taskbar; + + GalViewInstance *view_instance; }; enum { PROP_0, - PROP_ICON_NAME, PROP_PAGE_NUM, - PROP_PRIMARY_TEXT, - PROP_SECONDARY_TEXT, PROP_TITLE, + PROP_VIEW_INSTANCE, PROP_WINDOW }; @@ -83,34 +88,22 @@ shell_view_set_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_ICON_NAME: - e_shell_view_set_icon_name ( - E_SHELL_VIEW (object), - g_value_get_string (value)); - return; - case PROP_PAGE_NUM: shell_view_set_page_num ( E_SHELL_VIEW (object), g_value_get_int (value)); return; - case PROP_PRIMARY_TEXT: - e_shell_view_set_primary_text ( - E_SHELL_VIEW (object), - g_value_get_string (value)); - return; - - case PROP_SECONDARY_TEXT: - e_shell_view_set_secondary_text ( + case PROP_TITLE: + e_shell_view_set_title ( E_SHELL_VIEW (object), g_value_get_string (value)); return; - case PROP_TITLE: - e_shell_view_set_title ( + case PROP_VIEW_INSTANCE: + e_shell_view_set_view_instance ( E_SHELL_VIEW (object), - g_value_get_string (value)); + g_value_get_object (value)); return; case PROP_WINDOW: @@ -130,33 +123,21 @@ shell_view_get_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_ICON_NAME: - g_value_set_string ( - value, e_shell_view_get_icon_name ( - E_SHELL_VIEW (object))); - return; - case PROP_PAGE_NUM: g_value_set_int ( value, e_shell_view_get_page_num ( E_SHELL_VIEW (object))); return; - case PROP_PRIMARY_TEXT: - g_value_set_string ( - value, e_shell_view_get_primary_text ( - E_SHELL_VIEW (object))); - return; - - case PROP_SECONDARY_TEXT: + case PROP_TITLE: g_value_set_string ( - value, e_shell_view_get_secondary_text ( + value, e_shell_view_get_title ( E_SHELL_VIEW (object))); return; - case PROP_TITLE: - g_value_set_string ( - value, e_shell_view_get_title ( + case PROP_VIEW_INSTANCE: + g_value_set_object ( + value, e_shell_view_get_view_instance ( E_SHELL_VIEW (object))); return; @@ -183,6 +164,26 @@ shell_view_dispose (GObject *object) priv->window = NULL; } + if (priv->content != NULL) { + g_object_unref (priv->content); + priv->content = NULL; + } + + if (priv->sidebar != NULL) { + g_object_unref (priv->sidebar); + priv->sidebar = NULL; + } + + if (priv->taskbar != NULL) { + g_object_unref (priv->taskbar); + priv->taskbar = NULL; + } + + if (priv->view_instance != NULL) { + g_object_unref (priv->view_instance); + priv->view_instance = NULL; + } + /* Chain up to parent's dispose() method. */ G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -194,9 +195,6 @@ shell_view_finalize (GObject *object) priv = E_SHELL_VIEW_GET_PRIVATE (object); - g_free (priv->icon_name); - g_free (priv->primary_text); - g_free (priv->secondary_text); g_free (priv->title); /* Chain up to parent's finalize() method. */ @@ -206,6 +204,16 @@ shell_view_finalize (GObject *object) static void shell_view_constructed (GObject *object) { + EShellViewClass *class; + GtkWidget *sidebar; + + class = E_SHELL_VIEW_GET_CLASS (object); + sidebar = e_shell_view_get_sidebar_widget (E_SHELL_VIEW (object)); + e_shell_sidebar_set_icon_name ( + E_SHELL_SIDEBAR (sidebar), class->icon_name); + e_shell_sidebar_set_primary_text ( + E_SHELL_SIDEBAR (sidebar), class->label); + /* XXX GObjectClass doesn't implement constructed(), so we will. * Then subclasses won't have to check the function pointer * before chaining up. @@ -228,17 +236,6 @@ shell_view_class_init (EShellViewClass *class) object_class->finalize = shell_view_finalize; object_class->constructed = shell_view_constructed; - g_object_class_install_property ( - object_class, - PROP_ICON_NAME, - g_param_spec_string ( - "icon-name", - _("Icon Name"), - _("The icon name for the sidebar header"), - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - g_object_class_install_property ( object_class, PROP_PAGE_NUM, @@ -252,28 +249,6 @@ shell_view_class_init (EShellViewClass *class) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property ( - object_class, - PROP_PRIMARY_TEXT, - g_param_spec_string ( - "primary-text", - _("Primary Text"), - _("The primary text for the sidebar header"), - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - object_class, - PROP_SECONDARY_TEXT, - g_param_spec_string ( - "secondary-text", - _("Secondary Text"), - _("The secondary text for the sidebar header"), - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - g_object_class_install_property ( object_class, PROP_TITLE, @@ -285,6 +260,16 @@ shell_view_class_init (EShellViewClass *class) G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property ( + object_class, + PROP_VIEW_INSTANCE, + g_param_spec_object ( + "view-instance", + _("GAL View Instance"), + _("The GAL view instance for the shell view"), + GAL_VIEW_INSTANCE_TYPE, + G_PARAM_READWRITE)); + g_object_class_install_property ( object_class, PROP_WINDOW, @@ -309,7 +294,21 @@ shell_view_class_init (EShellViewClass *class) static void shell_view_init (EShellView *shell_view) { + GtkWidget *widget; + shell_view->priv = E_SHELL_VIEW_GET_PRIVATE (shell_view); + + widget = e_shell_content_new (); + shell_view->priv->content = g_object_ref_sink (widget); + gtk_widget_show (widget); + + widget = e_shell_sidebar_new (); + shell_view->priv->sidebar = g_object_ref_sink (widget); + gtk_widget_show (widget); + + widget = e_task_bar_new (); + shell_view->priv->taskbar = g_object_ref_sink (widget); + gtk_widget_show (widget); } GType @@ -357,99 +356,51 @@ e_shell_view_get_name (EShellView *shell_view) } const gchar * -e_shell_view_get_icon_name (EShellView *shell_view) -{ - g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); - - return shell_view->priv->icon_name; -} - -void -e_shell_view_set_icon_name (EShellView *shell_view, - const gchar *icon_name) -{ - g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); - - if (icon_name == NULL) { - EShellViewClass *class; - - /* Fall back to the switcher icon. */ - class = E_SHELL_VIEW_GET_CLASS (shell_view); - icon_name = class->icon_name; - } - - g_free (shell_view->priv->icon_name); - shell_view->priv->icon_name = g_strdup (icon_name); - - g_object_notify (G_OBJECT (shell_view), "icon-name"); -} - -const gchar * -e_shell_view_get_primary_text (EShellView *shell_view) +e_shell_view_get_title (EShellView *shell_view) { g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); - return shell_view->priv->primary_text; + return shell_view->priv->title; } void -e_shell_view_set_primary_text (EShellView *shell_view, - const gchar *primary_text) +e_shell_view_set_title (EShellView *shell_view, + const gchar *title) { g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); - if (primary_text == NULL) { - EShellViewClass *class; - - /* Fall back to the switcher label. */ - class = E_SHELL_VIEW_GET_CLASS (shell_view); - primary_text = class->label; - } - - g_free (shell_view->priv->primary_text); - shell_view->priv->primary_text = g_strdup (primary_text); + g_free (shell_view->priv->title); + shell_view->priv->title = g_strdup (title); - g_object_notify (G_OBJECT (shell_view), "primary-text"); + g_object_notify (G_OBJECT (shell_view), "title"); } -const gchar * -e_shell_view_get_secondary_text (EShellView *shell_view) +GalViewInstance * +e_shell_view_get_view_instance (EShellView *shell_view) { g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); - return shell_view->priv->secondary_text; + return shell_view->priv->view_instance; } void -e_shell_view_set_secondary_text (EShellView *shell_view, - const gchar *secondary_text) +e_shell_view_set_view_instance (EShellView *shell_view, + GalViewInstance *instance) { g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); - g_free (shell_view->priv->secondary_text); - shell_view->priv->secondary_text = g_strdup (secondary_text); - - g_object_notify (G_OBJECT (shell_view), "secondary-text"); -} - -const gchar * -e_shell_view_get_title (EShellView *shell_view) -{ - g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); - - return shell_view->priv->title; -} + if (instance != NULL) + g_return_if_fail (GAL_IS_VIEW_INSTANCE (instance)); -void -e_shell_view_set_title (EShellView *shell_view, - const gchar *title) -{ - g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); + if (shell_view->priv->view_instance != NULL) { + g_object_unref (shell_view->priv->view_instance); + shell_view->priv->view_instance = NULL; + } - g_free (shell_view->priv->title); - shell_view->priv->title = g_strdup (title); + if (instance != NULL) + shell_view->priv->view_instance = g_object_ref (instance); - g_object_notify (G_OBJECT (shell_view), "title"); + g_object_notify (G_OBJECT (shell_view), "view-instance"); } EShellWindow * @@ -490,40 +441,25 @@ e_shell_view_get_page_num (EShellView *shell_view) GtkWidget * e_shell_view_get_content_widget (EShellView *shell_view) { - EShellViewClass *class; - g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); - class = E_SHELL_VIEW_GET_CLASS (shell_view); - g_return_val_if_fail (class->get_content_widget != NULL, NULL); - - return class->get_content_widget (shell_view); + return shell_view->priv->content; } GtkWidget * e_shell_view_get_sidebar_widget (EShellView *shell_view) { - EShellViewClass *class; - g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); - class = E_SHELL_VIEW_GET_CLASS (shell_view); - g_return_val_if_fail (class->get_sidebar_widget != NULL, NULL); - - return class->get_sidebar_widget (shell_view); + return shell_view->priv->sidebar; } GtkWidget * -e_shell_view_get_status_widget (EShellView *shell_view) +e_shell_view_get_taskbar_widget (EShellView *shell_view) { - EShellViewClass *class; - g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); - class = E_SHELL_VIEW_GET_CLASS (shell_view); - g_return_val_if_fail (class->get_status_widget != NULL, NULL); - - return class->get_status_widget (shell_view); + return shell_view->priv->taskbar; } void diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h index 90aa35c450..a13efcf4b4 100644 --- a/shell/e-shell-view.h +++ b/shell/e-shell-view.h @@ -24,6 +24,8 @@ #include #include +#include + /* Standard GObject macros */ #define E_TYPE_SHELL_VIEW \ (e_shell_view_get_type ()) @@ -65,12 +67,7 @@ struct _EShellViewClass { * the GTypeInfo they pass to g_type_module_register_type(). */ GTypeModule *type_module; - GtkWidget * (*get_content_widget) (EShellView *shell_view); - GtkWidget * (*get_sidebar_widget) (EShellView *shell_view); - GtkWidget * (*get_status_widget) (EShellView *shell_view); - /* Signals */ - void (*changed) (EShellView *shell_view); }; @@ -88,12 +85,16 @@ void e_shell_view_set_secondary_text (EShellView *shell_view, const gchar * e_shell_view_get_title (EShellView *shell_view); void e_shell_view_set_title (EShellView *shell_view, const gchar *title); +GalViewInstance * + e_shell_view_get_view_instance (EShellView *shell_view); +void e_shell_view_set_view_instance (EShellView *shell_view, + GalViewInstance *instance); EShellWindow * e_shell_view_get_window (EShellView *shell_view); gboolean e_shell_view_is_selected (EShellView *shell_view); gint e_shell_view_get_page_num (EShellView *shell_view); GtkWidget * e_shell_view_get_content_widget (EShellView *shell_view); GtkWidget * e_shell_view_get_sidebar_widget (EShellView *shell_view); -GtkWidget * e_shell_view_get_status_widget (EShellView *shell_view); +GtkWidget * e_shell_view_get_taskbar_widget (EShellView *shell_view); void e_shell_view_changed (EShellView *shell_view); G_END_DECLS diff --git a/shell/e-shell-window-actions.c b/shell/e-shell-window-actions.c index 13fe3c7d12..44d82e8bbe 100644 --- a/shell/e-shell-window-actions.c +++ b/shell/e-shell-window-actions.c @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -703,6 +704,63 @@ action_forget_passwords_cb (GtkAction *action, e_passwords_forget_passwords (); } +static void +action_gal_define_views_cb (GtkAction *action, + EShellWindow *shell_window) +{ + EShellView *shell_view; + GalViewInstance *instance; + GtkWidget *dialog; + const gchar *view_name; + + view_name = e_shell_window_get_current_view (shell_window); + shell_view = e_shell_window_get_view (shell_window, view_name); + instance = e_shell_view_get_view_instance (shell_view); + g_return_if_fail (instance != NULL); + + dialog = gal_define_views_dialog_new (instance->collection); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) + gal_view_collection_save (instance->collection); + gtk_widget_destroy (dialog); +} + +static void +action_gal_save_custom_view_cb (GtkAction *action, + EShellWindow *shell_window) +{ + EShellView *shell_view; + GalViewInstance *instance; + const gchar *view_name; + + view_name = e_shell_window_get_current_view (shell_window); + shell_view = e_shell_window_get_view (shell_window, view_name); + instance = e_shell_view_get_view_instance (shell_view); + g_return_if_fail (instance != NULL); + + gal_view_instance_save_as (instance); +} + +static void +action_gal_view_cb (GtkRadioAction *action, + GtkRadioAction *current, + EShellWindow *shell_window) +{ + EShellView *shell_view; + GalViewInstance *instance; + const gchar *view_name; + const gchar *view_id; + + view_name = e_shell_window_get_current_view (shell_window); + shell_view = e_shell_window_get_view (shell_window, view_name); + instance = e_shell_view_get_view_instance (shell_view); + g_return_if_fail (instance != NULL); + + view_id = g_object_get_data (G_OBJECT (current), "view-id"); + g_return_if_fail (view_id != NULL); + + gal_view_instance_set_current_view_id (instance, view_id); +} + static void action_import_cb (GtkAction *action, EShellWindow *shell_window) @@ -825,10 +883,13 @@ static void action_show_sidebar_cb (GtkToggleAction *action, EShellWindow *shell_window) { + GtkPaned *paned; GtkWidget *widget; gboolean active; - widget = shell_window->priv->sidebar; + paned = GTK_PANED (shell_window->priv->content_pane); + + widget = gtk_paned_get_child1 (paned); active = gtk_toggle_action_get_active (action); g_object_set (widget, "visible", active, NULL); } @@ -849,12 +910,12 @@ static void action_show_switcher_cb (GtkToggleAction *action, EShellWindow *shell_window) { - ESidebar *sidebar; + GtkWidget *widget; gboolean active; - sidebar = E_SIDEBAR (shell_window->priv->sidebar); + widget = shell_window->priv->switcher; active = gtk_toggle_action_get_active (action); - e_sidebar_set_actions_visible (sidebar, active); + g_object_set (widget, "visible", active, NULL); } static void @@ -898,10 +959,10 @@ action_switcher_style_cb (GtkRadioAction *action, GtkRadioAction *current, EShellWindow *shell_window) { - ESidebar *sidebar; + EShellSwitcher *switcher; GtkToolbarStyle style; - sidebar = E_SIDEBAR (shell_window->priv->sidebar); + switcher = E_SHELL_SWITCHER (shell_window->priv->switcher); style = gtk_radio_action_get_current_value (action); switch (style) { @@ -909,11 +970,11 @@ action_switcher_style_cb (GtkRadioAction *action, case GTK_TOOLBAR_TEXT: case GTK_TOOLBAR_BOTH: case GTK_TOOLBAR_BOTH_HORIZ: - e_sidebar_set_style (sidebar, style); + e_shell_switcher_set_style (switcher, style); break; default: - e_sidebar_unset_style (sidebar); + e_shell_switcher_unset_style (switcher); break; } } @@ -1208,6 +1269,42 @@ static GtkRadioActionEntry shell_switcher_style_entries[] = { -1 } }; +static GtkActionEntry shell_gal_view_entries[] = { + + { "gal-define-views", + NULL, + N_("Define Views..."), + NULL, + N_("Create or edit views"), + G_CALLBACK (action_gal_define_views_cb) }, + + { "gal-save-custom-view", + NULL, + N_("Save Custom View..."), + NULL, + N_("Save current custom view"), + G_CALLBACK (action_gal_save_custom_view_cb) }, + + /*** Menus ***/ + + { "gal-view-menu", + NULL, + N_("C_urrent View"), + NULL, + NULL, + NULL } +}; + +static GtkRadioActionEntry shell_gal_view_radio_entries[] = { + + { "gal-custom-view", + NULL, + N_("Custom View"), + NULL, + N_("Current view is a customized view"), + -1 } +}; + static gint shell_window_compare_actions (GtkAction *action1, GtkAction *action2) @@ -1283,15 +1380,15 @@ void e_shell_window_actions_init (EShellWindow *shell_window) { GtkActionGroup *action_group; - GtkUIManager *manager; + GtkUIManager *ui_manager; const gchar *domain; g_return_if_fail (E_IS_SHELL_WINDOW (shell_window)); - manager = e_shell_window_get_ui_manager (shell_window); + ui_manager = e_shell_window_get_ui_manager (shell_window); domain = GETTEXT_PACKAGE; - e_load_ui_definition (manager, "evolution-shell.ui"); + e_load_ui_definition (ui_manager, "evolution-shell.ui"); /* Shell Actions */ action_group = shell_window->priv->shell_actions; @@ -1305,24 +1402,36 @@ e_shell_window_actions_init (EShellWindow *shell_window) gtk_action_group_add_radio_actions ( action_group, shell_switcher_style_entries, G_N_ELEMENTS (shell_switcher_style_entries), - E_SIDEBAR_DEFAULT_TOOLBAR_STYLE, + E_SHELL_SWITCHER_DEFAULT_TOOLBAR_STYLE, G_CALLBACK (action_switcher_style_cb), shell_window); - gtk_ui_manager_insert_action_group (manager, action_group, 0); + gtk_action_group_add_actions ( + action_group, shell_gal_view_entries, + G_N_ELEMENTS (shell_gal_view_entries), shell_window); + gtk_action_group_add_radio_actions ( + action_group, shell_gal_view_radio_entries, + G_N_ELEMENTS (shell_gal_view_radio_entries), + 0, G_CALLBACK (action_gal_view_cb), shell_window); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + + /* GAL View Actions (empty) */ + action_group = shell_window->priv->gal_view_actions; + gtk_action_group_set_translation_domain (action_group, domain); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); /* New Item Actions (empty) */ action_group = shell_window->priv->new_item_actions; gtk_action_group_set_translation_domain (action_group, domain); - gtk_ui_manager_insert_action_group (manager, action_group, 0); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); /* New Source Actions (empty) */ action_group = shell_window->priv->new_source_actions; gtk_action_group_set_translation_domain (action_group, domain); - gtk_ui_manager_insert_action_group (manager, action_group, 0); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); /* Shell View Actions (empty) */ action_group = shell_window->priv->shell_view_actions; gtk_action_group_set_translation_domain (action_group, domain); - gtk_ui_manager_insert_action_group (manager, action_group, 0); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); } GtkWidget * @@ -1404,7 +1513,8 @@ e_shell_window_create_shell_view_actions (EShellWindow *shell_window) GType *children; GSList *group = NULL; GtkActionGroup *action_group; - GtkUIManager *manager; + GtkUIManager *ui_manager; + EShellSwitcher *switcher; guint n_children, ii; guint merge_id; @@ -1412,8 +1522,9 @@ e_shell_window_create_shell_view_actions (EShellWindow *shell_window) action_group = shell_window->priv->shell_view_actions; children = g_type_children (E_TYPE_SHELL_VIEW, &n_children); - manager = e_shell_window_get_ui_manager (shell_window); - merge_id = gtk_ui_manager_new_merge_id (manager); + switcher = E_SHELL_SWITCHER (shell_window->priv->switcher); + ui_manager = e_shell_window_get_ui_manager (shell_window); + merge_id = gtk_ui_manager_new_merge_id (ui_manager); /* Construct a group of radio actions from the various EShellView * subclasses and register them with our ESidebar. These actions @@ -1480,12 +1591,10 @@ e_shell_window_create_shell_view_actions (EShellWindow *shell_window) gtk_action_group_add_action ( action_group, GTK_ACTION (action)); - e_sidebar_add_action ( - E_SIDEBAR (shell_window->priv->sidebar), - GTK_ACTION (action)); + e_shell_switcher_add_action (switcher, GTK_ACTION (action)); gtk_ui_manager_add_ui ( - manager, merge_id, + ui_manager, merge_id, "/main-menu/view-menu/window-menu", action_name, action_name, GTK_UI_MANAGER_AUTO, FALSE); @@ -1498,3 +1607,108 @@ e_shell_window_create_shell_view_actions (EShellWindow *shell_window) g_free (children); } + +void +e_shell_window_update_gal_view_menu (EShellWindow *shell_window) +{ + EShellView *shell_view; + GtkUIManager *ui_manager; + GtkActionGroup *action_group; + GalViewInstance *instance; + GalViewCollection *collection; + GtkRadioAction *radio_action; + GtkAction *action; + GList *list, *iter; + GSList *radio_group; + gboolean visible; + const gchar *view_name; + const gchar *path; + gchar *gal_view_id; + guint merge_id; + gint count, ii; + + ui_manager = e_shell_window_get_ui_manager (shell_window); + view_name = e_shell_window_get_current_view (shell_window); + shell_view = e_shell_window_get_view (shell_window, view_name); + instance = e_shell_view_get_view_instance (shell_view); + + action_group = shell_window->priv->gal_view_actions; + merge_id = shell_window->priv->gal_view_merge_id; + + /* Unmerge the previous menu. */ + gtk_ui_manager_remove_ui (ui_manager, merge_id); + + /* XXX Annoying that GTK+ doesn't provide a function for this. + * http://bugzilla.gnome.org/show_bug.cgi?id=550485 */ + list = gtk_action_group_list_actions (action_group); + for (iter = list; iter != NULL; iter = iter->next) { + GtkAction *action = iter->data; + gtk_action_group_remove_action (action_group, action); + } + g_list_free (list); + + /* If there's no view instance then just hide the entire + * "Current View" menu and return. */ + action = ACTION (GAL_VIEW_MENU); + gtk_action_set_visible (action, instance != NULL); + if (instance == NULL) + return; + + /* We have a view instance, so forge ahead. */ + collection = instance->collection; + count = gal_view_collection_get_count (collection); + path = "/main-menu/view-menu/gal-view-menu/gal-view-list"; + gal_view_id = gal_view_instance_get_current_view_id (instance); + g_return_if_fail (gal_view_id != NULL); + + /* Default to "Custom View", unless we find our view ID. */ + radio_action = GTK_RADIO_ACTION (ACTION (GAL_CUSTOM_VIEW)); + gtk_radio_action_set_group (radio_action, NULL); + radio_group = gtk_radio_action_get_group (radio_action); + gtk_radio_action_set_current_value (radio_action, -1); + + /* Add a menu item for each view collection item. */ + for (ii = 0; ii < count; ii++) { + GalViewCollectionItem *item; + gchar *action_name; + gchar *tooltip; + + item = gal_view_collection_get_view_item (collection, ii); + + action_name = g_strdup_printf ( + "gal-view-%s-%d", view_name, ii); + tooltip = g_strdup_printf ("Select view: %s", item->title); + + radio_action = gtk_radio_action_new ( + action_name, item->title, tooltip, NULL, ii); + + gtk_radio_action_set_group (radio_action, radio_group); + radio_group = gtk_radio_action_get_group (radio_action); + + g_object_set_data_full ( + G_OBJECT (radio_action), "view-id", + g_strdup (item->id), (GDestroyNotify) g_free); + + if (strcmp (item->id, gal_view_id) == 0) + gtk_radio_action_set_current_value (radio_action, ii); + + action = GTK_ACTION (radio_action); + gtk_action_group_add_action (action_group, action); + + gtk_ui_manager_add_ui ( + ui_manager, merge_id, path, action_name, + action_name, GTK_UI_MANAGER_AUTO, FALSE); + + g_free (action_name); + g_free (tooltip); + } + + /* Doesn't matter which radio action we check. */ + visible = (gtk_radio_action_get_current_value (radio_action) < 0); + + action = ACTION (GAL_CUSTOM_VIEW); + gtk_action_set_visible (action, visible); + + action = ACTION (GAL_SAVE_CUSTOM_VIEW); + gtk_action_set_visible (action, visible); +} diff --git a/shell/e-shell-window-actions.h b/shell/e-shell-window-actions.h index 012e8725ed..f1f9b8a554 100644 --- a/shell/e-shell-window-actions.h +++ b/shell/e-shell-window-actions.h @@ -36,6 +36,14 @@ E_SHELL_WINDOW_ACTION ((window), "faq") #define E_SHELL_WINDOW_ACTION_FORGET_PASSWORDS(window) \ E_SHELL_WINDOW_ACTION ((window), "forget-passwords") +#define E_SHELL_WINDOW_ACTION_GAL_CUSTOM_VIEW(window) \ + E_SHELL_WINDOW_ACTION ((window), "gal-custom-view") +#define E_SHELL_WINDOW_ACTION_GAL_DEFINE_VIEWS(window) \ + E_SHELL_WINDOW_ACTION ((window), "gal-define-views") +#define E_SHELL_WINDOW_ACTION_GAL_SAVE_CUSTOM_VIEW(window) \ + E_SHELL_WINDOW_ACTION ((window), "gal-save-custom-view") +#define E_SHELL_WINDOW_ACTION_GAL_VIEW_MENU(window) \ + E_SHELL_WINDOW_ACTION ((window), "gal-view-menu") #define E_SHELL_WINDOW_ACTION_IMPORT(window) \ E_SHELL_WINDOW_ACTION ((window), "import") #define E_SHELL_WINDOW_ACTION_NEW_WINDOW(window) \ @@ -70,6 +78,8 @@ E_SHELL_WINDOW_ACTION ((window), "work-online") /* Action Groups */ +#define E_SHELL_WINDOW_ACTION_GROUP_GAL_VIEW(window) \ + E_SHELL_WINDOW_ACTION_GROUP ((window), "gal-view") #define E_SHELL_WINDOW_ACTION_GROUP_NEW_ITEM(window) \ E_SHELL_WINDOW_ACTION_GROUP ((window), "new-item") #define E_SHELL_WINDOW_ACTION_GROUP_NEW_SOURCE(window) \ diff --git a/shell/e-shell-window-private.c b/shell/e-shell-window-private.c index efa6c594d2..5d0a8d3bee 100644 --- a/shell/e-shell-window-private.c +++ b/shell/e-shell-window-private.c @@ -29,7 +29,6 @@ shell_window_notify_current_view_cb (EShellWindow *shell_window) { GtkWidget *menu; GtkWidget *widget; - EShellView *shell_view; const gchar *path; /* Update the "File -> New" submenu. */ @@ -203,6 +202,7 @@ e_shell_window_private_init (EShellWindow *shell_window) GtkWidget *widget; GObject *object; const gchar *key; + guint merge_id; gint height; loaded_views = g_hash_table_new_full ( @@ -210,21 +210,25 @@ e_shell_window_private_init (EShellWindow *shell_window) (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); - priv->manager = gtk_ui_manager_new (); + priv->ui_manager = gtk_ui_manager_new (); priv->shell_actions = gtk_action_group_new ("shell"); + priv->gal_view_actions = gtk_action_group_new ("gal-view"); priv->new_item_actions = gtk_action_group_new ("new-item"); priv->new_source_actions = gtk_action_group_new ("new-source"); priv->shell_view_actions = gtk_action_group_new ("shell-view"); priv->loaded_views = loaded_views; + merge_id = gtk_ui_manager_new_merge_id (priv->ui_manager); + priv->gal_view_merge_id = merge_id; + e_shell_window_actions_init (shell_window); gtk_window_add_accel_group ( GTK_WINDOW (shell_window), - gtk_ui_manager_get_accel_group (priv->manager)); + gtk_ui_manager_get_accel_group (priv->ui_manager)); g_signal_connect_swapped ( - priv->manager, "connect-proxy", + priv->ui_manager, "connect-proxy", G_CALLBACK (shell_window_connect_proxy_cb), shell_window); /* Construct window widgets. */ @@ -283,9 +287,8 @@ e_shell_window_private_init (EShellWindow *shell_window) container = priv->content_pane; - widget = e_sidebar_new (); + widget = gtk_vbox_new (FALSE, 6); gtk_paned_pack1 (GTK_PANED (container), widget, TRUE, FALSE); - priv->sidebar = g_object_ref (widget); gtk_widget_show (widget); widget = gtk_notebook_new (); @@ -295,15 +298,20 @@ e_shell_window_private_init (EShellWindow *shell_window) priv->content_notebook = g_object_ref (widget); gtk_widget_show (widget); - container = priv->sidebar; + container = gtk_paned_get_child1 (GTK_PANED (priv->content_pane)); widget = gtk_notebook_new (); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE); gtk_notebook_set_show_border (GTK_NOTEBOOK (widget), FALSE); - gtk_container_add (GTK_CONTAINER (container), widget); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); priv->sidebar_notebook = g_object_ref (widget); gtk_widget_show (widget); + widget = e_shell_switcher_new (); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + priv->switcher = g_object_ref (widget); + gtk_widget_show (widget); + container = priv->status_area; widget = e_online_button_new (); @@ -378,8 +386,9 @@ e_shell_window_private_dispose (EShellWindow *shell_window) DISPOSE (priv->shell); - DISPOSE (priv->manager); + DISPOSE (priv->ui_manager); DISPOSE (priv->shell_actions); + DISPOSE (priv->gal_view_actions); DISPOSE (priv->new_item_actions); DISPOSE (priv->new_source_actions); DISPOSE (priv->shell_view_actions); @@ -391,8 +400,8 @@ e_shell_window_private_dispose (EShellWindow *shell_window) DISPOSE (priv->menu_tool_button); DISPOSE (priv->content_pane); DISPOSE (priv->content_notebook); - DISPOSE (priv->sidebar); DISPOSE (priv->sidebar_notebook); + DISPOSE (priv->switcher); DISPOSE (priv->status_area); DISPOSE (priv->online_button); DISPOSE (priv->tooltip_label); diff --git a/shell/e-shell-window-private.h b/shell/e-shell-window-private.h index db8174832d..81bf254c61 100644 --- a/shell/e-shell-window-private.h +++ b/shell/e-shell-window-private.h @@ -28,11 +28,11 @@ #include #include #include +#include #include #include #include -#include #define E_SHELL_WINDOW_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE \ @@ -58,11 +58,13 @@ struct _EShellWindowPrivate { /*** UI Management ***/ - GtkUIManager *manager; + GtkUIManager *ui_manager; GtkActionGroup *shell_actions; + GtkActionGroup *gal_view_actions; GtkActionGroup *new_item_actions; GtkActionGroup *new_source_actions; GtkActionGroup *shell_view_actions; + guint gal_view_merge_id; /*** Shell Views ***/ @@ -77,8 +79,8 @@ struct _EShellWindowPrivate { GtkWidget *menu_tool_button; GtkWidget *content_pane; GtkWidget *content_notebook; - GtkWidget *sidebar; GtkWidget *sidebar_notebook; + GtkWidget *switcher; GtkWidget *status_area; GtkWidget *online_button; GtkWidget *tooltip_label; @@ -100,6 +102,8 @@ void e_shell_window_actions_init (EShellWindow *shell_window); GtkWidget * e_shell_window_create_new_menu (EShellWindow *shell_window); void e_shell_window_create_shell_view_actions (EShellWindow *shell_window); +void e_shell_window_update_gal_view_menu + (EShellWindow *shell_window); G_END_DECLS diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c index 312307c2f7..c53867b527 100644 --- a/shell/e-shell-window.c +++ b/shell/e-shell-window.c @@ -24,7 +24,6 @@ #include #include -#include #include #include @@ -41,31 +40,6 @@ enum { static gpointer parent_class; -static void -shell_window_update_sidebar (EShellWindow *shell_window) -{ - ESidebar *sidebar; - EShellView *shell_view; - const gchar *view_name; - const gchar *icon_name; - const gchar *primary_text; - const gchar *secondary_text; - - sidebar = E_SIDEBAR (shell_window->priv->sidebar); - view_name = e_shell_window_get_current_view (shell_window); - shell_view = e_shell_window_get_view (shell_window, view_name); - - /* Update the sidebar header. */ - - icon_name = e_shell_view_get_icon_name (shell_view); - primary_text = e_shell_view_get_primary_text (shell_view); - secondary_text = e_shell_view_get_secondary_text (shell_view); - - e_sidebar_set_icon_name (sidebar, icon_name); - e_sidebar_set_primary_text (sidebar, primary_text); - e_sidebar_set_secondary_text (sidebar, secondary_text); -} - static EShellView * shell_window_new_view (EShellWindow *shell_window, GType shell_view_type, @@ -76,7 +50,6 @@ shell_window_new_view (EShellWindow *shell_window, GtkNotebook *notebook; GtkWidget *widget; const gchar *name; - gulong handler_id; gint page_num; /* Determine the page number for the new shell view. */ @@ -102,16 +75,9 @@ shell_window_new_view (EShellWindow *shell_window, gtk_notebook_append_page (notebook, widget, NULL); notebook = GTK_NOTEBOOK (shell_window->priv->status_notebook); - widget = e_shell_view_get_status_widget (shell_view); + widget = e_shell_view_get_taskbar_widget (shell_view); gtk_notebook_append_page (notebook, widget, NULL); - handler_id = g_signal_connect_swapped ( - shell_view, "notify", - G_CALLBACK (shell_window_update_sidebar), shell_window); - - /* This will be unblocked when the shell view is selected. */ - g_signal_handler_block (shell_view, handler_id); - return shell_view; } @@ -280,16 +246,16 @@ shell_window_class_init (EShellWindowClass *class) static void shell_window_init (EShellWindow *shell_window) { - GtkUIManager *manager; + GtkUIManager *ui_manager; shell_window->priv = E_SHELL_WINDOW_GET_PRIVATE (shell_window); e_shell_window_private_init (shell_window); - manager = e_shell_window_get_ui_manager (shell_window); + ui_manager = e_shell_window_get_ui_manager (shell_window); e_plugin_ui_register_manager ( - "org.gnome.evolution.shell", manager, shell_window); + "org.gnome.evolution.shell", ui_manager, shell_window); } GType @@ -386,22 +352,22 @@ e_shell_window_get_ui_manager (EShellWindow *shell_window) { g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), NULL); - return shell_window->priv->manager; + return shell_window->priv->ui_manager; } GtkAction * e_shell_window_get_action (EShellWindow *shell_window, const gchar *action_name) { - GtkUIManager *manager; + GtkUIManager *ui_manager; GtkAction *action = NULL; GList *iter; g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), NULL); g_return_val_if_fail (action_name != NULL, NULL); - manager = e_shell_window_get_ui_manager (shell_window); - iter = gtk_ui_manager_get_action_groups (manager); + ui_manager = e_shell_window_get_ui_manager (shell_window); + iter = gtk_ui_manager_get_action_groups (ui_manager); while (iter != NULL && action == NULL) { GtkActionGroup *action_group = iter->data; @@ -420,14 +386,14 @@ GtkActionGroup * e_shell_window_get_action_group (EShellWindow *shell_window, const gchar *group_name) { - GtkUIManager *manager; + GtkUIManager *ui_manager; GList *iter; g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), NULL); g_return_val_if_fail (group_name != NULL, NULL); - manager = e_shell_window_get_ui_manager (shell_window); - iter = gtk_ui_manager_get_action_groups (manager); + ui_manager = e_shell_window_get_ui_manager (shell_window); + iter = gtk_ui_manager_get_action_groups (ui_manager); while (iter != NULL) { GtkActionGroup *action_group = iter->data; @@ -447,14 +413,14 @@ GtkWidget * e_shell_window_get_managed_widget (EShellWindow *shell_window, const gchar *widget_path) { - GtkUIManager *manager; + GtkUIManager *ui_manager; GtkWidget *widget; g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), NULL); g_return_val_if_fail (widget_path != NULL, NULL); - manager = e_shell_window_get_ui_manager (shell_window); - widget = gtk_ui_manager_get_widget (manager, widget_path); + ui_manager = e_shell_window_get_ui_manager (shell_window); + widget = gtk_ui_manager_get_widget (ui_manager, widget_path); g_return_val_if_fail (widget != NULL, NULL); @@ -481,14 +447,6 @@ e_shell_window_set_current_view (EShellWindow *shell_window, g_return_if_fail (E_IS_SHELL_WINDOW (shell_window)); - if (shell_window->priv->current_view != NULL) { - view_name = e_shell_window_get_current_view (shell_window); - shell_view = e_shell_window_get_view (shell_window, view_name); - - g_signal_handlers_block_by_func ( - shell_view, shell_window_update_sidebar, shell_window); - } - view_name = name_or_alias; if (view_name != NULL) @@ -515,10 +473,7 @@ e_shell_window_set_current_view (EShellWindow *shell_window, shell_window->priv->current_view = view_name; g_object_notify (G_OBJECT (shell_window), "current-view"); - g_signal_handlers_unblock_by_func ( - shell_view, shell_window_update_sidebar, shell_window); - - shell_window_update_sidebar (shell_window); + e_shell_window_update_gal_view_menu (shell_window); /* Notify all loaded views. */ list = g_hash_table_get_values (shell_window->priv->loaded_views); @@ -553,7 +508,7 @@ e_shell_window_register_new_item_actions (EShellWindow *shell_window, { GtkActionGroup *action_group; GtkAccelGroup *accel_group; - GtkUIManager *manager; + GtkUIManager *ui_manager; guint ii; g_return_if_fail (E_IS_SHELL_WINDOW (shell_window)); @@ -561,8 +516,8 @@ e_shell_window_register_new_item_actions (EShellWindow *shell_window, g_return_if_fail (entries != NULL); action_group = shell_window->priv->new_item_actions; - manager = e_shell_window_get_ui_manager (shell_window); - accel_group = gtk_ui_manager_get_accel_group (manager); + ui_manager = e_shell_window_get_ui_manager (shell_window); + accel_group = gtk_ui_manager_get_accel_group (ui_manager); module_name = g_intern_string (module_name); gtk_action_group_add_actions ( @@ -600,7 +555,7 @@ e_shell_window_register_new_source_actions (EShellWindow *shell_window, { GtkActionGroup *action_group; GtkAccelGroup *accel_group; - GtkUIManager *manager; + GtkUIManager *ui_manager; guint ii; g_return_if_fail (E_IS_SHELL_WINDOW (shell_window)); @@ -608,8 +563,8 @@ e_shell_window_register_new_source_actions (EShellWindow *shell_window, g_return_if_fail (entries != NULL); action_group = shell_window->priv->new_source_actions; - manager = e_shell_window_get_ui_manager (shell_window); - accel_group = gtk_ui_manager_get_accel_group (manager); + ui_manager = e_shell_window_get_ui_manager (shell_window); + accel_group = gtk_ui_manager_get_accel_group (ui_manager); module_name = g_intern_string (module_name); gtk_action_group_add_actions ( diff --git a/shell/e-sidebar.c b/shell/e-sidebar.c deleted file mode 100644 index af747d152a..0000000000 --- a/shell/e-sidebar.c +++ /dev/null @@ -1,901 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-sidebar.c - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "e-sidebar.h" - -#define E_SIDEBAR_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_SIDEBAR, ESidebarPrivate)) - -#define H_PADDING 6 -#define V_PADDING 6 - -struct _ESidebarPrivate { - - /* Header */ - GtkWidget *event_box; - GtkWidget *image; - GtkWidget *primary_label; - GtkWidget *secondary_label; - gchar *primary_text; - gchar *secondary_text; - - /* Switcher */ - GList *proxies; - gboolean actions_visible; - gboolean style_set; - GtkToolbarStyle style; - GtkSettings *settings; - gulong settings_handler_id; -}; - -enum { - PROP_0, - PROP_ACTIONS_VISIBLE, - PROP_ICON_NAME, - PROP_PRIMARY_TEXT, - PROP_SECONDARY_TEXT, - PROP_TOOLBAR_STYLE -}; - -enum { - STYLE_CHANGED, - LAST_SIGNAL -}; - -static gpointer parent_class; -static guint signals[LAST_SIGNAL]; - -static int -sidebar_layout_actions (ESidebar *sidebar) -{ - GtkAllocation *allocation = & GTK_WIDGET (sidebar)->allocation; - gboolean icons_only; - int num_btns = g_list_length (sidebar->priv->proxies), btns_per_row; - GList **rows, *p; - int row_number; - int max_width = 0, max_height = 0; - int row_last; - int x, y; - int i; - - y = allocation->y + allocation->height - 1; - - if (num_btns == 0) - return y; - - icons_only = (sidebar->priv->style == GTK_TOOLBAR_ICONS); - - /* Figure out the max width and height */ - for (p = sidebar->priv->proxies; p != NULL; p = p->next) { - GtkWidget *widget = p->data; - GtkRequisition requisition; - - gtk_widget_size_request (widget, &requisition); - max_height = MAX (max_height, requisition.height); - max_width = MAX (max_width, requisition.width); - } - - /* Figure out how many rows and columns we'll use. */ - btns_per_row = MAX (1, allocation->width / (max_width + H_PADDING)); - if (!icons_only) { - /* If using text buttons, we want to try to have a - * completely filled-in grid, but if we can't, we want - * the odd row to have just a single button. - */ - while (num_btns % btns_per_row > 1) - btns_per_row--; - } - - /* Assign buttons to rows */ - rows = g_new0 (GList *, num_btns / btns_per_row + 1); - - if (!icons_only && num_btns % btns_per_row != 0) { - rows [0] = g_list_append (rows [0], sidebar->priv->proxies->data); - - p = sidebar->priv->proxies->next; - row_number = p ? 1 : 0; - } else { - p = sidebar->priv->proxies; - row_number = 0; - } - - for (; p != NULL; p = p->next) { - GtkWidget *widget = p->data; - - if (g_list_length (rows [row_number]) == btns_per_row) - row_number ++; - - rows [row_number] = g_list_append (rows [row_number], widget); - } - - row_last = row_number; - - /* Layout the buttons. */ - for (i = row_last; i >= 0; i --) { - int len, extra_width; - - y -= max_height; - x = H_PADDING + allocation->x; - len = g_list_length (rows[i]); - if (!icons_only) - extra_width = (allocation->width - (len * max_width ) - (len * H_PADDING)) / len; - else - extra_width = 0; - for (p = rows [i]; p != NULL; p = p->next) { - GtkAllocation child_allocation; - - child_allocation.x = x; - child_allocation.y = y; - child_allocation.width = max_width + extra_width; - child_allocation.height = max_height; - - gtk_widget_size_allocate (GTK_WIDGET (p->data), &child_allocation); - - x += child_allocation.width + H_PADDING; - } - - y -= V_PADDING; - } - - for (i = 0; i <= row_last; i ++) - g_list_free (rows [i]); - g_free (rows); - - return y; -} - -static void -sidebar_toolbar_style_changed_cb (ESidebar *sidebar) -{ - if (!sidebar->priv->style_set) { - sidebar->priv->style_set = TRUE; - e_sidebar_unset_style (sidebar); - } -} - -static void -sidebar_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ACTIONS_VISIBLE: - e_sidebar_set_actions_visible ( - E_SIDEBAR (object), - g_value_get_boolean (value)); - return; - - case PROP_ICON_NAME: - e_sidebar_set_icon_name ( - E_SIDEBAR (object), - g_value_get_string (value)); - return; - - case PROP_PRIMARY_TEXT: - e_sidebar_set_primary_text ( - E_SIDEBAR (object), - g_value_get_string (value)); - return; - - case PROP_SECONDARY_TEXT: - e_sidebar_set_secondary_text ( - E_SIDEBAR (object), - g_value_get_string (value)); - return; - - case PROP_TOOLBAR_STYLE: - e_sidebar_set_style ( - E_SIDEBAR (object), - g_value_get_enum (value)); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -sidebar_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ACTIONS_VISIBLE: - g_value_set_boolean ( - value, e_sidebar_get_actions_visible ( - E_SIDEBAR (object))); - return; - - case PROP_ICON_NAME: - g_value_set_string ( - value, e_sidebar_get_icon_name ( - E_SIDEBAR (object))); - return; - - case PROP_PRIMARY_TEXT: - g_value_set_string ( - value, e_sidebar_get_primary_text ( - E_SIDEBAR (object))); - return; - - case PROP_SECONDARY_TEXT: - g_value_set_string ( - value, e_sidebar_get_secondary_text ( - E_SIDEBAR (object))); - return; - - case PROP_TOOLBAR_STYLE: - g_value_set_enum ( - value, e_sidebar_get_style ( - E_SIDEBAR (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -sidebar_dispose (GObject *object) -{ - ESidebarPrivate *priv; - - priv = E_SIDEBAR_GET_PRIVATE (object); - - if (priv->event_box != NULL) { - g_object_unref (priv->event_box); - priv->event_box = NULL; - } - - if (priv->image != NULL) { - g_object_unref (priv->image); - priv->image = NULL; - } - - if (priv->primary_label != NULL) { - g_object_unref (priv->primary_label); - priv->image = NULL; - } - - if (priv->secondary_label != NULL) { - g_object_unref (priv->secondary_label); - priv->secondary_label = NULL; - } - - while (priv->proxies != NULL) { - GtkWidget *widget = priv->proxies->data; - gtk_container_remove (GTK_CONTAINER (object), widget); - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -static void -sidebar_finalize (GObject *object) -{ - ESidebarPrivate *priv; - - priv = E_SIDEBAR_GET_PRIVATE (object); - - g_free (priv->primary_text); - g_free (priv->secondary_text); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -sidebar_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - ESidebarPrivate *priv; - GtkRequisition child_requisition; - GtkWidget *child; - GList *iter; - - priv = E_SIDEBAR_GET_PRIVATE (widget); - child = gtk_bin_get_child (GTK_BIN (widget)); - - if (child == NULL) { - requisition->width = 2 * H_PADDING; - requisition->height = V_PADDING; - } else { - gtk_widget_size_request (child, requisition); - } - - child = priv->event_box; - gtk_widget_size_request (child, &child_requisition); - requisition->width = MAX (requisition->width, child_requisition.width); - requisition->height += child_requisition.height; - - if (!priv->actions_visible) - return; - - for (iter = priv->proxies; iter != NULL; iter = iter->next) { - GtkWidget *widget = iter->data; - GtkRequisition child_requisition; - - gtk_widget_size_request (widget, &child_requisition); - - child_requisition.width += H_PADDING; - child_requisition.height += V_PADDING; - - requisition->width = MAX ( - requisition->width, child_requisition.width); - requisition->height += child_requisition.height; - } -} - -static void -sidebar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - ESidebarPrivate *priv; - GtkAllocation child_allocation; - GtkRequisition child_requisition; - GtkWidget *child; - gint y; - - priv = E_SIDEBAR_GET_PRIVATE (widget); - - widget->allocation = *allocation; - - child = priv->event_box; - gtk_widget_size_request (child, &child_requisition); - - child_allocation.x = allocation->x; - child_allocation.y = allocation->y; - child_allocation.width = allocation->width; - child_allocation.height = child_requisition.height; - - gtk_widget_size_allocate (child, &child_allocation); - - allocation->y += child_requisition.height; - - if (priv->actions_visible) - y = sidebar_layout_actions (E_SIDEBAR (widget)); - else - y = allocation->y + allocation->height; - - child = gtk_bin_get_child (GTK_BIN (widget)); - - if (child != NULL) { - child_allocation.x = allocation->x; - child_allocation.y = allocation->y; - child_allocation.width = allocation->width; - child_allocation.height = y - allocation->y; - - gtk_widget_size_allocate (child, &child_allocation); - } -} - -static void -sidebar_screen_changed (GtkWidget *widget, - GdkScreen *previous_screen) -{ - ESidebarPrivate *priv; - GtkSettings *settings; - - priv = E_SIDEBAR_GET_PRIVATE (widget); - - if (gtk_widget_has_screen (widget)) - settings = gtk_widget_get_settings (widget); - else - settings = NULL; - - if (settings == priv->settings) - return; - - if (priv->settings != NULL) { - g_signal_handler_disconnect ( - priv->settings, priv->settings_handler_id); - g_object_unref (priv->settings); - } - - if (settings != NULL) { - priv->settings = g_object_ref (settings); - priv->settings_handler_id = g_signal_connect_swapped ( - settings, "notify::gtk-toolbar-style", - G_CALLBACK (sidebar_toolbar_style_changed_cb), widget); - } else - priv->settings = NULL; - - sidebar_toolbar_style_changed_cb (E_SIDEBAR (widget)); -} - -static void -sidebar_remove (GtkContainer *container, - GtkWidget *widget) -{ - ESidebarPrivate *priv; - GList *link; - - priv = E_SIDEBAR_GET_PRIVATE (container); - - /* Look in the internal widgets first. */ - - if (widget == priv->event_box) { - gtk_widget_unparent (priv->event_box); - gtk_widget_queue_resize (GTK_WIDGET (container)); - return; - } - - link = g_list_find (priv->proxies, widget); - if (link != NULL) { - GtkWidget *widget = link->data; - - gtk_widget_unparent (widget); - priv->proxies = g_list_delete_link (priv->proxies, link); - gtk_widget_queue_resize (GTK_WIDGET (container)); - return; - } - - /* Chain up to parent's remove() method. */ - GTK_CONTAINER_CLASS (parent_class)->remove (container, widget); -} - -static void -sidebar_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - ESidebarPrivate *priv; - - priv = E_SIDEBAR_GET_PRIVATE (container); - - if (include_internals) { - callback (priv->event_box, callback_data); - g_list_foreach ( - priv->proxies, (GFunc) callback, callback_data); - } - - /* Chain up to parent's forall() method. */ - GTK_CONTAINER_CLASS (parent_class)->forall ( - container, include_internals, callback, callback_data); -} - -static void -sidebar_style_changed (ESidebar *sidebar, - GtkToolbarStyle style) -{ - if (sidebar->priv->style == style) - return; - - sidebar->priv->style = style; - - g_list_foreach ( - sidebar->priv->proxies, - (GFunc) gtk_tool_item_toolbar_reconfigured, NULL); - - gtk_widget_queue_resize (GTK_WIDGET (sidebar)); - g_object_notify (G_OBJECT (sidebar), "toolbar-style"); -} - -static GtkIconSize -sidebar_get_icon_size (GtkToolShell *shell) -{ - return GTK_ICON_SIZE_LARGE_TOOLBAR; -} - -static GtkOrientation -sidebar_get_orientation (GtkToolShell *shell) -{ - return GTK_ORIENTATION_HORIZONTAL; -} - -static GtkToolbarStyle -sidebar_get_style (GtkToolShell *shell) -{ - return e_sidebar_get_style (E_SIDEBAR (shell)); -} - -static GtkReliefStyle -sidebar_get_relief_style (GtkToolShell *shell) -{ - /* XXX GTK+ 2.13.6 discards this value. - * http://bugzilla.gnome.org/show_bug.cgi?id=549943 */ - return GTK_RELIEF_NORMAL; -} - -static void -sidebar_class_init (ESidebarClass *class) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - parent_class = g_type_class_peek_parent (class); - g_type_class_add_private (class, sizeof (ESidebarPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = sidebar_set_property; - object_class->get_property = sidebar_get_property; - object_class->dispose = sidebar_dispose; - object_class->finalize = sidebar_finalize; - - widget_class = GTK_WIDGET_CLASS (class); - widget_class->size_request = sidebar_size_request; - widget_class->size_allocate = sidebar_size_allocate; - widget_class->screen_changed = sidebar_screen_changed; - - container_class = GTK_CONTAINER_CLASS (class); - container_class->remove = sidebar_remove; - container_class->forall = sidebar_forall; - - class->style_changed = sidebar_style_changed; - - g_object_class_install_property ( - object_class, - PROP_ACTIONS_VISIBLE, - g_param_spec_boolean ( - "actions-visible", - NULL, - NULL, - TRUE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - object_class, - PROP_ICON_NAME, - g_param_spec_string ( - "icon-name", - NULL, - NULL, - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - object_class, - PROP_PRIMARY_TEXT, - g_param_spec_string ( - "primary-text", - NULL, - NULL, - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - object_class, - PROP_SECONDARY_TEXT, - g_param_spec_string ( - "secondary-text", - NULL, - NULL, - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - object_class, - PROP_TOOLBAR_STYLE, - g_param_spec_enum ( - "toolbar-style", - NULL, - NULL, - GTK_TYPE_TOOLBAR_STYLE, - E_SIDEBAR_DEFAULT_TOOLBAR_STYLE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - signals[STYLE_CHANGED] = g_signal_new ( - "style-changed", - G_OBJECT_CLASS_TYPE (class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (ESidebarClass, style_changed), - NULL, NULL, - g_cclosure_marshal_VOID__ENUM, - G_TYPE_NONE, 1, - GTK_TYPE_TOOLBAR_STYLE); -} - -static void -sidebar_init (ESidebar *sidebar) -{ - GtkStyle *style; - GtkWidget *container; - GtkWidget *widget; - const GdkColor *color; - - sidebar->priv = E_SIDEBAR_GET_PRIVATE (sidebar); - - GTK_WIDGET_SET_FLAGS (sidebar, GTK_NO_WINDOW); - - widget = gtk_event_box_new (); - style = gtk_widget_get_style (widget); - color = &style->bg[GTK_STATE_ACTIVE]; - gtk_container_set_border_width (GTK_CONTAINER (widget), 1); - gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, color); - gtk_widget_set_parent (widget, GTK_WIDGET (sidebar)); - sidebar->priv->event_box = g_object_ref (widget); - gtk_widget_show (widget); - - container = widget; - - widget = gtk_hbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (widget), 6); - gtk_container_add (GTK_CONTAINER (container), widget); - gtk_widget_show (widget); - - container = widget; - - widget = gtk_image_new (); - gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); - sidebar->priv->image = g_object_ref (widget); - gtk_widget_show (widget); - - widget = gtk_label_new (NULL); - gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_END); - gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); - sidebar->priv->primary_label = g_object_ref (widget); - gtk_widget_show (widget); - - widget = gtk_label_new (NULL); - gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_MIDDLE); - gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5); - gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); - sidebar->priv->secondary_label = g_object_ref (widget); - gtk_widget_show (widget); -} - -static void -sidebar_tool_shell_iface_init (GtkToolShellIface *iface) -{ - iface->get_icon_size = sidebar_get_icon_size; - iface->get_orientation = sidebar_get_orientation; - iface->get_style = sidebar_get_style; - iface->get_relief_style = sidebar_get_relief_style; -} - -GType -e_sidebar_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) { - static const GTypeInfo type_info = { - sizeof (ESidebarClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) sidebar_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (ESidebar), - 0, /* n_preallocs */ - (GInstanceInitFunc) sidebar_init, - NULL /* value_table */ - }; - - static const GInterfaceInfo tool_shell_info = { - (GInterfaceInitFunc) sidebar_tool_shell_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL /* interface_data */ - }; - - type = g_type_register_static ( - GTK_TYPE_BIN, "ESidebar", &type_info, 0); - - g_type_add_interface_static ( - type, GTK_TYPE_TOOL_SHELL, &tool_shell_info); - } - - return type; -} - -GtkWidget * -e_sidebar_new (void) -{ - return g_object_new (E_TYPE_SIDEBAR, NULL); -} - -void -e_sidebar_add_action (ESidebar *sidebar, - GtkAction *action) -{ - GtkWidget *widget; - - g_return_if_fail (E_IS_SIDEBAR (sidebar)); - g_return_if_fail (GTK_IS_ACTION (action)); - - g_object_ref (action); - widget = gtk_action_create_tool_item (action); - gtk_tool_item_set_is_important (GTK_TOOL_ITEM (widget), TRUE); - gtk_widget_show (widget); - - sidebar->priv->proxies = g_list_append ( - sidebar->priv->proxies, widget); - - gtk_widget_set_parent (widget, GTK_WIDGET (sidebar)); - gtk_widget_queue_resize (GTK_WIDGET (sidebar)); -} - -gboolean -e_sidebar_get_actions_visible (ESidebar *sidebar) -{ - g_return_val_if_fail (E_IS_SIDEBAR (sidebar), FALSE); - - return sidebar->priv->actions_visible; -} - -void -e_sidebar_set_actions_visible (ESidebar *sidebar, - gboolean visible) -{ - GList *iter; - - if (sidebar->priv->actions_visible == visible) - return; - - sidebar->priv->actions_visible = visible; - - for (iter = sidebar->priv->proxies; iter != NULL; iter = iter->next) - g_object_set (iter->data, "visible", visible, NULL); - - gtk_widget_queue_resize (GTK_WIDGET (sidebar)); - - g_object_notify (G_OBJECT (sidebar), "actions-visible"); -} - -const gchar * -e_sidebar_get_icon_name (ESidebar *sidebar) -{ - GtkImage *image; - const gchar *icon_name; - - g_return_val_if_fail (E_IS_SIDEBAR (sidebar), NULL); - - image = GTK_IMAGE (sidebar->priv->image); - gtk_image_get_icon_name (image, &icon_name, NULL); - - return icon_name; -} - -void -e_sidebar_set_icon_name (ESidebar *sidebar, - const gchar *icon_name) -{ - GtkImage *image; - - g_return_if_fail (E_IS_SIDEBAR (sidebar)); - - if (icon_name == NULL) - icon_name = "image-missing"; - - image = GTK_IMAGE (sidebar->priv->image); - gtk_image_set_from_icon_name (image, icon_name, GTK_ICON_SIZE_MENU); - - gtk_widget_queue_resize (GTK_WIDGET (sidebar)); - g_object_notify (G_OBJECT (sidebar), "icon-name"); -} - -const gchar * -e_sidebar_get_primary_text (ESidebar *sidebar) -{ - g_return_val_if_fail (E_IS_SIDEBAR (sidebar), NULL); - - return sidebar->priv->primary_text; -} - -void -e_sidebar_set_primary_text (ESidebar *sidebar, - const gchar *primary_text) -{ - GtkLabel *label; - gchar *markup; - - g_return_if_fail (E_IS_SIDEBAR (sidebar)); - - g_free (sidebar->priv->primary_text); - sidebar->priv->primary_text = g_strdup (primary_text); - - if (primary_text == NULL) - primary_text = ""; - - label = GTK_LABEL (sidebar->priv->primary_label); - markup = g_markup_printf_escaped ("%s", primary_text); - gtk_label_set_markup (label, markup); - g_free (markup); - - gtk_widget_queue_resize (GTK_WIDGET (sidebar)); - g_object_notify (G_OBJECT (sidebar), "primary-text"); -} - -const gchar * -e_sidebar_get_secondary_text (ESidebar *sidebar) -{ - g_return_val_if_fail (E_IS_SIDEBAR (sidebar), NULL); - - return sidebar->priv->secondary_text; -} - -void -e_sidebar_set_secondary_text (ESidebar *sidebar, - const gchar *secondary_text) -{ - GtkLabel *label; - gchar *markup; - - g_return_if_fail (E_IS_SIDEBAR (sidebar)); - - g_free (sidebar->priv->secondary_text); - sidebar->priv->secondary_text = g_strdup (secondary_text); - - if (secondary_text == NULL) - secondary_text = ""; - - label = GTK_LABEL (sidebar->priv->secondary_label); - markup = g_markup_printf_escaped ("%s", secondary_text); - gtk_label_set_markup (label, markup); - g_free (markup); - - gtk_widget_queue_resize (GTK_WIDGET (sidebar)); - g_object_notify (G_OBJECT (sidebar), "secondary-text"); -} - -GtkToolbarStyle -e_sidebar_get_style (ESidebar *sidebar) -{ - g_return_val_if_fail ( - E_IS_SIDEBAR (sidebar), E_SIDEBAR_DEFAULT_TOOLBAR_STYLE); - - return sidebar->priv->style; -} - -void -e_sidebar_set_style (ESidebar *sidebar, - GtkToolbarStyle style) -{ - g_return_if_fail (E_IS_SIDEBAR (sidebar)); - - sidebar->priv->style_set = TRUE; - g_signal_emit (sidebar, signals[STYLE_CHANGED], 0, style); -} - -void -e_sidebar_unset_style (ESidebar *sidebar) -{ - GtkSettings *settings; - GtkToolbarStyle style; - - g_return_if_fail (E_IS_SIDEBAR (sidebar)); - - if (!sidebar->priv->style_set) - return; - - settings = sidebar->priv->settings; - if (settings != NULL) - g_object_get (settings, "gtk-toolbar-style", &style, NULL); - else - style = E_SIDEBAR_DEFAULT_TOOLBAR_STYLE; - - if (style == GTK_TOOLBAR_BOTH) - style = GTK_TOOLBAR_BOTH_HORIZ; - - if (style != sidebar->priv->style) - g_signal_emit (sidebar, signals[STYLE_CHANGED], 0, style); - - sidebar->priv->style_set = FALSE; -} diff --git a/shell/e-sidebar.h b/shell/e-sidebar.h deleted file mode 100644 index 0386a431bc..0000000000 --- a/shell/e-sidebar.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-sidebar.h - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 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., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef E_SIDEBAR_H -#define E_SIDEBAR_H - -#include - -/* Standard GObject macros */ -#define E_TYPE_SIDEBAR \ - (e_sidebar_get_type ()) -#define E_SIDEBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_SIDEBAR, ESidebar)) -#define E_SIDEBAR_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_SIDEBAR, ESidebarClass)) -#define E_IS_SIDEBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_SIDEBAR)) -#define E_IS_SIDEBAR_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((obj), E_TYPE_SIDEBAR)) -#define E_SIDEBAR_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_SIDEBAR, ESidebarClass)) - -#define E_SIDEBAR_DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH_HORIZ - -G_BEGIN_DECLS - -typedef struct _ESidebar ESidebar; -typedef struct _ESidebarClass ESidebarClass; -typedef struct _ESidebarPrivate ESidebarPrivate; - -struct _ESidebar { - GtkBin parent; - ESidebarPrivate *priv; -}; - -struct _ESidebarClass { - GtkBinClass parent_class; - - void (*style_changed) (ESidebar *sidebar, - GtkToolbarStyle style); -}; - -GType e_sidebar_get_type (void); -GtkWidget * e_sidebar_new (void); -void e_sidebar_add_action (ESidebar *sidebar, - GtkAction *action); -gboolean e_sidebar_get_actions_visible (ESidebar *sidebar); -void e_sidebar_set_actions_visible (ESidebar *sidebar, - gboolean visible); -const gchar * e_sidebar_get_icon_name (ESidebar *sidebar); -void e_sidebar_set_icon_name (ESidebar *sidebar, - const gchar *icon_name); -const gchar * e_sidebar_get_primary_text (ESidebar *sidebar); -void e_sidebar_set_primary_text (ESidebar *sidebar, - const gchar *primary_text); -const gchar * e_sidebar_get_secondary_text (ESidebar *sidebar); -void e_sidebar_set_secondary_text (ESidebar *sidebar, - const gchar *secondary_text); -GtkToolbarStyle e_sidebar_get_style (ESidebar *sidebar); -void e_sidebar_set_style (ESidebar *sidebar, - GtkToolbarStyle style); -void e_sidebar_unset_style (ESidebar *sidebar); - -G_END_DECLS - -#endif /* E_SIDEBAR_H */ diff --git a/shell/test/Makefile.am b/shell/test/Makefile.am index e355da60c8..d1ddefa268 100644 --- a/shell/test/Makefile.am +++ b/shell/test/Makefile.am @@ -2,6 +2,8 @@ module_LTLIBRARIES = libevolution-test.la INCLUDES = \ -I$(top_srcdir)/shell \ + -I$(top_srcdir)/widgets \ + -I$(top_srcdir)/widgets/menus \ -I$(top_srcdir)/widgets/misc \ -I$(top_builddir)/shell \ -DG_LOG_DOMAIN=\"evolution-test\" \ diff --git a/shell/test/e-test-shell-view.c b/shell/test/e-test-shell-view.c index db008fafea..e88df99d96 100644 --- a/shell/test/e-test-shell-view.c +++ b/shell/test/e-test-shell-view.c @@ -25,70 +25,12 @@ ((obj), E_TYPE_TEST_SHELL_VIEW, ETestShellViewPrivate)) struct _ETestShellViewPrivate { - GtkWidget *content_widget; - GtkWidget *sidebar_widget; - GtkWidget *status_widget; + gint dummy; }; GType e_test_shell_view_type = 0; static gpointer parent_class; -static void -test_shell_view_dispose (GObject *object) -{ - ETestShellViewPrivate *priv; - - priv = E_TEST_SHELL_VIEW_GET_PRIVATE (object); - - if (priv->content_widget != NULL) { - g_object_unref (priv->content_widget); - priv->content_widget = NULL; - } - - if (priv->sidebar_widget != NULL) { - g_object_unref (priv->sidebar_widget); - priv->sidebar_widget = NULL; - } - - if (priv->status_widget != NULL) { - g_object_unref (priv->status_widget); - priv->status_widget = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -static GtkWidget * -test_shell_view_get_content_widget (EShellView *shell_view) -{ - ETestShellViewPrivate *priv; - - priv = E_TEST_SHELL_VIEW_GET_PRIVATE (shell_view); - - return priv->content_widget; -} - -static GtkWidget * -test_shell_view_get_sidebar_widget (EShellView *shell_view) -{ - ETestShellViewPrivate *priv; - - priv = E_TEST_SHELL_VIEW_GET_PRIVATE (shell_view); - - return priv->sidebar_widget; -} - -static GtkWidget * -test_shell_view_get_status_widget (EShellView *shell_view) -{ - ETestShellViewPrivate *priv; - - priv = E_TEST_SHELL_VIEW_GET_PRIVATE (shell_view); - - return priv->status_widget; -} - static void test_shell_view_changed (EShellView *shell_view) { @@ -104,47 +46,38 @@ static void test_shell_view_class_init (ETestShellViewClass *class, GTypeModule *type_module) { - GObjectClass *object_class; EShellViewClass *shell_view_class; parent_class = g_type_class_peek_parent (class); g_type_class_add_private (class, sizeof (ETestShellViewPrivate)); - object_class = G_OBJECT_CLASS (class); - object_class->dispose = test_shell_view_dispose; - shell_view_class = E_SHELL_VIEW_CLASS (class); shell_view_class->label = "Test"; shell_view_class->icon_name = "face-monkey"; shell_view_class->type_module = type_module; shell_view_class->changed = test_shell_view_changed; - - shell_view_class->get_content_widget = - test_shell_view_get_content_widget; - shell_view_class->get_sidebar_widget = - test_shell_view_get_sidebar_widget; - shell_view_class->get_status_widget = - test_shell_view_get_status_widget; } static void test_shell_view_init (ETestShellView *test_shell_view) { + EShellView *shell_view; + GtkWidget *container; GtkWidget *widget; test_shell_view->priv = E_TEST_SHELL_VIEW_GET_PRIVATE (test_shell_view); + shell_view = E_SHELL_VIEW (test_shell_view); + + container = e_shell_view_get_content_widget (shell_view); widget = gtk_label_new ("Content Widget"); - test_shell_view->priv->content_widget = g_object_ref_sink (widget); + gtk_container_add (GTK_CONTAINER (container), widget); gtk_widget_show (widget); + container = e_shell_view_get_sidebar_widget (shell_view); widget = gtk_label_new ("Sidebar Widget"); - test_shell_view->priv->sidebar_widget = g_object_ref_sink (widget); - gtk_widget_show (widget); - - widget = gtk_label_new ("Status Widget"); - test_shell_view->priv->status_widget = g_object_ref_sink (widget); + gtk_container_add (GTK_CONTAINER (container), widget); gtk_widget_show (widget); } -- cgit