[bijiben] tracker: local provider use ensure_ressource
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] tracker: local provider use ensure_ressource
- Date: Tue, 27 Aug 2013 00:10:47 +0000 (UTC)
commit 22446a6f7ad76560361c45a295bc4c5f053e81f1
Author: Pierre-Yves Luyten <py luyten fr>
Date: Tue Aug 27 00:04:29 2013 +0200
tracker: local provider use ensure_ressource
Each provider will use the same func
src/libbiji/biji-local-note.c | 31 ++++++++++-
src/libbiji/biji-local-note.h | 3 +-
src/libbiji/biji-note-book.c | 14 +++--
src/libbiji/biji-note-obj.c | 13 +++--
src/libbiji/biji-tracker.c | 82 +++++-----------------------
src/libbiji/biji-tracker.h | 2 -
src/libbiji/provider/biji-local-provider.c | 25 +++++----
7 files changed, 75 insertions(+), 95 deletions(-)
---
diff --git a/src/libbiji/biji-local-note.c b/src/libbiji/biji-local-note.c
index 899f9ab..2b7c4a0 100644
--- a/src/libbiji/biji-local-note.c
+++ b/src/libbiji/biji-local-note.c
@@ -21,6 +21,8 @@
struct BijiLocalNotePrivate_
{
+ BijiProvider *provider;
+
GFile *location;
gchar *basename;
gchar *html;
@@ -57,10 +59,32 @@ local_note_set_html (BijiNoteObj *note,
void
local_note_save (BijiNoteObj *note)
{
+ const BijiProviderInfo *prov_info;
+ BijiInfoSet *info;
+ BijiItem *item;
+ BijiLocalNote *self;
+
g_return_if_fail (BIJI_IS_LOCAL_NOTE (note));
+ self = BIJI_LOCAL_NOTE (note);
+ item = BIJI_ITEM (note);
+
+ /* File save */
biji_lazy_serialize (note);
- bijiben_push_note_to_tracker (note);
+
+ /* Tracker */
+ prov_info = biji_provider_get_info (self->priv->provider);
+ info = biji_info_set_new ();
+
+ info->url = (gchar*) biji_item_get_uuid (item);
+ info->title = (gchar*) biji_item_get_title (item);
+ info->content = (gchar*) biji_note_obj_get_raw_text (note);
+ info->mtime = biji_item_get_mtime (item);
+ info->created = biji_note_obj_get_create_date (note);
+ info->datasource_urn = g_strdup (prov_info->datasource);
+
+ biji_tracker_ensure_ressource_from_info (biji_item_get_book (item),
+ info);
}
@@ -191,7 +215,9 @@ biji_local_note_class_init (BijiLocalNoteClass *klass)
BijiNoteObj *
-biji_local_note_new_from_info (BijiNoteBook *book, BijiInfoSet *set)
+biji_local_note_new_from_info (BijiProvider *provider,
+ BijiNoteBook *book,
+ BijiInfoSet *set)
{
BijiNoteID *id;
BijiNoteObj *obj;
@@ -207,6 +233,7 @@ biji_local_note_new_from_info (BijiNoteBook *book, BijiInfoSet *set)
local = BIJI_LOCAL_NOTE (obj);
local->priv->location = g_file_new_for_commandline_arg (set->url);
local->priv->basename = g_file_get_basename (local->priv->location);
+ local->priv->provider = provider;
return obj;
}
diff --git a/src/libbiji/biji-local-note.h b/src/libbiji/biji-local-note.h
index 1eb60a7..832987e 100644
--- a/src/libbiji/biji-local-note.h
+++ b/src/libbiji/biji-local-note.h
@@ -51,7 +51,8 @@ struct BijiLocalNoteClass_
GType biji_local_note_get_type (void);
-BijiNoteObj *biji_local_note_new_from_info (BijiNoteBook *book,
+BijiNoteObj *biji_local_note_new_from_info (BijiProvider *provider,
+ BijiNoteBook *book,
BijiInfoSet *set);
G_END_DECLS
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 69e40bb..65df7bf 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -29,9 +29,12 @@
struct _BijiNoteBookPrivate
{
- /* Notes & Collections */
+ /* Notes & Collections.
+ * Keep a direct pointer to local provider for convenience. */
+
GHashTable *items;
GHashTable *providers;
+ BijiProvider *local_provider;
/* Signals */
gulong note_renamed ;
@@ -396,7 +399,6 @@ biji_note_book_constructed (GObject *object)
{
BijiNoteBook *self;
BijiNoteBookPrivate *priv;
- BijiProvider *provider;
gchar *filename;
GFile *cache;
GError *error;
@@ -430,8 +432,8 @@ biji_note_book_constructed (GObject *object)
g_file_make_directory (cache, NULL, NULL);
g_object_unref (cache);
- provider = biji_local_provider_new (self, self->priv->location);
- _add_provider (self, provider);
+ priv->local_provider = biji_local_provider_new (self, self->priv->location);
+ _add_provider (self, priv->local_provider);
}
@@ -589,7 +591,7 @@ biji_note_get_new_from_file (BijiNoteBook *book, const gchar* path)
set.title = NULL;
set.content = NULL;
- ret = biji_local_note_new_from_info (book, &set);
+ ret = biji_local_note_new_from_info (book->priv->local_provider, book, &set);
biji_lazy_deserialize (ret);
return ret ;
@@ -627,7 +629,7 @@ get_note_skeleton (BijiNoteBook *book)
set.url = path;
if (!g_hash_table_lookup (book->priv->items, path))
- ret = biji_local_note_new_from_info (book, &set);
+ ret = biji_local_note_new_from_info (book->priv->local_provider, book, &set);
g_free (path);
}
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index abe5e8e..ae4d1ef 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -312,7 +312,8 @@ biji_note_obj_set_title (BijiNoteObj *note, const gchar *proposed_title)
{
title = biji_note_book_get_unique_title (
biji_item_get_book (BIJI_ITEM (note)), proposed_title);
- biji_note_id_set_last_metadata_change_date (note->priv->id, g_get_real_time ());
+ biji_note_id_set_last_metadata_change_date (note->priv->id,
+ g_get_real_time () / G_USEC_PER_SEC);
}
/* Otherwise it's up to the caller to sanitize its title */
@@ -423,7 +424,7 @@ biji_note_obj_set_rgba (BijiNoteObj *n, GdkRGBA *rgba)
biji_note_obj_clear_icons (n);
biji_note_obj_set_rgba_internal (n, rgba);
- biji_note_id_set_last_metadata_change_date (n->priv->id, g_get_real_time ());
+ biji_note_id_set_last_metadata_change_date (n->priv->id, g_get_real_time () / G_USEC_PER_SEC);
biji_note_obj_save_note (n);
}
}
@@ -514,7 +515,8 @@ biji_note_obj_add_collection (BijiItem *item,
{
biji_push_existing_collection_to_note (
note, label, _biji_collection_refresh, collection); // Tracker
- biji_note_id_set_last_metadata_change_date (note->priv->id, g_get_real_time ());
+ biji_note_id_set_last_metadata_change_date (note->priv->id,
+ g_get_real_time () / G_USEC_PER_SEC);
biji_note_obj_save_note (note);
}
@@ -534,7 +536,8 @@ biji_note_obj_remove_collection (BijiItem *item, BijiItem *collection)
{
biji_remove_collection_from_note (
note, collection, _biji_collection_refresh, collection); // tracker.
- biji_note_id_set_last_metadata_change_date (note->priv->id, g_get_real_time ());
+ biji_note_id_set_last_metadata_change_date (note->priv->id,
+ g_get_real_time () / G_USEC_PER_SEC);
biji_note_obj_save_note (note);
return TRUE;
}
@@ -771,7 +774,7 @@ biji_note_obj_set_all_dates_now (BijiNoteObj *note)
g_return_if_fail (BIJI_IS_NOTE_OBJ (note));
id = note->priv->id;
- time = g_get_real_time ();
+ time = g_get_real_time () / G_USEC_PER_SEC;
biji_note_id_set_create_date (id, time);
biji_note_id_set_last_metadata_change_date (id, time);
biji_note_id_set_mtime (id, time);
diff --git a/src/libbiji/biji-tracker.c b/src/libbiji/biji-tracker.c
index 8393aa5..e537103 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -169,14 +169,6 @@ tracker_str (const gchar * string )
}
-static gchar *
-to_8601_date( gchar * dot_iso_8601_date )
-{
- gchar *result = dot_iso_8601_date ;
- return g_strdup_printf ( "%sZ",
- g_utf8_strncpy (result ,dot_iso_8601_date, 19) );
-}
-
static gchar *
get_note_url (BijiNoteObj *note)
@@ -577,61 +569,6 @@ biji_note_delete_from_tracker (BijiNoteObj *note)
}
-void
-bijiben_push_note_to_tracker (BijiNoteObj *note)
-{
- gchar *title,*content,*file, *date, *create_date,*last_change_date;
- const gchar *path;
- GTimeVal time = {0, 0};
- BijiItem *item;
-
- g_return_if_fail (BIJI_IS_NOTE_OBJ (note));
-
- item = BIJI_ITEM (note);
- path = biji_item_get_uuid (item);
- title = tracker_str (biji_item_get_title (item));
- file = get_note_url (note);
-
- time.tv_sec = biji_note_obj_get_create_date (note) / G_USEC_PER_SEC;
- date = g_time_val_to_iso8601 (&time);
- create_date = to_8601_date (date);
- g_free (date);
-
-
- time.tv_sec = biji_note_obj_get_create_date (note) / G_USEC_PER_SEC;
- date = g_time_val_to_iso8601 (&time);
- last_change_date = to_8601_date (date);
- g_free (date);
-
- content = tracker_str (biji_note_obj_get_raw_text (note));
-
- /* TODO : nie:mimeType Note ;
- * All these properties are unique and thus can be "updated"
- * which is not the case of tags */
- gchar *query = g_strdup_printf (
- "INSERT OR REPLACE { <%s> a nfo:Note , nie:DataObject ; \
- nie:url '%s' ; \
- nie:contentLastModified '%s' ; \
- nie:contentCreated '%s' ; \
- nie:title '%s' ; \
- nie:plainTextContent '%s' ; \
- nie:generator 'Bijiben' . }",
- path,
- file,
- last_change_date,
- create_date,
- title,
- content) ;
-
- biji_perform_update_async_and_free (get_connection (biji_item_get_book (item)), query, NULL, NULL);
-
- g_free(title);
- g_free(file);
- g_free(content);
- g_free(create_date);
- g_free(last_change_date);
-}
-
void
biji_tracker_trash_ressource (BijiNoteBook *book,
@@ -658,8 +595,11 @@ update_ressource (BijiTrackerFinisher *finisher, gchar *tracker_urn_uuid )
t.tv_usec = 0;
t.tv_sec = info->mtime;
mtime = g_time_val_to_iso8601 (&t);
+
t.tv_sec = info->created;
- created = g_time_val_to_iso8601 (&t);
+ created = g_time_val_to_iso8601 (&t);
+
+
content = tracker_str (info->content);
g_message ("Updating ressource <%s> %s", info->title, tracker_urn_uuid);
@@ -696,7 +636,7 @@ push_new_note (BijiTrackerFinisher *finisher)
{
BijiNoteBook *book;
BijiInfoSet *info;
- gchar *query, *content, *created_time, *modified_time;
+ gchar *query, *content, *created_time, *mtime;
GTimeVal t;
book = finisher->book;
@@ -706,15 +646,17 @@ push_new_note (BijiTrackerFinisher *finisher)
content = tracker_str (info->content);
t.tv_usec = 0;
t.tv_sec = info->mtime;
- modified_time = g_time_val_to_iso8601 (&t);
+ mtime = g_time_val_to_iso8601 (&t);
+
+
t.tv_sec = info->created;
- created_time = g_time_val_to_iso8601 (&t);
+ created_time = g_time_val_to_iso8601 (&t);
query = g_strconcat (
"INSERT { _:res a nfo:Note ; ",
" a nie:DataObject ; ",
- " nie:contentLastModified '", modified_time, "' ;",
+ " nie:contentLastModified '", mtime, "' ;",
" nie:contentCreated '", created_time, "' ;",
" nie:title '", info->title, "' ;",
" nie:url '", info->url, "' ;",
@@ -724,6 +666,8 @@ push_new_note (BijiTrackerFinisher *finisher)
NULL);
+ g_debug ("%s", query);
+
tracker_sparql_connection_update_blank_async (get_connection (book),
query,
G_PRIORITY_DEFAULT,
@@ -734,7 +678,7 @@ push_new_note (BijiTrackerFinisher *finisher)
g_free (query);
g_free (content);
- g_clear_pointer (&modified_time, g_free);
+ g_clear_pointer (&mtime, g_free);
g_clear_pointer (&created_time, g_free);
biji_tracker_finisher_free (finisher);
}
diff --git a/src/libbiji/biji-tracker.h b/src/libbiji/biji-tracker.h
index 2037a63..b3f9e89 100644
--- a/src/libbiji/biji-tracker.h
+++ b/src/libbiji/biji-tracker.h
@@ -93,8 +93,6 @@ void biji_remove_collection_from_note (BijiNoteObj *note,
gpointer user_data);
-void bijiben_push_note_to_tracker (BijiNoteObj *note);
-
void biji_note_delete_from_tracker (BijiNoteObj *note);
diff --git a/src/libbiji/provider/biji-local-provider.c b/src/libbiji/provider/biji-local-provider.c
index b210020..4414b53 100644
--- a/src/libbiji/provider/biji-local-provider.c
+++ b/src/libbiji/provider/biji-local-provider.c
@@ -183,7 +183,8 @@ enumerate_next_files_ready_cb (GObject *source,
info.mtime = 0;
- note = biji_local_note_new_from_info (biji_provider_get_book (BIJI_PROVIDER (self)),
+ note = biji_local_note_new_from_info (BIJI_PROVIDER (self),
+ biji_provider_get_book (BIJI_PROVIDER (self)),
&info);
biji_lazy_deserialize (note);
@@ -284,17 +285,21 @@ biji_local_provider_finalize (GObject *object)
static void
biji_local_provider_init (BijiLocalProvider *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_LOCAL_PROVIDER, BijiLocalProviderPrivate);
- self->priv->load_cancellable = g_cancellable_new ();
- self->priv->items = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
+ BijiLocalProviderPrivate *priv;
+
+ priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_LOCAL_PROVIDER, BijiLocalProviderPrivate);
+ priv->load_cancellable = g_cancellable_new ();
+ priv->items = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
/* Info */
- self->priv->info.unique_id = "local";
- self->priv->info.name = _("Local storage");
- self->priv->info.icon =
- gtk_image_new_from_icon_name ("user-home", GTK_ICON_SIZE_INVALID);
- gtk_image_set_pixel_size (GTK_IMAGE (self->priv->info.icon), 48);
- g_object_ref (self->priv->info.icon);
+ priv->info.unique_id = "local";
+ priv->info.datasource = g_strdup_printf ("local:%s",
+ priv->info.unique_id);
+ priv->info.name = _("Local storage");
+ priv->info.icon =
+ gtk_image_new_from_icon_name ("user-home", GTK_ICON_SIZE_INVALID);
+ gtk_image_set_pixel_size (GTK_IMAGE (priv->info.icon), 48);
+ g_object_ref (priv->info.icon);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]