Beispiel #1
0
static void
switch_to_item (BjbMainView *view, BijiItem *to_open)
{
  if (BIJI_IS_NOTE_OBJ (to_open))
  {
    /* If the note is already opened in another window, just show it. */
    if (biji_note_obj_is_opened (BIJI_NOTE_OBJ (to_open)))
    {
      GList *notes ;

      notes = gtk_application_get_windows(GTK_APPLICATION(g_application_get_default()));
      g_list_foreach (notes, show_window_if_note, to_open);
      return ;
    }

    /* Otherwise, leave main view */
    switch_to_note_view (view, BIJI_NOTE_OBJ (to_open));
  }

  /* Notebook
   * TODO : check if already opened (same as above) */
  else if (BIJI_IS_NOTEBOOK (to_open))
  {
    bjb_controller_set_notebook (view->priv->controller,
                                   BIJI_NOTEBOOK (to_open));
  }
}
Beispiel #2
0
static gint64
biji_note_obj_get_mtime (BijiItem *note)
{
  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (note), 0);

  return biji_note_id_get_mtime (BIJI_NOTE_OBJ (note)->priv->id);
}
Beispiel #3
0
static const gchar *
biji_note_obj_get_title (BijiItem *note)
{
  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (note), NULL);

  return biji_note_id_get_title (BIJI_NOTE_OBJ (note)->priv->id);
}
Beispiel #4
0
static void
biji_note_obj_finalize (GObject *object)
{
  BijiNoteObj        *self = BIJI_NOTE_OBJ(object);
  BijiNoteObjPrivate *priv = self->priv;

  if (priv->timeout)
    g_object_unref (priv->timeout);

  if (priv->needs_save)
    on_save_timeout (self);

  g_clear_object (&priv->id);

  g_hash_table_destroy (priv->labels);

  if (priv->icon)
    g_object_unref (priv->icon);

  if (priv->emblem)
    g_object_unref (priv->emblem);

  if (priv->pristine)
    g_object_unref (priv->pristine);

  gdk_rgba_free (priv->color);

  G_OBJECT_CLASS (biji_note_obj_parent_class)->finalize (object);
}
Beispiel #5
0
static GdkPixbuf *
biji_note_obj_get_pristine (BijiItem *item)
{
  GdkRGBA                note_color;
  cairo_t               *cr;
  cairo_surface_t       *surface = NULL;
  BijiNoteObj           *note = BIJI_NOTE_OBJ (item);

  if (note->priv->pristine)
    return note->priv->pristine;

  /* Create & Draw surface */
  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                        BIJI_EMBLEM_WIDTH,
                                        BIJI_EMBLEM_HEIGHT) ;
  cr = cairo_create (surface);

  /* Background */
  cairo_rectangle (cr, 0, 0, BIJI_EMBLEM_WIDTH, BIJI_EMBLEM_HEIGHT);
  if (biji_note_obj_get_rgba (note, &note_color))
    gdk_cairo_set_source_rgba (cr, &note_color);

  cairo_fill (cr);
  cairo_destroy (cr);

  note->priv->pristine = gdk_pixbuf_get_from_surface (surface,
                                                      0, 0,
                                                      BIJI_EMBLEM_WIDTH,
                                                      BIJI_EMBLEM_HEIGHT);

  cairo_surface_destroy (surface);

  return note->priv->pristine;
}
Beispiel #6
0
void
bjb_window_base_switch_to_item (BjbWindowBase *bwb, BijiItem *item)
{
  BjbWindowBasePriv *priv = bwb->priv;
  GtkWidget *w = GTK_WIDGET (bwb);

  bjb_search_toolbar_disconnect (priv->search_bar);
  bjb_search_toolbar_fade_out (priv->search_bar);
  destroy_note_if_needed (bwb);

  if (BIJI_IS_NOTE_OBJ (item))
  {

    BijiNoteObj *note = BIJI_NOTE_OBJ (item);

    priv->note = note;

    priv->note_view = bjb_note_view_new (w, note);
    gtk_stack_add_named (priv->stack, GTK_WIDGET (priv->note_view), "note-view");

    g_object_add_weak_pointer (G_OBJECT (priv->note_view),
                               (gpointer *) &priv->note_view);

    bjb_window_base_switch_to (bwb, BJB_WINDOW_BASE_NOTE_VIEW);
    gtk_widget_show (w);
    bjb_note_view_grab_focus (priv->note_view);
  }
}
Beispiel #7
0
static void
biji_note_obj_finalize (GObject *object)
{    
  BijiNoteObj        *self = BIJI_NOTE_OBJ(object);
  BijiNoteObjPrivate *priv = self->priv;

  g_object_unref (priv->timeout);

  if (priv->needs_save)
    on_save_timeout (self);

  g_clear_object (&priv->id);

  if (priv->html)
    g_free (priv->html);

  if (priv->raw_text);
    g_free (priv->raw_text);

  g_list_free (priv->tags);

  g_clear_object (&priv->icon);

  G_OBJECT_CLASS (biji_note_obj_parent_class)->finalize (object);
}
Beispiel #8
0
/*static */ gboolean
biji_note_obj_add_notebook (BijiItem *item,
                              BijiItem *notebook,
                              gchar    *title)
{
  BijiNoteObj *note;
  gchar *label = title;

  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (item), FALSE);
  note = BIJI_NOTE_OBJ (item);

  if (BIJI_IS_NOTEBOOK (notebook))
    label = (gchar*) biji_item_get_title (notebook);

  if (biji_note_obj_has_notebook (item, label))
    return FALSE;

  g_hash_table_add (note->priv->labels, g_strdup (label));

  if (BIJI_IS_NOTEBOOK (notebook))
  {
    biji_push_existing_notebook_to_note (
      note, label, _biji_notebook_refresh, notebook); // Tracker
    biji_note_id_set_last_metadata_change_date (note->priv->id,
                                                g_get_real_time () / G_USEC_PER_SEC);
    biji_note_obj_save_note (note);
  }

  return TRUE;
}
Beispiel #9
0
static const gchar *
biji_note_obj_get_path (BijiItem *item)
{
  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (item), NULL);

  BijiNoteObj *note = BIJI_NOTE_OBJ (item);

  return biji_note_id_get_path (note->priv->id);
}
static void
biji_process_string (xmlTextReaderPtr reader,
                     BijiReaderFunc process_xml,
                     gpointer user_data)
{
  xmlChar *result = xmlTextReaderReadString (reader);
  process_xml (BIJI_NOTE_OBJ (user_data), (gchar*) result);
  free (result);
}
Beispiel #11
0
gboolean
biji_note_obj_has_notebook (BijiItem *item, gchar *label)
{
  BijiNoteObj *note = BIJI_NOTE_OBJ (item);

  if (g_hash_table_lookup (note->priv->labels, label))
    return TRUE;

  return FALSE;
}
static void
bjb_selection_toolbar_set_item_visibility (BjbSelectionToolbar *self)
{
  BjbSelectionToolbarPrivate *priv;
  GList *l, *selection;
  GdkRGBA color;

  g_return_if_fail (BJB_IS_SELECTION_TOOLBAR (self));

  priv = self->priv;
  selection = bjb_main_view_get_selected_items (priv->view);


  /* Color */
  gtk_widget_set_sensitive (priv->toolbar_color, FALSE);


  for (l=selection; l !=NULL; l=l->next)
  {
    if (!biji_item_has_color (l->data))
    {
      gtk_widget_set_sensitive (priv->toolbar_color, FALSE);
      break;
    }

    else if (BIJI_IS_NOTE_OBJ (l->data))
    {
      if (biji_note_obj_get_rgba (BIJI_NOTE_OBJ (l->data), &color))
      {
        gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (priv->toolbar_color), &color);
        gtk_widget_set_sensitive (priv->toolbar_color, TRUE);
        break;
      }
    }
  }


  /* Organize */
  gtk_widget_set_sensitive (priv->toolbar_tag, TRUE);

  for (l=selection; l!=NULL; l=l->next)
  {
    if (!biji_item_is_collectable (l->data))
    {
      gtk_widget_set_sensitive (priv->toolbar_tag, FALSE);
      break;
    }
  }

  g_list_free (selection);
}
Beispiel #13
0
BijiNoteObj *
biji_note_book_get_tag_template(BijiNoteBook *book, gchar *tag)
{
  GList *notes = _biji_note_book_get_notes_with_tag(book,tag) ;

  if ( notes == NULL ) 
    return NULL ;

  gint i ;
  for ( i=0 ; i < g_list_length (notes) ; i++ )
  {
    BijiNoteObj *note = BIJI_NOTE_OBJ ( g_list_nth_data(notes,i));
    if ( note_obj_is_template(note))
     return note ;
  }

  return NULL ;
}
Beispiel #14
0
static void
biji_note_obj_get_property (GObject    *object,
                            guint       property_id,
                            GValue     *value,
                            GParamSpec *pspec)
{
  BijiNoteObj *self = BIJI_NOTE_OBJ (object);

  switch (property_id)
    {
    case PROP_ID:
      g_value_set_object (value, self->priv->id);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}
Beispiel #15
0
static void
biji_note_obj_set_property (GObject      *object,
                            guint         property_id,
                            const GValue *value,
                            GParamSpec   *pspec)
{
  BijiNoteObj *self = BIJI_NOTE_OBJ (object);


  switch (property_id)
    {
    case PROP_PATH:
      g_object_set_property (G_OBJECT (self->priv->id), "path", value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}
Beispiel #16
0
gboolean
_biji_note_book_is_title_unique(BijiNoteBook *book,gchar *title)
{
  gint i;
  gboolean result = TRUE;
  BijiNoteObj *iter;
  GList *notes = g_hash_table_get_values (book->priv->notes);

  for ( i=0 ; i < g_hash_table_size (book->priv->notes) ; i++)
  {
    iter = BIJI_NOTE_OBJ (g_list_nth_data (notes, i));

    if (g_strcmp0 (biji_note_obj_get_title (iter), title) == 0)
     result = FALSE;
  }

  g_list_free (notes);
  return result;
}
Beispiel #17
0
gboolean
biji_note_obj_remove_notebook (BijiItem *item, BijiItem *notebook)
{
  g_return_val_if_fail (BIJI_IS_NOTE_OBJ (item), FALSE);
  g_return_val_if_fail (BIJI_IS_NOTEBOOK (notebook), FALSE);

  BijiNoteObj *note = BIJI_NOTE_OBJ (item);

  if (g_hash_table_remove (note->priv->labels, biji_item_get_title (notebook)))
  {
    biji_remove_notebook_from_note (
      note, notebook, _biji_notebook_refresh, notebook); // tracker.
    biji_note_id_set_last_metadata_change_date (note->priv->id,
                                                g_get_real_time () / G_USEC_PER_SEC);
    biji_note_obj_save_note (note);
    return TRUE;
  }

  return FALSE;
}
Beispiel #18
0
/* First cancel timeout
 * this func is most probably stupid it might exists (move file) */
gboolean
biji_note_obj_trash (BijiItem *item)
{
  BijiNoteObj *note_to_kill;
  BijiNoteObjPrivate *priv;
  GFile *icon;
  gchar *icon_path;
  gboolean result;

  note_to_kill = BIJI_NOTE_OBJ (item);
  priv = note_to_kill->priv;
  icon = NULL;
  icon_path = NULL;
  result = FALSE;

  /* The event has to be logged before the note is actually deleted */
#ifdef BUILD_ZEITGEIST
  insert_zeitgeist (note_to_kill, ZEITGEIST_ZG_DELETE_EVENT);
#endif /* BUILD_ZEITGEIST */

  priv->needs_save = FALSE;
  biji_timeout_cancel (priv->timeout);
  result = BIJI_NOTE_OBJ_GET_CLASS (note_to_kill)->archive (note_to_kill);

  if (result == TRUE)
  {
    /* Delete icon file */
    icon_path = biji_note_obj_get_icon_file (note_to_kill);
    icon = g_file_new_for_path (icon_path);
    g_file_delete (icon, NULL, NULL);
  }


  g_free (icon_path);

  if (icon != NULL)
    g_object_unref (icon);

  return result;
}
Beispiel #19
0
static void
on_find_create_event (GObject *log,
                      GAsyncResult *res,
                      gpointer user_data)
{
  GError             *error;
  ZeitgeistResultSet *events;

  error = NULL;
  events = zeitgeist_log_find_events_finish (ZEITGEIST_LOG (log), res, &error);

  if (error)
  {
    g_warning ("Error reading results: %s", error->message);
    g_error_free (error);
    return;
  }


  if (zeitgeist_result_set_size (events) == 0)
    insert_zeitgeist (BIJI_NOTE_OBJ (user_data), ZEITGEIST_ZG_CREATE_EVENT);

  g_object_unref (events);
}
Beispiel #20
0
static GdkPixbuf *
biji_note_obj_get_icon (BijiItem *item)
{
  GdkRGBA               note_color;
  const gchar           *text;
  cairo_t               *cr;
  PangoLayout           *layout;
  PangoFontDescription  *desc;
  GdkPixbuf             *ret = NULL;
  cairo_surface_t       *surface = NULL;
  GtkBorder              frame_slice = { 4, 3, 3, 6 };

  BijiNoteObj *note = BIJI_NOTE_OBJ (item);

  if (note->priv->icon)
    return note->priv->icon;

  /* Create & Draw surface */
  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                        BIJI_ICON_WIDTH,
                                        BIJI_ICON_HEIGHT) ;
  cr = cairo_create (surface);

  /* Background */
  cairo_rectangle (cr, 0, 0, BIJI_ICON_WIDTH, BIJI_ICON_HEIGHT);
  if (biji_note_obj_get_rgba (note, &note_color))
    gdk_cairo_set_source_rgba (cr, &note_color);

  cairo_fill (cr);

  /* Text */
  text = biji_note_id_get_content (note->priv->id);
  if (text != NULL)
  {
    cairo_translate (cr, 10, 10);
    layout = pango_cairo_create_layout (cr);

    pango_layout_set_width (layout, 180000 );
    pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
    pango_layout_set_height (layout, 180000 ) ;

    pango_layout_set_text (layout, text, -1);
    desc = pango_font_description_from_string (BIJI_ICON_FONT);
    pango_layout_set_font_description (layout, desc);
    pango_font_description_free (desc);

    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
    pango_cairo_update_layout (cr, layout);
    pango_cairo_show_layout (cr, layout);

    g_object_unref (layout);
  }

  cairo_destroy (cr);

  ret = gdk_pixbuf_get_from_surface (surface,
                                     0, 0,
                                     BIJI_ICON_WIDTH,
                                     BIJI_ICON_HEIGHT);
  cairo_surface_destroy (surface);

  note->priv->icon = gd_embed_image_in_frame (ret, "resource:///org/gnome/bijiben/thumbnail-frame.png",
                                              &frame_slice, &frame_slice);
  g_clear_object (&ret);

  return note->priv->icon;
}