~ubuntu-branches/ubuntu/oneiric/gnome-games/oneiric-updates

« back to all changes in this revision

Viewing changes to aisleriot/sol.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2011-07-21 04:22:50 UTC
  • mfrom: (1.1.93)
  • Revision ID: package-import@ubuntu.com-20110721042250-far722bxogjk1rhi
Tags: 1:3.1.3-0ubuntu1
* New upstream release
  - Aisleriot was split out of gnome-games into its own module.
  - Gnotravex was ported to GSettings.
  - Sudoku was ported to PyGObject/GTK3 by John Stowers.
* debian/aisleriot*: Dropped
* debian/control
  - Drop aisleriot package
  - Recommend aisleriot
  - Disable lightsoff & swell-foop as they're not ready yet
  - Re-enable gnome-sudoku
  - Use python-gobject instead of python-gtk2
  - Don't use python-launchpad-integration as it doesn't work with pygi yet
  - Switch to dh_python2 (LP: #788514)
  - Drop old pre-Lucid conflicts with gnome-cards-data & gnome-games-data
  - Drop obsolete build-depends: check, dpkg-dev, guile-1.8, lsb-release,
    rarian-compat, & scrollkeeper
  - Use ${gir:Depends}
* debian/copyright: Drop aisleriot & blackjack entries
* debian/glchess.install: Drop gnome-gnuchess
* debian/gnome-games-common.install: Drop aisleriot entries
* debian/gnome-sudoku.install: Install gconf schema
* debian/gnotravex.install: Install GSettings schema
* debian/rules
  - Clean up configure flags
  - Switch to dh_python2
* debian/watch: Watch for .bz2
* debian/patches/01_lpi.patch: Refreshed
* debian/patches/02_desktop-path.patch: Removed aisleriot references
* debian/patches/03_add-appinstall-keywords.patch
  - Add keywords to make searching for the games easier in Software Center

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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> 
5
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
 
22
 
#include <string.h>
23
 
 
24
 
#include <libguile.h>
25
 
 
26
 
#include <glib.h>
27
 
#include <glib/gi18n.h>
28
 
 
29
 
#include <gtk/gtk.h>
30
 
 
31
 
#ifdef HAVE_HILDON
32
 
#include <libosso.h>
33
 
 
34
 
#ifdef HAVE_MAEMO_3
35
 
#include <hildon-widgets/hildon-program.h>
36
 
#else
37
 
#include <hildon/hildon-program.h>
38
 
#endif /* HAVE_MAEMO_3 */
39
 
 
40
 
#define SERVICE_NAME "org.gnome.Games.AisleRiot"
41
 
#endif /* HAVE_HILDON */
42
 
 
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>
47
 
 
48
 
#ifdef WITH_SMCLIENT
49
 
#include <libgames-support/eggsmclient.h>
50
 
#endif /* WITH_SMCLIENT */
51
 
 
52
 
#include "conf.h"
53
 
#include "game.h"
54
 
#include "window.h"
55
 
#include "util.h"
56
 
 
57
 
#if 0
58
 
/* String reserve */
59
 
N_("Solitaire")
60
 
N_("GNOME Solitaire")
61
 
N_("About Solitaire")
62
 
#endif /* 0 */
63
 
 
64
 
typedef struct {
65
 
  AisleriotWindow *window;
66
 
  char *variation;
67
 
  guint seed;
68
 
  gboolean freecell;
69
 
#ifdef HAVE_HILDON
70
 
  HildonProgram *program;
71
 
#endif /* HAVE_HILDON */
72
 
} AppData;
73
 
 
74
 
#ifdef WITH_SMCLIENT
75
 
 
76
 
static void
77
 
save_state_cb (EggSMClient *client,
78
 
               GKeyFile *key_file,
79
 
               AppData *data)
80
 
{
81
 
  AisleriotGame *game;
82
 
  char *argv[5];
83
 
  const char *game_name;
84
 
  char *seed;
85
 
  int argc = 0;
86
 
 
87
 
  game = aisleriot_window_get_game (data->window);
88
 
 
89
 
  game_name = aisleriot_game_get_game_file (game);
90
 
  seed = g_strdup_printf ("%u", aisleriot_game_get_seed (game));
91
 
 
92
 
  argv[argc++] = g_get_prgname ();
93
 
 
94
 
  if (data->freecell) {
95
 
    argv[argc++] = (char *) "--freecell";
96
 
  } else {
97
 
    argv[argc++] = (char *) "--variation";
98
 
    argv[argc++] = (char *) game_name;
99
 
  }
100
 
 
101
 
  argv[argc++] = (char *) "--seed";
102
 
  argv[argc++] = seed;
103
 
 
104
 
  /* FIXMEchpe: save game state too? */
105
 
 
106
 
  egg_sm_client_set_restart_command (client, argc, (const char **) argv);
107
 
 
108
 
  g_free (seed);
109
 
}
110
 
 
111
 
static void
112
 
quit_cb (EggSMClient *client,
113
 
         AppData *data)
114
 
{
115
 
  /* This will cause gtk_main_quit */
116
 
  gtk_widget_destroy (GTK_WIDGET (data->window));
117
 
}
118
 
 
119
 
#endif /* WITH_SMCLIENT */
120
 
 
121
 
#ifdef HAVE_MAEMO
122
 
 
123
 
static void
124
 
osso_hw_event_cb (osso_hw_state_t *state,
125
 
                  gpointer user_data)
126
 
{
127
 
  AppData *data = (AppData *) user_data;
128
 
 
129
 
  /* This callback can be called immediately upon registration.
130
 
   * So check if we're started up yet.
131
 
   */
132
 
  if (data->program == NULL)
133
 
    return;
134
 
 
135
 
  games_conf_save ();
136
 
 
137
 
  if (state->memory_low_ind) {
138
 
    /* Run garbage collection */
139
 
    scm_gc ();
140
 
  }
141
 
 
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");
150
 
  }
151
 
#endif /* GNOME_ENABLE_DEBUG */
152
 
}
153
 
 
154
 
