Browse Source

Add initial gconf stuff, and hook up font preference.

Signed-off-by: Bradley Smith <[email protected]>
Bradley Smith 14 years ago
parent
commit
c1e1c37e6d
7 changed files with 107 additions and 4 deletions
  1. 1 1
      configure.ac
  2. 15 0
      mssh.gconf.xml
  3. 3 2
      src/Makefile.am
  4. 23 0
      src/mssh-gconf.c
  5. 12 0
      src/mssh-gconf.h
  6. 31 0
      src/mssh-pref.c
  7. 22 1
      src/mssh-window.c

+ 1 - 1
configure.ac

@@ -4,7 +4,7 @@ AM_INIT_AUTOMAKE
 
 AC_PROG_CC
 
-PKG_CHECK_MODULES(MSSH, [gtk+-2.0 vte])
+PKG_CHECK_MODULES(MSSH, [gtk+-2.0 vte gconf-2.0])
 AC_SUBST(MSSH_CFLAGS)
 AC_SUBST(MSSH_LIBS)
 

+ 15 - 0
mssh.gconf.xml

@@ -0,0 +1,15 @@
+<gconfschemafile>
+    <schemalist>
+        <schema>
+            <key>/schemas/apps/mssh/font</key>
+            <applyto>/apps/mssh/font</applyto>
+            <owner>mssh</owner>
+            <type>string</type>
+            <default>Monospace 10</default>
+            <locale name="C">
+                <short>Terminal font</short>
+                <long>Font to use for all MSSH terminals</long>
+            </locale>
+        </schema>
+    </schemalist>
+</gconfschemafile>

+ 3 - 2
src/Makefile.am

@@ -4,7 +4,8 @@ INCLUDES = $(MSSH_CFLAGS)
 
 bin_PROGRAMS = mssh
 
-mssh_SOURCES = mssh.c mssh-terminal.c mssh-window.c mssh-pref.c
+mssh_SOURCES = mssh.c mssh-terminal.c mssh-window.c mssh-pref.c \
+	mssh-gconf.c
 mssh_LDADD = $(MSSH_LIBS)
 
-EXTRA_DIST = mssh-window.h
+EXTRA_DIST = mssh-window.h mssh-terminal.h mssh-pref.h mssh-gconf.h

+ 23 - 0
src/mssh-gconf.c

@@ -0,0 +1,23 @@
+#include <vte/vte.h>
+
+#include "mssh-gconf.h"
+#include "mssh-window.h"
+#include "mssh-terminal.h"
+
+void mssh_gconf_notify_font(GConfClient *client, guint cnxn_id,
+	GConfEntry *entry, gpointer data)
+{
+	GConfValue *value;
+	const gchar *font;
+	int i;
+	MSSHWindow *window = MSSH_WINDOW(data);
+
+	value = gconf_entry_get_value(entry);
+	font = gconf_value_get_string(value);
+
+	for(i = 0; i < window->terminals->len; i++)
+	{
+		vte_terminal_set_font_from_string(VTE_TERMINAL(g_array_index(
+			window->terminals, MSSHTerminal*, i)), font);
+	}
+}

+ 12 - 0
src/mssh-gconf.h

@@ -0,0 +1,12 @@
+#ifndef __MSSH_GCONF__
+#define __MSSH_GCONF__
+
+#include <gconf/gconf-client.h>
+
+#define MSSH_GCONF_PATH			"/apps/mssh"
+#define MSSH_GCONF_KEY_FONT		MSSH_GCONF_PATH"/font"
+
+void mssh_gconf_notify_font(GConfClient *client, guint cnxn_id,
+	GConfEntry *entry, gpointer data);
+
+#endif

+ 31 - 0
src/mssh-pref.c

@@ -1,3 +1,7 @@
+#include <gconf/gconf-client.h>
+
+#include "mssh-gconf.h"
+
 #include "mssh-pref.h"
 
 static void mssh_pref_init(MSSHPref* pref);
@@ -17,8 +21,24 @@ static void mssh_pref_close(GtkWidget *widget, gpointer data)
 	gtk_widget_destroy(GTK_WIDGET(pref));
 }
 
