diff --git a/ChangeLog b/ChangeLog index 41234139a..cf40d5ec9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2012-01-26 Wolfgang Sourdeau + + * OpenChange/MAPIStoreSOGo.m (sogo_backend_list_contexts): new + backend method. + + * OpenChange/MAPIStoreContext.m + (+listAllContextsForUser:inMemCtx:): centralized method for + returning all contexts available from all context classes for one + user. + (+listContextsForUser:inMemCtx:): new individual method invoked by + the above. Overridden by concrete subclasses. + 2012-01-26 Ludovic Marcotte * SoObjects/SOGo/LDAPSource.{h,m} - now honor diff --git a/OpenChange/MAPIStoreCalendarContext.m b/OpenChange/MAPIStoreCalendarContext.m index b3cbb2899..8f05ceb17 100644 --- a/OpenChange/MAPIStoreCalendarContext.m +++ b/OpenChange/MAPIStoreCalendarContext.m @@ -27,6 +27,9 @@ #import "MAPIStoreCalendarContext.h" +#undef DEBUG +#include + @implementation MAPIStoreCalendarContext + (NSString *) MAPIModuleName @@ -34,6 +37,23 @@ return @"calendar"; } ++ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName + inMemCtx: (TALLOC_CTX *) memCtx +{ + struct mapistore_contexts_list *context; + + context = talloc_zero(memCtx, struct mapistore_contexts_list); + context->url = talloc_asprintf (context, "sogo://%s@calendar/", + [userName UTF8String]); + // context->name = "Agenda personnel"; + context->main_folder = true; + context->role = MAPISTORE_CALENDAR_ROLE; + context->tag = "tag"; + context->prev = context; + + return context; +} + - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreCalendarFolder baseFolderWithURL: newURL diff --git a/OpenChange/MAPIStoreContactsContext.m b/OpenChange/MAPIStoreContactsContext.m index 4a266ac30..34b6257e8 100644 --- a/OpenChange/MAPIStoreContactsContext.m +++ b/OpenChange/MAPIStoreContactsContext.m @@ -27,6 +27,9 @@ #import "MAPIStoreContactsContext.h" +#undef DEBUG +#include + @implementation MAPIStoreContactsContext + (NSString *) MAPIModuleName @@ -34,6 +37,23 @@ return @"contacts"; } ++ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName + inMemCtx: (TALLOC_CTX *) memCtx +{ + struct mapistore_contexts_list *context; + + context = talloc_zero(memCtx, struct mapistore_contexts_list); + context->url = talloc_asprintf (context, "sogo://%s@contacts/", + [userName UTF8String]); + // context->name = "Carnet d'adresses personnel"; + context->main_folder = true; + context->role = MAPISTORE_CONTACTS_ROLE; + context->tag = "tag"; + context->prev = context; + + return context; +} + - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreContactsFolder baseFolderWithURL: newURL diff --git a/OpenChange/MAPIStoreContext.h b/OpenChange/MAPIStoreContext.h index 09774238d..88c902e42 100644 --- a/OpenChange/MAPIStoreContext.h +++ b/OpenChange/MAPIStoreContext.h @@ -69,6 +69,11 @@ MAPIStoreFolder *baseFolder; } ++ (struct mapistore_contexts_list *) listAllContextsForUser: (NSString *) userName + inMemCtx: (TALLOC_CTX *) memCtx; ++ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName + inMemCtx: (TALLOC_CTX *) memCtx; + + (int) openContext: (MAPIStoreContext **) contextPtr withURI: (const char *) newUri connectionInfo: (struct mapistore_connection_info *) newConnInfo diff --git a/OpenChange/MAPIStoreContext.m b/OpenChange/MAPIStoreContext.m index 07ac7116a..9b6a40b46 100644 --- a/OpenChange/MAPIStoreContext.m +++ b/OpenChange/MAPIStoreContext.m @@ -101,6 +101,40 @@ static NSMutableDictionary *contextClassMapping; } } + ++ (struct mapistore_contexts_list *) listAllContextsForUser: (NSString *) userName + inMemCtx: (TALLOC_CTX *) memCtx +{ + struct mapistore_contexts_list *list, *current; + NSArray *classes; + Class currentClass; + NSUInteger count, max; + + list = NULL; + + classes = GSObjCAllSubclassesOfClass (self); + max = [classes count]; + for (count = 0; count < max; count++) + { + currentClass = [classes objectAtIndex: count]; + current = [currentClass listContextsForUser: userName + inMemCtx: memCtx]; + if (current) + { + [self logWithFormat: @"adding list: %p", current]; + DLIST_CONCATENATE(list, current, void); + } + } + + return list; +} + ++ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName + inMemCtx: (TALLOC_CTX *) memCtx +{ + return NULL; +} + static inline enum mapistore_error _prepareContextClass (Class contextClass, struct mapistore_connection_info *connInfo, diff --git a/OpenChange/MAPIStoreMailContext.m b/OpenChange/MAPIStoreMailContext.m index 0ca511936..f4885f10b 100644 --- a/OpenChange/MAPIStoreMailContext.m +++ b/OpenChange/MAPIStoreMailContext.m @@ -24,9 +24,13 @@ #import "MAPIStoreMailFolder.h" #import "MAPIStoreMapping.h" +#import "NSString+MAPIStore.h" #import "MAPIStoreMailContext.h" +#undef DEBUG +#include + @implementation MAPIStoreMailContext + (NSString *) MAPIModuleName @@ -34,6 +38,11 @@ return nil; } ++ (enum mapistore_context_role) contextRole +{ + return MAPISTORE_MAIL_ROLE; +} + @end @implementation MAPIStoreInboxContext @@ -43,6 +52,24 @@ return @"inbox"; } ++ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName + inMemCtx: (TALLOC_CTX *) memCtx +{ + struct mapistore_contexts_list *context; + NSString *url; + + context = talloc_zero(memCtx, struct mapistore_contexts_list); + url = [NSString stringWithFormat: @"sogo://%@:%@@%@/", userName, userName, [self MAPIModuleName]]; + context->url = [url asUnicodeInMemCtx: context]; + // context->name = "Inbox"; + context->main_folder = true; + context->role = [self contextRole]; + context->tag = "tag"; + context->prev = context; + + return context; +} + - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreInboxFolder baseFolderWithURL: newURL @@ -59,6 +86,11 @@ return @"sent-items"; } ++ (enum mapistore_context_role) contextRole +{ + return MAPISTORE_SENTITEMS_ROLE; +} + - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreSentItemsFolder baseFolderWithURL: newURL @@ -75,6 +107,11 @@ return @"drafts"; } ++ (enum mapistore_context_role) contextRole +{ + return MAPISTORE_DRAFTS_ROLE; +} + - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreDraftsFolder baseFolderWithURL: newURL @@ -93,6 +130,11 @@ return @"deleted-items"; } ++ (enum mapistore_context_role) contextRole +{ + return MAPISTORE_DELETEDITEMS_ROLE; +} + - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreFSFolder baseFolderWithURL: newURL inContext: self]; @@ -115,6 +157,11 @@ return @"outbox"; } ++ (enum mapistore_context_role) contextRole +{ + return MAPISTORE_OUTBOX_ROLE; +} + - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreOutboxFolder baseFolderWithURL: newURL diff --git a/OpenChange/MAPIStoreNotesContext.m b/OpenChange/MAPIStoreNotesContext.m index 7171f7da0..b6ca62bc3 100644 --- a/OpenChange/MAPIStoreNotesContext.m +++ b/OpenChange/MAPIStoreNotesContext.m @@ -27,6 +27,9 @@ #import "MAPIStoreNotesContext.h" +#undef DEBUG +#include + @implementation MAPIStoreNotesContext + (NSString *) MAPIModuleName @@ -34,6 +37,23 @@ return @"notes"; } ++ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName + inMemCtx: (TALLOC_CTX *) memCtx +{ + struct mapistore_contexts_list *context; + + context = talloc_zero(memCtx, struct mapistore_contexts_list); + context->url = talloc_asprintf (context, "sogo://%s@notes/", + [userName UTF8String]); + // context->name = "Notes personnelles"; + context->main_folder = true; + context->role = MAPISTORE_NOTES_ROLE; + context->tag = "tag"; + context->prev = context; + + return context; +} + - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreNotesFolder baseFolderWithURL: newURL diff --git a/OpenChange/MAPIStoreSOGo.m b/OpenChange/MAPIStoreSOGo.m index 527da32ec..7f6878f96 100644 --- a/OpenChange/MAPIStoreSOGo.m +++ b/OpenChange/MAPIStoreSOGo.m @@ -46,6 +46,8 @@ #include #include +static Class MAPIStoreContextK = Nil; + static enum mapistore_error sogo_backend_unexpected_error() { @@ -81,7 +83,7 @@ sogo_backend_init (void) [SOGoSystemDefaults sharedSystemDefaults]; - // /* We force the plugin to base its configuration on the SOGo tree. */ + /* We force the plugin to base its configuration on the SOGo tree. */ ud = [NSUserDefaults standardUserDefaults]; [ud registerDefaults: [ud persistentDomainForName: @"sogod"]]; @@ -98,6 +100,8 @@ sogo_backend_init (void) [[SOGoCache sharedCache] disableRequestsCache]; [[SOGoCache sharedCache] disableLocalCache]; + MAPIStoreContextK = NSClassFromString (@"MAPIStoreContext"); + [pool release]; return MAPISTORE_SUCCESS; @@ -118,7 +122,6 @@ sogo_backend_create_context(TALLOC_CTX *mem_ctx, const char *uri, void **context_object) { NSAutoreleasePool *pool; - Class MAPIStoreContextK; MAPIStoreContext *context; int rc; @@ -126,7 +129,6 @@ sogo_backend_create_context(TALLOC_CTX *mem_ctx, pool = [NSAutoreleasePool new]; - MAPIStoreContextK = NSClassFromString (@"MAPIStoreContext"); if (MAPIStoreContextK) { rc = [MAPIStoreContextK openContext: &context @@ -144,6 +146,33 @@ sogo_backend_create_context(TALLOC_CTX *mem_ctx, return rc; } +static enum mapistore_error +sogo_backend_list_contexts(const char *username, TALLOC_CTX *mem_ctx, + struct mapistore_contexts_list **contexts_listp) +{ + NSAutoreleasePool *pool; + NSString *userName; + int rc; + + DEBUG(0, ("[SOGo: %s:%d]\n", __FUNCTION__, __LINE__)); + + pool = [NSAutoreleasePool new]; + + if (MAPIStoreContextK) + { + userName = [NSString stringWithUTF8String: username]; + *contexts_listp = [MAPIStoreContextK listAllContextsForUser: userName + inMemCtx: mem_ctx]; + rc = MAPISTORE_SUCCESS; + } + else + rc = MAPISTORE_ERROR; + + [pool release]; + + return rc; +} + // andFID: fid // uint64_t fid, // void **private_data) @@ -1207,6 +1236,7 @@ int mapistore_init_backend(void) backend.backend.namespace = "sogo://"; backend.backend.init = sogo_backend_init; backend.backend.create_context = sogo_backend_create_context; + backend.backend.list_contexts = sogo_backend_list_contexts; backend.context.get_path = sogo_context_get_path; backend.context.get_root_folder = sogo_context_get_root_folder; backend.folder.open_folder = sogo_folder_open_folder; diff --git a/OpenChange/MAPIStoreTasksContext.m b/OpenChange/MAPIStoreTasksContext.m index 1d71c56da..644176aa3 100644 --- a/OpenChange/MAPIStoreTasksContext.m +++ b/OpenChange/MAPIStoreTasksContext.m @@ -27,6 +27,9 @@ #import "MAPIStoreTasksContext.h" +#undef DEBUG +#include + @implementation MAPIStoreTasksContext + (NSString *) MAPIModuleName @@ -34,6 +37,23 @@ return @"tasks"; } ++ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName + inMemCtx: (TALLOC_CTX *) memCtx +{ + struct mapistore_contexts_list *context; + + context = talloc_zero(memCtx, struct mapistore_contexts_list); + context->url = talloc_asprintf (context, "sogo://%s@tasks/", + [userName UTF8String]); + // context->name = "Tâches personnelles"; + context->main_folder = true; + context->role = MAPISTORE_TASKS_ROLE; + context->tag = "tag"; + context->prev = context; + + return context; +} + - (void) setupBaseFolder: (NSURL *) newURL { baseFolder = [MAPIStoreTasksFolder baseFolderWithURL: newURL