[bijiben/gnome-3-10] Tomboy notes: be sure not to alter source



commit 9d9fdc24faf421e24e7ceb8e24407c669b2e4dcf
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Fri Sep 27 00:34:55 2013 +0200

    Tomboy notes: be sure not to alter source
    
    See 708812
    New classes: BijiImportProvider, BijiTomboyReader
    Instead of directly creating a note from an existing file
    (then altering path and saving...), read the data, instanciate
    an object then save it as anyone would expect.

 src/bjb-bijiben.c                                 |  155 +------
 src/libbiji/Makefile.am                           |    4 +
 src/libbiji/biji-date-time.c                      |   11 +
 src/libbiji/biji-date-time.h                      |   17 +-
 src/libbiji/biji-error.c                          |    7 +-
 src/libbiji/biji-error.h                          |    7 +-
 src/libbiji/biji-note-book.c                      |   45 ++-
 src/libbiji/biji-note-book.h                      |   16 +
 src/libbiji/deserializer/biji-lazy-deserializer.c |   23 +-
 src/libbiji/deserializer/biji-tomboy-reader.c     |  527 +++++++++++++++++++++
 src/libbiji/deserializer/biji-tomboy-reader.h     |   64 +++
 src/libbiji/provider/biji-import-provider.c       |  367 ++++++++++++++
 src/libbiji/provider/biji-import-provider.h       |   75 +++
 src/libbiji/provider/biji-local-provider.c        |   37 ++
 src/libbiji/provider/biji-own-cloud-provider.c    |    2 +-
 src/libbiji/provider/biji-provider.h              |   42 ++-
 16 files changed, 1225 insertions(+), 174 deletions(-)
---
diff --git a/src/bjb-bijiben.c b/src/bjb-bijiben.c
index 5b8467f..0fc0bd4 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-bijiben.c
@@ -215,162 +215,15 @@ bijiben_init (Bijiben *self)
   priv->is_loaded = FALSE;
 }
 
-/* Import. TODO : move to libbiji */
-
-#define ATTRIBUTES_FOR_NOTEBOOK "standard::content-type,standard::name"
-
-static BijiNoteObj *
-abort_note (BijiNoteObj *rejected)
-{
-  g_object_unref (rejected);
-  return NULL;
-}
-
-static BijiNoteObj *
-copy_note (GFileInfo *info, GFile *container)
-{
-  BijiNoteObj *retval = NULL;
-  const gchar *name;
-  gchar *path;
-  Bijiben *self;
-  BijiNoteBook *book;
-
-  self = BIJIBEN_APPLICATION (g_application_get_default ());
-  book = self->priv->book;
-
-  /* First make sure it's a note */
-  name = g_file_info_get_name (info);
-  if (!g_str_has_suffix (name, ".note"))
-    return NULL;
-
-  /* Deserialize it */
-  path = g_build_filename (g_file_get_path (container), name, NULL);
-  retval = biji_note_get_new_from_file (book, path);
-  g_free (path);
-
-  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (retval), NULL);
-
-  /* Not a Template */
-  if (biji_note_obj_is_template (retval))
-    return abort_note (retval);
-
-  /* Assign the new path */
-  path = g_build_filename (g_get_user_data_dir (), "bijiben", name, NULL);
-  g_object_set (retval, "path", path, NULL);
-  g_free (path);
-
-  return retval;
-}
-
-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);
-}
-
-/* Some notes might have been added previously */
-static void
-go_through_notes_cb (GFileEnumerator *enumerator, GAsyncResult *res, Bijiben *self)
-{
-  GList *notes_info;
-  GList *notes_proposal = NULL;
-  GList *l;
-  GFile *container;
-
-  /* Sanitize title & color */
-  gchar *unique_title, *default_color;
-  BjbSettings *settings;
-  GdkRGBA color;
-
-  container = g_file_enumerator_get_container (enumerator);
-  notes_info = g_file_enumerator_next_files_finish (enumerator, res, NULL);
-  g_file_enumerator_close_async (enumerator, G_PRIORITY_DEFAULT, NULL,
-                                 release_enum_cb, self);
-
-  /* Get the GList of notes and load them */
-  for ( l=notes_info; l !=NULL; l = l->next)
-  {
-    GFileInfo *info = G_FILE_INFO (l->data);
-    BijiNoteObj *iter = copy_note (info, container);
-    if (iter)
-      notes_proposal = g_list_prepend (notes_proposal, iter);
-  }
-
-  for (l = notes_proposal; l != NULL; l = l->next)
-  {
-    BijiNoteObj *note = l->data;
-    const gchar *path = biji_item_get_uuid (BIJI_ITEM (note));
-
-    /* Don't add an already imported note */
-    if (biji_note_book_get_item_at_path (self->priv->book, path))
-    {
-      abort_note (note);
-    }
-
-    /* Sanitize, append & save */
-    else
-    {
-      /* Title */
-      unique_title = biji_note_book_get_unique_title (self->priv->book,
-                                                      biji_item_get_title (BIJI_ITEM (note)));
-      biji_note_obj_set_title (note, unique_title);
-      g_free (unique_title);
-
-      /* Color */
-      settings = bjb_app_get_settings (self);
-      g_object_get (G_OBJECT (settings), "color", &default_color, NULL);
-      if (gdk_rgba_parse (&color, default_color))
-        biji_note_obj_set_rgba (note, &color);
-
-      g_free (default_color);
-
-      biji_note_book_add_item (self->priv->book, BIJI_ITEM (note), FALSE);
-      biji_note_obj_save_note (note);
-    }
-
-  }
-
-  /* NoteBook will notify for all opened windows */
-
-  g_list_free_full (notes_info, g_object_unref);
-  g_list_free (notes_proposal);
-  biji_note_book_notify_changed (self->priv->book, BIJI_BOOK_MASS_CHANGE, NULL);
-}
-
-static void
-list_notes_to_copy (GObject *src_obj, GAsyncResult *res, Bijiben *self)
-{
-  GFileEnumerator *enumerator;
-  GError *error = NULL;
-
-  enumerator = g_file_enumerate_children_finish (G_FILE (src_obj), res, &error);
-
-  if (error)
-  {
-    g_warning ("Enumerator failed : %s", error->message);
-    g_error_free (error);
-    g_file_enumerator_close_async (enumerator, G_PRIORITY_DEFAULT, NULL, release_enum_cb, self);
-  }
-
-  else
-  {
-    g_file_enumerator_next_files_async (enumerator, G_MAXINT, G_PRIORITY_DEFAULT, NULL,
-                                        (GAsyncReadyCallback) go_through_notes_cb, self);
-  }
-}
-
 
 void
 bijiben_import_notes (Bijiben *self, gchar *location)
 {
-  GFile *to_import = g_file_new_for_path (location);
-
-  g_file_enumerate_children_async (to_import, ATTRIBUTES_FOR_NOTEBOOK,
-                                   G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
-                                   NULL, (GAsyncReadyCallback) list_notes_to_copy, self);
+  g_debug ("IMPORT to %s", bjb_settings_get_default_location (self->priv->settings));
 
-  g_object_unref (to_import);
+  biji_note_book_import_uri (self->priv->book,
+                             bjb_settings_get_default_location (self->priv->settings),
+                             location);
 }
 
 
