~taylorp36/ubuntu/wily/aisleriot/bug-1490189

« back to all changes in this revision

Viewing changes to src/window.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2011-09-26 12:54:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110926125422-fhnx2xyc0qcpgyh2
Tags: 1:3.2.0-0ubuntu1
* New upstream stable release.
  - Distribute a copy of the LGPL
  - Update card theme install info for Debian, Ubuntu & OpenSUSE
  - Build help with yelp-tools instead of gnome-doc-utils
  - Fix game restart
  - Translation updates
* debian/control: Build-depends on yelp-tools
* debian/copyright: Fixed a few lintian warnings
* 03_update_theme_install_data.patch: Dropped, applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "ar-string-utils.h"
40
40
#include "ar-gsettings.h"
41
41
 
42
 
#ifdef HAVE_CLUTTER
43
 
#include "ar-clutter-embed.h"
44
 
#include "ar-style.h"
45
 
#include "baize.h"
46
 
#include "board.h"
47
 
#else
48
42
#include "board-noclutter.h"
49
 
#endif
50
43
 
51
44
#include "ar-card-theme.h"
52
45
#include "ar-card-themes.h"
97
90
{
98
91
  AisleriotGame *game;
99
92
  ArStyle *board_style;
100
 
#ifdef HAVE_CLUTTER
101
 
  ArClutterEmbed *board;
102
 
  ClutterActor *baize_actor;
103
 
  ClutterActor *board_actor;
104
 
#else
105
93
  AisleriotBoard *board;
106
 
#endif
107
94
 
108
95
  ArCardThemes *theme_manager;
109
96
  ArCardTheme *theme;
187
174
      aisleriot_game_restart_game (priv->game);
188
175
      break;
189
176
    case RESPONSE_NEW_GAME:
190
 
      aisleriot_game_new_game (priv->game, NULL);
 
177
      aisleriot_game_new_game (priv->game);
191
178
      break;
192
179
    case GTK_RESPONSE_CLOSE:
193
180
      gtk_widget_destroy (GTK_WIDGET (window)); /* this will quit */
200
187
       * thing to do.
201
188
       */
202
189
      if (game_won) {
203
 
        aisleriot_game_new_game (priv->game, NULL);
 
190
        aisleriot_game_new_game (priv->game);
204
191
      } else {
205
192
        aisleriot_game_undo_move (priv->game);
206
193
      }
321
308
{
322
309
  AisleriotWindowPrivate *priv = window->priv;
323
310
 
324
 
  aisleriot_game_new_game (priv->game, NULL);
 
311
  aisleriot_game_new_game (priv->game);
325
312
 
326
313
  gtk_widget_grab_focus (GTK_WIDGET (priv->board));
327
314
}
333
320
  AisleriotWindowPrivate *priv = window->priv;
334
321
 
335
322
  /* If a move is in progress, cancel it before changing the game! */
336
 
#ifdef HAVE_CLUTTER
337
 
  aisleriot_board_abort_move (AISLERIOT_BOARD (priv->board_actor));
338
 
#else
339
323
  aisleriot_board_abort_move (priv->board);
340
 
#endif
341
324
 
342
325
  aisleriot_game_undo_move (priv->game);
343
326
}
348
331
{
349
332
  AisleriotWindowPrivate *priv = window->priv;
350
333
 
351
 
#ifdef HAVE_CLUTTER
352
 
  aisleriot_board_abort_move (AISLERIOT_BOARD (priv->board_actor));
353
 
#else
354
334
  aisleriot_board_abort_move (priv->board);
355
 
#endif
356
335
 
357
336
  aisleriot_game_redo_move (priv->game);
358
337
}
382
361
    "Alan Horkan <horkana@maths.tcd.ie>",
383
362
    "Richard Hoelscher <rah@rahga.com>",
384
363
    "Vincent Povirk",
 
364
    "Sapphire Becker",
385
365
    NULL
386
366
  };
387
367
  const char *artists[] = {
648
628
    return FALSE;
649
629
 
650
630
  game_file = data->current_game->data;  
651
 
  aisleriot_window_set_game (data->window, game_file, 0);
 
631
  aisleriot_window_set_game (data->window, game_file, NULL);
652
632
 
653
633
  return TRUE;
654
634
}
671
651
  if (!data->current_game)
672
652
    return;
673
653
 
674
 
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, 0);
 
654
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
675
655
}
676
656
 
677
657
static void
685
665
  if (!data->current_game)
686
666
    return;
687
667
 
688
 
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, 0);
 
