+static gint foldersel_folder_name_compare(GtkTreeModel *model,
+ GtkTreeIter *a,
+ GtkTreeIter *b,
+ gpointer context)
+{
+ gchar *str_a = NULL, *str_b = NULL;
+ gint res = 0;
+ FolderItem *fld_a = NULL, *fld_b = NULL;
+ GtkTreeIter parent;
+
+ gtk_tree_model_get(model, a,
+ FOLDERSEL_FOLDERITEM, &fld_a,
+ -1);
+ gtk_tree_model_get(model, b,
+ FOLDERSEL_FOLDERITEM, &fld_b,
+ -1);
+
+ /* no sort for root folder */
+ if (!gtk_tree_model_iter_parent(GTK_TREE_MODEL(model), &parent, a))
+ return 0;
+
+ /* if both a and b are special folders, sort them according to
+ * their types (which is in-order). Note that this assumes that
+ * there are no multiple folders of a special type. */
+ if (fld_a->stype != F_NORMAL && fld_b->stype != F_NORMAL)
+ return fld_a->stype < fld_b->stype ? -1 : 1;
+
+ /* if b is normal folder, and a is not, b is smaller (ends up
+ * lower in the list) */
+ if (fld_a->stype != F_NORMAL && fld_b->stype == F_NORMAL)
+ return -1;
+
+ /* if b is special folder, and a is not, b is larger (ends up
+ * higher in the list) */
+ if (fld_a->stype == F_NORMAL && fld_b->stype != F_NORMAL)
+ return 1;
+
+ /* XXX g_utf8_collate_key() comparisons may speed things
+ * up when having large lists of folders */
+ gtk_tree_model_get(model, a,
+ FOLDERSEL_FOLDERNAME, &str_a,
+ -1);
+ gtk_tree_model_get(model, b,
+ FOLDERSEL_FOLDERNAME, &str_b,
+ -1);
+
+ /* otherwise just compare the folder names */
+ res = g_utf8_collate(str_a, str_b);
+
+ g_free(str_a);
+ g_free(str_b);
+
+ return res;
+}
+
+typedef struct FolderItemSearch {
+ FolderItem *item;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+} FolderItemSearch;