[bijiben] bjbSettings: add a use-system-font setting



commit 035224457518bf33a25201c1284c5a35e91e0c11
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Thu Oct 3 23:21:03 2013 +0200

    bjbSettings: add a use-system-font setting
    
    And use this for note view.
    See 709025

 data/org.gnome.bijiben.gschema.xml.in |    4 +
 src/bjb-note-view.c                   |   27 +++++++--
 src/bjb-settings-dialog.c             |   74 +++++++++++++++++++---
 src/bjb-settings.c                    |  112 +++++++++++++++++++++++++-------
 src/bjb-settings.h                    |   10 +++
 5 files changed, 188 insertions(+), 39 deletions(-)
---
diff --git a/data/org.gnome.bijiben.gschema.xml.in b/data/org.gnome.bijiben.gschema.xml.in
index e3be9f7..b3a5f46 100755
--- a/data/org.gnome.bijiben.gschema.xml.in
+++ b/data/org.gnome.bijiben.gschema.xml.in
@@ -5,6 +5,10 @@
       <summary>Custom Font</summary>
       <description>The font name set here will be used as the font when displaying notes.</description>
     </key>
+    <key type="b" name="use-system-font">
+      <default>true</default>
+      <summary>Whether to use the system monospace font</summary>
+    </key>
     <key type="s" name="color">
       <default>'rgb(239,242,209)'</default>
       <summary>New notes color.</summary>
diff --git a/src/bjb-note-view.c b/src/bjb-note-view.c
index d2ff02e..4f26693 100644
--- a/src/bjb-note-view.c
+++ b/src/bjb-note-view.c
@@ -256,12 +256,19 @@ bjb_note_view_constructed (GObject *obj)
   ClutterActor           *text_actor, *overlay;
   ClutterConstraint      *constraint;
   ClutterLayoutManager   *full, *bin;
+  gboolean                use_system_font;
   gchar                  *default_font;
+  GdkRGBA                 color;
+
+
+  default_font = NULL;
+  settings = bjb_app_get_settings(g_application_get_default());
+
 
   /* view new from note deserializes the note-content. */
   priv->view = biji_note_obj_open (priv->note);
 
-  settings = bjb_app_get_settings(g_application_get_default());    
+
   priv->deleted = g_signal_connect(priv->note,"deleted",
                                    G_CALLBACK(on_note_deleted),self);
 
@@ -312,12 +319,22 @@ bjb_note_view_constructed (GObject *obj)
   clutter_actor_set_y_expand(text_actor,TRUE);
 
   /* Apply the gsettings font */
-  g_object_get (G_OBJECT(settings),"font",&default_font,NULL);
-  biji_webkit_editor_set_font (BIJI_WEBKIT_EDITOR (priv->view), default_font);
-  g_free (default_font);
+
+  if (bjb_settings_use_system_font (settings))
+     default_font = bjb_settings_get_system_font (settings);
+
+  else
+     default_font = g_strdup (bjb_settings_get_default_font (settings));
+
+  if (default_font != NULL)
+  {
+    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))
   {
     gchar *default_color;
diff --git a/src/bjb-settings-dialog.c b/src/bjb-settings-dialog.c
index cffff46..e60c40a 100644
--- a/src/bjb-settings-dialog.c
+++ b/src/bjb-settings-dialog.c
@@ -49,6 +49,12 @@ struct BjbSettingsDialogPrivate_
 
   GtkListBox       *box;
   GList            *children;
+
+
+  /* Note Edition page */
+
+  GtkLabel        *font_lbl;
+  GtkWidget       *font_bt;
 };
 
 
@@ -56,9 +62,38 @@ struct BjbSettingsDialogPrivate_
 
 G_DEFINE_TYPE (BjbSettingsDialog, bjb_settings_dialog, GTK_TYPE_DIALOG)
 
+
+static void
+update_buttons (BjbSettingsDialog *self)
+{
+  BjbSettingsDialogPrivate *priv;
+  gboolean use_system_font;
+
+  priv = self->priv;
+  use_system_font = bjb_settings_use_system_font (priv->settings);
+
+  gtk_widget_set_sensitive (priv->font_lbl, !use_system_font);
+  gtk_widget_set_sensitive (priv->font_bt, !use_system_font);
+}
+
+
 /* Callbacks */
 
 static void
