Procházet zdrojové kódy

Add preferences dialog.

Signed-off-by: Bradley Smith <[email protected]>
Bradley Smith před 15 roky
rodič
revize
e623bcde2d
4 změnil soubory, kde provedl 171 přidání a 2 odebrání
  1. 1 1
      src/Makefile.am
  2. 110 0
      src/mssh-pref.c
  3. 34 0
      src/mssh-pref.h
  4. 26 1
      src/mssh-window.c

+ 1 - 1
src/Makefile.am

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

+ 110 - 0
src/mssh-pref.c

@@ -0,0 +1,110 @@
+#include "mssh-pref.h"
+
+static void mssh_pref_init(MSSHPref* pref);
+static void mssh_pref_class_init(MSSHPrefClass *klass);
+
+G_DEFINE_TYPE(MSSHPref, mssh_pref, GTK_TYPE_WINDOW)
+
+GtkWidget* mssh_pref_new(void)
+{
+	return g_object_new(MSSH_TYPE_PREF, NULL);
+}
+
+static void mssh_pref_close(GtkWidget *widget, gpointer data)
+{
+	MSSHPref *pref = MSSH_PREF(data);
+
+	gtk_widget_destroy(GTK_WIDGET(pref));
+}
+
+static void mssh_pref_init(MSSHPref* pref)
+{
+	GtkWidget *frame = gtk_vbox_new(FALSE, 5);
+	GtkWidget *notebook = gtk_notebook_new();
+	GtkWidget *content = gtk_vbox_new(FALSE, 4);
+
+	GtkWidget *font_hbox = gtk_hbox_new(FALSE, 10);
+	GtkWidget *font_label = gtk_label_new("Font:");
+	GtkWidget *font_select = gtk_font_button_new();
+
+	GtkWidget *colour_table = gtk_table_new(2, 2, FALSE);
+	GtkWidget *bg_colour_label = gtk_label_new("Background:");
+	GtkWidget *bg_colour_select = gtk_color_button_new();
+	GtkWidget *fg_colour_label = gtk_label_new("Forground:");
+	GtkWidget *fg_colour_select = gtk_color_button_new();
+
+	GtkWidget *exit_check = gtk_check_button_new_with_label(
+		"Enable Ctrl+W quit shortcut");
+	GtkWidget *close_check = gtk_check_button_new_with_label(
+		"Close ended sessions");
+
+	GtkWidget *timeout_hbox = gtk_hbox_new(FALSE, 10);
+	GtkWidget *timeout_label1 = gtk_label_new(
+		"Closed ended sessions after");
+	GtkObject *timeout_adj = gtk_adjustment_new(3, 0, 100, 1, 10, 0);
+	GtkWidget *timeout_select = gtk_spin_button_new(
+		GTK_ADJUSTMENT(timeout_adj), 1, 0);
+	GtkWidget *timeout_label2 = gtk_label_new("seconds");
+
+	GtkWidget *columns_hbox = gtk_hbox_new(FALSE, 10);
+	GtkWidget *columns_label = gtk_label_new("Columns:");
+	GtkObject *columns_adj = gtk_adjustment_new(2, 1, 10, 1, 10, 0);
+	GtkWidget *columns_select = gtk_spin_button_new(
+		GTK_ADJUSTMENT(columns_adj), 1, 0);
+
+	GtkWidget *close_hbox = gtk_hbox_new(FALSE, 0);
+	GtkWidget *close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
+
+	gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
+	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), content, NULL);
+
+	gtk_box_pack_start(GTK_BOX(font_hbox), font_label, FALSE, TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(font_hbox), font_select, FALSE, TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(content), font_hbox, FALSE, TRUE, 0);
+
+	gtk_table_attach(GTK_TABLE(colour_table), bg_colour_label,
+		0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach(GTK_TABLE(colour_table), bg_colour_select,
+		1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach(GTK_TABLE(colour_table), fg_colour_label,
+		0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_table_attach(GTK_TABLE(colour_table), fg_colour_select,
+		1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
+	gtk_box_pack_start(GTK_BOX(content), colour_table, FALSE, TRUE, 0);
+
+	gtk_box_pack_start(GTK_BOX(content), exit_check, FALSE, TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(content), close_check, FALSE, TRUE, 0);
+
+	gtk_box_pack_start(GTK_BOX(timeout_hbox), timeout_label1, FALSE,
+		TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(timeout_hbox), timeout_select, FALSE,
+		TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(timeout_hbox), timeout_label2, FALSE,
+		TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(content), timeout_hbox, FALSE, TRUE, 0);
+
+	gtk_box_pack_start(GTK_BOX(columns_hbox), columns_label, FALSE,
+		TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(columns_hbox), columns_select, FALSE,
+		TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(content), columns_hbox, FALSE, TRUE, 0);
+
+	gtk_box_pack_end(GTK_BOX(close_hbox), close_button, FALSE, TRUE, 0);
+
+	gtk_box_pack_start(GTK_BOX(frame), notebook, TRUE, TRUE, 0);
+	gtk_box_pack_start(GTK_BOX(frame), close_hbox, FALSE, TRUE, 0);
+
+	gtk_container_add(GTK_CONTAINER(pref), frame);
+
+	g_signal_connect(G_OBJECT(close_button), "clicked",
+		G_CALLBACK(mssh_pref_close), pref);
+
+	gtk_container_set_border_width(GTK_CONTAINER(content), 6);
+	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);
+}
+
+static void mssh_pref_class_init(MSSHPrefClass *klass)
+{
+}

+ 34 - 0
src/mssh-pref.h

@@ -0,0 +1,34 @@
+#ifndef __MSSH_PREF_H__
+#define __MSSH_PREF_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define MSSH_TYPE_PREF				mssh_pref_get_type()
+#define MSSH_PREF(obj)				G_TYPE_CHECK_INSTANCE_CAST(obj,\
+	MSSH_TYPE_PREF, MSSHPref)
+#define MSSH_PREF_CLASS(klass)		G_TYPE_CHECK_CLASS_CAST(klass,\
+	MSSH_PREF_TYPE, MSSHPrefClass)
+#define IS_MSSH_PREF(obj)			G_TYPE_CHECK_INSTANCE_TYPE(obj,\
+	MSSH_TYPE_PREF)
+#define IS_MSSH_PREF_CLASS(klass) G_TYPE_CHECK_CLASS_TYPE(klass,\
+	MSSH_TYPE_PREF)
+
+typedef struct
+{
+	GtkWindow widget;
+} MSSHPref;
+
+typedef struct
+{
+	GtkWindowClass parent_class;
+} MSSHPrefClass;
+
+GType mssh_pref_get_type(void) G_GNUC_CONST;
+
+GtkWidget* mssh_pref_new(void);
+
+G_END_DECLS
+
+#endif /* __MSSH_PREF_H__ */

