~ubuntu-branches/ubuntu/precise/gnome-games/precise-proposed

« back to all changes in this revision

Viewing changes to libgames-support/games-files.c

  • Committer: Package Import Robot
  • Author(s): Rodrigo Moya
  • Date: 2011-05-30 13:32:04 UTC
  • mfrom: (1.3.4)
  • mto: (163.1.3 precise)
  • mto: This revision was merged to the branch mainline in revision 143.
  • Revision ID: package-import@ubuntu.com-20110530133204-celaq1v1dsxc48q1
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
G_DEFINE_TYPE (GamesFileList, games_file_list, G_TYPE_OBJECT)
48
48
 
 
49
struct GamesFileListPrivate
 
50
{
 
51
  GList *list;
 
52
};
 
53
 
49
54
/* Remove duplicate names form the list */
50
 
     static void
51
 
       games_file_list_remove_duplicates (GamesFileList * filelist)
 
55
static void
 
56
games_file_list_remove_duplicates (GamesFileList * filelist)
52
57
{
53
58
  GList *l;
54
59
 
55
60
  if (filelist == NULL)
56
61
    return;
57
62
 
58
 
  l = filelist->list;
 
63
  l = filelist->priv->list;
59
64
 
60
65
  if ((l == NULL) || (l->next == NULL))
61
66
    return;
123
128
  filelist = g_object_new (GAMES_FILE_LIST_TYPE, NULL);
124
129
 
125
130
  va_start (paths, glob);
126
 
  filelist->list = games_file_list_new_internal (glob, paths);
 
131
  filelist->priv->list = games_file_list_new_internal (glob, paths);
127
132
  va_end (paths);
128
133
 
129
 
  filelist->list =
130
 
    g_list_sort (filelist->list, (GCompareFunc) g_utf8_collate);
 
134
  filelist->priv->list =
 
135
    g_list_sort (filelist->priv->list, (GCompareFunc) g_utf8_collate);
131
136
  games_file_list_remove_duplicates (filelist);
132
137
 
133
138
  return filelist;
137
142
void
138
143
games_file_list_transform_basename (GamesFileList * filelist)
139
144
{
140
 
  GList *current = filelist->list;
 
145
  GList *current = filelist->priv->list;
141
146
  gchar *shortname;
142
147
 
143
148
  while (current) {
262
267
 
263
268
  filelist = g_object_new (GAMES_FILE_LIST_TYPE, NULL);
264
269
 
265
 
  filelist->list = games_file_list_new_images_single (path1);
 
270
  filelist->priv->list = games_file_list_new_images_single (path1);
266
271
  va_start (paths, path1);
267
272
  while ((pathentry = va_arg (paths, gchar *)) != NULL) {
268
 
    list = g_list_concat (filelist->list,
 
273
    list = g_list_concat (filelist->priv->list,
269
274
                          games_file_list_new_images_single (pathentry));
270
275
  }
271
276
  va_end (paths);
272
277
 
273
 
  filelist->list =
274
 
    g_list_sort (filelist->list, (GCompareFunc) g_utf8_collate);
 
278
  filelist->priv->list =
 
279
    g_list_sort (filelist->priv->list, (GCompareFunc) g_utf8_collate);
275
280
  games_file_list_remove_duplicates (filelist);
276
281
 
277
282
  return filelist;
279
284
 
280
285
/**
281
286
 * games_file_list_create_widget:
282
 
 * @gamesfilelist: The list of files to use.
 
287
 * @filelist: The list of files to use.
283
288
 * @selection: The name to select as the default. NULL means no default.
284
289
 * @flags: A set of flags to specify how the names are displayed. 
285
290
 * 
290
295
 * removes extensions, and GAMES_FILE_LIST_REPLACE_UNDERSCORES with replaces
291
296
 * underscores with spaces.
292
297
 * 
293
 
 * Return value: A widget with the list of names.
 
298
 * Return value: (transfer full): A widget with the list of names.
294
299
 **/
295
300
GtkWidget *
296
 
games_file_list_create_widget (GamesFileList * gamesfilelist,
 
301
games_file_list_create_widget (GamesFileList * filelist,
297
302
                               const gchar * selection, guint flags)
298
303
{
299
304
  gint itemno;
300
305
  GtkComboBox *widget;
301
306
  gchar *visible, *string;
302
 
  GList *filelist = gamesfilelist->list;
 
307
  GList *iter = filelist->priv->list;
303
308
  gboolean found = FALSE;
304
309
 
305
 
  widget = GTK_COMBO_BOX (gtk_combo_box_new_text ());
 
310
  widget = GTK_COMBO_BOX (gtk_combo_box_text_new ());
306
311
 
307
312
  itemno = 0;
308
 
  while (filelist) {
 
313
  while (iter) {
309
314
    gchar *s;
310
315
 
311
 
    string = (gchar *) filelist->data;
 
316
    string = (gchar *) iter->data;
312
317
    visible = g_strdup (string);
313
318
 
314
319
    /* These are a bit hackish, but we don't yet have a good regexp
328
333
      }
329
334
    }
330
335
 
331
 
    gtk_combo_box_append_text (widget, visible);
 
336
    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), visible);
332
337
    if (selection && (!strcmp (string, selection))) {
333
338
      gtk_combo_box_set_active (widget, itemno);
334
339
      found = TRUE;
337
342
    g_free (visible);
338
343
 
339
344
    itemno++;
340
 
    filelist = g_list_next (filelist);
 
345
    iter = g_list_next (iter);
341
346
  }
342
347
  if (!found)
343
348
    gtk_combo_box_set_active (widget, 0);
348
353
/**
349
354
 * games_file_list_for_each:
350
355
 * @filelist: The file list to iterate over.
351
 
 * @function: The function to call on each item. It gets called with two 
 
356
 * @function: (scope call): The function to call on each item. It gets called with two 
352
357
 * arguments: the file name and the pointer supplied to this function in 
353
358
 * the userdata argument.
354
 
 * @userdata: An arbitrary pointer that gets passed as the second argument
 
359
 * @userdata: (closure): An arbitrary pointer that gets passed as the second argument
355
360
 * to each call of function.
356
361
 * 
357
362
 * Apply a function to each file name in the list.
358
363
 **/
359
364
void
360
365
games_file_list_for_each (GamesFileList * filelist, GFunc function,
361
 
                          gpointer userdata)
 
366
                          gpointer userdata)
362
367
{
363
 
  g_list_foreach (filelist->list, function, userdata);
 
368
  g_list_foreach (filelist->priv->list, function, userdata);
364
369
}
365
370
 
366
371
/**
367
372
 * games_file_list_find:
368
373
 * @filelist: The file list to iterate over.
369
 
 * @function: The function to call on each item. It gets called with two 
 
374
 * @function: (scope call): The function to call on each item. It gets called with two 
370
375
 * arguments: the file name and the pointer supplied to this function in 
371
376
 * the userdata argument.
372
 
 * @userdata: An arbitrary pointer that gets passed as the second argument
 
377
 * @userdata: (closure): An arbitrary pointer that gets passed as the second argument
373
378
 * to each call of function.
374
379
 * 
375
380
 * Find a file name by iterating through a list until the given function
384
389
{
385
390
  GList *element;
386
391
 
387
 
  element = g_list_find_custom (filelist->list, userdata, function);
 
392
  element = g_list_find_custom (filelist->priv->list, userdata, function);
388
393
 
389
394
  return element ? g_strdup ((gchar *) element->data) : NULL;
390
395
}
402
407
gchar *
403
408
games_file_list_get_nth (GamesFileList * filelist, gint n)
404
409
{
405
 
  return (gchar *) g_list_nth_data (filelist->list, n);
 
410
  return (gchar *) g_list_nth_data (filelist->priv->list, n);
406
411
}
407
412
 
408
413
static void
413
418
  /* For simplicity we haven't used the dispose method since we can
414
419
   * guarantee that everything this references doesn't reference itself. */
415
420
 
416
 
  g_list_foreach (filelist->list, (GFunc) g_free, NULL);
417
 
  g_list_free (filelist->list);
 
421
  g_list_foreach (filelist->priv->list, (GFunc) g_free, NULL);
 
422
  g_list_free (filelist->priv->list);
418
423
 
419
424
  G_OBJECT_CLASS (games_file_list_parent_class)->finalize (object);
420
425
}
425
430
  GObjectClass *oclass = G_OBJECT_CLASS (class);
426
431
 
427
432
  oclass->finalize = games_file_list_finalize;
 
433
 
 
434
  g_type_class_add_private (oclass, sizeof (GamesFileListPrivate));
428
435
}
429
436
 
430
437
static void
431
438
games_file_list_init (GamesFileList * filelist)
432
439
{
 
440
  filelist->priv = G_TYPE_INSTANCE_GET_PRIVATE (filelist, GAMES_FILE_LIST_TYPE, GamesFileListPrivate);
433
441
}