Files
evolution/shell/e-shell-user-creatable-items-handler.c
Ettore Perazzoli 482cf3700a [With this commit, the shell compiles without deprecated
GLib/GTK+ functions, except for a couple of places were we use
GtkCList.]

* Makefile.am (INCLUDES): Add `-DG_DISABLE_DEPRECATED
-DGTK_DISABLE_DEPRECATED'.

* evolution-test-component.c (create_new_folder_selector): No
gtk_window_set_policy().

* main.c (quit_box_new): gtk_window_set_resizable() instead of
gtk_window_set_policy().
(view_map_callback): g_signal_handlers_disconnect_by_func()
instead of gtk_signal_disconnect_by_func().
(main): No need to push the GdkRGB visual/cmap anymore.
(new_view_created_callback): Likewise.

* e-task-widget.c: Renamed member pixmap of ETaskWidgetPrivate to
`image'.
(init): Updated accordingly.
(e_task_widget_construct): Use GtkImage, not GtkPixmap.

* e-storage.c (class_init): Converted from gtk_signal_new() to
g_signal_new().

* e-storage-set.c (class_init): Converted from gtk_signal_new() to
g_signal_new().

* e-storage-set-view.c
(setup_folder_properties_items_if_corba_storage_clicked):
g_string_append_printf() instead of g_string_sprintfa().
(class_init): Converted from gtk_signal_new() to g_signal_new().
(setup_folder_changed_callbacks): Use
e_signal_connect_while_alive() and
e_signal_connect_full_while_alive().

* e-splash.c (e_splash_construct): gtk_window_set_resizable()
instead of gtk_window_set_policy().

* e-shortcuts.c: Do not #include e-unicode.h.
(shortcut_item_update): Use g_path_get_basename() instead of
g_basename().
(e_shortcuts_add_default_shortcuts): No need to de-utfize strings.
(e_shortcuts_add_default_group): Same here.

* e-shortcuts-view.c: Do not #include <e-unicode.h>.
(class_init): Converted from gtk_signal_new() to g_signal_new().
(destroy_group_cb): No need to convert the text from UTF8.

* e-shell.c (impl_dispose): g_signal_handlers_disconnect_by_func()
instead of gtk_signal_disconnect_by_func().
(class_init): Use g_signal_new() instead of gtk_signal_new().

* e-shell-view.c: Do not #include e-unicode.h.  Renamed member
offline_toggle_pixmap to offline_toggle_image in
EShellViewPrivate.
(update_folder_title_bar): No need to de-UTF8-ize the title.
(cleanup_delayed_selection):
g_signal_handlers_disconnect_by_func() instead of
gtk_signal_disconnect_by_func().
(ui_engine_add_hint_callback): gtk_label_set_text(), not
gtk_label_set().
(class_init): Use g_signal_new() instead of gtk_signal_new().
(update_for_current_uri): No need to convert the title from UTF8.
(setup_offline_toggle): Changed to set up a GtkImage, not a
GtkPixmap.
(update_offline_toggle_status): Accordingly (gtk_image* instead of
gtk_pixmap*).
(set_current_notebook_page): gtk_notebook_set_current_page(), not
gtk_notebook_set_page().
(get_storage_set_path_from_uri): g_ascii_strncasecmp() instead of
g_strncasecmp().
(folder_bar_popup_map_callback): Use
e_signal_connect_while_alive() instead of
gtk_signal_connect_while_alive().
(e_shell_view_construct): Likewise.
(display_uri): g_signal_connect_after() instead of
gtk_signal_connect_full().
(update_for_current_uri):
g_signal_handlers_{block,unblock}_by_func() instead of
gtk_signal_handler_{block,unblock}_by_func().

* e-shell-view-menu.c (command_about_box):
gtk_window_set_resizable() instead of gtk_window_set_policy().

* e-shell-utils.c (get_mini_name): g_path_get_basename() instead
of g_basename().

* e-shell-user-creatable-items-handler.c
(append_xml_for_menu_item): g_string_append_printf() instead of
g_string_sprintfa().
(create_menu_xml): Likewise.