+ 26 - 1
src/mssh-window.c

@@ -4,12 +4,14 @@
 #include <gdk/gdkkeysyms.h>
 
 #include "mssh-terminal.h"
+#include "mssh-pref.h"
 #include "mssh-window.h"
 
 #include "config.h"
 
 static void mssh_window_sendhost(GtkWidget *widget, gpointer data);
 static void mssh_window_destroy(GtkWidget *widget, gpointer data);
+static void mssh_window_pref(GtkWidget *widget, gpointer data);
 static gboolean mssh_window_key_press(GtkWidget *widget,
 	GdkEventKey *event, gpointer data);
 static gboolean mssh_window_entry_focused(GtkWidget *widget,
@@ -81,6 +83,19 @@ static void mssh_window_destroy(GtkWidget *widget, gpointer data)
 	}
 }
 
+static void mssh_window_pref(GtkWidget *widget, gpointer data)
+{
+	MSSHWindow *window = MSSH_WINDOW(data);
+	GtkWidget *pref = mssh_pref_new();
+
+	gtk_window_set_transient_for(GTK_WINDOW(pref), GTK_WINDOW(window));
+	gtk_window_set_modal(GTK_WINDOW(pref), TRUE);
+	gtk_window_set_position(GTK_WINDOW(pref),
+		GTK_WIN_POS_CENTER_ON_PARENT);
+
+	gtk_widget_show_all(pref);
+}
+
 static gboolean mssh_window_key_press(GtkWidget *widget,
 	GdkEventKey *event, gpointer data)
 {
@@ -221,32 +236,42 @@ static void mssh_window_init(MSSHWindow* window)
 
 	GtkWidget *menu_bar = gtk_menu_bar_new();
 	GtkWidget *file_menu = gtk_menu_new();
+	GtkWidget *edit_menu = gtk_menu_new();
 
-	GtkWidget *server_item = gtk_menu_item_new_with_label("Servers");
 	GtkWidget *file_item = gtk_menu_item_new_with_label("File");
+	GtkWidget *edit_item = gtk_menu_item_new_with_label("Edit");
+	GtkWidget *server_item = gtk_menu_item_new_with_label("Servers");
 
 	GtkWidget *file_quit = gtk_image_menu_item_new_from_stock(
 		GTK_STOCK_QUIT, NULL);
 	GtkWidget *file_sendhost = gtk_image_menu_item_new_with_label(
 		"Send hostname");
 
+	GtkWidget *edit_pref = gtk_image_menu_item_new_from_stock(
+		GTK_STOCK_PREFERENCES, NULL);
+
 	window->server_menu = gtk_menu_new();
 
 	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),
 		window->server_menu);
 
 	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);
 	g_signal_connect(G_OBJECT(file_sendhost), "activate",
 		G_CALLBACK(mssh_window_sendhost), window);
 	g_signal_connect(G_OBJECT(file_quit), "activate",
 		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);
 	gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), server_item);
 
 	g_signal_connect(G_OBJECT(entry), "key-press-event",