[bijiben] Add emblems for list view



commit d0b641c5f586c0e754e7fd4912503d6a73c7c1e8
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Mon Apr 15 09:39:28 2013 +0200

    Add emblems for list view
    
    These emblems only show notes color. Better than generic icon
    and might be useful for later on

 src/bjb-controller.c         |  2 +-
 src/libbiji/biji-note-obj.c  | 66 ++++++++++++++++++++++++++++++++++++++++----
 src/libbiji/biji-note-obj.h  |  2 ++
 src/utils/bjb-icons-colors.c | 42 ----------------------------
 src/utils/bjb-icons-colors.h |  2 --
 5 files changed, 64 insertions(+), 50 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index ebe02a1..aae48d4 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -206,7 +206,7 @@ bjb_controller_add_note (BjbController *self,
     if (self->priv->cur)
     {
       if (gd_main_view_get_view_type (self->priv->cur) == GD_MAIN_VIEW_LIST)
-        pix = get_note_pixbuf();
+        pix = biji_note_obj_get_emblem (note);
     }
 
     /* If no gd-main-view or if not list view,
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 8da0b2b..b4ad837 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -32,6 +32,10 @@
 #define ICON_HEIGHT 240
 #define ICON_FONT "Purusa 10"
 
+/* a cute baby icon without txt */
+#define EMBLEM_WIDTH ICON_WIDTH / 8
+#define EMBLEM_HEIGHT ICON_HEIGHT / 8
+
 struct _BijiNoteObjPrivate
 {
   /* Notebook might be null. */
@@ -50,9 +54,12 @@ struct _BijiNoteObjPrivate
   BijiTimeout           *timeout;
   gboolean              needs_save;
 
-  /* Icon might be null untill usefull */
+  /* Icon might be null untill usefull
+   * Emblem is smaller & just shows the color */
   GdkPixbuf             *icon;
+  GdkPixbuf             *emblem;
   gboolean              icon_needs_update;
+  gboolean              emblem_needs_update;
 
   /* Tags 
    * In Tomboy, templates are 'system:notebook:%s' tags.*/
@@ -126,6 +133,7 @@ biji_note_obj_init (BijiNoteObj *self)
 
   /* Icon is only computed when necessary */
   priv->icon = NULL;
+  priv->emblem = NULL;
 
   /* Keep value unitialied, so bijiben knows to assign default color */
   priv->color = NULL;
@@ -156,6 +164,7 @@ biji_note_obj_finalize (GObject *object)
   g_hash_table_destroy (priv->labels);
 
   g_clear_object (&priv->icon);
+  g_clear_object (&priv->emblem);
   gdk_rgba_free (priv->color);
 
   G_OBJECT_CLASS (biji_note_obj_parent_class)->finalize (object);
@@ -511,6 +520,7 @@ biji_note_obj_set_rgba_internal (BijiNoteObj *n, GdkRGBA *rgba)
 {
   n->priv->color = gdk_rgba_copy(rgba);
   n->priv->icon_needs_update = TRUE;
+  n->priv->emblem_needs_update = TRUE;
 
   g_signal_emit (G_OBJECT (n), biji_obj_signals[NOTE_COLOR_CHANGED],0);
 }
@@ -548,7 +558,7 @@ biji_note_obj_get_rgba(BijiNoteObj *n,
 }
 
 static void
-biji_note_obj_clear_icon (BijiNoteObj *note)
+biji_note_obj_clear_icons (BijiNoteObj *note)
 {
   if (note->priv->icon)
   {
@@ -556,6 +566,12 @@ biji_note_obj_clear_icon (BijiNoteObj *note)
     note->priv->icon = NULL ;
   }
 
+  if (note->priv->emblem)
+  {
+    g_clear_object (&note->priv->emblem);
+    note->priv->emblem = NULL ;
+  }
+
   g_signal_emit (G_OBJECT (note), biji_obj_signals[NOTE_CHANGED],0);
 }
 
@@ -565,7 +581,7 @@ void biji_note_obj_set_raw_text (BijiNoteObj *note, gchar *plain_text)
     g_free (note->priv->raw_text);
 
   note->priv->raw_text = g_strdup (plain_text);
-  biji_note_obj_clear_icon (note);
+  biji_note_obj_clear_icons (note);
 }
 
 GList *
@@ -711,8 +727,8 @@ biji_note_obj_get_icon (BijiNoteObj *note)
   if (note->priv->icon && !note->priv->icon_needs_update)
     return note->priv->icon;
 
-  /* Create & Draw surface */ 
-  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32 , 
+  /* Create & Draw surface */
+  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                         ICON_WIDTH,
                                         ICON_HEIGHT) ;
   cr = cairo_create (surface);