static int
155
 
osso_rpc_cb (const char *interface,
156
 
             const char *method,
157
 
             GArray *args,
158
 
             gpointer user_data,
159
 
             osso_rpc_t *ret)
160
 
{
161
 
  AppData *data = (AppData *) user_data;
162
 
 
163
 
#if GNOME_ENABLE_DEBUG
164
 
  g_print ("OSSO RPC iface %s method %s\n", interface, method);
165
 
#endif /* GNOME_ENABLE_DEBUG */
166
 
 
167
 
  if (strcmp (method, "top_application") == 0) {
168
 
    gtk_window_present (GTK_WINDOW (data->window));
169
 
  }
170
 
 
171
 
  ret->type = DBUS_TYPE_INVALID;
172
 
  return OSSO_OK;
173
 
}
174
 
 
175
 
static void
176
 
sync_is_topmost_cb (HildonProgram *program,
177
 
                    GParamSpec *pspec,
178
 
                    AppData *data)
179
 
{
180
 
  if (hildon_program_get_is_topmost (program)) {
181
 
    hildon_program_set_can_hibernate (program, FALSE);
182
 
  } else {
183
 
    /* Ensure settings are saved to disk */
184
 
    games_conf_save ();
185
 
 
186
 
    /* FIXMEchpe: save state here */
187
 
 
188
 
    hildon_program_set_can_hibernate (program, TRUE);
189
 
  }
190
 
}
191
 
 
192
 
#endif /* HAVE_MAEMO */
193
 
 
194
 
static void
195
 
add_main_options (GOptionContext *option_context,
196
 
                  AppData *data)
197
 
{
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,
204
 
      NULL, NULL },
205
 
    { NULL }
206
 
  };
207
 
 
208
 
  g_option_context_add_main_entries (option_context,
209
 
                                     aisleriot_options, GETTEXT_PACKAGE);
210
 
}
211
 
 
212
 
static void
213
 
main_prog (void *closure, int argc, char *argv[])
214
 
{
215
 
  AppData data;
216
 
  GOptionContext *option_context;
217
 
  GError *error = NULL;
218
 
  gboolean retval;
219
 
#ifdef WITH_SMCLIENT
220
 
  EggSMClient *sm_client;
221
 
#endif /* WITH_SMCLIENT */
222
 
#ifdef HAVE_MAEMO
223
 
  osso_hw_state_t hw_events = {
224
 
    TRUE /* shutdown */,
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.
231
 
     */
232
 
  };
233
 
#endif /* HAVE_MAEMO */
234
 
 
235
 
  memset (&data, 0, sizeof (AppData));
236
 
 
237
 
#ifdef HAVE_MAEMO
238
 
  /* Set OSSO callbacks */
239
 
  if (osso_rpc_set_default_cb_f (games_runtime_get_osso_context (),
240
 
                                 osso_rpc_cb,
241
 
                                 &data) != OSSO_OK ||
242
 
      osso_hw_set_event_cb (games_runtime_get_osso_context (),
243
 
                            &hw_events,
244
 
                            osso_hw_event_cb,
245
 
                            &data) != OSSO_OK) {
246
 
    g_print ("Failed to connect OSSO handlers\n");
247
 
    goto cleanup;
248
 
  }
249
 
#endif /* HAVE_MAEMO */
250
 
 
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 */
255
 
 
256
 
  add_main_options (option_context, &data);
257
 
 
258
 
  games_sound_enable (FALSE);
259
 
 
260
 
  g_option_context_add_group (option_context, gtk_get_option_group (TRUE));
261
 
#ifdef WITH_SMCLIENT
262
 
  g_option_context_add_group (option_context, egg_sm_client_get_option_group ());
263
 
#endif /* WITH_SMCLIENT */
264
 
 
265
 
#if defined(HAVE_HILDON) && defined(HAVE_MAEMO_5)
266
 
  {
267
 
    char *rc_file;
268
 
 
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.
272
 
     */
273
 
    rc_file = games_runtime_get_file (GAMES_RUNTIME_GAME_DATA_DIRECTORY, "gtkrc-maemo");
274
 
    gtk_rc_add_default_file (rc_file);
275
 
    g_free (rc_file);
276
 
  }
277
 
#endif /* HAVE_HILDON && HAVE_MAEMO_5 */
278
 
 
279
 
  retval = g_option_context_parse (option_context, &argc, &argv, &error);
280
 
  g_option_context_free (option_context);
281
 
 
282
 
  if (!retval) {
283
 
    g_printerr ("%s\n", error->message);
284
 
    g_error_free (error);
285
 
    goto cleanup;
286
 
  }
287
 
 
288
 
#ifdef HAVE_MAEMO
289
 
  data.program = HILDON_PROGRAM (hildon_program_get_instance ());
290
 
 
291
 
  g_signal_connect (data.program, "notify::is-topmost",
292
 
                    G_CALLBACK(sync_is_topmost_cb), &data);
293
 
#endif /* HAVE_MAEMO */
294
 
 
295
 
  g_set_application_name (data.freecell ? _("FreeCell Solitaire") : _("AisleRiot"));
296
 
 
297
 
  aisleriot_conf_init ();
298
 
 
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;
303
 
 
304
 
    if (data.variation[0] != '\0') {
305
 
      game_file = aisleriot_variation_to_game_file (data.variation);
306
 
    }
307
 
 
308
 
    g_free (data.variation);
309
 
    data.variation = game_file;
310
 
  }
