2010-01-19 [holger] 3.7.4cvs6
authorHolger Berndt <hb@claws-mail.org>
Tue, 19 Jan 2010 21:32:04 +0000 (21:32 +0000)
committerHolger Berndt <hb@claws-mail.org>
Tue, 19 Jan 2010 21:32:04 +0000 (21:32 +0000)
* src/folder.c
* src/folder.h
Introduce folder_get_item_from_identifier().
In contrast to folder_find_item_from_identifier(), this
function recursively creates the FolderItems in the id path.
Useful for programmatically creating folders (e.g. by plugins)

ChangeLog
PATCHSETS
configure.ac
src/folder.c
src/folder.h

index ec5da22..14253ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-01-19 [holger]    3.7.4cvs6
+
+       * src/folder.c
+       * src/folder.h
+               Introduce folder_get_item_from_identifier().
+               In contrast to folder_find_item_from_identifier(), this
+               function recursively creates the FolderItems in the id path.
+               Useful for programmatically creating folders (e.g. by plugins)
+
 2010-01-17 [pawel]     3.7.4cvs5
 
        * src/gtk/authors.h
index c77528f..35b6067 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.5.2.10 -r 1.5.2.11 src/prefs_toolbar.h;  ) > 3.7.4cvs3.patchset
 ( cvs diff -u -r 1.1.2.65 -r 1.1.2.66 src/plugins/pgpcore/sgpgme.c;  ) > 3.7.4cvs4.patchset
 ( cvs diff -u -r 1.1.2.62 -r 1.1.2.63 src/gtk/authors.h;  ) > 3.7.4cvs5.patchset
+( cvs diff -u -r 1.213.2.195 -r 1.213.2.196 src/folder.c;  cvs diff -u -r 1.87.2.60 -r 1.87.2.61 src/folder.h;  ) > 3.7.4cvs6.patchset
index c960c50..52aafba 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=7
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=5
+EXTRA_VERSION=6
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 84ee245..0ee5637 100644 (file)
@@ -1426,6 +1426,91 @@ FolderItem *folder_find_item_from_identifier(const gchar *identifier)
        return d[1];
 }
 
+/** Returns the FolderItem from a given identifier
+ *
+ * The FolderItem is created if it doesn't already exist.
+ * If creation failed, the function returns NULL.
+ * 
+ * Identifiers are of the form #type/Mailbox/FolderA/FolderB/FolderC
+ */
+FolderItem *folder_get_item_from_identifier(const gchar *identifier)
+{
+       FolderItem *item, *last_parent;
+       Folder *folder;
+       gchar *p1, *p2, *str;
+       size_t len;
+       FolderClass *class;
+       gboolean created_something = FALSE;
+
+       item = folder_find_item_from_identifier(identifier);
+       if(item)
+               return item;
+
+       /* trivial sanity check: need at least # and two slashes */
+       len = strlen(identifier);
+       if(len < 3)
+               return NULL;
+
+       /* make sure identifier ends with a slash */
+       if(identifier[len-1] == G_DIR_SEPARATOR) {
+               Xstrdup_a(str, identifier, return NULL);
+       }
+       else {
+               Xstrndup_a(str, identifier, len+1, return NULL);
+               str[len] = G_DIR_SEPARATOR;
+       }
+
+       /* find folder class */
+       p1 = strchr(str, G_DIR_SEPARATOR);
+       if(!p1)
+               return NULL;
+       *p1 = '\0';
+       class = folder_get_class_from_string(&str[1]);
+       if(!class)
+               return NULL;
+       *p1 = G_DIR_SEPARATOR;
+       ++p1;
+
+       /* find folder from class and name */
+       p2 = strchr(p1, G_DIR_SEPARATOR);
+       if(!p2)
+               return NULL;
+       *p2 = '\0';
+       folder = folder_find_from_name(p1, class);
+       if(!folder)
+               return NULL;
+       *p2 = G_DIR_SEPARATOR;
+       ++p2;
+       p1 = p2;
+
+       /* Now, move forward and make sure all sections in the path exist */
+       last_parent = folder->node->data;
+       while((p1 = strchr(p1, G_DIR_SEPARATOR)) != NULL) {
+               *p1 = '\0';
+               item = folder_find_item_from_identifier(str);
+               if(!item) {
+                       item = folder_create_folder(last_parent, p2);
+                       if(!item)
+                               return NULL;
+                       debug_print("Created folder '%s'\n", str);
+                       created_something = TRUE;
+                       if(prefs_common.inherit_folder_props && (last_parent != item->folder->node->data)) {
+                               folder_item_prefs_copy_prefs(last_parent, item);
+                       }
+               }
+               last_parent = item;
+               *p1 = G_DIR_SEPARATOR;
+               ++p1;
+               p2 = p1;
+       }
+
+       if(created_something)
+               folder_write_list();
+
+       return item;
+}
+
+
 /**
  * Get a displayable name for a FolderItem
  *
index b740183..602cd8e 100644 (file)
@@ -801,6 +801,7 @@ gchar          *folder_get_identifier               (Folder *folder);
 /* return value is locale charset */
 gchar      *folder_item_get_identifier         (FolderItem     *item);
 FolderItem *folder_find_item_from_identifier   (const gchar    *identifier);
+FolderItem *folder_get_item_from_identifier    (const gchar    *identifier);
 gchar     *folder_item_get_name                (FolderItem     *item);
 
 FolderItem *folder_get_default_inbox   (void);