@@ -763,6 +779,46 @@ biji_note_obj_get_icon (BijiNoteObj *note)
   return note->priv->icon;
 }
 
+GdkPixbuf *
+biji_note_obj_get_emblem (BijiNoteObj *note)
+{
+  GdkRGBA                note_color;
+  cairo_t               *cr;
+  cairo_surface_t       *surface = NULL;
+  GdkPixbuf             *ret = NULL;
+  GtkBorder              frame_slice = { 4, 3, 3, 6 };
+
+  if (note->priv->emblem && !note->priv->emblem_needs_update)
+    return note->priv->emblem;
+
+  /* Create & Draw surface */
+  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                        EMBLEM_WIDTH,
+                                        EMBLEM_HEIGHT) ;
+  cr = cairo_create (surface);
+
+  /* Background */
+  cairo_rectangle (cr, 0, 0, EMBLEM_WIDTH, 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);
+
+  ret = gdk_pixbuf_get_from_surface (surface,
+                                     0, 0,
+                                     EMBLEM_WIDTH,
+                                     EMBLEM_HEIGHT);
+
+  cairo_surface_destroy (surface);
+  note->priv->emblem = gd_embed_image_in_frame (ret, "resource:///org/gnome/bijiben/thumbnail-frame.png",
+                                                &frame_slice, &frame_slice);
+  g_clear_object (&ret);
+  note->priv->emblem_needs_update = FALSE;
+
+  return note->priv->emblem;
+}
+
 /* Single Note */
 
 gchar *
diff --git a/src/libbiji/biji-note-obj.h b/src/libbiji/biji-note-obj.h
index 3fe0863..e773263 100644
--- a/src/libbiji/biji-note-obj.h
+++ b/src/libbiji/biji-note-obj.h
@@ -132,6 +132,8 @@ void biji_note_obj_save_note (BijiNoteObj *self);
 
 GdkPixbuf * biji_note_obj_get_icon (BijiNoteObj *note);
 
+GdkPixbuf * biji_note_obj_get_emblem (BijiNoteObj *note);
+
 void biji_note_obj_set_icon (BijiNoteObj *note, GdkPixbuf *pix);
 
 gchar *biji_note_obj_get_icon_file (BijiNoteObj *note);
diff --git a/src/utils/bjb-icons-colors.c b/src/utils/bjb-icons-colors.c
index 9a8f95c..da64672 100644
--- a/src/utils/bjb-icons-colors.c
+++ b/src/utils/bjb-icons-colors.c
@@ -13,45 +13,3 @@ get_icon (gchar *icon)
 
   return retval;
 }
-
-/* TODO
- * this func will probably disappear but otherwise it has
- * to handle size & directories */
-GdkPixbuf *
-get_note_pixbuf()
-{
-  GdkPixbuf *note_pixbuf;
-  gchar *full_path;
-  GError *error = NULL ;
-  const gchar *icons_path = bijiben_get_bijiben_dir ();
-
-  full_path = g_build_filename (icons_path,
-                                "bijiben",
-                                "icons",
-                                "hicolor",
-                                "16x16",
-                                "actions",
-                                "note.png",
-                                NULL);
-
-  note_pixbuf = gdk_pixbuf_new_from_file_at_size(full_path,
-                                                 16,
-                                                 16,
-                                                 &error);
-  g_free(full_path);
-  
-  if (error)
-  {
-    g_message("Error is %s",error->message);
-    g_error_free (error);
-    return NULL ;
-  }
-  
-  if (!note_pixbuf)
-  {
-    g_message("Notes pixbuf error.");
-    return NULL ;
-  }
-
-  return note_pixbuf ;  
-}
diff --git a/src/utils/bjb-icons-colors.h b/src/utils/bjb-icons-colors.h
index 48cdc65..3081326 100644
--- a/src/utils/bjb-icons-colors.h
+++ b/src/utils/bjb-icons-colors.h
@@ -5,6 +5,4 @@
 
 GtkWidget * get_icon (gchar *icon);
 
-GdkPixbuf * get_note_pixbuf();
-
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]