668
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
689
669
}
690
670
 
691
671
static void
704
684
  if (!data->current_game)
705
685
    return;
706
686
 
707
 
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, 0);
 
687
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
708
688
}
709
689
 
710
690
static void
723
703
  if (!data->current_game)
724
704
    return;
725
705
 
726
 
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, 0);
 
706
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
727
707
}
728
708
 
729
709
static void
737
717
    const char *text;
738
718
    char *endptr;
739
719
    guint seed;
 
720
    GRand *rand;
740
721
 
741
722
    entry = g_object_get_data (G_OBJECT (dialog), "entry");
742
723
    text = gtk_entry_get_text (entry);
744
725
    errno = 0;
745
726
    seed = g_ascii_strtoull (text, &endptr, 10);
746
727
    if (errno == 0 && endptr != text) {
747
 
      aisleriot_game_new_game (priv->game, &seed);
 
728
      rand = g_rand_new_with_seed (seed);
 
729
 
 
730
      aisleriot_game_new_game_with_rand (priv->game, rand /* adopts */);
748
731
 
749
732
      gtk_widget_grab_focus (GTK_WIDGET (priv->board));
750
733
    }
757
740
debug_choose_seed_cb (GtkAction *action,
758
741
                      AisleriotWindow *window)
759
742
{
760
 
  AisleriotWindowPrivate *priv = window->priv;
761
743
  GtkWidget *dialog, *entry;
762
 
  char str[32];
763
744
 
764
745
  dialog = gtk_message_dialog_new (GTK_WINDOW (window),
765
746
                                   GTK_DIALOG_DESTROY_WITH_PARENT |
771
752
                    G_CALLBACK (debug_choose_seed_response_cb), window);
772
753
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
773
754
 
 
755
  entry = gtk_entry_new ();
 
756
 
 
757
  #if 0
 
758
{
 
759
  char str[32];
774
760
  g_snprintf (str, sizeof (str), "%u", aisleriot_game_get_seed (priv->game));
775
 
  entry = gtk_entry_new ();
776
761
  gtk_entry_set_text (GTK_ENTRY (entry), str);
 
762
}
 
763
#endif
 
764
 
777
765
  gtk_box_pack_end (GTK_BOX (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog))), entry, FALSE, FALSE, 0);
778
766
  gtk_widget_show (entry);
779
767
  g_object_set_data (G_OBJECT (dialog), "entry", entry);
958
946
 
959
947
#endif /* ENABLE_SOUND */
960
948
 
961
 
#ifdef HAVE_CLUTTER
962
 
 
963
 
static void
964
 
animations_toggle_cb (GtkToggleAction *action,
965
 
                      AisleriotWindow *window)
966
 
{
967
 
  AisleriotWindowPrivate *priv = window->priv;
968
 
  gboolean enabled;
969
 
 
970
 
  enabled = gtk_toggle_action_get_active (action);
971
 
 
972
 
  ar_style_set_enable_animations (priv->board_style, enabled);
973
 
  
974
 
  ar_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_ANIMATIONS), enabled);
975
 
}
976
 
 
977
 
#endif /* HAVE_CLUTTER */
978
 
 
979
949
static void
980
950
show_hint_cb (GtkAction *action,
981
951
              AisleriotWindow *window)
1096
1066
  aisleriot_conf_set_options (aisleriot_game_get_game_file (priv->game), (int) value);
1097
1067
 
1098
1068
  /* Now re-deal, so the option is applied */
1099
 
  aisleriot_game_new_game (priv->game, NULL);
 
1069
  aisleriot_game_new_game (priv->game);
1100
1070
}
1101
1071
 
1102
1072
static void
1249
1219
  game_file = g_object_get_data (G_OBJECT (action), "game");
1250
1220
  g_return_if_fail (game_file != NULL);
1251
1221
 
1252
 
  aisleriot_window_set_game (window, game_file, 0);
 
1222
  aisleriot_window_set_game (window, game_file, NULL);
1253
1223
  
1254
1224
  ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), game_file);
1255
1225
}
1735
1705
  gtk_widget_destroy (dialog);
1736
1706
 
1737
1707
  /* Start a new game */
1738
 
  aisleriot_game_new_game (priv->game, NULL);
 
1708
  aisleriot_game_new_game (priv->game);
1739
1709
 
1740
1710
  gtk_widget_grab_focus (GTK_WIDGET (priv->board));
1741
1711
}
1780
1750
  gtk_widget_show (dialog);
1781
1751
}
1782
1752
 
