~ubuntu-branches/debian/jessie/aisleriot/jessie

« back to all changes in this revision

Viewing changes to src/window.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jeremy Bicha, Jordi Mallach
  • Date: 2012-04-22 12:49:26 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120422124926-gmr0thwstl91jt1n
Tags: 1:3.4.1-1
[ Jeremy Bicha ]
* New upstream release
* debian/control.in: (Build)-depend on guile-2.0
* debian/*.install: Cards files are now stored as zipped .svg's
* debian/patches/99_format-security.patch: Dropped, applied upstream

[ Jordi Mallach ]
* New upstream release.
* Update copyright to final version of the machine-readable 1.0 spec.
* Bump Standards Version to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
273
273
  aisleriot_stats_dialog_set_name (priv->stats_dialog, game_name);
274
274
  g_free (game_name);
275
275
 
276
 
  aisleriot_conf_get_statistic (aisleriot_game_get_game_file (priv->game),
 
276
  aisleriot_conf_get_statistic (aisleriot_game_get_game_module (priv->game),
277
277
                                &current_stats);
278
278
 
279
279
  aisleriot_stats_dialog_update (priv->stats_dialog, &current_stats);
289
289
  if (response == GTK_RESPONSE_REJECT) {
290
290
    AisleriotStatistic current_stats = { 0, 0, 0, 0 };
291
291
 
292
 
    aisleriot_conf_set_statistic (aisleriot_game_get_game_file (priv->game),
 
292
    aisleriot_conf_set_statistic (aisleriot_game_get_game_module (priv->game),
293
293
                                  &current_stats);
294
294
    aisleriot_stats_dialog_update (priv->stats_dialog, &current_stats);
295
295
 
401
401
                             "card engine that allows many different "
402
402
                             "games to be played."),
403
403
                         "copyright", "Copyright © 1998-2006 Jonathan Blandford\n"
404
 
                                      "Copyright © 2007, 2008, 2009, 2010, 2011 Christian Persch",
 
404
                                      "Copyright © 2007, 2008, 2009, 2010, 2011, 2012 Christian Persch",
405
405
                         "license", licence,
406
406
                         "authors", authors,
407
407
                         "artists", artists,
455
455
                 AisleriotWindow *window)
456
456
{
457
457
  AisleriotWindowPrivate *priv = window->priv;
458
 
  const char *game_file;
 
458
  const char *game_module;
459
459
  
460
 
  game_file = aisleriot_game_get_game_file (priv->game);
461
 
  aisleriot_show_help (GTK_WIDGET (window), game_file);
 
460
  game_module = aisleriot_game_get_game_module (priv->game);
 
461
  aisleriot_show_help (GTK_WIDGET (window), game_module);
462
462
}
463
463
 
464
464
static void
497
497
  AisleriotWindowPrivate *priv = window->priv;
498
498
 
499
499
  ar_card_themes_install_themes (priv->theme_manager,
500
 
                                    GTK_WINDOW (window),
501
 
                                    gtk_get_current_event_time ());
 
500
                                 GTK_WIDGET (window),
 
501
                                 gtk_get_current_event_time ());
502
502
}
503
503
 
504
504
#ifdef ENABLE_DEBUG_UI
552
552
 
553
553
typedef struct {
554
554
  AisleriotWindow *window;
555
 
  GList *games_list;
556
 
  GList *current_game;
 
555
  char **games;
 
556
  int n_games;
 
557
  int current;
557
558
} DebugWindowData;
558
559
 
559
560
static void
560
561
debug_data_free (DebugWindowData *data)
561
562
{
562
 
  g_list_foreach (data->games_list, (GFunc) g_free, NULL);
563
 
  g_list_free (data->games_list);
 
563
  g_strfreev (data->games);
 
564
 
564
565
  g_slice_free (DebugWindowData, data);
565
566
}
566
567
 
569
570
{
570
571
  AisleriotWindowPrivate *priv = window->priv;
571
572
  DebugWindowData *data;
572
 
  GDir *dir;
573
 
  GList *list = NULL;
574
 
  const char *games_dir;
 
573
  char **games;
 
574
  int n_games;
 
575
  const char *current_game_module;
 
576
  int i;
575
577
 
576
578
  data = g_object_get_data (G_OBJECT (window), DEBUG_WINDOW_DATA_KEY);
577
579
  if (data != NULL)
578
580
    return data;
579
581
 
580
 
  games_dir = ar_runtime_get_directory (AR_RUNTIME_GAMES_DIRECTORY);
581
 
  dir = g_dir_open (games_dir, 0, NULL);
582
 
  if (dir != NULL) {
583
 
    const char *game_file;
584
 
 
585
 
    while ((game_file = g_dir_read_name (dir)) != NULL) {
586
 
      if (!g_str_has_suffix (game_file, ".scm") ||
587
 
          strcmp (game_file, "sol.scm") == 0)
588
 
        continue;
589
 
 
590
 
      list = g_list_prepend (list, g_strdup (game_file));
591
 
    }
592
 
 
593
 
    list = g_list_sort (list, (GCompareFunc) strcmp);
594
 
    g_dir_close (dir);
 
582
  games = ar_get_game_modules ();
 
583
  if (games == NULL)
 
584
    return NULL;
 
585
 
 
586
  n_games = g_strv_length (games);
 
587
  if (n_games == 0) {
 
588
    g_strfreev (games);
 
589
    return NULL;
595
590
  }
596
591
 
597
592
  data = g_slice_new (DebugWindowData);
598
593
  data->window = window;
599
 
  data->games_list = list;
600
 
  data->current_game = g_list_find_custom (data->games_list,
601
 
                                           aisleriot_game_get_game_file (priv->game),
602
 
                                           (GCompareFunc) strcmp);
 
594
  data->games = games;
 
595
  data->n_games = n_games;
 
596
  data->current = -1;
 
597
 
 
598
  current_game_module = aisleriot_game_get_game_module (priv->game);
 
599
  for (i = 0; data->games[i]; ++i) {
 
600
    if (strcmp (data->games[i], current_game_module) == 0) {
 
601
      data->current = i;
 
602
      break;
 
603
    }
 
604
  }
603
605
 
604
606
  g_object_set_data_full (G_OBJECT (window), DEBUG_WINDOW_DATA_KEY,
605
607
                          data, (GDestroyNotify) debug_data_free);
608
610
}
609
611
 
610
612
static gboolean
611
 
debug_cycle_timeout_cb (AisleriotWindow *window)
 
613
debug_cycle_timeout_cb (DebugWindowData *data)
612
614
{
613
 
  DebugWindowData *data;
614
 
  char *game_file;
615
 
 
616
 
  data = debug_ensure_game_list (window);
617
 
  if (data->current_game != NULL) {
618
 
    data->current_game = data->current_game->next;
619
 
    /* We're done */
