gnome-terminal r2667 - trunk/src



Author: chpe
Date: Thu May 29 19:43:30 2008
New Revision: 2667
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=2667&view=rev

Log:
Make the system font a property on TerminalApp, so we don't need to monitor the gconf key in each and every TerminalScreen!


Modified:
   trunk/src/terminal-app.c
   trunk/src/terminal-screen.c

Modified: trunk/src/terminal-app.c
==============================================================================
--- trunk/src/terminal-app.c	(original)
+++ trunk/src/terminal-app.c	Thu May 29 19:43:30 2008
@@ -92,19 +92,28 @@
   GtkWidget *manage_profiles_default_menu;
 
   GConfClient *conf;
+  guint profile_list_notify_id;
+  guint default_profile_notify_id;
+  guint system_font_notify_id;
 
   GHashTable *profiles;
   char* default_profile_id;
   TerminalProfile *default_profile;
   gboolean default_profile_locked;
 
-  guint profile_list_notify_id;
-  guint default_profile_notify_id;
+  PangoFontDescription *system_font_desc;
 
   gboolean use_factory;
 };
 
-enum {
+enum
+{
+  PROP_0,
+  PROP_SYSTEM_FONT
+};
+
+enum
+{
   QUIT,
   PROFILES_LIST_CHANGED,
   DEFAULT_PROFILE_CHANGED,
@@ -128,6 +137,10 @@
 
 static TerminalApp *global_app = NULL;
 
+#define MONOSPACE_FONT_DIR "/desktop/gnome/interface"
+#define MONOSPACE_FONT_KEY MONOSPACE_FONT_DIR "/monospace_font_name"
+#define DEFAULT_MONOSPACE_FONT ("Monospace 10")
+
 #define PROFILE_LIST_KEY CONF_GLOBAL_PREFIX "/profile_list"
 #define DEFAULT_PROFILE_KEY CONF_GLOBAL_PREFIX "/default_profile"
 
@@ -1046,6 +1059,44 @@
 }
 
 static void
+terminal_app_system_font_notify_cb (GConfClient *client,
+                                    guint        cnxn_id,
+                                    GConfEntry  *entry,
+                                    gpointer     user_data)
+{
+  TerminalApp *app = TERMINAL_APP (user_data);
+  GConfValue *gconf_value;
+  const char *font;
+  PangoFontDescription *font_desc;
+
+  if (strcmp (gconf_entry_get_key (entry), MONOSPACE_FONT_KEY) != 0)
+    return;
+
+  gconf_value = gconf_entry_get_value (entry);
+  if (!gconf_value || gconf_value->type != GCONF_VALUE_STRING)
+    return;
+
+  font = gconf_value_get_string (gconf_value);
+  if (!font)
+    return;
+
+  font_desc = pango_font_description_from_string (font);
+  if (app->system_font_desc &&
+      pango_font_description_equal (app->system_font_desc, font_desc))
+    {
+      pango_font_description_free (font_desc);
+      return;
+    }
+
+  if (app->system_font_desc)
+    pango_font_description_free (app->system_font_desc);
+
+  app->system_font_desc = font_desc;
+
+  g_object_notify (G_OBJECT (app), "system-font");
+}
+
+static void
 new_profile_response_callback (GtkWidget *new_profile_dialog,
                                int        response_id,
                                TerminalApp *app)
@@ -1565,27 +1616,34 @@
   gconf_client_add_dir (app->conf, CONF_GLOBAL_PREFIX,
                         GCONF_CLIENT_PRELOAD_ONELEVEL,
                         NULL);
+  gconf_client_add_dir (app->conf, MONOSPACE_FONT_DIR,
+                        GCONF_CLIENT_PRELOAD_ONELEVEL,
+                        NULL);
   
   app->profile_list_notify_id =
     gconf_client_notify_add (app->conf, PROFILE_LIST_KEY,
                              terminal_app_profile_list_notify_cb,
-                             app,
-                             NULL, NULL);
+                             app, NULL, NULL);
 
   app->default_profile_notify_id =
     gconf_client_notify_add (app->conf,
                              DEFAULT_PROFILE_KEY,
                              terminal_app_default_profile_notify_cb,
-                             app,
-                             NULL, NULL);
-  
-  terminal_accels_init ();
-  terminal_encoding_init ();
-  
-  /* And now read the profile list */
+                             app, NULL, NULL);
+
+  app->system_font_notify_id =
+    gconf_client_notify_add (app->conf,
+                             MONOSPACE_FONT_KEY,
+                             terminal_app_system_font_notify_cb,
+                             app, NULL, NULL);
+
   gconf_client_notify (app->conf, PROFILE_LIST_KEY);
   gconf_client_notify (app->conf, DEFAULT_PROFILE_KEY);
+  gconf_client_notify (app->conf, MONOSPACE_FONT_KEY);
 