1783
 
#if defined(HAVE_CLUTTER) || defined(ENABLE_SOUND)
 
1753
#if defined(ENABLE_SOUND)
1784
1754
 
1785
1755
static void
1786
1756
settings_changed_cb (GtkSettings *settings,
1797
1767
  else
1798
1768
    name = NULL;
1799
1769
 
1800
 
#ifdef HAVE_CLUTTER
1801
 
  if (name == NULL || strcmp (name, "gtk-enable-animations") == 0) {
1802
 
    g_object_get (settings, "gtk-enable-animations", &enabled, NULL);
1803
 
 
1804
 
    action = gtk_action_group_get_action (priv->action_group, "Animations");
1805
 
    gtk_action_set_visible (action, enabled);
1806
 
  }
1807
 
#endif /* HAVE_CLUTTER */
1808
 
 
1809
 
#if defined(ENABLE_SOUND)
1810
1770
  if (name == NULL || strcmp (name, "gtk-enable-event-sounds") == 0) {
1811
1771
    g_object_get (settings, "gtk-enable-event-sounds", &enabled, NULL);
1812
1772
 
1813
1773
    action = gtk_action_group_get_action (priv->action_group, "Sound");
1814
1774
    gtk_action_set_visible (action, enabled);
1815
1775
  }
1816
 
#endif /* ENABLE_SOUND */
1817
1776
}
1818
1777
 
1819
1778
static void
1841
1800
 
1842
1801
  settings = gtk_widget_get_settings (widget);
1843
1802
  settings_changed_cb (settings, NULL, window);
1844
 
#ifdef HAVE_CLUTTER
1845
 
  g_signal_connect (settings, "notify::gtk-enable-animations",
1846
 
                    G_CALLBACK (settings_changed_cb), window);
1847
 
#endif
1848
 
#if defined (ENABLE_SOUND)
1849
1803
  g_signal_connect (settings, "notify::gtk-enable-event-sounds",
1850
1804
                    G_CALLBACK (settings_changed_cb), window);
1851
 
#endif
1852
1805
}
1853
1806
 
1854
 
#endif /* HAVE_CLUTTER || ENABLE_SOUND */
 
1807
#endif /* ENABLE_SOUND */
1855
1808
 
1856
1809
/*
1857
1810
 * aisleriot_window_set_freecell_mode:
1897
1850
  }
1898
1851
}
1899
1852
 
1900
 
#ifdef HAVE_CLUTTER
1901
 
 
1902
 
static void
1903
 
board_cursor_cb (AisleriotBoard *board,
1904
 
                 int cursor_type,
1905
 
                 ArClutterEmbed *embed)
1906
 
{
1907
 
  ar_clutter_embed_set_cursor (embed, (ArCursorType) cursor_type);
1908
 
}
1909
 
 
1910
 
static void
1911
 
board_error_bell_cb (AisleriotBoard *board,
1912
 
                     ArClutterEmbed *embed)
1913
 
{
1914
 
  gtk_widget_error_bell (GTK_WIDGET (embed));
1915
 
}
1916
 
 
1917
 
static void
1918
 
embed_size_allocate_cb (ArClutterEmbed *embed,
1919
 
                        GtkAllocation *allocation,
1920
 
                        AisleriotWindow *window)
1921
 
{
1922
 
  AisleriotWindowPrivate *priv = window->priv;
1923
 
 
1924
 
  clutter_actor_set_size (priv->board_actor, allocation->width, allocation->height);
1925
 
}
1926
 
 
1927
 
#endif /* HAVE_CLUTTER */
1928
 
 
1929
1853
/* Class implementation */
1930
1854
 
1931
1855
G_DEFINE_TYPE (AisleriotWindow, aisleriot_window, GTK_TYPE_WINDOW)
2105
2029
      G_CALLBACK (sound_toggle_cb),
2106
2030
      FALSE /* not active by default */ },
2107
2031
#endif /* ENABLE_SOUND */
2108
 
#ifdef HAVE_CLUTTER
2109
 
   { "Animations", NULL, N_("_Animations"), NULL,
2110
 
      N_("Whether or not to animate card moves"),
2111
 
      G_CALLBACK (animations_toggle_cb),
2112
 
      FALSE /* not active by default */ },
2113
 
#endif /* HAVE_CLUTTER */
2114
2032
  };
2115
2033
 
