Browse Source

Hook up the rest of the preferences dialog.

Signed-off-by: Bradley Smith <brad@brad-smith.co.uk>
Bradley Smith 11 years ago
parent
commit
ff9d8d34a0
10 changed files with 224 additions and 51 deletions
  1. 5 0
      Makefile.am
  2. 8 0
      configure.ac
  3. 34 0
      mssh.gconf.xml
  4. 63 0
      src/mssh-gconf.c
  5. 14 5
      src/mssh-gconf.h
  6. 61 0
      src/mssh-pref.c
  7. 3 0
      src/mssh-terminal.c
  8. 1 0
      src/mssh-terminal.h
  9. 29 46
      src/mssh-window.c
  10. 6 0
      src/mssh-window.h

+ 5 - 0
Makefile.am

@@ -1 +1,6 @@
 SUBDIRS = src
+
+if GCONF_SCHEMAS_INSTALL
+install-data-local:
+	GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(top_builddir)/mssh.gconf.xml
+endif

+ 8 - 0
configure.ac

@@ -8,6 +8,14 @@ PKG_CHECK_MODULES(MSSH, [gtk+-2.0 vte gconf-2.0])
 AC_SUBST(MSSH_CFLAGS)
 AC_SUBST(MSSH_LIBS)
 
+AC_PATH_PROG(GCONFTOOL, gconftool-2, no)
+
+if test x"$GCONFTOOL" = xno; then
+  AC_MSG_ERROR([gconftool-2 executable not found in your path - should be installed with GConf])
+fi
+
+AM_GCONF_SOURCE_2
+
 AC_OUTPUT(
     Makefile
     src/Makefile

+ 34 - 0
mssh.gconf.xml

@@ -44,5 +44,39 @@
                 <long>Number of columns of tiled terminals</long>
             </locale>
         </schema>
+        <schema>
+            <key>/schemas/apps/mssh/timeout</key>
+            <applyto>/apps/mssh/timeout</applyto>
+            <owner>mssh</owner>
+            <type>int</type>
+            <default>2</default>
+            <locale name="C">
+                <short>Terminal close timeout</short>
+                <long>Timeout after which to close ended sessions</long>
+            </locale>
+        </schema>
+        <schema>
+            <key>/schemas/apps/mssh/close_ended</key>
+            <applyto>/apps/mssh/close_ended</applyto>
+            <owner>mssh</owner>
+            <type>bool</type>
+            <default>true</default>
+            <locale name="C">
+                <short>Close ended sessions</short>
+                <long>Close ended ssh sessions</long>
+            </locale>
+        </schema>
+        <schema>
+            <key>/schemas/apps/mssh/quit_all_ended</key>
+            <applyto>/apps/mssh/quit_all_ended</applyto>
+            <owner>mssh</owner>
+            <type>bool</type>
+            <default>false</default>
+            <locale name="C">
+                <short>Quit after all sessions ended</short>
+                <long>Quit MSSH when all ssh sessions have ended</long>
+            </locale>
+        </schema>
+
     </schemalist>
 </gconfschemafile>

+ 63 - 0
src/mssh-gconf.c

@@ -96,3 +96,66 @@ void mssh_gconf_notify_columns(GConfClient *client, guint cnxn_id,
 	window->columns = columns;
 	mssh_window_relayout(window);
 }
+
+void mssh_gconf_notify_timeout(GConfClient *client, guint cnxn_id,
+	GConfEntry *entry, gpointer data)
+{
+	GConfValue *value;
+	int timeout;
+
+	MSSHWindow *window = MSSH_WINDOW(data);
+
+	value = gconf_entry_get_value(entry);
+	timeout = gconf_value_get_int(value);
+
+	if(timeout < 0)
+	{
+		timeout = 0;
+		gconf_client_set_int(client, MSSH_GCONF_KEY_TIMEOUT, timeout,
+			NULL);
+	}
+
+	window->timeout = timeout;
+	mssh_window_relayout(window);
+}
+
+void mssh_gconf_notify_close_ended(GConfClient *client, guint cnxn_id,
+	GConfEntry *entry, gpointer data)
+{
+	GConfValue *value;
+	gboolean close_ended;
+	int i;
+
+	MSSHWindow *window = MSSH_WINDOW(data);
+
+	value = gconf_entry_get_value(entry);
+	close_ended = gconf_value_get_bool(value);
+
+	window->close_ended_sessions = close_ended;
+
+	if(close_ended)
+	{
+		for(i = 0; i < window->terminals->len; i++)
+		{
+			MSSHTerminal *terminal = g_array_index(window->terminals,
+				MSSHTerminal*, i);
+
+			if(terminal->ended)
+			{
+				mssh_window_session_closed(terminal, window);
+			}
+		}
+	}
+}
+
+void mssh_gconf_notify_quit_all_ended(GConfClient *client, guint cnxn_id,
+	GConfEntry *entry, gpointer data)
+{
+	GConfValue *value;
+
+	MSSHWindow *window = MSSH_WINDOW(data);
+
+	value = gconf_entry_get_value(entry);
+
+	window->exit_on_all_closed = gconf_value_get_bool(value);
+}

+ 14 - 5
src/mssh-gconf.h

@@ -3,11 +3,14 @@
 
 #include <gconf/gconf-client.h>
 
-#define MSSH_GCONF_PATH				"/apps/mssh"
-#define MSSH_GCONF_KEY_FONT			MSSH_GCONF_PATH"/font"
-#define MSSH_GCONF_KEY_FG_COLOUR	MSSH_GCONF_PATH"/fg_colour"
-#define MSSH_GCONF_KEY_BG_COLOUR	MSSH_GCONF_PATH"/bg_colour"
-#define MSSH_GCONF_KEY_COLUMNS		MSSH_GCONF_PATH"/columns"
+#define MSSH_GCONF_PATH					"/apps/mssh"
+#define MSSH_GCONF_KEY_FONT				MSSH_GCONF_PATH"/font"
+#define MSSH_GCONF_KEY_FG_COLOUR		MSSH_GCONF_PATH"/fg_colour"
+#define MSSH_GCONF_KEY_BG_COLOUR		MSSH_GCONF_PATH"/bg_colour"
+#define MSSH_GCONF_KEY_COLUMNS			MSSH_GCONF_PATH"/columns"
+#define MSSH_GCONF_KEY_TIMEOUT			MSSH_GCONF_PATH"/timeout"
+#define MSSH_GCONF_KEY_CLOSE_ENDED		MSSH_GCONF_PATH"/close_ended"
+#define MSSH_GCONF_KEY_QUIT_ALL_ENDED	MSSH_GCONF_PATH"/quit_all_ended"
 
 void mssh_gconf_notify_font(GConfClient *client, guint cnxn_id,
 	GConfEntry *entry, gpointer data);
@@ -17,5 +20,11 @@ void mssh_gconf_notify_bg_colour(GConfClient *client, guint cnxn_id,
 	GConfEntry *entry, gpointer data);
 void mssh_gconf_notify_columns(GConfClient *client, guint cnxn_id,
 	GConfEntry *entry, gpointer data);
+void mssh_gconf_notify_timeout(GConfClient *client, guint cnxn_id,
+	GConfEntry *entry, gpointer data);
+void mssh_gconf_notify_close_ended(GConfClient *client, guint cnxn_id,
+	GConfEntry *entry, gpointer data);
+void mssh_gconf_notify_quit_all_ended(GConfClient *client, guint cnxn_id,
+	GConfEntry *entry, gpointer data);
 
 #endif

+ 61 - 0
src/mssh-pref.c

@@ -75,6 +75,43 @@ static void mssh_pref_columns_select(GtkWidget *widget, gpointer data)
 	gconf_client_set_int(client, MSSH_GCONF_KEY_COLUMNS, columns, NULL);
 }
 
