mssh-pref.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. #include <gconf/gconf-client.h>
  2. #include "mssh-gconf.h"
  3. #include "mssh-pref.h"
  4. static void mssh_pref_init(MSSHPref* pref);
  5. static void mssh_pref_class_init(MSSHPrefClass *klass);
  6. G_DEFINE_TYPE(MSSHPref, mssh_pref, GTK_TYPE_WINDOW)
  7. GtkWidget* mssh_pref_new(void)
  8. {
  9. return g_object_new(MSSH_TYPE_PREF, NULL);
  10. }
  11. static void mssh_pref_close(GtkWidget *widget, gpointer data)
  12. {
  13. MSSHPref *pref = MSSH_PREF(data);
  14. gtk_widget_destroy(GTK_WIDGET(pref));
  15. }
  16. static void mssh_pref_font_select(GtkWidget *widget, gpointer data)
  17. {
  18. GConfClient *client;
  19. const gchar *font;
  20. client = gconf_client_get_default();
  21. font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget));
  22. gconf_client_set_string(client, MSSH_GCONF_KEY_FONT, font, NULL);
  23. }
  24. static void mssh_pref_fg_colour_select(GtkWidget *widget, gpointer data)
  25. {
  26. GConfClient *client;
  27. GdkColor colour;
  28. const gchar *colour_s;
  29. client = gconf_client_get_default();
  30. gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), &colour);
  31. colour_s = gdk_color_to_string(&colour);
  32. gconf_client_set_string(client, MSSH_GCONF_KEY_FG_COLOUR, colour_s,
  33. NULL);
  34. }
  35. static void mssh_pref_bg_colour_select(GtkWidget *widget, gpointer data)
  36. {
  37. GConfClient *client;
  38. GdkColor colour;
  39. const gchar *colour_s;
  40. client = gconf_client_get_default();
  41. gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), &colour);
  42. colour_s = gdk_color_to_string(&colour);
  43. gconf_client_set_string(client, MSSH_GCONF_KEY_BG_COLOUR, colour_s,
  44. NULL);
  45. }
  46. static void mssh_pref_columns_select(GtkWidget *widget, gpointer data)
  47. {
  48. GConfClient *client;
  49. int columns;
  50. client = gconf_client_get_default();
  51. columns = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
  52. gconf_client_set_int(client, MSSH_GCONF_KEY_COLUMNS, columns, NULL);
  53. }
  54. static void mssh_pref_timeout_select(GtkWidget *widget, gpointer data)
  55. {
  56. GConfClient *client;
  57. int timeout;
  58. client = gconf_client_get_default();
  59. timeout = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
  60. gconf_client_set_int(client, MSSH_GCONF_KEY_TIMEOUT, timeout, NULL);
  61. }
  62. static void mssh_pref_close_check(GtkWidget *widget, gpointer data)
  63. {
  64. GConfClient *client;
  65. gboolean close;
  66. client = gconf_client_get_default();
  67. close = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
  68. gconf_client_set_bool(client, MSSH_GCONF_KEY_CLOSE_ENDED, close, NULL);
  69. }
  70. static void mssh_pref_exit_check(GtkWidget *widget, gpointer data)
  71. {
  72. GConfClient *client;
  73. gboolean close;
  74. client = gconf_client_get_default();
  75. close = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
  76. gconf_client_set_bool(client, MSSH_GCONF_KEY_QUIT_ALL_ENDED, close,
  77. NULL);
  78. }
  79. static void mssh_pref_dir_focus_check(GtkWidget *widget, gpointer data)
  80. {
  81. GConfClient *client;
  82. gboolean focus;
  83. client = gconf_client_get_default();
  84. focus = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
  85. gconf_client_set_bool(client, MSSH_GCONF_KEY_DIR_FOCUS, focus, NULL);
  86. }
  87. static void mssh_pref_modifier_check(GtkWidget *widget, gpointer data)
  88. {
  89. GConfClient *client;
  90. gboolean ctrl, alt, shift, super;
  91. gint val;
  92. MSSHPref * pref = MSSH_PREF(data);
  93. client = gconf_client_get_default();
  94. ctrl = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref->ctrl));
  95. shift = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref->shift));
  96. alt = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref->alt));
  97. super = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref->super));
  98. val = (shift << 0) | (ctrl << 2) | (alt << 3) | (super << 26);
  99. gconf_client_set_int(client, MSSH_GCONF_KEY_MODIFIER, val, NULL);
  100. }
  101. static void mssh_pref_init(MSSHPref* pref)
  102. {
  103. GConfClient *client;
  104. GConfEntry *entry;
  105. GConfValue *value;
  106. GdkVisual *visual = gdk_visual_get_system();
  107. GdkColormap *colour_map = gdk_colormap_new(visual, TRUE);
  108. GdkColor colour;
  109. const gchar *colour_s;
  110. GtkWidget *frame = gtk_vbox_new(FALSE, 5);
  111. GtkWidget *notebook = gtk_notebook_new();
  112. GtkWidget *content = gtk_vbox_new(FALSE, 4);
  113. GtkWidget *font_hbox = gtk_hbox_new(FALSE, 10);
  114. GtkWidget *font_label = gtk_label_new("Font:");
  115. GtkWidget *font_select = gtk_font_button_new();
  116. GtkWidget *colour_table = gtk_table_new(2, 2, FALSE);
  117. GtkWidget *bg_colour_label = gtk_label_new("Background:");
  118. GtkWidget *bg_colour_select = gtk_color_button_new();
  119. GtkWidget *fg_colour_label = gtk_label_new("Foreground:");
  120. GtkWidget *fg_colour_select = gtk_color_button_new();
  121. GtkWidget *exit_check = gtk_check_button_new_with_label(
  122. "Quit after all sessions have ended");
  123. GtkWidget *close_check = gtk_check_button_new_with_label(
  124. "Close ended sessions");
  125. GtkWidget *timeout_hbox = gtk_hbox_new(FALSE, 10);
  126. GtkWidget *timeout_label1 = gtk_label_new(
  127. "Closed ended sessions after");
  128. GtkObject *timeout_adj = gtk_adjustment_new(3, 0, 100, 1, 10, 0);
  129. GtkWidget *timeout_select = gtk_spin_button_new(
  130. GTK_ADJUSTMENT(timeout_adj), 1, 0);
  131. GtkWidget *timeout_label2 = gtk_label_new("seconds");
  132. GtkWidget *columns_hbox = gtk_hbox_new(FALSE, 10);
  133. GtkWidget *columns_label = gtk_label_new("Columns:");
  134. GtkObject *columns_adj = gtk_adjustment_new(2, 1, 10, 1, 10, 0);
  135. GtkWidget *columns_select = gtk_spin_button_new(
  136. GTK_ADJUSTMENT(columns_adj), 1, 0);
  137. GtkWidget *mod_hbox = gtk_hbox_new(FALSE, 10);
  138. GtkWidget *mod_label = gtk_label_new("Modifier:");
  139. GtkWidget *mod_ctrl_check = gtk_check_button_new_with_label("Ctrl");
  140. GtkWidget *mod_alt_check = gtk_check_button_new_with_label("Alt");
  141. GtkWidget *mod_shift_check = gtk_check_button_new_with_label("Shift");
  142. GtkWidget *mod_super_check = gtk_check_button_new_with_label("Super");
  143. GtkWidget *close_hbox = gtk_hbox_new(FALSE, 0);
  144. GtkWidget *close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
  145. GtkWidget *dir_focus_check = gtk_check_button_new_with_label(
  146. "Use directional focus");
  147. pref->ctrl = mod_ctrl_check;
  148. pref->shift = mod_shift_check;
  149. pref->alt = mod_alt_check;
  150. pref->super = mod_super_check;
  151. gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
  152. gtk_notebook_append_page(GTK_NOTEBOOK(notebook), content, NULL);
  153. gtk_box_pack_start(GTK_BOX(font_hbox), font_label, FALSE, TRUE, 0);
  154. gtk_box_pack_start(GTK_BOX(font_hbox), font_select, FALSE, TRUE, 0);
  155. gtk_box_pack_start(GTK_BOX(content), font_hbox, FALSE, TRUE, 0);
  156. gtk_table_attach(GTK_TABLE(colour_table), bg_colour_label,
  157. 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
  158. gtk_table_attach(GTK_TABLE(colour_table), bg_colour_select,
  159. 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
  160. gtk_table_attach(GTK_TABLE(colour_table), fg_colour_label,
  161. 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
  162. gtk_table_attach(GTK_TABLE(colour_table), fg_colour_select,
  163. 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
  164. gtk_box_pack_start(GTK_BOX(content), colour_table, FALSE, TRUE, 0);
  165. gtk_box_pack_start(GTK_BOX(content), exit_check, FALSE, TRUE, 0);
  166. gtk_box_pack_start(GTK_BOX(content), close_check, FALSE, TRUE, 0);
  167. gtk_box_pack_start(GTK_BOX(content), dir_focus_check, FALSE, TRUE, 0);
  168. gtk_box_pack_start(GTK_BOX(timeout_hbox), timeout_label1, FALSE,
  169. TRUE, 0);
  170. gtk_box_pack_start(GTK_BOX(timeout_hbox), timeout_select, FALSE,
  171. TRUE, 0);
  172. gtk_box_pack_start(GTK_BOX(timeout_hbox), timeout_label2, FALSE,
  173. TRUE, 0);
  174. gtk_box_pack_start(GTK_BOX(content), timeout_hbox, FALSE, TRUE, 0);
  175. gtk_box_pack_start(GTK_BOX(columns_hbox), columns_label, FALSE,
  176. TRUE, 0);
  177. gtk_box_pack_start(GTK_BOX(columns_hbox), columns_select, FALSE,
  178. TRUE, 0);
  179. gtk_box_pack_start(GTK_BOX(content), columns_hbox, FALSE, TRUE, 0);
  180. gtk_box_pack_start(GTK_BOX(mod_hbox), mod_label, FALSE, TRUE, 0);
  181. gtk_box_pack_start(GTK_BOX(mod_hbox), mod_ctrl_check, FALSE, TRUE, 0);
  182. gtk_box_pack_start(GTK_BOX(mod_hbox), mod_alt_check, FALSE, TRUE, 0);
  183. gtk_box_pack_start(GTK_BOX(mod_hbox), mod_shift_check, FALSE, TRUE, 0);
  184. gtk_box_pack_start(GTK_BOX(mod_hbox), mod_super_check, FALSE, TRUE, 0);
  185. gtk_box_pack_start(GTK_BOX(content), mod_hbox, FALSE, TRUE, 0);
  186. gtk_box_pack_end(GTK_BOX(close_hbox), close_button, FALSE, TRUE, 0);
  187. gtk_box_pack_start(GTK_BOX(frame), notebook, TRUE, TRUE, 0);
  188. gtk_box_pack_start(GTK_BOX(frame), close_hbox, FALSE, TRUE, 0);
  189. gtk_container_add(GTK_CONTAINER(pref), frame);
  190. g_signal_connect(G_OBJECT(close_button), "clicked",
  191. G_CALLBACK(mssh_pref_close), pref);
  192. gtk_container_set_border_width(GTK_CONTAINER(content), 6);
  193. gtk_container_set_border_width(GTK_CONTAINER(pref), 15);
  194. gtk_window_set_title(GTK_WINDOW(pref), "Preferences");
  195. gtk_window_set_resizable(GTK_WINDOW(pref), FALSE);
  196. g_signal_connect(G_OBJECT(font_select), "font-set",
  197. G_CALLBACK(mssh_pref_font_select), NULL);
  198. g_signal_connect(G_OBJECT(fg_colour_select), "color-set",
  199. G_CALLBACK(mssh_pref_fg_colour_select), NULL);
  200. g_signal_connect(G_OBJECT(bg_colour_select), "color-set",
  201. G_CALLBACK(mssh_pref_bg_colour_select), NULL);
  202. g_signal_connect(G_OBJECT(columns_select), "value-changed",
  203. G_CALLBACK(mssh_pref_columns_select), NULL);
  204. g_signal_connect(G_OBJECT(timeout_select), "value-changed",
  205. G_CALLBACK(mssh_pref_timeout_select), NULL);
  206. g_signal_connect(G_OBJECT(close_check), "toggled",
  207. G_CALLBACK(mssh_pref_close_check), NULL);
  208. g_signal_connect(G_OBJECT(exit_check), "toggled",
  209. G_CALLBACK(mssh_pref_exit_check), NULL);
  210. g_signal_connect(G_OBJECT(dir_focus_check), "toggled",
  211. G_CALLBACK(mssh_pref_dir_focus_check), NULL);
  212. g_signal_connect(G_OBJECT(mod_ctrl_check), "toggled",
  213. G_CALLBACK(mssh_pref_modifier_check), pref);
  214. g_signal_connect(G_OBJECT(mod_alt_check), "toggled",
  215. G_CALLBACK(mssh_pref_modifier_check), pref);
  216. g_signal_connect(G_OBJECT(mod_shift_check), "toggled",
  217. G_CALLBACK(mssh_pref_modifier_check), pref);
  218. g_signal_connect(G_OBJECT(mod_super_check), "toggled",
  219. G_CALLBACK(mssh_pref_modifier_check), pref);
  220. client = gconf_client_get_default();
  221. entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_FONT, NULL,
  222. TRUE, NULL);
  223. value = gconf_entry_get_value(entry);
  224. gtk_font_button_set_font_name(GTK_FONT_BUTTON(font_select),
  225. gconf_value_get_string(value));
  226. entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_FG_COLOUR, NULL,
  227. TRUE, NULL);
  228. value = gconf_entry_get_value(entry);
  229. colour_s = gconf_value_get_string(value);
  230. gdk_colormap_alloc_color(colour_map, &colour, TRUE, TRUE);
  231. gdk_color_parse(colour_s, &colour);
  232. gtk_color_button_set_color(GTK_COLOR_BUTTON(fg_colour_select),
  233. &colour);
  234. entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_BG_COLOUR, NULL,
  235. TRUE, NULL);
  236. value = gconf_entry_get_value(entry);
  237. colour_s = gconf_value_get_string(value);
  238. gdk_colormap_alloc_color(colour_map, &colour, TRUE, TRUE);
  239. gdk_color_parse(colour_s, &colour);
  240. gtk_color_button_set_color(GTK_COLOR_BUTTON(bg_colour_select),
  241. &colour);
  242. entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_COLUMNS, NULL,
  243. TRUE, NULL);
  244. value = gconf_entry_get_value(entry);
  245. gtk_spin_button_set_value(GTK_SPIN_BUTTON(columns_select),
  246. gconf_value_get_int(value));
  247. entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_TIMEOUT, NULL,
  248. TRUE, NULL);
  249. value = gconf_entry_get_value(entry);
  250. gtk_spin_button_set_value(GTK_SPIN_BUTTON(timeout_select),
  251. gconf_value_get_int(value));
  252. entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_CLOSE_ENDED,
  253. NULL, TRUE, NULL);
  254. value = gconf_entry_get_value(entry);
  255. gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(close_check),
  256. gconf_value_get_bool(value));
  257. entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_QUIT_ALL_ENDED,
  258. NULL, TRUE, NULL);
  259. value = gconf_entry_get_value(entry);
  260. gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(exit_check),
  261. gconf_value_get_bool(value));
  262. entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_DIR_FOCUS,
  263. NULL, TRUE, NULL);
  264. value = gconf_entry_get_value(entry);
  265. gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dir_focus_check),
  266. gconf_value_get_bool(value));
  267. entry = gconf_client_get_entry(client, MSSH_GCONF_KEY_MODIFIER,
  268. NULL, TRUE, NULL);
  269. value = gconf_entry_get_value(entry);
  270. gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mod_ctrl_check),
  271. (gconf_value_get_int(value) & GDK_CONTROL_MASK) ? 1 : 0);
  272. gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mod_shift_check),
  273. (gconf_value_get_int(value) & GDK_SHIFT_MASK) ? 1 : 0);
  274. gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mod_alt_check),
  275. (gconf_value_get_int(value) & GDK_MOD1_MASK) ? 1 : 0);
  276. gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mod_super_check),
  277. (gconf_value_get_int(value) & GDK_SUPER_MASK) ? 1 : 0);
  278. }
  279. static void mssh_pref_class_init(MSSHPrefClass *klass)
  280. {
  281. }