示例#1
0
static gchar *
get_desktop_dir (void)
{
  gboolean desktop_is_home_dir = FALSE;
  gchar *desktop_dir;
  gboolean schema_exists = FALSE;

  /* Check if caja schema is installed before trying to read settings */
  GSettingsSchema *schema = g_settings_schema_source_lookup (g_settings_schema_source_get_default (),
                                                             CAJA_PREFERENCES_SCHEMA,
                                                             FALSE);

  if (schema != NULL) {
    GSettings *caja_prefs;

    caja_prefs = g_settings_new (CAJA_PREFERENCES_SCHEMA);
    desktop_is_home_dir = g_settings_get_boolean (caja_prefs, "desktop-is-home-dir");

    g_object_unref (caja_prefs);
    g_settings_schema_unref (schema);
  }

  if (desktop_is_home_dir)
    desktop_dir = g_strconcat ("file://", g_get_home_dir (), NULL);
  else
    desktop_dir = g_strconcat ("file://", g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP), NULL);

  return desktop_dir;
}
示例#2
0
static void
on_gsettings_changed_active (GSettings *settings,
                             gchar     *key,
                             GtkWidget *widget)
{
  GtkListStore          *store;
  GSettingsSchemaSource *schema_source;
  GList                 *schema_list = NULL;
  gchar                **non_relocatable;
  const gchar           *id1;
  GtkTreeIter            iter;
  gint                   i;

  id1 = gtk_combo_box_get_active_id (GTK_COMBO_BOX (widget));
  store = (GtkListStore *) gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
  gtk_list_store_clear (store);

  gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
  schema_source = g_settings_schema_source_get_default ();
  g_settings_schema_source_list_schemas (schema_source, TRUE,
                                         &non_relocatable, NULL);

  for (i = 0; non_relocatable[i] != NULL; i++)
    if (g_str_has_prefix (non_relocatable[i], "org.nimf.engines."))
      schema_list = g_list_prepend (schema_list, non_relocatable[i]);

  for (schema_list = g_list_sort (schema_list, (GCompareFunc) on_comparison);
       schema_list != NULL;
       schema_list = schema_list->next)
  {
    GSettingsSchema *schema;
    GSettings       *gsettings;
    gchar           *name;
    const gchar     *id2;

    schema = g_settings_schema_source_lookup (schema_source,
                                              schema_list->data, TRUE);
    gsettings = g_settings_new (schema_list->data);
    name = g_settings_get_string (gsettings, "hidden-schema-name");
    id2 = schema_list->data + strlen ("org.nimf.engines.");

    if (g_settings_schema_has_key (schema, "active") == FALSE ||
        g_settings_get_boolean (gsettings, "active"))
    {
      gtk_list_store_append (store, &iter);
      gtk_list_store_set (store, &iter, 0, name, 1, id2, -1);
    }

    g_settings_schema_unref (schema);
    g_free (name);
    g_object_unref (gsettings);
  }

  if (gtk_combo_box_set_active_id (GTK_COMBO_BOX (widget), id1) == FALSE)
    gtk_combo_box_set_active_id (GTK_COMBO_BOX (widget), "nimf-system-keyboard");

  g_strfreev (non_relocatable);
  g_list_free (schema_list);
}
示例#3
0
bool QGSettings::isSchemaInstalled(const QString &schemaId)
{
    GSettingsSchemaSource *source = g_settings_schema_source_get_default();
    GSettingsSchema *schema = g_settings_schema_source_lookup(source, schemaId.toUtf8().constData(), true);
    if (schema) {
        g_settings_schema_unref(schema);
        return true;
    } else {
        return false;
    }
}
示例#4
0
eric_window* eric_window_create( int width, int height, char* title )
{
    eric_window* w = malloc( sizeof( eric_window ) );
    w->draw_callback = NULL;

    if( title == NULL )
    {
        title = "eric window";
    }

	w->window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    gtk_window_set_title( GTK_WINDOW( w->window ), title );
	gtk_window_resize( GTK_WINDOW( w->window ), width, height );
	gtk_widget_add_events( w->window, GDK_STRUCTURE_MASK );

    gtk_widget_set_app_paintable( w->window, TRUE );

    g_signal_connect( G_OBJECT( w->window ), "draw", G_CALLBACK(eric_window_draw), (gpointer)w );
    g_signal_connect( G_OBJECT( w->window ), "screen-changed", G_CALLBACK(eric_window_screen_changed), (gpointer)w );
	g_signal_connect( G_OBJECT( w->window ), "delete-event", gtk_main_quit, NULL );

    eric_window_screen_changed( w->window, NULL, NULL );

    /* GSettings Stuff */
    GSettings* gsettings;
    GSettingsSchema* gsettings_schema;

    gsettings_schema = g_settings_schema_source_lookup( g_settings_schema_source_get_default(),
                                                "org.gnome.desktop.background",
                                                TRUE );
    if( gsettings_schema )
    {
        g_settings_schema_unref (gsettings_schema);
        gsettings_schema = NULL;
        gsettings = g_settings_new ( "org.gnome.desktop.background" );
    }

    g_signal_connect_data( gsettings, "changed", G_CALLBACK( eric_window_gsettings_value_changed ), (gpointer)w, 0, 0 );
    gdk_rgba_parse( &w->background_color, g_settings_get_string( gsettings, "primary-color" ) );
    if( gdk_rgba_get_luminance( &w->background_color ) > 0.5 )
        gdk_rgba_parse( &w->text_color, "#000000" );
    else
        gdk_rgba_parse( &w->text_color, "#FFFFFF" );

    return w;
}
static gboolean
cc_sharing_panel_check_schema_available (CcSharingPanel *self,
                                         const gchar *schema_id)
{
  GSettingsSchemaSource *source;
  GSettingsSchema *schema;

  source = g_settings_schema_source_get_default ();
  if (!source)
    return FALSE;

  schema = g_settings_schema_source_lookup (source, schema_id, TRUE);
  if (!schema)
    return FALSE;

  g_settings_schema_unref (schema);
  return TRUE;
}
示例#6
0
/**
 * g_settings_schema_source_lookup:
 * @source: a #GSettingsSchemaSource
 * @schema_id: a schema ID
 * @recursive: %TRUE if the lookup should be recursive
 *
 * Looks up a schema with the identifier @schema_id in @source.
 *
 * This function is not required for normal uses of #GSettings but it
 * may be useful to authors of plugin management systems or to those who
 * want to introspect the content of schemas.
 *
 * If the schema isn't found directly in @source and @recursive is %TRUE
 * then the parent sources will also be checked.
 *
 * If the schema isn't found, %NULL is returned.
 *
 * Returns: (transfer full): a new #GSettingsSchema
 *
 * Since: 2.32
 **/
