Example #1
0
static gboolean
gconf_settings_backend_write_tree (GSettingsBackend *backend,
                                   GTree            *tree,
                                   gpointer          origin_tag)
{
  GConfSettingsBackend *gconf = GCONF_SETTINGS_BACKEND (backend);
  GConfChangeSet       *changeset;
  GConfChangeSet       *reversed;
  gboolean              success;

  changeset = gconf_change_set_new ();

  g_tree_foreach (tree, (GTraverseFunc) gconf_settings_backend_write_one_to_changeset, changeset);

  if (gconf_change_set_size (changeset) != g_tree_nnodes (tree))
    {
      gconf_change_set_unref (changeset);
      return FALSE;
    }

  reversed = gconf_client_reverse_change_set (gconf->priv->client, changeset, NULL);
  success = gconf_client_commit_change_set (gconf->priv->client, changeset, TRUE, NULL);

  g_tree_foreach (tree, (GTraverseFunc) gconf_settings_backend_add_ignore_notifications, gconf);

  if (!success)
    {
      /* This is a tricky situation: when committing, some keys will have been
       * changed, so there will be notifications that we'll want to ignore. But
       * we can't ignore notifications for what was not committed. Note that
       * when we'll commit the reversed changeset, it should fail for the same
       * key, so there'll be no other notifications created. And in the worst
       * case, it's no big deal... */
      gconf_change_set_foreach (changeset,
                                (GConfChangeSetForeachFunc) gconf_settings_backend_remove_ignore_notifications,
                                gconf);
      gconf_client_commit_change_set (gconf->priv->client, reversed, FALSE, NULL);
    }
  else
    g_settings_backend_changed_tree (backend, tree, origin_tag);

  gconf_change_set_unref (changeset);
  gconf_change_set_unref (reversed);

  return success;
}
Example #2
0
static void
g_keyfile_settings_backend_keyfile_reload (GKeyfileSettingsBackend *kfsb)
{
  guint8 digest[32];
  gchar *contents;
  gsize length;

  contents = NULL;
  length = 0;

  g_file_load_contents (kfsb->file, NULL, &contents, &length, NULL, NULL);
  compute_checksum (digest, contents, length);

  if (memcmp (kfsb->digest, digest, sizeof digest) != 0)
    {
      GKeyFile *keyfiles[2];
      GTree *tree;

      tree = g_tree_new_full ((GCompareDataFunc) strcmp, NULL,
                              g_free, g_free);

      keyfiles[0] = kfsb->keyfile;
      keyfiles[1] = g_key_file_new ();

      if (length > 0)
        g_key_file_load_from_data (keyfiles[1], contents, length,
                                   G_KEY_FILE_KEEP_COMMENTS |
                                   G_KEY_FILE_KEEP_TRANSLATIONS, NULL);

      keyfile_to_tree (kfsb, tree, keyfiles[0], FALSE);
      keyfile_to_tree (kfsb, tree, keyfiles[1], TRUE);
      g_key_file_free (keyfiles[0]);
      kfsb->keyfile = keyfiles[1];

      if (g_tree_nnodes (tree) > 0)
        g_settings_backend_changed_tree (&kfsb->parent_instance, tree, NULL);

      g_tree_unref (tree);

      memcpy (kfsb->digest, digest, sizeof digest);
    }

  g_free (contents);
}
Example #3
0
static gboolean
g_keyfile_settings_backend_write_tree (GSettingsBackend *backend,
                                       GTree            *tree,
                                       gpointer          origin_tag)
{
  WriteManyData data = { G_KEYFILE_SETTINGS_BACKEND (backend) };

  if (!data.kfsb->writable)
    return FALSE;

  g_tree_foreach (tree, g_keyfile_settings_backend_check_one, &data);

  if (data.failed)
    return FALSE;

  g_tree_foreach (tree, g_keyfile_settings_backend_write_one, &data);
  g_keyfile_settings_backend_keyfile_write (data.kfsb);

  g_settings_backend_changed_tree (backend, tree, origin_tag);

  return TRUE;
}