2
* Copyright (C) Pierre-Yves LUYTEN 2012 <py@luyten.fr>
4
* bijiben is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
9
* bijiben is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* See the GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "biji-note-id.h"
27
static GParamSpec *properties[BIJI_ID_PROPERTIES] = { NULL, };
29
struct _BijiNoteIDPrivate
34
GTimeVal last_change_date;
35
GTimeVal last_metadata_change_date;
36
GTimeVal create_date ;
39
#define NOTE_OBJ_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NOTE_TYPE_OBJ, NoteObjPrivate))
41
G_DEFINE_TYPE (BijiNoteID, biji_note_id, G_TYPE_OBJECT);
44
biji_note_id_init (BijiNoteID *self)
46
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, biji_note_id_get_type(),
49
self->priv->location = NULL;
50
self->priv->title = NULL;
54
biji_note_id_finalize (GObject *object)
56
BijiNoteID *id = BIJI_NOTE_ID (object);
57
BijiNoteIDPrivate *priv = id->priv;
59
g_object_unref (priv->location);
62
G_OBJECT_CLASS (biji_note_id_parent_class)->finalize (object);
66
biji_note_id_set_path (BijiNoteID *self, const gchar *path)
68
g_warn_if_fail (!self->priv->location);
69
self->priv->location = g_file_new_for_path (path);
73
biji_note_id_set_property (GObject *object,
78
BijiNoteID *self = BIJI_NOTE_ID (object);
84
biji_note_id_set_path (self,g_value_get_string (value));
87
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
93
biji_note_id_get_property (GObject *object,
98
BijiNoteID *self = BIJI_NOTE_ID (object);
103
g_value_set_object (value, g_file_get_basename (self->priv->location));
106
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
112
biji_note_id_class_init (BijiNoteIDClass *klass)
114
GObjectClass* object_class = G_OBJECT_CLASS (klass);
116
object_class->finalize = biji_note_id_finalize;
117
object_class->get_property = biji_note_id_get_property;
118
object_class->set_property = biji_note_id_set_property;
120
properties[PROP_PATH] =
121
g_param_spec_string("path",
123
"The location where the note is stored and saved",
127
g_object_class_install_properties (object_class, BIJI_ID_PROPERTIES, properties);
129
g_type_class_add_private (klass, sizeof (BijiNoteIDPrivate));
133
biji_note_id_equal (BijiNoteID *a, BijiNoteID *b)
135
return g_file_equal (a->priv->location, b->priv->location);
139
biji_note_id_get_path (BijiNoteID* n)
141
g_return_val_if_fail (BIJI_IS_NOTE_ID (n), NULL);
143
return g_file_get_path (n->priv->location);
147
biji_note_id_get_uuid (BijiNoteID *n)
149
return g_file_get_basename (n->priv->location);
153
biji_note_id_get_file (BijiNoteID *note)
155
return note->priv->location;
159
biji_note_id_set_title (BijiNoteID *n, gchar* title)
162
g_free (n->priv->title);
164
n->priv->title = g_strdup (title);
168
biji_note_id_get_title (BijiNoteID* n)
170
return n->priv->title ;
174
set_date_from_string (gchar *iso8601, GTimeVal *date)
176
g_return_val_if_fail (iso8601, FALSE);
177
g_return_val_if_fail (date, FALSE);
179
if (!g_time_val_from_iso8601 (iso8601, date))
181
g_get_current_time (date);
189
biji_note_id_get_last_change_date (BijiNoteID* n)
191
g_return_val_if_fail (BIJI_IS_NOTE_ID (n), NULL);
193
return g_time_val_to_iso8601 (&(n->priv->last_change_date));
197
biji_note_id_set_last_change_date_now (BijiNoteID *n)
199
g_get_current_time(&(n->priv->last_change_date));
203
biji_note_id_get_last_change_date_sec (BijiNoteID *n)
205
g_return_val_if_fail (BIJI_IS_NOTE_ID (n), 0);
207
return n->priv->last_change_date.tv_sec ;
211
biji_note_id_set_last_change_date (BijiNoteID* n,gchar* date)
213
return set_date_from_string(date,&(n->priv->last_change_date));
217
biji_note_id_get_last_metadata_change_date(BijiNoteID* n)
219
g_return_val_if_fail (BIJI_IS_NOTE_ID (n), NULL);
221
return g_time_val_to_iso8601 (&n->priv->last_metadata_change_date);
225
biji_note_id_set_last_metadata_change_date (BijiNoteID* n,gchar* date)
227
return set_date_from_string(date,&(n->priv->last_metadata_change_date));
231
biji_note_id_set_last_metadata_change_date_now (BijiNoteID *n)
233
g_get_current_time(&(n->priv->last_metadata_change_date));
237
biji_note_id_get_create_date(BijiNoteID* n)
239
g_return_val_if_fail (BIJI_IS_NOTE_ID (n), NULL);
241
return g_time_val_to_iso8601 (&n->priv->create_date);
245
biji_note_id_set_create_date (BijiNoteID* n,gchar* date)
247
return set_date_from_string (date, &(n->priv->create_date));
251
biji_note_id_set_create_date_now (BijiNoteID* n)
253
g_get_current_time (&(n->priv->create_date));