コード例 #1
0
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);
}
コード例 #2
0
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;
}