* e-shell-shared-folder-picker-dialog.c: Do not #include
e-unicode.h.
(progress_bar_timeout_callback): Expect a GtkProgressBar data and
just use gtk_progress_bar_pulse().
(create_progress_dialog): gtk_window_set_resizable() instead of
gtk_window_set_policy().  No gtk_progress_set_activity_mode().
(setup_server_option_menu): Just use
gtk_menu_item_new_with_label() instead of
e_utf8_gtk_menu_item_new_with_label().

* e-shell-settings-dialog.c (set_dialog_size): Ported to Pango.

* e-shell-offline-sync.c
(impl_SyncFolderProgressListener_updateProgress):
gtk_progress_set_fraction() instead of
gtk_progress_bar_set_percentage().
(sync_folder): Likewise.
(setup_dialog): gtk_window_set_resizable() instead of
gtk_window_set_policy().
(sync_folder): No gtk_progress_set_activity_mode().

* e-shell-offline-handler.c: #undef {G,GTK}_DISABLE_DEPRECATED
here for now (need to port from GtkCList).
(class_init): Use g_signal_new()

* e-shell-importer.c: #undef {G,GTK}_DISABLE_DEPRECATED here for
now (need to port from GtkCList).

* e-shell-folder-title-bar.c (create_image_widget_from_xpm):
Renamed from create_pixmap_widget_from_xpm(); handle GtkImage
instead of GtkPixmap.
(new_empty_image_widget): Renamed from new_empty_pixmap_widget();
return a GtkImage instead of a GtkPixmap.
(add_navigation_buttons): Updated accordingly; so use GtkImages
instead of GtkPixmaps.
(e_shell_folder_title_bar_construct): Likewise.
(e_shell_folder_title_bar_set_icon): Use gtk_image_* instead of
gtk_pixmap_* on the image widgets.
(class_init): Converted to use g_signal_new() instead of
gtk_signal_new().
(e_shell_folder_title_bar_new): No need for pushing the GdkRGB
visual/cmap anymore.

* e-shell-folder-selection-dialog.c (check_folder_type_valid):
Just use strcmp instead of strcasecmp().
(class_init): g_signal_new() instead of gtk_signal_new().
(e_shell_folder_selection_dialog_construct): Removed call to
gtk_window_set_policy().

* e-shell-folder-creation-dialog.c
(type_with_display_name_compare_func): Changed to use
g_utf8_casefold().

* e-shell-folder-commands.c: Do not #include e-unicode.h.
(e_shell_command_rename_folder): g_path_get_dirname() instead of
g_dirname().
(folder_selection_dialog_folder_selected_callback):
g_path_get_basename() instead of g_basename().
(rename_cb): Likewise.
(delete_dialog): Do not convert from UTF8 for display purposes.
(e_shell_command_rename_folder): Likewise.

* e-shell-about-box.c (timeout_callback): Ported to Pango and use
gdk_window_invalidate_rect() instead of gtk_widget_draw().

* e-setup.c (check_evolution_directory): Use
gtk_window_set_resizable() instead of gtk_window_set_policy().

* e-local-storage.c: Do not include e-unicode.h.
(create_folder): Use g_path_get_basename() instead of
g_basename().
(create_folder_directory): Likewise.
(remove_folder_directory): Likewise.
(append_xfer_item_list): Likewise.

* e-local-folder.c (construct_loading_metadata): Use
g_path_get_basename() instead of g_basename().

* e-folder-dnd-bridge.c (handle_evolution_path_drag_motion): Use
g_path_get_basename() instead of g_basename().

* e-corba-storage-registry.c: G_STRUCT_OFFSET instead of
GTK_STRUCT_OFFSET.

* e-corba-shortcuts.c: G_STRUCT_OFFSET instead of
GTK_STRUCT_OFFSET.

* e-component-registry.c
(sleep_with_g_main_loop_timeout_callback): g_main_loop_* instead
of g_main_*.
(sleep_with_g_main_loop): Likewise.

* e-activity-handler.c: G_STRUCT_OFFSET instead of
GTK_STRUCT_OFFSET.

* evolution-wizard.c (evolution_wizard_class_init): g_signal_new()
instead of gtk_signal_new().