GSettingsSchema *
g_settings_schema_source_lookup (GSettingsSchemaSource *source,
                                 const gchar           *schema_id,
                                 gboolean               recursive)
{
  GSettingsSchema *schema;
  GvdbTable *table;
  const gchar *extends;

  g_return_val_if_fail (source != NULL, NULL);
  g_return_val_if_fail (schema_id != NULL, NULL);

  table = gvdb_table_get_table (source->table, schema_id);

  if (table == NULL && recursive)
    for (source = source->parent; source; source = source->parent)
      if ((table = gvdb_table_get_table (source->table, schema_id)))
        break;

  if (table == NULL)
    return NULL;

  schema = g_slice_new0 (GSettingsSchema);
  schema->source = g_settings_schema_source_ref (source);
  schema->ref_count = 1;
  schema->id = g_strdup (schema_id);
  schema->table = table;
  schema->path = g_settings_schema_get_string (schema, ".path");
  schema->gettext_domain = g_settings_schema_get_string (schema, ".gettext-domain");

  if (schema->gettext_domain)
    bind_textdomain_codeset (schema->gettext_domain, "UTF-8");

  extends = g_settings_schema_get_string (schema, ".extends");
  if (extends)
    {
      schema->extends = g_settings_schema_source_lookup (source, extends, TRUE);
      if (schema->extends == NULL)
        g_warning ("Schema '%s' extends schema '%s' but we could not find it", schema_id, extends);
    }

  return schema;
}
示例#7
0
static NimfSettingsPage *
nimf_settings_page_new (NimfSettings *nsettings,
                        const gchar  *schema_id)
{
  NimfSettingsPage *page;
  GSettingsSchema  *schema;
  GList            *key_list = NULL;
  gchar           **keys;
  GList            *l;
  gint              i;

  page = g_slice_new0 (NimfSettingsPage);
  page->gsettings = g_settings_new (schema_id);
  page->label = nimf_settings_page_build_label (page, schema_id);
  page->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 15);
  page->page_keys = g_ptr_array_new_with_free_func ((GDestroyNotify) nimf_settings_page_key_free);

