diff options
author | Michael Zucci <zucchi@src.gnome.org> | 2005-05-13 13:19:55 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2005-05-13 13:19:55 +0800 |
commit | aab8b5c8273f6847f4ab33ebc5fa771d6a85832c (patch) | |
tree | ae0d1aa673d12a0993b93e29ce327106cda17702 | |
parent | 68416e0bdd4f24d7d1336df463d6944d5451ecdd (diff) | |
download | gsoc2013-evolution-aab8b5c8273f6847f4ab33ebc5fa771d6a85832c.tar gsoc2013-evolution-aab8b5c8273f6847f4ab33ebc5fa771d6a85832c.tar.gz gsoc2013-evolution-aab8b5c8273f6847f4ab33ebc5fa771d6a85832c.tar.bz2 gsoc2013-evolution-aab8b5c8273f6847f4ab33ebc5fa771d6a85832c.tar.lz gsoc2013-evolution-aab8b5c8273f6847f4ab33ebc5fa771d6a85832c.tar.xz gsoc2013-evolution-aab8b5c8273f6847f4ab33ebc5fa771d6a85832c.tar.zst gsoc2013-evolution-aab8b5c8273f6847f4ab33ebc5fa771d6a85832c.zip |
more api/changes. dosn't build again.
svn path=/trunk/; revision=29346
-rw-r--r-- | plugins/mail-remote/Evolution-DataServer-Mail.idl | 34 | ||||
-rw-r--r-- | plugins/mail-remote/Makefile.am | 4 | ||||
-rw-r--r-- | plugins/mail-remote/e-corba-utils.c | 21 | ||||
-rw-r--r-- | plugins/mail-remote/e-corba-utils.h | 10 | ||||
-rw-r--r-- | plugins/mail-remote/evolution-mail-messageiterator.c | 161 | ||||
-rw-r--r-- | plugins/mail-remote/evolution-mail-messageiterator.h | 47 | ||||
-rw-r--r-- | plugins/mail-remote/evolution-mail-session.c | 32 | ||||
-rw-r--r-- | plugins/mail-remote/evolution-mail-session.h | 2 | ||||
-rw-r--r-- | plugins/mail-remote/evolution-mail-store.c | 64 | ||||
-rw-r--r-- | plugins/mail-remote/evolution-mail-store.h | 3 |
10 files changed, 323 insertions, 55 deletions
diff --git a/plugins/mail-remote/Evolution-DataServer-Mail.idl b/plugins/mail-remote/Evolution-DataServer-Mail.idl index d7a1aa736c..f6c15348ad 100644 --- a/plugins/mail-remote/Evolution-DataServer-Mail.idl +++ b/plugins/mail-remote/Evolution-DataServer-Mail.idl @@ -23,6 +23,9 @@ module Mail { interface Store; typedef sequence<Store> Stores; + interface Session; + + /* ********************************************************************** */ // NB: tiny subset of omg properties service typedef string PropertyName; typedef sequence <PropertyName> PropertyNames; @@ -32,10 +35,26 @@ module Mail { }; typedef sequence <Property> Properties; + /* ********************************************************************** */ + + // ?? + interface Listener { + void storeAdded(in Store store); + void storeRemoved(in Store store); + + void folderAdded(in Store store, in Folder folder); + void folderRemoved(in Store store, in Folder folder); + }; + + /* ********************************************************************** */ + interface Session : Bonobo::Unknown { boolean getProperties(in PropertyNames names, out Properties props); Stores getStores(in string pattern); + + void addListener(in Listener listener); + void removeListener(in Listener listener); }; interface Store : Bonobo::Unknown { @@ -48,23 +67,22 @@ module Mail { raises (NOT_SUPPORTED); }; - struct MessageInfo { + struct Message { string uid; string subject; string to; string from; }; - typedef sequence <MessageInfo> MessageInfos; - -// interface MessageInfoIterator : Bonobo::Unknown { -// MessageInfos next(in long limit); -// }; + typedef sequence <Message> Messages; + interface MessageIterator : Bonobo::Unknown { + Messages next(in long limit); + }; interface Folder : Bonobo::Unknown { - void getProperties(inout Properties pseq); + boolean getProperties(in PropertyNames names, out Properties props); -// MessageInfoIterator getMessageInfo(in string pattern); + MessageIterator getMessages(in string pattern); Bonobo::Stream getMessage(in string uid); diff --git a/plugins/mail-remote/Makefile.am b/plugins/mail-remote/Makefile.am index 6f0601b541..76c8b7b411 100644 --- a/plugins/mail-remote/Makefile.am +++ b/plugins/mail-remote/Makefile.am @@ -11,8 +11,12 @@ plugin_LTLIBRARIES = liborg-gnome-evolution-mail-remote.la liborg_gnome_evolution_mail_remote_la_SOURCES = \ $(IDL_GENERATED_C) \ $(IDL_GENERATED_H) \ + e-corba-utils.c \ + e-corba-utils.h \ evolution-mail-folder.c \ evolution-mail-folder.h \ + evolution-mail-messageiterator.c \ + evolution-mail-messageiterator.h \ evolution-mail-session.c \ evolution-mail-session.h \ evolution-mail-store.c \ diff --git a/plugins/mail-remote/e-corba-utils.c b/plugins/mail-remote/e-corba-utils.c new file mode 100644 index 0000000000..c9f18d0313 --- /dev/null +++ b/plugins/mail-remote/e-corba-utils.c @@ -0,0 +1,21 @@ + +#include "e-corba-utils.h" + +void +e_mail_property_set_string(GNOME_Evolution_Mail_Property *prop, const char *name, const char *val) +{ + prop->value._release = CORBA_TRUE; + prop->value._type = TC_CORBA_string; + prop->value._value = CORBA_sequence_CORBA_string_allocbuf(1); + ((char **)prop->value._value)[0] = CORBA_string_dup(val); + prop->name = CORBA_string_dup(name); +} + +void +e_mail_property_set_null(GNOME_Evolution_Mail_Property *prop, const char *name) +{ + prop->value._release = CORBA_TRUE; + prop->value._type = TC_null; + prop->name = CORBA_string_dup(name); +} + diff --git a/plugins/mail-remote/e-corba-utils.h b/plugins/mail-remote/e-corba-utils.h new file mode 100644 index 0000000000..3e86c49224 --- /dev/null +++ b/plugins/mail-remote/e-corba-utils.h @@ -0,0 +1,10 @@ + +#ifndef _E_CORBA_UTILS_H +#define _E_CORBA_UTILS_H + +#include "Evolution-DataServer-Mail.h" + +void e_mail_property_set_string(GNOME_Evolution_Mail_Property *prop, const char *name, const char *val); +void e_mail_property_set_null(GNOME_Evolution_Mail_Property *prop, const char *name); + +#endif /* !_E_CORBA_UTILS_H */ diff --git a/plugins/mail-remote/evolution-mail-messageiterator.c b/plugins/mail-remote/evolution-mail-messageiterator.c new file mode 100644 index 0000000000..d31c958217 --- /dev/null +++ b/plugins/mail-remote/evolution-mail-messageiterator.c @@ -0,0 +1,161 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* + * Copyright (C) 2005 Novell, Inc. + * + * Authors: Michael Zucchi <notzed@novell.com> + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <errno.h> +#include <string.h> +#include <bonobo/bonobo-i18n.h> +#include <bonobo/bonobo-exception.h> +#include <bonobo/bonobo-arg.h> +#include "evolution-mail-messageiterator.h" + +#include <camel/camel-folder.h> + +#include <libedataserver/e-account.h> + +#define FACTORY_ID "OAFIID:GNOME_Evolution_Mail_MessageIterator_Factory:" BASE_VERSION +#define MAIL_MESSAGEITERATOR_ID "OAFIID:GNOME_Evolution_Mail_MessageIterator:" BASE_VERSION + +#define PARENT_TYPE bonobo_object_get_type () + +static BonoboObjectClass *parent_class = NULL; + +#define _PRIVATE(o) (g_type_instance_get_private ((GTypeInstance *)o, evolution_mail_messageiterator_get_type())) + +struct _EvolutionMailMessageIteratorPrivate { + int index; + CamelFolder *folder; + char *expr; + GPtrArray *search; +}; + +/* GObject methods */ + +static void +impl_dispose (GObject *object) +{ + (* G_OBJECT_CLASS (parent_class)->dispose) (object); +} + +static void +impl_finalize (GObject *object) +{ + struct _EvolutionMailMessageIteratorPrivate *p = _PRIVATE(object); + + if (*p->expr) + camel_folder_search_free(p->folder, p->search); + else + camel_folder_free_uids(p->folder, p->search); + + g_free(p->expr); + camel_object_unref(p->folder); + + (* G_OBJECT_CLASS (parent_class)->finalize) (object); +} + +/* Evolution.Mail.MessageIterator */ +static GNOME_Evolution_Mail_Messages * +impl_next(PortableServer_Servant _servant, const CORBA_long limit, CORBA_Environment * ev) +{ + EvolutionMailMessageIterator *emf = (EvolutionMailMessageIterator *)bonobo_object_from_servant(_servant); + int i, j; + GNOME_Evolution_Mail_Messages *msgs; + struct _EvolutionMailMessageIteratorPrivate *p = _PRIVATE(emf); + CamelException ex = { 0 }; + + if (p->search == NULL) { + if (*p->expr) + p->search = camel_folder_search_by_expression(p->folder, p->expr, &ex); + else + p->search = camel_folder_get_uids(p->folder); + + if (camel_exception_is_set(&ex)) { + camel_exception_clear(&ex); + return NULL; + } + + p->index = 0; + } + + msgs = GNOME_Evolution_Mail_Messages__alloc(); + msgs->_maximum = MIN(limit, p->search->len - p->index); + msgs->_buffer = GNOME_Evolution_Mail_Messages_allocbuf(msgs->_maximum); + CORBA_sequence_set_release(msgs, CORBA_TRUE); + + j=0; + for (i=p->index;i<p->search->len && j<msgs->_maximum;i++) { + CamelMessageInfo *info = camel_folder_get_message_info(p->folder, p->search->pdata[i]); + + if (info) { + msgs->_buffer[j].uid = CORBA_string_dup(camel_message_info_uid(info)); + msgs->_buffer[j].subject = CORBA_string_dup(camel_message_info_subject(info)); + msgs->_buffer[j].to = CORBA_string_dup(camel_message_info_to(info)); + msgs->_buffer[j].from = CORBA_string_dup(camel_message_info_from(info)); + j++; + camel_message_info_free(info); + } + } + + msgs->_length = j; + + return msgs; +} + +/* Initialization */ + +static void +evolution_mail_messageiterator_class_init (EvolutionMailMessageIteratorClass *klass) +{ + POA_GNOME_Evolution_Mail_MessageIterator__epv *epv = &klass->epv; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + epv->next = impl_next; + + object_class->dispose = impl_dispose; + object_class->finalize = impl_finalize; + + g_type_class_add_private(klass, sizeof(struct _EvolutionMailMessageIteratorPrivate)); +} + +static void +evolution_mail_messageiterator_init(EvolutionMailMessageIterator *component, EvolutionMailMessageIteratorClass *klass) +{ +} + +BONOBO_TYPE_FUNC_FULL (EvolutionMailMessageIterator, GNOME_Evolution_Mail_MessageIterator, PARENT_TYPE, evolution_mail_messageiterator) + +EvolutionMailMessageIterator * +evolution_mail_messageiterator_new(CamelFolder *folder, const char *expr) +{ + EvolutionMailMessageIterator *emf = g_object_new(evolution_mail_messageiterator_get_type(), NULL); + struct _EvolutionMailMessageIteratorPrivate *p = _PRIVATE(emf); + + p->folder = folder; + camel_object_ref(folder); + p->expr = g_strdup(expr); + + return emf; +} diff --git a/plugins/mail-remote/evolution-mail-messageiterator.h b/plugins/mail-remote/evolution-mail-messageiterator.h new file mode 100644 index 0000000000..746e96fbe8 --- /dev/null +++ b/plugins/mail-remote/evolution-mail-messageiterator.h @@ -0,0 +1,47 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* + * Copyright (C) 2005 Novell, 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: JP Rosevear <jpr@ximian.com> + */ + +#ifndef _EVOLUTION_MAIL_MESSAGEITERATOR_H_ +#define _EVOLUTION_MAIL_MESSAGEITERATOR_H_ + +#include <bonobo/bonobo-object.h> +#include "Evolution-DataServer-Mail.h" + +struct _CamelFolder; + +typedef struct _EvolutionMailMessageIterator EvolutionMailMessageIterator; +typedef struct _EvolutionMailMessageIteratorClass EvolutionMailMessageIteratorClass; + +struct _EvolutionMailMessageIterator { + BonoboObject parent; +}; + +struct _EvolutionMailMessageIteratorClass { + BonoboObjectClass parent_class; + + POA_GNOME_Evolution_Mail_MessageIterator__epv epv; +}; + +GType evolution_mail_messageiterator_get_type(void); + +EvolutionMailMessageIterator *evolution_mail_messageiterator_new(struct _CamelFolder *folder, const char *expr); + +#endif /* _EVOLUTION_MAIL_MESSAGEITERATOR_H_ */ diff --git a/plugins/mail-remote/evolution-mail-session.c b/plugins/mail-remote/evolution-mail-session.c index 5907f7f2fb..90c989838d 100644 --- a/plugins/mail-remote/evolution-mail-session.c +++ b/plugins/mail-remote/evolution-mail-session.c @@ -35,6 +35,8 @@ #include "evolution-mail-store.h" +#include <camel/camel-session.h> + #define FACTORY_ID "OAFIID:GNOME_Evolution_Mail_Session_Factory:" BASE_VERSION #define MAIL_SESSION_ID "OAFIID:GNOME_Evolution_Mail_Session:" BASE_VERSION @@ -145,11 +147,12 @@ evolution_mail_session_init (EvolutionMailSession *ems, EvolutionMailSessionClas struct _EvolutionMailSessionPrivate *p = _PRIVATE(ems); EIterator *iter; EvolutionMailStore *store; + extern CamelSession *session; /* FIXME: listen to changes */ /* local store first */ - p->stores = g_list_append(p->stores, evolution_mail_store_new(NULL)); + p->stores = g_list_append(p->stores, evolution_mail_store_new(ems, NULL)); p->accounts = e_account_list_new(gconf); iter = e_list_get_iterator((EList *)p->accounts); @@ -157,7 +160,7 @@ evolution_mail_session_init (EvolutionMailSession *ems, EvolutionMailSessionClas EAccount *ea; if ((ea = (EAccount *)e_iterator_get(iter)) - && (store = evolution_mail_store_new((struct _EAccount *)ea))) { + && (store = evolution_mail_store_new(ems, (struct _EAccount *)ea))) { p->stores = g_list_append(p->stores, store); } @@ -166,29 +169,8 @@ evolution_mail_session_init (EvolutionMailSession *ems, EvolutionMailSessionClas g_object_unref(iter); g_object_unref(gconf); -} - -BONOBO_TYPE_FUNC_FULL (EvolutionMailSession, GNOME_Evolution_Mail_Session, PARENT_TYPE, evolution_mail_session) - -#if 0 -static BonoboObject * -factory (BonoboGenericFactory *factory, const char *component_id, void *closure) -{ - if (strcmp(component_id, MAIL_SESSION_ID) == 0) { - static BonoboObject *object; - /* Enfoce singleton instance */ - if (object == NULL) - object = BONOBO_OBJECT (g_object_new (EVOLUTION_MAIL_TYPE_SESSION, NULL)); - - bonobo_object_ref (object); - return object; - } - - g_warning (FACTORY_ID ": Don't know what to do with %s", component_id); - - return NULL; + ems->session = session; } -BONOBO_ACTIVATION_SHLIB_FACTORY (FACTORY_ID, "Evolution Mail Session factory", factory, NULL) -#endif +BONOBO_TYPE_FUNC_FULL (EvolutionMailSession, GNOME_Evolution_Mail_Session, PARENT_TYPE, evolution_mail_session) diff --git a/plugins/mail-remote/evolution-mail-session.h b/plugins/mail-remote/evolution-mail-session.h index 2564ae113d..0681f975ca 100644 --- a/plugins/mail-remote/evolution-mail-session.h +++ b/plugins/mail-remote/evolution-mail-session.h @@ -37,6 +37,8 @@ typedef struct _EvolutionMailSessionClass EvolutionMailSessionClass; struct _EvolutionMailSession { BonoboObject parent; + + struct _CamelSession *session; }; struct _EvolutionMailSessionClass { diff --git a/plugins/mail-remote/evolution-mail-store.c b/plugins/mail-remote/evolution-mail-store.c index c704778370..d287c736bb 100644 --- a/plugins/mail-remote/evolution-mail-store.c +++ b/plugins/mail-remote/evolution-mail-store.c @@ -30,9 +30,16 @@ #include <bonobo/bonobo-i18n.h> #include <bonobo/bonobo-exception.h> #include <bonobo/bonobo-arg.h> + #include "evolution-mail-store.h" +#include "evolution-mail-session.h" + +#include "e-corba-utils.h" + +#include <camel/camel-store.h> +#include <camel/camel-session.h> -#include <libedataserver/e-account.h> +#include <e-util/e-account.h> #define FACTORY_ID "OAFIID:GNOME_Evolution_Mail_Store_Factory:" BASE_VERSION #define MAIL_STORE_ID "OAFIID:GNOME_Evolution_Mail_Store:" BASE_VERSION @@ -45,6 +52,9 @@ static BonoboObjectClass *parent_class = NULL; struct _EvolutionMailStorePrivate { struct _EAccount *account; + + CamelStore *store; + EvolutionMailSession *session; }; /* GObject methods */ @@ -93,8 +103,6 @@ impl_getProperties(PortableServer_Servant _servant, GNOME_Evolution_Mail_Property *prop = &props->_buffer[i]; char *val = NULL; - prop->value._release = CORBA_TRUE; - printf("getting property '%s'\n", name); if (!strcmp(name, "name")) { @@ -103,23 +111,17 @@ impl_getProperties(PortableServer_Servant _servant, else /* FIXME: name & i18n */ val = "Local"; + e_mail_property_set_string(prop, name, val); } else if (!strcmp(name, "uid")) { if (p->account) val = p->account->uid; else val = "local@local"; + e_mail_property_set_string(prop, name, val); } else { - prop->value._type = TC_null; + e_mail_property_set_null(prop, name); ok = CORBA_FALSE; } - - if (val) { - prop->value._type = TC_CORBA_string; - prop->value._value = CORBA_sequence_CORBA_string_allocbuf(1); - ((char **)prop->value._value)[0] = CORBA_string_dup(val); - } - - prop->name = CORBA_string_dup(name); } return ok; @@ -130,17 +132,35 @@ impl_getFolders(PortableServer_Servant _servant, const CORBA_char * pattern, CORBA_Environment * ev) { -#if 0 EvolutionMailStore *ems = (EvolutionMailStore *)bonobo_object_from_servant(_servant); - GNOME_Evolution_Mail_NOT_SUPPORTED *ex; + struct _EvolutionMailStorePrivate *p = _PRIVATE(ems); + CamelFolderInfo *fi; + CamelException ex = { 0 }; + + if (p->store == NULL) { + if (p->account == NULL) { + p->store = mail_component_peek_local_store(NULL); + camel_object_ref(p->store); + } else { + const char *uri; + + uri = e_account_get_string(p->account, E_ACCOUNT_SOURCE_URL); + if (uri && *uri) { + p->store = camel_session_get_store(p->session->session, uri, &ex); + if (camel_exception_is_set(&ex)) { + camel_exception_clear(&ex); + return NULL; + } + } else { + return NULL; + } + } + } - ex = GNOME_Evolution_Mail_NOT_SUPPORTED__alloc(); - ex->why = CORBA_string_dup("Unimplemented"); + fi = camel_store_get_folder_info(p->store, pattern, CAMEL_STORE_FOLDER_INFO_RECURSIVE|CAMEL_STORE_FOLDER_INFO_FAST, &ex); + + /* flatten folders ... */ - ev->_id = ex_GNOME_Evolution_Mail_NOT_SUPPORTED; - ev->_major = CORBA_USER_EXCEPTION; - ev->_any = ex; -#endif return NULL; } @@ -191,7 +211,7 @@ evolution_mail_store_init(EvolutionMailStore *component, EvolutionMailStoreClass BONOBO_TYPE_FUNC_FULL (EvolutionMailStore, GNOME_Evolution_Mail_Store, PARENT_TYPE, evolution_mail_store) EvolutionMailStore * -evolution_mail_store_new(struct _EAccount *ea) +evolution_mail_store_new(struct _EvolutionMailSession *s, struct _EAccount *ea) { EvolutionMailStore *ems = g_object_new (EVOLUTION_MAIL_TYPE_STORE, NULL); struct _EvolutionMailStorePrivate *p = _PRIVATE(ems); @@ -201,6 +221,8 @@ evolution_mail_store_new(struct _EAccount *ea) g_object_ref(ea); } + p->session = s; + return ems; } diff --git a/plugins/mail-remote/evolution-mail-store.h b/plugins/mail-remote/evolution-mail-store.h index c4c78d0c38..fef596e4f7 100644 --- a/plugins/mail-remote/evolution-mail-store.h +++ b/plugins/mail-remote/evolution-mail-store.h @@ -32,6 +32,7 @@ #define EVOLUTION_MAIL_IS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EVOLUTION_MAIL_TYPE_STORE)) struct _EAccount; +struct _EvolutionMailSession; typedef struct _EvolutionMailStore EvolutionMailStore; typedef struct _EvolutionMailStoreClass EvolutionMailStoreClass; @@ -48,6 +49,6 @@ struct _EvolutionMailStoreClass { GType evolution_mail_store_get_type(void); -EvolutionMailStore *evolution_mail_store_new(struct _EAccount *ea); +EvolutionMailStore *evolution_mail_store_new(struct _EvolutionMailSession *s, struct _EAccount *ea); #endif /* _EVOLUTION_MAIL_STORE_H_ */ |