[evolution-data-server] NNTP: Move from 'disco' to 'offline' base classes.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] NNTP: Move from 'disco' to 'offline' base classes.
- Date: Wed, 13 Nov 2013 23:30:03 +0000 (UTC)
commit 31dba17557e0c3fb17c0333a380ba26ff1271f63
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Nov 13 17:34:02 2013 -0500
NNTP: Move from 'disco' to 'offline' base classes.
NNTP was the last user of the old unmaintained 'CamelDisco' classes.
camel/providers/nntp/camel-nntp-folder.c | 467 +++++++++++++----------------
camel/providers/nntp/camel-nntp-folder.h | 5 +-
camel/providers/nntp/camel-nntp-store.c | 259 ++++++-----------
camel/providers/nntp/camel-nntp-store.h | 4 +-
4 files changed, 296 insertions(+), 439 deletions(-)
---
diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c
index 9981a5d..9a42a12 100644
--- a/camel/providers/nntp/camel-nntp-folder.c
+++ b/camel/providers/nntp/camel-nntp-folder.c
@@ -37,6 +37,10 @@
#include "camel-nntp-store.h"
#include "camel-nntp-summary.h"
+#define CAMEL_NNTP_FOLDER_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), CAMEL_TYPE_NNTP_FOLDER, CamelNNTPFolderPrivate))
+
/* The custom property ID is a CamelArg artifact.
* It still identifies the property in state files. */
enum {
@@ -44,11 +48,10 @@ enum {
PROP_APPLY_FILTERS = 0x2501
};
-#define CAMEL_NNTP_FOLDER_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE \
- ((obj), CAMEL_TYPE_NNTP_FOLDER, CamelNNTPFolderPrivate))
-
-G_DEFINE_TYPE (CamelNNTPFolder, camel_nntp_folder, CAMEL_TYPE_DISCO_FOLDER)
+G_DEFINE_TYPE (
+ CamelNNTPFolder,
+ camel_nntp_folder,
+ CAMEL_TYPE_OFFLINE_FOLDER)
static gboolean
nntp_folder_get_apply_filters (CamelNNTPFolder *folder)
@@ -177,41 +180,6 @@ camel_nntp_folder_selected (CamelNNTPFolder *nntp_folder,
return res;
}
-static gboolean
-nntp_folder_refresh_info_online (CamelFolder *folder,
- GCancellable *cancellable,
- GError **error)
-{
- CamelStore *parent_store;
- CamelNNTPStore *nntp_store;
- CamelFolderChangeInfo *changes = NULL;
- CamelNNTPFolder *nntp_folder;
- gchar *line;
- gboolean success;
-
- parent_store = camel_folder_get_parent_store (folder);
-
- nntp_folder = CAMEL_NNTP_FOLDER (folder);
- nntp_store = CAMEL_NNTP_STORE (parent_store);
-
- /* When invoked with no fmt, camel_nntp_command() just selects the folder
- * and should return zero. */
- success = !camel_nntp_command (
- nntp_store, cancellable, error, nntp_folder, &line, NULL);
-
- if (camel_folder_change_info_changed (nntp_folder->changes)) {
- changes = nntp_folder->changes;
- nntp_folder->changes = camel_folder_change_info_new ();
- }
-
- if (changes) {
- camel_folder_changed (folder, changes);
- camel_folder_change_info_free (changes);
- }
-
- return success;
-}
-
static void
unset_flagged_flag (const gchar *uid,
CamelFolderSummary *summary)
@@ -231,37 +199,6 @@ unset_flagged_flag (const gchar *uid,
}
}
-static gboolean
-nntp_folder_sync (CamelFolder *folder,
- GError **error)
-{
- GPtrArray *changed;
-
- changed = camel_folder_summary_get_changed (folder->summary);
- if (changed) {
- g_ptr_array_foreach (changed, (GFunc) unset_flagged_flag, folder->summary);
- g_ptr_array_foreach (changed, (GFunc) camel_pstring_free, NULL);
- g_ptr_array_free (changed, TRUE);
- camel_folder_summary_touch (folder->summary);
- }
-
- return camel_folder_summary_save_to_db (folder->summary, error);
-}
-
-static gboolean
-nntp_folder_sync_online (CamelFolder *folder,
- GError **error)
-{
- return nntp_folder_sync (folder, error);
-}
-
-static gboolean
-nntp_folder_sync_offline (CamelFolder *folder,
- GError **error)
-{
- return nntp_folder_sync (folder, error);
-}
-
static gchar *
nntp_get_filename (CamelFolder *folder,
const gchar *uid,
@@ -376,39 +313,6 @@ exit:
return stream;
}
-static gboolean
-nntp_folder_cache_message (CamelDiscoFolder *disco_folder,
- const gchar *uid,
- GCancellable *cancellable,
- GError **error)
-{
- CamelStream *stream;
- gchar *article, *msgid;
- gsize article_len;
- gboolean success = TRUE;
-
- article_len = strlen (uid) + 1;
- article = alloca (article_len);
- g_strlcpy (article, uid, article_len);
- msgid = strchr (article, ',');
- if (!msgid) {
- g_set_error (
- error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
- _("Internal error: UID in invalid format: %s"), uid);
- return FALSE;
- }
- *msgid++ = 0;
-
- stream = nntp_folder_download_message (
- (CamelNNTPFolder *) disco_folder, article, msgid, cancellable, error);
- if (stream)
- g_object_unref (stream);
- else
- success = FALSE;
-
- return success;
-}
-
static GPtrArray *
nntp_folder_search_by_expression (CamelFolder *folder,
const gchar *expression,
@@ -490,93 +394,13 @@ nntp_folder_search_free (CamelFolder *folder,
CAMEL_NNTP_FOLDER_UNLOCK (nntp_folder, search_lock);
}
-static CamelMimeMessage *
-nntp_folder_get_message_sync (CamelFolder *folder,
- const gchar *uid,
- GCancellable *cancellable,
- GError **error)
-{
- CamelStore *parent_store;
- CamelMimeMessage *message = NULL;
- CamelDataCache *nntp_cache;
- CamelNNTPStore *nntp_store;
- CamelFolderChangeInfo *changes;
- CamelNNTPFolder *nntp_folder;
- CamelStream *stream = NULL;
- GIOStream *base_stream;
- gchar *article, *msgid;
- gsize article_len;
-
- parent_store = camel_folder_get_parent_store (folder);
-
- nntp_folder = CAMEL_NNTP_FOLDER (folder);
- nntp_store = CAMEL_NNTP_STORE (parent_store);
-
- article_len = strlen (uid) + 1;
- article = alloca (article_len);
- g_strlcpy (article, uid, article_len);
- msgid = strchr (article, ',');
- if (msgid == NULL) {
- g_set_error (
- error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
- _("Internal error: UID in invalid format: %s"), uid);
- return NULL;
- }
- *msgid++ = 0;
-
- /* Lookup in cache, NEWS is global messageid's so use a global cache path */
- nntp_cache = camel_nntp_store_ref_cache (nntp_store);
- base_stream = camel_data_cache_get (nntp_cache, "cache", msgid, NULL);
- g_clear_object (&nntp_cache);
-
- if (base_stream != NULL) {
- stream = camel_stream_new (base_stream);
- g_object_unref (base_stream);
- } else {
- if (camel_disco_store_status ((CamelDiscoStore *) nntp_store) == CAMEL_DISCO_STORE_OFFLINE) {
- g_set_error (
- error, CAMEL_SERVICE_ERROR,
- CAMEL_SERVICE_ERROR_UNAVAILABLE,
- _("This message is not currently available"));
- goto fail;
- }
-
- stream = nntp_folder_download_message (nntp_folder, article, msgid, cancellable, error);
- if (stream == NULL)
- goto fail;
- }
-
- message = camel_mime_message_new ();
- if (!camel_data_wrapper_construct_from_stream_sync ((CamelDataWrapper *) message, stream,
cancellable, error)) {
- g_prefix_error (error, _("Cannot get message %s: "), uid);
- g_object_unref (message);
- message = NULL;
- }
-
- g_object_unref (stream);
-fail:
- if (camel_folder_change_info_changed (nntp_folder->changes)) {
- changes = nntp_folder->changes;
- nntp_folder->changes = camel_folder_change_info_new ();
- } else {
- changes = NULL;
- }
-
- if (changes) {
- camel_folder_changed (folder, changes);
- camel_folder_change_info_free (changes);
- }
-
- return message;
-}
-
static gboolean
-nntp_folder_append_message_online (CamelFolder *folder,
- CamelMimeMessage *mime_message,
- const CamelMessageInfo *info,
- gchar **appended_uid,
- GCancellable *cancellable,
- GError **error)
+nntp_folder_append_message_sync (CamelFolder *folder,
+ CamelMimeMessage *message,
+ CamelMessageInfo *info,
+ gchar **appended_uid,
+ GCancellable *cancellable,
+ GError **error)
{
CamelStore *parent_store;
CamelNNTPStore *nntp_store;
@@ -633,7 +457,7 @@ nntp_folder_append_message_online (CamelFolder *folder,
savedhdrs = NULL;
tail = (struct _camel_header_raw *) &savedhdrs;
- header = (struct _camel_header_raw *) &CAMEL_MIME_PART (mime_message)->headers;
+ header = (struct _camel_header_raw *) &CAMEL_MIME_PART (message)->headers;
n = header->next;
while (n != NULL) {
if (!g_ascii_strcasecmp (n->name, "To") || !g_ascii_strcasecmp (n->name, "Cc") ||
!g_ascii_strcasecmp (n->name, "Bcc")) {
@@ -656,7 +480,7 @@ nntp_folder_append_message_online (CamelFolder *folder,
cancellable, &local_error);
if (local_error == NULL)
camel_data_wrapper_write_to_stream_sync (
- CAMEL_DATA_WRAPPER (mime_message),
+ CAMEL_DATA_WRAPPER (message),
filtered_stream, cancellable, &local_error);
if (local_error == NULL)
camel_stream_flush (
@@ -691,74 +515,213 @@ exit:
}
static gboolean
-nntp_folder_append_message_offline (CamelFolder *folder,
- CamelMimeMessage *mime_message,
- const CamelMessageInfo *info,
- gchar **appended_uid,
- GCancellable *cancellable,
- GError **error)
+nntp_folder_expunge_sync (CamelFolder *folder,
+ GCancellable *cancellable,
+ GError **error)
{
- g_set_error (
- error, CAMEL_SERVICE_ERROR,
- CAMEL_SERVICE_ERROR_UNAVAILABLE,
- _("You cannot post NNTP messages while working offline!"));
+ CamelFolderSummary *summary;
+ CamelFolderChangeInfo *changes;
+ GPtrArray *known_uids;
+ guint ii;
- return FALSE;
+ summary = folder->summary;
+
+ camel_folder_summary_prepare_fetch_all (summary, NULL);
+ known_uids = camel_folder_summary_get_array (summary);
+
+ if (known_uids == NULL)
+ return TRUE;
+
+ changes = camel_folder_change_info_new ();
+
+ for (ii = 0; ii < known_uids->len; ii++) {
+ CamelMessageInfo *info;
+ const gchar *uid;
+
+ uid = g_ptr_array_index (known_uids, ii);
+ info = camel_folder_summary_get (summary, uid);
+
+ if (camel_message_info_flags (info) & CAMEL_MESSAGE_DELETED) {
+ camel_folder_change_info_remove_uid (changes, uid);
+ camel_folder_summary_remove (summary, info);
+ }
+
+ camel_message_info_unref (info);
+ }
+
+ camel_folder_summary_save_to_db (summary, NULL);
+ camel_folder_changed (folder, changes);
+
+ camel_folder_change_info_free (changes);
+ camel_folder_summary_free_array (known_uids);
+
+ return TRUE;
}
-/* I do not know what to do this exactly. Looking at the IMAP implementation for this, it
- * seems to assume the message is copied to a folder on the same store. In that case, an
- * NNTP implementation doesn't seem to make any sense. */
-static gboolean
-nntp_folder_transfer_message (CamelFolder *source,
- GPtrArray *uids,
- CamelFolder *dest,
- GPtrArray **transferred_uids,
- gboolean delete_orig,
+static CamelMimeMessage *
+nntp_folder_get_message_sync (CamelFolder *folder,
+ const gchar *uid,
GCancellable *cancellable,
GError **error)
{
- g_set_error (
- error, CAMEL_SERVICE_ERROR,
- CAMEL_SERVICE_ERROR_UNAVAILABLE,
- _("You cannot copy messages from a NNTP folder!"));
+ CamelStore *parent_store;
+ CamelMimeMessage *message = NULL;
+ CamelDataCache *nntp_cache;
+ CamelNNTPStore *nntp_store;
+ CamelFolderChangeInfo *changes;
+ CamelNNTPFolder *nntp_folder;
+ CamelStream *stream = NULL;
+ GIOStream *base_stream;
+ gchar *article, *msgid;
+ gsize article_len;
- return FALSE;
+ parent_store = camel_folder_get_parent_store (folder);
+
+ nntp_folder = CAMEL_NNTP_FOLDER (folder);
+ nntp_store = CAMEL_NNTP_STORE (parent_store);
+
+ article_len = strlen (uid) + 1;
+ article = alloca (article_len);
+ g_strlcpy (article, uid, article_len);
+ msgid = strchr (article, ',');
+ if (msgid == NULL) {
+ g_set_error (
+ error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+ _("Internal error: UID in invalid format: %s"), uid);
+ return NULL;
+ }
+ *msgid++ = 0;
+
+ /* Lookup in cache, NEWS is global messageid's so use a global cache path */
+ nntp_cache = camel_nntp_store_ref_cache (nntp_store);
+ base_stream = camel_data_cache_get (nntp_cache, "cache", msgid, NULL);
+ g_clear_object (&nntp_cache);
+
+ if (base_stream != NULL) {
+ stream = camel_stream_new (base_stream);
+ g_object_unref (base_stream);
+ } else {
+ CamelServiceConnectionStatus connection_status;
+
+ connection_status = camel_service_get_connection_status (
+ CAMEL_SERVICE (parent_store));
+
+ if (connection_status != CAMEL_SERVICE_CONNECTED) {
+ g_set_error (
+ error, CAMEL_SERVICE_ERROR,
+ CAMEL_SERVICE_ERROR_UNAVAILABLE,
+ _("This message is not currently available"));
+ goto fail;
+ }
+
+ stream = nntp_folder_download_message (nntp_folder, article, msgid, cancellable, error);
+ if (stream == NULL)
+ goto fail;
+ }
+
+ message = camel_mime_message_new ();
+ if (!camel_data_wrapper_construct_from_stream_sync ((CamelDataWrapper *) message, stream,
cancellable, error)) {
+ g_prefix_error (error, _("Cannot get message %s: "), uid);
+ g_object_unref (message);
+ message = NULL;
+ }
+
+ g_object_unref (stream);
+fail:
+ if (camel_folder_change_info_changed (nntp_folder->changes)) {
+ changes = nntp_folder->changes;
+ nntp_folder->changes = camel_folder_change_info_new ();
+ } else {
+ changes = NULL;
+ }
+
+ if (changes) {
+ camel_folder_changed (folder, changes);
+ camel_folder_change_info_free (changes);
+ }
+
+ return message;
}
static gboolean
-nntp_folder_expunge_uids_offline (CamelFolder *folder,
- GPtrArray *uids,
- GError **error)
+nntp_folder_refresh_info_sync (CamelFolder *folder,
+ GCancellable *cancellable,
+ GError **error)
{
- CamelFolderChangeInfo *changes;
- gint ii;
+ CamelStore *parent_store;
+ CamelNNTPStore *nntp_store;
+ CamelFolderChangeInfo *changes = NULL;
+ CamelNNTPFolder *nntp_folder;
+ gchar *line;
+ gboolean success;
- g_return_val_if_fail (folder != NULL, FALSE);
- g_return_val_if_fail (CAMEL_IS_NNTP_FOLDER (folder), FALSE);
- g_return_val_if_fail (uids != NULL, FALSE);
- g_return_val_if_fail (folder->summary != NULL, FALSE);
+ parent_store = camel_folder_get_parent_store (folder);
- /* can only remove deleted messages from a local cache */
+ nntp_folder = CAMEL_NNTP_FOLDER (folder);
+ nntp_store = CAMEL_NNTP_STORE (parent_store);
- changes = camel_folder_change_info_new ();
- for (ii = 0; ii < uids->len; ii++) {
- CamelMessageInfo *mi = camel_folder_summary_peek_loaded (folder->summary, uids->pdata[ii]);
- if (mi) {
- camel_folder_summary_remove (folder->summary, mi);
- camel_message_info_unref (mi);
- } else {
- camel_folder_summary_remove_uid (folder->summary, uids->pdata[ii]);
- }
+ /* When invoked with no fmt, camel_nntp_command() just selects the folder
+ * and should return zero. */
+ success = !camel_nntp_command (
+ nntp_store, cancellable, error, nntp_folder, &line, NULL);
- camel_folder_change_info_remove_uid (changes, uids->pdata[ii]);
+ if (camel_folder_change_info_changed (nntp_folder->changes)) {
+ changes = nntp_folder->changes;
+ nntp_folder->changes = camel_folder_change_info_new ();
}
- camel_folder_summary_save_to_db (folder->summary, NULL);
- camel_folder_changed (folder, changes);
- camel_folder_change_info_free (changes);
+ if (changes) {
+ camel_folder_changed (folder, changes);
+ camel_folder_change_info_free (changes);
+ }
- return TRUE;
+ return success;
+}
+
+static gboolean
+nntp_folder_synchronize_sync (CamelFolder *folder,
+ gboolean expunge,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CamelFolderSummary *summary;
+ GPtrArray *changed;
+
+ if (expunge) {
+ if (!camel_folder_expunge_sync (folder, cancellable, error))
+ return FALSE;
+ }
+
+ summary = folder->summary;
+
+ changed = camel_folder_summary_get_changed (summary);
+ if (changed != NULL) {
+ g_ptr_array_foreach (
+ changed, (GFunc) unset_flagged_flag, summary);
+ g_ptr_array_foreach (
+ changed, (GFunc) camel_pstring_free, NULL);
+ camel_folder_summary_touch (summary);
+ g_ptr_array_free (changed, TRUE);
+ }
+
+ return camel_folder_summary_save_to_db (summary, error);
+}
+
+static gboolean
+nntp_folder_transfer_messages_to_sync (CamelFolder *source,
+ GPtrArray *uids,
+ CamelFolder *dest,
+ gboolean delete_originals,
+ GPtrArray **transferred_uids,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_set_error (
+ error, CAMEL_SERVICE_ERROR,
+ CAMEL_SERVICE_ERROR_UNAVAILABLE,
+ _("You cannot copy messages from a NNTP folder"));
+
+ return FALSE;
}
static void
@@ -766,7 +729,6 @@ camel_nntp_folder_class_init (CamelNNTPFolderClass *class)
{
GObjectClass *object_class;
CamelFolderClass *folder_class;
- CamelDiscoFolderClass *disco_folder_class;
g_type_class_add_private (class, sizeof (CamelNNTPFolderPrivate));
@@ -782,23 +744,12 @@ camel_nntp_folder_class_init (CamelNNTPFolderClass *class)
folder_class->search_by_uids = nntp_folder_search_by_uids;
folder_class->search_free = nntp_folder_search_free;
folder_class->get_filename = nntp_get_filename;
+ folder_class->append_message_sync = nntp_folder_append_message_sync;
+ folder_class->expunge_sync = nntp_folder_expunge_sync;
folder_class->get_message_sync = nntp_folder_get_message_sync;
-
- disco_folder_class = CAMEL_DISCO_FOLDER_CLASS (class);
- disco_folder_class->sync_online = nntp_folder_sync_online;
- disco_folder_class->sync_resyncing = nntp_folder_sync_offline;
- disco_folder_class->sync_offline = nntp_folder_sync_offline;
- disco_folder_class->cache_message = nntp_folder_cache_message;
- disco_folder_class->append_online = nntp_folder_append_message_online;
- disco_folder_class->append_resyncing = nntp_folder_append_message_online;
- disco_folder_class->append_offline = nntp_folder_append_message_offline;
- disco_folder_class->transfer_online = nntp_folder_transfer_message;
- disco_folder_class->transfer_resyncing = nntp_folder_transfer_message;
- disco_folder_class->transfer_offline = nntp_folder_transfer_message;
- disco_folder_class->refresh_info_online = nntp_folder_refresh_info_online;
- disco_folder_class->expunge_uids_online = nntp_folder_expunge_uids_offline;
- disco_folder_class->expunge_uids_offline = nntp_folder_expunge_uids_offline;
- disco_folder_class->expunge_uids_resyncing = nntp_folder_expunge_uids_offline;
+ folder_class->refresh_info_sync = nntp_folder_refresh_info_sync;
+ folder_class->synchronize_sync = nntp_folder_synchronize_sync;
+ folder_class->transfer_messages_to_sync = nntp_folder_transfer_messages_to_sync;
g_object_class_install_property (
object_class,
diff --git a/camel/providers/nntp/camel-nntp-folder.h b/camel/providers/nntp/camel-nntp-folder.h
index 2f6a226..8167065 100644
--- a/camel/providers/nntp/camel-nntp-folder.h
+++ b/camel/providers/nntp/camel-nntp-folder.h
@@ -53,8 +53,7 @@ typedef struct _CamelNNTPFolderClass CamelNNTPFolderClass;
typedef struct _CamelNNTPFolderPrivate CamelNNTPFolderPrivate;
struct _CamelNNTPFolder {
- CamelDiscoFolder parent;
-
+ CamelOfflineFolder parent;
CamelNNTPFolderPrivate *priv;
struct _CamelFolderChangeInfo *changes;
@@ -63,7 +62,7 @@ struct _CamelNNTPFolder {
};
struct _CamelNNTPFolderClass {
- CamelDiscoFolderClass parent;
+ CamelOfflineFolderClass parent;
};
GType camel_nntp_folder_get_type (void);
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index 548fb02..1f032c0 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -85,7 +85,7 @@ static void camel_subscribable_init (CamelSubscribableInterface *interface);
G_DEFINE_TYPE_WITH_CODE (
CamelNNTPStore,
camel_nntp_store,
- CAMEL_TYPE_DISCO_STORE,
+ CAMEL_TYPE_OFFLINE_STORE,
G_IMPLEMENT_INTERFACE (
G_TYPE_INITABLE,
camel_nntp_store_initable_init)
@@ -162,7 +162,6 @@ static void
nntp_store_dispose (GObject *object)
{
CamelNNTPStorePrivate *priv;
- CamelDiscoStore *disco_store;
priv = CAMEL_NNTP_STORE_GET_PRIVATE (object);
@@ -178,13 +177,6 @@ nntp_store_dispose (GObject *object)
g_clear_object (&priv->stream);
g_clear_object (&priv->summary);
- disco_store = CAMEL_DISCO_STORE (object);
-
- if (disco_store->diary != NULL) {
- g_object_unref (disco_store->diary);
- disco_store->diary = NULL;
- }
-
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (camel_nntp_store_parent_class)->dispose (object);
}
@@ -208,12 +200,6 @@ nntp_store_finalize (GObject *object)
G_OBJECT_CLASS (camel_nntp_store_parent_class)->finalize (object);
}
-static gboolean
-nntp_can_work_offline (CamelDiscoStore *store)
-{
- return TRUE;
-}
-
static gint
check_capabilities (CamelNNTPStore *nntp_store,
GCancellable *cancellable,
@@ -344,7 +330,6 @@ connect_to_server (CamelService *service,
GCancellable *cancellable,
GError **error)
{
- CamelDiscoStore *disco_store;
CamelNNTPStore *nntp_store;
CamelNNTPStream *nntp_stream = NULL;
CamelNetworkSettings *network_settings;
@@ -352,16 +337,14 @@ connect_to_server (CamelService *service,
CamelSession *session;
CamelStream *stream;
GIOStream *base_stream;
- const gchar *user_cache_dir;
guchar *buf;
guint len;
- gchar *host, *path, *user, *mechanism;
+ gchar *host, *user, *mechanism;
gboolean success = FALSE;
nntp_store = CAMEL_NNTP_STORE (service);
session = camel_service_ref_session (service);
- user_cache_dir = camel_service_get_user_cache_dir (service);
settings = camel_service_ref_settings (service);
@@ -428,15 +411,6 @@ connect_to_server (CamelService *service,
if (xover_setup (nntp_store, cancellable, error) == -1)
goto fail;
- disco_store = CAMEL_DISCO_STORE (service);
-
- if (disco_store->diary == NULL) {
- path = g_build_filename (user_cache_dir, ".ev-journal", NULL);
- disco_store->diary =
- camel_disco_diary_new (disco_store, path, NULL);
- g_free (path);
- }
-
success = TRUE;
goto exit;
@@ -455,10 +429,36 @@ exit:
return success;
}
+static gchar *
+nntp_store_get_name (CamelService *service,
+ gboolean brief)
+{
+ CamelNetworkSettings *network_settings;
+ CamelSettings *settings;
+ gchar *host;
+ gchar *name;
+
+ settings = camel_service_ref_settings (service);
+
+ network_settings = CAMEL_NETWORK_SETTINGS (settings);
+ host = camel_network_settings_dup_host (network_settings);
+
+ g_object_unref (settings);
+
+ if (brief)
+ name = g_strdup_printf ("%s", host);
+ else
+ name = g_strdup_printf (_("USENET News via %s"), host);
+
+ g_free (host);
+
+ return name;
+}
+
static gboolean
-nntp_connect_online (CamelService *service,
- GCancellable *cancellable,
- GError **error)
+nntp_store_connect_sync (CamelService *service,
+ GCancellable *cancellable,
+ GError **error)
{
CamelNNTPStore *nntp_store;
@@ -478,34 +478,10 @@ nntp_connect_online (CamelService *service,
}
static gboolean
-nntp_connect_offline (CamelService *service,
- GCancellable *cancellable,
- GError **error)
-{
- CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (service);
- CamelDiscoStore *disco_store = (CamelDiscoStore *) nntp_store;
- const gchar *user_cache_dir;
- gchar *path;
-
- if (disco_store->diary)
- return TRUE;
-
- user_cache_dir = camel_service_get_user_cache_dir (service);
- path = g_build_filename (user_cache_dir, ".ev-journal", NULL);
- disco_store->diary = camel_disco_diary_new (disco_store, path, error);
- g_free (path);
-
- if (!disco_store->diary)
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-nntp_disconnect_online (CamelService *service,
- gboolean clean,
- GCancellable *cancellable,
- GError **error)
+nntp_store_disconnect_sync (CamelService *service,
+ gboolean clean,
+ GCancellable *cancellable,
+ GError **error)
{
CamelNNTPStore *nntp_store;
gchar *line;
@@ -521,48 +497,6 @@ nntp_disconnect_online (CamelService *service,
return TRUE;
}
-static gboolean
-nntp_disconnect_offline (CamelService *service,
- gboolean clean,
- GCancellable *cancellable,
- GError **error)
-{
- CamelDiscoStore *disco = CAMEL_DISCO_STORE (service);
-
- if (disco->diary) {
- g_object_unref (disco->diary);
- disco->diary = NULL;
- }
-
- return TRUE;
-}
-
-static gchar *
-nntp_store_get_name (CamelService *service,
- gboolean brief)
-{
- CamelNetworkSettings *network_settings;
- CamelSettings *settings;
- gchar *host;
- gchar *name;
-
- settings = camel_service_ref_settings (service);
-
- network_settings = CAMEL_NETWORK_SETTINGS (settings);
- host = camel_network_settings_dup_host (network_settings);
-
- g_object_unref (settings);
-
- if (brief)
- name = g_strdup_printf ("%s", host);
- else
- name = g_strdup_printf (_("USENET News via %s"), host);
-
- g_free (host);
-
- return name;
-}
-
extern CamelServiceAuthType camel_nntp_anonymous_authtype;
extern CamelServiceAuthType camel_nntp_password_authtype;
@@ -652,17 +586,6 @@ nntp_store_query_auth_types_sync (CamelService *service,
return auth_types;
}
-static CamelFolder *
-nntp_get_folder (CamelStore *store,
- const gchar *folder_name,
- guint32 flags,
- GCancellable *cancellable,
- GError **error)
-{
- return camel_nntp_folder_new (
- store, folder_name, cancellable, error);
-}
-
/*
* Converts a fully-fledged newsgroup name to a name in short dotted notation,
* e.g. nl.comp.os.linux.programmeren becomes n.c.o.l.programmeren
@@ -1167,7 +1090,6 @@ static CamelFolderInfo *
nntp_store_get_folder_info_all (CamelNNTPStore *nntp_store,
const gchar *top,
CamelStoreGetFolderInfoFlags flags,
- gboolean online,
GCancellable *cancellable,
GError **error)
{
@@ -1183,7 +1105,7 @@ nntp_store_get_folder_info_all (CamelNNTPStore *nntp_store,
if (top == NULL)
top = "";
- if (online && (top == NULL || top[0] == 0)) {
+ if (top == NULL || top[0] == 0) {
/* we may need to update */
if (nntp_store_summary->last_newslist[0] != 0) {
gchar date[14];
@@ -1277,60 +1199,64 @@ error:
return fi;
}
+static gboolean
+nntp_store_can_refresh_folder (CamelStore *store,
+ CamelFolderInfo *info,
+ GError **error)
+{
+ /* any nntp folder can be refreshed */
+ return TRUE;
+}
+
+static CamelFolder *
+nntp_store_get_folder_sync (CamelStore *store,
+ const gchar *folder_name,
+ CamelStoreGetFolderFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ return camel_nntp_folder_new (
+ store, folder_name, cancellable, error);
+}
+
static CamelFolderInfo *
-nntp_get_folder_info (CamelStore *store,
- const gchar *top,
- CamelStoreGetFolderInfoFlags flags,
- gboolean online,
- GCancellable *cancellable,
- GError **error)
+nntp_store_get_folder_info_sync (CamelStore *store,
+ const gchar *top,
+ CamelStoreGetFolderInfoFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (store);
+ CamelServiceConnectionStatus status;
CamelFolderInfo *first = NULL;
+ status = camel_service_get_connection_status (CAMEL_SERVICE (store));
+
dd (printf (
- "g_f_i: fast %d subscr %d recursive %d online %d top \"%s\"\n",
+ "g_f_i: fast %d subscr %d recursive %d top \"%s\"\n",
flags & CAMEL_STORE_FOLDER_INFO_FAST,
flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED,
flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE,
- online,
top ? top:""));
- if (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED)
+ if (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED) {
first = nntp_store_get_subscribed_folder_info (
nntp_store, top, flags, cancellable, error);
- else
+ } else if (status == CAMEL_SERVICE_CONNECTED) {
first = nntp_store_get_folder_info_all (
- nntp_store, top, flags, online, cancellable, error);
+ nntp_store, top, flags, cancellable, error);
+ } else {
+ g_set_error_literal (
+ error, CAMEL_SERVICE_ERROR,
+ CAMEL_SERVICE_ERROR_UNAVAILABLE,
+ _("You must be working online to complete "
+ "this operation"));
+ }
return first;
}
static CamelFolderInfo *
-nntp_get_folder_info_online (CamelStore *store,
- const gchar *top,
- CamelStoreGetFolderInfoFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- return nntp_get_folder_info (
- store, top, flags, TRUE, cancellable, error);
-}
-
-static CamelFolderInfo *
-nntp_get_folder_info_offline (CamelStore *store,
- const gchar *top,
- CamelStoreGetFolderInfoFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- return nntp_get_folder_info (
- store, top, flags, FALSE, cancellable, error);
-}
-
-/* stubs for various folder operations we're not implementing */
-
-static CamelFolderInfo *
nntp_store_create_folder_sync (CamelStore *store,
const gchar *parent_name,
const gchar *folder_name,
@@ -1385,15 +1311,6 @@ nntp_store_delete_folder_sync (CamelStore *store,
return FALSE;
}
-static gboolean
-nntp_can_refresh_folder (CamelStore *store,
- CamelFolderInfo *info,
- GError **error)
-{
- /* any nntp folder can be refreshed */
- return TRUE;
-}
-
/* nntp stores part of its data in user_data_dir and part in user_cache_dir,
* thus check whether to migrate based on folders.db file */
static void
@@ -1700,7 +1617,6 @@ camel_nntp_store_class_init (CamelNNTPStoreClass *class)
GObjectClass *object_class;
CamelServiceClass *service_class;
CamelStoreClass *store_class;
- CamelDiscoStoreClass *disco_store_class;
g_type_class_add_private (class, sizeof (CamelNNTPStorePrivate));
@@ -1713,28 +1629,19 @@ camel_nntp_store_class_init (CamelNNTPStoreClass *class)
service_class = CAMEL_SERVICE_CLASS (class);
service_class->settings_type = CAMEL_TYPE_NNTP_SETTINGS;
service_class->get_name = nntp_store_get_name;
+ service_class->connect_sync = nntp_store_connect_sync;
+ service_class->disconnect_sync = nntp_store_disconnect_sync;
service_class->authenticate_sync = nntp_store_authenticate_sync;
service_class->query_auth_types_sync = nntp_store_query_auth_types_sync;
store_class = CAMEL_STORE_CLASS (class);
- store_class->can_refresh_folder = nntp_can_refresh_folder;
+ store_class->can_refresh_folder = nntp_store_can_refresh_folder;
+ store_class->get_folder_sync = nntp_store_get_folder_sync;
+ store_class->get_folder_info_sync = nntp_store_get_folder_info_sync;
store_class->create_folder_sync = nntp_store_create_folder_sync;
store_class->delete_folder_sync = nntp_store_delete_folder_sync;
store_class->rename_folder_sync = nntp_store_rename_folder_sync;
- disco_store_class = CAMEL_DISCO_STORE_CLASS (class);
- disco_store_class->can_work_offline = nntp_can_work_offline;
- disco_store_class->connect_online = nntp_connect_online;
- disco_store_class->connect_offline = nntp_connect_offline;
- disco_store_class->disconnect_online = nntp_disconnect_online;
- disco_store_class->disconnect_offline = nntp_disconnect_offline;
- disco_store_class->get_folder_online = nntp_get_folder;
- disco_store_class->get_folder_resyncing = nntp_get_folder;
- disco_store_class->get_folder_offline = nntp_get_folder;
- disco_store_class->get_folder_info_online = nntp_get_folder_info_online;
- disco_store_class->get_folder_info_resyncing = nntp_get_folder_info_online;
- disco_store_class->get_folder_info_offline = nntp_get_folder_info_offline;
-
/* Inherited from CamelNetworkService. */
g_object_class_override_property (
object_class,
@@ -2180,7 +2087,7 @@ camel_nntp_command (CamelNNTPStore *nntp_store,
...)
{
CamelNNTPStream *nntp_stream = NULL;
- CamelDiscoStore *disco_store;
+ CamelServiceConnectionStatus status;
CamelService *service;
CamelSession *session;
gboolean success;
@@ -2192,9 +2099,9 @@ camel_nntp_command (CamelNNTPStore *nntp_store,
GError *local_error = NULL;
service = CAMEL_SERVICE (nntp_store);
+ status = camel_service_get_connection_status (service);
- disco_store = CAMEL_DISCO_STORE (nntp_store);
- if (disco_store->status == CAMEL_DISCO_STORE_OFFLINE) {
+ if (status != CAMEL_SERVICE_CONNECTED) {
g_set_error (
error, CAMEL_SERVICE_ERROR,
CAMEL_SERVICE_ERROR_NOT_CONNECTED,
diff --git a/camel/providers/nntp/camel-nntp-store.h b/camel/providers/nntp/camel-nntp-store.h
index 0b9a4df..d163b73 100644
--- a/camel/providers/nntp/camel-nntp-store.h
+++ b/camel/providers/nntp/camel-nntp-store.h
@@ -75,14 +75,14 @@ typedef enum {
} CamelNNTPCapabilities;
struct _CamelNNTPStore {
- CamelDiscoStore parent;
+ CamelOfflineStore parent;
CamelNNTPStorePrivate *priv;
struct _xover_header *xover;
};
struct _CamelNNTPStoreClass {
- CamelDiscoStoreClass parent_class;
+ CamelOfflineStoreClass parent_class;
};
GType camel_nntp_store_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]