310
311
koto_group_store_add_new_group (KotoGroupStore *store, GtkTreeIter *iter, const char *name)
312
313
KotoGroupStorePrivate *priv;
314
GtkTreeIter *current_it, new_it;
314
315
g_return_if_fail (KOTO_IS_GROUP_STORE (store));
315
316
g_return_if_fail (name);
317
318
priv = GET_PRIVATE (store);
319
it = g_hash_table_lookup (priv->iter_hash, name);
320
current_it = g_hash_table_lookup (priv->iter_hash, name);
322
if (iter) *iter = *current_it;
323
324
gtk_list_store_insert_with_values (GTK_LIST_STORE (store),
325
326
COL_TYPE, GROUP_TYPE_CATEGORY,
328
g_hash_table_insert (priv->iter_hash, g_strdup (name), gtk_tree_iter_copy (iter));
329
g_hash_table_insert (priv->iter_hash, g_strdup (name), gtk_tree_iter_copy (&new_it));
331
if (iter) *iter = new_it;
335
/* Helper struct for koto_group_store_match_group */
341
/* Helper function for koto_group_store_match_group */
343
find_group (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
345
MatchData *data = user_data;
349
gtk_tree_model_get (model, iter,
354
if (type != GROUP_TYPE_CATEGORY) {
359
if (e_util_utf8_strstrcasedecomp (name, data->guess)) {
369
* koto_group_store_match_group:
370
* @store: A #KotoGroupStore.
371
* @guess: The group name to search for.
373
* Seach the groups for a group named roughly @guess. If one is found, return
374
* it as a newly allocated string, otherwise return NULL.
376
* Currently "named roughly" means case-insensitive stripped decomposed
380
koto_group_store_match_group (KotoGroupStore *store, const char *guess)
384
g_return_val_if_fail (KOTO_IS_GROUP_STORE (store), NULL);
385
g_return_val_if_fail (guess, NULL);
390
gtk_tree_model_foreach (GTK_TREE_MODEL (store), find_group, &data);
401
int main (int argc, char **argv)
403
KotoGroupStore *store;
408
store = (KotoGroupStore*)koto_group_store_new
409
(KOTO_GROUP_STORE_TYPE_FILTER, NULL);
412
koto_group_store_add_new_group (store, NULL, "Foo");
413
koto_group_store_add_new_group (store, NULL, "Bar");
415
g_assert (koto_group_store_get_iter_for_group (store, "Foo", &iter));
416
g_assert (koto_group_store_get_iter_for_group (store, "Bar", &iter));
417
g_assert (koto_group_store_get_iter_for_group (store, "Flob", &iter) == FALSE);
419
g_assert (koto_group_store_match_group (store, "Flob") == NULL);
420
g_assert (strcmp (koto_group_store_match_group (store, "Foo"), "Foo") == 0);
421
g_assert (strcmp (koto_group_store_match_group (store, "foo"), "Foo") == 0);
422
g_assert (strcmp (koto_group_store_match_group (store, "baR"), "Bar") == 0);