~ubuntu-branches/ubuntu/raring/tracker/raring

« back to all changes in this revision

Viewing changes to src/libtracker-common/tracker-config-file.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2011-12-16 18:47:47 UTC
  • mfrom: (4.3.22 sid)
  • Revision ID: package-import@ubuntu.com-20111216184747-0cqqd53tx91buc44
Tags: 0.12.9-1
* New upstream release.
* Change section of gir1.2-tracker-0.12 to introspection.
* Update homepage URL. (Closes: #652141)

Show diffs side-by-side

added added

removed removed

Lines of Context:
413
413
                             NULL);
414
414
}
415
415
 
416
 
gboolean
417
 
tracker_config_file_migrate (TrackerConfigFile           *file,
418
 
                             GSettings                   *settings,
419
 
                             TrackerConfigMigrationEntry *entries)
 
416
static gboolean
 
417
migrate_keyfile_to_settings (TrackerConfigMigrationEntry *entries,
 
418
                             TrackerConfigFile           *file,
 
419
                             GSettings                   *settings)
420
420
{
421
421
        gint i;
422
422
 
423
 
        g_return_val_if_fail (TRACKER_IS_CONFIG_FILE (file), FALSE);
424
 
 
425
 
        if (!file->key_file || !file->file_exists) {
426
 
                return TRUE;
427
 
        }
428
 
 
429
423
        g_message ("Migrating configuration to GSettings...");
430
424
 
431
425
        for (i = 0; entries[i].type != G_TYPE_INVALID; i++) {
433
427
                                         entries[i].file_section,
434
428
                                         entries[i].file_key,
435
429
                                         NULL)) {
 
430
                        g_settings_reset (settings, entries[i].settings_key);
436
431
                        continue;
437
432
                }
438
433
 
487
482
                }
488
483
        }
489
484
 
490
 
        g_file_delete (file->file, NULL, NULL);
491
485
        g_message ("Finished migration to GSettings.");
492
486
 
493
487
        return TRUE;
494
488
}
495
489
 
 
490
static void
 
491
migrate_settings_to_keyfile (TrackerConfigMigrationEntry *entries,
 
492
                             GSettings                   *settings,
 
493
                             TrackerConfigFile           *file)
 
494
{
 
495
        gint i;
 
496
 
 
497
        g_message ("Storing configuration to Keyfile...");
 
498
 
 
499
        for (i = 0; entries[i].type != G_TYPE_INVALID; i++) {
 
500
                switch (entries[i].type) {
 
501
                case G_TYPE_INT:
 
502
                case G_TYPE_ENUM: {
 
503
                        gint val;
 
504
 
 
505
                        if (entries[i].type == G_TYPE_INT) {
 
506
                                val = g_settings_get_int (settings, entries[i].settings_key);
 
507
                        } else {
 
508
                                val = g_settings_get_enum (settings, entries[i].settings_key);
 
509
                        }
 
510
 
 
511
                        g_key_file_set_integer (file->key_file,
 
512
                                                entries[i].file_section,
 
513
                                                entries[i].file_key,
 
514
                                                val);
 
515
                        break;
 
516
                }
 
517
                case G_TYPE_BOOLEAN: {
 
518
                        gboolean val;
 
519
 
 
520
                        val = g_settings_get_boolean (settings, entries[i].settings_key);
 
521
                        g_key_file_set_boolean (file->key_file,
 
522
                                                entries[i].file_section,
 
523
                                                entries[i].file_key,
 
524
                                                val);
 
525
                        break;
 
526
                }
 
527
                case G_TYPE_POINTER: {
 
528
                        gchar **vals;
 
529
 
 
530
                        vals = g_settings_get_strv (settings, entries[i].settings_key);
 
531
 
 
532
                        if (vals) {
 
533
                                g_key_file_set_string_list (file->key_file,
 
534
                                                            entries[i].file_section,
 
535
                                                            entries[i].file_key,
 
536
                                                            (const gchar * const *)vals,
 
537
                                                            g_strv_length (vals));
 
538
                                g_strfreev (vals);
 
539
                        }
 
540
 
 
541
                        break;
 
542
                }
 
543
                default:
 
544
                        g_assert_not_reached ();
 
545
                        break;
 
546
                }
 
547
        }
 
548
}
 
549
 
 
550
typedef struct {
 
551
        TrackerConfigFile *file;
 
552
        TrackerConfigMigrationEntry *entries;
 
553
} UnappliedNotifyData;
 
554
 
 
555
static void
 
556
settings_has_unapplied_notify (GObject    *object,
 
557
                               GParamSpec *pspec,
 
558
                               gpointer    user_data)
 
559
{
 
560
        UnappliedNotifyData *data = user_data;
 
561
 
 
562
        if (!g_settings_get_has_unapplied (G_SETTINGS (object))) {
 
563
                /* Dump to config file too */
 
564
                migrate_settings_to_keyfile (data->entries,
 
565
                                             G_SETTINGS (object),
 
566
                                             data->file);
 
567
                tracker_config_file_save (data->file);
 
568
        }
 
569
}
 
570
 
 
571
gboolean
 
572
tracker_config_file_migrate (TrackerConfigFile           *file,
 
573
                             GSettings                   *settings,
 
574
                             TrackerConfigMigrationEntry *entries)
 
575
{
 
576
        g_return_val_if_fail (TRACKER_IS_CONFIG_FILE (file), FALSE);
 
577
 
 
578
        if (file->key_file && file->file_exists) {
 
579
                migrate_keyfile_to_settings (entries, file, settings);
 
580
        }
 
581
 
 
582
        if (g_getenv ("TRACKER_USE_CONFIG_FILES")) {
 
583
                UnappliedNotifyData *data;
 
584
 
 
585
                /* Ensure we have the config file in place */
 
586
                if (!file->file_exists) {
 
587
                        migrate_settings_to_keyfile (entries,
 
588
                                                     settings,
 
589
                                                     file);
 
590
                        tracker_config_file_save (file);
 
591
                }
 
592
 
 
593
                /* Keep the file around, and connect to notify::has-unapplied so
 
594
                 * we write back to it when g_settings_apply() is called
 
595
                 */
 
596
                data = g_new (UnappliedNotifyData, 1);
 
597
                data->file = g_object_ref (file);
 
598
                data->entries = entries;
 
599
 
 
600
                g_signal_connect (settings, "notify::has-unapplied",
 
601
                                  G_CALLBACK (settings_has_unapplied_notify),
 
602
                                  data);
 
603
        } else {
 
604
                /* The config file has been migrated to GSettings, delete it */
 
605
                g_file_delete (file->file, NULL, NULL);
 
606
        }
 
607
 
 
608
        return TRUE;
 
609
}