[gnome-games] glines: Move main window to .ui file
- From: Thomas Hindoe Paaboel Andersen <thomashpa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] glines: Move main window to .ui file
- Date: Thu, 6 Oct 2011 22:12:56 +0000 (UTC)
commit df5f7ec096dcc5ebf1def21a3cd17da60e7fe487
Author: Thomas Hindoe Paaboel Andersen <phomes gmail com>
Date: Fri Oct 7 00:12:46 2011 +0200
glines: Move main window to .ui file
glines/Makefile.am | 2 +
glines/data/Makefile.am | 1 +
glines/data/glines.ui | 261 +++++++++++++++++++++++++++++++++++++++++++++++
glines/glines.c | 172 +++++--------------------------
glines/glines.h | 10 ++
po/POTFILES.in | 1 +
6 files changed, 300 insertions(+), 147 deletions(-)
---
diff --git a/glines/Makefile.am b/glines/Makefile.am
index 8c37f43..be65cbb 100644
--- a/glines/Makefile.am
+++ b/glines/Makefile.am
@@ -24,11 +24,13 @@ glines_CPPFLAGS = \
$(AM_CPPFLAGS)
glines_CFLAGS = \
+ $(GMODULE_CFLAGS) \
$(GTK_CFLAGS) \
$(AM_CFLAGS)
glines_LDADD = \
$(top_builddir)/libgames-support/libgames-support.la \
+ $(GMODULE_LIBS) \
$(GTK_LIBS) \
$(INTLLIBS) \
-lm \
diff --git a/glines/data/Makefile.am b/glines/data/Makefile.am
index de8730c..547b780 100644
--- a/glines/data/Makefile.am
+++ b/glines/data/Makefile.am
@@ -1,5 +1,6 @@
uidir = $(pkgdatadir)/glines/
ui_DATA = \
+ glines.ui \
glines-preferences.ui
EXTRA_DIST = $(ui_DATA)
diff --git a/glines/data/glines.ui b/glines/data/glines.ui
new file mode 100644
index 0000000..4874e9a
--- /dev/null
+++ b/glines/data/glines.ui
@@ -0,0 +1,261 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkAccelGroup" id="accelgroup"/>
+ <object class="GtkWindow" id="glines_window">
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">Five or more</property>
+ <property name="default_width">320</property>
+ <property name="default_height">400</property>
+ <property name="icon_name">accessories-calculator</property>
+ <accel-groups>
+ <group name="accelgroup"/>
+ </accel-groups>
+ <child>
+ <object class="GtkBox" id="vbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkMenuBar" id="menubar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkMenuItem" id="game_menu_item">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">_Game</property>
+ <property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu" id="menu1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImageMenuItem" id="game_new_menuitem">
+ <property name="label">gtk-new</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <property name="accel_group">accelgroup</property>
+ <accelerator key="N" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+ <signal name="activate" handler="game_new_callback" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="scores_menuitem">
+ <property name="label">Scores</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="image">image1</property>
+ <property name="use_stock">False</property>
+ <property name="accel_group">accelgroup</property>
+ <signal name="activate" handler="game_top_ten_callback" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="separatormenuitem2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="quit_menuitem">
+ <property name="label">gtk-quit</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <property name="accel_group">accelgroup</property>
+ <accelerator key="Q" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+ <signal name="activate" handler="game_quit_callback" swapped="no"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="settings_menu_item">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">_Settings</property>
+ <property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu" id="menu2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImageMenuItem" id="fullscreen_menuitem">
+ <property name="label">gtk-fullscreen</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <property name="accel_group">accelgroup</property>
+ <accelerator key="F11" signal="activate"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="preferences_menuitem">
+ <property name="label">gtk-preferences</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <property name="accel_group">accelgroup</property>
+ <signal name="activate" handler="game_props_callback" swapped="no"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="help_menu_item">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">_Help</property>
+ <property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu" id="menu3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImageMenuItem" id="help_item">
+ <property name="label" translatable="yes" comments="Help contents menu item">_Contents</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">False</property>
+ <property name="accel_group">accelgroup</property>
+ <accelerator key="F1" signal="activate"/>
+ <signal name="activate" handler="game_help_callback" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="about_menuitem">
+ <property name="label">gtk-about</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <property name="accel_group">accelgroup</property>
+ <signal name="activate" handler="game_about_callback" swapped="no"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="top_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="labelNext">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xpad">6</property>
+ <property name="label" translatable="yes">Next:</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkLabel" id="scorelabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xpad">6</property>
+ <property name="label" translatable="yes">0</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="labelScore">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Score:</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkStatusbar" id="statusbar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-missing-image</property>
+ </object>
+</interface>
diff --git a/glines/glines.c b/glines/glines.c
index c9fbe89..89a4091 100644
--- a/glines/glines.c
+++ b/glines/glines.c
@@ -36,7 +36,6 @@
#include <gdk/gdkkeysyms.h>
#include <libgames-support/games-files.h>
-#include <libgames-support/games-frame.h>
#include <libgames-support/games-gridframe.h>
#include <libgames-support/games-help.h>
#include <libgames-support/games-preimage.h>
@@ -45,7 +44,6 @@
#include <libgames-support/games-scores-dialog.h>
#include <libgames-support/games-settings.h>
#include <libgames-support/games-stock.h>
-#include <libgames-support/games-fullscreen-action.h>
#ifdef WITH_SMCLIENT
#include <libgames-support/eggsmclient.h>
@@ -91,6 +89,7 @@ static const GamesScoresCategory scorecats[] = {
static GamesScores *highscores;
static GSettings *settings;
+static GtkBuilder *builder;
static GtkBuilder *builder_preferences;
static gint hfieldsize;
@@ -105,15 +104,6 @@ static GRand *rgen;
static GtkWidget *draw_area;
static GtkWidget *app, *statusbar, *pref_dialog, *gridframe;
static GtkWidget *preview_widgets[MAXNPIECES];
-static GtkWidget *menubar;
-static GtkWidget *scoreitem;
-static GtkAction *fullscreen_action;
-
-/* These keep track of what we put in the main table so we
- * can reshuffle them when we change the field size. */
-static GtkWidget *table;
-static GtkWidget *top_pane;
-static GtkWidget *bottom_pane;
static field_props field[MAXFIELDSIZE * MAXFIELDSIZE];
@@ -140,10 +130,6 @@ static gboolean show_cursor = FALSE;
static int boxsize;
-/* The width and height of the main window. */
-#define DEFAULT_WIDTH 320
-#define DEFAULT_HEIGHT 400
-
static int preview_height = 0;
static int preview_width = 0;
@@ -237,25 +223,6 @@ load_image (gchar * fname)
return preimage;
}
-/* The main table has to be layed out differently depending on the
- size of the playing area we choose. Otherwise the preview window
- gets too large. */
-static void
-relay_table (void)
-{
- gint height;
- GValue value = { 0 };
-
- height = 1 + vfieldsize;
- g_value_init (&value, G_TYPE_INT);
- g_value_set_int (&value, height);
-
- gtk_container_child_set_property (GTK_CONTAINER (table),
- bottom_pane, "bottom_attach", &value);
-
- gtk_table_resize (GTK_TABLE (table), vfieldsize + 1, 1);
-}
-
static void
refresh_pixmaps (void)
{
@@ -493,7 +460,7 @@ draw_preview (void)
}
}
-static void
+void
game_new_callback (void)
{
reset_game ();
@@ -1189,13 +1156,13 @@ animate (gpointer gp)
return TRUE;
}
-static void
+void
game_top_ten_callback (GtkAction * action, gpointer data)
{
show_scores (0, FALSE);
}
-static void
+void
game_about_callback (GtkAction * action, gpointer * data)
{
const gchar *authors[] = { "Robert Szokovacs <szo appaloosacorp hu>",
@@ -1308,7 +1275,6 @@ conf_value_changed_cb (GSettings *settings, gchar *key)
if (size_tmp != game_size) {
set_sizes (size_tmp);
- relay_table ();
reset_game ();
start_game ();
}
@@ -1374,7 +1340,7 @@ set_fast_moves_callback (GtkWidget * widget, gpointer * data)
g_settings_set_int (settings, KEY_MOVE_TIMEOUT, timeout);
}
-static void
+void
pref_dialog_response (GtkDialog * dialog, gint response, gpointer data)
{
gtk_widget_hide (GTK_WIDGET (dialog));
@@ -1447,7 +1413,7 @@ game_props_callback (void)
gtk_window_present (GTK_WINDOW (pref_dialog));
}
-static int
+int
game_quit_callback (GtkAction * action, gpointer data)
{
if (animate_id)
@@ -1456,7 +1422,7 @@ game_quit_callback (GtkAction * action, gpointer data)
return FALSE;
}
-static void
+void
game_help_callback (GtkAction * action, gpointer data)
{
games_help_display (app, "glines", NULL);
@@ -1593,65 +1559,6 @@ load_properties (void)
load_theme ();
}
-static const GtkActionEntry actions[] = {
- {"GameMenu", NULL, N_("_Game")},
- {"SettingsMenu", NULL, N_("_Settings")},
- {"HelpMenu", NULL, N_("_Help")},
- {"NewGame", GAMES_STOCK_NEW_GAME, NULL, NULL, NULL,
- G_CALLBACK (game_new_callback)},
- {"Scores", GAMES_STOCK_SCORES, NULL, NULL, NULL,
- G_CALLBACK (game_top_ten_callback)},
- {"Quit", GTK_STOCK_QUIT, NULL, NULL, NULL, G_CALLBACK (game_quit_callback)},
- {"Preferences", GTK_STOCK_PREFERENCES, NULL, NULL, NULL,
- G_CALLBACK (game_props_callback)},
- {"Contents", GAMES_STOCK_CONTENTS, NULL, NULL, NULL,
- G_CALLBACK (game_help_callback)},
- {"About", GTK_STOCK_ABOUT, NULL, NULL, NULL,
- G_CALLBACK (game_about_callback)},
-};
-
-const char ui_description[] =
- "<ui>"
- " <menubar name='MainMenu'>"
- " <menu action='GameMenu'>"
- " <menuitem action='NewGame'/>"
- " <separator/>"
- " <menuitem action='Scores'/>"
- " <separator/>"
- " <menuitem action='Quit'/>"
- " </menu>"
- " <menu action='SettingsMenu'>"
- " <menuitem action='Fullscreen'/>"
- " <menuitem action='Preferences'/>"
- " </menu>"
- " <menu action='HelpMenu'>"
- " <menuitem action='Contents'/>"
- " <menuitem action='About'/>" " </menu>" " </menubar>" "</ui>";
-
-static void
-create_menus (GtkUIManager * ui_manager)
-{
- GtkAccelGroup *accel_group;
- GtkActionGroup *action_group;
-
- action_group = gtk_action_group_new ("MenuActions");
- gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
- gtk_action_group_add_actions (action_group, actions,
- G_N_ELEMENTS (actions), NULL);
-
- fullscreen_action = GTK_ACTION (games_fullscreen_action_new ("Fullscreen", GTK_WINDOW (app)));
- gtk_action_group_add_action_with_accel (action_group, fullscreen_action, NULL);
-
- gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
- gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, NULL);
- accel_group = gtk_ui_manager_get_accel_group (ui_manager);
- gtk_window_add_accel_group (GTK_WINDOW (app), accel_group);
-
- scoreitem = gtk_ui_manager_get_widget (ui_manager,
- "/MainMenu/GameMenu/Scores");
- menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu");
-}
-
static void
init_config (void)
{
@@ -1670,11 +1577,9 @@ int
main (int argc, char *argv[])
{
GOptionContext *context;
- char *label_text;
- GtkWidget *label;
+ gchar *ui_path;
GtkWidget *vbox, *hbox;
GtkWidget *preview_hbox;
- GtkUIManager *ui_manager;
guint i;
gboolean retval;
GError *error = NULL;
@@ -1736,41 +1641,21 @@ main (int argc, char *argv[])
reset_game ();
#endif /* WITH_SMCLIENT */
- app = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
- gtk_window_set_title (GTK_WINDOW (app), _("Five or More"));
+ ui_path = g_build_filename (games_runtime_get_directory (GAMES_RUNTIME_GAME_DATA_DIRECTORY), "glines.ui", NULL);
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_file (builder, ui_path, &error);
+ g_free (ui_path);
- gtk_window_set_default_size (GTK_WINDOW (app), DEFAULT_WIDTH, DEFAULT_HEIGHT);
- g_signal_connect (app, "delete-event",
- G_CALLBACK (game_quit_callback), NULL);
+ if (error) {
+ g_critical ("Unable to load the user interface file: %s", error->message);
+ g_error_free (error);
+ g_assert_not_reached ();
+ }
+ app = GTK_WIDGET (gtk_builder_get_object (builder, "glines_window"));
games_settings_bind_window_state ("/org/gnome/glines/", GTK_WINDOW (app));
- statusbar = gtk_statusbar_new ();
- ui_manager = gtk_ui_manager_new ();
-
- games_stock_prepare_for_statusbar_tooltips (ui_manager, statusbar);
- gtk_window_set_has_resize_grip (GTK_WINDOW (app), TRUE);
-
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add (GTK_CONTAINER (app), vbox);
-
- create_menus (ui_manager);
- gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0);
-
- table = gtk_table_new (2, 1, TRUE);
- gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0);
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-
- gtk_table_attach_defaults (GTK_TABLE (table), hbox, 0, 1, 0, 1);
- top_pane = hbox;
- label_text =
- g_strdup_printf ("<span weight=\"bold\">%s</span>", _("Next:"));
- label = gtk_label_new (label_text);
- g_free (label_text);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 5);
+ hbox = GTK_WIDGET (gtk_builder_get_object (builder, "top_box"));
gridframe = games_grid_frame_new (MAXNPIECES, 1);
games_grid_frame_set_alignment (GAMES_GRID_FRAME (gridframe), 0, 0.5);
@@ -1791,17 +1676,9 @@ main (int argc, char *argv[])
g_signal_connect (preview_widgets[0], "configure-event",
G_CALLBACK (preview_configure_cb), NULL);
- scorelabel = gtk_label_new (NULL);
-
- gtk_box_pack_end (GTK_BOX (hbox), scorelabel, FALSE, FALSE, 5);
-
- label_text =
- g_strdup_printf ("<span weight=\"bold\">%s</span>", _("Score:"));
- label = gtk_label_new (label_text);
- g_free (label_text);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 5);
+ scorelabel = GTK_WIDGET (gtk_builder_get_object (builder, "scorelabel"));
+ vbox = GTK_WIDGET (gtk_builder_get_object (builder, "vbox"));
draw_area = gtk_drawing_area_new ();
g_signal_connect (draw_area, "button-press-event",
G_CALLBACK (button_press_event), NULL);
@@ -1814,10 +1691,9 @@ main (int argc, char *argv[])
gridframe = games_grid_frame_new (hfieldsize, vfieldsize);
games_grid_frame_set_padding (GAMES_GRID_FRAME (gridframe), 1, 1);
gtk_container_add (GTK_CONTAINER (gridframe), draw_area);
- gtk_table_attach_defaults (GTK_TABLE (table), gridframe, 0, 1, 1, 2);
- bottom_pane = gridframe;
+ gtk_box_pack_start (GTK_BOX (vbox), gridframe, TRUE, TRUE, 0);
- relay_table ();
+ statusbar = GTK_WIDGET (gtk_builder_get_object (builder, "statusbar"));
gtk_widget_set_events (draw_area,
gtk_widget_get_events (draw_area) |
@@ -1828,6 +1704,8 @@ main (int argc, char *argv[])
load_properties ();
+ gtk_builder_connect_signals (builder, NULL);
+
gtk_widget_show_all (app);
start_game ();
diff --git a/glines/glines.h b/glines/glines.h
index e120c54..1084bf3 100644
--- a/glines/glines.h
+++ b/glines/glines.h
@@ -34,4 +34,14 @@ int init_new_balls (int num, int prev);
gint animate (gpointer gp);
+
+void game_new_callback (void);
+void game_top_ten_callback (GtkAction * action, gpointer data);
+int game_quit_callback (GtkAction * action, gpointer data);
+void game_props_callback (void);
+void game_help_callback (GtkAction * action, gpointer data);
+void game_about_callback (GtkAction * action, gpointer * data);
+
+void pref_dialog_response (GtkDialog * dialog, gint response, gpointer data);
+
#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 61b6c33..e151791 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -25,6 +25,7 @@ glchess/src/test-chess-game.vala
glines/glines.c
glines/glines.h
glines/glines.desktop.in.in
+[type: gettext/glade]glines/data/glines.ui
[type: gettext/glade]glines/data/glines-preferences.ui
glines/org.gnome.glines.gschema.xml.in
gnect/data/gnect.desktop.in.in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]