From 912d759d75d9cc7f23f9774d692a44496c2e85fb Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Fri, 6 Oct 2000 08:25:36 +0000 Subject: add camel-nntp-grouplist.h (libcamelnntp_la_SOURCES): add 2000-10-06 Chris Toshok * providers/nntp/Makefile.am (libcamelnntpinclude_HEADERS): add camel-nntp-grouplist.h (libcamelnntp_la_SOURCES): add camel-nntp-grouplist.c * providers/nntp/camel-nntp-provider.c: add our own hash functions for nntp urls. * providers/nntp/camel-nntp-newsrc.c (camel_nntp_newsrc_group_is_subscribed): new function. (camel_nntp_newsrc_subscribe_group): new function. (camel_nntp_newsrc_unsubscribe_group): new function. * providers/nntp/camel-nntp-newsrc.h: add prototypes for _group_is_subscribed, _subscribe_group, and _unsubscribe_group. * providers/nntp/camel-nntp-store.c (build_folder_info_from_grouplist): new function. (nntp_store_get_folder_info): add subscribed_only_parameter. if it's FALSE, load the grouplist and call build_folder_info_from_grouplist. (nntp_store_folder_subscribed): implement. (nntp_store_subscribe_folder): implement. (nntp_store_unsubscribe_folder): implement. (camel_nntp_store_init): add CAMEL_STORE_SUBSCRIPTIONS to the store's flags. * providers/mh/camel-mh-store.c (get_folder_info): add subscribed_only parameter. * providers/mbox/camel-mbox-store.c (get_folder_info): add subscribed_only parameter. * providers/imap/camel-imap-store.c (get_folder_info): add subscribed_only parameter. * camel-store.c (camel_store_supports_subscriptions): new function. (camel_store_folder_subscribed): new function. (camel_store_subscribe_folder): new function. (camel_store_unsubscribe_folder): new function. * camel-store.h: add prototypes and virtual functions for the subscribe implementation. also, add a subscribed_only argument to camel_store_get_folder_info. svn path=/trunk/; revision=5760 --- camel/providers/nntp/camel-nntp-store.c | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'camel/providers/nntp/camel-nntp-store.c') diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c index 52ed2d4966..7f0f09ec27 100644 --- a/camel/providers/nntp/camel-nntp-store.c +++ b/camel/providers/nntp/camel-nntp-store.c @@ -38,6 +38,7 @@ #include "camel-nntp-resp-codes.h" #include "camel-folder-summary.h" #include "camel-nntp-store.h" +#include "camel-nntp-grouplist.h" #include "camel-nntp-folder.h" #include "camel-nntp-auth.h" #include "camel-exception.h" @@ -335,9 +336,40 @@ nntp_store_get_folder (CamelStore *store, const gchar *folder_name, return camel_nntp_folder_new (store, folder_name, ex); } +static CamelFolderInfo * +build_folder_info_from_grouplist (CamelNNTPStore *nntp_store) +{ + CamelURL *url = CAMEL_SERVICE (nntp_store)->url; + CamelFolderInfo *groups = NULL, *last = NULL, *fi; + GList *g; + + for (g = nntp_store->group_list->group_list; g; g = g_list_next (g)) { + CamelNNTPGroupListEntry *entry = g->data; + + fi = g_new0 (CamelFolderInfo, 1); + fi->name = g_strdup (entry->group_name); + fi->full_name = g_strdup (entry->group_name); + fi->url = g_strdup_printf ("nntp://%s%s%s/%s", + url->user ? url->user : "", + url->user ? "@" : "", + url->host, (char *)entry->group_name); + /* FIXME */ + fi->message_count = fi->unread_message_count = -1; + + if (last) + last->sibling = fi; + else + groups = fi; + last = fi; + } + + return groups; +} + static CamelFolderInfo * nntp_store_get_folder_info (CamelStore *store, const char *top, gboolean fast, gboolean recursive, + gboolean subscribed_only, CamelException *ex) { CamelURL *url = CAMEL_SERVICE (store)->url; @@ -359,6 +391,19 @@ nntp_store_get_folder_info (CamelStore *store, const char *top, return NULL; } + if (top == NULL && !subscribed_only) { + if (!nntp_store->group_list) + nntp_store->group_list = camel_nntp_grouplist_fetch (nntp_store, ex); + if (camel_exception_is_set (ex)) { + return NULL; + } + else { + fi = build_folder_info_from_grouplist (nntp_store); + return fi; + } + + } + if (top == NULL) { /* return the list of groups */ names = camel_nntp_newsrc_get_subscribed_group_names (nntp_store->newsrc); @@ -403,6 +448,32 @@ nntp_store_get_root_folder_name (CamelStore *store, CamelException *ex) return g_strdup (""); } +static gboolean +nntp_store_folder_subscribed (CamelStore *store, const char *folder_name) +{ + CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (store); + + return camel_nntp_newsrc_group_is_subscribed (nntp_store->newsrc, folder_name); +} + +static void +nntp_store_subscribe_folder (CamelStore *store, const char *folder_name, + CamelException *ex) +{ + CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (store); + + camel_nntp_newsrc_subscribe_group (nntp_store->newsrc, folder_name); +} + +static void +nntp_store_unsubscribe_folder (CamelStore *store, const char *folder_name, + CamelException *ex) +{ + CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (store); + + camel_nntp_newsrc_unsubscribe_group (nntp_store->newsrc, folder_name); +} + static void finalize (CamelObject *object) { @@ -437,6 +508,10 @@ camel_nntp_store_class_init (CamelNNTPStoreClass *camel_nntp_store_class) camel_store_class->get_root_folder_name = nntp_store_get_root_folder_name; camel_store_class->get_folder_info = nntp_store_get_folder_info; camel_store_class->free_folder_info = camel_store_free_folder_info_full; + + camel_store_class->folder_subscribed = nntp_store_folder_subscribed; + camel_store_class->subscribe_folder = nntp_store_subscribe_folder; + camel_store_class->unsubscribe_folder = nntp_store_unsubscribe_folder; } @@ -446,12 +521,15 @@ camel_nntp_store_init (gpointer object, gpointer klass) { CamelService *service = CAMEL_SERVICE (object); CamelRemoteStore *remote_store = CAMEL_REMOTE_STORE (object); + CamelStore *store = CAMEL_STORE (object); service->url_flags = (CAMEL_SERVICE_URL_NEED_HOST | CAMEL_SERVICE_URL_ALLOW_USER | CAMEL_SERVICE_URL_ALLOW_PASSWORD | CAMEL_SERVICE_URL_ALLOW_AUTH); remote_store->default_port = NNTP_PORT; + + store->flags = CAMEL_STORE_SUBSCRIPTIONS; } CamelType -- cgit v1.2.3