[bijiben] bijiCollection: have a urn as key
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] bijiCollection: have a urn as key
- Date: Thu, 2 May 2013 22:44:47 +0000 (UTC)
commit b5066fe307f4d2f085fda24c66835d2b9a7832d9
Author: Pierre-Yves Luyten <py luyten fr>
Date: Fri May 3 00:23:49 2013 +0200
bijiCollection: have a urn as key
Tracker always needs these urn and the book, too
Collections are unique while title, not.
src/bjb-controller.c | 31 ++++++++++------------
src/bjb-controller.h | 4 +-
src/bjb-main-toolbar.c | 15 ++++++-----
src/bjb-main-view.c | 22 ++++++++-------
src/libbiji/biji-collection.c | 50 ++++++++++++++++++++++++-----------
src/libbiji/biji-collection.h | 2 +-
src/libbiji/biji-note-book.c | 57 ++++++++++++++++++++++++++--------------
7 files changed, 108 insertions(+), 73 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index 33fe0ce..e0e7989 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -32,18 +32,18 @@
struct _BjbControllerPrivate
{
- BijiNoteBook *book ;
- gchar *needle ;
- gchar *collection;
- GtkTreeModel *model ;
- GtkTreeModel *completion;
+ BijiNoteBook *book ;
+ gchar *needle ;
+ BijiCollection *collection;
+ GtkTreeModel *model ;
+ GtkTreeModel *completion;
- BjbWindowBase *window;
+ BjbWindowBase *window;
/* Private */
GList *items_to_show;
- gboolean connected;
- gulong book_change;
+ gboolean connected;
+ gulong book_change;
};
enum {
@@ -723,7 +723,7 @@ bjb_controller_show_collection (GObject *source_object,
bjb_window_base_switch_to (self->priv->window, BJB_WINDOW_BASE_MAIN_VIEW);
}
-gchar *
+BijiCollection *
bjb_controller_get_collection (BjbController *self)
{
return self->priv->collection;
@@ -731,16 +731,16 @@ bjb_controller_get_collection (BjbController *self)
void
bjb_controller_set_collection (BjbController *self,
- gchar *to_open)
+ BijiCollection *coll)
{
/* Going back from a collection */
- if (!to_open)
+ if (!coll)
{
if (!self->priv->collection)
return;
bjb_window_base_switch_to (self->priv->window, BJB_WINDOW_BASE_SPINNER_VIEW);
- g_clear_pointer (&self->priv->collection, g_free);
+ self->priv->collection = NULL;
bjb_controller_apply_needle (self);
bjb_window_base_switch_to (self->priv->window, BJB_WINDOW_BASE_MAIN_VIEW);
return;
@@ -753,12 +753,9 @@ bjb_controller_set_collection (BjbController *self,
if (self->priv->needle)
g_free (self->priv->needle);
- if (self->priv->collection)
- g_free (self->priv->collection);
-
self->priv->needle = g_strdup ("");
- self->priv->collection = g_strdup (to_open);
- biji_get_items_with_collection_async (to_open,
+ self->priv->collection = coll;
+ biji_get_items_with_collection_async (biji_item_get_title (BIJI_ITEM (coll)),
bjb_controller_show_collection,
self);
}
diff --git a/src/bjb-controller.h b/src/bjb-controller.h
index 6157a39..7cbbc9a 100644
--- a/src/bjb-controller.h
+++ b/src/bjb-controller.h
@@ -76,9 +76,9 @@ void bjb_controller_disconnect (BjbController *self);
gboolean bjb_controller_shows_item (BjbController *self);
-gchar * bjb_controller_get_collection (BjbController *self);
+BijiCollection * bjb_controller_get_collection (BjbController *self);
-void bjb_controller_set_collection (BjbController *self, gchar *to_open);
+void bjb_controller_set_collection (BjbController *self, BijiCollection *coll);
G_END_DECLS
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index f91d8bd..a821a71 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -274,13 +274,14 @@ static void
update_label_for_standard (BjbMainToolbar *self)
{
BjbMainToolbarPrivate *priv = self->priv;
- gchar *collection, *needle, *label;
+ BijiCollection *coll;
+ gchar *needle, *label;
- collection = bjb_controller_get_collection (priv->controller);
+ coll = bjb_controller_get_collection (priv->controller);
needle = bjb_controller_get_needle (priv->controller);
- if (collection)
- label = g_strdup_printf ("%s", collection);
+ if (coll)
+ label = g_strdup_printf ("%s", biji_item_get_title (BIJI_ITEM (coll)));
else if (needle && g_strcmp0 (needle, "") !=0)
label = g_strdup_printf (_("Results for %s"), needle);
@@ -321,7 +322,7 @@ populate_bar_for_standard(BjbMainToolbar *self)
{
BjbMainToolbarPrivate *priv = self->priv;
GtkWidget *bin = NULL;
- gchar *collection;
+ BijiCollection *coll;
/* Label */
update_label_for_standard (self);
@@ -329,9 +330,9 @@ populate_bar_for_standard(BjbMainToolbar *self)
"search-changed", G_CALLBACK(update_label_for_standard), self);
/* Go back to all notes */
- collection = bjb_controller_get_collection (priv->controller);
+ coll = bjb_controller_get_collection (priv->controller);
- if (collection)
+ if (coll)
{
GtkWidget *back, *button;
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 2929715..3ab1de4 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -197,7 +197,7 @@ show_window_if_note (gpointer data, gpointer user_data)
}
static void
-switch_to_note (BjbMainView *view, BijiItem *to_open)
+switch_to_item (BjbMainView *view, BijiItem *to_open)
{
if (BIJI_IS_NOTE_OBJ (to_open))
{
@@ -217,10 +217,10 @@ switch_to_note (BjbMainView *view, BijiItem *to_open)
/* Collection
* TODO : check if already opened (same as above) */
- else
+ else if (BIJI_IS_COLLECTION (to_open))
{
bjb_controller_set_collection (view->priv->controller,
- biji_item_get_title (to_open));
+ BIJI_COLLECTION (to_open));
}
}
@@ -407,19 +407,21 @@ on_item_activated (GdMainView * gd,
BijiNoteBook * book ;
BijiItem * to_open ;
GtkTreeIter iter ;
- gchar * note_path ;
+ gchar * item_path ;
GtkTreeModel * model ;
- /* Get Note Path */
+ /* Get Item Path */
model = gd_main_view_get_model (gd);
gtk_tree_model_get_iter (model, &iter, (GtkTreePath*) path);
- gtk_tree_model_get (model, &iter, GD_MAIN_COLUMN_URI, ¬e_path,-1);
+ gtk_tree_model_get (model, &iter, GD_MAIN_COLUMN_URI, &item_path,-1);
- /* Switch to that note */
+ /* Switch to that item */
book = bjb_window_base_get_book (view->priv->window);
- to_open = biji_note_book_get_item_at_path (book, note_path);
- g_free (note_path);
- switch_to_note (view, to_open);
+ to_open = biji_note_book_get_item_at_path (book, item_path);
+ g_free (item_path);
+
+ if (to_open)
+ switch_to_item (view, to_open);
return FALSE ;
}
diff --git a/src/libbiji/biji-collection.c b/src/libbiji/biji-collection.c
index 22223f7..e4f1cd6 100644
--- a/src/libbiji/biji-collection.c
+++ b/src/libbiji/biji-collection.c
@@ -30,7 +30,7 @@
struct BijiCollectionPrivate_
{
- /* String is both the collection title & uuid */
+ gchar * urn;
gchar * name;
};
@@ -41,6 +41,7 @@ G_DEFINE_TYPE (BijiCollection, biji_collection, BIJI_TYPE_ITEM)
/* Properties */
enum {
PROP_0,
+ PROP_URN,
PROP_NAME,
BIJI_COLL_PROPERTIES
};
@@ -66,7 +67,7 @@ biji_collection_get_uuid (BijiItem *coll)
g_return_val_if_fail (BIJI_IS_COLLECTION (coll), NULL);
collection = BIJI_COLLECTION (coll);
- return g_strdup (collection->priv->name);
+ return g_strdup (collection->priv->urn);
}
GdkPixbuf *
@@ -231,12 +232,15 @@ biji_collection_set_property (GObject *object,
switch (property_id)
{
- case PROP_NAME:
- self->priv->name = g_strdup (g_value_get_string (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ case PROP_URN:
+ self->priv->urn = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_NAME:
+ self->priv->name = g_strdup (g_value_get_string (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
@@ -250,12 +254,15 @@ biji_collection_get_property (GObject *object,
switch (property_id)
{
- case PROP_NAME:
- g_value_set_string (value, self->priv->name);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
+ case PROP_URN:
+ g_value_set_string (value, self->priv->urn);
+ break;
+ case PROP_NAME:
+ g_value_set_string (value, self->priv->name);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
}
}
@@ -274,6 +281,13 @@ biji_collection_class_init (BijiCollectionClass *klass)
g_type_class_add_private ((gpointer)klass, sizeof (BijiCollectionPrivate));
+ properties[PROP_URN] =
+ g_param_spec_string ("urn",
+ "Collection URN",
+ "Collection URN as in Tracker",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
properties[PROP_NAME] =
g_param_spec_string ("name",
"Collection label",
@@ -304,6 +318,7 @@ biji_collection_finalize (GObject *object)
self = BIJI_COLLECTION (object);
g_free (self->priv->name);
+ g_free (self->priv->urn);
G_OBJECT_CLASS (biji_collection_parent_class)->finalize (object);
}
@@ -317,7 +332,10 @@ biji_collection_init (BijiCollection *self)
BijiCollection *
-biji_collection_new (gchar *name)
+biji_collection_new (gchar *urn, gchar *name)
{
- return g_object_new (BIJI_TYPE_COLLECTION, "name", name, NULL);
+ return g_object_new (BIJI_TYPE_COLLECTION,
+ "name", name,
+ "urn", urn,
+ NULL);
}
diff --git a/src/libbiji/biji-collection.h b/src/libbiji/biji-collection.h
index 5385bc5..7ba137d 100644
--- a/src/libbiji/biji-collection.h
+++ b/src/libbiji/biji-collection.h
@@ -52,7 +52,7 @@ struct BijiCollectionClass_
GType biji_collection_get_type (void);
-BijiCollection * biji_collection_new (gchar *name);
+BijiCollection * biji_collection_new (gchar *urn, gchar *name);
G_END_DECLS
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 0f85c30..299c75e 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -194,7 +194,6 @@ book_on_note_color_changed_cb (BijiNoteObj *note, BijiNoteBook *book)
static void
_biji_note_book_add_one_note (BijiNoteBook *book, BijiNoteObj *note)
{
- GList *collections, *l;
g_return_if_fail (BIJI_IS_NOTE_OBJ (note));
_biji_note_obj_set_book (note, (gpointer) book);
@@ -203,24 +202,6 @@ _biji_note_book_add_one_note (BijiNoteBook *book, BijiNoteObj *note)
g_hash_table_insert (book->priv->items,
biji_item_get_uuid (BIJI_ITEM (note)), note);
- /* Check for new collections */
- collections = biji_note_obj_get_collections (note);
-
- for (l = collections ; l != NULL; l = l->next)
- {
- BijiCollection *collection;
-
- collection = g_hash_table_lookup (book->priv->items, l->data);
-
- if (!collection)
- {
- collection = biji_collection_new ((gchar*) l->data);
- g_hash_table_insert (book->priv->items,
- biji_item_get_uuid (BIJI_ITEM (collection)),
- collection);
- }
- }
-
/* Notify */
g_signal_connect (note, "changed", G_CALLBACK (book_on_note_changed_cb), book);
g_signal_connect (note, "renamed", G_CALLBACK (book_on_note_changed_cb), book);
@@ -250,6 +231,40 @@ release_enum_cb (GObject *source, GAsyncResult *res, gpointer user_data)
}
static void
+create_collection_if_needed (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ BijiNoteBook *book = BIJI_NOTE_BOOK (user_data);
+ BijiCollection *collection;
+
+ collection = g_hash_table_lookup (book->priv->items, key);
+
+ if (!collection)
+ {
+ collection = biji_collection_new (key, value);
+ g_hash_table_insert (book->priv->items,
+ g_strdup (key),
+ collection);
+ }
+}
+
+static void
+load_book_finish (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ BijiNoteBook *self = BIJI_NOTE_BOOK (user_data);
+ GHashTable *collections;
+
+ collections = biji_get_all_collections_finish (source_object, res);
+ g_hash_table_foreach (collections, create_collection_if_needed, user_data);
+ g_hash_table_destroy (collections);
+
+ biji_note_book_notify_changed (self, BIJI_BOOK_MASS_CHANGE, NULL);
+}
+
+static void
enumerate_next_files_ready_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
@@ -298,7 +313,9 @@ enumerate_next_files_ready_cb (GObject *source,
g_free (base_path);
g_list_free_full (files, g_object_unref);
- biji_note_book_notify_changed (self, BIJI_BOOK_MASS_CHANGE, NULL);
+ /* Now we have all notes,
+ * load the collections and we're good to notify loading done */
+ biji_get_all_collections_async (load_book_finish, self);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]