[bijiben] noteBook: use a localProvider to represent local notes
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] noteBook: use a localProvider to represent local notes
- Date: Sun, 16 Jun 2013 22:07:26 +0000 (UTC)
commit b6cd6ddc89259f3d656f040fbc71495037c00d66
Author: Pierre-Yves Luyten <py luyten fr>
Date: Sun Jun 16 23:16:26 2013 +0200
noteBook: use a localProvider to represent local notes
Local notes should use the same principles
src/libbiji/Makefile.am | 2 +
src/libbiji/biji-note-book.c | 234 +++------------
src/libbiji/biji-note-book.h | 2 +-
src/libbiji/biji-note-id.h | 1 +
src/libbiji/libbiji.h | 1 +
src/libbiji/provider/Makefile.am | 2 +
src/libbiji/provider/biji-local-provider.c | 364 ++++++++++++++++++++++++
src/libbiji/provider/biji-local-provider.h | 66 +++++
src/libbiji/provider/biji-own-cloud-provider.c | 81 ++----
src/libbiji/provider/biji-provider.c | 105 +++++++-
src/libbiji/provider/biji-provider.h | 7 +
11 files changed, 620 insertions(+), 245 deletions(-)
---
diff --git a/src/libbiji/Makefile.am b/src/libbiji/Makefile.am
index ee718ea..e3e5711 100644
--- a/src/libbiji/Makefile.am
+++ b/src/libbiji/Makefile.am
@@ -41,6 +41,8 @@ libbiji_la_SOURCES = \
editor/biji-editor-utils.h \
editor/biji-webkit-editor.c \
editor/biji-webkit-editor.h \
+ provider/biji-local-provider.c \
+ provider/biji-local-provider.h \
provider/biji-own-cloud-note.c \
provider/biji-own-cloud-note.h \
provider/biji-own-cloud-provider.c \
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 52f030c..3b16e84 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -19,8 +19,10 @@
#include <uuid/uuid.h>
#include "libbiji.h"
+#include "biji-local-note.h" // FIXME !!!! biji_provider_note_new ()
#include "biji-collection.h"
-#include "biji-local-note.h"
+
+#include "provider/biji-local-provider.h"
#include "provider/biji-own-cloud-provider.h"
@@ -36,9 +38,9 @@ struct _BijiNoteBookPrivate
GFile *location;
TrackerSparqlConnection *connection;
GdkRGBA color;
- GCancellable *load_cancellable;
};
+
/* Properties */
enum {
PROP_0,
@@ -47,6 +49,7 @@ enum {
BIJI_BOOK_PROPERTIES
};
+
/* Signals */
enum {
BOOK_AMENDED,
@@ -106,10 +109,7 @@ biji_note_book_finalize (GObject *object)
{
BijiNoteBook *book = BIJI_NOTE_BOOK (object) ;
- if (book->priv->load_cancellable)
- g_cancellable_cancel (book->priv->load_cancellable);
- g_clear_object (&book->priv->load_cancellable);
g_clear_object (&book->priv->location);
g_hash_table_destroy (book->priv->items);
@@ -217,19 +217,20 @@ biji_note_book_get_unique_title (BijiNoteBook *book, const gchar *title)
return new_title;
}
-gboolean
+
+void
biji_note_book_notify_changed (BijiNoteBook *book,
BijiNoteBookChangeFlag flag,
BijiItem *item)
{
- g_warning ("biji_note_book_notify_changed, flag %i has_item=%i",
- flag, (item != NULL));
-
-
- g_signal_emit (G_OBJECT (book), biji_book_signals[BOOK_AMENDED], 0, flag, item);
- return FALSE;
+ g_signal_emit (book,
+ biji_book_signals[BOOK_AMENDED],
+ 0,
+ flag,
+ item);
}
+
/* TODO : use the same for note, put everything there
* rather calling a func */
static void
@@ -238,6 +239,7 @@ on_item_deleted_cb (BijiItem *item, BijiNoteBook *book)
biji_note_book_remove_item (book, item);
}
+
void
book_on_note_changed_cb (BijiNoteObj *note, BijiNoteBook *book)
{
@@ -253,10 +255,7 @@ book_on_item_icon_changed_cb (BijiNoteObj *note, BijiNoteBook *book)
static void
_biji_note_book_add_one_item (BijiNoteBook *book, BijiItem *item)
{
- BijiNoteObj *note;
-
g_return_if_fail (BIJI_IS_ITEM (item));
- note = BIJI_IS_NOTE_OBJ (item) ? BIJI_NOTE_OBJ (item) : NULL;
/* Add it to the list */
@@ -264,179 +263,18 @@ _biji_note_book_add_one_item (BijiNoteBook *book, BijiItem *item)
(gpointer) biji_item_get_uuid (item), item);
/* Notify */
- if (note)
+ if (BIJI_IS_NOTE_OBJ (item))
{
- 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);
- g_signal_connect (note, "color-changed", G_CALLBACK (book_on_item_icon_changed_cb), book);
+ g_signal_connect (item, "changed", G_CALLBACK (book_on_note_changed_cb), book);
+ g_signal_connect (item, "renamed", G_CALLBACK (book_on_note_changed_cb), book);
+ g_signal_connect (item, "color-changed", G_CALLBACK (book_on_item_icon_changed_cb), book);
}
-}
-
-#define ATTRIBUTES_FOR_NOTEBOOK "standard::content-type,standard::name"
-
-static void
-load_location_error (GFile *location,
- GError *error)
-{
- gchar *path = g_file_get_path (location);
- g_printerr ("Unable to load location %s: %s", path, error->message);
-
- g_free (path);
- g_error_free (error);
-}
-
-static void
-release_enum_cb (GObject *source, GAsyncResult *res, gpointer user_data)
-{
- g_file_enumerator_close_finish (G_FILE_ENUMERATOR (source),
- res,
- NULL);
- g_object_unref (source);
-}
-
-static void
-create_collection_if_needed (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- BijiNoteBook *book = BIJI_NOTE_BOOK (user_data);
- BijiInfoSet *set = value;
- BijiCollection *collection;
-
- collection = g_hash_table_lookup (book->priv->items, key);
- if (!collection)
+ else if (BIJI_IS_COLLECTION (item))
{
- collection = biji_collection_new (G_OBJECT (book), key, set->title, set->mtime);
-
- g_hash_table_insert (book->priv->items,
- g_strdup (key),
- collection);
-
- g_signal_connect (collection, "deleted",
- G_CALLBACK (on_item_deleted_cb), book);
- g_signal_connect (collection , "icon-changed",
- G_CALLBACK (book_on_item_icon_changed_cb), book);
+ g_signal_connect (item, "deleted", G_CALLBACK (on_item_deleted_cb), book);
+ g_signal_connect (item , "icon-changed", G_CALLBACK (book_on_item_icon_changed_cb), book);
}
-
- /* InfoSet are freed per g_hash_table_destroy thanks to below caller */
-}
-
-static void
-load_book_finish (GHashTable *collections,
- gpointer user_data)
-{
- BijiNoteBook *self = BIJI_NOTE_BOOK (user_data);
-
- 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)
-{
- GFileEnumerator *enumerator = G_FILE_ENUMERATOR (source);
- BijiNoteBook *self;
- GList *files, *l;
- GError *error = NULL;
- gchar *base_path;
-
- files = g_file_enumerator_next_files_finish (enumerator, res, &error);
- g_file_enumerator_close_async (enumerator, G_PRIORITY_DEFAULT, NULL,
- release_enum_cb, NULL);
-
- if (error != NULL)
- {
- load_location_error (g_file_enumerator_get_container (enumerator), error);
- return;
- }
-
- self = user_data;
- base_path = g_file_get_path (self->priv->location);
-
- // now load the notes
- for (l = files; l != NULL; l = l->next)
- {
- GFileInfo *file;
- const gchar *name;
- BijiNoteObj *note;
- BijiInfoSet info;
-
- file = l->data;
- name = g_file_info_get_name (file);
-
- if (!g_str_has_suffix (name, ".note"))
- continue;
-
- info.url = g_build_filename (base_path, name, NULL);
- info.title = "";
- info.content = "";
- info.mtime = 0;
-
-
- note = biji_local_note_new_from_info (self, &info);
- biji_lazy_deserialize (note);
-
- _biji_note_book_add_one_item (self, BIJI_ITEM (note));
-
- g_free (info.url);
- }
-
- g_free (base_path);
- g_list_free_full (files, g_object_unref);
-
- /* Now we have all notes,
- * load the collections and we're good to notify loading done */
- biji_get_all_collections_async (self, load_book_finish, self);
-}
-
-static void
-enumerate_children_ready_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- GFile *location = G_FILE (source);
- GFileEnumerator *enumerator;
- GError *error = NULL;
- BijiNoteBook *self;
-
- enumerator = g_file_enumerate_children_finish (location,
- res, &error);
-
- if (error != NULL)
- {
- load_location_error (location, error);
- return;
- }
-
- self = user_data;
-
- // enumerate all files
- g_file_enumerator_next_files_async (enumerator, G_MAXINT,
- G_PRIORITY_DEFAULT,
- self->priv->load_cancellable,
- enumerate_next_files_ready_cb,
- self);
-}
-
-
-
-
-
-static void
-note_book_load_from_location (BijiNoteBook *self)
-{
- self->priv->load_cancellable = g_cancellable_new ();
- g_file_enumerate_children_async (self->priv->location,
- ATTRIBUTES_FOR_NOTEBOOK, 0,
- G_PRIORITY_DEFAULT,
- self->priv->load_cancellable,
- enumerate_children_ready_cb,
- self);
}
@@ -472,6 +310,23 @@ on_provider_loaded_cb (BijiProvider *provider,
}
+/*
+ * It should be the right place
+ * to stock somehow providers list
+ * in order to handle properly book__note_new ()
+ *
+ */
+static void
+_add_provider (BijiNoteBook *self,
+ BijiProvider *provider)
+{
+ g_return_if_fail (BIJI_IS_PROVIDER (provider));
+
+ g_signal_connect (provider, "loaded",
+ G_CALLBACK (on_provider_loaded_cb), self);
+}
+
+
void
biji_note_book_add_goa_object (BijiNoteBook *self,
GoaObject *object)
@@ -491,20 +346,20 @@ biji_note_book_add_goa_object (BijiNoteBook *self,
provider = biji_own_cloud_provider_new (self, object);
}
- if (provider)
- g_signal_connect (provider, "loaded",
- G_CALLBACK (on_provider_loaded_cb), self);
+ _add_provider (self, provider);
}
static void
biji_note_book_constructed (GObject *object)
{
- BijiNoteBook *self = BIJI_NOTE_BOOK (object);
+ BijiNoteBook *self;
+ BijiProvider *provider;
gchar *filename;
GFile *cache;
G_OBJECT_CLASS (biji_note_book_parent_class)->constructed (object);
+ self = BIJI_NOTE_BOOK (object);
/* Ensure cache directory for icons */
filename = g_build_filename (g_get_user_cache_dir (),
@@ -515,9 +370,11 @@ biji_note_book_constructed (GObject *object)
g_file_make_directory (cache, NULL, NULL);
g_object_unref (cache);
- note_book_load_from_location (self);
+ provider = biji_local_provider_new (self, self->priv->location);
+ _add_provider (self, provider);
}
+
static void
biji_note_book_class_init (BijiNoteBookClass *klass)
{
@@ -651,6 +508,7 @@ biji_note_book_new (GFile *location, GdkRGBA *color)
NULL);
}
+
BijiNoteObj *
biji_note_get_new_from_file (BijiNoteBook *book, const gchar* path)
{
diff --git a/src/libbiji/biji-note-book.h b/src/libbiji/biji-note-book.h
index 7b0ce9c..e77520a 100644
--- a/src/libbiji/biji-note-book.h
+++ b/src/libbiji/biji-note-book.h
@@ -74,7 +74,7 @@ gboolean biji_note_book_add_item (BijiNoteBook *book,
gboolean notify);
-gboolean biji_note_book_notify_changed (BijiNoteBook *book,
+void biji_note_book_notify_changed (BijiNoteBook *book,
BijiNoteBookChangeFlag flag,
BijiItem *item);
diff --git a/src/libbiji/biji-note-id.h b/src/libbiji/biji-note-id.h
index 9d911f7..098e716 100644
--- a/src/libbiji/biji-note-id.h
+++ b/src/libbiji/biji-note-id.h
@@ -22,6 +22,7 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include "biji-info-set.h"
#include "biji-tracker.h"
G_BEGIN_DECLS
diff --git a/src/libbiji/libbiji.h b/src/libbiji/libbiji.h
index 3f04784..90b9436 100644
--- a/src/libbiji/libbiji.h
+++ b/src/libbiji/libbiji.h
@@ -33,5 +33,6 @@
#include "deserializer/biji-lazy-deserializer.h"
#include "editor/biji-webkit-editor.h"
+
#undef _LIBBIJI_INSIDE_H
#endif /*_LIB_BIJI_H*/
diff --git a/src/libbiji/provider/Makefile.am b/src/libbiji/provider/Makefile.am
index 8b13789..b28b04f 100644
--- a/src/libbiji/provider/Makefile.am
+++ b/src/libbiji/provider/Makefile.am
@@ -1 +1,3 @@
+
+
diff --git a/src/libbiji/provider/biji-local-provider.c b/src/libbiji/provider/biji-local-provider.c
new file mode 100644
index 0000000..3b0dfae
--- /dev/null
+++ b/src/libbiji/provider/biji-local-provider.c
@@ -0,0 +1,364 @@
+/*
+ * biji-local-provider.c
+ * Copyright (C) Pierre-Yves LUYTEN 2013 <py luyten fr>
+ *
+ * bijiben is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * bijiben is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+/*
+ * as of today, local provider really go through every single
+ * file at startup : no cache.
+ * We could as well play with metadata mtime
+ * and read file only when really needed
+ */
+
+
+#include "biji-local-note.h"
+#include "biji-local-provider.h"
+
+
+
+/*
+ * Items are both notes and collections
+ *
+ */
+
+struct BijiLocalProviderPrivate_
+{
+ BijiNoteBook *book;
+ GFile *location;
+ GHashTable *items;
+ GCancellable *load_cancellable;
+};
+
+
+G_DEFINE_TYPE (BijiLocalProvider, biji_local_provider, BIJI_TYPE_PROVIDER)
+
+
+/* Properties */
+enum {
+ PROP_0,
+ PROP_LOCATION,
+ BIJI_LOCAL_PROP
+};
+
+
+
+static GParamSpec *properties[BIJI_LOCAL_PROP] = { NULL, };
+
+
+#define ATTRIBUTES_FOR_NOTEBOOK "standard::content-type,standard::name"
+
+
+static void
+load_location_error (GFile *location,
+ GError *error)
+{
+ gchar *path;
+
+
+ path = g_file_get_path (location);
+ g_printerr ("Unable to load location %s: %s", path, error->message);
+ g_free (path);
+ g_error_free (error);
+}
+
+
+static void
+release_enum_cb (GObject *source, GAsyncResult *res, gpointer user_data)
+{
+ g_file_enumerator_close_finish (G_FILE_ENUMERATOR (source),
+ res,
+ NULL);
+ g_object_unref (source);
+}
+
+
+static void
+create_collection_if_needed (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ BijiLocalProvider *self;
+ BijiInfoSet *set;
+ BijiCollection *collection;
+ BijiNoteBook *book;
+
+
+ self = user_data;
+ set = value;
+ collection = g_hash_table_lookup (self->priv->items, key);
+ book = biji_provider_get_book (BIJI_PROVIDER (self));
+
+ if (!collection)
+ {
+ collection = biji_collection_new (G_OBJECT (book), key, set->title, set->mtime);
+
+ g_hash_table_insert (self->priv->items,
+ g_strdup (key),
+ collection);
+ }
+
+ /* InfoSet are freed per g_hash_table_destroy thanks to below caller */
+}
+
+
+static void
+local_provider_finish (GHashTable *collections,
+ gpointer user_data)
+{
+ BijiLocalProvider *self;
+ GList *list;
+
+
+ self = user_data;
+ g_hash_table_foreach (collections, create_collection_if_needed, user_data);
+ g_hash_table_destroy (collections);
+
+
+ /* Now simply provide data to controller */
+ list = g_hash_table_get_values (self->priv->items);
+ BIJI_PROVIDER_GET_CLASS (self)->notify_loaded (BIJI_PROVIDER (self), list);
+ g_list_free (list);
+}
+
+
+static void
+enumerate_next_files_ready_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GFileEnumerator *enumerator;
+ BijiLocalProvider *self;
+ GList *files, *l;
+ GError *error;
+ gchar *base_path;
+
+
+ enumerator = G_FILE_ENUMERATOR (source);
+ self = user_data;
+ error = NULL;
+ files = g_file_enumerator_next_files_finish (enumerator, res, &error);
+ g_file_enumerator_close_async (enumerator, G_PRIORITY_DEFAULT, NULL,
+ release_enum_cb, NULL);
+
+ if (error != NULL)
+ {
+ load_location_error (g_file_enumerator_get_container (enumerator), error);
+ return;
+ }
+
+
+ base_path = g_file_get_path (self->priv->location);
+
+ for (l = files; l != NULL; l = l->next)
+ {
+ GFileInfo *file;
+ const gchar *name;
+ BijiNoteObj *note;
+ BijiInfoSet info;
+
+ file = l->data;
+ name = g_file_info_get_name (file);
+
+ if (!g_str_has_suffix (name, ".note"))
+ continue;
+
+ info.url = g_build_filename (base_path, name, NULL);
+ info.title = "";
+ info.content = "";
+ info.mtime = 0;
+
+
+ note = biji_local_note_new_from_info (biji_provider_get_book (BIJI_PROVIDER (self)),
+ &info);
+ biji_lazy_deserialize (note);
+
+
+ g_hash_table_replace (self->priv->items,
+ info.url, note);
+
+ }
+
+ g_free (base_path);
+ g_list_free_full (files, g_object_unref);
+
+ /* Now we have all notes,
+ * load the collections and we're good to notify loading done */
+ biji_get_all_collections_async (biji_provider_get_book (BIJI_PROVIDER (self)),
+ local_provider_finish,
+ self);
+}
+
+static void
+enumerate_children_ready_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GFile *location;
+ GFileEnumerator *enumerator;
+ GError *error;
+ BijiLocalProvider *self;
+
+
+ location = G_FILE (source);
+ self = user_data;
+ error = NULL;
+ enumerator = g_file_enumerate_children_finish (location,
+ res, &error);
+
+ if (error != NULL)
+ {
+ load_location_error (location, error);
+ return;
+ }
+
+
+ g_file_enumerator_next_files_async (enumerator, G_MAXINT,
+ G_PRIORITY_DEFAULT,
+ self->priv->load_cancellable,
+ enumerate_next_files_ready_cb,
+ self);
+}
+
+
+
+
+
+static void
+load_from_location (BijiLocalProvider *self)
+{
+ g_file_enumerate_children_async (self->priv->location,
+ ATTRIBUTES_FOR_NOTEBOOK, 0,
+ G_PRIORITY_DEFAULT,
+ self->priv->load_cancellable,
+ enumerate_children_ready_cb,
+ self);
+}
+
+
+static void
+biji_local_provider_constructed (GObject *object)
+{
+ BijiLocalProvider *self;
+
+ g_return_if_fail (BIJI_IS_LOCAL_PROVIDER (object));
+ self = BIJI_LOCAL_PROVIDER (object);
+
+ load_from_location (self);
+}
+
+
+static void
+biji_local_provider_finalize (GObject *object)
+{
+ BijiLocalProvider *self;
+
+ g_return_if_fail (BIJI_IS_LOCAL_PROVIDER (object));
+
+ self = BIJI_LOCAL_PROVIDER (object);
+
+ if (self->priv->load_cancellable)
+ g_cancellable_cancel (self->priv->load_cancellable);
+
+ g_object_unref (self->priv->load_cancellable);
+
+ G_OBJECT_CLASS (biji_local_provider_parent_class)->finalize (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);
+}
+
+
+static void
+biji_local_provider_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ BijiLocalProvider *self = BIJI_LOCAL_PROVIDER (object);
+
+
+ switch (property_id)
+ {
+ case PROP_LOCATION:
+ self->priv->location = g_value_dup_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+biji_local_provider_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ BijiLocalProvider *self = BIJI_LOCAL_PROVIDER (object);
+
+ switch (property_id)
+ {
+ case PROP_LOCATION:
+ g_value_set_object (value, self->priv->location);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+biji_local_provider_class_init (BijiLocalProviderClass *klass)
+{
+ GObjectClass *g_object_class;
+
+ g_object_class = G_OBJECT_CLASS (klass);
+
+ g_object_class->constructed = biji_local_provider_constructed;
+ g_object_class->finalize = biji_local_provider_finalize;
+ g_object_class->get_property = biji_local_provider_get_property;
+ g_object_class->set_property = biji_local_provider_set_property;
+
+
+ properties[PROP_LOCATION] =
+ g_param_spec_object ("location",
+ "The book location",
+ "The location where the notes are loaded and saved",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (g_object_class, BIJI_LOCAL_PROP, properties);
+
+ g_type_class_add_private ((gpointer)klass, sizeof (BijiLocalProviderPrivate));
+}
+
+
+BijiProvider *
+biji_local_provider_new (BijiNoteBook *book,
+ GFile *location)
+{
+ return g_object_new (BIJI_TYPE_LOCAL_PROVIDER,
+ "book", book,
+ "location", location,
+ NULL);
+}
diff --git a/src/libbiji/provider/biji-local-provider.h b/src/libbiji/provider/biji-local-provider.h
new file mode 100644
index 0000000..dc3baec
--- /dev/null
+++ b/src/libbiji/provider/biji-local-provider.h
@@ -0,0 +1,66 @@
+/*
+ * biji-local-provider.h
+ * Copyright (C) Pierre-Yves LUYTEN 2013 <py luyten fr>
+ *
+ * bijiben is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * bijiben is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+#ifndef BIJI_LOCAL_PROVIDER_H_
+#define BIJI_LOCAL_PROVIDER_H_ 1
+
+
+#include "../biji-note-book.h"
+#include "biji-provider.h"
+
+
+G_BEGIN_DECLS
+
+
+#define BIJI_TYPE_LOCAL_PROVIDER (biji_local_provider_get_type ())
+#define BIJI_LOCAL_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BIJI_TYPE_LOCAL_PROVIDER,
BijiLocalProvider))
+#define BIJI_LOCAL_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BIJI_TYPE_LOCAL_PROVIDER,
BijiLocalProviderClass))
+#define BIJI_IS_LOCAL_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BIJI_TYPE_LOCAL_PROVIDER))
+#define BIJI_IS_LOCAL_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BIJI_TYPE_LOCAL_PROVIDER))
+#define BIJI_LOCAL_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BIJI_TYPE_LOCAL_PROVIDER,
BijiLocalProviderClass))
+
+typedef struct BijiLocalProvider_ BijiLocalProvider;
+typedef struct BijiLocalProviderClass_ BijiLocalProviderClass;
+typedef struct BijiLocalProviderPrivate_ BijiLocalProviderPrivate;
+
+
+struct BijiLocalProvider_
+{
+ BijiProvider parent;
+ BijiLocalProviderPrivate *priv;
+};
+
+
+struct BijiLocalProviderClass_
+{
+ BijiProviderClass parent_class;
+};
+
+
+GType biji_local_provider_get_type (void);
+
+
+BijiProvider *biji_local_provider_new (BijiNoteBook *book,
+ GFile *location);
+
+
+G_END_DECLS
+
+#endif /* BIJI_LOCAL_PROVIDER_H_ */
diff --git a/src/libbiji/provider/biji-own-cloud-provider.c b/src/libbiji/provider/biji-own-cloud-provider.c
index b21da99..44004a0 100644
--- a/src/libbiji/provider/biji-own-cloud-provider.c
+++ b/src/libbiji/provider/biji-own-cloud-provider.c
@@ -37,26 +37,16 @@ static void get_mount (BijiOwnCloudProvider *self);
/* Properties */
enum {
PROP_0,
- PROP_BOOK,
PROP_GOA_OBJECT,
OCLOUD_PROV_PROP
};
-/* Signals */
-enum {
- OCLOUD_PROV_LOADED,
- OCLOUD_PROV_SIGNALS
-};
-
-
-static guint biji_ocloud_provider_signals[OCLOUD_PROV_SIGNALS] = { 0 };
static GParamSpec *properties[OCLOUD_PROV_PROP] = { NULL, };
struct BijiOwnCloudProviderPrivate_
{
- BijiNoteBook *book;
GoaObject *object;
GoaAccount *account;
gchar *identifier;
@@ -154,11 +144,13 @@ create_note_from_item (BijiOCloudItem *item)
{
BijiNoteObj *note;
GdkRGBA color;
+ BijiNoteBook *book;
+ book = biji_provider_get_book (BIJI_PROVIDER (item->self));
note = biji_own_cloud_note_new_from_info (item->self,
- item->self->priv->book,
+ book,
&item->set);
- biji_note_book_get_default_color (item->self->priv->book, &color);
+ biji_note_book_get_default_color (book, &color);
biji_note_obj_set_rgba (note, &color);
g_hash_table_replace (item->self->priv->notes,
item->set.url,
@@ -212,7 +204,8 @@ on_content (GObject *source,
{
item->set.content = contents;
create_note_from_item (item);
- biji_tracker_ensure_ressource_from_info (self->priv->book, &item->set);
+ biji_tracker_ensure_ressource_from_info (
+ biji_provider_get_book (BIJI_PROVIDER (self)), &item->set);
// TODO --> ensure_ressource callback.... o_cloud_item_free (item);
}
@@ -271,7 +264,7 @@ static void
trash (gpointer urn_uuid, gpointer self)
{
biji_tracker_trash_ressource (
- BIJI_OWN_CLOUD_PROVIDER (self)->priv->book, (gchar*) urn_uuid);
+ biji_provider_get_book (BIJI_PROVIDER (self)), (gchar*) urn_uuid);
}
@@ -288,7 +281,7 @@ handle_next_item (BijiOwnCloudProvider *self)
{
g_hash_table_remove (self->priv->tracker, item->set.url);
- biji_tracker_check_for_info (self->priv->book,
+ biji_tracker_check_for_info (biji_provider_get_book (BIJI_PROVIDER (self)),
item->set.url,
item->set.mtime,
check_info_maybe_read_file,
@@ -306,12 +299,7 @@ handle_next_item (BijiOwnCloudProvider *self)
/* Now simply provide data to controller */
list = g_hash_table_get_values (self->priv->notes);
- g_warning ("emiting");
- g_signal_emit (G_OBJECT (self),
- biji_ocloud_provider_signals[OCLOUD_PROV_LOADED],
- 0,
- list);
-
+ BIJI_PROVIDER_GET_CLASS (self)->notify_loaded (BIJI_PROVIDER (self), list);
g_list_free (list);
}
}
@@ -458,12 +446,12 @@ static void
mine_notes (gboolean result, gpointer user_data)
{
BijiOwnCloudProvider *self;
- const gchar *root;
- gchar *query;
+ BijiProvider *provider;
+ gchar *query;
self = user_data;
- root = goa_files_get_uri (goa_object_peek_files (self->priv->object));
+ provider = user_data;
/*
* We could as well use nie:url to lookup existing db
@@ -478,10 +466,11 @@ mine_notes (gboolean result, gpointer user_data)
query = g_strdup_printf ("SELECT ?url ?urn WHERE {?urn a nfo:Note; "
" nie:dataSource '%s' ; nie:url ?url}",
- BIJI_PROVIDER_GET_CLASS (self)->get_datasource (BIJI_PROVIDER (self)));
+ BIJI_PROVIDER_GET_CLASS (self)->get_datasource (provider));
tracker_sparql_connection_query_async (
- biji_note_book_get_tracker_connection (self->priv->book),
+ biji_note_book_get_tracker_connection (
+ biji_provider_get_book (provider)),
query,
NULL,
on_notes_mined,
@@ -513,11 +502,12 @@ handle_mount (BijiOwnCloudProvider *self)
g_object_unref (root);
- biji_tracker_ensure_datasource (self->priv->book,
- self->priv->identifier,
- MINER_ID,
- mine_notes,
- self);
+ biji_tracker_ensure_datasource (
+ biji_provider_get_book (BIJI_PROVIDER (self)),
+ self->priv->identifier,
+ MINER_ID,
+ mine_notes,
+ self);
}
}
@@ -649,8 +639,6 @@ biji_own_cloud_provider_set_property (GObject *object,
switch (property_id)
{
- case PROP_BOOK:
- self->priv->book = g_value_dup_object (value);
case PROP_GOA_OBJECT:
self->priv->object = g_value_dup_object (value);
break;
@@ -706,25 +694,6 @@ biji_own_cloud_provider_class_init (BijiOwnCloudProviderClass *klass)
provider_class->get_datasource = own_cloud_get_datasource;
- biji_ocloud_provider_signals[OCLOUD_PROV_LOADED] =
- g_signal_new ("loaded",
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
-
-
- properties[PROP_BOOK] =
- g_param_spec_object("book",
- "Note Book",
- "The Note Book",
- BIJI_TYPE_NOTE_BOOK,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
-
-
properties[PROP_GOA_OBJECT] =
g_param_spec_object("goa",
"The Goa Object",
@@ -739,7 +708,11 @@ biji_own_cloud_provider_class_init (BijiOwnCloudProviderClass *klass)
BijiProvider *
-biji_own_cloud_provider_new (BijiNoteBook *book, GoaObject *object)
+biji_own_cloud_provider_new (BijiNoteBook *book,
+ GoaObject *object)
{
- return g_object_new (BIJI_TYPE_OWN_CLOUD_PROVIDER, "book", book, "goa", object, NULL);
+ return g_object_new (BIJI_TYPE_OWN_CLOUD_PROVIDER,
+ "book", book,
+ "goa", object,
+ NULL);
}
diff --git a/src/libbiji/provider/biji-provider.c b/src/libbiji/provider/biji-provider.c
index 012813a..9221ed5 100644
--- a/src/libbiji/provider/biji-provider.c
+++ b/src/libbiji/provider/biji-provider.c
@@ -30,15 +30,38 @@
#include "biji-provider.h"
+/* Properties */
+enum {
+ PROP_0,
+ PROP_BOOK,
+ PROVIDER_PROP
+};
+
+
+/* Signals */
+enum {
+ PROVIDER_LOADED,
+ PROVIDER_SIGNALS
+};
+
+
+static guint biji_provider_signals[PROVIDER_SIGNALS] = { 0 };
+static GParamSpec *properties[PROVIDER_PROP] = { NULL, };
+
+
struct BijiProviderPrivate_
{
- gpointer delete_me;
+ BijiNoteBook *book;
};
G_DEFINE_TYPE (BijiProvider, biji_provider, G_TYPE_OBJECT)
-
+BijiNoteBook *
+biji_provider_get_book (BijiProvider *provider)
+{
+ return provider->priv->book;
+}
static void
@@ -58,6 +81,58 @@ static void
biji_provider_init (BijiProvider *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_PROVIDER, BijiProviderPrivate);
+ self->priv->book = NULL;
+}
+
+
+static void
+biji_provider_notify_loaded (BijiProvider *self,
+ GList *items)
+{
+ g_signal_emit (self,
+ biji_provider_signals[PROVIDER_LOADED],
+ 0,
+ items);
+}
+
+
+static void
+biji_provider_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ BijiProvider *self = BIJI_PROVIDER (object);
+
+
+ switch (property_id)
+ {
+ case PROP_BOOK:
+ self->priv->book = g_value_dup_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+biji_provider_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ BijiProvider *self = BIJI_PROVIDER (object);
+
+ switch (property_id)
+ {
+ case PROP_BOOK:
+ g_value_set_object (value, self->priv->book);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
}
@@ -65,10 +140,36 @@ static void
biji_provider_class_init (BijiProviderClass *klass)
{
GObjectClass *g_object_class;
+ BijiProviderClass *provider_class;
g_object_class = G_OBJECT_CLASS (klass);
+ provider_class = BIJI_PROVIDER_CLASS (klass);
g_object_class->finalize = biji_provider_finalize;
+ g_object_class->get_property = biji_provider_get_property;
+ g_object_class->set_property = biji_provider_set_property;
+ provider_class->notify_loaded = biji_provider_notify_loaded;
+
+ biji_provider_signals[PROVIDER_LOADED] =
+ g_signal_new ("loaded",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+
+
+ properties[PROP_BOOK] =
+ g_param_spec_object("book",
+ "Note Book",
+ "The Note Book",
+ BIJI_TYPE_NOTE_BOOK,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
+
+
+ g_object_class_install_properties (g_object_class, PROVIDER_PROP, properties);
g_type_class_add_private ((gpointer)klass, sizeof (BijiProviderPrivate));
}
diff --git a/src/libbiji/provider/biji-provider.h b/src/libbiji/provider/biji-provider.h
index eb2847e..9bc306b 100644
--- a/src/libbiji/provider/biji-provider.h
+++ b/src/libbiji/provider/biji-provider.h
@@ -36,6 +36,7 @@ typedef struct BijiProvider_ BijiProvider;
typedef struct BijiProviderClass_ BijiProviderClass;
typedef struct BijiProviderPrivate_ BijiProviderPrivate;
+
struct BijiProvider_
{
GObject parent;
@@ -47,6 +48,9 @@ struct BijiProviderClass_
{
GObjectClass parent_class;
+ void (*notify_loaded) (BijiProvider *provider,
+ GList *loaded_items);
+
const gchar* (*get_datasource) (BijiProvider *provider);
};
@@ -54,6 +58,9 @@ struct BijiProviderClass_
GType biji_provider_get_type (void);
+BijiNoteBook *biji_provider_get_book (BijiProvider *provider);
+
+
G_END_DECLS
#endif /* BIJI_PROVIDER_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]