diff --git a/src/libbiji/Makefile.am b/src/libbiji/Makefile.am
index 5c8dcea..a43d22d 100644
--- a/src/libbiji/Makefile.am
+++ b/src/libbiji/Makefile.am
@@ -37,12 +37,16 @@ libbiji_la_SOURCES =  \
        biji-zeitgeist.h \
        deserializer/biji-lazy-deserializer.c \
        deserializer/biji-lazy-deserializer.h \
+       deserializer/biji-tomboy-reader.c \
+       deserializer/biji-tomboy-reader.h \
        editor/biji-editor-selection.c \
        editor/biji-editor-selection.h \
        editor/biji-editor-utils.c \
        editor/biji-editor-utils.h \
        editor/biji-webkit-editor.c \
        editor/biji-webkit-editor.h \
+       provider/biji-import-provider.c \
+       provider/biji-import-provider.h \
        provider/biji-local-provider.c \
        provider/biji-local-provider.h \
        provider/biji-own-cloud-note.c \
diff --git a/src/libbiji/biji-date-time.c b/src/libbiji/biji-date-time.c
index 9403c85..2df770f 100644
--- a/src/libbiji/biji-date-time.c
+++ b/src/libbiji/biji-date-time.c
@@ -45,3 +45,14 @@ biji_get_time_diff_with_time (glong sec_since_epoch)
 
   return _("Unknown");
 }
+
+
+
+gint64
+iso8601_to_gint64 (gchar *iso8601)
+{
+  GTimeVal time = {0,0};
+
+  g_time_val_from_iso8601 (iso8601, &time);
+  return (gint64) time.tv_sec;
+}
diff --git a/src/libbiji/biji-date-time.h b/src/libbiji/biji-date-time.h
index afcce58..b840586 100644
--- a/src/libbiji/biji-date-time.h
+++ b/src/libbiji/biji-date-time.h
@@ -1,5 +1,5 @@
 /* biji-date-time.h
- * Copyright (C) Pierre-Yves LUYTEN 2011 <py luyten fr>
+ * Copyright (C) Pierre-Yves LUYTEN 2011-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
@@ -14,7 +14,20 @@
  * 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_DATE_TIME_H
+#define _BIJI_DATE_TIME_H
+
+
 #include <glib-object.h>
 #include <glib/gprintf.h>
 
-gchar * biji_get_time_diff_with_time (glong sec_since_epoch);
+
+
+gchar            *biji_get_time_diff_with_time            (glong sec_since_epoch);
+
+
+
+gint64            iso8601_to_gint64                       (gchar *iso8601);
+
+
+#endif /* _BIJI_DATE_TIME_H */
diff --git a/src/libbiji/biji-error.c b/src/libbiji/biji-error.c
index 4923107..0a8536f 100644
--- a/src/libbiji/biji-error.c
+++ b/src/libbiji/biji-error.c
@@ -44,4 +44,9 @@ biji_error_quark (void)
 }
 
 
-
+GError *
+biji_error_new (BijiErrorType type,
+                gchar *message)
+{
+  return g_error_new (BIJI_ERROR, type, message);
+}
diff --git a/src/libbiji/biji-error.h b/src/libbiji/biji-error.h
index 23c8367..da89ff6 100644
--- a/src/libbiji/biji-error.h
+++ b/src/libbiji/biji-error.h
@@ -30,7 +30,8 @@ G_BEGIN_DECLS
 typedef enum
 {
   BIJI_ERROR_TRACKER,           /* org.gnome.Biji.Error.Tracker */
-} BijiError;
+  BIJI_ERROR_SOURCE
+} BijiErrorType;
 
 
 
@@ -43,6 +44,10 @@ typedef enum
 GQuark               biji_error_quark                       (void);
 
 
+GError              *biji_error_new                        (BijiErrorType type,
+                                                            gchar *message);
+
+
 G_END_DECLS
 
 #endif /* _BIJI_ERROR_H */
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 2cb416b..a96f0e0 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -23,6 +23,7 @@
 #include "biji-collection.h"
 #include "biji-error.h"
 
+#include "provider/biji-import-provider.h"
 #include "provider/biji-local-provider.h"
 #include "provider/biji-own-cloud-provider.h"
 
@@ -674,6 +675,23 @@ biji_note_book_local_note_new           (BijiNoteBook *book, gchar *str)
 }
 
 
