Files
evolution/shell/e-shell-user-creatable-items-handler.c
Ettore Perazzoli 8691f8584f Renamed from GNOME_Evolution_Shell.oaf.in.
* GNOME_Evolution_Shell.server.in: Renamed from
GNOME_Evolution_Shell.oaf.in.

* Makefile.am: Port from OAF to bonobo-activation.
(INCLUDES): Define SYSCONFDIR, DATADIR, LIBDIR.

* main.c (main): Use gnome_program_init().

* e-corba-storage-registry.c (e_corba_storage_registry_new):
g_object_new(), not gtk_type_new().
(impl_finalize): New, ported over from destroy.
(destroy): Removed.
(class_init): Install finalize handler, not destroy handler, since
we are not a GtkObject anymore.

* e-corba-storage.c (e_corba_storage_new): g_object_new(), not
gtk_type_new().

* e-shell.c (class_init): Override finalize, not destroy.
(impl_finalize): Finalize implementation, basically the old
destroy renamed.
(e_shell_new): g_object_new(), not gtk_type_new().
(class_init): Use e_shell_marshal_NONE__INT for
line_status_changed instead of using an ENUM.
(e_shell_construct): Use g_signal_connect_object() instead of
gtk_signal_connect_while_alive().

* e-setup.c (e_setup): Do not unref local_folder if NULL.

* e-folder.c (init): Make not floating.
(e_folder_construct): No need to make it floating here anymore.

* e-shell.c (impl_Shell_selectUserFolder): For now don't set
dialog parent from xid.

* main.c (no_views_left_cb): Add missing GTK_SIGNAL_FUNC() cast.
(new_view_created_callback): Likewise.
(warning_dialog_clicked_callback): Update to use the
EConfigListener from the shell instead of bonobo-conf.
(show_development_warning): Likewise.
(upgrade_from_1_0_if_needed): BONOBO_EX_ID -> BONOBO_EX_REPOID.
(idle_cb): Use bonobo-activation and BONOBO_EX_REPOID().
(main): Cleaned up the various things that are unneeded in GNOME
2.
(upgrade_from_1_0_if_needed): Use EConfigListener.

* evolution-storage-set-view.h, evolution-storage-set-view.c:
BonoboXObjectified.

* e-storage.c (class_init): GLIB2-ified and made to use
e-shell-marshal.h.
(ES_CLASS): Use GTK_OBJECT_GET_CLASS().
(e_storage_new_folder): Added missing GTK_SIGNAL_FUNC() prototype.

* e-storage-set.c (class_init): GLIB2-ified and made to use
e-shell-marshal.h.

* e-storage-set-view.c (popup_folder_menu): For now, do not add
the pop-up since we lack bonobo_ui_container_get_win() and I am
not sure how to work around it.
(popup_folder_menu): Pass self as the for_widget arg to
gnome_popup_menu_do_popup_modal().
(class_init): GLIB2-ified, and got to use e-shell-marshal.h.
(marshal_NONE__GDKDRAGCONTEXT_STRING_STRING_STRING): Removed.
(impl_tree_drag_data_get): Don't set the selection for now -- we
have to fix the CORBA target stuff to match GTK 2.
(e_storage_set_view_construct): Pass NULL as the opt_ev arg to
bonobo_ui_component_set_container().

* e-splash.c: #include <libgnomecanvas/gnome-canvas-pixbuf.h>
instead of <gdk-pixbuf/gnome-canvas-pixbuf.h>.
(e_splash_new): Pass NULL as the error arg to
gdk_pixbuf_new_from_file().

* e-shortcuts.c (class_init): GLIB2-ified.  Also use the
e-shell-marshal marshallers.
(e_shortcuts_new_view): Add missing GTK_SIGNAL_FUNC() cast.

* e-shortcuts-view.c: Use GTK_STOCK_* stuff instead of
GNOME_STOCK_* stuff.
(pop_up_right_click_menu_for_group): Pass self as the for_widget
arg to gnome_popup_menu_do_popup_modal().
(pop_up_right_click_menu_for_shortcut): Likewise.
(class_init): GLIB2-ified.

