Exemplo n.º 1
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);
}
Exemplo n.º 2
0
QStringList QGSettings::schemas()
{
    GSettingsSchemaSource *source = g_settings_schema_source_get_default();
    gchar **schemas;
    g_settings_schema_source_list_schemas(source, true, &schemas, Q_NULLPTR);
    QStringList result;
    for (int i = 0; schemas[i]; i++)
        result.append(schemas[i]);
    g_strfreev(schemas);
    return result;
}
Exemplo n.º 3
0
static GtkWidget *
nimf_settings_build_main_window (NimfSettings *nsettings)
{
  GtkWidget  *window;
  GtkWidget  *notebook;
  GList      *schema_list = NULL;
  gchar     **non_relocatable;
  gint        i;

  window = gtk_application_window_new (nsettings->app);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
  gtk_window_set_title        (GTK_WINDOW (window), _("Nimf Settings"));
  gtk_window_set_icon_name    (GTK_WINDOW (window), "nimf");

  notebook = gtk_notebook_new ();
  gtk_notebook_set_tab_pos    (GTK_NOTEBOOK (notebook), GTK_POS_LEFT);
  gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
  gtk_container_add (GTK_CONTAINER (window), notebook);

  g_settings_schema_source_list_schemas (nsettings->schema_source, TRUE,
                                         &non_relocatable, NULL);

  for (i = 0; non_relocatable[i] != NULL; i++)
    if (g_str_has_prefix (non_relocatable[i], "org.nimf"))
      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)
  {
    NimfSettingsPage  *page;
    GtkWidget         *scrolled_w;

    scrolled_w = gtk_scrolled_window_new (NULL, NULL);
    page = nimf_settings_page_new (nsettings,
                                   (const gchar *) schema_list->data);
    gtk_container_add (GTK_CONTAINER (scrolled_w), page->box);
    gtk_notebook_append_page (GTK_NOTEBOOK (notebook), scrolled_w, page->label);
    g_ptr_array_add (nsettings->pages, page);
  }

  g_strfreev (non_relocatable);
  g_list_free (schema_list);

  return window;
}
Exemplo n.º 4
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;
}