#if GTK_CHECK_VERSION (3, 12, 0)
  gtk_widget_set_margin_start  (page->box, 15);
  gtk_widget_set_margin_end    (page->box, 15);
#else
  gtk_widget_set_margin_left   (page->box, 15);
  gtk_widget_set_margin_right  (page->box, 15);
#endif

  gtk_widget_set_margin_top    (page->box, 15);
  gtk_widget_set_margin_bottom (page->box, 15);

  schema = g_settings_schema_source_lookup (nsettings->schema_source,
                                            schema_id, TRUE);
#if GLIB_CHECK_VERSION (2, 46, 0)
  keys = g_settings_schema_list_keys (schema);
#else
  keys = g_settings_list_keys (page->gsettings);
#endif

  for (i = 0; keys[i] != NULL; i++)
    key_list = g_list_prepend (key_list, keys[i]);

  key_list = g_list_sort (key_list, (GCompareFunc) on_comparison);

  for (i = 0, l = key_list; l != NULL; l = l->next, i++)
  {
    GVariant            *variant;
    GSettingsSchemaKey  *schema_key = NULL;
    NimfSettingsPageKey *page_key;
    const GVariantType  *type;
    const gchar         *key;
    const gchar         *summary;
    const gchar         *desc;

    key = l->data;

    if (g_str_has_prefix (key, "hidden-"))
      continue;

    variant = g_settings_get_value (page->gsettings, key);
    type = g_variant_get_type (variant);
    schema_key = g_settings_schema_get_key (schema, key);
    summary = g_settings_schema_key_get_summary     (schema_key);
    desc    = g_settings_schema_key_get_description (schema_key);

    page_key = nimf_settings_page_key_new (page->gsettings, key, summary, desc);
    g_ptr_array_add (page->page_keys, page_key);

    if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
    {
      GtkWidget *item;
      item = nimf_settings_page_key_build_boolean (page_key);
      gtk_box_pack_start (GTK_BOX (page->box), item, FALSE, FALSE, 0);
    }
    else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
    {
      GtkWidget *item;
      item = nimf_settings_page_key_build_string (page_key, schema_id, key_list);
      gtk_box_pack_start (GTK_BOX (page->box), item, FALSE, FALSE, 0);
    }
    else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING_ARRAY))
    {
      GtkWidget *item;
      item = nimf_settings_page_key_build_string_array (page_key);
      gtk_box_pack_start (GTK_BOX (page->box), item, FALSE, FALSE, 0);
    }
    else
      g_error (G_STRLOC ": %s: not supported variant type: \"%s\"",
               G_STRFUNC, (gchar *) type);

    g_settings_schema_key_unref (schema_key);
    g_variant_unref (variant);
  }

  g_strfreev (keys);
  g_list_free (key_list);
  g_settings_schema_unref (schema);

  return page;
}
示例#8
0
static GtkWidget *
nimf_settings_page_key_build_string (NimfSettingsPageKey *page_key,
                                     const gchar         *schema_id,
                                     GList               *key_list)
{
  GtkListStore *store;
  GtkWidget    *combo;
  GtkWidget    *hbox;
  gchar        *detailed_signal;
  GtkTreeIter   iter;

  store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
  combo = gtk_combo_box_text_new ();
  gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (store));
  g_object_unref (store);
  gtk_combo_box_set_id_column (GTK_COMBO_BOX (combo), 1);
  gtk_tree_model_get_iter_first ((GtkTreeModel *) store, &iter);

  if (g_strcmp0 (schema_id, "org.nimf.engines") == 0 &&
      g_strcmp0 (page_key->key, "default-engine") == 0)
  {
    GSettingsSchemaSource *schema_source;
    GList                 *schema_list = NULL;
    gchar                **non_relocatable;
    gchar                 *id1;
    gint                   i;

    id1 = g_settings_get_string (page_key->gsettings, page_key->key);
    schema_source = g_settings_schema_source_get_default ();
    g_settings_schema_source_list_schemas (schema_source, TRUE,
                                           &non_relocatable, NULL);

    for (i = 0; non_relocatable[i] != NULL; i++)
      if (g_str_has_prefix (non_relocatable[i], "org.nimf.engines."))
        schema_list = g_list_prepend (schema_list, non_relocatable[i]);

    for (schema_list = g_list_sort (schema_list, (GCompareFunc) on_comparison);
         schema_list != NULL;
         schema_list = schema_list->next)
    {
      GSettingsSchema *schema;
      GSettings       *gsettings;
      gchar           *name;
      const gchar     *id2;

      schema = g_settings_schema_source_lookup (schema_source,
                                                schema_list->data, TRUE);
      gsettings = g_settings_new (schema_list->data);
      name = g_settings_get_string (gsettings, "hidden-schema-name");
      id2 = schema_list->data + strlen ("org.nimf.engines.");

      if (g_settings_schema_has_key (schema, "active") == FALSE ||
          g_settings_get_boolean (gsettings, "active"))
      {
        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter, 0, name, 1, id2, -1);
      }

      if (g_settings_schema_has_key (schema, "active"))
        g_signal_connect (gsettings, "changed::active",
                          G_CALLBACK (on_gsettings_changed_active), combo);

      g_settings_schema_unref (schema);
      g_free (name);
      /*g_object_unref (gsettings);*/ /*** FIXME ***/
    }

    if (gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo), id1) == FALSE)
    {
      g_settings_set_string (page_key->gsettings, "default-engine",
                             "nimf-system-keyboard");
      gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo),
                                   "nimf-system-keyboard");
    }

    g_strfreev (non_relocatable);
    g_list_free (schema_list);
    g_free (id1);
  }
  else if (g_str_has_prefix (page_key->key, "hidden-") == FALSE)
  {
    gchar *id1;
    GList *list;

    id1 = g_settings_get_string (page_key->gsettings, page_key->key);

    for (list = key_list; list != NULL; list = list->next)
    {
      gchar *key2;
      gchar *prefix;

      key2 = list->data;
      prefix = g_strdup_printf ("hidden-%s-", page_key->key);

      if (g_str_has_prefix (key2, prefix))
      {
        gchar *val;
        const gchar *id2 = key2 + strlen (prefix);

        val = g_settings_get_string (page_key->gsettings, key2);
        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter, 0, val,
                                          1, id2, -1);

        if (g_strcmp0 (id1, id2) == 0)
          gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);

        g_free (val);
      }

      g_free (prefix);
    }

    g_free (id1);
  }

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 15);
  gtk_box_pack_start (GTK_BOX (hbox), page_key->label, FALSE, FALSE, 0);
  gtk_box_pack_end   (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
  detailed_signal = g_strdup_printf ("changed::%s", page_key->key);

  g_signal_connect (combo, "changed",
                    G_CALLBACK (on_combo_box_changed), page_key);
  g_signal_connect (page_key->gsettings, detailed_signal,
                    G_CALLBACK (on_gsettings_changed), combo);

  g_free (detailed_signal);

  return hbox;
}
示例#9
0
static gboolean
check_gsettings_condition (NemoAction *action, const gchar *condition)
{

    gchar **split = g_strsplit (condition, " ", 6);
    gint len = g_strv_length (split);

    if (len != 6 && 
        len != 3) {
        g_strfreev (split);
        return FALSE;
    }

    if (g_strcmp0 (split[0], "gsettings") != 0) {
        g_strfreev (split);
        return FALSE;
    }

    if (len == 6 &&
        (!g_variant_type_string_is_valid (split[GSETTINGS_TYPE_INDEX]) || 
         !operator_is_valid (split[GSETTINGS_OP_INDEX]))) {
        g_printerr ("Nemo Action: Either gsettings variant type (%s) or operator (%s) is invalid.\n",
                    split[GSETTINGS_TYPE_INDEX], split[GSETTINGS_OP_INDEX]);
        g_strfreev (split);
        return FALSE;
    }

    GSettingsSchemaSource *schema_source;
    gboolean ret = FALSE;
    const GVariantType *target_type;

    if (len == 3) {
        target_type = G_VARIANT_TYPE_BOOLEAN;
    } else {
        target_type = G_VARIANT_TYPE (split[GSETTINGS_TYPE_INDEX]);
    }

    schema_source = g_settings_schema_source_get_default();

    if (g_settings_schema_source_lookup (schema_source, split[GSETTINGS_SCHEMA_INDEX], TRUE)) {
        GSettings *s = g_settings_new (split[GSETTINGS_SCHEMA_INDEX]);
        gchar **keys = g_settings_list_keys (s);
        gint i;
        for (i = 0; i < g_strv_length (keys); i++) {
            if (len == 3) {
                if (g_strcmp0 (keys[i], split[GSETTINGS_KEY_INDEX]) == 0) {
                    GVariant *setting_var = g_settings_get_value (s, split[GSETTINGS_KEY_INDEX]);
                    const GVariantType *setting_type = g_variant_get_type (setting_var);
                    if (g_variant_type_equal (setting_type, target_type))
                        ret = g_variant_get_boolean (setting_var);
                    g_variant_unref (setting_var);
                }
            } else {
                if (g_strcmp0 (keys[i], split[GSETTINGS_KEY_INDEX]) == 0) {
                    GVariant *setting_var = g_settings_get_value (s, split[GSETTINGS_KEY_INDEX]);
                    const GVariantType *setting_type = g_variant_get_type (setting_var);
                    if (g_variant_type_equal (setting_type, target_type)) {
                        GVariant *target_var = g_variant_parse (target_type,
                                                                split[GSETTINGS_VAL_INDEX],
                                                                NULL, NULL, NULL);
                        if (target_var != NULL) {
                            gint vector = g_variant_compare (setting_var, target_var);
                            ret = try_vector (split[GSETTINGS_OP_INDEX], vector);
                            g_variant_unref (target_var);
                        } else {
                            g_printerr ("Nemo Action: gsettings value could not be parsed into a valid GVariant\n");
                        }
                    }
                    g_variant_unref (setting_var);
                }
            }
        }
        g_strfreev (keys);
        g_object_unref (s);
        g_strfreev (split);
        return ret;
    } else {
        g_strfreev (split);
        return FALSE;
    }
}
示例#10
0
static void
init_gsettings (void)
{
#ifdef HAVE_GSETTINGS
  GVariant *val;
  bool schema_found = false;

#if ! GLIB_CHECK_VERSION (2, 36, 0)
  g_type_init ();
#endif

#if GLIB_CHECK_VERSION (2, 32, 0)
  {
    GSettingsSchema *sc = g_settings_schema_source_lookup
      (g_settings_schema_source_get_default (),
       GSETTINGS_SCHEMA,
       true);
    schema_found = sc != NULL;
    if (sc) g_settings_schema_unref (sc);
  }
#else
  {
    const gchar *const *schemas = g_settings_list_schemas ();
    if (schemas == NULL) return;
    while (! schema_found && *schemas != NULL)
      schema_found = strcmp (*schemas++, GSETTINGS_SCHEMA) == 0;
  }
#endif
  if (!schema_found) return;

  gsettings_client = g_settings_new (GSETTINGS_SCHEMA);
  if (!gsettings_client) return;
  g_object_ref_sink (G_OBJECT (gsettings_client));
  g_signal_connect (G_OBJECT (gsettings_client), "changed",
                    G_CALLBACK (something_changed_gsettingsCB), NULL);

  val = g_settings_get_value (gsettings_client, GSETTINGS_TOOL_BAR_STYLE);
  if (val)
    {
      g_variant_ref_sink (val);
      if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
        current_tool_bar_style
          = map_tool_bar_style (g_variant_get_string (val, NULL));
      g_variant_unref (val);
    }

#ifdef HAVE_XFT
  val = g_settings_get_value (gsettings_client, GSETTINGS_MONO_FONT);
  if (val)
    {
      g_variant_ref_sink (val);
      if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
	dupstring (&current_mono_font, g_variant_get_string (val, NULL));
      g_variant_unref (val);
    }

  val = g_settings_get_value (gsettings_client, GSETTINGS_FONT_NAME);
  if (val)
    {
      g_variant_ref_sink (val);
      if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
        dupstring (&current_font, g_variant_get_string (val, NULL));
      g_variant_unref (val);
    }
#endif /* HAVE_XFT */

#endif /* HAVE_GSETTINGS */
}
示例#11
0
static gboolean
handle_file (const gchar *filename)
{
  GKeyFile *keyfile;
  GConfClient *client;
  GConfValue *value;
  gint i, j;
  gchar *gconf_key;
  gchar **groups;
  gchar **keys;
  GVariantBuilder *builder;
  GVariant *v;
  const gchar *s;
  gchar *str;
  gint ii;
  GSList *list, *l;
  GSettingsSchemaSource *source;
  GSettingsSchema *schema;
  GSettings *settings;
  GError *error;

  keyfile = g_key_file_new ();

  error = NULL;
  if (!g_key_file_load_from_file (keyfile, filename, 0, &error))
    {
      if (verbose)
        g_printerr ("%s: %s\n", filename, error->message);
      g_error_free (error);

      g_key_file_free (keyfile);

      return FALSE;
    }

  client = get_writable_client ();
  source = g_settings_schema_source_get_default ();

  groups = g_key_file_get_groups (keyfile, NULL);
  for (i = 0; groups[i]; i++)
    {
      gchar **schema_path;

      schema_path = g_strsplit (groups[i], ":", 2);

      schema = g_settings_schema_source_lookup (source, schema_path[0], TRUE);
      if (schema == NULL)
        {
          if (verbose)
            {
              g_print ("Schema '%s' not found, skipping\n", schema_path[0]);
            }

          g_strfreev (schema_path);
          continue;
        }

      g_settings_schema_unref (schema);

      if (verbose)
        {
          g_print ("Collecting settings for schema '%s'\n", schema_path[0]);
          if (schema_path[1])
            g_print ("for storage at '%s'\n", schema_path[1]);
        }

      if (schema_path[1] != NULL)
        settings = g_settings_new_with_path (schema_path[0], schema_path[1]);
      else
        settings = g_settings_new (schema_path[0]);

      g_settings_delay (settings);

      error = NULL;
      if ((keys = g_key_file_get_keys (keyfile, groups[i], NULL, &error)) == NULL)
        {
          g_printerr ("%s", error->message);
          g_error_free (error);

          continue;
        }

      for (j = 0; keys[j]; j++)
        {
          if (strchr (keys[j], '/') != 0)
            {
              g_printerr ("Key '%s' contains a '/'\n", keys[j]);

              continue;
            }

          error = NULL;
          if ((gconf_key = g_key_file_get_string (keyfile, groups[i], keys[j], &error)) ==  NULL)
            {
              g_printerr ("%s", error->message);
              g_error_free (error);

              continue;
            }

          error = NULL;
          if ((value = gconf_client_get_without_default (client, gconf_key, &error)) == NULL)
            {
              if (error)
                {
                  g_printerr ("Failed to get GConf key '%s': %s\n",
                              gconf_key, error->message);
                  g_error_free (error);
                }
              else
                {
                  if (verbose)
                    g_print ("Skipping GConf key '%s', no user value\n",
                             gconf_key);
                }

              g_free (gconf_key);

              continue;
            }

          switch (value->type)
            {
            case GCONF_VALUE_STRING:
              if (dry_run)
                g_print ("Set key '%s' to string '%s'\n", keys[j],
                         gconf_value_get_string (value));
              else
                g_settings_set (settings, keys[j], "s",
                                gconf_value_get_string (value));
              break;

            case GCONF_VALUE_INT:
              if (dry_run)
                g_print ("Set key '%s' to integer '%d'\n",
                         keys[j], gconf_value_get_int (value));
              else
                {
                  GVariant *range;
                  gchar *type;

                  range = g_settings_get_range (settings, keys[j]);
                  g_variant_get (range, "(&sv)", &type, NULL);

                  if (strcmp (type, "enum") == 0)
                    g_settings_set_enum (settings, keys[j], gconf_value_get_int (value));
                  else if (strcmp (type, "flags") == 0)
                    g_settings_set_flags (settings, keys[j], gconf_value_get_int (value));
                  else if (type_uint32 (settings, keys[j]))
                    g_settings_set (settings, keys[j], "u",
                                    gconf_value_get_int (value));
                  else
                    g_settings_set (settings, keys[j], "i",
                                    gconf_value_get_int (value));

                  g_variant_unref (range);
                }
              break;

            case GCONF_VALUE_BOOL:
              if (dry_run)
                g_print ("Set key '%s' to boolean '%d'\n",
                         keys[j], gconf_value_get_bool (value));
              else
                g_settings_set (settings, keys[j], "b",
                                gconf_value_get_bool (value));
              break;

            case GCONF_VALUE_FLOAT:
              if (dry_run)
                g_print ("Set key '%s' to double '%g'\n",
                         keys[j], gconf_value_get_float (value));
              else
                g_settings_set (settings, keys[j], "d",
                                gconf_value_get_float (value));
              break;

            case GCONF_VALUE_LIST:
              switch (gconf_value_get_list_type (value))
                {
                case GCONF_VALUE_STRING:
                  builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
                  list = gconf_value_get_list (value);
                  if (list != NULL)
                    {
                      for (l = list; l; l = l->next)
                        {
                          GConfValue *lv = l->data;
                          s = gconf_value_get_string (lv);
                          g_variant_builder_add (builder, "s", s);
                        }
                      v = g_variant_new ("as", builder);
                    }
                  else
                    v = g_variant_new_array (G_VARIANT_TYPE_STRING, NULL, 0);
                  g_variant_ref_sink (v);

                  if (dry_run)
                    {
                      str = g_variant_print (v, FALSE);
                      g_print ("Set key '%s' to a list of strings: %s\n",
                               keys[j], str);
                      g_free (str);
                    }
                  else
                    g_settings_set_value (settings, keys[j], v);

                  g_variant_unref (v);
                  g_variant_builder_unref (builder);
                  break;

                case GCONF_VALUE_INT:
                  builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
                  list = gconf_value_get_list (value);
                  if (list != NULL)
                    {
                      for (l = list; l; l = l->next)
                        {
                          GConfValue *lv = l->data;
                          ii = gconf_value_get_int (lv);
                          g_variant_builder_add (builder, "i", ii);
                        }
                      v = g_variant_new ("ai", builder);
                    }
                  else
                    v = g_variant_new_array (G_VARIANT_TYPE_INT32, NULL, 0);
                  g_variant_ref_sink (v);

                  if (dry_run)
                    {
                      str = g_variant_print (v, FALSE);
                      g_print ("Set key '%s' to a list of integers: %s\n",
                               keys[j], str);
                      g_free (str);
                    }
                  else
                    g_settings_set_value (settings, keys[j], v);

                  g_variant_unref (v);
                  g_variant_builder_unref (builder);
                  break;

                default:
                  g_printerr ("Keys of type 'list of %s' not handled yet\n",
                              gconf_value_type_to_string (gconf_value_get_list_type (value)));
                  break;
                }
              break;

            default:
              g_printerr ("Keys of type %s not handled yet\n",
                          gconf_value_type_to_string (value->type));
              break;
            }

          gconf_value_free (value);
          g_free (gconf_key);
        }

      g_strfreev (keys);

      if (!dry_run)
        g_settings_apply (settings);

      g_object_unref (settings);
      g_strfreev (schema_path);
    }

  g_strfreev (groups);

  g_object_unref (client);

  return TRUE;
}
示例#12
0
static void
ide_settings_constructed (GObject *object)
{
  IdeSettings *self = (IdeSettings *)object;
  g_autofree gchar *full_path = NULL;
  const gchar *project_id;
  IdeContext *context;
  IdeProject *project;
  GSettings *settings;
  gchar *path;

  IDE_ENTRY;

  G_OBJECT_CLASS (ide_settings_parent_class)->constructed (object);

  if (self->schema_id == NULL)
    {
      g_error ("You must provide IdeSettings:schema-id");
      abort ();
    }

  if (self->relative_path == NULL)
    {
      g_autoptr(GSettingsSchema) schema = NULL;
      GSettingsSchemaSource *source;
      const gchar *schema_path;

      source = g_settings_schema_source_get_default ();
      schema = g_settings_schema_source_lookup (source, self->schema_id, TRUE);

      if (schema == NULL)
        {
          g_error ("Could not locate schema %s", self->schema_id);
          abort ();
        }

      schema_path = g_settings_schema_get_path (schema);

      if ((schema_path != NULL) && !g_str_has_prefix (schema_path, "/org/gnome/builder/"))
        {
          g_error ("Schema path MUST be under /org/gnome/builder/");
          abort ();
        }
      else if (schema_path == NULL)
        {
          self->relative_path = g_strdup ("");
        }
      else
        {
          self->relative_path = g_strdup (schema_path + strlen ("/org/gnome/builder/"));
        }
    }

  g_assert (self->relative_path != NULL);
  g_assert (self->relative_path [0] != '/');
  g_assert ((self->relative_path [0] == 0) || g_str_has_suffix (self->relative_path, "/"));

  context = ide_object_get_context (IDE_OBJECT (self));
  project = ide_context_get_project (context);
  project_id = ide_project_get_id (project);

  full_path = g_strdup_printf ("/org/gnome/builder/%s", self->relative_path);
  self->settings_sandwich = egg_settings_sandwich_new (self->schema_id, full_path);

  /* Add our project relative settings */
  if (self->ignore_project_settings == FALSE)
    {
      path = g_strdup_printf ("/org/gnome/builder/projects/%s/%s",
                              project_id, self->relative_path);
      settings = g_settings_new_with_path (self->schema_id, path);
      egg_settings_sandwich_append (self->settings_sandwich, settings);
      g_clear_object (&settings);
      g_free (path);
    }

  /* Add our application global (user defaults) settings */
  settings = g_settings_new_with_path (self->schema_id, full_path);
  egg_settings_sandwich_append (self->settings_sandwich, settings);
  g_clear_object (&settings);

  IDE_EXIT;
}
示例#13
0
/**
 * peas_plugin_info_get_settings:
 * @info: A #PeasPluginInfo.
 * @schema_id: (allow-none): The schema id.
 *
 * Creates a new #GSettings for the given @schema_id and if
 * gschemas.compiled is not in the module directory an attempt
 * will be made to create it.
 *
 * Returns: (transfer full): a new #GSettings, or %NULL.
 */