+/* Create the importer == switch depending on the uri.
+ * That's all, the importer is responsible
+ * for emiting the signal transfering the notes
+ * And no need to _add_provider, it's a tmp provider. */
+void
+biji_note_book_import_uri (BijiNoteBook *book,
+                           gchar *target_provider_id,
+                           gchar *uri)
+{
+  BijiProvider *ret;
+
+  ret = biji_import_provider_new (book, target_provider_id, uri);
+  g_signal_connect (ret, "loaded", 
+                    G_CALLBACK (on_provider_loaded_cb), book);
+  
+}
+
 /* 
  * Use "local" for a local note new
  * Use goa_account_get_id for goa
@@ -698,7 +716,7 @@ biji_note_book_note_new            (BijiNoteBook *book,
                                   provider_id);
 
 
-  retval = BIJI_PROVIDER_GET_CLASS (provider)->create_note (provider, str);
+  retval = BIJI_PROVIDER_GET_CLASS (provider)->create_new_note (provider, str);
   // do not save. up to the provider implementation to save it or not
   // at creation.
   biji_note_book_add_item (book, BIJI_ITEM (retval), TRUE);
@@ -706,3 +724,28 @@ biji_note_book_note_new            (BijiNoteBook *book,
   return retval;
 }
                                     
+
+
+
+BijiNoteObj *
+biji_note_book_note_new_full (BijiNoteBook *book,
+                              gchar        *provider_id,
+                              gchar        *suggested_path,
+                              BijiInfoSet  *info,
+                              gchar        *html,
+                              GdkRGBA      *color)
+{
+  BijiProvider *provider;
+  BijiNoteObj *retval;
+
+  provider = g_hash_table_lookup (book->priv->providers,
+                                  provider_id);
+
+  retval = BIJI_PROVIDER_GET_CLASS (provider)->create_note_full (provider,
+                                                                 suggested_path,
+                                                                 info,
+                                                                 html,
+                                                                 color);
+
+  return retval;
+}
diff --git a/src/libbiji/biji-note-book.h b/src/libbiji/biji-note-book.h
index 4cc3710..f92a746 100644
--- a/src/libbiji/biji-note-book.h
+++ b/src/libbiji/biji-note-book.h
@@ -5,6 +5,7 @@
 #include <tracker-sparql.h>
 #include <zeitgeist.h>
 
+#include "biji-info-set.h"
 #include "biji-note-obj.h"
 
 #define GOA_API_IS_SUBJECT_TO_CHANGE
@@ -57,6 +58,11 @@ BijiNoteBook    *biji_note_book_new                   (GFile *location,
                                                        GError **error);
 
 
+void             biji_note_book_import_uri            (BijiNoteBook *book,
+                                                       gchar *target_provider_id,
+                                                       gchar *uri);
+
+
 void             biji_note_book_add_goa_object        (BijiNoteBook *book,
                                                        GoaObject *object);
 
@@ -101,6 +107,8 @@ BijiItem        *biji_note_book_get_item_at_path      (BijiNoteBook *book,
 GList           *biji_note_book_get_items             (BijiNoteBook *book);
 
 
+
+// deprecated - instead we'll use new import / providers facilities
 BijiNoteObj     *biji_note_get_new_from_file          (BijiNoteBook *book,
                                                        const gchar* tomboy_format_note_path);
 
@@ -111,6 +119,14 @@ BijiNoteObj     *biji_note_book_note_new              (BijiNoteBook *book,
                                                        gchar        *provider_id);
 
 
+BijiNoteObj     *biji_note_book_note_new_full         (BijiNoteBook *book,
+                                                       gchar        *provider_id,
+                                                       gchar        *suggested_path,
+                                                       BijiInfoSet  *info,
+                                                       gchar        *html,
+                                                       GdkRGBA      *color);
+
+
 G_END_DECLS
 
 #endif /* _BIJI_NOTE_BOOK_H_ */
diff --git a/src/libbiji/deserializer/biji-lazy-deserializer.c 
b/src/libbiji/deserializer/biji-lazy-deserializer.c
index 71eb36c..ac277df 100644
--- a/src/libbiji/deserializer/biji-lazy-deserializer.c
+++ b/src/libbiji/deserializer/biji-lazy-deserializer.c
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include "biji-lazy-deserializer.h"
+#include "../biji-date-time.h"
 #include "../biji-note-obj.h"
 #include "../biji-string.h"
 
@@ -162,16 +163,6 @@ biji_lazy_deserializer_class_init (BijiLazyDeserializerClass *klass)
 typedef void BijiReaderFunc (BijiNoteObj *note, gchar *string);
 
 