311
 
 
312
 
  if (!data.freecell && !data.variation) {
313
 
    data.variation = games_conf_get_string_with_default (NULL, aisleriot_conf_get_key (CONF_VARIATION), DEFAULT_VARIATION);
314
 
  }
315
 
 
316
 
  g_assert (data.variation != NULL || data.freecell);
317
 
 
318
 
  games_stock_init ();
319
 
 
320
 
  gtk_window_set_default_icon_name (data.freecell ? "gnome-freecell" : "gnome-aisleriot");
321
 
 
322
 
  data.window = AISLERIOT_WINDOW (aisleriot_window_new (data.freecell));
323
 
  g_signal_connect (data.window, "destroy",
324
 
                    G_CALLBACK (gtk_main_quit), NULL);
325
 
 
326
 
#ifdef WITH_SMCLIENT
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 */
333
 
 
334
 
#ifdef HAVE_HILDON
335
 
  hildon_program_add_window (data.program, HILDON_WINDOW (data.window));
336
 
 
337
 
  /* This is necessary since the setting is only installed
338
 
   * during class initialisation. See bug #585024.
339
 
   */
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));
346
 
 
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,
355
 
 
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.
359
 
                 */
360
 
                "gtk-enable-accels", TRUE,
361
 
#else
362
 
                "hildon-keyboard-shortcuts", FALSE,
363
 
#endif /* GTK 2.10.0 */
364
 
                NULL);
365
 
#endif /* HAVE_HILDON */
366
 
 
367
 
  if (data.freecell) {
368
 
    aisleriot_window_set_game (data.window, FREECELL_VARIATION, data.seed);
369
 
  } else {
370
 
    aisleriot_window_set_game (data.window, data.variation, data.seed);
371
 
  }
372
 
 
373
 
  gtk_window_present (GTK_WINDOW (data.window));
374
 
 
375
 
  gtk_main ();
376
 
 
377
 
  aisleriot_conf_shutdown ();
378
 
 
379
 
#ifdef WITH_SMCLIENT
380
 
  g_signal_handlers_disconnect_matched (sm_client, G_SIGNAL_MATCH_DATA,
381
 
                                        0, 0, NULL, NULL, &data);
382
 
#endif /* WITH_SMCLIENT */
383
 
 
384
 
cleanup:
385
 
  g_free (data.variation);
386
 
 
387
 
#ifdef HAVE_MAEMO
388
 
  if (data.program != NULL) {
389
 
    g_object_unref (data.program);
390
 
  }
391
 
#endif /* HAVE_MAEMO */
392
 
 
393
 
#if GLIB_CHECK_VERSION (2, 25, 15)
394
 
  g_settings_sync ();
395
 
#endif
396
 
 
397
 
  games_runtime_shutdown ();
398
 
}
399
 
 
400
 
int
401
 
main (int argc, char *argv[])
402
 
{
403
 
#ifndef HAVE_HILDON
404
 
  if (!games_runtime_init ("aisleriot"))
405
 
#else
406
 
  if (!games_runtime_init_with_osso ("aisleriot", SERVICE_NAME))
407
 
#endif /* !HAVE_HILDON */
408
 
    return 1;
409
 
 
410
 
  scm_boot_guile (argc, argv, main_prog, NULL); /* no return */
411
 
 
412
 
  return 0;
413
 
}