From 03d5278cdd2fd4fd7b6caef33aa53b28e71ffc1c Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 29 Jul 2010 07:01:32 +0000 Subject: added 'Junk' special folder and automatically create it when not exist. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2638 ee746299-78ed-0310-b773-934348b2243d --- libsylph/defs.h | 1 + libsylph/folder.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++---- libsylph/folder.h | 5 +++ libsylph/mh.c | 5 +++ 4 files changed, 97 insertions(+), 6 deletions(-) (limited to 'libsylph') diff --git a/libsylph/defs.h b/libsylph/defs.h index 0b39d778..c3790a18 100644 --- a/libsylph/defs.h +++ b/libsylph/defs.h @@ -43,6 +43,7 @@ #define QUEUE_DIR "queue" #define DRAFT_DIR "draft" #define TRASH_DIR "trash" +#define JUNK_DIR "junk" #ifdef G_OS_WIN32 # define RC_DIR "Sylpheed" #else diff --git a/libsylph/folder.c b/libsylph/folder.c index 29a3a9ee..c6cb8a74 100644 --- a/libsylph/folder.c +++ b/libsylph/folder.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2009 Hiroyuki Yamamoto + * Copyright (C) 1999-2010 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -43,11 +43,22 @@ #include "prefs_account.h" #include "sylmain.h" +typedef struct _FolderPrivData FolderPrivData; + +struct _FolderPrivData { + Folder *folder; + FolderItem *junk; + gpointer data; +}; + static GList *folder_list = NULL; +static GList *folder_priv_list = NULL; static void folder_init (Folder *folder, const gchar *name); +static FolderPrivData *folder_get_priv (Folder *folder); + static gboolean folder_read_folder_func (GNode *node, gpointer data); static gchar *folder_get_list_path (void); @@ -115,6 +126,8 @@ void folder_remote_folder_init(Folder *folder, const gchar *name, void folder_destroy(Folder *folder) { + FolderPrivData *priv; + g_return_if_fail(folder != NULL); g_return_if_fail(folder->klass->destroy != NULL); @@ -122,6 +135,10 @@ void folder_destroy(Folder *folder) folder_list = g_list_remove(folder_list, folder); + priv = folder_get_priv(folder); + folder_priv_list = g_list_remove(folder_priv_list, priv); + g_free(priv); + folder_tree_destroy(folder); g_free(folder->name); g_free(folder); @@ -312,6 +329,8 @@ void folder_item_destroy(FolderItem *item) folder->queue = NULL; else if (folder->trash == item) folder->trash = NULL; + else if (folder_get_junk(folder) == item) + folder_set_junk(folder, NULL); } g_free(item->name); @@ -398,6 +417,9 @@ void folder_add(Folder *folder) Folder *cur_folder; GList *cur; gint i; + FolderPrivData *priv; + + debug_print("Adding folder (%p) to folder list\n", folder); g_return_if_fail(folder != NULL); @@ -416,6 +438,9 @@ void folder_add(Folder *folder) } folder_list = g_list_insert(folder_list, folder, i); + priv = g_new0(FolderPrivData, 1); + priv->folder = folder; + folder_priv_list = g_list_insert(folder_priv_list, priv, i); } GList *folder_get_list(void) @@ -858,6 +883,57 @@ FolderItem *folder_get_default_trash(void) return folder->trash; } +FolderItem *folder_get_default_junk(void) +{ + FolderPrivData *priv; + + if (!folder_list) return NULL; + if (!folder_priv_list) return NULL; + priv = (FolderPrivData *)folder_priv_list->data; + g_return_val_if_fail(priv != NULL, NULL); + g_return_val_if_fail(priv->folder != NULL, NULL); + return priv->junk; +} + +static FolderPrivData *folder_get_priv(Folder *folder) +{ + FolderPrivData *priv; + GList *cur; + + g_return_val_if_fail(folder != NULL, NULL); + + for (cur = folder_priv_list; cur != NULL; cur = cur->next) { + priv = (FolderPrivData *)cur->data; + if (priv->folder == folder) + return priv; + } + + g_warning("folder_get_priv: private data for Folder (%p) not found.", + folder); + + return NULL; +} + +FolderItem *folder_get_junk(Folder *folder) +{ + FolderPrivData *priv; + + priv = folder_get_priv(folder); + if (priv) + return priv->junk; + + return NULL; +} + +void folder_set_junk(Folder *folder, FolderItem *item) +{ + FolderPrivData *priv; + + priv = folder_get_priv(folder); + if (priv) + priv->junk = item; +} + #define CREATE_FOLDER_IF_NOT_EXIST(member, dir, type) \ { \ if (!folder->member) { \ @@ -882,7 +958,7 @@ void folder_set_missing_folders(void) g_return_if_fail(rootitem != NULL); if (folder->inbox && folder->outbox && folder->draft && - folder->queue && folder->trash) + folder->queue && folder->trash && folder_get_junk(folder)) continue; if (folder_create_tree(folder) < 0) { @@ -896,7 +972,13 @@ void folder_set_missing_folders(void) CREATE_FOLDER_IF_NOT_EXIST(draft, DRAFT_DIR, F_DRAFT); CREATE_FOLDER_IF_NOT_EXIST(queue, QUEUE_DIR, F_QUEUE); CREATE_FOLDER_IF_NOT_EXIST(trash, TRASH_DIR, F_TRASH); - /* CREATE_FOLDER_IF_NOT_EXIST(junk, JUNK_DIR, F_JUNK); */ + + if (!folder_get_junk(folder)) { + item = folder_item_new(JUNK_DIR, JUNK_DIR); + item->stype = F_JUNK; + folder_item_append(rootitem, item); + folder_set_junk(folder, item); + } } } @@ -1392,10 +1474,8 @@ static gboolean folder_build_tree(GNode *node, gpointer data) stype = F_QUEUE; else if (!g_ascii_strcasecmp(attr->value, "trash")) stype = F_TRASH; -#if 0 else if (!g_ascii_strcasecmp(attr->value, "junk")) stype = F_JUNK; -#endif else if (!g_ascii_strcasecmp(attr->value, "virtual")) stype = F_VIRTUAL; } else if (!strcmp(attr->name, "name")) @@ -1519,7 +1599,7 @@ static gboolean folder_build_tree(GNode *node, gpointer data) case F_DRAFT: folder->draft = item; break; case F_QUEUE: folder->queue = item; break; case F_TRASH: folder->trash = item; break; - /* case F_JUNK: folder->junk = item; break; */ + case F_JUNK: folder_set_junk(folder, item); break; default: break; } item->account = account; diff --git a/libsylph/folder.h b/libsylph/folder.h index 7c046eb3..c3822c39 100644 --- a/libsylph/folder.h +++ b/libsylph/folder.h @@ -382,6 +382,11 @@ FolderItem *folder_get_default_outbox (void); FolderItem *folder_get_default_draft (void); FolderItem *folder_get_default_queue (void); FolderItem *folder_get_default_trash (void); +FolderItem *folder_get_default_junk (void); + +FolderItem *folder_get_junk (Folder *folder); +void folder_set_junk (Folder *folder, + FolderItem *item); void folder_set_missing_folders (void); void folder_unref_account_all (PrefsAccount *account); diff --git a/libsylph/mh.c b/libsylph/mh.c index d3be1cf7..89ba6baa 100644 --- a/libsylph/mh.c +++ b/libsylph/mh.c @@ -1229,6 +1229,7 @@ static gint mh_create_tree(Folder *folder) MAKE_DIR_IF_NOT_EXIST(QUEUE_DIR); MAKE_DIR_IF_NOT_EXIST(DRAFT_DIR); MAKE_DIR_IF_NOT_EXIST(TRASH_DIR); + MAKE_DIR_IF_NOT_EXIST(JUNK_DIR); return 0; } @@ -1820,6 +1821,10 @@ static void mh_scan_tree_recursive(FolderItem *item) !strcmp(dir_name, TRASH_DIR)) { new_item->stype = F_TRASH; folder->trash = new_item; + } else if (!folder_get_junk(folder) && + !strcmp(dir_name, JUNK_DIR)) { + new_item->stype = F_JUNK; + folder_set_junk(folder, new_item); } } -- cgit v1.2.3