* e-shell.c: Do not #include <gal/util/e-unicode-i18n.h> or
#include <libgnome/gnome-defs.h>.
(set_interactive): Use BONOBO_EX_REPOID().
(setup_local_storage): Use _() not U_().
(destroy): Use gtk_widget_destroy() instead of
gtk_object_destroy() on priv->settings_dialog.
(class_init): GLIB2-ized.
(init): Initialize config_listener member.
(get_icon_path_for_component_info): Port to bonobo-activation from
OAF.
(setup_components): Likewise.
(destroy): Likewise.
(e_shell_construct): Use e_setup_check_config(), not
e_setup_check_db ().  Use the e_config_listener instead of
bonobo-conf.
(save_settings_for_views): Likewise.
(save_misc_settings): Likewise.
(e_shell_restore_from_settings): Likewise.
(parse_default_uri): Likewise.
(e_shell_component_maybe_crashed): Pass NULL for opt_ev arg to
bonobo_unkown_ping()
(e_shell_component_maybe_crashed): Use
bonobo_engine_deregister_dead_components() instead of
bonobo_window_deregister_component_by_ref() which is no more.
(e_shell_send_receive): BONOBO_EX_REPOID() instead of
BONOBO_EX_ID().
(e_shell_get_config_listener): Return the config_listener.

* e-shell-view.c (find_inbox_in_storage): Use _() instead of U_().
(load_images): Pass NULL as the error arg to
gdk_pixbuf_new_from_file().
(load_images): Likewise.
(find_inbox_in_storage): Work around the lack of
g_utf8_strcasecmp() in glib-2.0.
(class_init): GLIB2-ified.  Also, use the marshallers in
e-shell-marshal.h.
(pop_up_folder_bar): Use gtk_window_move()/gtk_widget_show()
instead gtk_widget_popup().
(unmerge_on_error): Work around the death of
bonobo_ui_component_get_win() and
bonobo_window_deregister_component_by_ref().
(e_shell_view_construct): Pass NULL as the uic arg to
bonobo_window_construct().  Add missing GTK_SIGNAL_FUNC() cast.
Match the new BonoboWindow behavior wrt the UIContainer and the
new opt_ev args.
(display_uri): Use bonobo_ui_engine_freeze() and
bonobo_ui_engine_thaw() since bonobo_window_freeze() and
bonobo_window_thaw() got axed [sigh].
(e_shell_view_save_settings): Use EConfigListener.
(e_shell_view_load_settings): Likewise.
(get_view_for_uri): Use bonobo_widget_new_control_from_objref()
instead of e_bonobo_widget_new_control_from_objref().

* e-shell-view-menu.c (command_help_faq): Pass NULL for the error
arg to gnome_url_show().
(command_about_box): Use GtkDialog instead of a GtkWindow of a
type GTK_WINDOW_DIALOG [which does not exist anymore].
(command_xml_dump): Removed.
(menu_do_misc): Do not add the corresponding verb.

* e-shell-user-creatable-items-handler.c (execute_verb): Use
BONOBO_EX_REPOID().

* e-shell-startup-wizard.c: Remove id member from SWData.  Replace
member db with config_listener.
(e_shell_startup_wizard_create): Initialize config_listener.
(make_mail_dialog_pages): Do not set the listener id here.
(druid_event_notify_cb): Pass FALSE as the help_sensitive arg to
gnome_druid_set_buttons_sensitive().
(e_shell_startup_wizard_create): Likewise.
(make_mail_dialog_pages): Use bonobo-activation instead of OAF.
(get_intelligent_importers): Likewise.
(prepare_importer_page): Likewise.
(start_importers): Do nothing here for now.
(finish_func): Constify local variable displayname.
(finish_func): Updated to use the config_listener instead of the
bono-conf db.
(prepare_importer_page): Do not actually run the importer yet.
(e_shell_startup_wizard_create): Pass NULL as the domain arg to
glade_xml_new().  Use the config_listener.

* e-shell-shared-folder-picker-dialog.c (user_clicked):
BONOBO_EX_REPOID() instead of BONOBO_EX_ID().
(setup_name_selector): Likewise.
(setup_name_selector): Use bonobo-activation.
(show_dialog): Pass NULL as the domain arg to glade_xml_new().
(setup_name_selector): Add a missing GTK_SIGNAL_FUNC() cast.