2116
2034
  static const char names[][16] = {
2158
2076
#ifdef ENABLE_SOUND
2159
2077
          "<menuitem action='Sound'/>"
2160
2078
#endif
2161
 
#ifdef HAVE_CLUTTER
2162
 
          "<menuitem action='Animations'/>"
2163
 
#endif
2164
2079
        "</menu>"
2165
2080
        "<menu action='OptionsMenu'/>"
2166
2081
        "<menu action='HelpMenu'>"
2217
2132
  guint i;
2218
2133
  GtkStatusbar *statusbar;
2219
2134
  GtkWidget *statusbar_hbox, *label, *time_box;
2220
 
#ifdef HAVE_CLUTTER
2221
 
  ClutterContainer *stage;
2222
 
#endif
2223
2135
 
2224
2136
  g_assert (G_N_ELEMENTS (names) == LAST_ACTION);
2225
2137
 
2233
2145
 
2234
2146
  priv->board_style = ar_style_new ();
2235
2147
 
2236
 
#ifdef HAVE_CLUTTER
2237
 
  priv->board = ar_clutter_embed_new (priv->board_style);
2238
 
 
2239
 
  priv->baize_actor = aisleriot_baize_new ();
2240
 
 
2241
 
  stage = CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->board)));
2242
 
  clutter_container_add (stage, priv->baize_actor, NULL);
2243
 
  /* FIXMEchpe: how to ensure this is ALWAYS the lowest actor? */
2244
 
  clutter_actor_lower_bottom (priv->baize_actor);
2245
 
 
2246
 
  priv->board_actor = aisleriot_board_new (priv->board_style, priv->game);
2247
 
  clutter_container_add (stage, priv->board_actor, NULL);
2248
 
 
2249
 
  /* FIXMEchpe */
2250
 
  clutter_stage_set_key_focus (CLUTTER_STAGE (stage), priv->board_actor);
2251
 
 
2252
 
  g_signal_connect_after (priv->board, "size-allocate",
2253
 
                          G_CALLBACK (embed_size_allocate_cb), window);
2254
 
 
2255
 
  g_signal_connect (priv->board_actor, "request-cursor",
2256
 
                    G_CALLBACK (board_cursor_cb), priv->board);
2257
 
  g_signal_connect (priv->board_actor, "error-bell",
2258
 
                    G_CALLBACK (board_error_bell_cb), priv->board);
2259
 
 
2260
 
  /* FIXMEchpe: unref baize & board_actor here? */
2261
 
#else
2262
2148
  priv->board = AISLERIOT_BOARD (aisleriot_board_new (priv->board_style, priv->game));
2263
 
#endif /* HAVE_CLUTTER */
2264
2149
 
2265
2150
  theme_name = ar_conf_get_string (NULL, aisleriot_conf_get_key (CONF_THEME), NULL);
2266
2151
  theme = ar_card_themes_get_theme_by_name (priv->theme_manager, theme_name);
2311
2196
 
2312
2197
  priv->game_message_id = gtk_statusbar_get_context_id (priv->statusbar, "board-message");
2313
2198
 
2314
 
#ifdef HAVE_CLUTTER
2315
 
  g_signal_connect (priv->board_actor, "status-message",
2316
 
                    G_CALLBACK (board_status_message_cb), window);
2317
 
#else
2318
2199
  g_signal_connect (priv->board, "status-message",
2319
2200
                    G_CALLBACK (board_status_message_cb), window);
2320
 
#endif
2321
2201
 
2322
2202
  gtk_window_set_has_resize_grip (GTK_WINDOW (window), TRUE);
2323
2203
 
2413
2293
 
2414
2294
  set_fullscreen_actions (window, FALSE);
2415
2295
 
2416
 
#ifdef HAVE_CLUTTER
2417
 
  action = gtk_action_group_get_action (priv->action_group, "Animations");
2418
 
  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
2419
 
                                ar_conf_get_boolean (NULL, aisleriot_conf_get_key (CONF_ANIMATIONS), NULL));
2420
 
 
2421
 
#endif /* HAVE_CLUTTER */
2422
 
 
2423
 
#if defined(HAVE_CLUTTER) || defined(ENABLE_SOUND)
 
2296
#if defined(ENABLE_SOUND)
2424
2297
  /* Set the action visibility and listen for animation and sound mode changes */
2425
2298
  screen_changed_cb (GTK_WIDGET (window), NULL, window);
2426
2299
  g_signal_connect (window, "screen-changed",
2427
2300
                    G_CALLBACK (screen_changed_cb), window);
2428
 
#endif /* HAVE_CLUTTER || ENABLE_SOUND */
 