+  terminal_accels_init ();
+  terminal_encoding_init ();
+  
   sm_client = gnome_master_client ();
   g_signal_connect (sm_client,
                     "save_yourself",
@@ -1604,11 +1662,13 @@
 
   if (app->profile_list_notify_id != 0)
     gconf_client_notify_remove (app->conf, app->profile_list_notify_id);
-
   if (app->default_profile_notify_id != 0)
     gconf_client_notify_remove (app->conf, app->default_profile_notify_id);
+  if (app->system_font_notify_id != 0)
+    gconf_client_notify_remove (app->conf, app->system_font_notify_id);
 
   gconf_client_remove_dir (app->conf, CONF_GLOBAL_PREFIX, NULL);
+  gconf_client_remove_dir (app->conf, MONOSPACE_FONT_DIR, NULL);
 
   g_object_unref (app->conf);
 
@@ -1616,17 +1676,43 @@
 
   g_hash_table_destroy (app->profiles);
 
+  if (app->system_font_desc)
+    pango_font_description_free (app->system_font_desc);
+
   G_OBJECT_CLASS (terminal_app_parent_class)->finalize (object);
 
   global_app = NULL;
 }
 
 static void
+terminal_app_get_property (GObject *object,
+                            guint prop_id,
+                            GValue *value,
+                            GParamSpec *pspec)
+{
+  TerminalApp *app = TERMINAL_APP (object);
+
+  switch (prop_id)
+    {
+      case PROP_SYSTEM_FONT:
+        if (app->system_font_desc)
+          g_value_set_boxed (value, app->system_font_desc);
+        else
+          g_value_take_boxed (value, pango_font_description_from_string (DEFAULT_MONOSPACE_FONT));
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
 terminal_app_class_init (TerminalAppClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->finalize = terminal_app_finalize;
+  object_class->get_property = terminal_app_get_property;
 
   signals[QUIT] =
     g_signal_new (I_("quit"),
@@ -1636,6 +1722,13 @@
                   NULL, NULL,
                   g_cclosure_marshal_VOID__VOID,
                   G_TYPE_NONE, 0);
+
+  g_object_class_install_property
+    (object_class,
+     PROP_SYSTEM_FONT,
+     g_param_spec_boxed ("system-font", NULL, NULL,
+                         PANGO_TYPE_FONT_DESCRIPTION,
+                         G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 }
 
 /* Public API */

Modified: trunk/src/terminal-screen.c
==============================================================================
--- trunk/src/terminal-screen.c	(original)
+++ trunk/src/terminal-screen.c	Thu May 29 19:43:30 2008
@@ -28,8 +28,8 @@
 #include <X11/extensions/Xrender.h>
 #include <gdk/gdkx.h>
 
+#include <gconf/gconf.h>
 #include <libgnome/gnome-util.h> /* gnome_util_user_shell */
-#include <libgnome/gnome-url.h> /* gnome_url_show */
 
 #include "terminal-accels.h"
 #include "terminal-app.h"
@@ -41,8 +41,6 @@
 #include "terminal-window.h"
 #include "skey-popup.h"
 
-#define MONOSPACE_FONT_DIR "/desktop/gnome/interface"
-#define MONOSPACE_FONT_KEY MONOSPACE_FONT_DIR "/monospace_font_name"
 #define HTTP_PROXY_DIR "/system/http_proxy"
 
 typedef struct
@@ -68,13 +66,13 @@
   int child_pid;
   double font_scale;
   guint recheck_working_dir_idle;
-  guint gconf_connection_id;
   gboolean user_title; /* title was manually set */
   GSList *url_tags;
   GSList *skey_tags;
 };
 
-enum {
+enum
+{
   PROFILE_SET,
   SHOW_POPUP_MENU,
   LAST_SIGNAL
@@ -102,6 +100,9 @@
 static void terminal_screen_finalize    (GObject             *object);
 static void terminal_screen_update_on_realize (VteTerminal *vte_terminal,
                                                TerminalScreen *screen);
+static void terminal_screen_system_font_notify_cb (TerminalApp *app,
+                                                   GParamSpec *pspec,
+                                                   TerminalScreen *screen);
 static void terminal_screen_change_font (TerminalScreen *screen);
 static gboolean terminal_screen_popup_menu         (GtkWidget      *term,
                                                     TerminalScreen *screen);
@@ -126,11 +127,6 @@
 
 static void queue_recheck_working_dir (TerminalScreen *screen);
 
-static void monospace_font_change_notify (GConfClient *client,
-					  guint        cnxn_id,
-					  GConfEntry  *entry,
-					  gpointer     user_data);
-
 static void drag_data_received (TerminalScreen   *widget,
                                 GdkDragContext   *context,
                                 gint              x,
@@ -217,47 +213,6 @@
 }
 
 static void
-connect_monospace_font_change (TerminalScreen *screen)
-{
-  TerminalScreenPrivate *priv = screen->priv;
-  GError *err;
-  GConfClient *conf;
-  guint connection_id;
-
-  conf = gconf_client_get_default ();
-  
-  err = NULL;
-  gconf_client_add_dir (conf, MONOSPACE_FONT_DIR,
-                        GCONF_CLIENT_PRELOAD_ONELEVEL,
-                        &err);
-
-  if (err)
-    {
-      g_printerr (_("There was an error loading config from %s. (%s)\n"),
-                  MONOSPACE_FONT_DIR, err->message);
-      g_error_free (err);
-    }
-
-  err = NULL;
-  connection_id = gconf_client_notify_add (conf,
-					   MONOSPACE_FONT_DIR,
-					   monospace_font_change_notify,
-					   screen, 
-					   NULL, &err);
-
-  g_object_unref (conf);
-  
-  if (err)
-    {
-      g_printerr (_("There was an error subscribing to notification of monospace font changes. (%s)\n"),
-                  err->message);
-      g_error_free (err);
-    }
-  else
-    priv->gconf_connection_id = connection_id;
-}
-
-static void
 terminal_screen_sync_settings (GtkSettings *settings,
                                GParamSpec *pspec,
                                TerminalScreen *screen)
@@ -424,12 +379,13 @@
                     G_CALLBACK (terminal_screen_widget_child_died),
                     screen);
 
-  connect_monospace_font_change (screen);
-
   g_signal_connect (G_OBJECT (screen), "parent-set",
                     G_CALLBACK (parent_set_callback), 
                     NULL);
 
+  g_signal_connect (terminal_app_get (), "notify::system-font",
+                    G_CALLBACK (terminal_screen_system_font_notify_cb), screen);
+
 #ifdef DEBUG_GEOMETRY
   g_signal_connect_after (screen, "size-request", G_CALLBACK (size_request), NULL);
   g_signal_connect_after (screen, "size-allocate", G_CALLBACK (size_allocate), NULL);
@@ -496,7 +452,6 @@
                                                         NULL,
                                                         G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
-
   g_type_class_add_private (object_class, sizeof (TerminalScreenPrivate));
 }
 
@@ -519,17 +474,10 @@
 {
   TerminalScreen *screen = TERMINAL_SCREEN (object);
   TerminalScreenPrivate *priv = screen->priv;
-  GConfClient *conf;
-
-  conf = gconf_client_get_default ();
-  
-  if (priv->gconf_connection_id)
-    gconf_client_notify_remove (conf, priv->gconf_connection_id);
-  
-  gconf_client_remove_dir (conf, MONOSPACE_FONT_DIR,
-			   NULL);
 
-  g_object_unref (conf);
+  g_signal_handlers_disconnect_by_func (terminal_app_get (),
+                                        G_CALLBACK (terminal_screen_system_font_notify_cb),
+                                        screen);
 
   if (priv->title_editor)
     gtk_widget_destroy (priv->title_editor);
@@ -855,44 +803,6 @@
   vte_terminal_set_background_tint_color (VTE_TERMINAL (screen), &bg);
 }
 
-/* Note this can be called on style_set, on prefs changing,
- * and on setting the font scale factor
- */
-static void
-monospace_font_change_notify (GConfClient *client,
-			      guint        cnxn_id,
-			      GConfEntry  *entry,
-			      gpointer     user_data)
-{
-  TerminalScreen *screen = TERMINAL_SCREEN (user_data);
-  
-  if (strcmp (entry->key, MONOSPACE_FONT_KEY) == 0 &&
-      GTK_WIDGET_REALIZED (screen))
-    terminal_screen_change_font (screen);
-}
-
-static PangoFontDescription *
-get_system_monospace_font (void)
-{
-  GConfClient *conf;
-  char *name;
-  PangoFontDescription *desc = NULL;
-
-  conf = gconf_client_get_default ();
-  name = gconf_client_get_string (conf, MONOSPACE_FONT_KEY, NULL);
-
-  if (name)
-    {
-      desc = pango_font_description_from_string (name);
-      g_free (name);
-    }
-  
-  if (!desc)
-    desc = pango_font_description_from_string ("Monospace 10");
-
-  return desc;
-}
-
 void
 terminal_screen_set_font (TerminalScreen *screen)
 {
@@ -905,9 +815,10 @@
   
   /* FIXMEchpe make this use a get_font_desc on TerminalProfile */
   if (terminal_profile_get_property_boolean (profile, TERMINAL_PROFILE_USE_SYSTEM_FONT))
-    desc = get_system_monospace_font ();
+    g_object_get (terminal_app_get (), "system-font", &desc, NULL);
   else
     desc = pango_font_description_copy (terminal_profile_get_property_boxed (profile, TERMINAL_PROFILE_FONT));
+  g_assert (desc);
 
   pango_font_description_set_size (desc,
 				   priv->font_scale *
@@ -941,6 +852,25 @@
 }
 
 static void
+terminal_screen_system_font_notify_cb (TerminalApp *app,
+                                       GParamSpec *pspec,
+                                       TerminalScreen *screen)
+{
+  TerminalScreenPrivate *priv = screen->priv;
+
+  if (!priv->profile)
+    return; // FIXMEchpe
+
+  if (!GTK_WIDGET_REALIZED (screen))
+    return; // FIXMEchpe still necessary??
+
+  if (!terminal_profile_get_property_boolean (priv->profile, TERMINAL_PROFILE_USE_SYSTEM_FONT))
+    return;
+
+  terminal_screen_change_font (screen);
+}
+
+static void
 terminal_screen_update_on_realize (VteTerminal *vte_terminal,
                                    TerminalScreen *screen)
 {



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