+static void mssh_pref_timeout_select(GtkWidget *widget, gpointer data)
+{
+	GConfClient *client;
+	int timeout;
+
+	client = gconf_client_get_default();
+
+	timeout = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
+
+	gconf_client_set_int(client, MSSH_GCONF_KEY_TIMEOUT, timeout, NULL);
+}
+
+static void mssh_pref_close_check(GtkWidget *widget, gpointer data)
+{
+	GConfClient *client;
+	gboolean close;
+
+	client = gconf_client_get_default();
+
+	close = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+
+	gconf_client_set_bool(client, MSSH_GCONF_KEY_CLOSE_ENDED, close, NULL);
+}
+
+static void mssh_pref_exit_check(GtkWidget *widget, gpointer data)
+{
+	GConfClient *client;
+	gboolean close;
+
+	client = gconf_client_get_default();
+
+	close = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+
+	gconf_client_set_bool(client, MSSH_GCONF_KEY_QUIT_ALL_ENDED, close,
+		NULL);
+}
+
 static void mssh_pref_init(MSSHPref* pref)
 {
 	GConfClient *client;
@@ -178,6 +215,12 @@ static void mssh_pref_init(MSSHPref* pref)
 		G_CALLBACK(mssh_pref_bg_colour_select), NULL);
 	g_signal_connect(G_OBJECT(columns_select), "value-changed",
 		G_CALLBACK(mssh_pref_columns_select), NULL);