620
 
    if (!data->current_game)
621
 
      return FALSE;
622
 
  }
623
 
  if (!data->current_game) {
624
 
    data->current_game = data->games_list;
625
 
  }
626
 
  if (!data->current_game)
627
 
    return FALSE;
628
 
 
629
 
  game_file = data->current_game->data;  
630
 
  aisleriot_window_set_game (data->window, game_file, NULL);
631
 
 
632
 
  return TRUE;
 
615
  if (data->current >= -1)
 
616
    data->current++;
 
617
 
 
618
  /* We're done */
 
619
  if (data->current >= data->n_games) {
 
620
    data->current = data->n_games - 1;
 
621
    return FALSE; /* don't run again */
 
622
  }
 
623
 
 
624
  aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
 
625
 
 
626
  return TRUE; /* run again */
633
627
}
634
628
 
635
629
static void
636
630
debug_cycle_cb (GtkAction *action,
637
631
                AisleriotWindow *window)
638
632
{
639
 
  g_timeout_add (500, (GSourceFunc) debug_cycle_timeout_cb, window);
 
633
  DebugWindowData *data;
 
634
 
 
635
  data = debug_ensure_game_list (window);
 
636
  if (data == NULL)
 
637
    return;
 
638
 
 
639
  g_timeout_add (500, (GSourceFunc) debug_cycle_timeout_cb, data);
640
640
}
641
641
 
642
642
static void
646
646
  DebugWindowData *data;
647
647
 
648
648
  data = debug_ensure_game_list (window);
649
 
  data->current_game = data->games_list;
650
 
  if (!data->current_game)
 
649
  if (data == NULL)
651
650
    return;
652
651
 
653
 
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
 
