[PATCH 2/3] Folder list store path separator is now configurable.
- From: José Dapena Paz <jdapena igalia com>
- Subject: [PATCH 2/3] Folder list store path separator is now configurable.
- Date: Thu, 27 Nov 2008 13:43:54 +0100
diff --git a/ChangeLog b/ChangeLog
index 292ef98..c708e40 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,10 @@
2008-11-27 Jose Dapena Paz <jdapena igalia com>
+ * libtinymailui-gtk/tny-gtk-folder-list-store.[ch]:
+ Folder list store path separator is now configurable.
+
* libtinymailui-gtk/tny-gtk-folder-list-store.c:
Fixed reference leaks
2008-11-24 Jose Dapena Paz <jdapena igalia com>
diff --git a/libtinymailui-gtk/tny-gtk-folder-list-store.c b/libtinymailui-gtk/tny-gtk-folder-list-store.c
index 2181898..650748a 100644
--- a/libtinymailui-gtk/tny-gtk-folder-list-store.c
+++ b/libtinymailui-gtk/tny-gtk-folder-list-store.c
@@ -66,11 +66,11 @@
#include <tny-gtk-folder-list-store.h>
#include "tny-gtk-folder-list-store-iterator-priv.h"
-#define PATH_SEPARATOR " "
+#define DEFAULT_PATH_SEPARATOR " "
static GObjectClass *parent_class = NULL;
typedef void (*listaddfunc) (GtkListStore *list_store, GtkTreeIter *iter);
@@ -211,11 +211,11 @@ recurse_folders_sync (TnyGtkFolderListStore *self,
if (self->flags & TNY_GTK_FOLDER_LIST_STORE_FLAG_SHOW_PATH) {
if ((parent_name == NULL) || *parent_name == '\0') {
name = g_strdup (tny_folder_get_name (folder));
} else {
name = g_strconcat (parent_name,
- PATH_SEPARATOR,
+ self->path_separator,
tny_folder_get_name (folder),
NULL);
}
} else {
name = g_strdup (tny_folder_get_name (folder));
@@ -673,10 +673,11 @@ tny_gtk_folder_list_store_instance_init (GTypeInstance *instance, gpointer g_cla
me->store_obs = NULL;
me->iterator_lock = g_mutex_new ();
me->first_needs_unref = FALSE;
me->flags = 0;
+ me->path_separator = g_strdup (DEFAULT_PATH_SEPARATOR);
gtk_list_store_set_column_types (store,
TNY_GTK_FOLDER_LIST_STORE_N_COLUMNS, types);
return;
@@ -1012,10 +1013,11 @@ find_node (GtkTreeModel *model, TnyFolder *folder, GtkTreeIter *iter)
static void
update_children_names (GtkTreeModel *model, TnyFolder *folder, const gchar *name)
{
TnyList *children;
TnyIterator *iterator;
+ TnyGtkFolderListStore *self = TNY_GTK_FOLDER_LIST_STORE (model);
children = TNY_LIST (tny_simple_list_new ());
iterator = tny_list_create_iterator (children);
while (!tny_iterator_is_done (iterator)) {
@@ -1023,11 +1025,11 @@ update_children_names (GtkTreeModel *model, TnyFolder *folder, const gchar *name
TnyFolder *child;
child = TNY_FOLDER (tny_iterator_get_current (iterator));
if (find_node (model, child, &iter)) {
gchar *new_name;
- new_name = g_strconcat (name, PATH_SEPARATOR,
+ new_name = g_strconcat (name, self->path_separator,
tny_folder_get_name (TNY_FOLDER (child)),
NULL);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
TNY_GTK_FOLDER_LIST_STORE_NAME_COLUMN,
new_name,
@@ -1042,10 +1044,70 @@ update_children_names (GtkTreeModel *model, TnyFolder *folder, const gchar *name
g_object_unref (iterator);
g_object_unref (children);
}
+static void
+update_folder_name (GtkTreeModel *model, TnyFolder *folder, GtkTreeIter *iter, gboolean update_children)
+{
+ GtkTreeIter parent_iter;
+ gchar *name = NULL;
+ TnyGtkFolderListStore *self = TNY_GTK_FOLDER_LIST_STORE (model);
+
+ if (self->flags & TNY_GTK_FOLDER_LIST_STORE_FLAG_SHOW_PATH) {
+ if (find_parent (model, folder, &parent_iter)) {
+ gchar *parent_name;
+ gtk_tree_model_get (model, &parent_iter,
+ TNY_GTK_FOLDER_LIST_STORE_NAME_COLUMN,
+ &parent_name, -1);
+ if (parent_name && parent_name[0] == '\0')
+ name = g_strconcat (parent_name, self->path_separator,
+ tny_folder_get_name (TNY_FOLDER (folder)),
+ NULL);
+ g_free (parent_name);
+ }
+ }
+
+ if (name == NULL)
+ name = g_strdup (tny_folder_get_name (TNY_FOLDER (folder)));
+
+ gtk_list_store_set (GTK_LIST_STORE (model), iter,
+ TNY_GTK_FOLDER_LIST_STORE_NAME_COLUMN,
+ name,
+ -1);
+ if (update_children &&
+ (self->flags & TNY_GTK_FOLDER_LIST_STORE_FLAG_SHOW_PATH)) {
+ update_children_names (model, folder, name);
+ }
+ g_free (name);
+}
+
+static void
+update_names (TnyGtkFolderListStore *self)
+{
+ GtkTreeIter iter;
+
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self), &iter))
+ return;
+
+ do {
+ TnyFolderStore *store;
+ gtk_tree_model_get (GTK_TREE_MODEL (self), &iter,
+ TNY_GTK_FOLDER_LIST_STORE_INSTANCE_COLUMN,
+ &store, -1);
+
+ if (TNY_IS_FOLDER (store)) {
+ update_folder_name (GTK_TREE_MODEL (self),
+ TNY_FOLDER (store),
+ &iter,
+ FALSE /*don't update children*/);
+ }
+ g_object_unref (store);
+
+ } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self), &iter));
+}
+
static gboolean
updater (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data1)
{
TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
@@ -1109,43 +1171,11 @@ updater (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer use
unread,
TNY_GTK_FOLDER_LIST_STORE_ALL_COLUMN,
total, -1);
if (changed & TNY_FOLDER_CHANGE_CHANGED_FOLDER_RENAME) {
- GtkTreeIter parent_iter;
- gchar *name = NULL;
-
- if (TNY_GTK_FOLDER_LIST_STORE (model)->flags &
- TNY_GTK_FOLDER_LIST_STORE_FLAG_SHOW_PATH) {
- if (find_parent (model, folder, &parent_iter)) {
- gchar *parent_name;
- gtk_tree_model_get (model, &parent_iter,
- TNY_GTK_FOLDER_LIST_STORE_NAME_COLUMN,
- &parent_name, -1);
- if (parent_name && parent_name[0] == '\0')
- name = g_strconcat (parent_name, PATH_SEPARATOR,
- tny_folder_get_name (TNY_FOLDER (folder)),
- NULL);
- g_free (parent_name);
-
-
- }
- }
-
-
- if (name == NULL)
- name = g_strdup (tny_folder_get_name (TNY_FOLDER (folder)));
-
- gtk_list_store_set (GTK_LIST_STORE (model), iter,
- TNY_GTK_FOLDER_LIST_STORE_NAME_COLUMN,
- name,
- -1);
- if (TNY_GTK_FOLDER_LIST_STORE (model)->flags &
- TNY_GTK_FOLDER_LIST_STORE_FLAG_SHOW_PATH) {
- update_children_names (model, folder, name);
- }
- g_free (name);
+ update_folder_name (model, folder, iter, TRUE /*update children*/);
}
}
g_object_unref (folder);
}
@@ -1283,11 +1313,11 @@ creater (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *in_iter, gpointer
the gtktreestore infrastructure. */
if (TNY_GTK_FOLDER_LIST_STORE (self)->flags &
TNY_GTK_FOLDER_LIST_STORE_FLAG_SHOW_PATH) {
if (parent_name && *parent_name != '\0')
- finalname = g_strconcat (parent_name, PATH_SEPARATOR,
+ finalname = g_strconcat (parent_name, self->path_separator,
tny_folder_get_name (TNY_FOLDER (folder)), NULL);
else
finalname = g_strdup (tny_folder_get_name (TNY_FOLDER (folder)));
} else {
finalname = g_strdup (tny_folder_get_name (TNY_FOLDER (folder)));
@@ -1323,10 +1353,36 @@ creater (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *in_iter, gpointer
g_object_unref (parent_store);
return found;
}
+void
+tny_gtk_folder_list_store_set_path_separator (TnyGtkFolderListStore *self,
+ const gchar *separator)
+{
+ g_return_if_fail (TNY_IS_GTK_FOLDER_LIST_STORE (self));
+
+ if (separator == NULL)
+ separator = "";
+
+ g_free (self->path_separator);
+
+ self->path_separator = g_strdup (separator);
+
+ if (self->flags & TNY_GTK_FOLDER_LIST_STORE_FLAG_SHOW_PATH)
+ update_names (self);
+}
+
+const gchar *
+tny_gtk_folder_list_store_get_path_separator (TnyGtkFolderListStore *self)
+{
+ g_return_val_if_fail (TNY_IS_GTK_FOLDER_LIST_STORE (self), NULL);
+
+ return self->path_separator;
+}
+
+
static void
tny_gtk_folder_list_store_folder_obsr_update (TnyFolderObserver *self, TnyFolderChange *change)
{
diff --git a/libtinymailui-gtk/tny-gtk-folder-list-store.h b/libtinymailui-gtk/tny-gtk-folder-list-store.h
index e03dee8..e6ba754 100644
--- a/libtinymailui-gtk/tny-gtk-folder-list-store.h
+++ b/libtinymailui-gtk/tny-gtk-folder-list-store.h
@@ -69,10 +69,11 @@ struct _TnyGtkFolderListStore
TnyFolderStoreQuery *query;
gboolean first_needs_unref;
GPtrArray *signals;
TnyGtkFolderListStoreFlags flags;
+ gchar *path_separator;
};
struct _TnyGtkFolderListStoreClass
{
GtkTreeStoreClass parent_class;
@@ -81,10 +82,12 @@ struct _TnyGtkFolderListStoreClass
GType tny_gtk_folder_list_store_get_type (void);
GType tny_gtk_folder_list_store_column_get_type (void);
GtkTreeModel* tny_gtk_folder_list_store_new (TnyFolderStoreQuery *query);
GtkTreeModel* tny_gtk_folder_list_store_new_with_flags (TnyFolderStoreQuery *query,
TnyGtkFolderListStoreFlags flags);
+void tny_gtk_folder_list_store_set_path_separator (TnyGtkFolderListStore *self, const gchar *separator);
+const gchar *tny_gtk_folder_list_store_get_path_separator (TnyGtkFolderListStore *self);
void tny_gtk_folder_list_store_prepend (TnyGtkFolderListStore *self, TnyFolderStore* item, const gchar *root_name);
void tny_gtk_folder_list_store_append (TnyGtkFolderListStore *self, TnyFolderStore* item, const gchar *root_name);
G_END_DECLS
--
1.5.6.3
--=-EFtQ+AiGF094LeYEhGHs--
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]