[bijiben] Collections: fix icon refresh
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] Collections: fix icon refresh
- Date: Mon, 13 May 2013 01:11:13 +0000 (UTC)
commit b0a4ce83e2a19f95078cdc02656e25b8ef8b25b1
Author: Pierre-Yves Luyten <py luyten fr>
Date: Mon May 13 02:11:48 2013 +0200
Collections: fix icon refresh
Always use an URN to add a collection on user response.
The biji_item_add_collection is responsible for
refreshing the collection itself afterward
src/bjb-note-tag-dialog.c | 36 ++++++++++++++-------
src/libbiji/biji-collection.c | 7 +++-
src/libbiji/biji-collection.h | 4 ++
src/libbiji/biji-item.c | 4 +-
src/libbiji/biji-item.h | 12 +++++--
src/libbiji/biji-note-obj.c | 26 ++++++++++-----
src/libbiji/biji-tracker.c | 23 ++++++++-----
src/libbiji/biji-tracker.h | 14 ++++++--
src/libbiji/deserializer/biji-lazy-deserializer.c | 2 +-
9 files changed, 88 insertions(+), 40 deletions(-)
---
diff --git a/src/bjb-note-tag-dialog.c b/src/bjb-note-tag-dialog.c
index 2978411..bf19c9d 100644
--- a/src/bjb-note-tag-dialog.c
+++ b/src/bjb-note-tag-dialog.c
@@ -203,9 +203,10 @@ update_collections_model_async (BjbNoteTagDialog *self)
/* Libbiji handles tracker & saving */
static void
-note_dialog_add_tag (gpointer iter, gpointer collection)
+note_dialog_add_collection (gpointer iter, gpointer user_data)
{
- biji_item_add_collection (BIJI_ITEM (iter), (gchar*) collection, TRUE);
+ g_return_if_fail (BIJI_IS_COLLECTION (user_data));
+ biji_item_add_collection (iter, user_data, NULL);
}
@@ -235,6 +236,8 @@ on_tag_toggled (GtkCellRendererToggle *cell,
gint toggle_item;
gint *column;
gchar *tag;
+ BijiNoteBook *book;
+ BijiItem *collection;
column = g_object_get_data (G_OBJECT (cell), "column");
gtk_tree_model_get_iter (model, &iter, path);
@@ -242,17 +245,22 @@ on_tag_toggled (GtkCellRendererToggle *cell,
gtk_tree_model_get (model, &iter, COL_URN, &tag, -1);
priv->toggled_collection = tag;
+ book = bjb_window_base_get_book (GTK_WIDGET (self->priv->window));
+ collection = biji_note_book_get_item_at_path (book, tag);
- if (toggle_item == SELECTION_INCONSISTENT || toggle_item == SELECTION_FALSE)
+ if (BIJI_IS_COLLECTION (collection))
{
- g_list_foreach (priv->items, note_dialog_add_tag, tag);
- toggle_item = SELECTION_TRUE;
- }
+ if (toggle_item == SELECTION_INCONSISTENT || toggle_item == SELECTION_FALSE)
+ {
+ g_list_foreach (priv->items, note_dialog_add_collection, collection);
+ toggle_item = SELECTION_TRUE;
+ }
- else
- {
- g_list_foreach (priv->items, note_dialog_remove_tag, self);
- toggle_item = SELECTION_FALSE;
+ else
+ {
+ g_list_foreach (priv->items, note_dialog_remove_tag, self);
+ toggle_item = SELECTION_FALSE;
+ }
}
priv->toggled_collection = NULL;
@@ -260,14 +268,18 @@ on_tag_toggled (GtkCellRendererToggle *cell,
gtk_tree_path_free (path);
}
+
+/* If the collection with same title already existed,
+ * libbiji has to avoid creating a new one
+ * and also check before tagging items */
static void
-on_new_collection_created_cb (gpointer user_data)
+on_new_collection_created_cb (BijiItem *coll, gpointer user_data)
{
BjbNoteTagDialog *self = user_data;
BjbNoteTagDialogPrivate *priv = self->priv;
priv->tag_to_scroll_to = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry)));
- g_list_foreach (priv->items, note_dialog_add_tag, priv->tag_to_scroll_to);
+ g_list_foreach (priv->items, note_dialog_add_collection, coll);
update_collections_model_async (self);
gtk_entry_set_text (GTK_ENTRY (priv->entry), "");
diff --git a/src/libbiji/biji-collection.c b/src/libbiji/biji-collection.c
index 249765b..804cdb3 100644
--- a/src/libbiji/biji-collection.c
+++ b/src/libbiji/biji-collection.c
@@ -276,7 +276,7 @@ biji_collection_has_collection (BijiItem *item, gchar *collection)
static gboolean
-biji_collection_add_collection (BijiItem *item, gchar *collection, gboolean notify)
+biji_collection_add_collection (BijiItem *item, BijiItem *coll, gchar *title)
{
g_warning ("biji collection add collection is not implemented.");
return FALSE;
@@ -399,6 +399,11 @@ biji_collection_update_collected (GObject *source_object,
g_signal_emit (self, biji_collections_signals[COLLECTION_ICON_UPDATED], 0);
}
+void
+biji_collection_refresh (BijiCollection *collection)
+{
+ on_collected_item_change (collection);
+}
static void
biji_collection_constructed (GObject *obj)
diff --git a/src/libbiji/biji-collection.h b/src/libbiji/biji-collection.h
index e227a63..88cf9bb 100644
--- a/src/libbiji/biji-collection.h
+++ b/src/libbiji/biji-collection.h
@@ -57,6 +57,10 @@ GType biji_collection_get_type (void);
* see biji_create_new_collection_async */
BijiCollection * biji_collection_new (GObject *book, gchar *urn, gchar *name, gchar *mtime);
+
+/* Watching for tracker would be best. Right now manually called. */
+void biji_collection_refresh (BijiCollection *collection);
+
G_END_DECLS
#endif /* BIJI_COLLECTION_H_ */
diff --git a/src/libbiji/biji-item.c b/src/libbiji/biji-item.c
index ee5da43..607c9c3 100644
--- a/src/libbiji/biji-item.c
+++ b/src/libbiji/biji-item.c
@@ -107,9 +107,9 @@ biji_item_has_collection (BijiItem *item, gchar *coll)
return BIJI_ITEM_GET_CLASS (item)->has_collection (item, coll);
}
-gboolean biji_item_add_collection (BijiItem *item, gchar *coll, gboolean on_user_action)
+gboolean biji_item_add_collection (BijiItem *item, BijiItem *coll, gchar *title)
{
- return BIJI_ITEM_GET_CLASS (item)->add_collection (item, coll, on_user_action);
+ return BIJI_ITEM_GET_CLASS (item)->add_collection (item, coll, title);
}
gboolean biji_item_remove_collection (BijiItem *item, gchar *coll, gchar *urn)
diff --git a/src/libbiji/biji-item.h b/src/libbiji/biji-item.h
index 39f7b91..75f634d 100644
--- a/src/libbiji/biji-item.h
+++ b/src/libbiji/biji-item.h
@@ -65,7 +65,7 @@ struct BijiItemClass_
gint64 (*get_mtime) (BijiItem *item);
gboolean (*trash) (BijiItem *item);
gboolean (*has_collection) (BijiItem *item, gchar *coll);
- gboolean (*add_collection) (BijiItem *item, gchar *coll, gboolean on_user_action);
+ gboolean (*add_collection) (BijiItem *item, BijiItem *coll, gchar *title);
gboolean (*remove_collection) (BijiItem *item, gchar *coll, gchar *urn);
};
@@ -103,11 +103,17 @@ gboolean biji_item_trash (BijiItem *item);
gboolean biji_item_has_collection (BijiItem *item, gchar *collection);
-/* add_collection / on_user_action : thus biji_item does notify */
+/* Add Collection:
+ * either provide an existing collection object
+ * or a title, in which case it's considered not on user action
+ * and no notifiy happens */
-gboolean biji_item_add_collection (BijiItem *item, gchar *coll, gboolean on_user_action);
+gboolean biji_item_add_collection (BijiItem *item, BijiItem *collection, gchar *title);
+/* Remove Collection:
+ * always on user action. */
+
gboolean biji_item_remove_collection (BijiItem *item, gchar *coll, gchar *urn);
G_END_DECLS
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 5cf339b..0ea690e 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -540,21 +540,29 @@ biji_note_obj_has_collection (BijiItem *item, gchar *label)
return FALSE;
}
-gboolean
-biji_note_obj_add_collection (BijiItem *item, gchar *label, gboolean on_user_action_cb)
+/*static */ gboolean
+biji_note_obj_add_collection (BijiItem *item,
+ BijiItem *collection,
+ gchar *title)
{
+ BijiNoteObj *note;
+ gchar *label = title;
+
g_return_val_if_fail (BIJI_IS_NOTE_OBJ (item), FALSE);
- g_return_val_if_fail (label != NULL, FALSE);
- g_return_val_if_fail (!biji_note_obj_has_collection (item, label), FALSE);
+ note = BIJI_NOTE_OBJ (item);
- BijiNoteObj *note = BIJI_NOTE_OBJ (item);
- gchar *tag = g_strdup (label);
+ if (BIJI_IS_COLLECTION (collection))
+ label = (gchar*) biji_item_get_title (collection);
+
+ if (biji_note_obj_has_collection (item, label))
+ return FALSE;
- g_hash_table_add (note->priv->labels, tag);
+ g_hash_table_add (note->priv->labels, g_strdup (label));
- if (on_user_action_cb)
+ if (BIJI_IS_COLLECTION (collection))
{
- biji_push_existing_collection_to_note (note, tag); // Tracker
+ biji_push_existing_collection_to_note (
+ note, label, (BijiFunc) biji_collection_refresh, collection); // Tracker
biji_note_id_set_last_metadata_change_date_now (note->priv->id);
biji_note_obj_save_note (note);
}
diff --git a/src/libbiji/biji-tracker.c b/src/libbiji/biji-tracker.c
index 41ab6b1..5c518a7 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -29,6 +29,7 @@ typedef struct {
/* after the query */
BijiFunc func;
+ BijiCallback callback;
gpointer user_data;
} BijiTrackerFinisher;
@@ -37,6 +38,7 @@ static BijiTrackerFinisher *
biji_tracker_finisher_new (BijiNoteBook *book,
gchar *str,
BijiFunc f,
+ BijiCallback callback,
gpointer user_data)
{
BijiTrackerFinisher *retval = g_new (BijiTrackerFinisher, 1);
@@ -44,6 +46,7 @@ biji_tracker_finisher_new (BijiNoteBook *book,
retval->book = book;
retval->str = str;
retval->func = f;
+ retval->callback = callback;
retval->user_data = user_data;
return retval;
@@ -132,7 +135,7 @@ biji_finish_update (GObject *source_object,
static void
biji_perform_update_async_and_free (gchar *query, BijiFunc f, gpointer user_data)
{
- BijiTrackerFinisher *finisher = biji_tracker_finisher_new (NULL, query, f, user_data);
+ BijiTrackerFinisher *finisher = biji_tracker_finisher_new (NULL, query, f, NULL, user_data);
tracker_sparql_connection_update_async (get_connection_singleton(),
query,
@@ -365,6 +368,7 @@ on_new_collection_query_executed (GObject *source_object, GAsyncResult *res, gpo
gchar *key = NULL;
gchar *val = NULL;
gchar *urn = NULL;
+ BijiCollection *collection = NULL;
error = NULL;
variant = tracker_sparql_connection_update_blank_finish (connection, res, &error);
@@ -412,8 +416,6 @@ on_new_collection_query_executed (GObject *source_object, GAsyncResult *res, gpo
tv.tv_usec = 0;
time = g_time_val_to_iso8601 (&tv);
- BijiCollection *collection;
-
collection = biji_collection_new (
G_OBJECT (finisher->book),
urn,
@@ -425,8 +427,8 @@ on_new_collection_query_executed (GObject *source_object, GAsyncResult *res, gpo
/* Run the callback from the caller */
out:
- if (finisher->func != NULL)
- (*finisher->func) (finisher->user_data);
+ if (finisher->callback != NULL)
+ (*finisher->callback) (BIJI_ITEM (collection), finisher->user_data);
g_free (val);
g_free (key);
@@ -439,7 +441,7 @@ on_new_collection_query_executed (GObject *source_object, GAsyncResult *res, gpo
void
biji_create_new_collection_async (BijiNoteBook *book,
const gchar *name,
- BijiFunc afterward,
+ BijiCallback afterward,
gpointer user_data)
{
gchar *query;
@@ -463,7 +465,7 @@ biji_create_new_collection_async (BijiNoteBook *book,
/* The finisher has all the pointers we want.
* And the callback will free it */
- finisher = biji_tracker_finisher_new (book, g_strdup (name), afterward, user_data);
+ finisher = biji_tracker_finisher_new (book, g_strdup (name), NULL, afterward, user_data);
tracker_sparql_connection_update_blank_async (get_connection_singleton (),
query,
G_PRIORITY_DEFAULT,
@@ -482,13 +484,16 @@ biji_remove_collection_from_tracker (const gchar *urn)
}
void
-biji_push_existing_collection_to_note (BijiNoteObj *note, gchar *title)
+biji_push_existing_collection_to_note (BijiNoteObj *note,
+ gchar *title,
+ BijiFunc afterward,
+ gpointer user_data)
{
gchar *url = get_note_url (note);
gchar *query = g_strdup_printf ("INSERT {?urn nie:isPartOf '%s'} WHERE {?urn a nfo:DataContainer;
nie:title '%s'; nie:generator 'Bijiben'}",
url, title);
- biji_perform_update_async_and_free (query, NULL, NULL);
+ biji_perform_update_async_and_free (query, afterward, user_data);
g_free (url);
}
diff --git a/src/libbiji/biji-tracker.h b/src/libbiji/biji-tracker.h
index 19cf873..3fa6ce6 100644
--- a/src/libbiji/biji-tracker.h
+++ b/src/libbiji/biji-tracker.h
@@ -41,9 +41,14 @@ typedef struct
} BijiTrackerInfoSet;
-/* todo : find this on glib */
+
typedef void (*BijiFunc) (gpointer user_data);
+typedef void (*BijiCallback) (BijiItem *item, gpointer user_data);
+
+
+
+
GList * biji_get_items_with_collection_finish (GObject *source_object,
GAsyncResult *res,
BijiNoteBook *book);
@@ -68,12 +73,15 @@ GHashTable * biji_get_all_collections_finish (GObject *source_object, GAsyncResu
void biji_get_all_collections_async (GAsyncReadyCallback f, gpointer user_data);
-void biji_create_new_collection_async (BijiNoteBook *book, const gchar *tag, BijiFunc afterward, gpointer
user_data);
+void biji_create_new_collection_async (BijiNoteBook *book, const gchar *tag, BijiCallback afterward,
gpointer user_data);
void biji_remove_collection_from_tracker (const gchar *urn);
// when adding an existing collection, use the collection title
-void biji_push_existing_collection_to_note (BijiNoteObj *note, gchar *title);
+void biji_push_existing_collection_to_note (BijiNoteObj *note,
+ gchar *title,
+ BijiFunc callback,
+ gpointer user_data);
// when removing, use the urn
void biji_remove_collection_from_note (BijiNoteObj *note, gchar *urn);
diff --git a/src/libbiji/deserializer/biji-lazy-deserializer.c
b/src/libbiji/deserializer/biji-lazy-deserializer.c
index 0f291f9..09dbd9f 100644
--- a/src/libbiji/deserializer/biji-lazy-deserializer.c
+++ b/src/libbiji/deserializer/biji-lazy-deserializer.c
@@ -492,7 +492,7 @@ processNode (BijiLazyDeserializer *self)
{
norm = g_string_new (tag);
g_string_erase (norm,0,16);
- biji_item_add_collection (BIJI_ITEM (n), norm->str, FALSE);
+ biji_item_add_collection (BIJI_ITEM (n), NULL, norm->str);
g_string_free (norm, TRUE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]