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

« back to all changes in this revision

Viewing changes to src/conf.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:
71
71
static GHashTable *stats;
72
72
 
73
73
static char *
74
 
options_gconf_key (const char *game_file)
 
74
options_gconf_key (const char *game_module)
75
75
{
76
76
  static const char basekey[] = "/apps/aisleriot/rules/";
77
77
 
78
 
  return g_strconcat (basekey, game_file, NULL);
 
78
  return g_strdelimit (g_strconcat (basekey, game_module, ".scm", NULL), "-", '_');
 
79
}
 
80
 
 
81
static char *
 
82
game_module_to_game_name (const char *game_module)
 
83
{
 
84
  char *game_name;
 
85
 
 
86
  game_name = g_strdelimit (g_strconcat (game_module, ".scm", NULL), "-", '_');
 
87
 
 
88
  return game_name;
79
89
}
80
90
 
81
91
static void
183
193
  }
184
194
 
185
195
#ifdef HAVE_GNOME
186
 
  
 
196
 
187
197
  gconf_client = gconf_client_get_default ();
188
198
 
189
199
  stats = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
217
227
}
218
228
 
219
229
gboolean
220
 
aisleriot_conf_get_options (const char *game_file,
 
230
aisleriot_conf_get_options (const char *game_module,
221
231
                            int *options)
222
232
{
223
233
#ifdef HAVE_GNOME
225
235
  GConfValue *value;
226
236
  char *gconf_key;
227
237
 
228
 
  gconf_key = options_gconf_key (game_file);
 
238
  gconf_key = options_gconf_key (game_module);
229
239
  entry = gconf_client_get_entry (gconf_client, gconf_key, NULL, TRUE, NULL);
230
240
  g_free (gconf_key);
231
241
  if (!entry)
244
254
  return TRUE;
245
255
#else
246
256
  GError *error = NULL;
 
257
  char *game_name;
247
258
 
248
 
  *options = ar_conf_get_integer (game_file, "Options", &error);
 
259
  game_name = game_module_to_game_name (game_module);
 
260
  *options = ar_conf_get_integer (game_name, "Options", &error);
 
261
  g_free (game_name);
249
262
  if (error) {
250
263
    g_error_free (error);
251
264
    return FALSE;
256
269
}
257
270
 
258
271
void
259
 
aisleriot_conf_set_options (const char *game_file,
 
272
aisleriot_conf_set_options (const char *game_module,
260
273
                            int value)
261
274
{
262
275
#ifdef HAVE_GNOME
263
276
  GConfSchema *schema;
264
277
  char *gconf_key, *schemas_key;
265
278
 
266
 
  gconf_key = options_gconf_key (game_file);
 
279
  gconf_key = options_gconf_key (game_module);
267
280
 
268
281
  schemas_key = g_strconcat ("/schemas", gconf_key, NULL);
269
282
 
296
309
  gconf_client_set_int (gconf_client, gconf_key, value, NULL);
297
310
  g_free (gconf_key);
298
311
#else
299
 
  ar_conf_set_integer (game_file, "Options", value);
 
312
  char *game_name;
 
313
 
 
314
  game_name = game_module_to_game_name (game_module);
 
315
  ar_conf_set_integer (game_name, "Options", value);
 
316
  g_free (game_name);
300
317
#endif /* HAVE_GNOME */
301
318
}
302
319
 
303
320
void
304
 
aisleriot_conf_get_statistic (const char *game_file,
 
321
aisleriot_conf_get_statistic (const char *game_module,
305
322
                              AisleriotStatistic *statistic)
306
323
{
307
324
#ifdef HAVE_GNOME
308
325
  AisleriotStatistic *game_stat;
309
 
 
310
 
  game_stat = g_hash_table_lookup (stats, game_file);
 
326
  char *game_name;
 
327
 
 
328
  game_name = game_module_to_game_name (game_module);
 
329
 
 
330
  game_stat = g_hash_table_lookup (stats, game_name);
311
331
  if (!game_stat) {
312
332
    char *display_name;
313
333
 
314
334
    /* Previous versions used the localised name as key, so try it as fall-back.
315
335
     * See bug #406267 and bug #525177.
316
336
     */
317
 
    display_name = ar_filename_to_display_name (game_file);
 
337
    display_name = ar_filename_to_display_name (game_module);
318
338
    game_stat = g_hash_table_lookup (stats, display_name);
319
339
    g_free (display_name);
320
340
  }
325
345
    memset (statistic, 0, sizeof (AisleriotStatistic));
326
346
  }
327
347
 
 
348
  g_free (game_name);
 
349
 
328
350
#else
329
351
 
330
352
  int *values;
331
353
  gsize len = 0;
332
354
  GError *error = NULL;
 
355
  char *game_name;
 
356
 
 
357
  game_name = game_module_to_game_name (game_module);
333
358
 
334
359
  memset (statistic, 0, sizeof (AisleriotStatistic));
335
360
 
336
 
  values = ar_conf_get_integer_list (game_file, "Statistic", &len, &error);
 
361
  values = ar_conf_get_integer_list (game_name, "Statistic", &len, &error);
337
362
  if (error) {
338
363
    g_error_free (error);
 
364
    g_free (game_name);
339
365
    return;
340
366
  }
341
367
  if (len != 4) {
342
368
    g_free (values);
 
369
    g_free (game_name);
343
370
    return;
344
371
  }
345
372
 
358
385
  }
359
386
 
360
387
  g_free (values);
 
388
  g_free (game_name);
361
389
#endif /* HAVE_GNOME */
362
390
}
363
391
 
364
392
void
365
 
aisleriot_conf_set_statistic (const char *game_file,
 
393
aisleriot_conf_set_statistic (const char *game_module,
366
394
                              AisleriotStatistic *statistic)
367
395
{
368
396
#ifdef HAVE_GNOME
369
397
  AisleriotStatistic *game_stat;
370
 
 
371
 
  game_stat = g_hash_table_lookup (stats, game_file);
 
398
  char *game_name;
 
399
 
 
400
  game_name = game_module_to_game_name (game_module);
 
401
 
 
402
  game_stat = g_hash_table_lookup (stats, game_name);
372
403
  /* Backward compatibility with buggy old aisleriot versions
373
404
   * which stored the localised game name.
374
405
   */
375
406
  if (!game_stat) {
376
407
    char *localised_name;
377
408
 
378
 
    localised_name = ar_filename_to_display_name (game_file);
 
409
    localised_name = ar_filename_to_display_name (game_module);
379
410
    game_stat = g_hash_table_lookup (stats, localised_name);
380
411
    g_free (localised_name);
381
412
  }
382
413
 
383
414
  if (!game_stat) {
384
415
    game_stat = g_new0 (AisleriotStatistic, 1);
385
 
    g_hash_table_insert (stats, g_strdup (game_file), game_stat);
 
416
    g_hash_table_insert (stats, g_strdup (game_name), game_stat);
386
417
  }
387
418
 
388
419
  *game_stat = *statistic;
389
420
 
390
421
  save_statistics ();
391
422
 
 
423
  g_free (game_name);
 
424
 
392
425
#else
393
426
 
 
427
  char *game_name;
394
428
  int values[4];
395
429
 
 
430
  game_name = game_module_to_game_name (game_module);
 
431
 
396
432
  values[0] = statistic->wins;
397
433
  values[1] = statistic->total;
398
434
  values[2] = statistic->best;
399
435
  values[3] = statistic->worst;
400
436
 
401
 
  ar_conf_set_integer_list (game_file, "Statistic", values, G_N_ELEMENTS (values));
 
437
  ar_conf_set_integer_list (game_name, "Statistic", values, G_N_ELEMENTS (values));
 
438
 
 
439
  g_free (game_name);
402
440
#endif /* HAVE_GNOME */
403
441
}