[bijiben] Preferences : allow to choose default font and color



commit 949572696e0e107dd09a753809e86f2ca03e7f37
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Sun Nov 18 21:43:54 2012 +0100

    Preferences : allow to choose default font and color

 data/org.gnome.bijiben.gschema.xml.in   |    8 ++++----
 src/bjb-note-view.c                     |   31 +++++++++++++++++++------------
 src/bjb-settings.c                      |    3 +++
 src/libbiji/biji-note-obj.c             |   10 ++++------
 src/libbiji/editor/biji-webkit-editor.c |   24 ++++++++++++++++++++++++
 src/libbiji/editor/biji-webkit-editor.h |    2 ++
 6 files changed, 56 insertions(+), 22 deletions(-)
---
diff --git a/data/org.gnome.bijiben.gschema.xml.in b/data/org.gnome.bijiben.gschema.xml.in
index 83e8f4e..526ea58 100755
--- a/data/org.gnome.bijiben.gschema.xml.in
+++ b/data/org.gnome.bijiben.gschema.xml.in
@@ -1,13 +1,13 @@
 <schemalist>
   <schema path="/org/gnome/bijiben/" id="org.gnome.bijiben">
     <key type="s" name="font">
-      <default>'Serif 11'</default>
-      <summary>Custom Font Face</summary>
+      <default>'Cantarell 12'</default>
+      <summary>Custom Font</summary>
       <description>The font name set here will be used as the font when displaying notes.</description>
     </key>
     <key type="s" name="color">
-      <default>'Red'</default>
-      <summary>The color when text is highlighted.</summary>
+      <default>'rgb(229,230,180)'</default>
+      <summary>New notes color.</summary>
       <description>The color name set here will be used as the color when creating new notes.</description>
     </key>
   </schema>
diff --git a/src/bjb-note-view.c b/src/bjb-note-view.c
index 32929bc..92d2e41 100644
--- a/src/bjb-note-view.c
+++ b/src/bjb-note-view.c
@@ -30,9 +30,6 @@
 #include "bjb-note-view.h"
 #include "bjb-window-base.h"
 
-/* Default color (X11 rgb.txt) - maybe gsettings instead */ 
-#define DEFAULT_NOTE_COLOR "LightGoldenrodYellow"
-
 enum
 {
   PROP_0,
@@ -337,10 +334,13 @@ bjb_note_main_toolbar_new (BjbNoteView *self,
 
   GtkWidget        *color_button;
   GdkRGBA           color;
+  BjbSettings      *settings;
 
   w = gd_main_toolbar_new();
   gd = GD_MAIN_TOOLBAR(w);
 
+  settings = bjb_app_get_settings (g_application_get_default());
+
   result = gtk_clutter_actor_new_with_contents(w);
   clutter_actor_add_child(parent,result);
   gtk_widget_show_all(w);
@@ -371,7 +371,12 @@ bjb_note_main_toolbar_new (BjbNoteView *self,
 
   /* Note Color */
   if (!biji_note_obj_get_rgba (note, &color))
-    gdk_rgba_parse (&color, DEFAULT_NOTE_COLOR );
+  {
+    gchar *default_color;
+    g_object_get (G_OBJECT(settings),"color", &default_color, NULL);
+    gdk_rgba_parse (&color, default_color);
+    g_free (default_color);
+  }
 
   color_button = gtk_color_button_new ();
   gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (color_button), &color);
@@ -449,7 +454,7 @@ bjb_note_view_constructed (GObject *obj)
   ClutterActor           *stage, *vbox;
   ClutterConstraint      *constraint;
   ClutterLayoutManager   *full, *box, *bin;
-  gchar                  *default_font, *default_color;
+  gchar                  *default_font;
 
   /* view new from note deserializes the note-content. */
   priv->view = biji_note_obj_open (priv->note);
@@ -520,18 +525,20 @@ bjb_note_view_constructed (GObject *obj)
   clutter_actor_set_x_expand(text_actor,TRUE);
   clutter_actor_set_y_expand(text_actor,TRUE);
 
-  /* Apply the selected font */ 
+  /* Apply the gsettings font */
   g_object_get (G_OBJECT(settings),"font",&default_font,NULL);
-  gtk_widget_modify_font(GTK_WIDGET(priv->view),
-                         pango_font_description_from_string(default_font));
+  biji_webkit_editor_set_font (BIJI_WEBKIT_EDITOR (priv->view), default_font);
+  g_free (default_font);
 
   /* User defined color */
   GdkRGBA color ;
   if (!biji_note_obj_get_rgba(priv->note, &color))
-    gdk_rgba_parse (&color, DEFAULT_NOTE_COLOR);
-
-  g_object_get (G_OBJECT(settings),"color", &default_color,NULL);
-  
+  {
+    gchar *default_color;
+    g_object_get (G_OBJECT(settings),"color", &default_color, NULL);
+    gdk_rgba_parse (&color, default_color);
+    g_free (default_color);
+  }  
 
   biji_note_obj_set_rgba (priv->note, &color);
 
diff --git a/src/bjb-settings.c b/src/bjb-settings.c
index 2cf4294..cf9db38 100644
--- a/src/bjb-settings.c
+++ b/src/bjb-settings.c
@@ -167,6 +167,7 @@ void
 show_bijiben_settings_window (GtkWidget *parent_window)
 {
   GtkWidget *dialog,*area,*notebook,*page, *hbox, *label, *picker;
+  GdkRGBA color;
   gint width, height;
 
   BjbSettings *settings = bjb_app_get_settings(g_application_get_default());
@@ -209,6 +210,8 @@ show_bijiben_settings_window (GtkWidget *parent_window)
   label = gtk_label_new ("Default color");
   gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, FALSE, 2);
   picker = gtk_color_button_new ();
+  gdk_rgba_parse (&color, settings->color );
+  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (picker), &color);
   g_signal_connect (picker, "color-set",
                     G_CALLBACK(on_color_set), settings);
   gtk_box_pack_start (GTK_BOX (hbox),picker,TRUE,FALSE,2);  
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index cdfec11..a0e7d30 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -27,9 +27,6 @@
 
 #include <libgd/gd.h>
 
-/* Default color (X11 rgb.txt)  */ 
-#define DEFAULT_NOTE_COLOR "rgb(229,230,180)"
-
 /* Icon */
 #define ICON_WIDTH 200
 #define ICON_HEIGHT 240
@@ -120,8 +117,8 @@ biji_note_obj_init (BijiNoteObj *self)
   /* Icon is only computed when necessary */
   priv->icon = NULL;
 
-  priv->color = g_new(GdkRGBA,1) ;
-  gdk_rgba_parse ( priv->color , DEFAULT_NOTE_COLOR ) ;
+  /* Keep value unitialied, so bijiben knows to assign default color */
+  priv->color = NULL;
 
   priv->tags = NULL;
 }