* e-shell-settings-dialog.c: #include
<bonobo-activation/bonobo-activation.h>.  Use
Bonobo_ActivationProperty instead of OAF_Property.
(set_dialog_size): Use gtk_style_get_font() to get the font from
the widget->style.
(load_pages): Converted to use bonobo-activation instead of OAF.
Pass NULL as the error arg to gdk_pixbuf_new_from_file().

* e-shell-offline-sync.c (sync_folder): BONOBO_EX_REPOID(), not
BONOBO_EX_ID().
(e_shell_offline_sync_all_folders): For now, avoid doing anything
[see changes to e-shell-config-offline.c below].
(setup_progress_listener): #if 0 for now.
(setup_dialog): Likewise.
(sync_folder): Likewise.
(cleanup): Likewise.
(progress_listener_servant_free): Likewise.
(progress_listener_servant_new): Likewise.
(impl_SyncFolderProgressListener_updateProgress): Likewise.
(impl_SyncFolderProgressListener_reportSuccess): Likewise.
(impl_SyncFolderProgressListener_reportFailure): Likewise.
(progress_dialog_close_callback): Likewise.
(progress_dialog_clicked_callback): Likewise.

* e-shell-offline-handler.c (prepare_for_offline): Use
BONOBO_EX_REPOID().
(pop_up_confirmation_dialog): Pass NULL as the domain arg to
glade_xml_new().
(class_init): GLIB2-ified.

* Makefile.am: Do not compile e-shell-importer.c,
e-shell-importer.h for now.

* e-shell-folder-title-bar.c (get_max_clipped_label_width): Use
gtk_style_get_font() to retrieve the font.
(class_init): GLIB2-ified.
(e_shell_folder_title_bar_construct): Get {x,y}thickness from
widget->style, not from widget->style->klass.

* e-shell-folder-selection-dialog.c: #include <string.h>,
<gtk/gtklabel.h> and <gtk/gtksignal.h>.
(class_init): GLIB2-ified.

* e-shell-folder-creation-dialog.c: No <libgnome/gnome-defs.h>,
add some GTK includes.
(e_shell_show_folder_creation_dialog): Pass NULL as the domain arg
to glade_xml_new().  Added missing GTK_SIGNAL_FUNC() cast.

* e-shell-folder-commands.c: Do not #include
<libgnomeui/gnome-stock.h> and #include
<bonobo-conf/Bonobo_Config.h>.

* e-shell-config-default-folders.c: Replace member db in
EvolutionDefaultFolderConfig with config_listener.
(e_shell_config_default_folders_create_widget): Init here.
(config_control_destroy_cb): Unref here.
(config_control_apply_cb): Use EConfigListener instead of
BonoboConf.
(setup_folder_selector): Likewise.
(e_shell_config_default_folders_create_widget): Pass NULL as the
domain arg to glade_xml_new().

* e-shell-config-offline.c (config_control_apply_callback): For
now, do not change the configuration.  [Needs to be ported to
EConfigListener or something, but we were storing a sequence using
typecodes here and there is no trivial way to do that right now.]
(init_storage_set_view_status_from_config): Likewise, do not
retrieve the configuration here.

svn path=/trunk/; revision=18510
2002-11-03 16:43:18 +00:00