GSettings *
peas_plugin_info_get_settings (const PeasPluginInfo *info,
                               const gchar          *schema_id)
{
    GSettingsSchema *schema;
    GSettings *settings;

    g_return_val_if_fail (info != NULL, NULL);

    if (info->schema_source == NULL)
    {
        GFile *module_dir_location;
        GFile *gschema_compiled;
        GSettingsSchemaSource *default_source;

        module_dir_location = g_file_new_for_path (info->module_dir);
        gschema_compiled = g_file_get_child (module_dir_location,
                                             "gschemas.compiled");

        if (!g_file_query_exists (gschema_compiled, NULL))
        {
            const gchar *argv[] = {
                "glib-compile-schemas",
                "--targetdir", info->module_dir,
                info->module_dir,
                NULL
            };

            g_spawn_sync (NULL, (gchar **) argv, NULL, G_SPAWN_SEARCH_PATH,
                          NULL, NULL, NULL, NULL, NULL, NULL);
        }

        g_object_unref (gschema_compiled);
        g_object_unref (module_dir_location);

        default_source = g_settings_schema_source_get_default ();
        ((PeasPluginInfo *) info)->schema_source =
            g_settings_schema_source_new_from_directory (info->module_dir,
                    default_source,
                    FALSE, NULL);

        /* glib-compile-schemas already outputted a message */
        if (info->schema_source == NULL)
            return NULL;
    }

    if (schema_id == NULL)
        schema_id = info->module_name;

    schema = g_settings_schema_source_lookup (info->schema_source, schema_id,
             FALSE);

    if (schema == NULL)
        return NULL;

    settings = g_settings_new_full (schema, NULL, NULL);

    g_settings_schema_unref (schema);

    return settings;
}