652
  data->current = 0;
 
653
  aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
654
654
}
655
655
 
656
656
static void
660
660
  DebugWindowData *data;
661
661
 
662
662
  data = debug_ensure_game_list (window);
663
 
  data->current_game = g_list_last (data->games_list);
664
 
  if (!data->current_game)
 
663
  if (data == NULL)
665
664
    return;
666
665
 
667
 
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
 
666
  data->current = data->n_games - 1;
 
667
  aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
668
668
}
669
669
 
670
670
static void
674
674
  DebugWindowData *data;
675
675
 
676
676
  data = debug_ensure_game_list (window);
677
 
  if (data->current_game) {
678
 
    data->current_game = data->current_game->next;
679
 
  }
680
 
  if (!data->current_game) {
681
 
    data->current_game = data->games_list;
682
 
  }
683
 
  if (!data->current_game)
 
677
  if (data == NULL || data->current + 1 == data->n_games)
684
678
    return;
685
679
 
686
 
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
 
680
  data->current++;
 
681
  aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
687
682
}
688
683
 
689
684
static void
693
688
  DebugWindowData *data;
694
689
 
695
690
  data = debug_ensure_game_list (window);
696
 
  if (data->current_game) {
697
 
    data->current_game = data->current_game->prev;
698
 
  }
699
 
  if (!data->current_game) {
700
 
    data->current_game = data->games_list;
701
 
  }
702
 
  if (!data->current_game)
 
691
  if (data == NULL || data->current == 0)
703
692
    return;
704
693
 
705
 
  aisleriot_window_set_game (data->window, (const char *) data->current_game->data, NULL);
 
694
  data->current--;
 
695
  aisleriot_window_set_game_module (data->window, data->games[data->current], NULL);
706
696
}
707
697
 
708
698
static void
1062
1052
 
1063
1053
  value = aisleriot_game_change_options (priv->game, changed_mask, changed_value);
1064
1054
 
1065
 
  aisleriot_conf_set_options (aisleriot_game_get_game_file (priv->game), (int) value);
 
1055
  aisleriot_conf_set_options (aisleriot_game_get_game_module (priv->game), (int) value);
1066
1056
 
1067
1057
  /* Now re-deal, so the option is applied */
1068
1058
  aisleriot_game_new_game (priv->game);
1093
1083
  /* Only apply the options if they exist. Otherwise the options in the menu
1094
1084
   * and the real game options are out of sync until first changed by the user.
1095
1085
   */
1096
 
  if (aisleriot_conf_get_options (aisleriot_game_get_game_file (priv->game), &options_value)) {
 
1086
  if (aisleriot_conf_get_options (aisleriot_game_get_game_module (priv->game), &options_value)) {
1097
1087
    aisleriot_game_change_options (priv->game, AISLERIOT_GAME_OPTIONS_MAX, options_value);
1098
1088
  }
1099
1089
 
1166
1156
 */
1167
1157
static void
1168
1158
add_recently_played_game (AisleriotWindow *window,
1169
 
                          const char *game_file)
 
1159
                          const char *game_module)
1170
1160
{
1171
1161
  AisleriotWindowPrivate *priv = window->priv;
1172
1162
  char **recent_games, **new_recent;
1173
1163
  gsize i, n_recent = 0, n_new_recent = 0;
1174
1164
 
1175
 
  if (!game_file)
 
1165
  if (!game_module)
1176
1166
    return;
1177
1167
 
1178
1168
  /* Don't store the game type in freecell mode */
1183
1173
 
1184
1174
  if (recent_games == NULL) {
1185
1175
    new_recent = g_new (char *, 2);
1186
 
    new_recent[0] = g_strdup (game_file);
 
1176
    new_recent[0] = g_strdup (game_module);
1187
1177
    new_recent[1] = NULL;
1188
1178
    n_new_recent = 1;
1189
1179
  } else {
1190
1180
    new_recent = g_new (char *, MIN (n_recent + 1, MAX_RECENT) + 1);
1191
1181
    n_new_recent = 0;
1192
1182
 
1193
 
    new_recent[n_new_recent++] = g_strdup (game_file);
 
1183
    new_recent[n_new_recent++] = g_strdup (game_module);
1194
1184
 
1195
1185
    for (i = 0; i < n_recent && n_new_recent < MAX_RECENT; ++i) {
1196
 
      if (g_ascii_strcasecmp (game_file, recent_games[i]) != 0) {
 
1186
      if (g_ascii_strcasecmp (game_module, recent_games[i]) != 0) {
1197
1187
        new_recent[n_new_recent++] = g_strdup (recent_games[i]);
1198
1188
      }
1199
1189
    }
1213
1203
recent_game_cb (GtkAction *action,
1214
1204
                AisleriotWindow *window)
1215
1205
{
1216
 
  const char *game_file;
1217
 
 
1218
 
  game_file = g_object_get_data (G_OBJECT (action), "game");
1219
 
  g_return_if_fail (game_file != NULL);
1220
 
 
1221
 
  aisleriot_window_set_game (window, game_file, NULL);
1222
 
  
1223
 
  ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), game_file);
 
1206
  const char *game_module;
 
1207
 
 
1208
  game_module = g_object_get_data (G_OBJECT (action), "game");
 
1209
  g_return_if_fail (game_module != NULL);
 
1210
 
 
1211
  aisleriot_window_set_game_module (window, game_module, NULL);
 
1212
 
 
1213
  ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), game_module);
