[bijiben] item: use const attribute for uuid and title
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] item: use const attribute for uuid and title
- Date: Mon, 6 May 2013 22:38:26 +0000 (UTC)
commit 042f1eb946dba3ed350e9089bbf9ef66c9c94c33
Author: Pierre-Yves Luyten <py luyten fr>
Date: Mon May 6 23:09:12 2013 +0200
item: use const attribute for uuid and title
path getter is no more allocated to remain the same than title
src/bjb-bijiben.c | 3 +-
src/bjb-controller.c | 18 +--
src/bjb-rename-note.c | 2 +-
src/bjb-rename-note.h | 5 +-
src/bjb-share.c | 5 +-
src/libbiji/biji-collection.c | 6 +-
src/libbiji/biji-item.c | 4 +-
src/libbiji/biji-item.h | 19 +--
src/libbiji/biji-note-book.c | 20 ++--
src/libbiji/biji-note-book.h | 4 +-
src/libbiji/biji-note-id.c | 23 ++-
src/libbiji/biji-note-id.h | 6 +-
src/libbiji/biji-note-obj.c | 175 ++++++++++-----------
src/libbiji/biji-string.c | 6 +-
src/libbiji/biji-string.h | 4 +-
src/libbiji/biji-tracker.c | 28 ++--
src/libbiji/biji-tracker.h | 4 +-
src/libbiji/biji-zeitgeist.c | 6 +-
src/libbiji/deserializer/biji-lazy-deserializer.c | 5 +-
src/libbiji/serializer/biji-lazy-serializer.c | 7 +-
20 files changed, 171 insertions(+), 179 deletions(-)
---
diff --git a/src/bjb-bijiben.c b/src/bjb-bijiben.c
index 4f967c7..aea7f98 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-bijiben.c
@@ -179,7 +179,7 @@ go_through_notes_cb (GFileEnumerator *enumerator, GAsyncResult *res, Bijiben *se
for (l = notes_proposal; l != NULL; l = l->next)
{
BijiNoteObj *note = l->data;
- gchar *path = biji_item_get_uuid (BIJI_ITEM (note));
+ 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))
@@ -208,7 +208,6 @@ go_through_notes_cb (GFileEnumerator *enumerator, GAsyncResult *res, Bijiben *se
biji_note_obj_save_note (note);
}
- g_free (path);
}
/* NoteBook will notify for all opened windows */
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index c8fd93f..b56f0cb 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -191,11 +191,13 @@ bjb_controller_get_iter (BjbController *self,
{
BjbControllerPrivate *priv = self->priv;
gboolean retval = FALSE;
- gboolean still = gtk_tree_model_get_iter_first (priv->model, *iter);
- gchar *needle = NULL;
+ gboolean still;
+ const gchar *needle = NULL;
if (item && BIJI_IS_ITEM (item))
- needle = biji_item_get_uuid (item);
+ needle = biji_item_get_uuid (item);
+
+ still = gtk_tree_model_get_iter_first (priv->model, *iter);
while (still)
{
@@ -220,9 +222,6 @@ bjb_controller_get_iter (BjbController *self,
still = gtk_tree_model_iter_next (priv->model, *iter);
}
- if (needle)
- g_free (needle);
-
return retval;
}
@@ -237,7 +236,7 @@ bjb_controller_add_item (BjbController *self,
GtkTreeIter iter;
GtkListStore *store;
GdkPixbuf *pix = NULL;
- gchar *uuid;
+ const gchar *uuid;
g_return_if_fail (BIJI_IS_ITEM (item));
store = GTK_LIST_STORE (self->priv->model);
@@ -282,8 +281,6 @@ bjb_controller_add_item (BjbController *self,
GD_MAIN_COLUMN_SELECTED, FALSE,
-1);
- g_free (uuid);
-
}
/* If the user searches for notes, is the note searched? */
@@ -294,7 +291,8 @@ bjb_controller_add_item_if_needed (BjbController *self,
GtkTreeIter *sibling)
{
gboolean need_to_add_item = FALSE;
- gchar *title, *content;
+ gchar *content;
+ const gchar *title;
BjbControllerPrivate *priv = self->priv;
/* No note... */
diff --git a/src/bjb-rename-note.c b/src/bjb-rename-note.c
index 82ffd76..624905f 100644
--- a/src/bjb-rename-note.c
+++ b/src/bjb-rename-note.c
@@ -1,7 +1,7 @@
#include "bjb-rename-note.h"
gchar *
-note_title_dialog(GtkWindow *win, gchar *instructions, gchar *current_title)
+note_title_dialog(GtkWindow *win, gchar *instructions, const gchar *current_title)
{
GtkWidget *dialog;
GtkWidget *area;
diff --git a/src/bjb-rename-note.h b/src/bjb-rename-note.h
index 7c548f3..cc3a9ab 100644
--- a/src/bjb-rename-note.h
+++ b/src/bjb-rename-note.h
@@ -3,6 +3,7 @@
#include <gtk/gtk.h>
-gchar * note_title_dialog(GtkWindow *win, gchar *instructions, gchar *title);
+gchar * note_title_dialog (GtkWindow *win, gchar *instructions, const gchar *title);
-#endif
\ No newline at end of file
+
+#endif
diff --git a/src/bjb-share.c b/src/bjb-share.c
index 4a243fc..c64f878 100644
--- a/src/bjb-share.c
+++ b/src/bjb-share.c
@@ -18,10 +18,11 @@
#include "bjb-share.h"
static gchar *
-mail_str ( gchar * string )
+mail_str (gchar * string )
{
if (!string)
return g_strdup ("''");
+
return g_strdup (g_strdelimit (string, "\n", ' '));
}
@@ -33,7 +34,7 @@ on_email_note_callback(GtkWidget *widget, BijiNoteObj *note)
error = NULL;
gchar *title_mail, *text_mail;
- title_mail = mail_str (biji_item_get_title (BIJI_ITEM (note)));
+ title_mail = mail_str ((gchar*) biji_item_get_title (BIJI_ITEM (note)));
text_mail = mail_str (biji_note_get_raw_text (note));
gchar *execute[7] = { "xdg-email",
diff --git a/src/libbiji/biji-collection.c b/src/libbiji/biji-collection.c
index e4aab0d..a85ee72 100644
--- a/src/libbiji/biji-collection.c
+++ b/src/libbiji/biji-collection.c
@@ -69,7 +69,7 @@ static GParamSpec *properties[BIJI_COLL_PROPERTIES] = { NULL, };
static guint biji_collections_signals [BIJI_COLLECTIONS_SIGNALS] = { 0 };
-static gchar *
+static const gchar *
biji_collection_get_title (BijiItem *coll)
{
BijiCollection *collection;
@@ -81,7 +81,7 @@ biji_collection_get_title (BijiItem *coll)
}
-static gchar *
+static const gchar *
biji_collection_get_uuid (BijiItem *coll)
{
BijiCollection *collection;
@@ -89,7 +89,7 @@ biji_collection_get_uuid (BijiItem *coll)
g_return_val_if_fail (BIJI_IS_COLLECTION (coll), NULL);
collection = BIJI_COLLECTION (coll);
- return g_strdup (collection->priv->urn);
+ return collection->priv->urn;
}
diff --git a/src/libbiji/biji-item.c b/src/libbiji/biji-item.c
index 2862247..3298680 100644
--- a/src/libbiji/biji-item.c
+++ b/src/libbiji/biji-item.c
@@ -57,13 +57,13 @@ biji_item_init (BijiItem *self)
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_ITEM, BijiItemPrivate);
}
-gchar *
+const gchar *
biji_item_get_title (BijiItem *item)
{
return BIJI_ITEM_GET_CLASS (item)->get_title (item);
}
-gchar *
+const gchar *
biji_item_get_uuid (BijiItem *item)
{
return BIJI_ITEM_GET_CLASS (item)->get_uuid (item);
diff --git a/src/libbiji/biji-item.h b/src/libbiji/biji-item.h
index 5499827..a81ee5d 100644
--- a/src/libbiji/biji-item.h
+++ b/src/libbiji/biji-item.h
@@ -57,8 +57,8 @@ struct BijiItemClass_
{
GObjectClass parent_class;
- gchar * (*get_title) (BijiItem *item);
- gchar * (*get_uuid) (BijiItem *item);
+ const gchar * (*get_title) (BijiItem *item);
+ const gchar * (*get_uuid) (BijiItem *item);
GdkPixbuf * (*get_icon) (BijiItem *item);
GdkPixbuf * (*get_emblem) (BijiItem *item);
GdkPixbuf * (*get_pristine) (BijiItem *item);
@@ -69,21 +69,20 @@ struct BijiItemClass_
gboolean (*remove_collection) (BijiItem *item, gchar *coll, gchar *urn);
};
-/* Do not create a generic items.
- * It's rather an iface */
+/* Do not create a generic items, it's rather an iface
+ * but i just need common stuff */
-GType biji_item_get_type (void);
+GType biji_item_get_type (void);
-/* Do not free title */
-gchar * biji_item_get_title (BijiItem *item);
+/* - note uuid is a location (as in GFile)
+ * - collection uuid is urn */
+const gchar * biji_item_get_title (BijiItem *item);
-/* Always g_free uuid
- * NoteObj uuid is a location */
-gchar * biji_item_get_uuid (BijiItem *item);
+const gchar * biji_item_get_uuid (BijiItem *item);
GdkPixbuf * biji_item_get_icon (BijiItem *item);
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 2c642a4..7c451c9 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -60,10 +60,10 @@ biji_note_book_init (BijiNoteBook *self)
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_NOTE_BOOK,
BijiNoteBookPrivate);
- /* Note path is key for table. It's freed by note itself */
+ /* Item path is key for table */
self->priv->items = g_hash_table_new_full (g_str_hash,
g_str_equal,
- g_free,
+ NULL,
g_object_unref);
}
@@ -147,7 +147,7 @@ title_is_unique (BijiNoteBook *book, gchar *title)
/* If title not unique, add sufffix "n", starting with 2, until ok */
gchar *
-biji_note_book_get_unique_title (BijiNoteBook *book, gchar *title)
+biji_note_book_get_unique_title (BijiNoteBook *book, const gchar *title)
{
if (!book)
return g_strdup (title);
@@ -208,7 +208,8 @@ _biji_note_book_add_one_note (BijiNoteBook *book, BijiNoteObj *note)
/* Add it to the list */
g_hash_table_insert (book->priv->items,
- biji_item_get_uuid (BIJI_ITEM (note)), note);
+ (gpointer) biji_item_get_uuid (BIJI_ITEM (note)),
+ note);
/* Notify */
g_signal_connect (note, "changed", G_CALLBACK (book_on_note_changed_cb), book);
@@ -427,7 +428,7 @@ biji_note_book_remove_item (BijiNoteBook *book, BijiItem *item)
g_return_val_if_fail (BIJI_IS_ITEM (item), FALSE);
BijiItem *to_delete = NULL;
- gchar *path;
+ const gchar *path;
gboolean retval = FALSE;
path = biji_item_get_uuid (item);
@@ -447,7 +448,6 @@ biji_note_book_remove_item (BijiNoteBook *book, BijiItem *item)
retval = TRUE;
}
- g_free (path);
return retval;
}
@@ -457,7 +457,7 @@ biji_note_book_add_item (BijiNoteBook *book, BijiItem *item, gboolean notify)
g_return_val_if_fail (BIJI_IS_NOTE_BOOK (book), FALSE);
g_return_val_if_fail (BIJI_IS_ITEM (item), FALSE);
- gchar *uid;
+ const gchar *uid;
gboolean retval = TRUE;
uid = biji_item_get_uuid (item);
@@ -471,7 +471,7 @@ biji_note_book_add_item (BijiNoteBook *book, BijiItem *item, gboolean notify)
else if (BIJI_IS_COLLECTION (item))
{
g_hash_table_insert (book->priv->items,
- biji_item_get_uuid (item),
+ (gpointer) biji_item_get_uuid (item),
item);
g_signal_connect (item, "deleted",
@@ -491,9 +491,9 @@ biji_note_book_get_items (BijiNoteBook *book)
}
BijiItem *
-biji_note_book_get_item_at_path (BijiNoteBook *book, gchar *path)
+biji_note_book_get_item_at_path (BijiNoteBook *book, const gchar *path)
{
- return g_hash_table_lookup (book->priv->items, path);
+ return g_hash_table_lookup (book->priv->items, (gconstpointer) path);
}
BijiNoteBook *
diff --git a/src/libbiji/biji-note-book.h b/src/libbiji/biji-note-book.h
index 0d29ace..60fac8e 100644
--- a/src/libbiji/biji-note-book.h
+++ b/src/libbiji/biji-note-book.h
@@ -45,7 +45,7 @@ GType biji_note_book_get_type (void) G_GNUC_CONST;
BijiNoteBook * biji_note_book_new (GFile *location);
-gchar * biji_note_book_get_unique_title (BijiNoteBook *book, gchar *title);
+gchar * biji_note_book_get_unique_title (BijiNoteBook *book, const gchar *title);
gboolean biji_note_book_add_item (BijiNoteBook *book, BijiItem *item, gboolean notify);
@@ -55,7 +55,7 @@ gboolean biji_note_book_notify_changed (BijiNoteBook *book,
gboolean biji_note_book_remove_item (BijiNoteBook *book, BijiItem *item);
-BijiItem * biji_note_book_get_item_at_path (BijiNoteBook *book, gchar *path);
+BijiItem * biji_note_book_get_item_at_path (BijiNoteBook *book, const gchar *path);
/* Get all items, either notes or collections
* Free the GList, not its content */
diff --git a/src/libbiji/biji-note-id.c b/src/libbiji/biji-note-id.c
index df7f6bd..2564304 100644
--- a/src/libbiji/biji-note-id.c
+++ b/src/libbiji/biji-note-id.c
@@ -28,8 +28,10 @@ static GParamSpec *properties[BIJI_ID_PROPERTIES] = { NULL, };
struct _BijiNoteIDPrivate
{
- GFile * location;
- gchar * title ;
+ GFile * location;
+ gchar * title ;
+ gchar * basename;
+ const gchar * path;
GTimeVal last_change_date;
GTimeVal last_metadata_change_date;
@@ -65,8 +67,11 @@ biji_note_id_finalize (GObject *object)
static void
biji_note_id_set_path (BijiNoteID *self, const gchar *path)
{
- g_warn_if_fail (!self->priv->location);
+ g_return_if_fail (BIJI_IS_NOTE_ID (self));
+
self->priv->location = g_file_new_for_path (path);
+ self->priv->basename = g_file_get_basename (self->priv->location);
+ self->priv->path = g_file_get_path (self->priv->location);
}
static void
@@ -135,18 +140,20 @@ biji_note_id_equal (BijiNoteID *a, BijiNoteID *b)
return g_file_equal (a->priv->location, b->priv->location);
}
-gchar *
+const gchar *
biji_note_id_get_path (BijiNoteID* n)
{
g_return_val_if_fail (BIJI_IS_NOTE_ID (n), NULL);
- return g_file_get_path (n->priv->location);
+ return n->priv->path;
}
-gchar *
+const gchar *
biji_note_id_get_uuid (BijiNoteID *n)
{
- return g_file_get_basename (n->priv->location);
+ g_return_val_if_fail (BIJI_IS_NOTE_ID (n), NULL);
+
+ return n->priv->basename;
}
GFile *
@@ -164,7 +171,7 @@ biji_note_id_set_title (BijiNoteID *n, gchar* title)
n->priv->title = g_strdup (title);
}
-gchar *
+const gchar *
biji_note_id_get_title (BijiNoteID* n)
{
return n->priv->title ;
diff --git a/src/libbiji/biji-note-id.h b/src/libbiji/biji-note-id.h
index c8163fc..aa0d7ba 100644
--- a/src/libbiji/biji-note-id.h
+++ b/src/libbiji/biji-note-id.h
@@ -51,15 +51,15 @@ GType biji_note_id_get_type (void) G_GNUC_CONST;
gboolean biji_note_id_equal (BijiNoteID *a, BijiNoteID *b);
-gchar * biji_note_id_get_path (BijiNoteID *note);
+const gchar * biji_note_id_get_path (BijiNoteID *note);
-gchar * biji_note_id_get_uuid (BijiNoteID *note);
+const gchar * biji_note_id_get_uuid (BijiNoteID *note);
GFile * biji_note_id_get_file (BijiNoteID *note);
void biji_note_id_set_title (BijiNoteID* n,gchar* title);
-gchar* biji_note_id_get_title (BijiNoteID* n);
+const gchar* biji_note_id_get_title (BijiNoteID* n);
gchar * biji_note_id_get_last_change_date (BijiNoteID* n);
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 7130f6a..1c21248 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -76,18 +76,6 @@ static GParamSpec *properties[BIJI_OBJ_PROPERTIES] = { NULL, };
G_DEFINE_TYPE (BijiNoteObj, biji_note_obj, BIJI_TYPE_ITEM);
-/* BijiItem iface */
-static gchar * biji_note_obj_get_title (BijiItem *note);
-static gchar * biji_note_obj_get_path (BijiItem *note);
-static GdkPixbuf * biji_note_obj_get_icon (BijiItem *note);
-static GdkPixbuf * biji_note_obj_get_emblem (BijiItem *note);
-static GdkPixbuf * biji_note_obj_get_pristine (BijiItem *note);
-static gboolean biji_note_obj_trash (BijiItem *note);
-static glong biji_note_obj_get_last_change_date_sec (BijiItem *note);
-static gboolean biji_note_obj_has_collection (BijiItem *note, gchar *label);
-static gboolean biji_note_obj_add_collection (BijiItem *note, gchar *label, gboolean
on_user_action);
-static gboolean biji_note_obj_remove_collection (BijiItem *note, gchar *label, gchar *urn);
-
static void
on_save_timeout (BijiNoteObj *self)
{
@@ -229,7 +217,7 @@ biji_note_obj_get_property (GObject *object,
switch (property_id)
{
case PROP_PATH:
- g_value_set_object (value, biji_note_id_get_path (self->priv->id));
+ g_value_set_object (value, (gpointer) biji_note_id_get_path (self->priv->id));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -237,80 +225,6 @@ biji_note_obj_get_property (GObject *object,
}
}
-static void
-biji_note_obj_class_init (BijiNoteObjClass *klass)
-{
- BijiItemClass* item_class = BIJI_ITEM_CLASS (klass);
- GObjectClass* object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = biji_note_obj_constructed;
- object_class->finalize = biji_note_obj_finalize;
- object_class->get_property = biji_note_obj_get_property;
- object_class->set_property = biji_note_obj_set_property;
-
- properties[PROP_PATH] =
- g_param_spec_string("path",
- "The note file",
- "The location where the note is stored and saved",
- NULL,
- G_PARAM_READWRITE);
-
- g_object_class_install_properties (object_class, BIJI_OBJ_PROPERTIES, properties);
-
- biji_obj_signals[NOTE_RENAMED] = g_signal_new ( "renamed" ,
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
- biji_obj_signals[NOTE_CHANGED] = g_signal_new ( "changed" ,
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
- biji_obj_signals[NOTE_COLOR_CHANGED] = g_signal_new ("color-changed" ,
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
- biji_obj_signals[NOTE_DELETED] = g_signal_new ( "deleted" ,
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
- g_type_class_add_private (klass, sizeof (BijiNoteObjPrivate));
-
- /* Interface */
- item_class->get_title = biji_note_obj_get_title;
- item_class->get_uuid = biji_note_obj_get_path;
- item_class->get_icon = biji_note_obj_get_icon;
- item_class->get_emblem = biji_note_obj_get_emblem;
- item_class->get_pristine = biji_note_obj_get_pristine;
- item_class->get_change_sec = biji_note_obj_get_last_change_date_sec;
- item_class->trash = biji_note_obj_trash;
- item_class->has_collection = biji_note_obj_has_collection;
- item_class->add_collection = biji_note_obj_add_collection;
- item_class->remove_collection = biji_note_obj_remove_collection;
-}
BijiNoteObj *
biji_note_obj_new_from_path (const gchar *path)
@@ -430,7 +344,7 @@ biji_note_obj_trash (BijiItem *item)
return result;
}
-static gchar *
+static const gchar *
biji_note_obj_get_path (BijiItem *item)
{
g_return_val_if_fail (BIJI_IS_NOTE_OBJ (item), NULL);
@@ -445,7 +359,7 @@ BijiNoteID* note_get_id(BijiNoteObj* n)
return n->priv->id;
}
-static gchar *
+static const gchar *
biji_note_obj_get_title (BijiItem *note)
{
g_return_val_if_fail (BIJI_IS_NOTE_OBJ (note), NULL);
@@ -710,7 +624,8 @@ biji_note_obj_get_icon_file (BijiNoteObj *note)
{
g_return_val_if_fail (BIJI_IS_NOTE_OBJ (note), NULL);
- gchar *uuid, *basename, *filename;
+ const gchar *uuid;
+ gchar *basename, *filename;
uuid = biji_note_id_get_uuid (note->priv->id);
basename = biji_str_mass_replace (uuid, ".note", ".png", NULL);
@@ -720,7 +635,6 @@ biji_note_obj_get_icon_file (BijiNoteObj *note)
basename,
NULL);
- g_free (uuid);
g_free (basename);
return filename;
@@ -1078,3 +992,82 @@ void biji_note_obj_editor_paste (BijiNoteObj *note)
biji_webkit_editor_paste (note->priv->editor);
}
+static void
+biji_note_obj_class_init (BijiNoteObjClass *klass)
+{
+ BijiItemClass* item_class = BIJI_ITEM_CLASS (klass);
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = biji_note_obj_constructed;
+ object_class->finalize = biji_note_obj_finalize;
+ object_class->get_property = biji_note_obj_get_property;
+ object_class->set_property = biji_note_obj_set_property;
+
+ properties[PROP_PATH] =
+ g_param_spec_string("path",
+ "The note file",
+ "The location where the note is stored and saved",
+ NULL,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (object_class, BIJI_OBJ_PROPERTIES, properties);
+
+ biji_obj_signals[NOTE_RENAMED] =
+ g_signal_new ("renamed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ biji_obj_signals[NOTE_CHANGED] =
+ g_signal_new ("changed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ biji_obj_signals[NOTE_COLOR_CHANGED] =
+ g_signal_new ("color-changed" ,
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ biji_obj_signals[NOTE_DELETED] =
+ g_signal_new ("deleted" ,
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ g_type_class_add_private (klass, sizeof (BijiNoteObjPrivate));
+
+ /* Interface */
+ item_class->get_title = biji_note_obj_get_title;
+ item_class->get_uuid = biji_note_obj_get_path;
+ item_class->get_icon = biji_note_obj_get_icon;
+ item_class->get_emblem = biji_note_obj_get_emblem;
+ item_class->get_pristine = biji_note_obj_get_pristine;
+ item_class->get_change_sec = biji_note_obj_get_last_change_date_sec;
+ item_class->trash = biji_note_obj_trash;
+ item_class->has_collection = biji_note_obj_has_collection;
+ item_class->add_collection = biji_note_obj_add_collection;
+ item_class->remove_collection = biji_note_obj_remove_collection;
+}
+
diff --git a/src/libbiji/biji-string.c b/src/libbiji/biji-string.c
index 34de9b2..8b6ed4b 100644
--- a/src/libbiji/biji-string.c
+++ b/src/libbiji/biji-string.c
@@ -19,7 +19,7 @@
#include "biji-string.h"
gchar *
-biji_str_replace (gchar *string, gchar *as_is, gchar *to_be)
+biji_str_replace (const gchar *string, gchar *as_is, gchar *to_be)
{
gchar **array;
gchar *result = NULL;
@@ -44,7 +44,7 @@ biji_str_replace (gchar *string, gchar *as_is, gchar *to_be)
return result;
}
-gchar * biji_str_mass_replace (gchar *string,
+gchar * biji_str_mass_replace (const gchar *string,
...)
{
va_list args;
@@ -62,7 +62,7 @@ gchar * biji_str_mass_replace (gchar *string,
if (to_be)
{
- tmp = biji_str_replace (result, as_is, to_be);
+ tmp = biji_str_replace ((const gchar*) result, as_is, to_be);
if (tmp)
{
diff --git a/src/libbiji/biji-string.h b/src/libbiji/biji-string.h
index 74fc477..a1d55a5 100644
--- a/src/libbiji/biji-string.h
+++ b/src/libbiji/biji-string.h
@@ -25,11 +25,11 @@ G_BEGIN_DECLS
/* Replaces inside string the as_is with to_be
* Returns a newly allocated string */
-gchar * biji_str_replace (gchar *string, gchar *as_is, gchar *to_be);
+gchar * biji_str_replace (const gchar *string, gchar *as_is, gchar *to_be);
/* Calls biji_str_replace as much as there are paired gchar* args
* Returns a newly allocated string */
-gchar * biji_str_mass_replace (gchar *string, ...) G_GNUC_NULL_TERMINATED ;
+gchar * biji_str_mass_replace (const gchar *string, ...) G_GNUC_NULL_TERMINATED ;
G_END_DECLS
diff --git a/src/libbiji/biji-tracker.c b/src/libbiji/biji-tracker.c
index 4445f1c..76b07f6 100644
--- a/src/libbiji/biji-tracker.c
+++ b/src/libbiji/biji-tracker.c
@@ -129,7 +129,7 @@ biji_perform_update_async_and_free (gchar *query, BijiFunc f, gpointer user_data
/* Don't worry too much. We just want plain text here */
static gchar *
-tracker_str ( gchar * string )
+tracker_str (const gchar * string )
{
return biji_str_mass_replace (string, "\n", " ", "'", " ", NULL);
}
@@ -145,12 +145,7 @@ to_8601_date( gchar * dot_iso_8601_date )
static gchar *
get_note_url (BijiNoteObj *note)
{
- gchar *path, *retval;
-
- path = biji_item_get_uuid (BIJI_ITEM (note));
- retval = g_strdup_printf ("file://%s", path);
- g_free (path);
- return retval;
+ return g_strdup_printf ("file://%s", biji_item_get_uuid (BIJI_ITEM (note)));
}
/////////////// Tags
@@ -261,7 +256,7 @@ biji_get_items_with_collection_finish (GObject *source_object,
}
void
-biji_get_items_with_collection_async (gchar *collection,
+biji_get_items_with_collection_async (const gchar *collection,
GAsyncReadyCallback f,
gpointer user_data)
{
@@ -451,7 +446,7 @@ biji_create_new_collection_async (BijiNoteBook *book,
/* removes the tag EVEN if files associated.
* TODO : afterward */
void
-biji_remove_collection_from_tracker (gchar *urn)
+biji_remove_collection_from_tracker (const gchar *urn)
{
gchar *query = g_strdup_printf ("DELETE {'%s' a nfo:DataContainer}", urn);
biji_perform_update_async_and_free (query, NULL, NULL);
@@ -482,11 +477,10 @@ biji_remove_collection_from_note (BijiNoteObj *note, gchar *urn)
void
biji_note_delete_from_tracker (BijiNoteObj *note)
{
- gchar *query, *path;
+ gchar *query;
- path = biji_item_get_uuid (BIJI_ITEM (note));
- query = g_strdup_printf ("DELETE { <%s> a rdfs:Resource }", path);
- g_free (path);
+ query = g_strdup_printf ("DELETE { <%s> a rdfs:Resource }",
+ biji_item_get_uuid (BIJI_ITEM (note)));
biji_perform_update_async_and_free (query, NULL, NULL);
}
@@ -494,11 +488,14 @@ biji_note_delete_from_tracker (BijiNoteObj *note)
void
bijiben_push_note_to_tracker (BijiNoteObj *note)
{
- gchar *title,*content,*file,*date, *create_date,*last_change_date, *path;
+ gchar *title,*content,*file,*date, *create_date,*last_change_date;
+ const gchar *path;
+
+ g_return_if_fail (BIJI_IS_NOTE_OBJ (note));
path = biji_item_get_uuid (BIJI_ITEM (note));
title = tracker_str (biji_item_get_title (BIJI_ITEM (note)));
- file = g_strdup_printf ("file://%s", path);
+ file = get_note_url (note);
date = biji_note_obj_get_create_date (note);
create_date = to_8601_date (date);
@@ -535,6 +532,5 @@ bijiben_push_note_to_tracker (BijiNoteObj *note)
g_free(content);
g_free(create_date);
g_free(last_change_date);
- g_free (path);
}
diff --git a/src/libbiji/biji-tracker.h b/src/libbiji/biji-tracker.h
index f559be5..9425b92 100644
--- a/src/libbiji/biji-tracker.h
+++ b/src/libbiji/biji-tracker.h
@@ -31,7 +31,7 @@ GList * biji_get_items_with_collection_finish (GObject *source_object,
GAsyncResult *res,
BijiNoteBook *book);
-void biji_get_items_with_collection_async (gchar *needle,
+void biji_get_items_with_collection_async (const gchar *needle,
GAsyncReadyCallback f,
gpointer user_data);
@@ -53,7 +53,7 @@ void biji_get_all_collections_async (GAsyncReadyCallback f, gpointer user_data);
void biji_create_new_collection_async (BijiNoteBook *book, const gchar *tag, BijiFunc afterward, gpointer
user_data);
-void biji_remove_collection_from_tracker (gchar *urn);
+void biji_remove_collection_from_tracker (const gchar *urn);
// when adding an existing collection, use the collection title
void biji_push_existing_collection_to_note (BijiNoteObj *note, gchar *title);
diff --git a/src/libbiji/biji-zeitgeist.c b/src/libbiji/biji-zeitgeist.c
index ba5e9c2..31faf6b 100644
--- a/src/libbiji/biji-zeitgeist.c
+++ b/src/libbiji/biji-zeitgeist.c
@@ -33,14 +33,12 @@ get_log (void)
void
insert_zeitgeist (BijiNoteObj *note, const char *action)
{
- gchar *uri, *path;
+ gchar *uri;
ZeitgeistEvent *event;
ZeitgeistSubject *subject ;
ZeitgeistLog *log = get_log() ;
- path = biji_item_get_uuid (BIJI_ITEM (note));
- uri = g_strdup_printf ("file://%s", path);
- g_free (path);
+ uri = g_strdup_printf ("file://%s", biji_item_get_uuid (BIJI_ITEM (note)));
subject = zeitgeist_subject_new_full (uri, //URI
ZEITGEIST_NFO_DOCUMENT, //inter
diff --git a/src/libbiji/deserializer/biji-lazy-deserializer.c
b/src/libbiji/deserializer/biji-lazy-deserializer.c
index a543504..0f291f9 100644
--- a/src/libbiji/deserializer/biji-lazy-deserializer.c
+++ b/src/libbiji/deserializer/biji-lazy-deserializer.c
@@ -518,14 +518,13 @@ gboolean
biji_lazy_deserialize_internal (BijiLazyDeserializer *self)
{
BijiNoteObj* n = self->priv->note;
- gchar *path;
+ const gchar *path;
xmlDocPtr doc;
xmlNodePtr cur;
xmlChar *version;
path = biji_item_get_uuid (BIJI_ITEM (n));
doc = xmlParseFile (path);
- g_free (path);
if (doc == NULL )
{
@@ -583,7 +582,7 @@ biji_lazy_deserialize_internal (BijiLazyDeserializer *self)
path = biji_item_get_uuid (BIJI_ITEM (n));
self->priv->r = xmlNewTextReaderFilename (path);
- g_free (path);
+
biji_parse_file (self);
xmlFreeDoc (doc);
diff --git a/src/libbiji/serializer/biji-lazy-serializer.c b/src/libbiji/serializer/biji-lazy-serializer.c
index 1da1080..e40a800 100644
--- a/src/libbiji/serializer/biji-lazy-serializer.c
+++ b/src/libbiji/serializer/biji-lazy-serializer.c
@@ -168,8 +168,9 @@ biji_lazy_serialize_internal (BijiLazySerializer *self)
BijiLazySerializerPrivate *priv = self->priv;
GList *tags;
GdkRGBA color;
- gchar *path, *date, *color_str;
+ gchar *date, *color_str;
gboolean retval;
+ const gchar *path;
priv->writer = xmlNewTextWriterMemory(priv->buf, 0);
@@ -191,7 +192,7 @@ biji_lazy_serialize_internal (BijiLazySerializer *self)
// <Title>
serialize_node (priv->writer,
"title",
- biji_item_get_title (BIJI_ITEM (priv->note)));
+ (gchar*) biji_item_get_title (BIJI_ITEM (priv->note)));
// <text>
xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n ");
@@ -249,7 +250,7 @@ biji_lazy_serialize_internal (BijiLazySerializer *self)
path = biji_item_get_uuid (BIJI_ITEM (priv->note));
retval = g_file_set_contents (path, (gchar*) priv->buf->content, -1, NULL);
- g_free (path);
+
return retval;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]