778 lines
20 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-shell-user-creatable-items-handler.c
*
* Copyright (C) 2001 Ximian, Inc.
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Ettore Perazzoli <ettore@ximian.com>
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "e-shell-user-creatable-items-handler.h"
#include "e-shell-corba-icon-utils.h"
#include "widgets/misc/e-combo-button.h"
#include "e-util/e-corba-utils.h"
#include <gal/util/e-util.h>
#include <bonobo/bonobo-ui-util.h>
#include <bonobo/bonobo-exception.h>
#include <libgnome/gnome-i18n.h>
#include <gtk/gtksignal.h>
#include <gtk/gtktooltips.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define PARENT_TYPE gtk_object_get_type ()
static GtkObjectClass *parent_class = NULL;
#define VERB_PREFIX "ShellUserCreatableItemVerb"
#define EVOLUTION_MAIL_OAFIID "OAFIID:GNOME_Evolution_Mail_ShellComponent"
#define SHELL_VIEW_KEY "EShellUserCreatableItemsHandler:shell_view"
#define COMBO_BUTTON_WIDGET_KEY "EShellUserCreatableItemsHandler:combo_button"
#define TOOLTIPS_KEY "EShellUserCreatableItemsHandler:tooltips"
struct _Component {
EvolutionShellComponentClient *component_client;
GNOME_Evolution_UserCreatableItemTypeList *type_list;
};
typedef struct _Component Component;
/* Representation of a single menu item. */
struct _MenuItem {
const char *label;
char shortcut;
char *verb;
char *tooltip;
GdkPixbuf *icon;
char *component_id;
char *folder_type;
};
typedef struct _MenuItem MenuItem;
struct _EShellUserCreatableItemsHandlerPrivate {
/* The components that register user creatable items. */
GSList *components; /* Component */
/* The "New ..." menu items. */
GSList *menu_items; /* MenuItem */
/* The default item (the mailer's "message" item). To be used when the
component in the view we are in doesn't provide a default user
creatable type. This pointer always points to one of the menu items
in ->menu_items. */
const MenuItem *default_menu_item;
};
/* Component struct handling. */
static Component *
component_new (const char *id,
EvolutionShellComponentClient *client)
{
CORBA_Environment ev;
Component *new;
GNOME_Evolution_ShellComponent objref;
new = g_new (Component, 1);
new->component_client = client;
gtk_object_ref (GTK_OBJECT (client));
CORBA_exception_init (&ev);
objref = bonobo_object_corba_objref (BONOBO_OBJECT (client));
new->type_list = GNOME_Evolution_ShellComponent__get_userCreatableItemTypes (objref, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
new->type_list = NULL;
CORBA_exception_free (&ev);
return new;
}
static void
component_free (Component *component)
{
gtk_object_unref (GTK_OBJECT (component->component_client));
if (component->type_list != NULL)
CORBA_free (component->type_list);
g_free (component);
}
/* Helper functions. */
static gboolean
item_is_default (const MenuItem *item,
const char *folder_type,
const char *component_id)
{
if (component_id == NULL || folder_type == NULL)
return FALSE;
if (item->folder_type != NULL && *item->folder_type != 0) {
if (strcmp (item->folder_type, folder_type) == 0)
return TRUE;
else
return FALSE;
}
if (strcmp (item->component_id, component_id) == 0)
return TRUE;
else
return FALSE;
}
static char *
create_verb_from_component_number_and_type_id (int component_num,
const char *type_id)
{
return g_strdup_printf (VERB_PREFIX ":%d:%s", component_num, type_id);
}
/* Setting up menu items for the "File -> New" submenu and the "New" toolbar
button. */
static void
ensure_menu_items (EShellUserCreatableItemsHandler *handler)
{
EShellUserCreatableItemsHandlerPrivate *priv;
GSList *menu_items;
GSList *p;
int component_num;
const char *default_verb;
priv = handler->priv;
if (priv->menu_items != NULL)
return;
menu_items = NULL;
component_num = 0;
default_verb = NULL;
for (p = priv->components; p != NULL; p = p->next) {
const Component *component;
int i;
component = (const Component *) p->data;
if (component->type_list != NULL) {
for (i = 0; i < component->type_list->_length; i ++) {
const GNOME_Evolution_UserCreatableItemType *type;
MenuItem *item;
type = (const GNOME_Evolution_UserCreatableItemType *) component->type_list->_buffer + i;
item = g_new (MenuItem, 1);
item->label = type->menuDescription;
item->shortcut = type->menuShortcut;
item->verb = create_verb_from_component_number_and_type_id (component_num, type->id);
item->tooltip = type->tooltip;
item->component_id = g_strdup (evolution_shell_component_client_get_id (component->component_client));
item->folder_type = g_strdup (type->folderType);
if (strcmp (item->component_id, EVOLUTION_MAIL_OAFIID) == 0
&& strcmp (type->id, "message") == 0)
default_verb = item->verb;
if (type->icon.width == 0 || type->icon.height == 0)
item->icon = NULL;
else
item->icon = e_new_gdk_pixbuf_from_corba_icon (& type->icon, 16, 16);
menu_items = g_slist_prepend (menu_items, item);
}
}
component_num ++;
}
priv->menu_items = menu_items;
priv->default_menu_item = NULL;
if (default_verb != NULL) {
for (p = priv->menu_items; p != NULL; p = p->next) {
const MenuItem *item;
item = (const MenuItem *) p->data;
if (strcmp (item->verb, default_verb) == 0)
priv->default_menu_item = item;
}
}
}
static void
free_menu_items (GSList *menu_items)
{
GSList *p;
if (menu_items == NULL)
return;
for (p = menu_items; p != NULL; p = p->next) {
MenuItem *item;
item = (MenuItem *) p->data;
g_free (item->verb);
if (item->icon != NULL)
gdk_pixbuf_unref (item->icon);
g_free (item->component_id);
g_free (item);
}
g_slist_free (menu_items);
}
static const MenuItem *
get_default_action_for_view (EShellUserCreatableItemsHandler *handler,
EShellView *shell_view)
{
EShellUserCreatableItemsHandlerPrivate *priv;
const char *view_component_id;
const GSList *p;
priv = handler->priv;
view_component_id = e_shell_view_get_current_component_id (shell_view);
if (view_component_id == NULL)
return NULL;
for (p = priv->menu_items; p != NULL; p = p->next) {
const MenuItem *item;
item = (const MenuItem *) p->data;
if (item_is_default (item,
e_shell_view_get_current_folder_type (shell_view),
e_shell_view_get_current_component_id (shell_view)))
return item;
}
return priv->default_menu_item;
}
/* The XML description for "File -> New". */
/* This adds a menu item for @item. If @first is true, the keyboard shortcut
is going to be "Control-N" instead of whatever the component defines. */
static void
append_xml_for_menu_item (GString *xml,
const MenuItem *item,
gboolean first)
{
char *encoded_label;
char *encoded_tooltip;
encoded_label = bonobo_ui_util_encode_str (item->label);
g_string_sprintfa (xml, "<menuitem name=\"New:%s\" verb=\"%s\" label=\"%s\"",
item->verb, item->verb, encoded_label);
if (first)
g_string_sprintfa (xml, " accel=\"*Control*N\"");
else if (item->shortcut != '\0')
g_string_sprintfa (xml, " accel=\"*Control**Shift*%c\"", item->shortcut);
if (item->icon != NULL)
g_string_sprintfa (xml, " pixtype=\"pixbuf\" pixname=\"%s\"",
bonobo_ui_util_pixbuf_to_xml (item->icon));
encoded_tooltip = bonobo_ui_util_encode_str (item->tooltip);
g_string_sprintfa (xml, " tip=\"%s\"", encoded_tooltip);
g_string_append (xml, "/> ");
g_free (encoded_label);
g_free (encoded_tooltip);
}
static int
item_types_sort_func (const void *a,
const void *b)
{
const MenuItem *item_a;
const MenuItem *item_b;
const char *p1, *p2;
item_a = (const MenuItem *) a;
item_b = (const MenuItem *) b;
p1 = item_a->label;
p2 = item_b->label;
while (*p1 != '\0' && *p2 != '\0') {
if (*p1 == '_') {
p1 ++;
continue;
}
if (*p2 == '_') {
p2 ++;
continue;
}
if (toupper ((int) *p1) < toupper ((int) *p2))
return -1;
else if (toupper ((int) *p1) > toupper ((int) *p2))
return +1;
p1 ++, p2 ++;
}
if (*p1 == '\0') {
if (*p2 == '\0')
return 0;
else
return -1;
} else {
return +1;
}
}
static char *
create_menu_xml (EShellUserCreatableItemsHandler *handler,
const char *folder_type,
const char *component_id)
{
EShellUserCreatableItemsHandlerPrivate *priv;
GString *xml;
GSList *p;
GSList *non_default_items;
char *retval;
priv = handler->priv;
ensure_menu_items (handler);
xml = g_string_new ("");
g_string_append (xml, "<placeholder name=\"ComponentItems\">");
g_string_append (xml, "<placeholder name=\"EShellUserCreatableItemsPlaceholder\">");
/* 1. Add all the elements that are default for this component. (Note
that we don't need to do any sorting since the items are already
sorted alphabetically.) */
if (component_id != NULL) {
gboolean first = TRUE;
for (p = priv->menu_items; p != NULL; p = p->next) {
const MenuItem *item;
item = (const MenuItem *) p->data;
if (item_is_default (item, folder_type, component_id)) {
append_xml_for_menu_item (xml, item, first);
first = FALSE;
}
}
}
/* 2. Add a separator. */
if (component_id != NULL)
g_string_sprintfa (xml, "<separator f=\"\" name=\"EShellUserCreatableItemsHandlerSeparator\"/>");
/* 3. Add the elements that are not default for this component. */
non_default_items = NULL;
for (p = priv->menu_items; p != NULL; p = p->next) {
const MenuItem *item;
item = (const MenuItem *) p->data;
if (! item_is_default (item, folder_type, component_id))
non_default_items = g_slist_prepend (non_default_items, (void *) item);
}
non_default_items = g_slist_sort (non_default_items, item_types_sort_func);
for (p = non_default_items; p != NULL; p = p->next)
append_xml_for_menu_item (xml, (const MenuItem *) p->data, FALSE);
g_slist_free (non_default_items);
/* Done... */
g_string_append (xml, "</placeholder>"); /* EShellUserCreatableItemsPlaceholder */
g_string_append (xml, "</placeholder>"); /* ComponentItems */
retval = xml->str;
g_string_free (xml, FALSE);
return retval;
}
/* Verb handling. */
static void
execute_verb (EShellUserCreatableItemsHandler *handler,
EShellView *shell_view,
const char *verb_name)
{
EShellUserCreatableItemsHandlerPrivate *priv;
const Component *component;
int component_number;
const char *p;
const char *id;
GSList *component_list_item;
int i;
priv = handler->priv;
p = strchr (verb_name, ':');
g_assert (p != NULL);
component_number = atoi (p + 1);
p = strchr (p + 1, ':');
g_assert (p != NULL);
id = p + 1;
component_list_item = g_slist_nth (priv->components, component_number);
g_assert (component_list_item != NULL);
component = (const Component *) component_list_item->data;
if (component->type_list == NULL)
return;
for (i = 0; i < component->type_list->_length; i ++) {
if (strcmp (component->type_list->_buffer[i].id, id) == 0) {
CORBA_Environment ev;
CORBA_exception_init (&ev);
GNOME_Evolution_ShellComponent_userCreateNewItem
(bonobo_object_corba_objref (BONOBO_OBJECT (component->component_client)),
id,
e_safe_corba_string (e_shell_view_get_current_physical_uri (shell_view)),
e_safe_corba_string (e_shell_view_get_current_folder_type (shell_view)),
&ev);
if (ev._major != CORBA_NO_EXCEPTION)
g_warning ("Error in userCreateNewItem -- %s", BONOBO_EX_REPOID (&ev));
CORBA_exception_free (&ev);
return;
}
}
}
static void
verb_fn (BonoboUIComponent *ui_component,
void *data,
const char *verb_name)
{
EShellUserCreatableItemsHandler *handler;
EShellView *shell_view;
shell_view = gtk_object_get_data (GTK_OBJECT (ui_component), SHELL_VIEW_KEY);
g_assert (E_IS_SHELL_VIEW (shell_view));
handler = E_SHELL_USER_CREATABLE_ITEMS_HANDLER (data);
execute_verb (handler, shell_view, verb_name);
}
static void
add_verbs (EShellUserCreatableItemsHandler *handler,
EShellView *shell_view)
{
EShellUserCreatableItemsHandlerPrivate *priv;
BonoboUIComponent *ui_component;
int component_num;
GSList *p;
priv = handler->priv;
ui_component = e_shell_view_get_bonobo_ui_component (shell_view);
gtk_object_set_data (GTK_OBJECT (ui_component), SHELL_VIEW_KEY, shell_view);
component_num = 0;
for (p = priv->components; p != NULL; p = p->next) {
const Component *component;
int i;
component = (const Component *) p->data;
if (component->type_list != NULL) {
for (i = 0; i < component->type_list->_length; i ++) {
char *verb_name;
verb_name = create_verb_from_component_number_and_type_id
(component_num, component->type_list->_buffer[i].id);
bonobo_ui_component_add_verb (ui_component, verb_name, verb_fn, handler);
g_free (verb_name);
}
}
component_num ++;
}
}
/* The "New" button in the toolbar. */
static void
combo_button_activate_default_callback (EComboButton *combo_button,
void *data)
{
EShellView *shell_view;
EShellUserCreatableItemsHandler *handler;
const MenuItem *menu_item;
shell_view = E_SHELL_VIEW (data);
handler = e_shell_get_user_creatable_items_handler (e_shell_view_get_shell (shell_view));
menu_item = get_default_action_for_view (handler, shell_view);
execute_verb (handler, shell_view, menu_item->verb);
}
static void
setup_toolbar_button (EShellUserCreatableItemsHandler *handler,
EShellView *shell_view)
{
EShellUserCreatableItemsHandlerPrivate *priv;
BonoboUIComponent *ui_component;
GtkWidget *combo_button;
GtkWidget *menu;
GtkTooltips *tooltips;
BonoboControl *control;
priv = handler->priv;
menu = gtk_menu_new ();
combo_button = e_combo_button_new ();
e_combo_button_set_menu (E_COMBO_BUTTON (combo_button), GTK_MENU (menu));
e_combo_button_set_label (E_COMBO_BUTTON (combo_button), _("New"));
gtk_widget_show (combo_button);
gtk_signal_connect (GTK_OBJECT (combo_button), "activate_default",
GTK_SIGNAL_FUNC (combo_button_activate_default_callback),
shell_view);
ui_component = e_shell_view_get_bonobo_ui_component (shell_view);
bonobo_window_add_popup (BONOBO_WINDOW (shell_view), GTK_MENU (menu), "/popups/NewPopup");
control = bonobo_control_new (combo_button);
bonobo_ui_component_object_set (ui_component, "/Toolbar/NewComboButton",
BONOBO_OBJREF (control), NULL);
gtk_object_set_data (GTK_OBJECT (shell_view), COMBO_BUTTON_WIDGET_KEY, combo_button);
tooltips = gtk_tooltips_new ();
gtk_object_set_data (GTK_OBJECT (combo_button), TOOLTIPS_KEY, tooltips);
}
/* This handles the menus for a given EShellView. We have to rebuild the menu
and set the toolbar button every time the view changes, and clean up when
the view is destroyed. */
static void
shell_view_view_changed_callback (EShellView *shell_view,
const char *evolution_path,
const char *physical_uri,
const char *folder_type,
const char *component_id,
void *data)
{
EShellUserCreatableItemsHandler *handler;
EShellUserCreatableItemsHandlerPrivate *priv;
GtkWidget *combo_button_widget;
GtkTooltips *tooltips;
BonoboUIComponent *ui_component;
const MenuItem *default_menu_item;
char *menu_xml;
handler = E_SHELL_USER_CREATABLE_ITEMS_HANDLER (data);
priv = handler->priv;
combo_button_widget = gtk_object_get_data (GTK_OBJECT (shell_view), COMBO_BUTTON_WIDGET_KEY);
g_assert (E_IS_COMBO_BUTTON (combo_button_widget));
tooltips = gtk_object_get_data (GTK_OBJECT (combo_button_widget), TOOLTIPS_KEY);
g_assert (tooltips != NULL);
default_menu_item = get_default_action_for_view (handler, shell_view);
if (default_menu_item == NULL) {
gtk_widget_set_sensitive (combo_button_widget, FALSE);
e_combo_button_set_label (E_COMBO_BUTTON (combo_button_widget), _("New"));
e_combo_button_set_icon (E_COMBO_BUTTON (combo_button_widget), NULL);
gtk_tooltips_set_tip (tooltips, combo_button_widget, NULL, NULL);
return;
}
gtk_widget_set_sensitive (combo_button_widget, TRUE);
e_combo_button_set_icon (E_COMBO_BUTTON (combo_button_widget), default_menu_item->icon);
gtk_tooltips_set_tip (tooltips, combo_button_widget, default_menu_item->tooltip, NULL);
ui_component = e_shell_view_get_bonobo_ui_component (shell_view);
bonobo_ui_component_rm (ui_component, "/menu/File/New/ComponentItems/EShellUserCreatableItemsPlaceholder", NULL);
bonobo_ui_component_rm (ui_component, "/popups/NewPopup/ComponentItems/EShellUserCreatableItemsPlaceholder", NULL);
menu_xml = create_menu_xml (handler,
e_shell_view_get_current_folder_type (shell_view),
e_shell_view_get_current_component_id (shell_view));
bonobo_ui_component_set (ui_component, "/menu/File/New", menu_xml, NULL);
bonobo_ui_component_set (ui_component, "/popups/NewPopup", menu_xml, NULL);
g_free (menu_xml);
}
/* GtkObject methods. */
static void
impl_destroy (GtkObject *object)
{
EShellUserCreatableItemsHandler *handler;
EShellUserCreatableItemsHandlerPrivate *priv;
GSList *p;
handler = E_SHELL_USER_CREATABLE_ITEMS_HANDLER (object);
priv = handler->priv;
for (p = priv->components; p != NULL; p = p->next)
component_free ((Component *) p->data);
g_slist_free (priv->components);
free_menu_items (priv->menu_items);
g_free (priv);
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
static void
class_init (GtkObjectClass *object_class)
{
parent_class = gtk_type_class (PARENT_TYPE);
object_class->destroy = impl_destroy;
}
static void
init (EShellUserCreatableItemsHandler *shell_user_creatable_items_handler)
{
EShellUserCreatableItemsHandlerPrivate *priv;
priv = g_new (EShellUserCreatableItemsHandlerPrivate, 1);
priv->components = NULL;
priv->menu_items = NULL;
priv->default_menu_item = NULL;
shell_user_creatable_items_handler->priv = priv;
}
EShellUserCreatableItemsHandler *
e_shell_user_creatable_items_handler_new (void)
{
EShellUserCreatableItemsHandler *new;
new = gtk_type_new (e_shell_user_creatable_items_handler_get_type ());
return new;
}
void
e_shell_user_creatable_items_handler_add_component (EShellUserCreatableItemsHandler *handler,
const char *id,
EvolutionShellComponentClient *shell_component_client)
{
EShellUserCreatableItemsHandlerPrivate *priv;
g_return_if_fail (handler != NULL);
g_return_if_fail (E_IS_SHELL_USER_CREATABLE_ITEMS_HANDLER (handler));
g_return_if_fail (shell_component_client != NULL);
g_return_if_fail (EVOLUTION_IS_SHELL_COMPONENT_CLIENT (shell_component_client));
priv = handler->priv;
priv->components = g_slist_prepend (priv->components, component_new (id, shell_component_client));
}
/**
* e_shell_user_creatable_items_handler_attach_menus:
* @handler:
* @shell_view:
*
* Set up the menus and toolbar items for @shell_view. When the shell changes
* view, the menu and the toolbar item will update automatically (i.e. the
* actions for the current folder will go on top etc.).
**/
void
e_shell_user_creatable_items_handler_attach_menus (EShellUserCreatableItemsHandler *handler,
EShellView *shell_view)
{
BonoboUIComponent *ui_component;
EShellUserCreatableItemsHandlerPrivate *priv;
char *menu_xml;
g_return_if_fail (handler != NULL);
g_return_if_fail (E_IS_SHELL_USER_CREATABLE_ITEMS_HANDLER (handler));
g_return_if_fail (shell_view != NULL);
g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
priv = handler->priv;
setup_toolbar_button (handler, shell_view);
gtk_signal_connect (GTK_OBJECT (shell_view), "view_changed",
GTK_SIGNAL_FUNC (shell_view_view_changed_callback), handler);
add_verbs (handler, shell_view);
menu_xml = create_menu_xml (handler,
e_shell_view_get_current_component_id (shell_view),
e_shell_view_get_current_folder_type (shell_view));
ui_component = e_shell_view_get_bonobo_ui_component (shell_view);
bonobo_ui_component_set (ui_component, "/menu/File/New", menu_xml, NULL);
bonobo_ui_component_set (ui_component, "/popups/NewPopup", menu_xml, NULL);
g_free (menu_xml);
}
E_MAKE_TYPE (e_shell_user_creatable_items_handler,
"EShellUserCreatableItemsHandler", EShellUserCreatableItemsHandler,
class_init, init, PARENT_TYPE)