1224
1214
}
1225
1215
 
1226
1216
static void
1262
1252
    g_free (tooltip);
1263
1253
 
1264
1254
    g_object_set_data_full (G_OBJECT (action), "game",
1265
 
                            recent_games[i], (GDestroyNotify) g_free);
 
1255
                            ar_filename_to_game_module (recent_games[i]),
 
1256
                            (GDestroyNotify) g_free);
1266
1257
    g_signal_connect (action, "activate",
1267
1258
                      G_CALLBACK (recent_game_cb), window);
1268
1259
    gtk_action_group_add_action (priv->recent_games_group, action);
1475
1466
                 AisleriotWindow *window)
1476
1467
{
1477
1468
  AisleriotWindowPrivate *priv = window->priv;
1478
 
  guint score = 0;
1479
 
  char str[64];
1480
 
 
1481
 
  g_object_get (game, "score", &score, NULL);
1482
 
 
1483
 
  /* Translators: if you want to use localised digits for the game score,
1484
 
   * then translate this string to "%I6d", else to "%6d".
1485
 
   * Do not translate it to anything else!
1486
 
   */
1487
 
  g_snprintf (str, sizeof (str), C_("score", "%6d"), score);
1488
 
  gtk_label_set_text (GTK_LABEL (priv->score_label), str);
 
1469
 
 
1470
  gtk_label_set_text (GTK_LABEL (priv->score_label),
 
1471
                      aisleriot_game_get_score (game));
1489
1472
}
1490
1473
 
1491
1474
static void
1588
1571
 
1589
1572
  g_free (game_name);
1590
1573
 
1591
 
  add_recently_played_game (window, aisleriot_game_get_game_file (game));
 
1574
  add_recently_played_game (window, aisleriot_game_get_game_module (game));
1592
1575
 
1593
1576
  install_recently_played_menu (window);
1594
1577
 
1883
1866
  AisleriotWindowPrivate *priv = window->priv;
1884
1867
 
