[gnome-robots] Remove command line options, port to GApplication
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-robots] Remove command line options, port to GApplication
- Date: Mon, 19 May 2014 03:30:19 +0000 (UTC)
commit 2909aa88db406f546debf319b31e34eae891db97
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun May 18 22:24:47 2014 -0500
Remove command line options, port to GApplication
Both of the meaningful command line options have been broken for a long
time, and their value appears limited.
configure.ac | 3 +
data/gnome-robots.6 | 22 +--------
src/gnobots.c | 132 +++++++++++++++++----------------------------------
3 files changed, 47 insertions(+), 110 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index fbbcc18..912c8d8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,11 +16,14 @@ dnl Dependencies
dnl ###########################################################################
GTK_REQUIRED=3.12.0
+GLIB_REQUIRED=2.28
RSVG_REQUIRED=2.32.0
CANBERRA_GTK_REQUIRED=0.26
PKG_CHECK_MODULES(ROBOTS, [
gtk+-3.0 >= $GTK_REQUIRED
+ glib-2.0 >= $GLIB_REQUIRED
+ gio-2.0 >= $GLIB_REQUIRED
librsvg-2.0 >= $RSVG_REQUIRED
libcanberra-gtk3 >= $CANBERRA_GTK_REQUIRED
])
diff --git a/data/gnome-robots.6 b/data/gnome-robots.6
index a217384..93a90b0 100644
--- a/data/gnome-robots.6
+++ b/data/gnome-robots.6
@@ -13,7 +13,7 @@
.\"You should have received a copy of the GNU General Public License along
.\"with this program; if not, write to the Free Software Foundation, Inc.,
.\"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-.TH gnome-robots 6 "2007\-06\-07" "GNOME"
+.TH gnome-robots 6 "2014\-05\-18" "GNOME"
.SH NAME
Robots \- Based on classic BSD Robots
.SH SYNOPSIS
@@ -25,29 +25,9 @@ is a game where you try and avoid a band of marauding
robots which are, for no adequately explained reason, trying to kill
you. It is based on the text-based robots game which can be found on a
number of UNIX systems.
-.SH OPTIONS
-.TP
-.B \-c, --config=NAME
-Set game configuration. Choose from "robots2", "robots2 easy", "classic
-robots", "robots with safe teleport" and "nightmare".
-.TP
-.B \-x, \-\-x=X
-Initial window position
-.TP
-.B \-y, \-\-y=Y
-Initial window position
-.P
-This program also accepts the standard GNOME and GTK options.
.SH AUTHORS
.B gnome-robots
was written by Mark Rae <m rae inpharmatica co uk>.
.P
This manual page was written by Sven Arvidsson <sa whiz se>,
for the Debian project (but may be used by others).
-.SH SEE ALSO
-.BR "gtk-options" (7),
-.BR "gnome-options" (7)
-.P
-The online documentation available through the program's
-.I Help
-menu.
diff --git a/src/gnobots.c b/src/gnobots.c
index c1de4b9..44654ea 100644
--- a/src/gnobots.c
+++ b/src/gnobots.c
@@ -60,32 +60,9 @@ GamesScores *highscores;
GSettings *settings;
/**********************************************************************/
-
/**********************************************************************/
/* File Static Variables */
/**********************************************************************/
-static gchar *cmdline_scenario = NULL;
-static gchar *cmdline_config = NULL;
-static gint session_xpos = -1;
-static gint session_ypos = -1;
-/**********************************************************************/
-
-
-/**********************************************************************/
-/* File Static Variables */
-/**********************************************************************/
-static const GOptionEntry options[] = {
- {"scenario", 's', 0, G_OPTION_ARG_STRING, &cmdline_scenario,
- N_("Set game scenario"), N_("NAME")},
- {"config", 'c', 0, G_OPTION_ARG_STRING, &cmdline_config,
- N_("Set game configuration"), N_("NAME")},
- {"x", 'x', 0, G_OPTION_ARG_INT, &session_xpos,
- N_("Initial window position"), N_("X")},
- {"y", 'y', 0, G_OPTION_ARG_INT, &session_ypos,
- N_("Initial window position"), N_("Y")},
- {NULL},
-};
-
static const GamesScoresCategory scorecats[] = {
{"classic_robots", N_("Classic robots")},
{"classic_robots-safe", N_("Classic robots with safe moves")},
@@ -142,36 +119,13 @@ window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event)
void
quit_game (void)
{
- g_settings_set_int (settings, "window-width", window_width);
- g_settings_set_int (settings, "window-height", window_height);
- g_settings_set_boolean (settings, "window-is-maximized", window_is_maximized);
- g_settings_set_boolean (settings, "window-is-fullscreen", window_is_fullscreen);
- gtk_main_quit ();
+ gtk_window_close (window);
}
-/**
- * main
- * @argc: number of arguments
- * @argv: arguments
- *
- * Description:
- * main
- *
- * Returns:
- * exit code
- **/
-int
-main (int argc, char *argv[])
+static void
+startup (GtkApplication *app, gpointer user_data)
{
- GtkWidget *errordialog;
- GtkWidget *vbox, *menubar, *toolbar, *statusbar, *gridframe;
- GtkUIManager *ui_manager;
- GOptionContext *context;
struct timeval tv;
- gint i;
- gchar *config;
- gboolean retval;
- GError *error = NULL;
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
@@ -183,20 +137,6 @@ main (int argc, char *argv[])
gettimeofday (&tv, NULL);
srand (tv.tv_usec);
- context = g_option_context_new (NULL);
- g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
- g_option_context_add_group (context, gtk_get_option_group (TRUE));
-
- g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
-
- retval = g_option_context_parse (context, &argc, &argv, &error);
- g_option_context_free (context);
- if (!retval) {
- g_print ("%s", error->message);
- g_error_free (error);
- exit (1);
- }
-
g_set_application_name (_("Robots"));
highscores = games_scores_new ("gnome-robots",
@@ -208,8 +148,25 @@ main (int argc, char *argv[])
settings = g_settings_new ("org.gnome.robots");
gtk_window_set_default_icon_name ("gnome-robots");
+}
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+static void
+shutdown (GtkApplication *app, gpointer user_data)
+{
+ g_settings_set_int (settings, "window-width", window_width);
+ g_settings_set_int (settings, "window-height", window_height);
+ g_settings_set_boolean (settings, "window-is-maximized", window_is_maximized);
+ g_settings_set_boolean (settings, "window-is-fullscreen", window_is_fullscreen);
+}
+
+static void
+activate (GtkApplication *app, gpointer user_data)
+{
+ GtkWidget *errordialog;
+ GtkWidget *vbox, *menubar, *toolbar, *statusbar, *gridframe;
+ GtkUIManager *ui_manager;
+
+ window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), _("Robots"));
g_signal_connect (GTK_WINDOW (window), "configure-event", G_CALLBACK (window_configure_event_cb), NULL);
g_signal_connect (GTK_WINDOW (window), "window-state-event", G_CALLBACK (window_state_event_cb), NULL);
@@ -219,9 +176,6 @@ main (int argc, char *argv[])
if (g_settings_get_boolean (settings, "window-is-maximized"))
gtk_window_maximize (GTK_WINDOW (window));
- g_signal_connect (G_OBJECT (window), "delete_event",
- G_CALLBACK (quit_game), NULL);
-
statusbar = gnobots_statusbar_new ();
ui_manager = gtk_ui_manager_new ();
@@ -265,11 +219,6 @@ main (int argc, char *argv[])
MINIMUM_TILE_WIDTH * GAME_WIDTH,
MINIMUM_TILE_HEIGHT * GAME_HEIGHT);
- /* Set the window position if it was set by the session manager */
- if (session_xpos >= 0 && session_ypos >= 0) {
- gtk_window_move (GTK_WINDOW (window), session_xpos, session_ypos);
- }
-
gtk_widget_show_all (window);
if (!load_game_configs ()) {
@@ -308,27 +257,32 @@ main (int argc, char *argv[])
init_game ();
- if (cmdline_scenario) {
- load_game_graphics ();
- }
+ g_settings_sync();
+}
- if (cmdline_config) {
- for (i = 0; i < num_game_configs (); ++i) {
- config = game_config_name (i);
- if (!strcmp (cmdline_config, config)) {
- properties_set_config (i);
- g_free (config);
- break;
- }
- g_free (config);
- }
- }
+/**
+ * main
+ * @argc: number of arguments
+ * @argv: arguments
+ *
+ * Description:
+ * main
+ *
+ * Returns:
+ * exit code
+ **/
+int
+main (int argc, char *argv[])
+{
+ GtkApplication *app;
- gtk_main ();
+ app = gtk_application_new ("org.gnome.robots", G_APPLICATION_FLAGS_NONE);
- g_settings_sync();
+ g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
+ g_signal_connect (app, "shutdown", G_CALLBACK (shutdown), NULL);
+ g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
- return 0;
+ return g_application_run (G_APPLICATION (app), argc, argv);
}
/**********************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]