gboolean 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); const gchar *uid; gboolean retval = TRUE; uid = biji_item_get_uuid (item); if (g_hash_table_lookup (book->priv->items, uid)) retval = FALSE; else if (BIJI_IS_NOTE_OBJ (item)) _biji_note_book_add_one_item (book, item); else if (BIJI_IS_COLLECTION (item)) { g_hash_table_insert (book->priv->items, (gpointer) biji_item_get_uuid (item), item); g_signal_connect (item, "deleted", G_CALLBACK (on_item_deleted_cb), book); } if (retval && notify) biji_note_book_notify_changed (book, BIJI_BOOK_ITEM_ADDED, item); return retval; }
static void check_insert_create_zeitgeist (BijiNoteObj *note) { gchar *uri; ZeitgeistLog *log; GPtrArray *templates; ZeitgeistEvent *event; ZeitgeistSubject *subject; uri = g_strdup_printf ("file://%s", biji_item_get_uuid (BIJI_ITEM (note))); log = biji_note_book_get_zg_log (biji_item_get_book (BIJI_ITEM (note))); templates = g_ptr_array_new (); event = zeitgeist_event_new_full (ZEITGEIST_ZG_CREATE_EVENT, NULL, "application://bijiben.desktop", NULL, NULL); subject = zeitgeist_subject_new (); zeitgeist_subject_set_uri (subject, uri); zeitgeist_event_add_subject (event, subject); g_ptr_array_add (templates, event); zeitgeist_log_find_events (log, zeitgeist_time_range_new_to_now (), templates, ZEITGEIST_STORAGE_STATE_ANY, 10, ZEITGEIST_RESULT_TYPE_LEAST_RECENT_EVENTS, NULL, (GAsyncReadyCallback) on_find_create_event, note); }
gboolean biji_note_book_remove_item (BijiNoteBook *book, BijiItem *item) { g_return_val_if_fail (BIJI_IS_NOTE_BOOK (book), FALSE); g_return_val_if_fail (BIJI_IS_ITEM (item), FALSE); BijiItem *to_delete = NULL; const gchar *path; gboolean retval = FALSE; path = biji_item_get_uuid (item); to_delete = g_hash_table_lookup (book->priv->items, path); if (to_delete) { /* Signal before doing anything here. So the note is still * fully available for signal receiver. */ biji_note_book_notify_changed (book, BIJI_BOOK_ITEM_TRASHED, to_delete); biji_item_trash (item); g_hash_table_remove (book->priv->items, path); retval = TRUE; } return retval; }
void insert_zeitgeist (BijiNoteObj *note, gchar *zg_interpretation) { gchar *uri; const gchar *title; ZeitgeistEvent *event; ZeitgeistSubject *subject; ZeitgeistLog *log; /* Make sure that only notes with a title log their events. If a note is closed without a title, it is deleted. This section prevents the ACCESS_EVENT being called immediately after the note is created and the note is empty */ title = biji_item_get_title (BIJI_ITEM (note)); if (title == NULL || g_utf8_strlen (title, -1) <= 0) return; /* Insert requested log */ log = biji_note_book_get_zg_log (biji_item_get_book (BIJI_ITEM (note))); uri = g_strdup_printf ("file://%s", biji_item_get_uuid (BIJI_ITEM (note))); subject = zeitgeist_subject_new_full (uri, ZEITGEIST_NFO_DOCUMENT, ZEITGEIST_NFO_FILE_DATA_OBJECT, "application/x-note", "", title, ""); event = zeitgeist_event_new_full (zg_interpretation, ZEITGEIST_ZG_USER_ACTIVITY, "application://bijiben.desktop", "", subject, NULL); if (g_strcmp0 (zg_interpretation, ZEITGEIST_ZG_CREATE_EVENT) ==0) zeitgeist_event_set_timestamp (event, biji_note_obj_get_create_date (note)/1000); zeitgeist_log_insert_event_no_reply (log, event, NULL); g_free (uri); /* * Check if the note * was already created into zeitgeist */ if (g_strcmp0 (zg_interpretation, ZEITGEIST_ZG_MODIFY_EVENT) ==0) check_insert_create_zeitgeist (note); }
static void _biji_note_book_add_one_item (BijiNoteBook *book, BijiItem *item) { g_return_if_fail (BIJI_IS_ITEM (item)); /* Add it to the list */ g_hash_table_insert (book->priv->items, (gpointer) biji_item_get_uuid (item), item); /* Notify */ if (BIJI_IS_NOTE_OBJ (item)) { g_signal_connect (item, "changed", G_CALLBACK (book_on_note_changed_cb), book); g_signal_connect (item, "renamed", G_CALLBACK (book_on_note_changed_cb), book); g_signal_connect (item, "color-changed", G_CALLBACK (book_on_item_icon_changed_cb), book); } else if (BIJI_IS_COLLECTION (item)) { g_signal_connect (item, "deleted", G_CALLBACK (on_item_deleted_cb), book); g_signal_connect (item , "icon-changed", G_CALLBACK (book_on_item_icon_changed_cb), book); } }
gboolean biji_lazy_serialize_internal (BijiLazySerializer *self) { BijiLazySerializerPrivate *priv = self->priv; GList *tags; GdkRGBA color; gchar *date, *color_str; gboolean retval; const gchar *path; GTimeVal time = {0, 0}; priv->writer = xmlNewTextWriterMemory(priv->buf, 0); // Header xmlTextWriterStartDocument (priv->writer,"1.0","utf-8",NULL); xmlTextWriterStartElement (priv->writer, BAD_CAST "note"); xmlTextWriterWriteAttributeNS (priv->writer, NULL, BAD_CAST "version",NULL, BAD_CAST "1"); xmlTextWriterWriteAttributeNS (priv->writer, BAD_CAST "xmlns", BAD_CAST "link", NULL, BAD_CAST "http://projects.gnome.org/bijiben/link"); xmlTextWriterWriteAttributeNS (priv->writer, BAD_CAST "xmlns", BAD_CAST "size", NULL, BAD_CAST "http://projects.gnome.org/bijiben/size"); xmlTextWriterWriteAttributeNS (priv->writer, NULL, BAD_CAST "xmlns", NULL, BAD_CAST "http://projects.gnome.org/bijiben"); // <Title> serialize_node (priv->writer, "title", (gchar*) biji_item_get_title (BIJI_ITEM (priv->note))); // <text> xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n "); xmlTextWriterStartElement(priv->writer, BAD_CAST "text"); xmlTextWriterWriteAttributeNS(priv->writer, BAD_CAST "xml", BAD_CAST "space", NULL, BAD_CAST "preserve"); serialize_html (self); // </text> xmlTextWriterEndElement(priv->writer); // <last-change-date> time.tv_sec = biji_item_get_mtime (BIJI_ITEM (priv->note)); date = g_time_val_to_iso8601 (&time); if (date) { serialize_node (priv->writer, "last-change-date", date); g_free (date); } time.tv_sec = biji_note_obj_get_last_metadata_change_date (priv->note); date = g_time_val_to_iso8601 (&time); if (date) { serialize_node (priv->writer, "last-metadata-change-date", date); g_free (date); } time.tv_sec = biji_note_obj_get_create_date (priv->note); date = g_time_val_to_iso8601 (&time); if (date) { serialize_node (priv->writer, "create-date", date); g_free (date); } serialize_node (priv->writer, "cursor-position", "0"); serialize_node (priv->writer, "selection-bound-position", "0"); serialize_node (priv->writer, "width", "0"); serialize_node (priv->writer, "height", "0"); serialize_node (priv->writer, "x", "0"); serialize_node (priv->writer, "y", "0"); if (biji_note_obj_get_rgba (priv->note, &color)) { color_str = gdk_rgba_to_string (&color); serialize_node (priv->writer, "color", color_str); g_free (color_str); } //<tags> xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n "); xmlTextWriterStartElement (priv->writer, BAD_CAST "tags"); tags = biji_note_obj_get_notebooks (priv->note); g_list_foreach (tags, (GFunc) serialize_tags, priv->writer); xmlTextWriterEndElement (priv->writer); g_list_free (tags); // <open-on-startup> serialize_node (priv->writer, "open-on-startup", "False"); // <note> xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n "); xmlTextWriterEndElement(priv->writer); xmlFreeTextWriter(priv->writer); path = biji_item_get_uuid (BIJI_ITEM (priv->note)); retval = g_file_set_contents (path, (gchar*) priv->buf->content, -1, NULL); return retval; }
gboolean biji_lazy_deserialize_internal (BijiLazyDeserializer *self) { BijiNoteObj* n = self->priv->note; const gchar *path; xmlDocPtr doc; xmlNodePtr cur; xmlChar *version; path = biji_item_get_uuid (BIJI_ITEM (n)); doc = xmlParseFile (path); if (doc == NULL ) { g_warning ("File not parsed successfully"); return FALSE; } cur = xmlDocGetRootElement (doc); if (cur == NULL) { g_warning ("File empty"); xmlFreeDoc(doc); return FALSE; } if (xmlStrcmp(cur->name, (const xmlChar *) "note")) { g_message ("document of the wrong type, root node != note"); xmlFreeDoc(doc); return FALSE; } /* Switch there for note type * Despite not yet handled */ version = xmlGetNoNsProp (cur, BAD_CAST "version"); /* Bijiben type */ if (g_strcmp0 ((gchar*) cur->ns->href, BIJI_NS) ==0) { self->priv->type = BIJIBEN_1; } /* Tomboy type */ else { if (g_strcmp0 ((gchar*) cur->ns->href, TOMBOY_NS) == 0) { if (g_strcmp0 ((const gchar*) version, "0.1") == 0) self->priv->type = TOMBOY_1; if (g_strcmp0 ((const gchar*) version, "0.2") == 0) self->priv->type = TOMBOY_2; if (g_strcmp0 ((const gchar*) version, "0.3") == 0) self->priv->type = TOMBOY_3; } /* Wow this note won't be loaded i guess */ else { self->priv->type = NO_TYPE; } } xmlFree (version); path = biji_item_get_uuid (BIJI_ITEM (n)); self->priv->r = xmlNewTextReaderFilename (path); biji_parse_file (self); xmlFreeDoc (doc); return TRUE ; }