1885
1868
  if (event->changed_mask & (GDK_WINDOW_STATE_FULLSCREEN | GDK_WINDOW_STATE_MAXIMIZED)) {
1886
 
    gboolean is_fullscreen, is_maximised;
 
1869
    gboolean is_fullscreen;
1887
1870
 
1888
1871
    is_fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;
1889
 
    is_maximised = (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
1890
1872
 
1891
1873
    set_fullscreen_actions (window, is_fullscreen);
1892
1874
 
2472
2454
 
2473
2455
typedef struct {
2474
2456
  AisleriotWindow *window;
2475
 
  char *game_file;
 
2457
  char *game_module;
2476
2458
  GRand *rand;
2477
2459
} LoadIdleData;
2478
2460
 
2482
2464
                        AisleriotWindow *window)
2483
2465
{
2484
2466
  /* Load the default game */
2485
 
  aisleriot_window_set_game (window, DEFAULT_VARIATION, NULL);
 
2467
  aisleriot_window_set_game_module (window, DEFAULT_VARIATION, NULL);
2486
2468
 
2487
2469
  gtk_widget_destroy (dialog);
2488
2470
}
2494
2476
  GError *error = NULL;
2495
2477
  GRand *rand;
2496
2478
 
2497
 
  if (!aisleriot_game_load_game (priv->game, data->game_file, &error)) {
 
2479
  if (!aisleriot_game_load_game (priv->game, data->game_module, &error)) {
2498
2480
    GtkWidget *dialog;
2499
2481
    char *name;
2500
2482
 
2501
 
    name = ar_filename_to_display_name (data->game_file);
 
2483
    name = ar_filename_to_display_name (data->game_module);
2502
2484
 
2503
2485
    dialog = gtk_message_dialog_new (GTK_WINDOW (data->window),
2504
2486
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
2509
2491
    g_free (name);
2510
2492
 
2511
2493
    if (priv->freecell_mode ||
2512
 
        strcmp (data->game_file, DEFAULT_VARIATION) == 0) {
 
2494
        strcmp (data->game_module, DEFAULT_VARIATION) == 0) {
2513
2495
      /* Loading freecell/the fallback game failed; all we can do is exit */
2514
2496
      g_signal_connect_swapped (dialog, "response",
2515
2497
                                G_CALLBACK (gtk_widget_destroy), data->window);
2540
2522
   * store it in conf, except when we're running in freecell mode.
2541
2523
   */
2542
2524
  if (!priv->freecell_mode) {
2543
 
    ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), data->game_file);
 
2525
    char *pref;
 
2526
 
 
2527
    pref = g_strconcat (data->game_module, ".scm", NULL);
 
2528
    ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), pref);
 
2529
    g_free (pref);
2544
2530
  }
2545
2531
 
2546
2532
  rand = data->rand;
2561
2547
  if (data->rand)
2562
2548
    g_rand_free (data->rand);
2563
2549
 
2564
 
  g_free (data->game_file);
 
2550
  g_free (data->game_module);
2565
2551
  g_slice_free (LoadIdleData, data);
2566
2552
}
2567
2553
 
2568
2554
/**
2569
2555
 * aisleriot_window_set_game:
2570
2556
 * @window:
2571
 
 * @game_file: a UTF-8 string
 
2557
 * @game_module: a UTF-8 string
2572
2558
 * @rand: (allow-none) (transfer full): a #GRand, or %NULL
2573
2559
 *
2574
 
 * Loads the game variation defined in the @game_file file.
2575
 
 * Note that even though @game_file is used as a filename,
 
2560
 * Loads the game variation defined in the @game_module file.
 
2561
 * Note that even though @game_module is used as a filename,
2576
2562
 * it must be in UTF-8!
2577
2563
 */
2578
2564
void
2579
 
aisleriot_window_set_game (AisleriotWindow *window,
2580
 
                           const char *game_file,
2581
 
                           GRand *rand)
 
2565
aisleriot_window_set_game_module (AisleriotWindow *window,
 
2566
                                  const char *game_module,
 
2567
                                  GRand *rand)
2582
2568
{
2583
2569
  AisleriotWindowPrivate *priv = window->priv;
2584
2570
  LoadIdleData *data;
2590
2576
 
2591
2577
  data = g_slice_new (LoadIdleData);
2592
2578
  data->window = window;
2593
 
  data->game_file = g_strdup (game_file);
 
2579
  data->game_module = g_strdup (game_module);
2594
2580
  data->rand = rand; /* adopted */
2595
2581
 
2596
2582
  priv->load_idle_id = g_idle_add_full (G_PRIORITY_LOW,
2600
2586
}
2601
2587
 
2602
2588
/**
2603
 
 * aisleriot_window_get_game:
 
2589
 * aisleriot_window_get_game_module:
2604
2590
 * @window:
2605
2591
 *
2606
 
 * Returns: the #AisleriotGame running in @window
 
2592
 * Returns: the name of the game running in @window
2607
2593
 */
2608
 
AisleriotGame *
2609
 
aisleriot_window_get_game (AisleriotWindow *window)
 
2594
const char *
 
2595
aisleriot_window_get_game_module (AisleriotWindow *window)
2610
2596
{
2611
2597
  AisleriotWindowPrivate *priv = window->priv;
2612
2598
 
2613
 
  return priv->game;
 
2599
  return aisleriot_game_get_game_module (priv->game);
2614
2600
}