+	g_signal_connect(G_OBJECT(timeout_select), "value-changed",
+		G_CALLBACK(mssh_pref_timeout_select), NULL);
+	g_signal_connect(G_OBJECT(close_check), "toggled",
+		G_CALLBACK(mssh_pref_close_check), NULL);
+	g_signal_connect(G_OBJECT(exit_check), "toggled",
+		G_CALLBACK(mssh_pref_exit_check), NULL);
 
 	client = gconf_client_get_default();
 
@@ -210,6 +253,24 @@ static void mssh_pref_init(MSSHPref* pref)
 	value = gconf_entry_get_value(entry);
 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(columns_select),
 		gconf_value_get_int(value));
+
+	entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_TIMEOUT, NULL,
+		TRUE, NULL);
+	value = gconf_entry_get_value(entry);
+	gtk_spin_button_set_value(GTK_SPIN_BUTTON(timeout_select),
+		gconf_value_get_int(value));
+
+	entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_CLOSE_ENDED,
+		NULL, TRUE, NULL);
+	value = gconf_entry_get_value(entry);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(close_check),
+		gconf_value_get_bool(value));
+
+	entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_QUIT_ALL_ENDED,
+			NULL, TRUE, NULL);
+	value = gconf_entry_get_value(entry);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(exit_check),
+		gconf_value_get_bool(value));
 }
 
 static void mssh_pref_class_init(MSSHPrefClass *klass)

+ 3 - 0
src/mssh-terminal.c

@@ -83,6 +83,7 @@ void mssh_terminal_send_data(MSSHTerminal *terminal, GdkEventKey *event)
 static void mssh_terminal_init(MSSHTerminal* terminal)
 {
 	terminal->started = 0;
+	terminal->ended = 0;
 
 	g_signal_connect(G_OBJECT(terminal), "child-exited",
 		G_CALLBACK(mssh_terminal_child_exited), terminal);
@@ -109,6 +110,8 @@ static void mssh_terminal_child_exited(VteTerminal *vte, gpointer data)
 
 	MSSHTerminal *terminal = MSSH_TERMINAL(data);
 
+	terminal->ended = 1;
+
 	vte_terminal_feed(vte, msg, strlen(msg));
 
 	g_signal_emit_by_name(terminal, "session-closed");

+ 1 - 0
src/mssh-terminal.h

@@ -22,6 +22,7 @@ typedef struct
 	GtkWidget *menu_item;
 	char *hostname;
 	int started;
+	int ended;
 } MSSHTerminal;
 
 typedef struct

