diff options
author | Not Zed <NotZed@Ximian.com> | 2004-10-15 15:36:53 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-10-15 15:36:53 +0800 |
commit | 084a2d2e3d39e7b25a6101f125a37bb05b9caf81 (patch) | |
tree | 7dfaec2c9b2feccc605d7704b0ee1b9dd93fa62b | |
parent | 3c9bfa7f65ee62000f5eef7376e4de7a88163f55 (diff) | |
download | gsoc2013-evolution-084a2d2e3d39e7b25a6101f125a37bb05b9caf81.tar.gz gsoc2013-evolution-084a2d2e3d39e7b25a6101f125a37bb05b9caf81.tar.zst gsoc2013-evolution-084a2d2e3d39e7b25a6101f125a37bb05b9caf81.zip |
added an any select mask and updated the hook maps.
2004-10-15 Not Zed <NotZed@Ximian.com>
* gui/widgets/eab-popup.c: added an any select mask and updated
the hook maps.
* gui/component/addressbook-component.c
(addressbook_component_init): register the addressbook hooks.
* gui/component/addressbook-view.c (addressbook_view_init): setup
the menu manager.
(control_activate_cb): activate the menu manager.
(update_command_state): and update the menu manager.
* gui/widgets/eab-menu.[ch]: Added menu manager class.
svn path=/trunk/; revision=27589
-rw-r--r-- | addressbook/ChangeLog | 15 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook-component.c | 10 | ||||
-rw-r--r-- | addressbook/gui/component/addressbook-view.c | 15 | ||||
-rw-r--r-- | addressbook/gui/widgets/Makefile.am | 2 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-view.c | 23 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-view.h | 5 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-menu.c | 257 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-menu.h | 109 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-popup.c | 13 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-popup.h | 8 |
10 files changed, 453 insertions, 4 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index c8aa933f09..77f65e0044 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,18 @@ +2004-10-15 Not Zed <NotZed@Ximian.com> + + * gui/widgets/eab-popup.c: added an any select mask and updated + the hook maps. + + * gui/component/addressbook-component.c + (addressbook_component_init): register the addressbook hooks. + + * gui/component/addressbook-view.c (addressbook_view_init): setup + the menu manager. + (control_activate_cb): activate the menu manager. + (update_command_state): and update the menu manager. + + * gui/widgets/eab-menu.[ch]: Added menu manager class. + 2004-10-13 JP Rosevear <jpr@novell.com> * importers/evolution-vcard-importer.c: find source selector and diff --git a/addressbook/gui/component/addressbook-component.c b/addressbook/gui/component/addressbook-component.c index befd07098d..9e71580d0b 100644 --- a/addressbook/gui/component/addressbook-component.c +++ b/addressbook/gui/component/addressbook-component.c @@ -31,6 +31,9 @@ #include "addressbook-view.h" #include "addressbook/gui/contact-editor/eab-editor.h" #include "addressbook/gui/widgets/eab-gui-util.h" +#include "e-util/e-plugin.h" +#include "addressbook/gui/widgets/eab-popup.h" +#include "addressbook/gui/widgets/eab-menu.h" #include "widgets/misc/e-task-bar.h" #include "widgets/misc/e-info-label.h" @@ -246,6 +249,7 @@ static void addressbook_component_init (AddressbookComponent *component) { AddressbookComponentPrivate *priv; + static int first = TRUE; priv = g_new0 (AddressbookComponentPrivate, 1); @@ -259,6 +263,12 @@ addressbook_component_init (AddressbookComponent *component) #ifdef ENABLE_SMIME smime_component_init (); #endif + + if (first) { + first = FALSE; + e_plugin_hook_register_type(eab_popup_hook_get_type()); + e_plugin_hook_register_type(eab_menu_hook_get_type()); + } } diff --git a/addressbook/gui/component/addressbook-view.c b/addressbook/gui/component/addressbook-view.c index bd5b3b3c1e..ef4a24b5e0 100644 --- a/addressbook/gui/component/addressbook-view.c +++ b/addressbook/gui/component/addressbook-view.c @@ -62,6 +62,7 @@ #include "addressbook/printing/e-contact-print.h" #include "addressbook/util/eab-book-util.h" #include "addressbook/gui/widgets/eab-popup.h" +#include "addressbook/gui/widgets/eab-menu.h" #define PARENT_TYPE G_TYPE_OBJECT static GObjectClass *parent_class = NULL; @@ -93,6 +94,8 @@ struct _AddressbookViewPrivate { ESourceList *source_list; char *passwd; EUserCreatableItemsHandler *creatable_items_handler; + + EABMenu *menu; }; enum DndTargetType { @@ -337,14 +340,20 @@ update_command_state (EABView *eav, AddressbookView *view) { AddressbookViewPrivate *priv = view->priv; BonoboUIComponent *uic; + EABMenuTargetSelect *target; if (eav != get_current_view (view)) return; g_object_ref (view); + target = eab_view_get_menu_target(eav, priv->menu); + e_menu_update_target((EMenu *)priv->menu, target); + uic = bonobo_control_get_ui_component (priv->folder_view_control); + /* TODO: this stuff can mostly be made to use the target bits instead */ + if (bonobo_ui_component_get_container (uic) != CORBA_OBJECT_NIL) { #define SET_SENSITIVE(verb,f) \ bonobo_ui_component_set_prop (uic, (verb), "sensitive", (f)(eav) ? "1" : "0", NULL) @@ -464,9 +473,11 @@ control_activate_cb (BonoboControl *control, if (activate) { control_activate (control, uic, view); + e_menu_activate((EMenu *)view->priv->menu, uic, activate); if (activate && v && v->model) eab_model_force_folder_bar_message (v->model); } else { + e_menu_activate((EMenu *)view->priv->menu, uic, activate); bonobo_ui_component_unset_container (uic, NULL); eab_view_discard_menus (v); } @@ -1087,6 +1098,7 @@ addressbook_view_init (AddressbookView *view) G_CALLBACK (source_list_changed_cb), view); priv->creatable_items_handler = e_user_creatable_items_handler_new ("contacts", NULL, NULL); + priv->menu = eab_menu_new("com.novell.evolution.addressbook.view"); g_signal_connect (priv->folder_view_control, "activate", G_CALLBACK (control_activate_cb), view); @@ -1176,6 +1188,9 @@ addressbook_view_dispose (GObject *object) if (priv->creatable_items_handler) g_object_unref (priv->creatable_items_handler); + if (priv->menu) + g_object_unref (priv->menu); + g_free (view->priv); view->priv = NULL; } diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am index 504702b277..b54045a5c8 100644 --- a/addressbook/gui/widgets/Makefile.am +++ b/addressbook/gui/widgets/Makefile.am @@ -44,6 +44,8 @@ libeabwidgets_la_SOURCES = \ eab-contact-display.h \ eab-gui-util.c \ eab-gui-util.h \ + eab-menu.c \ + eab-menu.h \ eab-popup.c \ eab-popup.h \ eab-popup-control.c \ diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c index ed55f42a89..09e6f7626e 100644 --- a/addressbook/gui/widgets/e-addressbook-view.c +++ b/addressbook/gui/widgets/e-addressbook-view.c @@ -44,6 +44,7 @@ #include "addressbook/printing/e-contact-print-envelope.h" #include "addressbook/gui/search/e-addressbook-search-dialog.h" #include "addressbook/gui/widgets/eab-popup.h" +#include "addressbook/gui/widgets/eab-menu.h" #include "e-util/e-categories-master-list-wombat.h" #include "e-util/e-sexp.h" @@ -2171,3 +2172,25 @@ eab_view_can_move_to_folder (EABView *view) { return view ? eab_view_selection_nonempty (view) && eab_model_editable (view->model) : FALSE; } + +EABMenuTargetSelect * +eab_view_get_menu_target (EABView *view, EABMenu *menu) +{ + GPtrArray *cards = g_ptr_array_new(); + ESelectionModel *selection_model; + EABMenuTargetSelect *t; + + selection_model = get_selection_model (view); + if (selection_model) { + ContactAndBook cab; + + cab.view = view; + cab.closure = cards; + e_selection_model_foreach(selection_model, get_card_1, &cab); + } + + t = eab_menu_target_new_select(menu, view->book, !eab_model_editable(view->model), cards); + t->target.widget = (GtkWidget *)view; + + return t; +} diff --git a/addressbook/gui/widgets/e-addressbook-view.h b/addressbook/gui/widgets/e-addressbook-view.h index 810252ea6b..a55406915e 100644 --- a/addressbook/gui/widgets/e-addressbook-view.h +++ b/addressbook/gui/widgets/e-addressbook-view.h @@ -32,6 +32,9 @@ G_BEGIN_DECLS +struct _EABMenu; +struct _EABMenuTargetSelect; + /* EABView - A card displaying information about a contact. * * The following arguments are available: @@ -154,6 +157,8 @@ gboolean eab_view_can_stop (EABView *view); gboolean eab_view_can_copy_to_folder (EABView *view); gboolean eab_view_can_move_to_folder (EABView *view); +struct _EABMenuTargetSelect *eab_view_get_menu_target (EABView *view, struct _EABMenu *menu); + G_END_DECLS; #endif /* __EAB_VIEW_H__ */ diff --git a/addressbook/gui/widgets/eab-menu.c b/addressbook/gui/widgets/eab-menu.c new file mode 100644 index 0000000000..d398c769f2 --- /dev/null +++ b/addressbook/gui/widgets/eab-menu.c @@ -0,0 +1,257 @@ +/* -*- 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 <libebook/e-contact.h> + +#include "eab-menu.h" + +static void eabm_standard_menu_factory(EMenu *emp, void *data); + +static GObjectClass *eabm_parent; + +static void +eabm_init(GObject *o) +{ + /*EABMenu *emp = (EABMenu *)o; */ +} + +static void +eabm_finalise(GObject *o) +{ + ((GObjectClass *)eabm_parent)->finalize(o); +} + +static void +eabm_target_free(EMenu *ep, EMenuTarget *t) +{ + switch (t->type) { + case EAB_MENU_TARGET_SELECT: { + EABMenuTargetSelect *s = (EABMenuTargetSelect *)t; + int i; + + for (i=0;i<s->cards->len;i++) + g_object_unref(s->cards->pdata[i]); + g_ptr_array_free(s->cards, TRUE); + g_object_unref(s->book); + break; } + } + + ((EMenuClass *)eabm_parent)->target_free(ep, t); +} + +static void +eabm_class_init(GObjectClass *klass) +{ + klass->finalize = eabm_finalise; + ((EMenuClass *)klass)->target_free = eabm_target_free; + + e_menu_class_add_factory((EMenuClass *)klass, NULL, (EMenuFactoryFunc)eabm_standard_menu_factory, NULL); +} + +GType +eab_menu_get_type(void) +{ + static GType type = 0; + + if (type == 0) { + static const GTypeInfo info = { + sizeof(EABMenuClass), + NULL, NULL, + (GClassInitFunc)eabm_class_init, + NULL, NULL, + sizeof(EABMenu), 0, + (GInstanceInitFunc)eabm_init + }; + eabm_parent = g_type_class_ref(e_menu_get_type()); + type = g_type_register_static(e_menu_get_type(), "EABMenu", &info, 0); + } + + return type; +} + +EABMenu *eab_menu_new(const char *menuid) +{ + EABMenu *emp = g_object_new(eab_menu_get_type(), 0); + + e_menu_construct(&emp->menu, menuid); + + return emp; +} + +/** + * eab_menu_target_new_select - create a menu target of the current selection. + * @eabp: Address book menu. + * @book: Book the cards belong to. May be NULL in which case cards must be an empty GPtrArray. + * @readonly: Book is read-only mode. FIXME: Why can't we just get this off the book? + * @cards: Cards selected. This will be freed on completion and the array indices unreferenced. + * + * Create a new selection menu target. + * + * Return value: + **/ +EABMenuTargetSelect * +eab_menu_target_new_select(EABMenu *eabp, struct _EBook *book, int readonly, GPtrArray *cards) +{ + EABMenuTargetSelect *t = e_menu_target_new(&eabp->menu, EAB_MENU_TARGET_SELECT, sizeof(*t)); + guint32 mask = ~0; + int has_email = FALSE, i; + + /* FIXME: duplicated in eab-popup.c */ + + t->book = book; + if (book) + g_object_ref(book); + t->cards = cards; + + for (i=0;i<cards->len && !has_email;i++) { + EContact *contact = cards->pdata[i]; + GList *email; + + email = e_contact_get(E_CONTACT(contact), E_CONTACT_EMAIL); + if (email) { + has_email = TRUE; + + g_list_foreach(email, (GFunc)g_free, NULL); + g_list_free(email); + } + } + + if (has_email) + mask &= ~EAB_MENU_SELECT_EMAIL; + + if (!readonly) + mask &= ~EAB_MENU_SELECT_EDITABLE; + + if (cards->len == 1) + mask &= ~EAB_MENU_SELECT_ONE; + + if (cards->len > 1) + mask &= ~EAB_MENU_SELECT_MANY; + + if (cards->len >= 1) + mask &= ~EAB_MENU_SELECT_ANY; + + t->target.mask = mask; + + return t; +} + +static void +eabm_standard_menu_factory(EMenu *emp, void *data) +{ + /* noop */ +} + +/* ********************************************************************** */ + +/* menu plugin handler */ + +/* +<e-plugin + class="com.ximian.mail.plugin.popup:1.0" + id="com.ximian.mail.plugin.popup.item:1.0" + type="shlib" + location="/opt/gnome2/lib/camel/1.0/libcamelimap.so" + name="imap" + description="IMAP4 and IMAP4v1 mail store"> + <hook class="com.ximian.mail.popupMenu:1.0" + handler="HandlePopup"> + <menu id="any" target="select"> + <item + type="item|toggle|radio|image|submenu|bar" + active + path="foo/bar" + label="label" + icon="foo" + mask="select_one" + activate="eabm_view_emacs"/> + </menu> + </extension> + +*/ + +static void *eabmph_parent_class; +#define eabmph ((EABMenuHook *)eph) + +static const EMenuHookTargetMask eabmph_select_masks[] = { + { "one", EAB_MENU_SELECT_ONE }, + { "many", EAB_MENU_SELECT_MANY }, + { "any", EAB_MENU_SELECT_ANY }, + { "editable", EAB_MENU_SELECT_EDITABLE }, + { "email", EAB_MENU_SELECT_EMAIL }, + { 0 } +}; + +static const EMenuHookTargetMap eabmph_targets[] = { + { "select", EAB_MENU_TARGET_SELECT, eabmph_select_masks }, + { 0 } +}; + +static void +eabmph_finalise(GObject *o) +{ + /*EPluginHook *eph = (EPluginHook *)o;*/ + + ((GObjectClass *)eabmph_parent_class)->finalize(o); +} + +static void +eabmph_class_init(EPluginHookClass *klass) +{ + int i; + + ((GObjectClass *)klass)->finalize = eabmph_finalise; + ((EPluginHookClass *)klass)->id = "com.novell.evolution.addressbook.bonobomenu:1.0"; + + for (i=0;eabmph_targets[i].type;i++) + e_menu_hook_class_add_target_map((EMenuHookClass *)klass, &eabmph_targets[i]); + + /* FIXME: leaks parent set class? */ + ((EMenuHookClass *)klass)->menu_class = g_type_class_ref(eab_menu_get_type()); +} + +GType +eab_menu_hook_get_type(void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof(EABMenuHookClass), NULL, NULL, (GClassInitFunc) eabmph_class_init, NULL, NULL, + sizeof(EABMenuHook), 0, (GInstanceInitFunc) NULL, + }; + + eabmph_parent_class = g_type_class_ref(e_menu_hook_get_type()); + type = g_type_register_static(e_menu_hook_get_type(), "EABMenuHook", &info, 0); + } + + return type; +} diff --git a/addressbook/gui/widgets/eab-menu.h b/addressbook/gui/widgets/eab-menu.h new file mode 100644 index 0000000000..0427d43fe1 --- /dev/null +++ b/addressbook/gui/widgets/eab-menu.h @@ -0,0 +1,109 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Authors: Michel Zucchi <notzed@ximian.com> + * + * Copyright 2004 Novell Inc. (www.novell.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 __EAB_MENU_H__ +#define __EAB_MENU_H__ + +#include <glib-object.h> + +#include "e-util/e-menu.h" + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +struct _EBook; + +typedef struct _EABMenu EABMenu; +typedef struct _EABMenuClass EABMenuClass; + +/* Current target description */ +enum _eab_menu_target_t { + EAB_MENU_TARGET_SELECT, +}; + +/** + * enum _eab_menu_target_select_t - EABMenuTargetSelect qualifiers. + * + * @EAB_MENU_SELECT_ONE: Only one item is selected. + * @EAB_MENU_SELECT_MANY: More than one item selected. + * @EAB_MENU_SELECT_ANY: One or more items selected. + * @EAB_MENU_SELECT_EDITABLE: Editable addressbook. + * @EAB_MENU_SELECT_EMAIL: Has an email address. + **/ +enum _eab_menu_target_select_t { + EAB_MENU_SELECT_ONE = 1<<0, + EAB_MENU_SELECT_MANY = 1<<1, + EAB_MENU_SELECT_ANY = 1<<2, + EAB_MENU_SELECT_EDITABLE = 1<<3, + EAB_MENU_SELECT_EMAIL = 1<<4, +}; + +typedef struct _EABMenuTargetSelect EABMenuTargetSelect; + +struct _EABMenuTargetSelect { + EMenuTarget target; + + struct _EBook *book; + GPtrArray *cards; +}; + +typedef struct _EMenuItem EABMenuItem; + +/* The object */ +struct _EABMenu { + EMenu menu; + + struct _EABMenuPrivate *priv; +}; + +struct _EABMenuClass { + EMenuClass menu_class; +}; + +GType eab_menu_get_type(void); + +EABMenu *eab_menu_new(const char *menuid); + +EABMenuTargetSelect *eab_menu_target_new_select(EABMenu *eabp, struct _EBook *book, int readonly, GPtrArray *cards); + +/* ********************************************************************** */ + +typedef struct _EABMenuHook EABMenuHook; +typedef struct _EABMenuHookClass EABMenuHookClass; + +struct _EABMenuHook { + EMenuHook hook; +}; + +struct _EABMenuHookClass { + EMenuHookClass hook_class; +}; + +GType eab_menu_hook_get_type(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __EAB_MENU_H__ */ diff --git a/addressbook/gui/widgets/eab-popup.c b/addressbook/gui/widgets/eab-popup.c index 79e9c2a57a..2a9a7e654b 100644 --- a/addressbook/gui/widgets/eab-popup.c +++ b/addressbook/gui/widgets/eab-popup.c @@ -130,6 +130,8 @@ eab_popup_target_new_select(EABPopup *eabp, struct _EBook *book, int readonly, G guint32 mask = ~0; int has_email = FALSE, i; + /* FIXME: duplicated in eab-menu.c */ + t->book = book; g_object_ref(book); t->cards = cards; @@ -156,9 +158,12 @@ eab_popup_target_new_select(EABPopup *eabp, struct _EBook *book, int readonly, G if (cards->len == 1) mask &= ~EAB_POPUP_SELECT_ONE; - if (cards->len >= 1) + if (cards->len > 1) mask &= ~EAB_POPUP_SELECT_MANY; + if (cards->len >= 1) + mask &= ~EAB_POPUP_SELECT_ANY; + t->target.mask = mask; return t; @@ -199,6 +204,9 @@ eab_popup_target_new_select_names(EABPopup *eabp, struct _ESelectNamesModel *mod { EABPopupTargetSelectNames *t = e_popup_target_new(&eabp->popup, EAB_POPUP_TARGET_SELECT_NAMES, sizeof(*t)); + /* TODO: this is sort of not very useful, maybe the popup which uses it doesn't + need to be pluggable */ + t->model = model; g_object_ref(model); t->row = row; @@ -239,6 +247,9 @@ static void *eabph_parent_class; static const EPopupHookTargetMask eabph_select_masks[] = { { "one", EAB_POPUP_SELECT_ONE }, { "many", EAB_POPUP_SELECT_MANY }, + { "any", EAB_POPUP_SELECT_ANY }, + { "editable", EAB_POPUP_SELECT_EDITABLE }, + { "email", EAB_POPUP_SELECT_EMAIL }, { 0 } }; diff --git a/addressbook/gui/widgets/eab-popup.h b/addressbook/gui/widgets/eab-popup.h index 39df885de5..7fec4cc742 100644 --- a/addressbook/gui/widgets/eab-popup.h +++ b/addressbook/gui/widgets/eab-popup.h @@ -52,15 +52,17 @@ enum _eab_popup_target_t { * enum _eab_popup_target_select_t - EABPopupTargetSelect qualifiers. * * @EAB_POPUP_SELECT_ONE: Only one item is selected. - * @EAB_POPUP_SELECT_MANY: One ore more items are selected. + * @EAB_POPUP_SELECT_MANY: Two or more items are selected. + * @EAB_POPUP_SELECT_ANY: One or more items are selected. * @EAB_POPUP_SELECT_EDITABLE: Read/writable source. * @EAB_POPUP_SELECT_EMAIL: Has an email address. **/ enum _eab_popup_target_select_t { EAB_POPUP_SELECT_ONE = 1<<0, EAB_POPUP_SELECT_MANY = 1<<1, - EAB_POPUP_SELECT_EDITABLE = 1<<2, - EAB_POPUP_SELECT_EMAIL = 1<<3, + EAB_POPUP_SELECT_ANY = 1<<2, + EAB_POPUP_SELECT_EDITABLE = 1<<3, + EAB_POPUP_SELECT_EMAIL = 1<<4, }; /** |