@@ -475,7 +472,8 @@ void
 biji_note_obj_set_rgba(BijiNoteObj *n,GdkRGBA *rgba)
 {
   if (!n->priv->color)
-  {    
+  {
+    n->priv->color = g_new (GdkRGBA,1);
     biji_note_obj_set_rgba_internal (n, rgba);
     return;
   }
diff --git a/src/libbiji/editor/biji-webkit-editor.c b/src/libbiji/editor/biji-webkit-editor.c
index c110261..d928b42 100644
--- a/src/libbiji/editor/biji-webkit-editor.c
+++ b/src/libbiji/editor/biji-webkit-editor.c
@@ -166,6 +166,30 @@ set_editor_color (GtkWidget *w, GdkRGBA *col)
   gtk_widget_override_background_color (w, GTK_STATE_FLAG_NORMAL, col);
 }
 
+void
+biji_webkit_editor_set_font (BijiWebkitEditor *self, gchar *font)
+{
+  BijiWebkitEditorPrivate *priv = self->priv;
+  PangoFontDescription *font_desc;
+
+  /* parse : but we only parse font properties we'll be able
+   * to transfer to webkit editor
+   * Maybe is there a better way than webkitSettings,
+   * eg applying format to the whole body */
+  font_desc = pango_font_description_from_string (font);
+  const gchar * family = pango_font_description_get_family (font_desc);
+  gint size = pango_font_description_get_size (font_desc) / 1000 ;
+
+  /* Set */
+  g_object_set (G_OBJECT(priv->settings),
+                "default-font-family", family,
+                "default-font-size", size,
+                NULL);
+
+  pango_font_description_free (font_desc);
+}
+
+
 static void
 biji_webkit_editor_init (BijiWebkitEditor *self)
 {
diff --git a/src/libbiji/editor/biji-webkit-editor.h b/src/libbiji/editor/biji-webkit-editor.h
index ccca676..3a43a12 100644
--- a/src/libbiji/editor/biji-webkit-editor.h
+++ b/src/libbiji/editor/biji-webkit-editor.h
@@ -63,6 +63,8 @@ void biji_webkit_editor_copy (BijiWebkitEditor *self);
 
 void biji_webkit_editor_paste (BijiWebkitEditor *self);
 
+void biji_webkit_editor_set_font (BijiWebkitEditor *self, gchar *font);
+
 G_END_DECLS
 
 #endif /* _WEBKIT_EDITOR_H_ */



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