diff options
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ChangeLog | 17 | ||||
-rw-r--r-- | shell/Makefile.am | 4 | ||||
-rw-r--r-- | shell/e-shell-window.c | 28 | ||||
-rw-r--r-- | shell/e-shell.c | 19 | ||||
-rw-r--r-- | shell/es-event.c | 193 | ||||
-rw-r--r-- | shell/es-event.h | 95 | ||||
-rw-r--r-- | shell/es-menu.c | 188 | ||||
-rw-r--r-- | shell/es-menu.h | 96 | ||||
-rw-r--r-- | shell/main.c | 8 |
9 files changed, 645 insertions, 3 deletions
diff --git a/shell/ChangeLog b/shell/ChangeLog index d2ed6880a8..7412630195 100644 --- a/shell/ChangeLog +++ b/shell/ChangeLog @@ -1,3 +1,20 @@ +2004-10-25 Not Zed <NotZed@Ximian.com> + + * main.c (main): register event hook. + + * e-shell.c (offline_procedure_finished_cb, e_shell_go_online): + emit new state changed event. + + * main.c (main): register the menu hook. + (): only define DEVELOPMENT if not already. + + * e-shell-window.c (init): setup menu manager. + (e_shell_window_new): activate menu manager. + (update_offline_toggle_status): update the menu manager when the + offline state changes (currently only state which requires it) + + * es-menu.[ch]: Shell plugin menu manager. + 2004-10-07 Not Zed <NotZed@Ximian.com> * main.c (main): initialise plugin system. diff --git a/shell/Makefile.am b/shell/Makefile.am index 4583f3cb92..bfaa6d97a5 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -132,6 +132,10 @@ evolution_SOURCES = \ e-shell.h \ e-sidebar.c \ e-sidebar.h \ + es-event.c \ + es-event.h \ + es-menu.c \ + es-menu.h \ main.c evolution_LDADD = \ diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c index 1d9c4f5202..05e4384c95 100644 --- a/shell/e-shell-window.c +++ b/shell/e-shell-window.c @@ -30,6 +30,7 @@ #include "e-shell-window-commands.h" #include "e-shell-marshal.h" #include "e-sidebar.h" +#include "es-menu.h" #include <gal/util/e-util.h> @@ -79,6 +80,9 @@ typedef struct _ComponentView ComponentView; struct _EShellWindowPrivate { EShell *shell; + /* plugin menu manager */ + ESMenu *menu; + /* All the ComponentViews. */ GSList *component_views; @@ -326,6 +330,8 @@ update_offline_toggle_status (EShellWindow *window) GdkBitmap *icon_mask; const char *tooltip; gboolean sensitive; + guint32 flags = 0; + ESMenuTargetShell *t; priv = window->priv; @@ -336,12 +342,14 @@ update_offline_toggle_status (EShellWindow *window) sensitive = TRUE; tooltip = _("Evolution is currently online. " "Click on this button to work offline."); + flags = ES_MENU_SHELL_ONLINE; break; case E_SHELL_LINE_STATUS_GOING_OFFLINE: icon_pixmap = online_pixmap; icon_mask = online_mask; sensitive = FALSE; tooltip = _("Evolution is in the process of going offline."); + flags = ES_MENU_SHELL_OFFLINE; break; case E_SHELL_LINE_STATUS_OFFLINE: icon_pixmap = offline_pixmap; @@ -349,6 +357,7 @@ update_offline_toggle_status (EShellWindow *window) sensitive = TRUE; tooltip = _("Evolution is currently offline. " "Click on this button to work online."); + flags = ES_MENU_SHELL_OFFLINE; break; default: g_assert_not_reached (); @@ -358,6 +367,11 @@ update_offline_toggle_status (EShellWindow *window) gtk_image_set_from_pixmap (GTK_IMAGE (priv->offline_toggle_image), icon_pixmap, icon_mask); gtk_widget_set_sensitive (priv->offline_toggle, sensitive); gtk_tooltips_set_tip (priv->tooltips, priv->offline_toggle, tooltip, NULL); + + /* TODO: If we get more shell flags, this should be centralised */ + t = es_menu_target_new_shell(priv->menu, flags); + t->target.widget = (GtkWidget *)window; + e_menu_update_target((EMenu *)priv->menu, t); } static void @@ -701,6 +715,8 @@ impl_finalize (GObject *object) g_slist_foreach (priv->component_views, (GFunc) component_view_free, NULL); g_slist_free (priv->component_views); + g_object_unref(priv->menu); + g_free (priv); (* G_OBJECT_CLASS (parent_class)->finalize) (object); @@ -738,6 +754,17 @@ init (EShellWindow *shell_window) priv->tooltips = gtk_tooltips_new (); shell_window->priv = priv; + + /** @HookPoint: Shell Main Menu + * @Id: org.gnome.evolution.shell + * @Type: ESMenu + * @Target: ESMenuTargetShell + * + * This hook point is used to add bonobo menu's to the main + * evolution shell window, used for global commands not + * requiring a specific component. + */ + priv->menu = es_menu_new("org.gnome.evolution.shell"); } @@ -780,6 +807,7 @@ e_shell_window_new (EShell *shell, "evolution-" BASE_VERSION, NULL); e_shell_window_commands_setup (window); + e_menu_activate((EMenu *)priv->menu, priv->ui_component, TRUE); setup_widgets (window); diff --git a/shell/e-shell.c b/shell/e-shell.c index 07c7dd9df5..5664f669c3 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -41,6 +41,7 @@ #include "e-shell-startup-wizard.h" #include "e-shell-marshal.h" +#include "es-event.h" #include "evolution-shell-component-utils.h" @@ -1057,6 +1058,7 @@ offline_procedure_finished_cb (EShellOfflineHandler *offline_handler, { EShell *shell; EShellPrivate *priv; + ESEvent *ese; shell = E_SHELL (data); priv = shell->priv; @@ -1071,6 +1073,17 @@ offline_procedure_finished_cb (EShellOfflineHandler *offline_handler, priv->offline_handler = NULL; g_signal_emit (shell, signals[LINE_STATUS_CHANGED], 0, priv->line_status); + + /** @Event: Shell online state changed + * @Id: state.changed + * @Target: ESMenuTargetState + * + * This event is emitted whenever the shell online state changes. + * + * Only the online and offline states are emitted. + */ + ese = es_event_peek(); + e_event_emit((EEvent *)ese, "state.changed", (EEventTarget *)es_event_target_new_state(ese, TRUE)); } /** @@ -1120,7 +1133,8 @@ e_shell_go_online (EShell *shell, EShellPrivate *priv; GSList *component_infos; GSList *p; - + ESEvent *ese; + g_return_if_fail (shell != NULL); g_return_if_fail (E_IS_SHELL (shell)); g_return_if_fail (action_window == NULL || E_IS_SHELL_WINDOW (action_window)); @@ -1153,6 +1167,9 @@ e_shell_go_online (EShell *shell, priv->line_status = E_SHELL_LINE_STATUS_ONLINE; e_passwords_set_online (TRUE); g_signal_emit (shell, signals[LINE_STATUS_CHANGED], 0, priv->line_status); + + ese = es_event_peek(); + e_event_emit((EEvent *)ese, "state.changed", (EEventTarget *)es_event_target_new_state(ese, TRUE)); } diff --git a/shell/es-event.c b/shell/es-event.c new file mode 100644 index 0000000000..c49ce66163 --- /dev/null +++ b/shell/es-event.c @@ -0,0 +1,193 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Michael Zucchi <notzed@ximian.com> + * + * Copyright 2004 Ximian, Inc. (www.ximian.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include <stdlib.h> + +#include <glib.h> + +#include "es-event.h" + +static GObjectClass *eme_parent; +static ESEvent *es_event; + +static void +eme_init(GObject *o) +{ + /*ESEvent *eme = (ESEvent *)o; */ +} + +static void +eme_finalise(GObject *o) +{ + ((GObjectClass *)eme_parent)->finalize(o); +} + +static void +eme_target_free(EEvent *ep, EEventTarget *t) +{ + switch (t->type) { + case ES_EVENT_TARGET_STATE: { + ESEventTargetState *s = (ESEventTargetState *)t; + + s = s; + break; } + } + + ((EEventClass *)eme_parent)->target_free(ep, t); +} + +static void +eme_class_init(GObjectClass *klass) +{ + klass->finalize = eme_finalise; + ((EEventClass *)klass)->target_free = eme_target_free; +} + +GType +es_event_get_type(void) +{ + static GType type = 0; + + if (type == 0) { + static const GTypeInfo info = { + sizeof(ESEventClass), + NULL, NULL, + (GClassInitFunc)eme_class_init, + NULL, NULL, + sizeof(ESEvent), 0, + (GInstanceInitFunc)eme_init + }; + eme_parent = g_type_class_ref(e_event_get_type()); + type = g_type_register_static(e_event_get_type(), "ESEvent", &info, 0); + } + + return type; +} + +/** + * es_event_peek: + * @void: + * + * Get the singular instance of the shell event handler. + * + * Return value: + **/ +ESEvent *es_event_peek(void) +{ + if (es_event == NULL) { + es_event = g_object_new(es_event_get_type(), 0); + /** @HookPoint: Shell Events Hookpoint + * Id: org.gnome.evolution.shell.events + * + * This is the hook point which emits shell events. + */ + e_event_construct(&es_event->event, "org.gnome.evolution.shell.events"); + } + + return es_event; +} + +ESEventTargetState * +es_event_target_new_state(ESEvent *eme, int state) +{ + ESEventTargetState *t = e_event_target_new(&eme->event, ES_EVENT_TARGET_STATE, sizeof(*t)); + guint32 mask = ~0; + + t->state = state; + + if (state) + mask &= ~ES_EVENT_STATE_ONLINE; + else + mask &= ~ES_EVENT_STATE_OFFLINE; + + t->target.mask = mask; + + return t; +} + +/* ********************************************************************** */ + +static void *emeh_parent_class; +#define emeh ((ESEventHook *)eph) + +static const EEventHookTargetMask emeh_state_masks[] = { + { "online", ES_EVENT_STATE_ONLINE }, + { "offline", ES_EVENT_STATE_OFFLINE }, + { 0 } +}; + +static const EEventHookTargetMap emeh_targets[] = { + { "state", ES_EVENT_TARGET_STATE, emeh_state_masks }, + { 0 } +}; + +static void +emeh_finalise(GObject *o) +{ + /*EPluginHook *eph = (EPluginHook *)o;*/ + + ((GObjectClass *)emeh_parent_class)->finalize(o); +} + +static void +emeh_class_init(EPluginHookClass *klass) +{ + int i; + + /** @HookClass: Shell Main Menu + * @Id: org.gnome.evolution.shell.events:1.0 + * @Target: ESEventTargetState + * + * A hook for events coming from the shell. + **/ + + ((GObjectClass *)klass)->finalize = emeh_finalise; + ((EPluginHookClass *)klass)->id = "org.gnome.evolution.shell.events:1.0"; + + for (i=0;emeh_targets[i].type;i++) + e_event_hook_class_add_target_map((EEventHookClass *)klass, &emeh_targets[i]); + + ((EEventHookClass *)klass)->event = (EEvent *)es_event_peek(); +} + +GType +es_event_hook_get_type(void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof(ESEventHookClass), NULL, NULL, (GClassInitFunc) emeh_class_init, NULL, NULL, + sizeof(ESEventHook), 0, (GInstanceInitFunc) NULL, + }; + + emeh_parent_class = g_type_class_ref(e_event_hook_get_type()); + type = g_type_register_static(e_event_hook_get_type(), "ESEventHook", &info, 0); + } + + return type; +} diff --git a/shell/es-event.h b/shell/es-event.h new file mode 100644 index 0000000000..f660733fbb --- /dev/null +++ b/shell/es-event.h @@ -0,0 +1,95 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Authors: Michel Zucchi <notzed@ximian.com> + * + * Copyright 2003 Ximian, Inc. (www.ximian.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __ES_EVENT_H__ +#define __ES_EVENT_H__ + +#include <glib-object.h> + +#include "e-util/e-event.h" + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +typedef struct _ESEvent ESEvent; +typedef struct _ESEventClass ESEventClass; + +/* Current target description */ +enum _es_event_target_t { + ES_EVENT_TARGET_STATE, +}; + +/* Flags that qualify TARGET_STATE */ +enum { + ES_EVENT_STATE_ONLINE = 1<< 0, + ES_EVENT_STATE_OFFLINE = 1<< 0, +}; + +typedef struct _ESEventTargetState ESEventTargetState; + +struct _ESEventTargetState { + EEventTarget target; + + int state; +}; + +typedef struct _EEventItem ESEventItem; + +/* The object */ +struct _ESEvent { + EEvent event; + + struct _ESEventPrivate *priv; +}; + +struct _ESEventClass { + EEventClass event_class; +}; + +GType es_event_get_type(void); + +ESEvent *es_event_peek(void); + +ESEventTargetState *es_event_target_new_state(ESEvent *emp, int state); + +/* ********************************************************************** */ + +typedef struct _ESEventHook ESEventHook; +typedef struct _ESEventHookClass ESEventHookClass; + +struct _ESEventHook { + EEventHook hook; +}; + +struct _ESEventHookClass { + EEventHookClass hook_class; +}; + +GType es_event_hook_get_type(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __ES_EVENT_H__ */ diff --git a/shell/es-menu.c b/shell/es-menu.c new file mode 100644 index 0000000000..14c02d897c --- /dev/null +++ b/shell/es-menu.c @@ -0,0 +1,188 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Michael Zucchi <notzed@ximian.com> + * + * Copyright 2004 Ximian, Inc. (www.ximian.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include <stdlib.h> + +#include <glib.h> + +#include "es-menu.h" + +static GObjectClass *esm_parent; + +static void +esm_init(GObject *o) +{ + /*ESMenu *esm = (ESMenu *)o; */ +} + +static void +esm_finalise(GObject *o) +{ + ((GObjectClass *)esm_parent)->finalize(o); +} + +static void +esm_target_free(EMenu *ep, EMenuTarget *t) +{ + switch (t->type) { + case ES_MENU_TARGET_SHELL: { + ESMenuTargetShell *s = (ESMenuTargetShell *)t; + + s = s; + break; } + } + + ((EMenuClass *)esm_parent)->target_free(ep, t); +} + +static void +esm_class_init(GObjectClass *klass) +{ + printf("es menu class init\n"); + + klass->finalize = esm_finalise; + ((EMenuClass *)klass)->target_free = esm_target_free; +} + +GType +es_menu_get_type(void) +{ + static GType type = 0; + + if (type == 0) { + static const GTypeInfo info = { + sizeof(ESMenuClass), + NULL, NULL, + (GClassInitFunc)esm_class_init, + NULL, NULL, + sizeof(ESMenu), 0, + (GInstanceInitFunc)esm_init + }; + esm_parent = g_type_class_ref(e_menu_get_type()); + type = g_type_register_static(e_menu_get_type(), "ESMenu", &info, 0); + } + + return type; +} + +ESMenu *es_menu_new(const char *menuid) +{ + ESMenu *esm = g_object_new(es_menu_get_type(), 0); + + e_menu_construct(&esm->menu, menuid); + + return esm; +} + +/** + * es_menu_target_new_shell: + * @esm: + * @flags: + * + * Create a new menu target for the shell. + * + * Return value: + **/ +ESMenuTargetShell * +es_menu_target_new_shell(ESMenu *esm, guint32 flags) +{ + ESMenuTargetShell *t = e_menu_target_new(&esm->menu, ES_MENU_TARGET_SHELL, sizeof(*t)); + guint32 mask = ~0; + + mask &= ~ flags; + t->target.mask = mask; + + return t; +} + +/* ********************************************************************** */ + + +static void *esph_parent_class; +#define esph ((ESMenuHook *)eph) + +static const EMenuHookTargetMask esph_shell_masks[] = { + { "online", ES_MENU_SHELL_ONLINE }, + { "offline", ES_MENU_SHELL_OFFLINE }, + { 0 } +}; + +static const EMenuHookTargetMap esph_targets[] = { + { "shell", ES_MENU_TARGET_SHELL, esph_shell_masks }, + { 0 } +}; + +static void +esph_finalise(GObject *o) +{ + /*EPluginHook *eph = (EPluginHook *)o;*/ + + ((GObjectClass *)esph_parent_class)->finalize(o); +} + +static void +esph_class_init(EPluginHookClass *klass) +{ + int i; + + /** @HookClass: Shell Main Menu + * @Id: org.gnome.evolution.shell.bonobomenu:1.0 + * @Target: ESMenuTargetShell + * + * A hook for the main menus from the shell component. + * + * These menu's will be available from all components, but + * will have no context for the current component. + **/ + + ((GObjectClass *)klass)->finalize = esph_finalise; + ((EPluginHookClass *)klass)->id = "org.gnome.evolution.shell.bonobomenu:1.0"; + + for (i=0;esph_targets[i].type;i++) + e_menu_hook_class_add_target_map((EMenuHookClass *)klass, &esph_targets[i]); + + /* FIXME: leaks parent set class? */ + ((EMenuHookClass *)klass)->menu_class = g_type_class_ref(es_menu_get_type()); +} + +GType +es_menu_hook_get_type(void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof(ESMenuHookClass), NULL, NULL, (GClassInitFunc) esph_class_init, NULL, NULL, + sizeof(ESMenuHook), 0, (GInstanceInitFunc) NULL, + }; + + esph_parent_class = g_type_class_ref(e_menu_hook_get_type()); + type = g_type_register_static(e_menu_hook_get_type(), "ESMenuHook", &info, 0); + } + + return type; +} diff --git a/shell/es-menu.h b/shell/es-menu.h new file mode 100644 index 0000000000..19e2ec95dd --- /dev/null +++ b/shell/es-menu.h @@ -0,0 +1,96 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Authors: Michel Zucchi <notzed@ximian.com> + * + * Copyright 2004 Ximian, Inc. (www.ximian.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __ES_MENU_H__ +#define __ES_MENU_H__ + +#include <glib-object.h> + +#include "e-util/e-menu.h" + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +typedef struct _ESMenu ESMenu; +typedef struct _ESMenuClass ESMenuClass; + +/* Current target description */ +/* Types of popup tagets */ +enum _es_menu_target_t { + ES_MENU_TARGET_SHELL, +}; + +/* Flags that describe a TARGET_SHELL */ +enum { + ES_MENU_SHELL_ONLINE = 1<<0, + ES_MENU_SHELL_OFFLINE = 1<<1, +}; + +typedef struct _ESMenuTargetShell ESMenuTargetShell; + +struct _ESMenuTargetShell { + EMenuTarget target; + + /* current component?? */ +}; + +typedef struct _EMenuItem ESMenuItem; + +/* The object */ +struct _ESMenu { + EMenu menu; + + struct _ESMenuPrivate *priv; +}; + +struct _ESMenuClass { + EMenuClass menu_class; +}; + +GType es_menu_get_type(void); + +ESMenu *es_menu_new(const char *menuid); + +ESMenuTargetShell *es_menu_target_new_shell(ESMenu *emp, guint32 flags); + +/* ********************************************************************** */ + +typedef struct _ESMenuHook ESMenuHook; +typedef struct _ESMenuHookClass ESMenuHookClass; + +struct _ESMenuHook { + EMenuHook hook; +}; + +struct _ESMenuHookClass { + EMenuHookClass hook_class; +}; + +GType es_menu_hook_get_type(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __ES_MENU_H__ */ diff --git a/shell/main.c b/shell/main.c index c3f9cde841..94f25b89c8 100644 --- a/shell/main.c +++ b/shell/main.c @@ -33,6 +33,7 @@ #include "e-shell-constants.h" #include "e-shell.h" +#include "es-menu.h" #include <libxml/xmlmemory.h> #include <libxml/parser.h> @@ -86,8 +87,9 @@ #include "e-util/e-plugin-mono.h" #endif -#define DEVELOPMENT - +#ifndef DEVELOPMENT +#define DEVELOPMENT (1) +#endif static EShell *shell = NULL; @@ -591,6 +593,8 @@ main (int argc, char **argv) e_plugin_register_type(e_plugin_mono_get_type()); #endif e_plugin_register_type(e_plugin_lib_get_type()); + e_plugin_hook_register_type(es_menu_hook_get_type()); + e_plugin_hook_register_type(es_event_hook_get_type()); e_plugin_load_plugins(); } |