diff options
author | Ettore Perazzoli <ettore@src.gnome.org> | 2000-05-25 13:55:59 +0800 |
---|---|---|
committer | Ettore Perazzoli <ettore@src.gnome.org> | 2000-05-25 13:55:59 +0800 |
commit | bb241192eb773d7f0d178306dd55f9ca8e31c1f0 (patch) | |
tree | 4201777027364eeea243b2f625bb373bca30ef6d /shell | |
parent | e90eea58a2109961faa8632ac5e5783d9970366b (diff) | |
download | gsoc2013-evolution-bb241192eb773d7f0d178306dd55f9ca8e31c1f0.tar gsoc2013-evolution-bb241192eb773d7f0d178306dd55f9ca8e31c1f0.tar.gz gsoc2013-evolution-bb241192eb773d7f0d178306dd55f9ca8e31c1f0.tar.bz2 gsoc2013-evolution-bb241192eb773d7f0d178306dd55f9ca8e31c1f0.tar.lz gsoc2013-evolution-bb241192eb773d7f0d178306dd55f9ca8e31c1f0.tar.xz gsoc2013-evolution-bb241192eb773d7f0d178306dd55f9ca8e31c1f0.tar.zst gsoc2013-evolution-bb241192eb773d7f0d178306dd55f9ca8e31c1f0.zip |
Reorganized the shell to allow dynamic registration of storages and
folder types, and changed all the components to work with the new
setup.
svn path=/trunk/; revision=3199
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ChangeLog | 55 | ||||
-rw-r--r-- | shell/Evolution-ShellComponent.idl | 20 | ||||
-rw-r--r-- | shell/Makefile.am | 8 | ||||
-rw-r--r-- | shell/e-component-registry.c | 283 | ||||
-rw-r--r-- | shell/e-component-registry.h | 74 | ||||
-rw-r--r-- | shell/e-folder-type-registry.c | 336 | ||||
-rw-r--r-- | shell/e-folder-type-registry.h | 86 | ||||
-rw-r--r-- | shell/e-shell-view.c | 69 | ||||
-rw-r--r-- | shell/e-shell.c | 77 | ||||
-rw-r--r-- | shell/e-shell.h | 22 | ||||
-rw-r--r-- | shell/e-shortcuts-view.c | 6 | ||||
-rw-r--r-- | shell/e-shortcuts.c | 18 | ||||
-rw-r--r-- | shell/e-shortcuts.h | 45 | ||||
-rw-r--r-- | shell/e-storage-set-view.c | 16 | ||||
-rw-r--r-- | shell/e-storage-set.c | 22 | ||||
-rw-r--r-- | shell/e-storage-set.h | 39 | ||||
-rw-r--r-- | shell/evolution-shell-component.c | 332 | ||||
-rw-r--r-- | shell/evolution-shell-component.h | 91 | ||||
-rw-r--r-- | shell/main.c | 38 |
19 files changed, 1492 insertions, 145 deletions
diff --git a/shell/ChangeLog b/shell/ChangeLog index a6243ba328..9854bb840e 100644 --- a/shell/ChangeLog +++ b/shell/ChangeLog @@ -1,3 +1,58 @@ +2000-05-25 Ettore Perazzoli <ettore@helixcode.com> + + * e-storage-set-view.c (e_storage_set_view_construct): Set the + dotted line type again. Dotted is less butt-ugly than continuous. + + * e-shell-view.c (show_error): Display page zero in the notebook. + + * main.c (idle_cb): Renamed from `new_view_idle_cb'. Create the + EShell object here, because now the shell depends on the GLib loop + to be running for correct operation. + (main): Don't create the EShell here. + + * e-storage-set-view.c (get_pixmap_and_mask_for_folder): If the + icon is not found, set the returned pixmap and mask to NULL. + + * e-shell.c (e_shell_construct): Added precondition: @corba_object + must be non-nil. + (e_shell_new): Added precondition: @local_direcory must be + non-null. + + * evolution-shell-component.c: New. + * evolution-shell-component.h: New. + + * e-shell.c: New member `component_registry' in `EShellPrivate'. + (init): Initialize to NULL. + (destroy): Unref it. + (setup_components): New function to set up the compnent registry + and initialize the mail, calendar and addressbook components. + (e_shell_construct): Call it. + + * e-storage-set.c: Updated to use EFolderTypeRegistry. + * e-storage-set.h: Likewise. + * e-shortcuts.c: Likewise. + * e-shortcuts.h: Likewise. + * e-shell.c: Likewise. + + * e-shell.h: Likewise. + * e-shell-view.c: Likewise. + * e-shortcuts-view.c: Likewise. + * e-storage-set-view.c: Likewise. + + * e-component-registry.c: New. + * e-component-registry.h: New. + + * e-folder-type-registry.c: New. + * e-folder-type-registry.h: New. + + * e-folder-type-repository.c: Removed. + * e-folder-type-repository.h: Removed. + + * Evolution-ShellComponent.idl: New struct `FolderType'; new type + `FolderTypeList'. New attribute `supported_types'. + (ShellComponent::set_owner): Renamed from `set_shell'. + (ShellComponent::create_view): New. + 2000-05-24 Christopher James Lahey <clahey@helixcode.com> * e-shell-view.c: Was using the wrong include here. diff --git a/shell/Evolution-ShellComponent.idl b/shell/Evolution-ShellComponent.idl index 9a4624010e..2e67b18c17 100644 --- a/shell/Evolution-ShellComponent.idl +++ b/shell/Evolution-ShellComponent.idl @@ -11,7 +11,25 @@ #include <Bonobo.h> module Evolution { + interface Shell; + + struct FolderType { + string name; + string icon_name; + }; + + typedef sequence<FolderType> FolderTypeList; + interface ShellComponent : Bonobo::Unknown { - void set_shell (in Shell shell); + readonly attribute FolderTypeList supported_types; + + /* FIXME can we use an attribute here? */ + exception AlreadyOwned {}; + void set_owner (in Shell shell) + raises (AlreadyOwned); + + exception NotFound {}; + Bonobo::Control create_view (in string physical_uri) + raises (NotFound); }; }; diff --git a/shell/Makefile.am b/shell/Makefile.am index 10a7404035..d3f680b975 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -33,8 +33,8 @@ evolution_SOURCES = \ e-corba-storage.h \ e-corba-storage-registry.c \ e-corba-storage-registry.h \ - e-folder-type-repository.c \ - e-folder-type-repository.h \ + e-folder-type-registry.c \ + e-folder-type-registry.h \ e-folder.c \ e-folder.h \ e-local-folder.c \ @@ -43,6 +43,8 @@ evolution_SOURCES = \ e-local-storage.h \ e-setup.c \ e-setup.h \ + e-component-registry.h \ + e-component-registry.c \ e-shell-constants.h \ e-shell-utils.c \ e-shell-utils.h \ @@ -64,6 +66,8 @@ evolution_SOURCES = \ e-storage-watcher.h \ e-storage.c \ e-storage.h \ + evolution-shell-component.c \ + evolution-shell-component.h \ main.c Evolution-impl.o: Evolution.h diff --git a/shell/e-component-registry.c b/shell/e-component-registry.c new file mode 100644 index 0000000000..15e5204569 --- /dev/null +++ b/shell/e-component-registry.c @@ -0,0 +1,283 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-component-registry.c + * + * Copyright (C) 2000 Helix Code, Inc. + * + * 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 Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gtk/gtkobject.h> +#include <gtk/gtktypeutils.h> +#include <bonobo.h> + +#include "e-util/e-util.h" +#include "e-shell-utils.h" + +#include "Evolution.h" + +#include "e-component-registry.h" + + +#define PARENT_TYPE GTK_TYPE_OBJECT +static GtkObjectClass *parent_class = NULL; + +typedef struct _Component Component; + +struct _Component { + char *id; + + BonoboObjectClient *client; + + /* Names of the folder types we support (normal ASCII strings). */ + GList *folder_type_names; +}; + +struct _EComponentRegistryPrivate { + EShell *shell; + + GHashTable *component_id_to_component; +}; + + +/* Component information handling. */ + +static Component * +component_new (const char *id, + BonoboObjectClient *client) +{ + Component *new; + + bonobo_object_ref (BONOBO_OBJECT (client)); + + new = g_new (Component, 1); + new->id = g_strdup (id); + new->folder_type_names = NULL; + new->client = client; + + return new; +} + +static void +component_free (Component *component) +{ + g_free (component->id); + bonobo_object_unref (BONOBO_OBJECT (component->client)); + + e_free_string_list (component->folder_type_names); + + g_free (component); +} + +static gboolean +register_type (EComponentRegistry *component_registry, + const char *name, + const char *icon_name, + Component *handler) +{ + EComponentRegistryPrivate *priv; + EFolderTypeRegistry *folder_type_registry; + + priv = component_registry->priv; + + folder_type_registry = e_shell_get_folder_type_registry (priv->shell); + g_assert (folder_type_registry != NULL); + + if (! e_folder_type_registry_register_type (folder_type_registry, name, icon_name)) { + g_warning ("Trying to register duplicate folder type -- %s", name); + return FALSE; + } + + e_folder_type_registry_set_handler_for_type (folder_type_registry, name, handler->client); + + return TRUE; +} + +static gboolean +register_component (EComponentRegistry *component_registry, + const char *id) +{ + EComponentRegistryPrivate *priv; + Evolution_ShellComponent component_corba_interface; + Evolution_Shell shell_corba_interface; + Evolution_FolderTypeList *supported_types; + Component *component; + BonoboObjectClient *client; + CORBA_Environment ev; + CORBA_unsigned_long i; + + priv = component_registry->priv; + + if (g_hash_table_lookup (priv->component_id_to_component, id) != NULL) { + g_warning ("Trying to register component twice -- %s", id); + return FALSE; + } + + client = bonobo_object_activate (id, 0); + if (client == NULL) + return FALSE; + + CORBA_exception_init (&ev); + + component_corba_interface = bonobo_object_corba_objref (BONOBO_OBJECT (client)); + shell_corba_interface = bonobo_object_corba_objref (BONOBO_OBJECT (priv->shell)); + + Evolution_ShellComponent_set_owner (component_corba_interface, shell_corba_interface, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + bonobo_object_unref (BONOBO_OBJECT (client)); + CORBA_exception_free (&ev); + return FALSE; + } + + supported_types = Evolution_ShellComponent__get_supported_types (component_corba_interface, &ev); + if (ev._major != CORBA_NO_EXCEPTION || supported_types->_length == 0) { + bonobo_object_unref (BONOBO_OBJECT (client)); + CORBA_exception_free (&ev); + return FALSE; + } + + CORBA_exception_free (&ev); + + component = component_new (id, client); + g_hash_table_insert (priv->component_id_to_component, component->id, component); + + for (i = 0; i < supported_types->_length; i++) { + const Evolution_FolderType *type; + + type = supported_types->_buffer + i; + + if (! register_type (component_registry, type->name, type->icon_name, component)) { + g_warning ("Cannot register type `%s' for component %s", + type->name, component->id); + } else { + g_print ("Registered type for component -- (%s) %s\n", + type->name, component->id); + } + } + + CORBA_free (supported_types); + + return TRUE; +} + + +/* GtkObject methods. */ + +static void +component_id_foreach_free (void *key, + void *value, + void *user_data) +{ + Component *component; + + component = (Component *) value; + component_free (component); +} + +static void +destroy (GtkObject *object) +{ + EComponentRegistry *component_registry; + EComponentRegistryPrivate *priv; + + component_registry = E_COMPONENT_REGISTRY (object); + priv = component_registry->priv; + + bonobo_object_unref (BONOBO_OBJECT (priv->shell)); + + g_hash_table_foreach (priv->component_id_to_component, component_id_foreach_free, NULL); + g_hash_table_destroy (priv->component_id_to_component); + + g_free (priv); +} + + +static void +class_init (EComponentRegistryClass *klass) +{ + GtkObjectClass *object_class; + + object_class = GTK_OBJECT_CLASS (klass); + object_class->destroy = destroy; + + parent_class = gtk_type_class (gtk_object_get_type ()); +} + + +static void +init (EComponentRegistry *component_registry) +{ + EComponentRegistryPrivate *priv; + + priv = g_new (EComponentRegistryPrivate, 1); + priv->shell = NULL; + priv->component_id_to_component = g_hash_table_new (g_str_hash, g_str_equal); + + component_registry->priv = priv; +} + + +void +e_component_registry_construct (EComponentRegistry *component_registry, + EShell *shell) +{ + EComponentRegistryPrivate *priv; + + g_return_if_fail (component_registry != NULL); + g_return_if_fail (E_IS_COMPONENT_REGISTRY (component_registry)); + g_return_if_fail (shell != NULL); + g_return_if_fail (E_IS_SHELL (shell)); + + priv = component_registry->priv; + + bonobo_object_ref (BONOBO_OBJECT (shell)); + priv->shell = shell; +} + +EComponentRegistry * +e_component_registry_new (EShell *shell) +{ + EComponentRegistry *component_registry; + + g_return_val_if_fail (shell != NULL, NULL); + g_return_val_if_fail (E_IS_SHELL (shell), NULL); + + component_registry = gtk_type_new (e_component_registry_get_type ()); + e_component_registry_construct (component_registry, shell); + + return component_registry; +} + + +gboolean +e_component_registry_register_component (EComponentRegistry *component_registry, + const char *id) +{ + g_return_val_if_fail (component_registry != NULL, FALSE); + g_return_val_if_fail (E_IS_COMPONENT_REGISTRY (component_registry), FALSE); + g_return_val_if_fail (id != NULL, FALSE); + + return register_component (component_registry, id); +} + + +E_MAKE_TYPE (e_component_registry, "EComponentRegistry", EComponentRegistry, + class_init, init, PARENT_TYPE) diff --git a/shell/e-component-registry.h b/shell/e-component-registry.h new file mode 100644 index 0000000000..298b756391 --- /dev/null +++ b/shell/e-component-registry.h @@ -0,0 +1,74 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-component-registry.h + * + * Copyright (C) 2000 Helix Code, Inc. + * + * 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 Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifndef __E_COMPONENT_REGISTRY_H__ +#define __E_COMPONENT_REGISTRY_H__ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gtk/gtkobject.h> + +#include "e-shell.h" + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define E_TYPE_COMPONENT_REGISTRY (e_component_registry_get_type ()) +#define E_COMPONENT_REGISTRY(obj) (GTK_CHECK_CAST ((obj), E_TYPE_COMPONENT_REGISTRY, EComponentRegistry)) +#define E_COMPONENT_REGISTRY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_COMPONENT_REGISTRY, EComponentRegistryClass)) +#define E_IS_COMPONENT_REGISTRY(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_COMPONENT_REGISTRY)) +#define E_IS_COMPONENT_REGISTRY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_COMPONENT_REGISTRY)) + + +typedef struct _EComponentRegistry EComponentRegistry; +typedef struct _EComponentRegistryPrivate EComponentRegistryPrivate; +typedef struct _EComponentRegistryClass EComponentRegistryClass; + +struct _EComponentRegistry { + GtkObject parent; + + EComponentRegistryPrivate *priv; +}; + +struct _EComponentRegistryClass { + GtkObjectClass parent_class; +}; + + +GtkType e_component_registry_get_type (void); +void e_component_registry_construct (EComponentRegistry *component_registry, + EShell *shell); +EComponentRegistry *e_component_registry_new (EShell *shell); + +gboolean e_component_registry_register_component (EComponentRegistry *component_registry, + const char *id); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __E_COMPONENT_REGISTRY_H__ */ diff --git a/shell/e-folder-type-registry.c b/shell/e-folder-type-registry.c new file mode 100644 index 0000000000..e5447ca54d --- /dev/null +++ b/shell/e-folder-type-registry.c @@ -0,0 +1,336 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-folder-type-registry.c + * + * Copyright (C) 2000 Helix Code, Inc. + * + * 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 Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib.h> +#include <gtk/gtktypeutils.h> + +#include "e-util/e-util.h" + +#include "e-shell-utils.h" + +#include "e-folder-type-registry.h" + + +#define PARENT_TYPE GTK_TYPE_OBJECT +static GtkObjectClass *parent_class = NULL; + +struct _FolderType { + char *name; + char *icon_name; + + BonoboObjectClient *handler; + + /* The icon, standard (48x48) and mini (16x16) versions. */ + GdkPixbuf *icon_pixbuf; + GdkPixbuf *mini_icon_pixbuf; +}; +typedef struct _FolderType FolderType; + +struct _EFolderTypeRegistryPrivate { + GHashTable *name_to_type; +}; + + +/* FolderType handling. */ + +static FolderType * +folder_type_new (const char *name, + const char *icon_name) +{ + FolderType *new; + char *icon_path; + + new = g_new (FolderType, 1); + + new->name = g_strdup (name); + new->icon_name = g_strdup (icon_name); + new->handler = NULL; + + icon_path = e_shell_get_icon_path (icon_name, FALSE); + if (icon_path == NULL) + new->icon_pixbuf = NULL; + else + new->icon_pixbuf = gdk_pixbuf_new_from_file (icon_path); + + g_free (icon_path); + + icon_path = e_shell_get_icon_path (icon_name, TRUE); + if (icon_path != NULL) { + new->mini_icon_pixbuf = gdk_pixbuf_new_from_file (icon_path); + } else { + if (new->icon_pixbuf != NULL) + new->mini_icon_pixbuf = gdk_pixbuf_ref (new->icon_pixbuf); + else + new->mini_icon_pixbuf = NULL; + } + + g_free (icon_path); + + return new; +} + +static void +folder_type_free (FolderType *folder_type) +{ + g_free (folder_type->name); + g_free (folder_type->icon_name); + + if (folder_type->icon_pixbuf != NULL) + gdk_pixbuf_unref (folder_type->icon_pixbuf); + if (folder_type->mini_icon_pixbuf != NULL) + gdk_pixbuf_unref (folder_type->mini_icon_pixbuf); + + if (folder_type->handler != NULL) + bonobo_object_unref (BONOBO_OBJECT (folder_type->handler)); + + g_free (folder_type); +} + +static FolderType * +get_folder_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name) +{ + EFolderTypeRegistryPrivate *priv; + + priv = folder_type_registry->priv; + + return g_hash_table_lookup (priv->name_to_type, type_name); +} + +static gboolean +register_folder_type (EFolderTypeRegistry *folder_type_registry, + const char *name, + const char *icon_name) +{ + EFolderTypeRegistryPrivate *priv; + FolderType *folder_type; + + priv = folder_type_registry->priv; + + /* Make sure we don't add the same type twice. */ + if (get_folder_type (folder_type_registry, name) != NULL) + return FALSE; + + folder_type = folder_type_new (name, icon_name); + g_hash_table_insert (priv->name_to_type, folder_type->name, folder_type); + + return TRUE; +} + +static gboolean +set_handler (EFolderTypeRegistry *folder_type_registry, + const char *name, + BonoboObjectClient *handler) +{ + EFolderTypeRegistryPrivate *priv; + FolderType *folder_type; + + priv = folder_type_registry->priv; + + folder_type = get_folder_type (folder_type_registry, name); + if (folder_type == NULL) + return FALSE; + if (folder_type->handler != NULL) { + g_warning ("Folder type already has a handler -- %s", folder_type->name); + return FALSE; + } + + bonobo_object_ref (BONOBO_OBJECT (handler)); + folder_type->handler = handler; + + return TRUE; +} + + +/* GtkObject methods. */ + +static void +hash_forall_free_folder_type (gpointer key, + gpointer value, + gpointer data) +{ + FolderType *folder_type; + + folder_type = (FolderType *) value; + folder_type_free (folder_type); +} + +static void +destroy (GtkObject *object) +{ + EFolderTypeRegistry *folder_type_registry; + EFolderTypeRegistryPrivate *priv; + + folder_type_registry = E_FOLDER_TYPE_REGISTRY (object); + priv = folder_type_registry->priv; + + g_hash_table_foreach (priv->name_to_type, hash_forall_free_folder_type, NULL); + g_hash_table_destroy (priv->name_to_type); + + g_free (priv); + + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + + +static void +class_init (EFolderTypeRegistryClass *class) +{ + GtkObjectClass *object_class; + + object_class = GTK_OBJECT_CLASS (class); + object_class->destroy = destroy; + + parent_class = gtk_type_class (gtk_object_get_type ()); +} + +static void +init (EFolderTypeRegistry *folder_type_registry) +{ + EFolderTypeRegistryPrivate *priv; + + priv = g_new (EFolderTypeRegistryPrivate, 1); + priv->name_to_type = g_hash_table_new (g_str_hash, g_str_equal); + + folder_type_registry->priv = priv; +} + + +void +e_folder_type_registry_construct (EFolderTypeRegistry *folder_type_registry) +{ + g_return_if_fail (folder_type_registry != NULL); + g_return_if_fail (E_IS_FOLDER_TYPE_REGISTRY (folder_type_registry)); + + GTK_OBJECT_UNSET_FLAGS (GTK_OBJECT (folder_type_registry), GTK_FLOATING); +} + +EFolderTypeRegistry * +e_folder_type_registry_new (void) +{ + EFolderTypeRegistry *new; + + new = gtk_type_new (e_folder_type_registry_get_type ()); + + e_folder_type_registry_construct (new); + + return new; +} + + +gboolean +e_folder_type_registry_register_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name, + const char *icon_name) +{ + g_return_val_if_fail (folder_type_registry != NULL, FALSE); + g_return_val_if_fail (E_IS_FOLDER_TYPE_REGISTRY (folder_type_registry), FALSE); + g_return_val_if_fail (type_name != NULL, FALSE); + g_return_val_if_fail (icon_name != NULL, FALSE); + + return register_folder_type (folder_type_registry, type_name, icon_name); +} + +gboolean +e_folder_type_registry_set_handler_for_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name, + BonoboObjectClient *handler) +{ + g_return_val_if_fail (folder_type_registry != NULL, FALSE); + g_return_val_if_fail (E_IS_FOLDER_TYPE_REGISTRY (folder_type_registry), FALSE); + g_return_val_if_fail (handler != NULL, FALSE); + g_return_val_if_fail (BONOBO_IS_OBJECT_CLIENT (handler), FALSE); + + return set_handler (folder_type_registry, type_name, handler); +} + + + +const char * +e_folder_type_registry_get_icon_name_for_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name) +{ + const FolderType *folder_type; + + g_return_val_if_fail (folder_type_registry != NULL, NULL); + g_return_val_if_fail (E_IS_FOLDER_TYPE_REGISTRY (folder_type_registry), NULL); + g_return_val_if_fail (type_name != NULL, NULL); + + folder_type = get_folder_type (folder_type_registry, type_name); + if (folder_type == NULL) { + g_warning ("%s: Unknown type -- %s", __FUNCTION__, type_name); + return NULL; + } + + return folder_type->icon_name; +} + +GdkPixbuf * +e_folder_type_registry_get_icon_for_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name, + gboolean mini) +{ + const FolderType *folder_type; + + g_return_val_if_fail (folder_type_registry != NULL, NULL); + g_return_val_if_fail (E_IS_FOLDER_TYPE_REGISTRY (folder_type_registry), NULL); + g_return_val_if_fail (type_name != NULL, NULL); + + folder_type = get_folder_type (folder_type_registry, type_name); + if (folder_type == NULL) { + g_warning ("%s: Unknown type -- %s", __FUNCTION__, type_name); + return NULL; + } + + if (mini) + return folder_type->mini_icon_pixbuf; + else + return folder_type->icon_pixbuf; +} + +BonoboObjectClient * +e_folder_type_registry_get_handler_for_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name) +{ + const FolderType *folder_type; + + g_return_val_if_fail (folder_type_registry != NULL, NULL); + g_return_val_if_fail (E_IS_FOLDER_TYPE_REGISTRY (folder_type_registry), NULL); + g_return_val_if_fail (type_name != NULL, NULL); + + folder_type = get_folder_type (folder_type_registry, type_name); + if (folder_type == NULL) { + g_warning ("%s: Unknown type -- %s", __FUNCTION__, type_name); + return NULL; + } + + return folder_type->handler; +} + + +E_MAKE_TYPE (e_folder_type_registry, "EFolderTypeRegistry", EFolderTypeRegistry, + class_init, init, PARENT_TYPE) diff --git a/shell/e-folder-type-registry.h b/shell/e-folder-type-registry.h new file mode 100644 index 0000000000..0297633007 --- /dev/null +++ b/shell/e-folder-type-registry.h @@ -0,0 +1,86 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-folder-type-registry.h + * + * Copyright (C) 2000 Helix Code, Inc. + * + * 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 Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifndef _E_FOLDER_TYPE_REGISTRY_H_ +#define _E_FOLDER_TYPE_REGISTRY_H_ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gtk/gtkobject.h> +#include <gdk-pixbuf/gdk-pixbuf.h> + +#include <bonobo/bonobo-object-client.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define E_TYPE_FOLDER_TYPE_REGISTRY (e_folder_type_registry_get_type ()) +#define E_FOLDER_TYPE_REGISTRY(obj) (GTK_CHECK_CAST ((obj), E_TYPE_FOLDER_TYPE_REGISTRY, EFolderTypeRegistry)) +#define E_FOLDER_TYPE_REGISTRY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_FOLDER_TYPE_REGISTRY, EFolderTypeRegistryClass)) +#define E_IS_FOLDER_TYPE_REGISTRY(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_FOLDER_TYPE_REGISTRY)) +#define E_IS_FOLDER_TYPE_REGISTRY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_FOLDER_TYPE_REGISTRY)) + + +typedef struct _EFolderTypeRegistry EFolderTypeRegistry; +typedef struct _EFolderTypeRegistryPrivate EFolderTypeRegistryPrivate; +typedef struct _EFolderTypeRegistryClass EFolderTypeRegistryClass; + +struct _EFolderTypeRegistry { + GtkObject parent; + + EFolderTypeRegistryPrivate *priv; +}; + +struct _EFolderTypeRegistryClass { + GtkObjectClass parent_class; +}; + + +GtkType e_folder_type_registry_get_type (void); +void e_folder_type_registry_construct (EFolderTypeRegistry *folder_type_registry); +EFolderTypeRegistry *e_folder_type_registry_new (void); + +gboolean e_folder_type_registry_register_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name, + const char *icon_name); +gboolean e_folder_type_registry_set_handler_for_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name, + BonoboObjectClient *handler); + +GdkPixbuf *e_folder_type_registry_get_icon_for_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name, + gboolean mini); +const char *e_folder_type_registry_get_icon_name_for_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name); +BonoboObjectClient *e_folder_type_registry_get_handler_for_type (EFolderTypeRegistry *folder_type_registry, + const char *type_name); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _E_FOLDER_TYPE_REGISTRY_H_ */ diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c index 9b52631166..c2b6816a25 100644 --- a/shell/e-shell-view.c +++ b/shell/e-shell-view.c @@ -117,18 +117,18 @@ setup_menus (EShellView *shell_view) } static gboolean -bonobo_widget_is_dead (BonoboWidget *bw) +bonobo_widget_is_dead (BonoboWidget *bonobo_widget) { - BonoboObject *boc = BONOBO_OBJECT (bonobo_widget_get_server (bw)); - CORBA_Object obj = bonobo_object_corba_objref (boc); - + BonoboControlFrame *control_frame; + CORBA_Object corba_object; CORBA_Environment ev; - - gboolean is_dead = FALSE; + gboolean is_dead; + + control_frame = bonobo_widget_get_control_frame (bonobo_widget); + corba_object = bonobo_control_frame_get_control (control_frame); CORBA_exception_init (&ev); - if (CORBA_Object_non_existent(obj, &ev)) - is_dead = TRUE; + is_dead = CORBA_Object_non_existent (corba_object, &ev); CORBA_exception_free (&ev); return is_dead; @@ -446,11 +446,10 @@ set_icon (EShellView *shell_view, if (type == NULL) { icon_path = NULL; } else { - EFolderTypeRepository *folder_type_repository; + EFolderTypeRegistry *folder_type_registry; - folder_type_repository = e_shell_get_folder_type_repository (priv->shell); - icon_name = e_folder_type_repository_get_icon_name_for_type (folder_type_repository, - type); + folder_type_registry = e_shell_get_folder_type_registry (priv->shell); + icon_name = e_folder_type_registry_get_icon_name_for_type (folder_type_registry, type); if (icon_name == NULL) icon_path = NULL; else @@ -550,6 +549,7 @@ show_error (EShellView *shell_view, { EShellViewPrivate *priv; GtkWidget *label; + GtkNotebook *notebook; char *s; priv = shell_view->priv; @@ -560,25 +560,30 @@ show_error (EShellView *shell_view, gtk_widget_show (label); - gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), 0); - gtk_notebook_prepend_page (GTK_NOTEBOOK (priv->notebook), label, NULL); + notebook = GTK_NOTEBOOK (priv->notebook); + + gtk_notebook_remove_page (notebook, 0); + gtk_notebook_prepend_page (notebook, label, NULL); + gtk_notebook_set_page (notebook, 0); } -/* Create a new view for @uri with @control. It assumes a view for @uri does - not exist yet. */ +/* Create a new view for @uri with @control. It assumes a view for @uri does not exist yet. */ static GtkWidget * get_control_for_uri (EShellView *shell_view, const char *uri) { EShellViewPrivate *priv; - EFolderTypeRepository *folder_type_repository; + EFolderTypeRegistry *folder_type_registry; EStorageSet *storage_set; EFolder *folder; Bonobo_UIHandler corba_uih; - const char *control_id; + BonoboObjectClient *handler_client; + Bonobo_Control corba_control; + Evolution_ShellComponent handler; const char *path; const char *folder_type; GtkWidget *control; + CORBA_Environment ev; priv = shell_view->priv; @@ -591,7 +596,7 @@ get_control_for_uri (EShellView *shell_view, return NULL; storage_set = e_shell_get_storage_set (priv->shell); - folder_type_repository = e_shell_get_folder_type_repository (priv->shell); + folder_type_registry = e_shell_get_folder_type_registry (priv->shell); folder = e_storage_set_get_folder (storage_set, path); if (folder == NULL) @@ -601,20 +606,26 @@ get_control_for_uri (EShellView *shell_view, if (folder_type == NULL) return NULL; - control_id = e_folder_type_repository_get_control_id_for_type (folder_type_repository, - folder_type); - if (control_id == NULL) + handler_client = e_folder_type_registry_get_handler_for_type (folder_type_registry, folder_type); + if (handler_client == NULL) return NULL; - corba_uih = bonobo_object_corba_objref (BONOBO_OBJECT (priv->uih)); - control = bonobo_widget_new_control (control_id, corba_uih); + handler = bonobo_object_corba_objref (BONOBO_OBJECT (handler_client)); + if (handler_client == CORBA_OBJECT_NIL) + return NULL; + + CORBA_exception_init (&ev); - if (control == NULL) + corba_control = Evolution_ShellComponent_create_view (handler, e_folder_get_physical_uri (folder), &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + CORBA_exception_free (&ev); return NULL; + } - bonobo_widget_set_property (BONOBO_WIDGET (control), - "folder_uri", e_folder_get_physical_uri (folder), - NULL); + CORBA_exception_free (&ev); + + corba_uih = bonobo_object_corba_objref (BONOBO_OBJECT (priv->uih)); + control = bonobo_widget_new_control_from_objref (corba_control, corba_uih); return control; } @@ -627,6 +638,8 @@ show_existing_view (EShellView *shell_view, EShellViewPrivate *priv; int notebook_page; + g_print ("Already have view for %s\n", uri); + priv = shell_view->priv; notebook_page = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook), control); diff --git a/shell/e-shell.c b/shell/e-shell.c index 19cdcdc596..ca1c44f576 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -32,8 +32,9 @@ #include "e-util/e-util.h" +#include "e-component-registry.h" #include "e-corba-storage-registry.h" -#include "e-folder-type-repository.h" +#include "e-folder-type-registry.h" #include "e-local-storage.h" #include "e-shell-view.h" #include "e-shortcuts.h" @@ -52,14 +53,30 @@ struct _EShellPrivate { EStorageSet *storage_set; EShortcuts *shortcuts; - EFolderTypeRepository *folder_type_repository; + EFolderTypeRegistry *folder_type_registry; + + EComponentRegistry *component_registry; ECorbaStorageRegistry *corba_storage_registry; }; + +/* Constants. */ + #define SHORTCUTS_FILE_NAME "shortcuts.xml" #define LOCAL_STORAGE_DIRECTORY "local" +#ifdef USING_OAF +#define MAIL_COMPONENT_ID "OAFIID:evolution-shell-component:evolution-mail:d3cb3ed6-a654-4337-8aa0-f443751d6d1b" +#define CALENDAR_COMPONENT_ID "OAFIID:evolution-shell-component:evolution-calendar:2eb9eb63-d305-4918-9c35-faae5db19e51" +#define ADDRESSBOOK_COMPONENT_ID "OAFIID:evolution-shell-component:addressbook:b7a26547-7014-4bb5-98ab-2bcac2bb55ca" +#else +#define MAIL_COMPONENT_ID "evolution-shell-component:evolution-mail" +#define CALENDAR_COMPONENT_ID "evolution-shell-component:evolution-calendar" +#define ADDRESSBOOK_COMPONENT_ID "evolution-shell-component:addressbook" +#endif + + enum { NO_VIEWS_LEFT, LAST_SIGNAL @@ -143,15 +160,39 @@ setup_storages (EShell *shell) } g_free (local_storage_path); - g_assert (shell->priv->folder_type_repository); + g_assert (shell->priv->folder_type_registry); - priv->storage_set = e_storage_set_new (shell->priv->folder_type_repository); + priv->storage_set = e_storage_set_new (shell->priv->folder_type_registry); e_storage_set_add_storage (priv->storage_set, local_storage); return setup_corba_storages (shell); } +/* Initialization of the components. */ + +static void +setup_components (EShell *shell) +{ + EShellPrivate *priv; + + priv = shell->priv; + + priv->component_registry = e_component_registry_new (shell); + + /* FIXME: Hardcoded for now. */ + + if (! e_component_registry_register_component (priv->component_registry, MAIL_COMPONENT_ID)) + g_warning ("Cannot activate mail component -- %s", MAIL_COMPONENT_ID); + + if (! e_component_registry_register_component (priv->component_registry, CALENDAR_COMPONENT_ID)) + g_warning ("Cannot activate calendar component -- %s", CALENDAR_COMPONENT_ID); + + if (! e_component_registry_register_component (priv->component_registry, ADDRESSBOOK_COMPONENT_ID)) + g_warning ("Cannot activate addressbook component -- %s", ADDRESSBOOK_COMPONENT_ID); +} + + /* EShellView destruction callback. */ static void @@ -188,8 +229,11 @@ destroy (GtkObject *object) if (priv->shortcuts != NULL) gtk_object_unref (GTK_OBJECT (priv->shortcuts)); - if (priv->folder_type_repository != NULL) - gtk_object_unref (GTK_OBJECT (priv->folder_type_repository)); + if (priv->folder_type_registry != NULL) + gtk_object_unref (GTK_OBJECT (priv->folder_type_registry)); + + if (priv->component_registry != NULL) + gtk_object_unref (GTK_OBJECT (priv->component_registry)); for (p = priv->views; p != NULL; p = p->next) { EShellView *view; @@ -269,7 +313,8 @@ init (EShell *shell) priv->local_directory = NULL; priv->storage_set = NULL; priv->shortcuts = NULL; - priv->folder_type_repository = NULL; + priv->component_registry = NULL; + priv->folder_type_registry = NULL; priv->corba_storage_registry = NULL; shell->priv = priv; @@ -286,6 +331,7 @@ e_shell_construct (EShell *shell, g_return_if_fail (shell != NULL); g_return_if_fail (E_IS_SHELL (shell)); + g_return_if_fail (corba_object != CORBA_OBJECT_NIL); g_return_if_fail (local_directory != NULL); g_return_if_fail (g_path_is_absolute (local_directory)); @@ -294,12 +340,16 @@ e_shell_construct (EShell *shell, priv = shell->priv; priv->local_directory = g_strdup (local_directory); - priv->folder_type_repository = e_folder_type_repository_new (); + priv->folder_type_registry = e_folder_type_registry_new (); + /* Storages must be set up before the components, because otherwise components + cannot register their own storages. */ if (! setup_storages (shell)) return; - priv->shortcuts = e_shortcuts_new (priv->storage_set, priv->folder_type_repository); + setup_components (shell); + + priv->shortcuts = e_shortcuts_new (priv->storage_set, priv->folder_type_registry); shortcut_path = g_concat_dir_and_file (local_directory, "shortcuts.xml"); @@ -321,6 +371,9 @@ e_shell_new (const char *local_directory) Evolution_Shell corba_object; POA_Evolution_Shell *servant; + g_return_val_if_fail (local_directory != NULL, NULL); + g_return_val_if_fail (*local_directory != '\0', NULL); + servant = create_servant (); if (servant == NULL) return NULL; @@ -382,13 +435,13 @@ e_shell_get_storage_set (EShell *shell) return shell->priv->storage_set; } -EFolderTypeRepository * -e_shell_get_folder_type_repository (EShell *shell) +EFolderTypeRegistry * +e_shell_get_folder_type_registry (EShell *shell) { g_return_val_if_fail (shell != NULL, NULL); g_return_val_if_fail (E_IS_SHELL (shell), NULL); - return shell->priv->folder_type_repository; + return shell->priv->folder_type_registry; } diff --git a/shell/e-shell.h b/shell/e-shell.h index 503b056986..cf29daad9b 100644 --- a/shell/e-shell.h +++ b/shell/e-shell.h @@ -62,20 +62,20 @@ struct _EShellClass { }; -GtkType e_shell_get_type (void); -void e_shell_construct (EShell *shell, - Evolution_Shell corba_object, - const char *local_directory); -EShell *e_shell_new (const char *local_directory); +GtkType e_shell_get_type (void); +void e_shell_construct (EShell *shell, + Evolution_Shell corba_object, + const char *local_directory); -GtkWidget *e_shell_new_view (EShell *shell, - const char *uri); +EShell *e_shell_new (const char *local_directory); +GtkWidget *e_shell_new_view (EShell *shell, + const char *uri); -EShortcuts *e_shell_get_shortcuts (EShell *shell); -EStorageSet *e_shell_get_storage_set (EShell *shell); -EFolderTypeRepository *e_shell_get_folder_type_repository (EShell *shell); +EShortcuts *e_shell_get_shortcuts (EShell *shell); +EStorageSet *e_shell_get_storage_set (EShell *shell); +EFolderTypeRegistry *e_shell_get_folder_type_registry (EShell *shell); -void e_shell_quit (EShell *shell); +void e_shell_quit (EShell *shell); #ifdef __cplusplus } diff --git a/shell/e-shortcuts-view.c b/shell/e-shortcuts-view.c index dd17326d8c..c9fa17653c 100644 --- a/shell/e-shortcuts-view.c +++ b/shell/e-shortcuts-view.c @@ -149,7 +149,7 @@ icon_callback (EShortcutBar *shortcut_bar, const char *uri, gpointer data) { - EFolderTypeRepository *folder_type_repository; + EFolderTypeRegistry *folder_type_registry; EShortcuts *shortcuts; EStorageSet *storage_set; EFolder *folder; @@ -159,7 +159,7 @@ icon_callback (EShortcutBar *shortcut_bar, shortcuts = E_SHORTCUTS (data); storage_set = e_shortcuts_get_storage_set (shortcuts); - folder_type_repository = e_storage_set_get_folder_type_repository (storage_set); + folder_type_registry = e_storage_set_get_folder_type_registry (storage_set); folder = e_storage_set_get_folder (storage_set, get_storage_set_path_from_uri (uri)); @@ -172,7 +172,7 @@ icon_callback (EShortcutBar *shortcut_bar, return NULL; /* FIXME mini icons? */ - pixbuf = e_folder_type_repository_get_icon_for_type (folder_type_repository, type, FALSE); + pixbuf = e_folder_type_registry_get_icon_for_type (folder_type_registry, type, FALSE); if (pixbuf != NULL) gdk_pixbuf_ref (pixbuf); diff --git a/shell/e-shortcuts.c b/shell/e-shortcuts.c index 34abe467bb..c6d8a77107 100644 --- a/shell/e-shortcuts.c +++ b/shell/e-shortcuts.c @@ -76,8 +76,8 @@ struct _EShortcutsPrivate { /* The storage set to which these shortcuts are associated. */ EStorageSet *storage_set; - /* The folder type repository. */ - EFolderTypeRepository *folder_type_repository; + /* The folder type registry. */ + EFolderTypeRegistry *folder_type_registry; /* A list of ShortcutGroups. */ GList *groups; @@ -265,8 +265,8 @@ destroy (GtkObject *object) if (priv->storage_set != NULL) gtk_object_unref (GTK_OBJECT (priv->storage_set)); - if (priv->folder_type_repository != NULL) - gtk_object_unref (GTK_OBJECT (priv->folder_type_repository)); + if (priv->folder_type_registry != NULL) + gtk_object_unref (GTK_OBJECT (priv->folder_type_registry)); unload_shortcuts (shortcuts); @@ -307,7 +307,7 @@ init (EShortcuts *shortcuts) void e_shortcuts_construct (EShortcuts *shortcuts, EStorageSet *storage_set, - EFolderTypeRepository *folder_type_repository) + EFolderTypeRegistry *folder_type_registry) { EShortcutsPrivate *priv; @@ -323,13 +323,13 @@ e_shortcuts_construct (EShortcuts *shortcuts, gtk_object_ref (GTK_OBJECT (storage_set)); priv->storage_set = storage_set; - gtk_object_ref (GTK_OBJECT (folder_type_repository)); - priv->folder_type_repository = folder_type_repository; + gtk_object_ref (GTK_OBJECT (folder_type_registry)); + priv->folder_type_registry = folder_type_registry; } EShortcuts * e_shortcuts_new (EStorageSet *storage_set, - EFolderTypeRepository *folder_type_repository) + EFolderTypeRegistry *folder_type_registry) { EShortcuts *new; @@ -337,7 +337,7 @@ e_shortcuts_new (EStorageSet *storage_set, g_return_val_if_fail (E_IS_STORAGE_SET (storage_set), NULL); new = gtk_type_new (e_shortcuts_get_type ()); - e_shortcuts_construct (new, storage_set, folder_type_repository); + e_shortcuts_construct (new, storage_set, folder_type_registry); return new; } diff --git a/shell/e-shortcuts.h b/shell/e-shortcuts.h index bdc9126d68..63c897ece0 100644 --- a/shell/e-shortcuts.h +++ b/shell/e-shortcuts.h @@ -30,7 +30,7 @@ #include <gtk/gtkwidget.h> -#include "e-folder-type-repository.h" +#include "e-folder-type-registry.h" #include "e-storage-set.h" #ifdef __cplusplus @@ -60,29 +60,26 @@ struct _EShortcutsClass { }; -GtkType e_shortcuts_get_type (void); -void e_shortcuts_construct (EShortcuts *shortcuts, - EStorageSet *storage_set, - EFolderTypeRepository *folder_type_repository); -EShortcuts *e_shortcuts_new (EStorageSet *storage_set, - EFolderTypeRepository *folder_type_repository); - -GList *e_shortcuts_get_group_titles (EShortcuts *shortcuts); -GList *e_shortcuts_get_shortcuts_in_group (EShortcuts *shortcuts, - const char *group_title); - -EStorageSet *e_shortcuts_get_storage_set (EShortcuts *shortcuts); - -GtkWidget *e_shortcuts_new_view (EShortcuts *shortcuts); - -gboolean e_shortcuts_load (EShortcuts *shortcuts, - const char *path); -gboolean e_shortcuts_save (EShortcuts *shortcuts, - const char *path); - -const char *e_shortcuts_get_uri (EShortcuts *shortcuts, - int group_num, - int num); +GtkType e_shortcuts_get_type (void); +void e_shortcuts_construct (EShortcuts *shortcuts, + EStorageSet *storage_set, + EFolderTypeRegistry *folder_type_registry); +EShortcuts *e_shortcuts_new (EStorageSet *storage_set, + EFolderTypeRegistry *folder_type_registry); + +GList *e_shortcuts_get_group_titles (EShortcuts *shortcuts); +GList *e_shortcuts_get_shortcuts_in_group (EShortcuts *shortcuts, + const char *group_title); +EStorageSet *e_shortcuts_get_storage_set (EShortcuts *shortcuts); +GtkWidget *e_shortcuts_new_view (EShortcuts *shortcuts); +gboolean e_shortcuts_load (EShortcuts *shortcuts, + const char *path); +gboolean e_shortcuts_save (EShortcuts *shortcuts, + const char *path); + +const char *e_shortcuts_get_uri (EShortcuts *shortcuts, + int group_num, + int num); #ifdef __cplusplus } diff --git a/shell/e-storage-set-view.c b/shell/e-storage-set-view.c index f6c5699e22..7c957c2e9a 100644 --- a/shell/e-storage-set-view.c +++ b/shell/e-storage-set-view.c @@ -408,7 +408,7 @@ get_pixmap_and_mask_for_folder (EStorageSetView *storage_set_view, GdkPixmap **pixmap_return, GdkBitmap **mask_return) { - EFolderTypeRepository *folder_type_repository; + EFolderTypeRegistry *folder_type_registry; EStorageSet *storage_set; const char *type_name; GdkPixbuf *icon_pixbuf; @@ -417,11 +417,17 @@ get_pixmap_and_mask_for_folder (EStorageSetView *storage_set_view, GdkGC *gc; storage_set = storage_set_view->priv->storage_set; - folder_type_repository = e_storage_set_get_folder_type_repository (storage_set); + folder_type_registry = e_storage_set_get_folder_type_registry (storage_set); type_name = e_folder_get_type_string (folder); - icon_pixbuf = e_folder_type_repository_get_icon_for_type (folder_type_repository, - type_name, TRUE); + icon_pixbuf = e_folder_type_registry_get_icon_for_type (folder_type_registry, + type_name, TRUE); + + if (icon_pixbuf == NULL) { + *pixmap_return = NULL; + *mask_return = NULL; + return; + } scaled_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (icon_pixbuf), gdk_pixbuf_get_has_alpha (icon_pixbuf), @@ -555,9 +561,7 @@ e_storage_set_view_construct (EStorageSetView *storage_set_view, /* Set up GtkCTree/GtkCList parameters. */ gtk_ctree_construct (ctree, 1, 0, NULL); -#if 0 gtk_ctree_set_line_style (ctree, GTK_CTREE_LINES_DOTTED); -#endif gtk_clist_set_selection_mode (GTK_CLIST (ctree), GTK_SELECTION_BROWSE); gtk_clist_set_row_height (GTK_CLIST (ctree), E_SHELL_MINI_ICON_SIZE); diff --git a/shell/e-storage-set.c b/shell/e-storage-set.c index 6fcb4c24ba..d1adec19ce 100644 --- a/shell/e-storage-set.c +++ b/shell/e-storage-set.c @@ -52,7 +52,7 @@ static guint signals[LAST_SIGNAL] = { 0 }; struct _EStorageSetPrivate { GList *storages; - EFolderTypeRepository *folder_type_repository; + EFolderTypeRegistry *folder_type_registry; }; @@ -69,7 +69,7 @@ destroy (GtkObject *object) e_free_object_list (priv->storages); - gtk_object_unref (GTK_OBJECT (priv->folder_type_repository)); + gtk_object_unref (GTK_OBJECT (priv->folder_type_registry)); g_free (priv); @@ -116,7 +116,7 @@ init (EStorageSet *storage_set) priv = g_new (EStorageSetPrivate, 1); priv->storages = NULL; - priv->folder_type_repository = NULL; + priv->folder_type_registry = NULL; storage_set->priv = priv; } @@ -124,25 +124,25 @@ init (EStorageSet *storage_set) void e_storage_set_construct (EStorageSet *storage_set, - EFolderTypeRepository *folder_type_repository) + EFolderTypeRegistry *folder_type_registry) { g_return_if_fail (storage_set != NULL); g_return_if_fail (E_IS_STORAGE_SET (storage_set)); GTK_OBJECT_UNSET_FLAGS (storage_set, GTK_FLOATING); - gtk_object_ref (GTK_OBJECT (folder_type_repository)); - storage_set->priv->folder_type_repository = folder_type_repository; + gtk_object_ref (GTK_OBJECT (folder_type_registry)); + storage_set->priv->folder_type_registry = folder_type_registry; } EStorageSet * -e_storage_set_new (EFolderTypeRepository *folder_type_repository) +e_storage_set_new (EFolderTypeRegistry *folder_type_registry) { EStorageSet *new; new = gtk_type_new (e_storage_set_get_type ()); - e_storage_set_construct (new, folder_type_repository); + e_storage_set_construct (new, folder_type_registry); return new; } @@ -287,13 +287,13 @@ e_storage_set_new_view (EStorageSet *storage_set) } -EFolderTypeRepository * -e_storage_set_get_folder_type_repository (EStorageSet *storage_set) +EFolderTypeRegistry * +e_storage_set_get_folder_type_registry (EStorageSet *storage_set) { g_return_val_if_fail (storage_set != NULL, NULL); g_return_val_if_fail (E_IS_STORAGE_SET (storage_set), NULL); - return storage_set->priv->folder_type_repository; + return storage_set->priv->folder_type_registry; } diff --git a/shell/e-storage-set.h b/shell/e-storage-set.h index da4687d642..500f3c31de 100644 --- a/shell/e-storage-set.h +++ b/shell/e-storage-set.h @@ -30,7 +30,7 @@ #include <gtk/gtkwidget.h> -#include "e-folder-type-repository.h" +#include "e-folder-type-registry.h" #include "e-storage.h" #ifdef __cplusplus @@ -71,26 +71,23 @@ struct _EStorageSetClass { GtkType e_storage_set_get_type (void); -void e_storage_set_construct (EStorageSet *storage_set, - EFolderTypeRepository *folder_type_repository); -EStorageSet *e_storage_set_new (EFolderTypeRepository *folder_type_repository); - -GList *e_storage_set_get_storage_list (EStorageSet *storage_set); -EStorage *e_storage_set_get_storage (EStorageSet *storage_set, - const char *name); -void e_storage_set_add_storage (EStorageSet *storage_set, - EStorage *storage); -void e_storage_set_remove_storage (EStorageSet *storage_set, - EStorage *storage); - -EStorage *e_storage_set_get_storage (EStorageSet *storage_set, - const char *storage_name); -EFolder *e_storage_set_get_folder (EStorageSet *storage_set, - const char *path); - -GtkWidget *e_storage_set_new_view (EStorageSet *storage_set); - -EFolderTypeRepository *e_storage_set_get_folder_type_repository (EStorageSet *storage_set); +void e_storage_set_construct (EStorageSet *storage_set, + EFolderTypeRegistry *folder_type_registry); +EStorageSet *e_storage_set_new (EFolderTypeRegistry *folder_type_registry); + +void e_storage_set_add_storage (EStorageSet *storage_set, + EStorage *storage); +void e_storage_set_remove_storage (EStorageSet *storage_set, + EStorage *storage); + +GList *e_storage_set_get_storage_list (EStorageSet *storage_set); +EStorage *e_storage_set_get_storage (EStorageSet *storage_set, + const char *storage_name); +EFolder *e_storage_set_get_folder (EStorageSet *storage_set, + const char *path); +GtkWidget *e_storage_set_new_view (EStorageSet *storage_set); + +EFolderTypeRegistry *e_storage_set_get_folder_type_registry (EStorageSet *storage_set); #ifdef __cplusplus } diff --git a/shell/evolution-shell-component.c b/shell/evolution-shell-component.c new file mode 100644 index 0000000000..9c0861e14a --- /dev/null +++ b/shell/evolution-shell-component.c @@ -0,0 +1,332 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* evolution-shell-component.c + * + * Copyright (C) 2000 Helix Code, Inc. + * + * 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 Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <bonobo.h> + +#include "Evolution.h" + +#include "e-util/e-util.h" + +#include "evolution-shell-component.h" + + +#define PARENT_TYPE BONOBO_OBJECT_TYPE +static BonoboObjectClass *parent_class = NULL; + +struct _EvolutionShellComponentPrivate { + GList *folder_types; /* EvolutionShellComponentFolderType */ + + EvolutionShellComponentCreateViewFn create_view_fn; + Evolution_Shell corba_owner; + void *closure; +}; + +enum { + OWNER_SET, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + + +/* CORBA interface implementation. */ + +static POA_Evolution_ShellComponent__vepv ShellComponent_vepv; + +static POA_Evolution_ShellComponent * +create_servant (void) +{ + POA_Evolution_ShellComponent *servant; + CORBA_Environment ev; + + servant = (POA_Evolution_ShellComponent *) g_new0 (BonoboObjectServant, 1); + servant->vepv = &ShellComponent_vepv; + + CORBA_exception_init (&ev); + + POA_Evolution_ShellComponent__init ((PortableServer_Servant) servant, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_free (servant); + CORBA_exception_free (&ev); + return NULL; + } + + CORBA_exception_free (&ev); + + return servant; +} + +static Evolution_FolderTypeList * +impl_ShellComponent__get_supported_types (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + BonoboObject *bonobo_object; + EvolutionShellComponent *shell_component; + EvolutionShellComponentPrivate *priv; + Evolution_FolderTypeList *folder_type_list; + unsigned int i; + GList *p; + + bonobo_object = bonobo_object_from_servant (servant); + shell_component = EVOLUTION_SHELL_COMPONENT (bonobo_object); + priv = shell_component->priv; + + folder_type_list = Evolution_FolderTypeList__alloc (); + folder_type_list->_length = g_list_length (priv->folder_types); + folder_type_list->_maximum = folder_type_list->_length; + folder_type_list->_buffer = CORBA_sequence_Evolution_FolderType_allocbuf (folder_type_list->_maximum); + + for (p = priv->folder_types, i = 0; p != NULL; p = p->next, i++) { + Evolution_FolderType *corba_folder_type; + EvolutionShellComponentFolderType *folder_type; + + folder_type = (EvolutionShellComponentFolderType *) p->data; + + corba_folder_type = folder_type_list->_buffer + i; + corba_folder_type->name = CORBA_string_dup (folder_type->name); + corba_folder_type->icon_name = CORBA_string_dup (folder_type->icon_name); + } + + return folder_type_list; +} + +static void +impl_ShellComponent_set_owner (PortableServer_Servant servant, + const Evolution_Shell shell, + CORBA_Environment *ev) +{ + BonoboObject *bonobo_object; + EvolutionShellComponent *shell_component; + EvolutionShellComponentPrivate *priv; + + bonobo_object = bonobo_object_from_servant (servant); + shell_component = EVOLUTION_SHELL_COMPONENT (bonobo_object); + priv = shell_component->priv; + + if (priv->corba_owner != CORBA_OBJECT_NIL) { + CORBA_exception_set (ev, CORBA_USER_EXCEPTION, + ex_Evolution_ShellComponent_AlreadyOwned, NULL); + return; + } + + Bonobo_Unknown_ref (shell, ev); + priv->corba_owner = CORBA_Object_duplicate (shell, ev); + + gtk_signal_emit (GTK_OBJECT (shell_component), signals[OWNER_SET], priv->corba_owner); +} + +static Bonobo_Control +impl_ShellComponent_create_view (PortableServer_Servant servant, + const CORBA_char *physical_uri, + CORBA_Environment *ev) +{ + BonoboObject *bonobo_object; + EvolutionShellComponent *shell_component; + EvolutionShellComponentPrivate *priv; + BonoboControl *control; + + bonobo_object = bonobo_object_from_servant (servant); + shell_component = EVOLUTION_SHELL_COMPONENT (bonobo_object); + priv = shell_component->priv; + + control = (* priv->create_view_fn) (shell_component, physical_uri, priv->closure); + + if (control == NULL) { + CORBA_exception_set (ev, CORBA_USER_EXCEPTION, + ex_Evolution_ShellComponent_NotFound, + NULL); + return CORBA_OBJECT_NIL; + } + + return bonobo_object_corba_objref (BONOBO_OBJECT (control)); +} + + +/* GtkObject methods. */ + +static void +destroy (GtkObject *object) +{ + EvolutionShellComponent *shell_component; + EvolutionShellComponentPrivate *priv; + CORBA_Environment ev; + GList *p; + + shell_component = EVOLUTION_SHELL_COMPONENT (object); + + priv = shell_component->priv; + + CORBA_exception_init (&ev); + + if (priv->corba_owner != NULL) { + Bonobo_Unknown_unref (priv->corba_owner, &ev); + CORBA_Object_release (priv->corba_owner, &ev); + } + + CORBA_exception_free (&ev); + + for (p = priv->folder_types; p != NULL; p = p->next) { + EvolutionShellComponentFolderType *folder_type; + + folder_type = (EvolutionShellComponentFolderType *) p->data; + + g_free (folder_type->name); + g_free (folder_type->icon_name); + g_free (folder_type); + } + g_list_free (priv->folder_types); + + g_free (priv); +} + + +/* Initialization. */ + +static void +corba_class_init (void) +{ + POA_Evolution_ShellComponent__vepv *vepv; + POA_Evolution_ShellComponent__epv *epv; + PortableServer_ServantBase__epv *base_epv; + + base_epv = g_new0 (PortableServer_ServantBase__epv, 1); + base_epv->_private = NULL; + base_epv->finalize = NULL; + base_epv->default_POA = NULL; + + epv = g_new0 (POA_Evolution_ShellComponent__epv, 1); + epv->_get_supported_types = impl_ShellComponent__get_supported_types; + epv->set_owner = impl_ShellComponent_set_owner; + epv->create_view = impl_ShellComponent_create_view; + + vepv = &ShellComponent_vepv; + vepv->Bonobo_Unknown_epv = bonobo_object_get_epv (); + vepv->Evolution_ShellComponent_epv = epv; +} + +static void +class_init (EvolutionShellComponentClass *klass) +{ + GtkObjectClass *object_class; + + object_class = GTK_OBJECT_CLASS (klass); + object_class->destroy = destroy; + + signals[OWNER_SET] = gtk_signal_new ("owner_set", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (EvolutionShellComponentClass, owner_set), + gtk_marshal_NONE__POINTER, + GTK_TYPE_NONE, 1, + GTK_TYPE_POINTER); + + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); + + parent_class = gtk_type_class (PARENT_TYPE); + + corba_class_init (); +} + +static void +init (EvolutionShellComponent *shell_component) +{ + EvolutionShellComponentPrivate *priv; + + priv = g_new (EvolutionShellComponentPrivate, 1); + + priv->folder_types = NULL; + priv->create_view_fn = NULL; + priv->closure = NULL; + priv->corba_owner = CORBA_OBJECT_NIL; + + shell_component->priv = priv; +} + + +void +evolution_shell_component_construct (EvolutionShellComponent *shell_component, + const EvolutionShellComponentFolderType folder_types[], + Evolution_ShellComponent corba_object, + EvolutionShellComponentCreateViewFn create_view_fn, + void *closure) +{ + EvolutionShellComponentPrivate *priv; + int i; + + g_return_if_fail (shell_component != NULL); + g_return_if_fail (corba_object != CORBA_OBJECT_NIL); + + bonobo_object_construct (BONOBO_OBJECT (shell_component), corba_object); + + priv = shell_component->priv; + + priv->create_view_fn = create_view_fn; + priv->closure = closure; + + for (i = 0; folder_types[i].name != NULL; i++) { + EvolutionShellComponentFolderType *new; + + if (folder_types[i].icon_name == NULL + || folder_types[i].name[0] == '\0' + || folder_types[i].icon_name[0] == '\0') + continue; + + new = g_new (EvolutionShellComponentFolderType, 1); + new->name = g_strdup (folder_types[i].name); + new->icon_name = g_strdup (folder_types[i].icon_name); + + priv->folder_types = g_list_prepend (priv->folder_types, new); + } + + if (priv->folder_types == NULL) + g_warning ("No valid folder types constructing EShellComponent %p", shell_component); +} + +EvolutionShellComponent * +evolution_shell_component_new (const EvolutionShellComponentFolderType folder_types[], + EvolutionShellComponentCreateViewFn create_view_fn, + void *closure) +{ + EvolutionShellComponent *new; + POA_Evolution_ShellComponent *servant; + Evolution_ShellComponent corba_object; + + servant = create_servant (); + if (servant == NULL) + return NULL; + + new = gtk_type_new (evolution_shell_component_get_type ()); + + corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (new), servant); + evolution_shell_component_construct (new, folder_types, corba_object, create_view_fn, closure); + + return new; +} + + +E_MAKE_TYPE (evolution_shell_component, "EvolutionShellComponent", EvolutionShellComponent, + class_init, init, PARENT_TYPE) diff --git a/shell/evolution-shell-component.h b/shell/evolution-shell-component.h new file mode 100644 index 0000000000..0922124606 --- /dev/null +++ b/shell/evolution-shell-component.h @@ -0,0 +1,91 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* evolution-shell-component.h + * + * Copyright (C) 2000 Helix Code, Inc. + * + * 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 Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifndef __EVOLUTION_SHELL_COMPONENT_H__ +#define __EVOLUTION_SHELL_COMPONENT_H__ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <bonobo/bonobo-object.h> +#include "Evolution.h" + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define EVOLUTION_TYPE_SHELL_COMPONENT (evolution_shell_component_get_type ()) +#define EVOLUTION_SHELL_COMPONENT(obj) (GTK_CHECK_CAST ((obj), EVOLUTION_TYPE_SHELL_COMPONENT, EvolutionShellComponent)) +#define EVOLUTION_SHELL_COMPONENT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), EVOLUTION_TYPE_SHELL_COMPONENT, EvolutionShellComponentClass)) +#define EVOLUTION_IS_SHELL_COMPONENT(obj) (GTK_CHECK_TYPE ((obj), EVOLUTION_TYPE_SHELL_COMPONENT)) +#define EVOLUTION_IS_SHELL_COMPONENT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), EVOLUTION_TYPE_SHELL_COMPONENT)) + + +typedef struct _EvolutionShellComponent EvolutionShellComponent; +typedef struct _EvolutionShellComponentPrivate EvolutionShellComponentPrivate; +typedef struct _EvolutionShellComponentClass EvolutionShellComponentClass; + +typedef BonoboControl * (* EvolutionShellComponentCreateViewFn) (EvolutionShellComponent *shell_component, + const char *physical_uri, + void *closure); + +struct _EvolutionShellComponentFolderType { + char *name; + char *icon_name; +}; +typedef struct _EvolutionShellComponentFolderType EvolutionShellComponentFolderType; + +struct _EvolutionShellComponent { + BonoboObject parent; + + EvolutionShellComponentPrivate *priv; +}; + +struct _EvolutionShellComponentClass { + BonoboObjectClass parent_class; + + /* Signals. */ + + void (* owner_set) (EvolutionShellComponent *shell_component, + Evolution_Shell shell_interface); +}; + + +GtkType evolution_shell_component_get_type (void); +void evolution_shell_component_construct (EvolutionShellComponent *shell_component, + const EvolutionShellComponentFolderType folder_types[], + Evolution_ShellComponent corba_object, + EvolutionShellComponentCreateViewFn create_view_fn, + void *closure); +EvolutionShellComponent *evolution_shell_component_new (const EvolutionShellComponentFolderType folder_types[], + EvolutionShellComponentCreateViewFn create_view_fn, + void *closure); +Evolution_Shell evolution_shell_component_get_shell (EvolutionShellComponent *shell_component); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __EVOLUTION_SHELL_COMPONENT_H__ */ diff --git a/shell/main.c b/shell/main.c index e8885ecfc9..1499a186e5 100644 --- a/shell/main.c +++ b/shell/main.c @@ -33,6 +33,8 @@ #define STARTUP_URI "evolution:/local/Inbox" +static EShell *shell; + static void no_views_left_cb (EShell *shell, gpointer data) @@ -140,11 +142,26 @@ development_warning () } static gint -new_view_idle_cb (gpointer data) +idle_cb (gpointer data) { - EShell *shell; + char *evolution_directory; + + evolution_directory = (char *) data; + + shell = e_shell_new (evolution_directory); + g_free (evolution_directory); + + if (shell == NULL) { + e_notice (NULL, GNOME_MESSAGE_BOX_ERROR, + _("Cannot initialize the Evolution shell.")); + exit (1); + } + + gtk_signal_connect (GTK_OBJECT (shell), "no_views_left", + GTK_SIGNAL_FUNC (no_views_left_cb), NULL); + gtk_signal_connect (GTK_OBJECT (shell), "destroy", + GTK_SIGNAL_FUNC (destroy_cb), NULL); - shell = E_SHELL (data); e_shell_new_view (shell, STARTUP_URI); if (!getenv ("EVOLVE_ME_HARDER")) @@ -157,7 +174,6 @@ new_view_idle_cb (gpointer data) int main (int argc, char **argv) { - EShell *shell; char *evolution_directory; init_corba (&argc, argv); @@ -179,19 +195,7 @@ main (int argc, char **argv) exit (1); } - shell = e_shell_new (evolution_directory); - if (shell == NULL) { - e_notice (NULL, GNOME_MESSAGE_BOX_ERROR, - _("Cannot initialize the Evolution shell.")); - exit (1); - } - - gtk_signal_connect (GTK_OBJECT (shell), "no_views_left", - GTK_SIGNAL_FUNC (no_views_left_cb), NULL); - gtk_signal_connect (GTK_OBJECT (shell), "destroy", - GTK_SIGNAL_FUNC (destroy_cb), NULL); - - gtk_idle_add (new_view_idle_cb, shell); + gtk_idle_add (idle_cb, evolution_directory); bonobo_main (); |