2
* Copyright © 1998, 2001, 2003, 2006 Jonathan Blandford <jrb@alum.mit.edu>
3
* Copyright © 2007 Christian Persch
4
* Copyright © 2007 Andreas Røsdal <andreasr@gnome.org>
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include <glib/gi18n.h>
35
#include <hildon-widgets/hildon-program.h>
37
#include <hildon/hildon-program.h>
38
#endif /* HAVE_MAEMO_3 */
40
#define SERVICE_NAME "org.gnome.Games.AisleRiot"
41
#endif /* HAVE_HILDON */
43
#include <libgames-support/games-debug.h>
44
#include <libgames-support/games-stock.h>
45
#include <libgames-support/games-runtime.h>
46
#include <libgames-support/games-sound.h>
49
#include <libgames-support/eggsmclient.h>
50
#endif /* WITH_SMCLIENT */
65
AisleriotWindow *window;
70
HildonProgram *program;
71
#endif /* HAVE_HILDON */
77
save_state_cb (EggSMClient *client,
83
const char *game_name;
87
game = aisleriot_window_get_game (data->window);
89
game_name = aisleriot_game_get_game_file (game);
90
seed = g_strdup_printf ("%u", aisleriot_game_get_seed (game));
92
argv[argc++] = g_get_prgname ();
95
argv[argc++] = (char *) "--freecell";
97
argv[argc++] = (char *) "--variation";
98
argv[argc++] = (char *) game_name;
101
argv[argc++] = (char *) "--seed";
104
/* FIXMEchpe: save game state too? */
106
egg_sm_client_set_restart_command (client, argc, (const char **) argv);
112
quit_cb (EggSMClient *client,
115
/* This will cause gtk_main_quit */
116
gtk_widget_destroy (GTK_WIDGET (data->window));
119
#endif /* WITH_SMCLIENT */
124
osso_hw_event_cb (osso_hw_state_t *state,
127
AppData *data = (AppData *) user_data;
129
/* This callback can be called immediately upon registration.
130
* So check if we're started up yet.
132
if (data->program == NULL)
137
if (state->memory_low_ind) {
138
/* Run garbage collection */
142
#if GNOME_ENABLE_DEBUG
143
if (state->shutdown_ind) {
144
g_print ("Going to shut down\n");
145
} else if (state->save_unsaved_data_ind) {
146
} else if (state->memory_low_ind) {
147
g_print ("Should try to free some memory\n");
148
} else if (state->system_inactivity_ind) {
149
g_print ("System inactive\n");
151
#endif /* GNOME_ENABLE_DEBUG */
155
osso_rpc_cb (const char *interface,
161
AppData *data = (AppData *) user_data;
163
#if GNOME_ENABLE_DEBUG
164
g_print ("OSSO RPC iface %s method %s\n", interface, method);
165
#endif /* GNOME_ENABLE_DEBUG */
167
if (strcmp (method, "top_application") == 0) {
168
gtk_window_present (GTK_WINDOW (data->window));
171
ret->type = DBUS_TYPE_INVALID;
176
sync_is_topmost_cb (HildonProgram *program,
180
if (hildon_program_get_is_topmost (program)) {
181
hildon_program_set_can_hibernate (program, FALSE);
183
/* Ensure settings are saved to disk */
186
/* FIXMEchpe: save state here */
188
hildon_program_set_can_hibernate (program, TRUE);
192
#endif /* HAVE_MAEMO */
195
add_main_options (GOptionContext *option_context,
198
const GOptionEntry aisleriot_options[] = {
199
{ "variation", 'v', 0, G_OPTION_ARG_STRING, &data->variation,
200
N_("Select the game type to play"), N_("NAME") },
201
{ "seed", 's', 0, G_OPTION_ARG_STRING, &data->seed,
202
N_("Select the game number"), N_("NUMBER") },
203
{ "freecell", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &data->freecell,
208
g_option_context_add_main_entries (option_context,
209
aisleriot_options, GETTEXT_PACKAGE);
213
main_prog (void *closure, int argc, char *argv[])
216
GOptionContext *option_context;
217
GError *error = NULL;
220
EggSMClient *sm_client;
221
#endif /* WITH_SMCLIENT */
223
osso_hw_state_t hw_events = {
225
TRUE /* save unsaved data */,
226
TRUE /* low memory */,
227
FALSE /* system inactivity */,
228
OSSO_DEVMODE_NORMAL /* device mode */
229
/* FIXMEchpe: or is OSSO_DEVMODE_INVALID the value to use
230
* when not interested in this signal? The docs don't tell.
233
#endif /* HAVE_MAEMO */
235
memset (&data, 0, sizeof (AppData));
238
/* Set OSSO callbacks */
239
if (osso_rpc_set_default_cb_f (games_runtime_get_osso_context (),
242
osso_hw_set_event_cb (games_runtime_get_osso_context (),
246
g_print ("Failed to connect OSSO handlers\n");
249
#endif /* HAVE_MAEMO */
251
option_context = g_option_context_new (NULL);
252
#if GLIB_CHECK_VERSION (2, 12, 0)
253
g_option_context_set_translation_domain (option_context, GETTEXT_PACKAGE);
254
#endif /* GLIB 2.12.0 */
256
add_main_options (option_context, &data);
258
games_sound_enable (FALSE);
260
g_option_context_add_group (option_context, gtk_get_option_group (TRUE));
262
g_option_context_add_group (option_context, egg_sm_client_get_option_group ());
263
#endif /* WITH_SMCLIENT */
265
#if defined(HAVE_HILDON) && defined(HAVE_MAEMO_5)
269
/* Note: we have to use gtk_rc_add_default_file() before calling gtk_init() (via
270
* g_option_context_parse()) rather than parsing the file directly afterward, in
271
* order to get priority over the theme.
273
rc_file = games_runtime_get_file (GAMES_RUNTIME_GAME_DATA_DIRECTORY, "gtkrc-maemo");
274
gtk_rc_add_default_file (rc_file);
277
#endif /* HAVE_HILDON && HAVE_MAEMO_5 */
279
retval = g_option_context_parse (option_context, &argc, &argv, &error);
280
g_option_context_free (option_context);
283
g_printerr ("%s\n", error->message);
284
g_error_free (error);
289
data.program = HILDON_PROGRAM (hildon_program_get_instance ());
291
g_signal_connect (data.program, "notify::is-topmost",
292
G_CALLBACK(sync_is_topmost_cb), &data);
293
#endif /* HAVE_MAEMO */
295
g_set_application_name (data.freecell ? _("FreeCell Solitaire") : _("AisleRiot"));
297
aisleriot_conf_init ();
299
/* If we are asked for a specific game, check that it is valid. */
300
if (!data.freecell &&
301
data.variation != NULL) {
302
char *game_file = NULL;
304
if (data.variation[0] != '\0') {
305
game_file = aisleriot_variation_to_game_file (data.variation);
308
g_free (data.variation);
309
data.variation = game_file;
312
if (!data.freecell && !data.variation) {
313
data.variation = games_conf_get_string_with_default (NULL, aisleriot_conf_get_key (CONF_VARIATION), DEFAULT_VARIATION);
316
g_assert (data.variation != NULL || data.freecell);
320
gtk_window_set_default_icon_name (data.freecell ? "gnome-freecell" : "gnome-aisleriot");
322
data.window = AISLERIOT_WINDOW (aisleriot_window_new (data.freecell));
323
g_signal_connect (data.window, "destroy",
324
G_CALLBACK (gtk_main_quit), NULL);
327
sm_client = egg_sm_client_get ();
328
g_signal_connect (sm_client, "save-state",
329
G_CALLBACK (save_state_cb), &data);
330
g_signal_connect (sm_client, "quit",
331
G_CALLBACK (quit_cb), &data);
332
#endif /* WITH_SMCLIENT */
335
hildon_program_add_window (data.program, HILDON_WINDOW (data.window));
337
/* This is necessary since the setting is only installed
338
* during class initialisation. See bug #585024.
340
/* For "gtk-menu-images" */
341
g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
342
/* For "gtk-button-images" */
343
g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON));
344
/* For "gtk-toolbar-style" */
345
g_type_class_unref (g_type_class_ref (GTK_TYPE_TOOLBAR));
347
/* FIXMEchpe sort of strange that maemo doesn't all of this out-of-the-box... */
348
g_object_set (gtk_widget_get_settings (GTK_WIDGET (data.window)),
349
"gtk-alternative-button-order", TRUE,
350
"gtk-toolbar-style", GTK_TOOLBAR_ICONS,
351
"gtk-menu-images", FALSE,
352
"gtk-button-images", FALSE,
353
#if GTK_CHECK_VERSION (2, 10, 0)
354
"gtk-enable-mnemonics", FALSE,
356
/* We want the default of FALSE for this property, but to work
357
* around https://bugs.maemo.org/show_bug.cgi?id=2278 we have
358
* to set this to TRUE.
360
"gtk-enable-accels", TRUE,
362
"hildon-keyboard-shortcuts", FALSE,
363
#endif /* GTK 2.10.0 */
365
#endif /* HAVE_HILDON */
368
aisleriot_window_set_game (data.window, FREECELL_VARIATION, data.seed);
370
aisleriot_window_set_game (data.window, data.variation, data.seed);
373
gtk_window_present (GTK_WINDOW (data.window));
377
aisleriot_conf_shutdown ();
380
g_signal_handlers_disconnect_matched (sm_client, G_SIGNAL_MATCH_DATA,
381
0, 0, NULL, NULL, &data);
382
#endif /* WITH_SMCLIENT */
385
g_free (data.variation);
388
if (data.program != NULL) {
389
g_object_unref (data.program);
391
#endif /* HAVE_MAEMO */
393
#if GLIB_CHECK_VERSION (2, 25, 15)
397
games_runtime_shutdown ();
401
main (int argc, char *argv[])
404
if (!games_runtime_init ("aisleriot"))
406
if (!games_runtime_init_with_osso ("aisleriot", SERVICE_NAME))
407
#endif /* !HAVE_HILDON */
410
scm_boot_guile (argc, argv, main_prog, NULL); /* no return */