+ 29 - 46
src/mssh-window.c

@@ -19,8 +19,6 @@ static gboolean mssh_window_key_press(GtkWidget *widget,
 static gboolean mssh_window_entry_focused(GtkWidget *widget,
 	GtkDirectionType dir, gpointer data);
 static gboolean mssh_window_session_close(gpointer data);
-static void mssh_window_session_closed(MSSHTerminal *terminal,
-	gpointer data);
 static void mssh_window_session_focused(MSSHTerminal *terminal,
 	gpointer data);
 static void mssh_window_insert(GtkWidget *widget, gchar *new_text,
@@ -57,37 +55,7 @@ static void mssh_window_sendhost(GtkWidget *widget, gpointer data)
 
 static void mssh_window_destroy(GtkWidget *widget, gpointer data)
 {
-	int i;
-
-	MSSHWindow *window = MSSH_WINDOW(data);
-
-	if(window->terminals->len > 0)
-	{
-		GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window),
-			GTK_DIALOG_DESTROY_WITH_PARENT,	GTK_MESSAGE_QUESTION,
-			GTK_BUTTONS_YES_NO, "%s, %s",
-			"You still have open sessions",
-			"are you sure you wish to quit?");
-
-		if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_YES)
-		{
-				for(i = 0; i < window->terminals->len; i++)
-				{
-					mssh_terminal_destroy(g_array_index(window->terminals,
-						MSSHTerminal*, i));
-				}
-
-				g_array_free(window->terminals, TRUE);
-
-				gtk_main_quit();
-		}
-
-		gtk_widget_destroy(dialog);
-	}
-	else
-	{
-		gtk_main_quit();
-	}
+	gtk_main_quit();
 }
 
 static void mssh_window_pref(GtkWidget *widget, gpointer data)
@@ -178,19 +146,28 @@ static gboolean mssh_window_session_close(gpointer data)
 		mssh_window_relayout(data_pair->window);
 	}
 
+	if(data_pair->window->terminals->len == 0 &&
+		data_pair->window->exit_on_all_closed)
+	{
+		mssh_window_destroy(NULL, (void*)data_pair->window);
+	}
+
 	free(data_pair);
 
 	return FALSE;
 }
 
-static void mssh_window_session_closed(MSSHTerminal *terminal,
-	gpointer data)
+void mssh_window_session_closed(MSSHTerminal *terminal, gpointer data)
 {
 	struct WinTermPair *data_pair = malloc(sizeof(struct WinTermPair));
 	data_pair->terminal = terminal;
 	data_pair->window = MSSH_WINDOW(data);
 
-	g_timeout_add_seconds(2, mssh_window_session_close, data_pair);
+	if(data_pair->window->close_ended_sessions)
+	{
+		g_timeout_add_seconds(data_pair->window->timeout,
+			mssh_window_session_close, data_pair);
+	}
 }
 
 static void mssh_window_session_focused(MSSHTerminal *terminal,
@@ -215,7 +192,9 @@ void mssh_window_relayout(MSSHWindow *window)
 {
 	GConfClient *client;
 	GConfEntry *entry;
-	int i, len = window->terminals->len, cols = window->columns;
+	int i, len = window->terminals->len;
+	int cols = (len < window->columns) ? len : window->columns;
+	int rows = (len + 0.5) / cols;
 
 	for(i = 0; i < len; i++)
 	{
@@ -244,8 +223,7 @@ void mssh_window_relayout(MSSHWindow *window)
 
 	if(len > 0)
 	{
-		gtk_table_resize(GTK_TABLE(window->table), ((len + 1) / cols),
-			cols);
+		gtk_table_resize(GTK_TABLE(window->table), rows, cols);
 	}
 
 	client = gconf_client_get_default();
@@ -284,7 +262,6 @@ 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();
 
@@ -300,8 +277,8 @@ static void mssh_window_init(MSSHWindow* window)
 		GTK_STOCK_QUIT, NULL);
 	GtkWidget *file_sendhost = gtk_image_menu_item_new_with_label(
 		"Send hostname");
-	GtkWidget *file_add = gtk_image_menu_item_new_with_label(
-		"Add session");
+/*	GtkWidget *file_add = gtk_image_menu_item_new_with_label(
+		"Add session");*/
 
 	GtkWidget *edit_pref = gtk_image_menu_item_new_from_stock(
 		GTK_STOCK_PREFERENCES, NULL);
@@ -315,7 +292,7 @@ static void mssh_window_init(MSSHWindow* window)
 	gtk_menu_item_set_submenu(GTK_MENU_ITEM(server_item),
 		window->server_menu);
 
-	gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_add);
+/*	gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_add);*/
 	gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_sendhost);
 	gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_quit);
 	gtk_menu_shell_append(GTK_MENU_SHELL(edit_menu), edit_pref);
