diff options
author | bertrand <Bertrand.Guiheneuf@aful.org> | 1999-08-04 02:08:04 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-08-04 02:08:04 +0800 |
commit | 0f2d4dd1153bb7491c5494843d959148a31a895d (patch) | |
tree | f2d88dcc56a504498f59979c01e97729a7c53afc | |
parent | b9daf0016bc3d7244ced57dd88f63c1fd6debbac (diff) | |
download | gsoc2013-evolution-0f2d4dd1153bb7491c5494843d959148a31a895d.tar gsoc2013-evolution-0f2d4dd1153bb7491c5494843d959148a31a895d.tar.gz gsoc2013-evolution-0f2d4dd1153bb7491c5494843d959148a31a895d.tar.bz2 gsoc2013-evolution-0f2d4dd1153bb7491c5494843d959148a31a895d.tar.lz gsoc2013-evolution-0f2d4dd1153bb7491c5494843d959148a31a895d.tar.xz gsoc2013-evolution-0f2d4dd1153bb7491c5494843d959148a31a895d.tar.zst gsoc2013-evolution-0f2d4dd1153bb7491c5494843d959148a31a895d.zip |
Started implementing mh store/folder as a test provider. Next will be pop3.
1999-08-03 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/providers/MH/camel-mh-folder.c (_create):
implemented.
(_delete): started implementation.
* camel/camel-folder.c (_get_folder): default implementation
calls camel_store_get_folder ().
* camel/providers/MH/camel-mh-folder.c (_init_with_store):
implemented.
* camel/camel-folder.h (struct _CamelFolder):
remove useless exist_on_store field.
* camel/camel-folder.c (_exists):
do not use exist_on_store field.
svn path=/trunk/; revision=1073
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | camel/camel-folder.c | 58 | ||||
-rw-r--r-- | camel/camel-folder.h | 1 | ||||
-rw-r--r-- | camel/providers/MH/camel-mh-folder.c | 102 |
4 files changed, 145 insertions, 32 deletions
@@ -1,5 +1,21 @@ 1999-08-03 bertrand <Bertrand.Guiheneuf@aful.org> + * camel/providers/MH/camel-mh-folder.c (_create): + implemented. + (_delete): started implementation. + + * camel/camel-folder.c (_get_folder): default implementation + calls camel_store_get_folder (). + + * camel/providers/MH/camel-mh-folder.c (_init_with_store): + implemented. + + * camel/camel-folder.h (struct _CamelFolder): + remove useless exist_on_store field. + + * camel/camel-folder.c (_exists): + do not use exist_on_store field. + * camel/camel-folder.c (camel_folder_set_name): (camel_folder_get_name): new public functions diff --git a/camel/camel-folder.c b/camel/camel-folder.c index db3e7f9f8a..2f103283d4 100644 --- a/camel/camel-folder.c +++ b/camel/camel-folder.c @@ -315,7 +315,7 @@ _can_hold_messages (CamelFolder *folder) /** - * _exists: tests if the folder object exists in its parent store. + * _exists: tests if the folder object exists in its parent store. * @folder: folder object * * Test if a folder exists on a store. A folder can be @@ -327,7 +327,7 @@ _can_hold_messages (CamelFolder *folder) static gboolean _exists (CamelFolder *folder) { - return folder->exists_on_store; + return FALSE; } @@ -350,30 +350,32 @@ _is_open (CamelFolder *folder) -/** - * _get_folder: return the (sub)folder object that is specified. - * - * @folder : the folder - * @folder_name: subfolder path. - * - * This method returns a folder objects. This folder - * is necessarily a subfolder of the current folder. - * It is an error to ask a folder begining with the - * folder separator character. - * - * - * Return value: Required folder. NULL if the subfolder object - * could not be obtained - **/ + static CamelFolder * _get_folder (CamelFolder *folder, const gchar *folder_name) { - g_warning("getFolder called on the abstract CamelFolder class\n"); - return NULL; + CamelFolder *new_folder; + gchar *full_name; + const gchar *current_folder_full_name; + gchar separator; + + g_assert (folder); + g_assert (folder_name); + + if (!folder->parent_store) return NULL; + + current_folder_full_name = camel_folder_get_full_name (folder); + if (!current_folder_full_name) return NULL; + + separator = camel_store_get_separator (folder->parent_store); + full_name = g_strdup_printf ("%s%d%s", current_folder_full_name, separator, folder_name); + + new_folder = camel_store_get_folder (folder->parent_store, full_name); + return new_folder; } /** - * _get_folder: return the (sub)folder object that is specified. + * camel_folder_get_folder: return the (sub)folder object that is specified. * * @folder : the folder * @folder_name: subfolder path. @@ -396,16 +398,18 @@ camel_folder_get_folder(CamelFolder *folder, gchar *folder_name) /** - * _create: - * @folder: + * _create: creates a folder on its store + * @folder: a CamelFolder object. * * this routine handles the recursion mechanism. * Children classes have to implement the actual * creation mechanism. They must call this method * before physically creating the folder in order * to be sure the parent folder exists. + * Calling this routine on an existing folder is + * not an error, and returns %TRUE. * - * Return value: + * Return value: %TRUE if the folder exists, %FALSE otherwise **/ static gboolean _create(CamelFolder *folder) @@ -415,9 +419,9 @@ _create(CamelFolder *folder) CamelFolder *parent; gchar sep; - - g_assert(folder->parent_store); - g_assert(folder->name); + g_assert (folder); + g_assert (folder->parent_store); + g_assert (folder->name); if (CF_CLASS(folder)->exists (folder)) return TRUE; @@ -511,7 +515,7 @@ _delete (CamelFolder *folder, gboolean recurse) if (subfolders) { sf = subfolders; do { - CF_CLASS(sf->data)->delete(sf->data, TRUE);; + /* CF_CLASS(sf->data)->delete(sf->data, TRUE); */ } while (sf = sf->next); } } else if (subfolders) return FALSE; diff --git a/camel/camel-folder.h b/camel/camel-folder.h index 69a082fe1f..40d7d8f303 100644 --- a/camel/camel-folder.h +++ b/camel/camel-folder.h @@ -61,7 +61,6 @@ struct _CamelFolder gboolean can_hold_folders; gboolean can_hold_messages; - gboolean exists_on_store; CamelFolderOpenMode open_mode; CamelFolderState open_state; gchar *name; diff --git a/camel/providers/MH/camel-mh-folder.c b/camel/providers/MH/camel-mh-folder.c index 2db3a74e8e..206636578b 100644 --- a/camel/providers/MH/camel-mh-folder.c +++ b/camel/providers/MH/camel-mh-folder.c @@ -24,6 +24,11 @@ #include "camel-mh-folder.h" #include "camel-mh-store.h" #include "gstring-util.h" +#include <sys/stat.h> +#include <unistd.h> +#include <sys/types.h> +#include <fcntl.h> + static CamelFolderClass *parent_class=NULL; @@ -34,16 +39,23 @@ static CamelFolderClass *parent_class=NULL; #define CMHS_CLASS(so) CAMEL_STORE_CLASS (GTK_OBJECT(so)->klass) static void _set_name(CamelFolder *folder, const gchar *name); - +static void _init_with_store (CamelFolder *folder, CamelStore *parent_store); +static gboolean _exists (CamelFolder *folder); +static gboolean _create(CamelFolder *folder); static void camel_mh_folder_class_init (CamelMhFolderClass *camel_mh_folder_class) { + CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS(camel_mh_folder_class); + parent_class = gtk_type_class (camel_folder_get_type ()); - + /* virtual method definition */ /* virtual method overload */ - CAMEL_FOLDER_CLASS(camel_mh_folder_class)->set_name = _set_name; + camel_folder_class->init_with_store = _init_with_store; + camel_folder_class->set_name = _set_name; + camel_folder_class->exists = _exists; + } @@ -77,6 +89,20 @@ camel_mh_folder_get_type (void) } + + +static void +_init_with_store (CamelFolder *folder, CamelStore *parent_store) +{ + /* call parent method */ + parent_class->init_with_store (folder, parent_store); + + folder->can_hold_messages = TRUE; + folder->can_hold_folders = TRUE; +} + + + /** * camel_mh_folder_set_name: set the name of an MH folder * @folder: the folder to set the name @@ -88,10 +114,10 @@ camel_mh_folder_get_type (void) static void _set_name (CamelFolder *folder, const gchar *name) { + CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); const gchar *root_dir_path; gchar *full_name; const gchar *parent_full_name; - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); gchar separator; g_assert(folder); @@ -110,3 +136,71 @@ _set_name (CamelFolder *folder, const gchar *name) } + + +static gboolean +_exists (CamelFolder *folder) +{ + CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); + struct stat stat_buf; + gint stat_error; + gboolean exists; + + g_assert (folder); + + if (!mh_folder->directory_path) return FALSE; + + stat_error = stat (mh_folder->directory_path, &stat_buf); + if (stat_error == -1) return FALSE; + + exists = S_ISDIR(stat_buf.st_mode); + return exists; +} + + +static gboolean +_create(CamelFolder *folder) +{ + CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); + const gchar *directory_path; + mode_t dir_mode = S_IRWXU; + gint mkdir_error; + + g_assert(folder); + + /* call default implementation */ + parent_class->create (folder); + + directory_path = mh_folder->directory_path; + if (!directory_path) return FALSE; + + if (camel_folder_exists (folder)) return TRUE; + + mkdir_error = mkdir (directory_path, dir_mode); + return (mkdir_error == -1); +} + + + +static gboolean +_delete (CamelFolder *folder, gboolean recurse) +{ + + CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); + const gchar *directory_path; + gint rmdir_error; + + g_assert(folder); + + /* call default implementation */ + parent_class->delete (folder, recurse); + + directory_path = mh_folder->directory_path; + if (!directory_path) return FALSE; + + if (!camel_folder_exists (folder)) return TRUE; + + + rmdir_error = rmdir (directory_path); + +} |