2301
#endif /* ENABLE_SOUND */
2429
2302
 
2430
2303
  /* Now set up the widgets */
2431
2304
  main_vbox = gtk_vbox_new (FALSE, 0);
2481
2354
{
2482
2355
  AisleriotWindow *window = AISLERIOT_WINDOW (object);
2483
2356
  AisleriotWindowPrivate *priv = window->priv;
2484
 
  
2485
 
#ifdef HAVE_CLUTTER
 
2357
 
 
2358
#ifdef ENABLE_SOUND
2486
2359
  g_signal_handlers_disconnect_by_func (gtk_widget_get_settings (GTK_WIDGET (window)),
2487
2360
                                        G_CALLBACK (settings_changed_cb),
2488
2361
                                        window);
2489
 
#endif /* HAVE_CLUTTER */
 
2362
#endif /* ENABLE_SOUND */
2490
2363
 
2491
2364
  if (priv->hint_dialog) {
2492
2365
    gtk_widget_destroy (priv->hint_dialog);
2526
2399
  AisleriotWindow *window = AISLERIOT_WINDOW (object);
2527
2400
  AisleriotWindowPrivate *priv = window->priv;
2528
2401
 
2529
 
#ifdef HAVE_CLUTTER
2530
 
  g_object_unref (priv->board_style);
2531
 
#endif /* HAVE_CLUTTER */
2532
 
 
2533
2402
  if (priv->theme) {
2534
2403
    g_object_unref (priv->theme);
2535
2404
  }
2609
2478
typedef struct {
2610
2479
  AisleriotWindow *window;
2611
2480
  char *game_file;
2612
 
  guint seed;
 
2481
  GRand *rand;
2613
2482
} LoadIdleData;
2614
2483
 
2615
2484
static void
2618
2487
                        AisleriotWindow *window)
2619
2488
{
2620
2489
  /* Load the default game */
2621
 
  aisleriot_window_set_game (window, DEFAULT_VARIATION, 0);
 
2490
  aisleriot_window_set_game (window, DEFAULT_VARIATION, NULL);
2622
2491
 
2623
2492
  gtk_widget_destroy (dialog);
2624
2493
}
2628
2497
{
2629
2498
  AisleriotWindowPrivate *priv = data->window->priv;
2630
2499
  GError *error = NULL;
 
2500
  GRand *rand;
2631
2501
 
2632
2502
  if (!aisleriot_game_load_game (priv->game, data->game_file, &error)) {
2633
2503
    GtkWidget *dialog;
2678
2548
    ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), data->game_file);
2679
2549
  }
2680
2550
 
2681
 
  aisleriot_game_new_game (priv->game, data->seed != 0 ? &data->seed : NULL);
 
2551
  rand = data->rand;
 
2552
  data->rand = NULL;
 
2553
 
 
2554
  aisleriot_game_new_game_with_rand (priv->game, rand /* adopted */);
2682
2555
 
2683
2556
  gtk_widget_grab_focus (GTK_WIDGET (priv->board));
2684
2557
 
2690
2563
{
2691
2564
  data->window->priv->load_idle_id = 0;
2692
2565
 
 
2566
  if (data->rand)
 
2567
    g_rand_free (data->rand);
 
2568
 
2693
2569
  g_free (data->game_file);
2694
2570
  g_slice_free (LoadIdleData, data);
2695
2571
}
2698
2574
 * aisleriot_window_set_game:
2699
2575
 * @window:
2700
2576
 * @game_file: a UTF-8 string
2701
 
 * @seed:
 
2577
 * @rand: (allow-none) (transfer full): a #GRand, or %NULL
2702
2578
 *
2703
2579
 * Loads the game variation defined in the @game_file file.
2704
2580
 * Note that even though @game_file is used as a filename,
2707
2583
void
2708
2584
aisleriot_window_set_game (AisleriotWindow *window,
2709
2585
                           const char *game_file,
2710
 
                           guint seed)
 
2586
                           GRand *rand)
2711
2587
{
2712
2588
  AisleriotWindowPrivate *priv = window->priv;
2713
2589
  LoadIdleData *data;
2720
2596
  data = g_slice_new (LoadIdleData);
2721
2597
  data->window = window;
2722
2598
  data->game_file = g_strdup (game_file);
2723
 
  data->seed = seed;
 
2599
  data->rand = rand; /* adopted */
2724
2600
 
2725
2601
  priv->load_idle_id = g_idle_add_full (G_PRIORITY_LOW,
2726
2602
                                        (GSourceFunc) load_idle_cb,