[bijiben] libbiji: add initial ProviderInfo struct
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] libbiji: add initial ProviderInfo struct
- Date: Thu, 8 Aug 2013 19:32:18 +0000 (UTC)
commit 442a78ce6cbf8c25a90a4ab00ef096233fd2dcb0
Author: Pierre-Yves Luyten <py luyten fr>
Date: Thu Aug 8 21:15:48 2013 +0200
libbiji: add initial ProviderInfo struct
the book can now list the different locations in human readable
format
src/libbiji/biji-info-set.h | 2 +-
src/libbiji/biji-note-book.c | 72 ++++++++-
src/libbiji/biji-note-book.h | 11 +-
src/libbiji/biji-note-id.c | 2 +
src/libbiji/libbiji.h | 1 +
src/libbiji/provider/biji-local-note.c | 211 ++++++++++++++++++++++++
src/libbiji/provider/biji-local-note.h | 59 +++++++
src/libbiji/provider/biji-local-provider.c | 27 +++-
src/libbiji/provider/biji-own-cloud-note.c | 124 +++++++++++---
src/libbiji/provider/biji-own-cloud-provider.c | 96 +++++++++--
src/libbiji/provider/biji-own-cloud-provider.h | 3 +
src/libbiji/provider/biji-provider.c | 7 +
src/libbiji/provider/biji-provider.h | 36 ++++-
13 files changed, 604 insertions(+), 47 deletions(-)
---
diff --git a/src/libbiji/biji-info-set.h b/src/libbiji/biji-info-set.h
index 0bb423b..f9023f5 100644
--- a/src/libbiji/biji-info-set.h
+++ b/src/libbiji/biji-info-set.h
@@ -35,7 +35,7 @@
typedef struct
{
- /* core (ie, cache). All but content are coomon to bijiIem. */
+ /* core (ie, cache). All but content are common to bijiIem. */
gchar *url;
gchar *title;
gint64 mtime;
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index ad12123..13c5617 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -87,6 +87,16 @@ biji_note_book_init (BijiNoteBook *self)
g_str_equal,
NULL,
g_object_unref);
+
+ /*
+ * Providers are the different notes storage
+ * the hash table use an id
+ *
+ * - local files stored notes = "local"
+ * - own cloud notes = account_get_id
+ */
+
+ priv->providers = g_hash_table_new (g_str_hash, g_str_equal);
}
@@ -104,6 +114,26 @@ biji_note_book_get_tracker_connection (BijiNoteBook *book)
}
+
+GList *
+biji_note_book_get_providers (BijiNoteBook *book)
+{
+ GList *providers, *l, *retval;
+
+ retval = NULL;
+ providers = g_hash_table_get_values (book->priv->providers);
+
+ for (l = providers; l != NULL; l = l->next)
+ {
+ retval = g_list_prepend (
+ retval, (gpointer) biji_provider_get_info (BIJI_PROVIDER (l->data)));
+ }
+
+ g_list_free (providers);
+ return retval;
+}
+
+
static void
biji_note_book_finalize (GObject *object)
{
@@ -326,6 +356,14 @@ _add_provider (BijiNoteBook *self,
{
g_return_if_fail (BIJI_IS_PROVIDER (provider));
+
+ /* we can safely cast get_id from const to gpointer
+ * since there is no key free func */
+
+ const BijiProviderInfo *info;
+
+ info = biji_provider_get_info (provider);
+ g_hash_table_insert (self->priv->providers, (gpointer) info->unique_id, provider);
g_signal_connect (provider, "loaded",
G_CALLBACK (on_provider_loaded_cb), self);
}
@@ -601,8 +639,11 @@ get_note_skeleton (BijiNoteBook *book)
}
-BijiNoteObj *
-biji_note_book_note_new (BijiNoteBook *book, gchar *str)
+/*
+ * TODO : move this to local provider.
+ */
+static BijiNoteObj *
+biji_note_book_local_note_new (BijiNoteBook *book, gchar *str)
{
BijiNoteObj *ret = get_note_skeleton (book);
@@ -626,3 +667,30 @@ biji_note_book_note_new (BijiNoteBook *book, gchar *str)
return ret;
}
+
+
+/*
+ * Use "local" for a local note new
+ * Use goa_account_get_id for goa
+ */
+BijiNoteObj *
+biji_note_book_note_new (BijiNoteBook *book,
+ gchar *str,
+ gchar *provider_id)
+{
+ BijiProvider *provider;
+
+ // If we move local_note_new to create_note for local provider
+ // we won't need this stupid switch.
+
+ if (provider_id == NULL ||
+ g_strcmp0 (provider_id, "local") == 0)
+ return biji_note_book_local_note_new (book, str);
+
+
+ provider = g_hash_table_lookup (book->priv->providers,
+ provider_id);
+
+ return BIJI_PROVIDER_GET_CLASS (provider)->create_note (provider, str);
+}
+
diff --git a/src/libbiji/biji-note-book.h b/src/libbiji/biji-note-book.h
index 92606ad..4cc3710 100644
--- a/src/libbiji/biji-note-book.h
+++ b/src/libbiji/biji-note-book.h
@@ -46,6 +46,8 @@ struct _BijiNoteBook
BijiNoteBookPrivate *priv ;
};
+
+
GType biji_note_book_get_type (void) G_GNUC_CONST;
@@ -58,6 +60,9 @@ BijiNoteBook *biji_note_book_new (GFile *location,
void biji_note_book_add_goa_object (BijiNoteBook *book,
GoaObject *object);
+/* <ProviderInfo*> */
+GList *biji_note_book_get_providers (BijiNoteBook *book);
+
ZeitgeistLog *biji_note_book_get_zg_log (BijiNoteBook *book);
@@ -100,9 +105,11 @@ BijiNoteObj *biji_note_get_new_from_file (BijiNoteBook *book,
const gchar* tomboy_format_note_path);
-/* todo: add optional parameter : LOCAL or GOA */
+
BijiNoteObj *biji_note_book_note_new (BijiNoteBook *book,
- gchar *str);
+ gchar *str,
+ gchar *provider_id);
+
G_END_DECLS
diff --git a/src/libbiji/biji-note-id.c b/src/libbiji/biji-note-id.c
index cc7e39f..85d6f7d 100644
--- a/src/libbiji/biji-note-id.c
+++ b/src/libbiji/biji-note-id.c
@@ -100,6 +100,7 @@ biji_note_id_set_property (GObject *object,
break;
case PROP_TITLE:
biji_note_id_set_title (self, (gchar*) g_value_get_string (value));
+ g_object_notify_by_pspec (object, properties[PROP_TITLE]);
break;
case PROP_MTIME:
self->priv->mtime = g_value_get_int64 (value);
@@ -211,6 +212,7 @@ biji_note_id_set_title (BijiNoteID *n, gchar* title)
g_free (n->priv->title);
n->priv->title = g_strdup (title);
+ g_object_notify_by_pspec (G_OBJECT (n), properties[PROP_TITLE]);
}
diff --git a/src/libbiji/libbiji.h b/src/libbiji/libbiji.h
index 90b9436..17590f8 100644
--- a/src/libbiji/libbiji.h
+++ b/src/libbiji/libbiji.h
@@ -32,6 +32,7 @@
#include "biji-zeitgeist.h"
#include "deserializer/biji-lazy-deserializer.h"
#include "editor/biji-webkit-editor.h"
+#include "provider/biji-provider.h"
#undef _LIBBIJI_INSIDE_H
diff --git a/src/libbiji/provider/biji-local-note.c b/src/libbiji/provider/biji-local-note.c
new file mode 100644
index 0000000..60d9d95
--- /dev/null
+++ b/src/libbiji/provider/biji-local-note.c
@@ -0,0 +1,211 @@
+/* bjb-local-note.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/>.
+ */
+
+#include "biji-local-note.h"
+#include "../serializer/biji-lazy-serializer.h"
+
+
+struct BijiLocalNotePrivate_
+{
+ GFile *location;
+ gchar *basename;
+ gchar *html;
+};
+
+
+G_DEFINE_TYPE (BijiLocalNote, biji_local_note, BIJI_TYPE_NOTE_OBJ)
+
+/* Iface */
+
+gchar *
+local_note_get_html (BijiNoteObj *note)
+{
+ if (BIJI_IS_LOCAL_NOTE (note))
+ return BIJI_LOCAL_NOTE (note)->priv->html;
+
+ else
+ return NULL;
+}
+
+
+void
+local_note_set_html (BijiNoteObj *note,
+ gchar *html)
+{
+ if (BIJI_LOCAL_NOTE (note)->priv->html)
+ g_free (BIJI_LOCAL_NOTE (note)->priv->html);
+
+ if (html)
+ BIJI_LOCAL_NOTE (note)->priv->html = g_strdup (html);
+}
+
+
+void
+local_note_save (BijiNoteObj *note)
+{
+ g_return_if_fail (BIJI_IS_LOCAL_NOTE (note));
+
+ biji_lazy_serialize (note);
+ bijiben_push_note_to_tracker (note);
+}
+
+
+/* GObj */
+
+static void
+biji_local_note_finalize (GObject *object)
+{
+ BijiLocalNote *self;
+
+ g_return_if_fail (BIJI_IS_LOCAL_NOTE (object));
+
+ self = BIJI_LOCAL_NOTE (object);
+
+ if (self->priv->html)
+ g_free (self->priv->html);
+
+ G_OBJECT_CLASS (biji_local_note_parent_class)->finalize (object);
+}
+
+
+static void
+biji_local_note_init (BijiLocalNote *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_LOCAL_NOTE, BijiLocalNotePrivate);
+ self->priv->html = NULL;
+}
+
+
+static gboolean
+item_yes (BijiItem * item)
+{
+ return TRUE;
+}
+
+
+static gboolean
+note_yes (BijiNoteObj *item)
+{
+ return TRUE;
+}
+
+
+static gboolean
+local_note_archive (BijiNoteObj *note)
+{
+ BijiLocalNote *self;
+ GFile *parent, *trash, *archive;
+ gchar *parent_path, *trash_path, *backup_path;
+ GError *error = NULL;
+ gboolean result = FALSE;
+
+ g_warning ("local note archive");
+ self = BIJI_LOCAL_NOTE (note);
+
+ /* Create the trash directory
+ * No matter if already exists */
+ parent = g_file_get_parent (self->priv->location);
+ parent_path = g_file_get_path (parent);
+ trash_path = g_build_filename (parent_path, ".Trash", NULL);
+ trash = g_file_new_for_path (trash_path);
+ g_file_make_directory (trash, NULL, NULL);
+
+ /* Move the note to trash */
+
+ backup_path = g_build_filename (trash_path, self->priv->basename, NULL);
+ archive = g_file_new_for_path (backup_path);
+
+ result = g_file_move (self->priv->location,
+ archive,
+ G_FILE_COPY_OVERWRITE,
+ NULL, // cancellable
+ NULL, // progress callback
+ NULL, // progress_callback_data,
+ &error);
+
+ if (error)
+ {
+ g_message ("%s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+
+
+ g_free (parent_path);
+ g_object_unref (parent);
+ g_free (trash_path);
+ g_object_unref (trash);
+ g_free (backup_path);
+ g_object_unref (archive);
+
+ return result;
+}
+
+
+static gchar*
+local_note_get_basename (BijiNoteObj *note)
+{
+ return BIJI_LOCAL_NOTE (note)->priv->basename;
+}
+
+static void
+biji_local_note_class_init (BijiLocalNoteClass *klass)
+{
+ GObjectClass *g_object_class;
+ BijiItemClass *item_class;
+ BijiNoteObjClass *note_class;
+
+ g_object_class = G_OBJECT_CLASS (klass);
+ item_class = BIJI_ITEM_CLASS (klass);
+ note_class = BIJI_NOTE_OBJ_CLASS (klass);
+
+ g_object_class->finalize = biji_local_note_finalize;
+
+ item_class->is_collectable = item_yes;
+ item_class->has_color = item_yes;
+
+ note_class->get_basename = local_note_get_basename;
+ note_class->get_html = local_note_get_html;
+ note_class->set_html = local_note_set_html;
+ note_class->save_note = local_note_save;
+ note_class->can_format = note_yes;
+ note_class->archive = local_note_archive;
+
+ g_type_class_add_private ((gpointer)klass, sizeof (BijiLocalNotePrivate));
+}
+
+
+BijiNoteObj *
+biji_local_note_new_from_info (BijiNoteBook *book, BijiInfoSet *set)
+{
+ BijiNoteID *id;
+ BijiNoteObj *obj;
+ BijiLocalNote *local;
+
+ id = biji_note_id_new_from_info (set);
+
+ obj = g_object_new (BIJI_TYPE_LOCAL_NOTE,
+ "note-book", book,
+ "id", id,
+ NULL);
+
+ 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);
+
+ return obj;
+}
diff --git a/src/libbiji/provider/biji-local-note.h b/src/libbiji/provider/biji-local-note.h
new file mode 100644
index 0000000..9019b36
--- /dev/null
+++ b/src/libbiji/provider/biji-local-note.h
@@ -0,0 +1,59 @@
+/* bjb-local-note.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_NOTE_H_
+#define BIJI_LOCAL_NOTE_H_ 1
+
+#include "../biji-note-id.h"
+#include "../biji-note-obj.h"
+
+G_BEGIN_DECLS
+
+
+#define BIJI_TYPE_LOCAL_NOTE (biji_local_note_get_type ())
+#define BIJI_LOCAL_NOTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BIJI_TYPE_LOCAL_NOTE,
BijiLocalNote))
+#define BIJI_LOCAL_NOTE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BIJI_TYPE_LOCAL_NOTE,
BijiLocalNoteClass))
+#define BIJI_IS_LOCAL_NOTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BIJI_TYPE_LOCAL_NOTE))
+#define BIJI_IS_LOCAL_NOTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BIJI_TYPE_LOCAL_NOTE))
+#define BIJI_LOCAL_NOTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BIJI_TYPE_LOCAL_NOTE,
BijiLocalNoteClass))
+
+typedef struct BijiLocalNote_ BijiLocalNote;
+typedef struct BijiLocalNoteClass_ BijiLocalNoteClass;
+typedef struct BijiLocalNotePrivate_ BijiLocalNotePrivate;
+
+struct BijiLocalNote_
+{
+ BijiNoteObj parent;
+ BijiLocalNotePrivate *priv;
+};
+
+struct BijiLocalNoteClass_
+{
+ BijiNoteObjClass parent_class;
+};
+
+
+GType biji_local_note_get_type (void);
+
+
+BijiNoteObj *biji_local_note_new_from_info (BijiNoteBook *book,
+ BijiInfoSet *set);
+
+G_END_DECLS
+
+#endif /* BIJI_LOCAL_NOTE_H_ */
diff --git a/src/libbiji/provider/biji-local-provider.c b/src/libbiji/provider/biji-local-provider.c
index 3b0dfae..b210020 100644
--- a/src/libbiji/provider/biji-local-provider.c
+++ b/src/libbiji/provider/biji-local-provider.c
@@ -37,7 +37,8 @@
struct BijiLocalProviderPrivate_
{
- BijiNoteBook *book;
+ BijiProviderInfo info;
+
GFile *location;
GHashTable *items;
GCancellable *load_cancellable;
@@ -274,6 +275,7 @@ biji_local_provider_finalize (GObject *object)
g_cancellable_cancel (self->priv->load_cancellable);
g_object_unref (self->priv->load_cancellable);
+ g_object_unref (self->priv->info.icon);
G_OBJECT_CLASS (biji_local_provider_parent_class)->finalize (object);
}
@@ -285,6 +287,15 @@ 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);
+
+ /* 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);
+
}
@@ -327,18 +338,32 @@ biji_local_provider_get_property (GObject *object,
}
}
+
+const BijiProviderInfo *
+local_provider_get_info (BijiProvider *provider)
+{
+ BijiLocalProvider *self;
+
+ self = BIJI_LOCAL_PROVIDER (provider);
+ return &(self->priv->info);
+}
+
+
static void
biji_local_provider_class_init (BijiLocalProviderClass *klass)
{
GObjectClass *g_object_class;
+ BijiProviderClass *provider_class;
g_object_class = G_OBJECT_CLASS (klass);
+ provider_class = BIJI_PROVIDER_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;
+ provider_class->get_info = local_provider_get_info;
properties[PROP_LOCATION] =
g_param_spec_object ("location",
diff --git a/src/libbiji/provider/biji-own-cloud-note.c b/src/libbiji/provider/biji-own-cloud-note.c
index 997350b..be3e901 100644
--- a/src/libbiji/provider/biji-own-cloud-note.c
+++ b/src/libbiji/provider/biji-own-cloud-note.c
@@ -68,45 +68,28 @@ ocloud_note_ensure_ressource (BijiNoteObj *note)
BijiOwnCloudNote *ocnote;
GFile *file;
GFileInfo *file_info;
+ const BijiProviderInfo *prov_info;
g_return_if_fail (BIJI_IS_OWN_CLOUD_NOTE (note));
item = BIJI_ITEM (note);
ocnote = BIJI_OWN_CLOUD_NOTE (note);
file = ocnote->priv->location;
file_info = g_file_query_info (file, "time::modified", G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ prov_info = biji_provider_get_info (BIJI_PROVIDER (ocnote->priv->prov));
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->mtime = g_file_info_get_attribute_uint64 (file_info, "time::modified");
info->created = biji_note_obj_get_create_date (note);
- info->datasource_urn = g_strdup (
- BIJI_PROVIDER_GET_CLASS (ocnote->priv->prov)->get_datasource (BIJI_PROVIDER (ocnote->priv->prov)));
+ info->datasource_urn = g_strdup (prov_info->datasource);
biji_tracker_ensure_ressource_from_info (biji_item_get_book (item),
info);
}
-/* Notes creation as soon as files content retrieved */
-static void
-on_content_change (gpointer user_data)
-{
- BijiNoteObj *note;
- gchar *html;
-
- g_return_if_fail (BIJI_IS_OWN_CLOUD_NOTE (user_data));
- note = user_data;
-
- html = html_from_plain_text ((gchar*) biji_note_obj_get_raw_text (user_data));
-
- ocloud_note_set_html (note, html);
- g_free (html);
-}
-
-
/* TODO: propagate error if any
* through generic provider -> book */
void
@@ -137,7 +120,7 @@ on_content_replaced (GObject *source_object,
-void
+static void
ocloud_note_save (BijiNoteObj *note)
{
BijiOwnCloudNote *self;
@@ -165,6 +148,87 @@ ocloud_note_save (BijiNoteObj *note)
}
+/* Rename the file
+ * when note title change
+ * Also handle new notes being populated */
+
+static void
+create_new_file (BijiOwnCloudNote *self, const gchar *basename)
+{
+ GFile *folder;
+ BijiNoteObj *note;
+
+ note = BIJI_NOTE_OBJ (self);
+ folder = biji_own_cloud_provider_get_folder (self->priv->prov);
+
+ self->priv->location = g_file_get_child (folder, basename);
+ self->priv->basename = g_file_get_basename (self->priv->location);
+
+ ocloud_note_save (note);
+ ocloud_note_ensure_ressource (note);
+}
+
+
+/* with current design, title might change
+ * from user will or because note is edited */
+
+static void
+on_title_change (gpointer user_data)
+{
+ BijiOwnCloudNote *self;
+ gchar *old_title;
+ const gchar *new_title;
+
+
+ g_return_if_fail (BIJI_IS_OWN_CLOUD_NOTE (user_data));
+
+ self = BIJI_OWN_CLOUD_NOTE (user_data);
+ old_title = self->priv->basename;
+ new_title = biji_note_id_get_title (self->priv->id);
+
+
+ if (old_title == NULL)
+ {
+ if (new_title != NULL)
+ create_new_file (self, new_title);
+ }
+
+ else if (g_strcmp0 (old_title, new_title) != 0)
+ {
+ g_file_delete_async (self->priv->location,
+ G_PRIORITY_LOW,
+ NULL,
+ NULL,
+ NULL);
+ // g_object_unref (self->priv->location);
+ // g_free (self->priv->basename);
+ create_new_file (self, new_title);
+ }
+
+}
+
+
+/* TODO : check if the title needs change
+ * and adjust */
+
+static void
+on_content_change (gpointer user_data)
+{
+ BijiNoteObj *note;
+ gchar *html;
+
+ g_return_if_fail (BIJI_IS_OWN_CLOUD_NOTE (user_data));
+
+ note = user_data;
+ html = html_from_plain_text ((gchar*) biji_note_obj_get_raw_text (user_data));
+ ocloud_note_set_html (note, html);
+ g_free (html);
+}
+
+
+
+
+
static void
biji_own_cloud_note_finalize (GObject *object)
@@ -279,10 +343,24 @@ BijiNoteObj *biji_own_cloud_note_new_from_info (BijiOwnCloudPro
biji_note_obj_set_create_date (retval, info->created);
g_signal_connect_swapped (id, "notify::content",
G_CALLBACK (on_content_change), retval);
+ g_signal_connect_swapped (id, "notify::title",
+ G_CALLBACK (on_title_change), retval);
+
+ /* That's not a blank note. That's an existing file. */
+ if (info->url != NULL)
+ {
+ ocloud->priv->location = g_file_new_for_commandline_arg (info->url);
+ ocloud->priv->basename = g_file_get_basename (ocloud->priv->location);
+ }
- ocloud->priv->location = g_file_new_for_commandline_arg (info->url);
- ocloud->priv->basename = g_file_get_basename (ocloud->priv->location);
+ /* Really new note */
+
+ else
+ {
+ ocloud->priv->location = NULL;
+ ocloud->priv->basename = NULL;
+ }
return retval;
}
diff --git a/src/libbiji/provider/biji-own-cloud-provider.c b/src/libbiji/provider/biji-own-cloud-provider.c
index 4145a3d..b45e019 100644
--- a/src/libbiji/provider/biji-own-cloud-provider.c
+++ b/src/libbiji/provider/biji-own-cloud-provider.c
@@ -24,6 +24,8 @@
*/
+
+
#include "biji-own-cloud-note.h"
#include "biji-own-cloud-provider.h"
@@ -47,6 +49,8 @@ static GParamSpec *properties[OCLOUD_PROV_PROP] = { NULL, };
struct BijiOwnCloudProviderPrivate_
{
+ BijiProviderInfo info;
+
GoaObject *object;
GoaAccount *account;
gchar *identifier;
@@ -118,6 +122,7 @@ biji_own_cloud_provider_finalize (GObject *object)
g_free (self->priv->identifier);
g_object_unref (self->priv->account);
g_object_unref (self->priv->object);
+ g_object_unref (self->priv->info.icon);
G_OBJECT_CLASS (biji_own_cloud_provider_parent_class)->finalize (object);
}
@@ -445,13 +450,15 @@ on_notes_mined (GObject *source_object,
static void
mine_notes (gboolean result, gpointer user_data)
{
- BijiOwnCloudProvider *self;
- BijiProvider *provider;
- gchar *query;
+ BijiOwnCloudProvider *self;
+ BijiProvider *provider;
+ const BijiProviderInfo *info;
+ gchar *query;
self = user_data;
provider = user_data;
+ info = biji_provider_get_info (provider);
/*
* We could as well use nie:url to lookup existing db
@@ -466,7 +473,7 @@ 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 (provider));
+ info->datasource);
tracker_sparql_connection_query_async (
biji_note_book_get_tracker_connection (
@@ -592,22 +599,50 @@ static void
biji_own_cloud_provider_constructed (GObject *obj)
{
BijiOwnCloudProvider *self;
+ BijiOwnCloudProviderPrivate *priv;
+ GError *error;
+ GIcon *icon;
G_OBJECT_CLASS (biji_own_cloud_provider_parent_class)->constructed (obj);
self = BIJI_OWN_CLOUD_PROVIDER (obj);
+ priv = self->priv;
+
- if (!GOA_IS_OBJECT (self->priv->object))
+ if (!GOA_IS_OBJECT (priv->object))
return;
- self->priv->account = goa_object_get_account (self->priv->object);
+ priv->account = goa_object_get_account (priv->object);
- if (self->priv->account != NULL)
+ if (priv->account != NULL)
{
- self->priv->identifier = g_strdup_printf ("gn:goa-account:%s",
- goa_account_get_id (self->priv->account));
+
+ priv->info.unique_id = goa_account_get_id (priv->account);
+ priv->info.datasource = g_strdup_printf ("gn:goa-account:%s",
+ priv->info.unique_id);
+ priv->info.name = goa_account_get_provider_name (priv->account);
+
+ error = NULL;
+ icon = g_icon_new_for_string (goa_account_get_provider_icon (priv->account),
+ &error);
+ if (error)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ priv->info.icon = NULL;
+ }
+
+ else
+ {
+ priv->info.icon = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_INVALID);
+ gtk_image_set_pixel_size (GTK_IMAGE (priv->info.icon), 48);
+ g_object_ref (priv->info.icon);
+ }
+
get_mount (self);
}
+
+
}
@@ -663,13 +698,46 @@ biji_own_cloud_provider_get_property (GObject *object,
}
-static const gchar *
-own_cloud_get_datasource (BijiProvider *provider)
+static const BijiProviderInfo *
+own_cloud_get_info (BijiProvider *provider)
{
BijiOwnCloudProvider *self;
self = BIJI_OWN_CLOUD_PROVIDER (provider);
- return (const gchar *) self->priv->identifier;
+ return &(self->priv->info);
+}
+
+
+
+/*
+ * Note is created from sratch, without any file or tracker metadata
+ * But as soon as note title changes,
+ * things will go right.
+ * Promise. */
+
+BijiNoteObj *
+own_cloud_create_note (BijiProvider *provider,
+ gchar *str)
+{
+ BijiInfoSet info;
+
+ info.url = NULL;
+ info.title = NULL;
+ info.mtime = g_get_real_time ();
+ info.content = "";
+ info.created = g_get_real_time ();
+
+ return biji_own_cloud_note_new_from_info (
+ BIJI_OWN_CLOUD_PROVIDER (provider),
+ biji_provider_get_book (provider),
+ &info);
+}
+
+
+GFile *
+biji_own_cloud_provider_get_folder (BijiOwnCloudProvider *provider)
+{
+ return provider->priv->folder;
}
@@ -686,7 +754,9 @@ biji_own_cloud_provider_class_init (BijiOwnCloudProviderClass *klass)
g_object_class->get_property = biji_own_cloud_provider_get_property;
g_object_class->set_property = biji_own_cloud_provider_set_property;
g_object_class->constructed = biji_own_cloud_provider_constructed;
- provider_class->get_datasource = own_cloud_get_datasource;
+
+ provider_class->get_info = own_cloud_get_info;
+ provider_class->create_note = own_cloud_create_note;
properties[PROP_GOA_OBJECT] =
diff --git a/src/libbiji/provider/biji-own-cloud-provider.h b/src/libbiji/provider/biji-own-cloud-provider.h
index 5a50831..61f234f 100644
--- a/src/libbiji/provider/biji-own-cloud-provider.h
+++ b/src/libbiji/provider/biji-own-cloud-provider.h
@@ -56,6 +56,9 @@ BijiProvider *biji_own_cloud_provider_new (BijiNoteBook *book,
GoaObject *object);
+GFile *biji_own_cloud_provider_get_folder (BijiOwnCloudProvider *provider);
+
+
G_END_DECLS
#endif /* BIJI_OWN_CLOUD_PROVIDER_H_ */
diff --git a/src/libbiji/provider/biji-provider.c b/src/libbiji/provider/biji-provider.c
index 9221ed5..d100a46 100644
--- a/src/libbiji/provider/biji-provider.c
+++ b/src/libbiji/provider/biji-provider.c
@@ -64,6 +64,13 @@ biji_provider_get_book (BijiProvider *provider)
}
+const BijiProviderInfo *
+biji_provider_get_info (BijiProvider *provider)
+{
+ return BIJI_PROVIDER_GET_CLASS (provider)->get_info (provider);
+}
+
+
static void
biji_provider_finalize (GObject *object)
{
diff --git a/src/libbiji/provider/biji-provider.h b/src/libbiji/provider/biji-provider.h
index 9bc306b..ca2185a 100644
--- a/src/libbiji/provider/biji-provider.h
+++ b/src/libbiji/provider/biji-provider.h
@@ -19,6 +19,7 @@
#define BIJI_PROVIDER_H_ 1
#include <glib-object.h>
+#include <glib/gi18n.h> // translate providers type
#include "../biji-note-book.h"
@@ -37,6 +38,20 @@ typedef struct BijiProviderClass_ BijiProviderClass;
typedef struct BijiProviderPrivate_ BijiProviderPrivate;
+typedef struct
+{
+ const gchar *unique_id; // anything unique, eg, goa_account_get_id
+ const gchar *datasource; // for tracker
+
+ gchar *name; // eg, goa_account_get_provider_name
+ GtkWidget *icon;
+
+ gchar *domain; // todo - distinguish several accounts
+ gchar *user; // todo - distinguish several accounts
+
+} BijiProviderInfo;
+
+
struct BijiProvider_
{
GObject parent;
@@ -48,18 +63,29 @@ struct BijiProviderClass_
{
GObjectClass parent_class;
- void (*notify_loaded) (BijiProvider *provider,
- GList *loaded_items);
- const gchar* (*get_datasource) (BijiProvider *provider);
+ const BijiProviderInfo* (*get_info) (BijiProvider *provider);
+
+
+ void (*notify_loaded) (BijiProvider *provider,
+ GList *loaded_items);
+
+
+ BijiNoteObj* (*create_note) (BijiProvider *provider,
+ gchar *content);
};
-GType biji_provider_get_type (void);
-BijiNoteBook *biji_provider_get_book (BijiProvider *provider);
+GType biji_provider_get_type (void);
+
+
+BijiNoteBook *biji_provider_get_book (BijiProvider *provider);
+
+
+const BijiProviderInfo *biji_provider_get_info (BijiProvider *provider);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]