Пример #1
0
/**
 * irc_context_lookup_setting_boolean:
 * @self: Context to lookup in
 * @setting_name: Setting to lookup
 *
 * If the setting has never been set for a context it will lookup
 * the setting in the parent. If all else fails it uses global settings.
 *
 * Returns: Value of setting
 */
gboolean
irc_context_lookup_setting_boolean (IrcContext *self, const char *setting_name)
{
	GSettings *settings = g_object_get_data (G_OBJECT(self), "settings");

	if (G_UNLIKELY(settings == NULL))
	{
		const char *id = irc_context_get_id (self);
		g_autofree char *path = g_strconcat ("/se/tingping/IrcClient/", id, "/", NULL);
		settings = g_settings_new_with_path ("se.tingping.context", path);
		g_object_set_data_full (G_OBJECT(self), "settings", settings, g_object_unref);
	}

	g_autoptr (GVariant) value = g_settings_get_user_value (settings, setting_name);
	if (value != NULL)
		return g_variant_get_boolean (value);

	IrcContext *parent = irc_context_get_parent (self);
	if (parent)
		return irc_context_lookup_setting_boolean (parent, setting_name);


	static GSettings *global_settings;

	if (G_UNLIKELY(global_settings == NULL))
		global_settings = g_settings_new_with_path ("se.tingping.context", "/se/tingping/IrcClient/");

	return g_settings_get_boolean (global_settings, setting_name);
}
void
gsd_settings_migrate_check (const gchar             *origin_schema,
                            const gchar             *origin_path,
                            const gchar             *dest_schema,
                            const gchar             *dest_path,
                            GsdSettingsMigrateEntry  entries[],
                            guint                    n_entries)
{
        GSettings *origin_settings, *dest_settings;
        GVariant *variant;
        guint i;

        origin_settings = g_settings_new_with_path (origin_schema, origin_path);
        dest_settings = g_settings_new_with_path (dest_schema, dest_path);

        for (i = 0; i < n_entries; i++) {
                variant = g_settings_get_user_value (origin_settings, entries[i].origin_key);

                if (!variant)
                        continue;

                if (entries[i].dest_key) {
                        if (entries[i].func) {
                                GVariant *modified;

                                modified = entries[i].func (variant);
                                g_variant_unref (variant);
                                variant = g_variant_ref_sink (modified);
                        }

                        g_settings_set_value (dest_settings, entries[i].dest_key, variant);
                }

                g_settings_reset (origin_settings, entries[i].origin_key);
                g_variant_unref (variant);
        }

        g_object_unref (origin_settings);
        g_object_unref (dest_settings);
}
Пример #3
0
void migrate_config(GmpvApplication *app)
{
	const gchar *keys[] = {	"dark-theme-enable",
				"csd-enable",
				"last-folder-enable",
				"mpv-options",
				"mpv-config-file",
				"mpv-config-enable",
				"mpv-input-config-file",
				"mpv-input-config-enable",
				NULL };

	GSettings *old_settings = g_settings_new("org.gnome-mpv");
	GSettings *new_settings = g_settings_new(CONFIG_ROOT);

	if(!g_settings_get_boolean(new_settings, "settings-migrated"))
	{
		g_settings_set_boolean(new_settings, "settings-migrated", TRUE);

		for(gint i = 0; keys[i]; i++)
		{
			GVariant *buf = g_settings_get_user_value
						(old_settings, keys[i]);

			if(buf)
			{
				g_settings_set_value
					(new_settings, keys[i], buf);

				g_variant_unref(buf);
			}
		}
	}

	g_object_unref(old_settings);
	g_object_unref(new_settings);
}