-static gint64
-str_to_gint64 (xmlChar *str)
-{
-  GTimeVal time = {0,0};
-
-  g_time_val_from_iso8601 ((gchar*) str, &time);
-  return (gint64) time.tv_sec;
-}
-
-
 static void
 biji_process_string (xmlTextReaderPtr reader,
                      BijiReaderFunc process_xml,
@@ -472,22 +463,22 @@ processNode (BijiLazyDeserializer *self)
 
   if (g_strcmp0 ((gchar*) name, "last-change-date") == 0)
   {
-    xmlChar *result = xmlTextReaderReadString (r);
-    biji_note_obj_set_mtime (n, str_to_gint64 (result));
+    gchar *result = (gchar*) xmlTextReaderReadString (r);
+    biji_note_obj_set_mtime (n, iso8601_to_gint64 (result));
     free (result);
   }
 
   if (g_strcmp0 ((gchar*) name, "last-metadata-change-date") == 0)
   {
-    xmlChar *result = xmlTextReaderReadString (r);
-    biji_note_obj_set_last_metadata_change_date (n, str_to_gint64 (result));
+    gchar *result = (gchar*) xmlTextReaderReadString (r);
+    biji_note_obj_set_last_metadata_change_date (n, iso8601_to_gint64 (result));
     free (result);
   }
 
   if (g_strcmp0 ((gchar*) name, "create-date") == 0)
   {
-    xmlChar *result = xmlTextReaderReadString (r);
-    biji_note_obj_set_create_date (n, str_to_gint64 (result));
+    gchar *result = (gchar*) xmlTextReaderReadString (r);
+    biji_note_obj_set_create_date (n, iso8601_to_gint64 (result));
     free (result);
   }
 
diff --git a/src/libbiji/deserializer/biji-tomboy-reader.c b/src/libbiji/deserializer/biji-tomboy-reader.c
new file mode 100644
index 0000000..a17c021
--- /dev/null
+++ b/src/libbiji/deserializer/biji-tomboy-reader.c
@@ -0,0 +1,527 @@
+/*
+ * biji-tomboy-reader.c
+ * 
+ * Copyright 2013 Pierre-Yves Luyten <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/>.
+ */
+
+
+/* TODO escape strings to have sane html */
+
+#include <libxml/xmlreader.h>
+#include <string.h>
+
+#include "../biji-error.h"
+#include "../biji-date-time.h"
+#include "../biji-info-set.h"
+#include "../biji-string.h"
+
+#include "biji-tomboy-reader.h"
+
+
+#define TOMBOY_NS "http://beatniksoftware.com/tomboy";
+
+
+/* gobject properties */
+enum {
+  PROP_0,
+  PROP_SRC_PATH,
+  TOMBOY_READER_PROP
+};
+
+
+
+static GParamSpec *properties[TOMBOY_READER_PROP] = { NULL, };
+
+
+typedef enum 
+{
+  NO_TYPE,
+  TOMBOY_1,
+  TOMBOY_2,
+  TOMBOY_3,
+  NUM_NOTE_TYPES
+} BijiTomboyType;
+
+
+struct BijiTomboyReaderPrivate_
+{
+
+  /* File */
+
+  gchar *path;
+  BijiTomboyType type;
+
+
+  /* Read */
+
+  xmlTextReaderPtr r;
+  xmlTextReaderPtr inner;
+  GString *raw_text;
+  GString *html;
+
+
+
+  /* Return */
+
+  GError *error;
+  BijiInfoSet *set;
+  gint64  metadata_mtime;
+  GQueue *collections;
+
+};
+
+
+
+
+G_DEFINE_TYPE (BijiTomboyReader, biji_tomboy_reader, G_TYPE_OBJECT)
+
+
+
+
+/* Tomboy Inner XML */
+
+static void
+process_tomboy_start_elem (BijiTomboyReader *self)
+{
+  BijiTomboyReaderPrivate *priv;
+  const gchar *element_name;
+
+  priv = self->priv;
+  element_name = (const gchar *) xmlTextReaderConstName (priv->inner);
+
+  if (g_strcmp0 (element_name, "note-content")==0)
+    return;
+
+  if (g_strcmp0 (element_name, "bold")==0)
+    priv->html = g_string_append (priv->html, "<b>");
+
+  if (g_strcmp0 (element_name, "italic")==0)
+    priv->html = g_string_append (priv->html, "<i>");
+
+  if (g_strcmp0 (element_name, "strikethrough")==0)
+    priv->html = g_string_append (priv->html, "<strike>");
+
+  /* Currently tomboy has unordered list */
+
+  if (g_strcmp0 (element_name, "list")==0)
+    priv->html = g_string_append (priv->html, "<ul>");
+
+  if (g_strcmp0 (element_name, "list-item")==0)
+    priv->html = g_string_append (priv->html, "<li>");
+}
+
+
+
+static void
+process_tomboy_end_elem (BijiTomboyReader *self)
+{
+  BijiTomboyReaderPrivate *priv = self->priv;
+  const gchar *element_name;
+  
+  element_name = (const gchar *) xmlTextReaderConstName (priv->inner);
+
+  if (g_strcmp0 (element_name, "note-content")==0)
+    return;
+
+  if (g_strcmp0 (element_name, "bold")==0)
+    priv->html = g_string_append (priv->html, "</b>");
+
+  if (g_strcmp0 (element_name, "italic")==0)
+    priv->html = g_string_append (priv->html, "</i>");
+
+  if (g_strcmp0 (element_name, "strikethrough")==0)
+    priv->html = g_string_append (priv->html, "</strike>");
+
+  /* Currently tomboy has unordered list */
+
+  if (g_strcmp0 (element_name, "list")==0)
+    priv->html = g_string_append (priv->html, "</ul>");
+
+  if (g_strcmp0 (element_name, "list-item")==0)
+    priv->html = g_string_append (priv->html, "</li>");
+}
+
+
+
+static void
+process_tomboy_text_elem (BijiTomboyReader *self)
+{
+  const gchar *text;
+  BijiTomboyReaderPrivate *priv = self->priv;
+
+  text = (const gchar *) xmlTextReaderConstValue (priv->inner);
+
+  /* Simply append the text to both raw & html
+   * FIXME : escape things for html */
+
+  priv->raw_text = g_string_append (priv->raw_text, text);
+  priv->html = g_string_append (priv->html, text);
+}
+
+
+
+static void
+process_tomboy_node (BijiTomboyReader *self)
+{
+  int            type;
+  const xmlChar *name ;
+  BijiTomboyReaderPrivate *priv = self->priv;
+
+  type  = xmlTextReaderNodeType (priv->inner);
+  name  = xmlTextReaderConstName (priv->inner);
+
+  if (name == NULL)
+    name = BAD_CAST "(NULL)";
+
+  switch (type)
+  {
+    case XML_ELEMENT_NODE:
+      process_tomboy_start_elem (self);
+      break;
+
+    case XML_ELEMENT_DECL:
+      process_tomboy_end_elem (self);
+      break;
+
+    case XML_TEXT_NODE:
+      process_tomboy_text_elem (self);
+      break;
+
+    case XML_DTD_NODE:
+      process_tomboy_text_elem (self);
+      break;
+  }
+}
+
+
+
+static void
+process_tomboy_xml_content (BijiTomboyReader *self, gchar *text)
+{
+  BijiTomboyReaderPrivate *priv;
+  gint ret;
+
+  priv = self->priv;
+  g_string_append (priv->html, "<html xmlns=\"http://www.w3.org/1999/xhtml\";><body>");
+
+  priv->inner = xmlReaderForMemory (text,
+                                    strlen (text),
+                                    "", "UTF-8", 0);
+
+  ret = xmlTextReaderRead (priv->inner);
+
+  /* Make the GString grow as we read */
+  while (ret == 1)
+  {
+    process_tomboy_node (self);
+    ret = xmlTextReaderRead (priv->inner);
+  }
+
+
+  /* Close the html and set content */
+  g_string_append (priv->html, "</body></html>");
+  priv->set->content = g_strdup (priv->raw_text->str);
+}
+
+
+
+
+
+
+static void
+processNode (BijiTomboyReader *self) 
+{
+  BijiTomboyReaderPrivate *priv;
+  xmlTextReaderPtr r;
+  gchar *name, *result;
+  gchar     *tag;
+  GString   *norm;
+
+
+  priv = self->priv;
+  r = priv->r;
+  name = (gchar*) xmlTextReaderName (r);
+
+
+  if (g_strcmp0 (name, "title") == 0)
+    priv->set->title = (gchar*) xmlTextReaderReadString (r);
+    
+
+  if (g_strcmp0(name, "text") == 0)
+  {
+    process_tomboy_xml_content (self, (gchar*) xmlTextReaderReadInnerXml (r));
+  }
+
+
+  if (g_strcmp0 (name, "last-change-date") == 0)
+  {
+    result = (gchar*) xmlTextReaderReadString (r);
+    priv->set->mtime = iso8601_to_gint64 (result);
+    g_free (result);
+  }
+
+
+  if (g_strcmp0 (name, "last-metadata-change-date") == 0)
+  {
+    result = (gchar*) xmlTextReaderReadString (r);
+    priv->metadata_mtime = iso8601_to_gint64 (result);
+    g_free (result);
+  }
+
+
+  if (g_strcmp0 (name, "create-date") == 0)
+  {
+    result = (gchar*) xmlTextReaderReadString (r);
+    priv->set->created  =  iso8601_to_gint64 (result);
+    g_free (result);
+  }
+
+
+
+  if (g_strcmp0 (name,"tag") == 0 )  
+  {
+    tag = (gchar*) xmlTextReaderReadString(r);
+
+    if (g_str_has_prefix (tag,"system:template"))
+    {
+      priv->error = biji_error_new (BIJI_ERROR_SOURCE,
+                                    "Aborting import for template note.");
+    }
+
+    else if (g_str_has_prefix (tag,"system:notebook:"))
+    {
+      norm = g_string_new (tag);
+      g_string_erase (norm,0,16);
+      //biji_item_add_collection (BIJI_ITEM (n), NULL, norm->str);
+      //g_queue_push_head (priv->collections, norm->str);
+      g_string_free (norm, TRUE);
+    }
+
+    free (tag);
+  }
+
+
+  xmlFree(name);
+}
+
+static void
+biji_tomboy_reader_constructed (GObject *obj)
+{
+  BijiTomboyReader *self;
+  BijiTomboyReaderPrivate *priv;
+  xmlDocPtr doc;
+  xmlNodePtr cur;
+  xmlChar     *version; 
+
+  self = BIJI_TOMBOY_READER (obj);
+  priv = self->priv;
+ 
+
+  doc = xmlParseFile (priv->path);
+
+  if (doc == NULL ) 
+  {
+    priv->error = biji_error_new (BIJI_ERROR_SOURCE,
+                                  "File not parsed successfully");
+    return;
+  }
+
+
+  cur = xmlDocGetRootElement (doc);
+
+  if (cur == NULL) 
+  {
+    priv->error = biji_error_new (BIJI_ERROR_SOURCE,
+                                  "File empty");
+    xmlFreeDoc(doc);
+    return;
+  }
+
+
+  if (xmlStrcmp(cur->name, (const xmlChar *) "note")) 
+  {
+    priv->error = biji_error_new (BIJI_ERROR_SOURCE,
+                                  "Root node != note");
+    xmlFreeDoc(doc);
+    return;
+  }
+
+  version = xmlGetNoNsProp (cur, BAD_CAST "version");
+
+  if (g_strcmp0 ((const gchar*) version, "0.1") == 0)
+    priv->type = TOMBOY_1;
+
+  else if (g_strcmp0 ((const gchar*) version, "0.2") == 0)
+    priv->type = TOMBOY_2;
+
+  else if (g_strcmp0 ((const gchar*) version, "0.3") == 0)
+    priv->type = TOMBOY_3;
+
+  priv->r = xmlNewTextReaderFilename (priv->path);
+
+  while ( xmlTextReaderRead(self->priv->r) == 1 )
+  {
+    if ( xmlTextReaderNodeType(self->priv->r) == 1 )
+    {
+      processNode(self);
+    }
+  }
+
+  xmlFree (version);
+  xmlFreeDoc (doc);
+}
+
+
+static void
+biji_tomboy_reader_set_property (GObject      *object,
+                                 guint         property_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  BijiTomboyReader *self = BIJI_TOMBOY_READER (object);
+
+
+  switch (property_id)
+    {
+    case PROP_SRC_PATH:
+      self->priv->path = g_value_dup_string (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+
+
+static void
+biji_tomboy_reader_get_property (GObject    *object,
+                                 guint       property_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  BijiTomboyReader *self = BIJI_TOMBOY_READER (object);
+
+  switch (property_id)
+    {
+    case PROP_SRC_PATH:
+      g_value_set_string (value, self->priv->path);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+
+
+
+static void
+biji_tomboy_reader_finalize (GObject *object)
+{
+  BijiTomboyReader *self;
+  BijiTomboyReaderPrivate *priv;
+
+  g_return_if_fail (BIJI_IS_TOMBOY_READER (object));
+
+  self = BIJI_TOMBOY_READER (object);
+  priv = self->priv;
+
+  g_string_free (priv->raw_text, TRUE);
+  g_string_free (priv->html, TRUE);
+
+
+  xmlFreeTextReader (priv->r);
+  xmlFreeTextReader (priv->inner);
+
+
+  G_OBJECT_CLASS (biji_tomboy_reader_parent_class)->finalize (object);
+}
+
+
+static void
+biji_tomboy_reader_init (BijiTomboyReader *self)
+{
+  BijiTomboyReaderPrivate *priv;
+
+  priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE
+             (self, BIJI_TYPE_TOMBOY_READER, BijiTomboyReaderPrivate);
+
+  priv->raw_text = g_string_new ("");
+  priv->html = g_string_new ("");
+
+  priv->set = biji_info_set_new ();
+}
+
+
+
+static void
+biji_tomboy_reader_class_init (BijiTomboyReaderClass *klass)
+{
+  GObjectClass *g_object_class;
+
+  g_object_class = G_OBJECT_CLASS (klass);
+
+  g_object_class->finalize = biji_tomboy_reader_finalize;
+  g_object_class->constructed = biji_tomboy_reader_constructed;
+  g_object_class->set_property = biji_tomboy_reader_set_property;
+  g_object_class->get_property = biji_tomboy_reader_get_property;
+
+  properties[PROP_SRC_PATH] =
+    g_param_spec_string ("path",
+                         "External note path",
+                         "A Tomboy-formated xml note to import",
+                         "",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+  g_object_class_install_properties (g_object_class, TOMBOY_READER_PROP, properties);
+
+
+  g_type_class_add_private ((gpointer)klass, sizeof (BijiTomboyReaderPrivate));
+}
+
+
+static BijiTomboyReader *
+biji_tomboy_reader_new (gchar *source)
+{
+  return g_object_new (BIJI_TYPE_TOMBOY_READER, "path", source, NULL);
+}
+
+
+
+gboolean
+biji_tomboy_reader_read (gchar *source,
+                         GError **error,
+                         BijiInfoSet **set,
+                         gchar       **html,
+                         GList **collections)
+{
+  BijiTomboyReader *self;
+  BijiTomboyReaderPrivate *priv;
+  gchar *html_revamped;
+
+  self = biji_tomboy_reader_new (source);
+  priv = self->priv;
+
+  html_revamped = biji_str_replace (priv->html->str, "\n", "<br/>");
+
+  *error = priv->error;
+  *set = priv->set;
+  *html = html_revamped;
+
+  g_object_unref (self);
+  return TRUE;
+}
diff --git a/src/libbiji/deserializer/biji-tomboy-reader.h b/src/libbiji/deserializer/biji-tomboy-reader.h
new file mode 100644
index 0000000..81b3cdb
--- /dev/null
+++ b/src/libbiji/deserializer/biji-tomboy-reader.h
@@ -0,0 +1,64 @@
+/*
+ * biji-tomboy-reader.h
+ * 
+ * Copyright 2013 Pierre-Yves Luyten <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_TOMBOY_READER_H_
+#define BIJI_TOMBOY_READER_H_ 1
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+
+#define BIJI_TYPE_TOMBOY_READER             (biji_tomboy_reader_get_type ())
+#define BIJI_TOMBOY_READER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), BIJI_TYPE_TOMBOY_READER, 
BijiTomboyReader))
+#define BIJI_TOMBOY_READER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), BIJI_TYPE_TOMBOY_READER, 
BijiTomboyReaderClass))
+#define BIJI_IS_TOMBOY_READER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BIJI_TYPE_TOMBOY_READER))
+#define BIJI_IS_TOMBOY_READER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), BIJI_TYPE_TOMBOY_READER))
+#define BIJI_TOMBOY_READER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BIJI_TYPE_TOMBOY_READER, 
BijiTomboyReaderClass))
+
+typedef struct BijiTomboyReader_         BijiTomboyReader;
+typedef struct BijiTomboyReaderClass_    BijiTomboyReaderClass;
+typedef struct BijiTomboyReaderPrivate_  BijiTomboyReaderPrivate;
+
+struct BijiTomboyReader_
+{
+  GObject parent;
+  BijiTomboyReaderPrivate *priv;
+};
+
+struct BijiTomboyReaderClass_
+{
+  GObjectClass parent_class;
+};
+
+
+GType                biji_tomboy_reader_get_type            (void);
+
+
+gboolean             biji_tomboy_reader_read              (gchar *source,
+                                                           GError **result,
+                                                           BijiInfoSet **set,
+                                                           gchar       **html,
+                                                           GList **collections);
+
+
+G_END_DECLS
+
+#endif /* BIJI_TOMBOY_READER_H_ */
diff --git a/src/libbiji/provider/biji-import-provider.c b/src/libbiji/provider/biji-import-provider.c
new file mode 100644
index 0000000..c4ee275
--- /dev/null
+++ b/src/libbiji/provider/biji-import-provider.c
@@ -0,0 +1,367 @@
+/*
+ * biji-import-provider.c
+ * 
+ * Copyright 2013 Pierre-Yves Luyten <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/>.
+ */
+
+
+
+/*
+ * TODO : re-implement collections
+ * TODO : re-implement old imports preserving
+ */
+
+#include "biji-import-provider.h"
+#include "../deserializer/biji-tomboy-reader.h"
+
+
+/* Properties */
+enum {
+  PROP_0,
+  PROP_URI,
+  PROP_TARGET,
+  IMPORT_PROV_PROP
+};
+
+static GParamSpec *properties[IMPORT_PROV_PROP] = { NULL, };
+
+
+
+
+struct BijiImportProviderPrivate_
+{
+  BijiProviderInfo info;
+  gchar            *uri;
+  gchar            *target; // the provider to import to
+  GHashTable       *items; // same as book, notes key=path, coll key = name.
+};
+
+
+
+
+
+static void biji_import_provider_finalize (GObject *object);
+
+G_DEFINE_TYPE (BijiImportProvider, biji_import_provider, BIJI_TYPE_PROVIDER)
+
+
+#define ATTRIBUTES_FOR_NOTEBOOK "standard::content-type,standard::name"
+
+
+
+
+
+static BijiNoteObj *
+instanciate_note (BijiNoteBook *book, GFileInfo *info, GFile *container)
+{
+  BijiNoteObj *retval = NULL;
+  const gchar *name;
+  gchar *path;
+  GdkRGBA *color;
+
+
+  retval = NULL;
+
+  /* First make sure it's a note */
+  name = g_file_info_get_name (info);
+  if (!g_str_has_suffix (name, ".note"))
+    return NULL;
+
+  path = g_build_filename (g_file_get_path (container), name, NULL);
+
+
+  /* Deserialize it */
+
+  GError *error = NULL;
+  BijiInfoSet *set;
+  gchar *html = NULL;
+  GList *collections = NULL;
+  
+
+  biji_tomboy_reader_read   (path,
+                             &error,
+                             &set,
+                             &html,
+                             &collections);
+
+  if (error != NULL)
+  {
+    g_warning ("Could not import %s - %s", path, error->message);
+    g_free (path);
+    g_error_free (error);
+    return NULL;
+  }
+
+
+  g_debug ("note %s:%s \n%s\n%s", path, set->title, set->content, html);
+
+
+
+  /* Create the note w/ default color */
+  color = g_new0 (GdkRGBA, 1);
+  biji_note_book_get_default_color (book, color);
+  retval = biji_note_book_note_new_full (book,
+                                         "local",
+                                         g_strdup (g_file_info_get_name (info)),
+                                         set,
+                                         html,
+                                         color);
+
+  BIJI_NOTE_OBJ_GET_CLASS (retval)->save_note (retval);
+
+  return retval;
+}
+
+
+
+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);
+}
+
+
+
+/* Some notes might have been added previously */
+static void
+go_through_notes_cb (GObject *object, GAsyncResult *res, gpointer data)
+{
+  GFileEnumerator *enumerator;
+  GList *l, *notes_info;
+  GFile *container;
+  BijiImportProvider *self;
+
+
+  enumerator = G_FILE_ENUMERATOR (object);
+  self = data;
+
+
+  container = g_file_enumerator_get_container (enumerator);
+  notes_info = g_file_enumerator_next_files_finish (enumerator, res, NULL);
+  g_file_enumerator_close_async (enumerator, G_PRIORITY_DEFAULT, NULL,
+                                 release_enum_cb, self);
+
+
+
+  /* Get the GList of notes and load them */
+  for ( l=notes_info; l !=NULL; l = l->next)
+  {
+    GFileInfo *info;
+    BijiNoteObj *iter;
+
+    info = G_FILE_INFO (l->data);
+    iter = instanciate_note (
+                  biji_provider_get_book (BIJI_PROVIDER (self)),
+                  info,
+                  container);
+
+    if (iter != NULL)
+    {
+      g_hash_table_insert (self->priv->items,
+                           (gpointer) biji_item_get_uuid (BIJI_ITEM (iter)),
+                           (gpointer) iter);
+    }
+  }
+
+  g_list_free_full (notes_info, g_object_unref);
+  BIJI_PROVIDER_GET_CLASS (self)->notify_loaded (BIJI_PROVIDER (self),
+                                                 g_hash_table_get_values (self->priv->items));
+
+
+
+
+  /* Goodbye */
+  g_object_unref (self);
+}
+
+
+
+
+static void
+list_notes_to_copy (GObject *src_obj, GAsyncResult *res, gpointer data)
+{
+  GFileEnumerator *enumerator;
+  GError *error;
+  BijiImportProvider *self;
+
+  self = data;
+  error = NULL;
+  enumerator = g_file_enumerate_children_finish (G_FILE (src_obj), res, &error);
+
+  if (error)
+  {
+    g_warning ("Enumerator failed : %s", error->message);
+    g_error_free (error);
+    g_file_enumerator_close_async (enumerator, G_PRIORITY_DEFAULT, NULL, release_enum_cb, self);
+  }
+
+  else
+  {
+    g_file_enumerator_next_files_async (enumerator, G_MAXINT, G_PRIORITY_DEFAULT, NULL,
+                                        go_through_notes_cb, self);
+  }
+}
+
+
+
+static void
+biji_import_provider_constructed (GObject *object)
+{
+  BijiImportProvider *self;
+  BijiImportProviderPrivate *priv;
+  GFile *to_import;
+
+
+  self = BIJI_IMPORT_PROVIDER (object);
+  priv = self->priv;
+
+
+  priv->info.unique_id = NULL;
+  priv->info.datasource = NULL;
+  priv->info.name = "import-provider";
+  priv->info.icon =  NULL;
+  priv->info.domain = NULL;
+  priv->info.user = NULL;
+
+  
+  to_import = g_file_new_for_path (self->priv->uri);
+
+  g_file_enumerate_children_async (to_import, ATTRIBUTES_FOR_NOTEBOOK,
+                                   G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
+                                   NULL, list_notes_to_copy, self);
+
+  g_object_unref (to_import);
+}
+
+
+const BijiProviderInfo *
+biji_import_provider_get_info (BijiProvider *self)
+{
+  return & (BIJI_IMPORT_PROVIDER (self)->priv->info);
+}
+
+
+static void
+biji_import_provider_set_property (GObject      *object,
+                                   guint         property_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
+{
+  BijiImportProvider *self = BIJI_IMPORT_PROVIDER (object);
+
+
+  switch (property_id)
+    {
+    case PROP_URI:
+      self->priv->uri = g_value_dup_string (value);
+      break;
+    case PROP_TARGET:
+      self->priv->target = g_value_dup_string (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+
+static void
+biji_import_provider_get_property (GObject    *object,
+                                   guint       property_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
+{
+  BijiImportProvider *self = BIJI_IMPORT_PROVIDER (object);
+
+  switch (property_id)
+    {
+    case PROP_URI:
+      g_value_set_string (value, self->priv->uri);
+      break;
+    case PROP_TARGET:
+      g_value_set_string (value, self->priv->target);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+
+static void
+biji_import_provider_class_init (BijiImportProviderClass *klass)
+{
+  GObjectClass *g_object_class;
+  BijiProviderClass *provider_class;
+
+  g_object_class = G_OBJECT_CLASS (klass);
+  provider_class = BIJI_PROVIDER_CLASS (klass);
+
+  g_object_class->set_property = biji_import_provider_set_property;
+  g_object_class->get_property = biji_import_provider_get_property;
+  g_object_class->finalize = biji_import_provider_finalize;
+  g_object_class->constructed = biji_import_provider_constructed;
+
+  provider_class->get_info = biji_import_provider_get_info;
+
+  properties[PROP_URI] =
+    g_param_spec_string ("uri",
+                         "The import path",
+                         "The folder to be imported",
+                         "",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+
+  properties[PROP_TARGET] =
+    g_param_spec_string ("target",
+                         "The target storage",
+                         "Target provider to import to",
+                         "",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+  g_object_class_install_properties (g_object_class, IMPORT_PROV_PROP, properties);
+
+
+  g_type_class_add_private ((gpointer)klass, sizeof (BijiImportProviderPrivate));
+}
+
+
+static void
+biji_import_provider_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (biji_import_provider_parent_class)->finalize (object);
+}
+
+
+static void
+biji_import_provider_init (BijiImportProvider *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_IMPORT_PROVIDER, BijiImportProviderPrivate);
+  self->priv->items = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+
+BijiProvider *
+biji_import_provider_new (BijiNoteBook *b, gchar *target_provider, gchar *uri)
+{
+  return g_object_new (BIJI_TYPE_IMPORT_PROVIDER,
+                       "book", b,
+                       "target", target_provider,
+                       "uri", uri,
+                       NULL);
+}
+
diff --git a/src/libbiji/provider/biji-import-provider.h b/src/libbiji/provider/biji-import-provider.h
new file mode 100644
index 0000000..3ed867f
--- /dev/null
+++ b/src/libbiji/provider/biji-import-provider.h
@@ -0,0 +1,75 @@
+/*
+ * biji-import-provider.h
+ * 
+ * Copyright 2013 Pierre-Yves Luyten <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/>.
+ */
+
+
+/* A special case of providers : importing data.
+ * As the provider type is close enough
+ * use this : all import func should be ported to use this.
+ *
+ * Once the ImportProvider does it's job,
+ * it kills its own ref.
+ */
+
+/* As of today this is the direct class to be used by notebook.
+ * Later on book might use different importProviders sub-classes */
+
+#ifndef BIJI_IMPORT_PROVIDER_H_
+#define BIJI_IMPORT_PROVIDER_H_ 1
+
+
+#include "../biji-note-book.h"
+#include "biji-provider.h"
+
+G_BEGIN_DECLS
+
+
+#define BIJI_TYPE_IMPORT_PROVIDER             (biji_import_provider_get_type ())
+#define BIJI_IMPORT_PROVIDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), BIJI_TYPE_IMPORT_PROVIDER, 
BijiImportProvider))
+#define BIJI_IMPORT_PROVIDER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), BIJI_TYPE_IMPORT_PROVIDER, 
BijiImportProviderClass))
+#define BIJI_IS_IMPORT_PROVIDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BIJI_TYPE_IMPORT_PROVIDER))
+#define BIJI_IS_IMPORT_PROVIDER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), BIJI_TYPE_IMPORT_PROVIDER))
+#define BIJI_IMPORT_PROVIDER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BIJI_TYPE_IMPORT_PROVIDER, 
BijiImportProviderClass))
+
+typedef struct BijiImportProvider_         BijiImportProvider;
+typedef struct BijiImportProviderClass_    BijiImportProviderClass;
+typedef struct BijiImportProviderPrivate_  BijiImportProviderPrivate;
+
+struct BijiImportProvider_
+{
+  BijiProvider parent;
+  BijiImportProviderPrivate *priv;
+};
+
+struct BijiImportProviderClass_
+{
+  BijiProviderClass parent_class;
+};
+
+
+GType                   biji_import_provider_get_type             (void);
+
+
+BijiProvider           *biji_import_provider_new                  (BijiNoteBook *book,
+                                                                   gchar *target_provider,
+                                                                   gchar *uri);
+
+
+G_END_DECLS
+
+#endif /* BIJI_IMPORT_PROVIDER_H_ */
diff --git a/src/libbiji/provider/biji-local-provider.c b/src/libbiji/provider/biji-local-provider.c
index 4414b53..ad7200a 100644
--- a/src/libbiji/provider/biji-local-provider.c
+++ b/src/libbiji/provider/biji-local-provider.c
@@ -304,6 +304,41 @@ biji_local_provider_init (BijiLocalProvider *self)
 }
 
 
+static BijiNoteObj *
+local_prov_create_note_full (BijiProvider *provider,
+                             gchar        *suggested_path,
+                             BijiInfoSet  *info,
+                             gchar        *html,
+                             GdkRGBA      *color)
+{
+  BijiLocalProvider *self;
+  BijiNoteObj *retval;
+  gchar *folder;
+
+  g_return_val_if_fail (BIJI_IS_LOCAL_PROVIDER (provider), NULL);
+
+  self = BIJI_LOCAL_PROVIDER (provider);
+  retval = NULL;
+
+  /* PATH */
+  folder = g_file_get_path (self->priv->location);
+  info->url = g_build_filename (folder, suggested_path, NULL);
+  g_free (folder);
+
+  /* RAW NOTE */
+  retval = biji_local_note_new_from_info (provider,
+                                          biji_provider_get_book (provider),
+                                          info);
+
+  /* EXTRAS */
+  biji_note_obj_set_html (retval, html);
+  biji_note_obj_set_rgba (retval, color);
+
+
+  return retval;
+}
+
+
 static void
 biji_local_provider_set_property (GObject      *object,
                                   guint         property_id,
@@ -369,6 +404,8 @@ biji_local_provider_class_init (BijiLocalProviderClass *klass)
   g_object_class->set_property = biji_local_provider_set_property;
 
   provider_class->get_info = local_provider_get_info;
+  // provider_class->create_new_note = local_prov_create_new_note;
+  provider_class->create_note_full = local_prov_create_note_full;
 
   properties[PROP_LOCATION] =
     g_param_spec_object ("location",
diff --git a/src/libbiji/provider/biji-own-cloud-provider.c b/src/libbiji/provider/biji-own-cloud-provider.c
index 1300a97..eebfdb6 100644
--- a/src/libbiji/provider/biji-own-cloud-provider.c
+++ b/src/libbiji/provider/biji-own-cloud-provider.c
@@ -768,7 +768,7 @@ biji_own_cloud_provider_class_init (BijiOwnCloudProviderClass *klass)
   g_object_class->constructed = biji_own_cloud_provider_constructed;
 
   provider_class->get_info = own_cloud_get_info;
-  provider_class->create_note = own_cloud_create_note;
+  provider_class->create_new_note = own_cloud_create_note;
 
 
   properties[PROP_GOA_OBJECT] =
diff --git a/src/libbiji/provider/biji-provider.h b/src/libbiji/provider/biji-provider.h
index ca2185a..f6ee7be 100644
--- a/src/libbiji/provider/biji-provider.h
+++ b/src/libbiji/provider/biji-provider.h
@@ -21,6 +21,7 @@
 #include <glib-object.h>
 #include <glib/gi18n.h>  // translate providers type
 
+#include "../biji-info-set.h"
 #include "../biji-note-book.h"
 
 G_BEGIN_DECLS
@@ -64,15 +65,54 @@ struct BijiProviderClass_
   GObjectClass parent_class;
 
 
+/* Each Provider subclass instance owns its own BijiProviderInfo
+ * to signal name, icon, or whatever useful info.
+ * datasource is only needed for actual providers,
+ * ie. persistent data source */
+
   const BijiProviderInfo*    (*get_info)              (BijiProvider *provider);
   
 
+  /* When a provider is loaded, notify the book to transmit the items */
+
   void                       (*notify_loaded)         (BijiProvider *provider,
                                                        GList *loaded_items);
 
 
-  BijiNoteObj*               (*create_note)           (BijiProvider *provider,
+  /* Create a single note and let the provider handle things.
+   * Only works from raw text.
+   * Does not allow to trick color or dates */
+
+  BijiNoteObj*               (*create_new_note)       (BijiProvider *provider,
                                                        gchar        *content);
+
+  /* Creates a single note representing some existing data,
+   * with title, content, dates, html, color.
+   * The caller should set as many fields as possible.
+   * The provider should ensure as much as possible to handle
+   * NULL values properly, if any.
+   * Providers will discard assigned values they do not handle.
+   * Local provider is supposed to handle everything.
+   *
+   * Suggested path : if possible, the provider should preserve
+   * the file name. If an import provider is asked to import a file,
+   * first check the item does not exist yet
+   * with same path (basename). ie. do not import twice the same note.
+   *
+   * the info set is not supposed to store any url.
+   * otherwise, you might expect it to be lost.
+   *
+   * TODO: rebase startup code on local provider create note full when good enough
+   * TODO: owncloud provider (to handle importing) */
+
+  BijiNoteObj*               (*create_note_full)      (BijiProvider *provider,
+                                                       gchar        *suggested_path,
+                                                       BijiInfoSet  *info,
+                                                       gchar        *html,
+                                                       GdkRGBA      *color);
+
+
+   /* TODO : (*create_collection). Add a flag into provider info? */
 };
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]