* evolution-storage-listener.c (class_init): g_signal_new()
instead of gtk_signal_new().

* evolution-shell-view.c (class_init): g_signal_new() instead of
gtk_signal_new().

* evolution-shell-component-dnd.c: G_STRUCT_OFFSET instead of
GTK_STRUCT_OFFSET.

* evolution-shell-component.c: G_STRUCT_OFFSET instead of
GTK_STRUCT_OFFSET.

* evolution-session.c: G_STRUCT_OFFSET instead of
GTK_STRUCT_OFFSET.

* evolution-folder-selector-button.c: Do not include e-unicode.h.
(set_folder): No need to convert from UTF8 to locale encoding
anymore.  Removed unused variable.

* evolution-config-control.c (class_init): Use g_signal_new()
instead of gtk_signal_new().

* evolution-activity-client.c (class_init): Use g_signal_new()
instead of gtk_signal_new().

* e-folder-list.c: Do not include e-unicode.h.  Use E_MAKE_TYPE().
(e_folder_list_get_type): Removed explicit implementation of this.
(e_folder_list_set_arg): Removed.
(e_folder_list_get_arg): Removed.
(e_folder_list_set_property): New.
(e_folder_list_get_property): New.
(e_folder_list_destroy): Removed.
(e_folder_list_dispose): New.
(e_folder_list_class_init): Updated accordingly.

* e-folder.c (impl_save_info): Use G_OBJECT_TYPE_NAME() instead of
gtk_type_name().
(impl_load_info): Likewise.
(impl_remove): Likewise.
(class_init): Use g_signal_new() instead of gtk_signal_new().

svn path=/trunk/; revision=19170
2002-12-19 22:03:40 +00:00

793 lines
21 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 G_TYPE_OBJECT
static GObjectClass *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;
g_object_ref (client);
CORBA_exception_init (&ev);
objref = evolution_shell_component_client_corba_objref (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)
{
g_object_unref (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)
g_object_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_append_printf (xml, "<menuitem name=\"New:%s\" verb=\"%s\" label=\"%s\"",
item->verb, item->verb, encoded_label);
if (first)
g_string_append_printf (xml, " accel=\"*Control*N\"");
else if (item->shortcut != '\0')
g_string_append_printf (xml, " accel=\"*Control**Shift*%c\"", item->shortcut);
if (item->icon != NULL)
g_string_append_printf (xml, " pixtype=\"pixbuf\" pixname=\"%s\"",
bonobo_ui_util_pixbuf_to_xml (item->icon));
encoded_tooltip = bonobo_ui_util_encode_str (item->tooltip);
g_string_append_printf (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_append_printf (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
(evolution_shell_component_client_corba_objref (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 = g_object_get_data (G_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);
g_object_set_data (G_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);
g_signal_connect (combo_button, "activate_default",
G_CALLBACK (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);
g_object_set_data (G_OBJECT (shell_view), COMBO_BUTTON_WIDGET_KEY, combo_button);
tooltips = gtk_tooltips_new ();
g_object_set_data (G_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 = g_object_get_data (G_OBJECT (shell_view), COMBO_BUTTON_WIDGET_KEY);
g_assert (E_IS_COMBO_BUTTON (combo_button_widget));
tooltips = g_object_get_data (G_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);
}
/* GObject methods. */
static void
impl_dispose (GObject *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);
priv->components = NULL;
(* G_OBJECT_CLASS (parent_class)->dispose) (object);
}
static void
impl_finalize (GObject *object)
{
EShellUserCreatableItemsHandler *handler;
EShellUserCreatableItemsHandlerPrivate *priv;
handler = E_SHELL_USER_CREATABLE_ITEMS_HANDLER (object);
priv = handler->priv;
free_menu_items (priv->menu_items);
g_free (priv);
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}
static void
class_init (GObjectClass *object_class)
{
parent_class = g_type_class_ref(PARENT_TYPE);
object_class->dispose = impl_dispose;
object_class->finalize = impl_finalize;
}
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 = g_object_new (e_shell_user_creatable_items_handler_get_type (), NULL);
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);
g_signal_connect (shell_view, "view_changed",
G_CALLBACK (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)