+static void mssh_pref_font_select(GtkWidget *widget, gpointer data)
+{
+	GConfClient *client;
+	const gchar *font;
+
+	client = gconf_client_get_default();
+
+	font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget));
+
+	gconf_client_set_string(client, MSSH_GCONF_KEY_FONT, font, NULL);
+}
+
 static void mssh_pref_init(MSSHPref* pref)
 {
+	GConfClient *client;
+	GConfEntry *entry;
+	GConfValue *value;
+
 	GtkWidget *frame = gtk_vbox_new(FALSE, 5);
 	GtkWidget *notebook = gtk_notebook_new();
 	GtkWidget *content = gtk_vbox_new(FALSE, 4);
@@ -103,6 +123,17 @@ static void mssh_pref_init(MSSHPref* pref)
 	gtk_container_set_border_width(GTK_CONTAINER(pref), 15);
 	gtk_window_set_title(GTK_WINDOW(pref), "Preferences");
 	gtk_window_set_resizable(GTK_WINDOW(pref), FALSE);
+
+	g_signal_connect(G_OBJECT(font_select), "font-set",
+		G_CALLBACK(mssh_pref_font_select), NULL);
+
+	client = gconf_client_get_default();
+
+	entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_FONT, NULL,
+		TRUE, NULL);
+	value = gconf_entry_get_value(entry);
+	gtk_font_button_set_font_name(GTK_FONT_BUTTON(font_select),
+		gconf_value_get_string(value));
 }
 
 static void mssh_pref_class_init(MSSHPrefClass *klass)

+ 22 - 1
src/mssh-window.c

@@ -1,10 +1,12 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <gconf/gconf-client.h>
 #include <gdk/gdkkeysyms.h>
 
 #include "mssh-terminal.h"
 #include "mssh-pref.h"
+#include "mssh-gconf.h"
 #include "mssh-window.h"
 
 #include "config.h"
@@ -212,6 +214,8 @@ static void mssh_window_session_focused(MSSHTerminal *terminal,
 
 static void mssh_window_relayout(MSSHWindow *window)
 {
+	GConfClient *client;
+	GConfEntry *entry;
 	int i, len = window->terminals->len;
 
 	for(i = 0; i < len; i++)
@@ -242,6 +246,12 @@ static void mssh_window_relayout(MSSHWindow *window)
 	{
 		gtk_table_resize(GTK_TABLE(window->table), ((len + 1) / 2), 2);
 	}
+
+	client = gconf_client_get_default();
+
+	entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_FONT, NULL,
+		TRUE, NULL);
+	mssh_gconf_notify_font(client, 0, entry, window);
 }
 
 static void mssh_window_add_session(MSSHWindow *window, char *hostname)
@@ -263,6 +273,8 @@ static void mssh_window_add_session(MSSHWindow *window, char *hostname)
 
 static void mssh_window_init(MSSHWindow* window)
 {
+	GConfClient *client;
+
 	GtkAccelGroup *accel_group = gtk_accel_group_new();
 	GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
 	GtkWidget *entry = gtk_entry_new();
@@ -287,6 +299,8 @@ static void mssh_window_init(MSSHWindow* window)
 
 	window->server_menu = gtk_menu_new();
 
+	window->terminals = g_array_new(FALSE, TRUE, sizeof(MSSHTerminal*));
+
 	gtk_menu_item_set_submenu(GTK_MENU_ITEM(file_item), file_menu);
 	gtk_menu_item_set_submenu(GTK_MENU_ITEM(edit_item), edit_menu);
 	gtk_menu_item_set_submenu(GTK_MENU_ITEM(server_item),
@@ -327,6 +341,14 @@ static void mssh_window_init(MSSHWindow* window)
 
 	gtk_widget_set_size_request(GTK_WIDGET(window), 1024, 768);
 	gtk_window_set_title(GTK_WINDOW(window), PACKAGE_NAME);
+
+	client = gconf_client_get_default();
+
+	gconf_client_add_dir(client, MSSH_GCONF_PATH,
+		GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
+
+	gconf_client_notify_add(client, MSSH_GCONF_KEY_FONT,
+		mssh_gconf_notify_font, window, NULL, NULL);
 }
 
 void mssh_window_start_session(MSSHWindow* window, char **env, int nhosts,
@@ -336,7 +358,6 @@ void mssh_window_start_session(MSSHWindow* window, char **env, int nhosts,
 	int rows = (nhosts / 2) + (nhosts % 2);
 
 	window->env = env;
-	window->terminals = g_array_new(FALSE, TRUE, sizeof(MSSHTerminal*));
 
 	for(i = 0; i < rows; i++)
 	{