+on_system_font_toggled (GtkSwitch         *button,
+                        GParamSpec        *pspec,
+                        BjbSettingsDialog *self)
+{
+  BjbSettings *settings;
+
+
+  settings = self->priv->settings;
+  bjb_settings_set_use_system_font (settings, gtk_switch_get_active (button));
+  update_buttons (self);
+}
+
+
+static void
 on_font_selected (GtkFontButton     *widget,
                   BjbSettings       *settings)
 {
@@ -335,32 +370,53 @@ create_page_primary (BjbSettingsDialog *self)
 
 
 GtkWidget *
-create_page_edition (BjbSettings *settings)
+create_page_edition (BjbSettingsDialog *self)
 {
+  BjbSettingsDialogPrivate   *priv;
+  BjbSettings                *settings;
   GtkWidget                  *grid, *label, *picker, *box;
   GdkRGBA                    color;
 
+  priv = self->priv;
+  settings = priv->settings;
+
   grid = gtk_grid_new ();
   gtk_grid_set_column_spacing (GTK_GRID (grid), 36);
   gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
   gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
 
 
-  /* Default font */
-  label = gtk_label_new (_("Note Font"));
+
+  /* Use System Font */
+  label = gtk_label_new (_("Use System Font"));
   gtk_widget_set_halign (label, GTK_ALIGN_END);
   gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
-  picker = gtk_font_button_new_with_font (bjb_settings_get_default_font (settings));
+  picker = gtk_switch_new ();
+  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  gtk_box_pack_start (GTK_BOX (box), picker, FALSE, FALSE, 0);
+  gtk_switch_set_active (GTK_SWITCH (picker),
+                         bjb_settings_use_system_font (settings));
+  g_signal_connect (picker, "notify::active",
+                    G_CALLBACK (on_system_font_toggled), self);
+  gtk_grid_attach (GTK_GRID (grid), box, 2, 1, 1, 1);
+
+
+  /* Default font */
+  label = priv->font_lbl = gtk_label_new (_("Note Font"));
+  gtk_widget_set_halign (label, GTK_ALIGN_END);
+  gtk_grid_attach (GTK_GRID (grid), label, 1, 2, 1, 1);
+
+  picker = priv->font_bt = gtk_font_button_new_with_font (bjb_settings_get_default_font (settings));
   g_signal_connect (picker, "font-set",
                     G_CALLBACK (on_font_selected), settings);
-  gtk_grid_attach (GTK_GRID (grid), picker, 2, 1, 1, 1);
-
+  gtk_grid_attach (GTK_GRID (grid), picker, 2, 2, 1, 1);
+  update_buttons (self);
 
 
   /* Default color */
   label = gtk_label_new (_("Default Color"));
   gtk_widget_set_halign (label, GTK_ALIGN_END);
-  gtk_grid_attach (GTK_GRID (grid), label, 1, 2, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), label, 1, 3, 1, 1);
 
   picker = bjb_color_button_new ();
   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
@@ -369,7 +425,7 @@ create_page_edition (BjbSettings *settings)
   gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (picker), &color);
   g_signal_connect (picker, "color-set",
                     G_CALLBACK (on_color_set), settings); 
-  gtk_grid_attach (GTK_GRID (grid), box, 2, 2, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), box, 2, 3, 1, 1);
 
   return grid;
 }
@@ -432,7 +488,7 @@ bjb_settings_dialog_constructed (GObject *object)
 
 
   /* Dialog Pages */
-  page = create_page_edition (priv->settings);
+  page = create_page_edition (self);
   gtk_widget_set_vexpand (page, TRUE);
   gtk_stack_add_titled (priv->stack, page, "edition", _("Note Edition"));
 
diff --git a/src/bjb-settings.c b/src/bjb-settings.c
index 137477a..1d7feba 100644
--- a/src/bjb-settings.c
+++ b/src/bjb-settings.c
@@ -27,23 +27,32 @@
 struct _BjbSettingsPrivate
 {
   /* Note edition settings */
+  gboolean use_system_font;
   gchar *font;
   gchar *color;
 
   /* Default Provider */
   gchar *primary;
+
+  /* org.gnome.desktop */
+  GSettings *system;
 };
 
 
 enum
 {
   PROP_0,
+  PROP_USE_SYSTEM_FONT,
   PROP_FONT,
   PROP_COLOR,
   PROP_PRIMARY,
   N_PROPERTIES
 };
 
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL, };
+
+
 #define BJB_SETTINGS_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BJB_TYPE_SETTINGS, BjbSettingsPrivate))
 
 G_DEFINE_TYPE (BjbSettings, bjb_settings, G_TYPE_SETTINGS);
@@ -58,6 +67,11 @@ bjb_settings_init (BjbSettings *object)
 static void
 bjb_settings_finalize (GObject *object)
 {
+  BjbSettings *self;
+
+  self = BJB_SETTINGS (object);
+  g_object_unref (self->priv->system);
+
   G_OBJECT_CLASS (bjb_settings_parent_class)->finalize (object);
 }
 