@@ -325,9 +302,6 @@ static void mssh_window_init(MSSHWindow* window)
 		G_CALLBACK(mssh_window_destroy), window);
 	g_signal_connect(G_OBJECT(edit_pref), "activate",
 		G_CALLBACK(mssh_window_pref), window);
-	gtk_widget_add_accelerator(file_quit, "activate", accel_group,
-		GDK_W, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-	gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
 
 	gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), file_item);
 	gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), edit_item);
@@ -364,8 +338,17 @@ static void mssh_window_init(MSSHWindow* window)
 		mssh_gconf_notify_bg_colour, window, NULL, NULL);
 	gconf_client_notify_add(client, MSSH_GCONF_KEY_COLUMNS,
 		mssh_gconf_notify_columns, window, NULL, NULL);
+	gconf_client_notify_add(client, MSSH_GCONF_KEY_TIMEOUT,
+		mssh_gconf_notify_timeout, window, NULL, NULL);
+	gconf_client_notify_add(client, MSSH_GCONF_KEY_CLOSE_ENDED,
+		mssh_gconf_notify_close_ended, window, NULL, NULL);
+	gconf_client_notify_add(client, MSSH_GCONF_KEY_QUIT_ALL_ENDED,
+		mssh_gconf_notify_quit_all_ended, window, NULL, NULL);
 
 	gconf_client_notify(client, MSSH_GCONF_KEY_COLUMNS);
+	gconf_client_notify(client, MSSH_GCONF_KEY_TIMEOUT);
+	gconf_client_notify(client, MSSH_GCONF_KEY_CLOSE_ENDED);
+	gconf_client_notify(client, MSSH_GCONF_KEY_QUIT_ALL_ENDED);
 }
 
 void mssh_window_start_session(MSSHWindow* window, char **env, int nhosts,

+ 6 - 0
src/mssh-window.h

@@ -4,6 +4,8 @@
 #include <gtk/gtk.h>
 #include <vte/vte.h>
 
+#include "mssh-terminal.h"
+
 G_BEGIN_DECLS
 
 #define MSSH_TYPE_WINDOW			mssh_window_get_type()
@@ -24,6 +26,9 @@ typedef struct
 	GArray *terminals;
 	char **env;
 	int columns;
+	int timeout;
+	gboolean close_ended_sessions;
+	gboolean exit_on_all_closed;
 } MSSHWindow;
 
 typedef struct
@@ -37,6 +42,7 @@ GtkWidget* mssh_window_new(void);
 void mssh_window_start_session(MSSHWindow* window, char **env, int nhosts,
 	char **servers);
 void mssh_window_relayout(MSSHWindow *window);
+void mssh_window_session_closed(MSSHTerminal *terminal, gpointer data);
 
 G_END_DECLS