diff options
-rw-r--r-- | mail/Makefile.am | 2 | ||||
-rw-r--r-- | mail/component-factory.c | 3 | ||||
-rw-r--r-- | mail/mail-local-storage.c | 188 | ||||
-rw-r--r-- | mail/mail-local-storage.h | 34 |
4 files changed, 227 insertions, 0 deletions
diff --git a/mail/Makefile.am b/mail/Makefile.am index db70087f38..7c2d0f19c5 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -56,6 +56,8 @@ evolution_mail_SOURCES = \ mail-identify.c \ mail-local.c \ mail-local.h \ + mail-local-storage.c \ + mail-local-storage.h \ mail-ops.c \ mail-ops.h \ mail-threads.c \ diff --git a/mail/component-factory.c b/mail/component-factory.c index c874cdeec9..00879c93ce 100644 --- a/mail/component-factory.c +++ b/mail/component-factory.c @@ -111,6 +111,7 @@ owner_set_cb (EvolutionShellComponent *shell_component, { GSList *sources; Evolution_Shell corba_shell; + Evolution_LocalStorage corba_local_storage; g_print ("evolution-mail: Yeeeh! We have an owner!\n"); /* FIXME */ @@ -132,6 +133,8 @@ owner_set_cb (EvolutionShellComponent *shell_component, mail_load_storages (corba_shell, sources); sources = mail_config_get_news (); mail_load_storages (corba_shell, sources); + + mail_local_storage_startup (shell_client); } static void diff --git a/mail/mail-local-storage.c b/mail/mail-local-storage.c new file mode 100644 index 0000000000..90bd32a081 --- /dev/null +++ b/mail/mail-local-storage.c @@ -0,0 +1,188 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* mail-local-storage.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 + */ + +/* This handles the interfacing with the shell's local storage. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib.h> +#include <gtk/gtk.h> +#include <orb/orbit.h> + +#include "e-folder-tree.h" +#include "evolution-storage-listener.h" + +#include "mail-local-storage.h" + + +/* Static stuff. Sigh, it sucks, but it fits in the way the whole mail + compnent is written. */ + +/* The interface to the local storage. */ +static Evolution_LocalStorage corba_local_storage = CORBA_OBJECT_NIL; + +/* The listener on our side. We get notified of things happening in the local + storage through this. */ +static EvolutionStorageListener *local_storage_listener = NULL; + +/* The folder set. The folder data is an Evolution_Folder, allocated through + CORBA normally. */ +static EFolderTree *folder_tree = NULL; + + +/* Folder destroy notification function for the `folder_tree'. */ + +static void +folder_tree_folder_notify_cb (EFolderTree *tree, + const char *path, + void *data, + void *closure) +{ + Evolution_Folder *corba_folder; + + corba_folder = (Evolution_Folder *) data; + CORBA_free (corba_folder); +} + + +/* Callbacks for the EvolutionStorageListner signals. */ + +static void +local_storage_destroyed_cb (EvolutionStorageListener *storage_listener, + void *data) +{ + /* FIXME: Dunno how to handle this yet. */ + g_warning ("%s -- The LocalStorage has gone?!", __FILE__); +} + +static void +local_storage_new_folder_cb (EvolutionStorageListener *storage_listener, + const char *path, + const Evolution_Folder *folder, + void *data) +{ + Evolution_Folder *copy_of_folder; + CORBA_Environment ev; + + if (strcmp (folder->type, "mail") != 0) + return; + + CORBA_exception_init (&ev); + +#if 0 + /* This is how we could do to display extra information about the + folder. */ + display_name = g_strconcat (folder->display_name, _(" (XXX unread)"), NULL); + Evolution_LocalStorage_set_display_name (corba_local_storage, path, display_name, &ev); +#endif + + copy_of_folder = Evolution_Folder__alloc (); + copy_of_folder->type = CORBA_string_dup (folder->type); + copy_of_folder->description = CORBA_string_dup (folder->description); + copy_of_folder->display_name = CORBA_string_dup (folder->display_name); + copy_of_folder->physical_uri = CORBA_string_dup (folder->physical_uri); + + e_folder_tree_add (folder_tree, path, copy_of_folder); + + CORBA_exception_free (&ev); +} + +static void +local_storage_removed_folder_cb (EvolutionStorageListener *storage_listener, + const char *path, + void *data) +{ + /* Prevent a warning from `e_folder_tree_remove()'. */ + if (e_folder_tree_get_folder (folder_tree, path) == NULL) + return; + + e_folder_tree_remove (folder_tree, path); +} + + +gboolean +mail_local_storage_startup (EvolutionShellClient *shell_client) +{ + Evolution_StorageListener corba_local_storage_listener; + + CORBA_Environment ev; + + CORBA_exception_init (&ev); + + corba_local_storage = evolution_shell_client_get_local_storage (shell_client); + if (corba_local_storage == CORBA_OBJECT_NIL) { + CORBA_exception_free (&ev); + return FALSE; + } + + local_storage_listener = evolution_storage_listener_new (); + corba_local_storage_listener = evolution_storage_listener_corba_objref (local_storage_listener); + + gtk_signal_connect (GTK_OBJECT (local_storage_listener), "destroyed", + GTK_SIGNAL_FUNC (local_storage_destroyed_cb), NULL); + gtk_signal_connect (GTK_OBJECT (local_storage_listener), "new_folder", + GTK_SIGNAL_FUNC (local_storage_new_folder_cb), NULL); + gtk_signal_connect (GTK_OBJECT (local_storage_listener), "removed_folder", + GTK_SIGNAL_FUNC (local_storage_removed_folder_cb), NULL); + + Evolution_Storage_add_listener (corba_local_storage, corba_local_storage_listener, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("%s -- Cannot add a listener to the Local Storage.", __FILE__); + + gtk_object_unref (GTK_OBJECT (local_storage_listener)); + + Bonobo_Unknown_unref (corba_local_storage, &ev); + CORBA_Object_release (corba_local_storage, &ev); + + CORBA_exception_free (&ev); + return FALSE; + } + + CORBA_exception_free (&ev); + + folder_tree = e_folder_tree_new (folder_tree_folder_notify_cb, NULL); + + return TRUE; +} + +void +mail_local_storage_shutdown (void) +{ + CORBA_Environment ev; + + CORBA_exception_init (&ev); + + Bonobo_Unknown_unref (corba_local_storage, &ev); + CORBA_Object_release (corba_local_storage, &ev); + corba_local_storage = CORBA_OBJECT_NIL; + + gtk_object_unref (GTK_OBJECT (local_storage_listener)); + local_storage_listener = NULL; + + gtk_object_unref (GTK_OBJECT (folder_tree)); + folder_tree = NULL; + + CORBA_exception_free (&ev); +} diff --git a/mail/mail-local-storage.h b/mail/mail-local-storage.h new file mode 100644 index 0000000000..251897681c --- /dev/null +++ b/mail/mail-local-storage.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* mail-local-storage.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 _MAIL_LOCAL_STORAGE_H_ +#define _MAIL_LOCAL_STORAGE_H_ + +#include <glib.h> + +#include "evolution-shell-client.h" + +gboolean mail_local_storage_startup (EvolutionShellClient *shell_client); +void mail_local_storage_shutdown (void); + +#endif |