@@ -70,7 +84,11 @@ bjb_settings_get_property (GObject    *object,
   BjbSettings *settings = BJB_SETTINGS (object);
 
   switch (prop_id)
-  {            
+  {
+    case PROP_USE_SYSTEM_FONT:
+      g_value_set_boolean (value, settings->priv->use_system_font);
+      break;
+
     case PROP_FONT:
       g_value_set_string (value, settings->priv->font);
       break;
@@ -99,6 +117,10 @@ bjb_settings_set_property (GObject      *object,
 
   switch (prop_id)
   {
+    case PROP_USE_SYSTEM_FONT:
+      settings->priv->use_system_font = g_value_get_boolean (value) ; 
+      break;
+
     case PROP_FONT:
       settings->priv->font = g_value_dup_string(value) ; 
       break;
@@ -128,8 +150,13 @@ bjb_settings_constructed (GObject *object)
 
   self = BJB_SETTINGS (object);
   settings = G_SETTINGS (object);
+  self->priv->system = g_settings_new ("org.gnome.desktop.interface");
 
 
+  g_settings_bind  (settings, "use-system-font",
+                    self,     "use-system-font",
+                    G_SETTINGS_BIND_DEFAULT);
+
   g_settings_bind  (settings, "font",
                     self,     "font",
                     G_SETTINGS_BIND_DEFAULT);
@@ -155,30 +182,44 @@ bjb_settings_class_init (BjbSettingsClass *klass)
   object_class->finalize = bjb_settings_finalize;
   object_class->get_property = bjb_settings_get_property;
   object_class->set_property = bjb_settings_set_property;
-    
-  g_object_class_install_property (object_class,PROP_FONT,
-                                   g_param_spec_string("font",
-                                                       "Notes Font",
-                                                       "Font for Notes",
-                                                       NULL,
-                                                       G_PARAM_READWRITE | 
-                                                       G_PARAM_STATIC_STRINGS));
-
-  g_object_class_install_property (object_class,PROP_COLOR,
-                                   g_param_spec_string("color",
-                                                       "New Notes Color",
-                                                       "Default Color for New Notes",
-                                                       NULL,
-                                                       G_PARAM_READWRITE | 
-                                                       G_PARAM_STATIC_STRINGS));
-
-  g_object_class_install_property (object_class,PROP_PRIMARY,
-                                   g_param_spec_string("default-location",
-                                                       "Primary Location",
-                                                       "Default Provider for New Notes",
-                                                       NULL,
-                                                       G_PARAM_READWRITE | 
-                                                       G_PARAM_STATIC_STRINGS));
+
+  properties[PROP_USE_SYSTEM_FONT] = g_param_spec_boolean (
+                                   "use-system-font",
+                                   "Use system font",
+                                   "Default System Font for Notes",
+                                   TRUE,
+                                   G_PARAM_READWRITE | 
+                                   G_PARAM_STATIC_STRINGS);
+
+
+  properties[PROP_FONT] = g_param_spec_string (
+                                   "font",
+                                   "Notes Font",
+                                   "Font for Notes",
+                                   NULL,
+                                   G_PARAM_READWRITE | 
+                                   G_PARAM_STATIC_STRINGS);
+
+
+  properties[PROP_COLOR] = g_param_spec_string (
+                                   "color",
+                                   "New Notes Color",
+                                   "Default Color for New Notes",
+                                   NULL,
+                                   G_PARAM_READWRITE | 
+                                   G_PARAM_STATIC_STRINGS);
+
+
+  properties[PROP_PRIMARY] = g_param_spec_string (
+                                   "default-location",
+                                   "Primary Location",
+                                   "Default Provider for New Notes",
+                                   NULL,
+                                   G_PARAM_READWRITE | 
+                                   G_PARAM_STATIC_STRINGS);
+
+
+  g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 }
 
 
@@ -191,6 +232,19 @@ bjb_settings_new (void)
 }
 
 
+gboolean
+bjb_settings_use_system_font            (BjbSettings *settings)
+{
+  return settings->priv->use_system_font;
+}
+
+
+void
+bjb_settings_set_use_system_font        (BjbSettings *settings, gboolean value)
+{
+  settings->priv->use_system_font = value;  
+}
+
 
 gchar *
 bjb_settings_get_default_font           (BjbSettings *settings)
@@ -213,6 +267,14 @@ bjb_settings_get_default_location       (BjbSettings *settings)
 }
 
 
+gchar *
+bjb_settings_get_system_font            (BjbSettings *settings)
+{
+  return g_settings_get_string (settings->priv->system,
+                                "font-name");
+}
+
+
 void
 show_bijiben_settings_window (GtkWidget *parent_window)
 {
diff --git a/src/bjb-settings.h b/src/bjb-settings.h
index e83d931..2051fde 100644
--- a/src/bjb-settings.h
+++ b/src/bjb-settings.h
@@ -54,6 +54,13 @@ GType             bjb_settings_get_type                   (void) G_GNUC_CONST;
 BjbSettings      *bjb_settings_new                        (void);
 
 
+gboolean          bjb_settings_use_system_font            (BjbSettings *settings);
+
+
+void              bjb_settings_set_use_system_font        (BjbSettings *settings,
+                                                           gboolean value);
+
+
 gchar            *bjb_settings_get_default_font           (BjbSettings *settings);
 
 
@@ -63,6 +70,9 @@ gchar            *bjb_settings_get_default_color          (BjbSettings *settings
 gchar            *bjb_settings_get_default_location       (BjbSettings *settings);
 
 
+gchar            *bjb_settings_get_system_font            (BjbSettings *settings);
+
+
 void              show_bijiben_settings_window            (GtkWidget *parent_window);
 
 G_END_DECLS


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