[gnome-games] gnect: Simplify preferences and stop using GamesFrame
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] gnect: Simplify preferences and stop using GamesFrame
- Date: Mon, 23 Jul 2012 02:29:15 +0000 (UTC)
commit 124b8cfd8a8af5fb7af383a8410aa658b2d29b41
Author: Robert Ancell <robert ancell canonical com>
Date: Mon Jul 23 14:28:59 2012 +1200
gnect: Simplify preferences and stop using GamesFrame
gnect/src/prefs.c | 209 +++++++++++++++++++++++------------------------------
1 files changed, 91 insertions(+), 118 deletions(-)
---
diff --git a/gnect/src/prefs.c b/gnect/src/prefs.c
index 04f669c..12a2c99 100644
--- a/gnect/src/prefs.c
+++ b/gnect/src/prefs.c
@@ -30,7 +30,6 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
-#include <libgames-support/games-frame.h>
#include <libgames-support/games-controls.h>
#include "main.h"
@@ -51,10 +50,8 @@ extern Theme theme[];
extern gint n_themes;
static GtkWidget *prefsbox = NULL;
-static GtkWidget *frame_player1;
-static GtkWidget *frame_player2;
-static GtkWidget *radio1[4];
-static GtkWidget *radio2[4];
+static GtkWidget *combobox1;
+static GtkWidget *combobox2;
static GtkWidget *combobox_theme;
static GtkWidget *checkbutton_animate;
static GtkWidget *checkbutton_sound;
@@ -78,25 +75,6 @@ sane_player_level (gint val)
}
static void
-prefsbox_update_player_labels (void)
-{
- /* Make player selection labels match the current theme */
-
- gchar *str;
-
- if (prefsbox == NULL)
- return;
-
- str = g_strdup_printf (_("Player One:\n%s"), _(theme_get_player (PLAYER1)));
- games_frame_set_label (GAMES_FRAME (frame_player1), str);
- g_free (str);
-
- str = g_strdup_printf (_("Player Two:\n%s"), _(theme_get_player (PLAYER2)));
- games_frame_set_label (GAMES_FRAME (frame_player2), str);
- g_free (str);
-}
-
-static void
settings_changed_cb (GSettings *settings,
const char *key,
gpointer user_data)
@@ -128,7 +106,6 @@ settings_changed_cb (GSettings *settings,
if (prefsbox == NULL)
return;
gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_theme), p.theme_id);
- prefsbox_update_player_labels ();
}
}
}
@@ -161,10 +138,15 @@ on_toggle_sound (GtkToggleButton * t, gpointer data)
static void
on_select_player1 (GtkWidget * w, gpointer data)
{
- if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)))
+ GtkTreeIter iter;
+ gint value;
+
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &iter))
return;
- p.level[PLAYER1] = GPOINTER_TO_INT (data);
- g_settings_set_int (settings, "player1", GPOINTER_TO_INT (data));
+ gtk_tree_model_get (GTK_TREE_MODEL (gtk_combo_box_get_model (GTK_COMBO_BOX (w))), &iter, 1, &value, -1);
+
+ p.level[PLAYER1] = value;
+ g_settings_set_int (settings, "player1", value);
scorebox_reset ();
who_starts = PLAYER2; /* This gets reversed in game_reset. */
game_reset ();
@@ -173,10 +155,15 @@ on_select_player1 (GtkWidget * w, gpointer data)
static void
on_select_player2 (GtkWidget * w, gpointer data)
{
- if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)))
+ GtkTreeIter iter;
+ gint value;
+
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &iter))
return;
- p.level[PLAYER2] = GPOINTER_TO_INT (data);
- g_settings_set_int (settings, "player2", GPOINTER_TO_INT (data));
+ gtk_tree_model_get (GTK_TREE_MODEL (gtk_combo_box_get_model (GTK_COMBO_BOX (w))), &iter, 1, &value, -1);
+
+ p.level[PLAYER2] = value;
+ g_settings_set_int (settings, "player2", value);
scorebox_reset ();
who_starts = PLAYER2; /* This gets reversed in game_reset. */
game_reset ();
@@ -201,36 +188,16 @@ prefs_init (void)
p.theme_id = sane_theme_id (p.theme_id);
}
-
-
-static const gchar *
-get_player_radio (LevelID id)
-{
- switch (id) {
- case LEVEL_HUMAN:
- return _("Human");
- case LEVEL_WEAK:
- return _("Level one");
- case LEVEL_MEDIUM:
- return _("Level two");
- case LEVEL_STRONG:
- return _("Level three");
- }
- return "";
-}
-
-
-
void
prefsbox_open (void)
{
GtkWidget *notebook;
- GtkWidget *frame;
- GtkWidget *hbox;
- GtkWidget *vbox1, *vbox2;
+ GtkWidget *grid;
GtkWidget *controls_list;
GtkWidget *label;
- GSList *group;
+ GtkCellRenderer *renderer;
+ GtkListStore *model;
+ GtkTreeIter iter;
gint i;
if (prefsbox != NULL) {
@@ -252,76 +219,94 @@ prefsbox_open (void)
notebook = gtk_notebook_new ();
gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (prefsbox))),
- notebook, TRUE, TRUE, 0);
-
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (prefsbox))), notebook, TRUE, TRUE, 0);
/* game tab */
- vbox1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
- gtk_container_set_border_width (GTK_CONTAINER (vbox1), 12);
- label = gtk_label_new (_("Game"));
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox1, label);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);
- gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
-
- frame_player1 = games_frame_new (NULL);
- gtk_box_pack_start (GTK_BOX (hbox), frame_player1, FALSE, FALSE, 0);
-
- vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add (GTK_CONTAINER (frame_player1), vbox2);
-
- group = NULL;
- for (i = 0; i < 4; i++) {
- radio1[i] = gtk_radio_button_new_with_label (group, get_player_radio (i));
- group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio1[i]));
- gtk_box_pack_start (GTK_BOX (vbox2), radio1[i], FALSE, FALSE, 0);
- }
-
- frame_player2 = games_frame_new (NULL);
- gtk_box_pack_start (GTK_BOX (hbox), frame_player2, FALSE, FALSE, 0);
-
- vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add (GTK_CONTAINER (frame_player2), vbox2);
+ grid = gtk_grid_new ();
+ gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
+ gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
+ gtk_container_set_border_width (GTK_CONTAINER (grid), 12);
- group = NULL;
- for (i = 0; i < 4; i++) {
- radio2[i] = gtk_radio_button_new_with_label (group, get_player_radio (i));
- group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio2[i]));
- gtk_box_pack_start (GTK_BOX (vbox2), radio2[i], FALSE, FALSE, 0);
- }
-
- frame = games_frame_new (_("Appearance"));
- gtk_box_pack_start (GTK_BOX (vbox1), frame, FALSE, FALSE, 0);
-
- vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 7);
- gtk_container_add (GTK_CONTAINER (frame), vbox2);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox, TRUE, TRUE, 0);
+ label = gtk_label_new (_("Game"));
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), grid, label);
+
+ label = gtk_label_new (_("Player One:"));
+ gtk_widget_set_hexpand (label, TRUE);
+ gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
+
+ combobox1 = gtk_combo_box_new ();
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox1), renderer, TRUE);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox1), renderer, "text", 0);
+ model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (combobox1), GTK_TREE_MODEL (model));
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, 0, _("Human"), 1, LEVEL_HUMAN, -1);
+ if (p.level[PLAYER1] == LEVEL_HUMAN)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox1), &iter);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, 0, _("Level one"), 1, LEVEL_WEAK, -1);
+ if (p.level[PLAYER1] == LEVEL_WEAK)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox1), &iter);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, 0, _("Level two"), 1, LEVEL_MEDIUM, -1);
+ if (p.level[PLAYER1] == LEVEL_MEDIUM)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox1), &iter);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, 0, _("Level three"), 1, LEVEL_STRONG, -1);
+ if (p.level[PLAYER1] == LEVEL_STRONG)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox1), &iter);
+ g_signal_connect (combobox1, "changed", G_CALLBACK (on_select_player1), NULL);
+ gtk_grid_attach (GTK_GRID (grid), combobox1, 1, 0, 1, 1);
+
+ label = gtk_label_new (_("Player Two:"));
+ gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
+
+ combobox2 = gtk_combo_box_new ();
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox2), renderer, TRUE);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox2), renderer, "text", 0);
+ model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (combobox2), GTK_TREE_MODEL (model));
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, 0, _("Human"), 1, LEVEL_HUMAN, -1);
+ if (p.level[PLAYER2] == LEVEL_HUMAN)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox2), &iter);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, 0, _("Level one"), 1, LEVEL_WEAK, -1);
+ if (p.level[PLAYER2] == LEVEL_WEAK)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox2), &iter);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, 0, _("Level two"), 1, LEVEL_MEDIUM, -1);
+ if (p.level[PLAYER2] == LEVEL_MEDIUM)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox2), &iter);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, 0, _("Level three"), 1, LEVEL_STRONG, -1);
+ if (p.level[PLAYER2] == LEVEL_STRONG)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox2), &iter);
+ g_signal_connect (combobox2, "changed", G_CALLBACK (on_select_player2), NULL);
+ gtk_grid_attach (GTK_GRID (grid), combobox2, 1, 1, 1, 1);
label = gtk_label_new_with_mnemonic (_("_Theme:"));
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
combobox_theme = gtk_combo_box_text_new ();
for (i = 0; i < n_themes; i++) {
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combobox_theme),
_(theme_get_title (i)));
}
-
- gtk_box_pack_start (GTK_BOX (hbox), combobox_theme, TRUE, TRUE, 0);
-
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combobox_theme);
+ gtk_grid_attach (GTK_GRID (grid), combobox_theme, 1, 2, 1, 1);
checkbutton_animate =
gtk_check_button_new_with_mnemonic (_("Enable _animation"));
- gtk_box_pack_start (GTK_BOX (vbox2), checkbutton_animate, FALSE, FALSE, 0);
+ gtk_grid_attach (GTK_GRID (grid), checkbutton_animate, 0, 3, 2, 1);
checkbutton_sound =
gtk_check_button_new_with_mnemonic (_("E_nable sounds"));
- gtk_box_pack_start (GTK_BOX (vbox2), checkbutton_sound, FALSE, FALSE, 0);
+ gtk_grid_attach (GTK_GRID (grid), checkbutton_sound, 0, 4, 2, 1);
/* keyboard tab */
@@ -338,11 +323,6 @@ prefsbox_open (void)
/* fill in initial values */
- prefsbox_update_player_labels ();
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio1[p.level[PLAYER1]]),
- TRUE);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio2[p.level[PLAYER2]]),
- TRUE);
gtk_combo_box_set_active (GTK_COMBO_BOX (combobox_theme), p.theme_id);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton_animate),
p.do_animate);
@@ -354,13 +334,6 @@ prefsbox_open (void)
g_signal_connect (prefsbox, "response", G_CALLBACK (on_dialog_close),
&prefsbox);
- for (i = 0; i < 4; i++) {
- g_signal_connect (G_OBJECT (radio1[i]), "toggled",
- G_CALLBACK (on_select_player1), GINT_TO_POINTER (i));
- g_signal_connect (G_OBJECT (radio2[i]), "toggled",
- G_CALLBACK (on_select_player2), GINT_TO_POINTER (i));
- }
-
g_signal_connect (G_OBJECT (combobox_theme), "changed",
G_CALLBACK (on_select_theme), NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]