
done but it needs pretty icons so I am leaving it disabled for now.] * e-combo-button.c: Remove member `separator' from `EComboButtonPrivate'. New members `icon', `label'. (init): There shall be no separator no more. Init `icon' and `label' to %NULL. (e_combo_button_construct): Set no relief. (e_combo_button_new): Don't get a @menu arg anymore. (e_combo_button_construct): Likewise. (e_combo_button_set_icon): New. (e_combo_button_set_label): New. (e_combo_button_set_menu): New. (impl_clicked): New, overriding the "clicked" method for GtkButton. (class_init): Install. (impl_button_release_event): Removed. (class_init): No need to override ::release_event with this anymore. (impl_released): New, override for the GtkButton::released method. (class_init): Install. * e-shell-user-creatable-items-handler.c: New member `id' in struct `Component'. New member `icon' in struct `MenuItem'. (component_free): Free ->id. (component_new): Renamed from `component_new_from_client'. Get an @id arg and set ->id accordingly. (e_shell_user_creatable_items_handler_add_component): New arg @id. Pass it to `component_new'. (e_shell_user_creatable_items_handler_setup_menus): New arg @current_component_id. (e_shell_user_creatable_items_handler_update_menus): New. (set_current_component): New helper function. (get_component_by_id): New helper function. (add_verbs): Renamed from `add_verbs_to_ui_component()'. Get a @shell_view instead of a @ui_component. Set the SHELL_VIEW_KEY on the ui_component of the shell_view to point to the shell_view itself. (ensure_menu_items): Set item->icon to NULL. (free_menu_items): Unref item->icon. (ensure_menu_xml): Set the icon as well. (get_default_action_for_view): New helper function. (find_menu_item_for_verb): New helper function. (shell_view_view_changed_callback): New callback, set up the label on the "New" button depending on the current component. (e_shell_user_creatable_items_handler_attach_menus): New. For now, do not display the toolbar button yet. (execute_verb): New helper function, splitting out code from `verb_fn'. (verb_fn): Use `execute_verb'. (combo_button_activate_default_callback): Callback for the "activate_default" signal on the EComboButton. (setup_toolbar_button): Connect. * evolution-shell-component.c: New member `icon' in `UserCreatableItemType'. (impl__get_userCreatableItemTypes): Put the ->icon in the corba_type as well. (user_creatable_item_type_new): Get a new @icon argument. (evolution_shell_component_add_user_creatable_item): New arg @icon. * Evolution-ShellComponent.idl: New member `icon' in struct `UserCreatableItemType'. * evolution-test-component.c (register_component): Pass a NULL @icon to `evolution_shell_component_add_user_creatable_item()'. * e-shell-view.c (class_init): Add the signal to the class. (e_shell_view_display_uri): Emit "view_changed". (e_shell_view_get_current_component_id): New. * evolution-shell-component-client.c: New member `id' in EvolutionShellComponentClientPrivate. (init): Init to NULL. (impl_destroy): Free. (evolution_shell_component_client_new_for_objref): Removed. (evolution_shell_component_client_construct): New arg @id. Initialize ->id from it. (evolution_shell_component_client_get_id): New. * e-shell-view.h: New signal "view_changed". * evolution-activity-client.c (create_icon_from_pixbuf): Removed. (create_corba_animated_icon_from_pixbuf_array): Removed. (evolution_activity_client_construct): Use `e_new_corba_animated_icon_from_pixbuf_array()' instead. svn path=/trunk/; revision=15438
353 lines
9.2 KiB
C
353 lines
9.2 KiB
C
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
|
||
/* evolution-test-component.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
|
||
*/
|
||
|
||
/* Simple test component for the Evolution shell. */
|
||
|
||
#ifdef HAVE_CONFIG_H
|
||
#include <config.h>
|
||
#endif
|
||
|
||
#include "evolution-shell-component.h"
|
||
#include "evolution-activity-client.h"
|
||
|
||
#include <bonobo/bonobo-generic-factory.h>
|
||
#include <bonobo/bonobo-main.h>
|
||
|
||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||
|
||
|
||
#define COMPONENT_ID "OAFIID:GNOME_Evolution_TestComponent_ShellComponent"
|
||
|
||
static const EvolutionShellComponentFolderType folder_types[] = {
|
||
{ "test", "/usr/share/pixmaps/gnome-money.png", N_("Test"), N_("Test type"), FALSE, NULL, NULL },
|
||
{ NULL }
|
||
};
|
||
|
||
|
||
static EvolutionShellClient *parent_shell = NULL;
|
||
|
||
static int timeout_id = 0;
|
||
|
||
|
||
/* Test the ::Shortcut interface. */
|
||
|
||
static void
|
||
spit_out_shortcuts (EvolutionShellClient *shell_client)
|
||
{
|
||
GNOME_Evolution_Shortcuts shortcuts_interface;
|
||
GNOME_Evolution_Shortcuts_GroupList *groups;
|
||
CORBA_Environment ev;
|
||
int i, j;
|
||
|
||
CORBA_exception_init (&ev);
|
||
|
||
shortcuts_interface = evolution_shell_client_get_shortcuts_interface (shell_client);
|
||
if (CORBA_Object_is_nil (shortcuts_interface, &ev)) {
|
||
g_warning ("No ::Shortcut interface on the shell");
|
||
CORBA_exception_free (&ev);
|
||
return;
|
||
}
|
||
|
||
groups = GNOME_Evolution_Shortcuts__get_groups (shortcuts_interface, &ev);
|
||
if (ev._major != CORBA_NO_EXCEPTION) {
|
||
g_warning ("Exception getting the groups: %s", ev._repo_id);
|
||
CORBA_exception_free (&ev);
|
||
return;
|
||
}
|
||
|
||
for (i = 0; i < groups->_length; i ++) {
|
||
GNOME_Evolution_Shortcuts_Group *group;
|
||
GNOME_Evolution_Shortcuts_ShortcutList *shortcuts;
|
||
|
||
group = groups->_buffer + i;
|
||
shortcuts = &group->shortcuts;
|
||
|
||
g_print ("\tGROUP: %s\n", group->name);
|
||
|
||
for (j = 0; j < shortcuts->_length; j ++) {
|
||
GNOME_Evolution_Shortcuts_Shortcut *shortcut;
|
||
|
||
shortcut = shortcuts->_buffer + j;
|
||
|
||
g_print ("\t\tName: %s\n", shortcut->name);
|
||
g_print ("\t\t\tType: %s\n", shortcut->type);
|
||
g_print ("\t\t\tURI: %s\n", shortcut->uri);
|
||
}
|
||
}
|
||
|
||
g_print ("** Done\n\n");
|
||
|
||
CORBA_exception_free (&ev);
|
||
}
|
||
|
||
|
||
/* Callbacks. */
|
||
|
||
static void
|
||
activity_client_cancel_callback (EvolutionActivityClient *client,
|
||
void *data)
|
||
{
|
||
g_print ("User requested that the operation be cancelled.\n");
|
||
}
|
||
|
||
static void
|
||
activity_client_show_details_callback (EvolutionActivityClient *client,
|
||
void *data)
|
||
{
|
||
g_print ("User wants to see details.\n");
|
||
}
|
||
|
||
|
||
/* Timeout #3: We are done. */
|
||
static int
|
||
timeout_callback_3 (void *data)
|
||
{
|
||
EvolutionActivityClient *activity_client;
|
||
|
||
activity_client = EVOLUTION_ACTIVITY_CLIENT (data);
|
||
|
||
gtk_object_unref (GTK_OBJECT (activity_client));
|
||
|
||
g_print ("--> Done.\n");
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
/* Timeout #2: Update the progress until it reaches 100%. */
|
||
static int
|
||
timeout_callback_2 (void *data)
|
||
{
|
||
EvolutionActivityClient *activity_client;
|
||
int progress;
|
||
|
||
activity_client = EVOLUTION_ACTIVITY_CLIENT (data);
|
||
progress = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (activity_client), "my_progress"));
|
||
|
||
if (progress < 0)
|
||
progress = 0;
|
||
|
||
g_print ("--> Updating %d\n", progress);
|
||
|
||
if (! evolution_activity_client_update (activity_client, "Operation Foo in progress",
|
||
(float) progress / 100.0)) {
|
||
g_warning ("Error when updating operation");
|
||
return FALSE;
|
||
}
|
||
|
||
progress ++;
|
||
gtk_object_set_data (GTK_OBJECT (activity_client), "my_progress", GINT_TO_POINTER (progress));
|
||
|
||
if (progress > 100) {
|
||
gtk_timeout_add (200, timeout_callback_3, activity_client);
|
||
return FALSE;
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/* Timeout #1: Set busy. */
|
||
static int
|
||
timeout_callback_1 (void *data)
|
||
{
|
||
EvolutionActivityClient *activity_client;
|
||
gboolean suggest_display;
|
||
GdkPixbuf *animated_icon[2];
|
||
static int count = 0;
|
||
|
||
#define NUM_ACTIVITIES 10
|
||
|
||
animated_icon[0] = gdk_pixbuf_new_from_file (gnome_pixmap_file ("gnome-money.png"));
|
||
animated_icon[1] = NULL;
|
||
|
||
g_assert (animated_icon[0] != NULL);
|
||
|
||
activity_client = evolution_activity_client_new (parent_shell, COMPONENT_ID,
|
||
animated_icon,
|
||
"Operation Foo started!",
|
||
TRUE,
|
||
&suggest_display);
|
||
if (activity_client == CORBA_OBJECT_NIL) {
|
||
g_warning ("Cannot create EvolutionActivityClient object");
|
||
return FALSE;
|
||
}
|
||
|
||
gtk_object_set_data (GTK_OBJECT (activity_client), "my_progress", GINT_TO_POINTER (-1));
|
||
|
||
gtk_signal_connect (GTK_OBJECT (activity_client), "cancel",
|
||
GTK_SIGNAL_FUNC (activity_client_cancel_callback), NULL);
|
||
gtk_signal_connect (GTK_OBJECT (activity_client), "show_details",
|
||
GTK_SIGNAL_FUNC (activity_client_show_details_callback), NULL);
|
||
|
||
g_print ("Component becoming busy -- %s\n", COMPONENT_ID);
|
||
if (suggest_display)
|
||
g_print (" --> Could display dialog box.\n");
|
||
|
||
gtk_timeout_add (100, timeout_callback_2, activity_client);
|
||
|
||
if (count < NUM_ACTIVITIES) {
|
||
count ++;
|
||
gtk_timeout_add ((rand () % 5 + 1) * 500, timeout_callback_1, NULL);
|
||
}
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
|
||
static EvolutionShellComponentResult
|
||
create_view_fn (EvolutionShellComponent *shell_component,
|
||
const char *physical_uri,
|
||
const char *folder_type,
|
||
BonoboControl **control_return,
|
||
void *closure)
|
||
{
|
||
GtkWidget *vbox;
|
||
GtkWidget *label_1, *label_2;
|
||
GtkWidget *event_box_1, *event_box_2;
|
||
|
||
label_1 = gtk_label_new ("This is just a test component, displaying the following URI:");
|
||
label_2 = gtk_label_new (physical_uri);
|
||
|
||
event_box_1 = gtk_event_box_new ();
|
||
event_box_2 = gtk_event_box_new ();
|
||
|
||
vbox = gtk_vbox_new (FALSE, 5);
|
||
|
||
gtk_box_pack_start (GTK_BOX (vbox), event_box_1, TRUE, TRUE, 0);
|
||
gtk_box_pack_start (GTK_BOX (vbox), label_1, FALSE, TRUE, 0);
|
||
gtk_box_pack_start (GTK_BOX (vbox), label_2, FALSE, TRUE, 0);
|
||
gtk_box_pack_start (GTK_BOX (vbox), event_box_2, TRUE, TRUE, 0);
|
||
|
||
gtk_widget_show (label_1);
|
||
gtk_widget_show (label_2);
|
||
gtk_widget_show (event_box_1);
|
||
gtk_widget_show (event_box_2);
|
||
|
||
gtk_widget_show (vbox);
|
||
|
||
*control_return = bonobo_control_new (vbox);
|
||
|
||
g_assert (timeout_id == 0);
|
||
timeout_id = gtk_timeout_add (2000, timeout_callback_1, NULL);
|
||
|
||
return EVOLUTION_SHELL_COMPONENT_OK;
|
||
}
|
||
|
||
|
||
/* Callbacks. */
|
||
|
||
static void
|
||
owner_set_callback (EvolutionShellComponent *shell_component,
|
||
EvolutionShellClient *shell_client,
|
||
const char *evolution_homedir)
|
||
{
|
||
g_assert (parent_shell == NULL);
|
||
|
||
g_print ("We have an owner -- home directory is `%s'\n", evolution_homedir);
|
||
|
||
parent_shell = shell_client;
|
||
|
||
if (evolution_shell_client_get_activity_interface (parent_shell) == CORBA_OBJECT_NIL)
|
||
g_warning ("Shell doesn't have a ::Activity interface -- weird!");
|
||
|
||
spit_out_shortcuts (shell_client);
|
||
}
|
||
|
||
static int
|
||
owner_unset_idle_callback (void *data)
|
||
{
|
||
gtk_main_quit ();
|
||
return FALSE;
|
||
}
|
||
|
||
static void
|
||
owner_unset_callback (EvolutionShellComponent *shell_component,
|
||
void *data)
|
||
{
|
||
g_idle_add_full (G_PRIORITY_LOW, owner_unset_idle_callback, NULL, NULL);
|
||
}
|
||
|
||
static void
|
||
user_create_new_item_callback (EvolutionShellComponent *shell_component,
|
||
const char *id,
|
||
const char *parent_folder_physical_uri,
|
||
const char *parent_folder_type)
|
||
{
|
||
g_print ("\n*** Should create -- %s\n", id);
|
||
g_print ("\n\tType %s, URI %s\n", parent_folder_type, parent_folder_physical_uri);
|
||
}
|
||
|
||
|
||
static void
|
||
register_component (void)
|
||
{
|
||
EvolutionShellComponent *shell_component;
|
||
int result;
|
||
|
||
shell_component = evolution_shell_component_new (folder_types,
|
||
NULL,
|
||
create_view_fn,
|
||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||
|
||
gtk_signal_connect (GTK_OBJECT (shell_component), "owner_set",
|
||
GTK_SIGNAL_FUNC (owner_set_callback), NULL);
|
||
gtk_signal_connect (GTK_OBJECT (shell_component), "owner_unset",
|
||
GTK_SIGNAL_FUNC (owner_unset_callback), NULL);
|
||
|
||
evolution_shell_component_add_user_creatable_item (shell_component, "Stuff",
|
||
"New Stuff", "New _Stuff", '\0', NULL);
|
||
evolution_shell_component_add_user_creatable_item (shell_component, "MoreStuff",
|
||
"New More Stuff", "New _More Stuff", 'n', NULL);
|
||
|
||
gtk_signal_connect (GTK_OBJECT (shell_component), "user_create_new_item",
|
||
GTK_SIGNAL_FUNC (user_create_new_item_callback), NULL);
|
||
|
||
result = oaf_active_server_register (COMPONENT_ID,
|
||
bonobo_object_corba_objref (BONOBO_OBJECT (shell_component)));
|
||
|
||
if (result == OAF_REG_ERROR)
|
||
g_error ("Cannot register active server into OAF");
|
||
}
|
||
|
||
|
||
int
|
||
main (int argc, char **argv)
|
||
{
|
||
CORBA_ORB orb;
|
||
|
||
bindtextdomain (PACKAGE, EVOLUTION_LOCALEDIR);
|
||
textdomain (PACKAGE);
|
||
|
||
gnome_init_with_popt_table ("evolution-test-component", VERSION,
|
||
argc, argv, oaf_popt_options, 0, NULL);
|
||
|
||
orb = oaf_init (argc, argv);
|
||
|
||
if (bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE)
|
||
g_error ("Cannot initialize the test component.");
|
||
|
||
register_component ();
|
||
|
||
bonobo_main ();
|
||
|
||
return 0;
|
||
}
|