static void setup_options (void) { MatePanelAppletsManager *manager; GList *applet_list, *l; int i; int j; char *prefs_path = NULL; char *unique_key = NULL; gboolean unique_key_found = FALSE; gchar **dconf_paths; GtkListStore *model; GtkTreeIter iter; GtkCellRenderer *renderer; model = gtk_list_store_new (NUMBER_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); gtk_combo_box_set_model (GTK_COMBO_BOX (applet_combo), GTK_TREE_MODEL (model)); manager = g_object_new (PANEL_TYPE_APPLETS_MANAGER_DBUS, NULL); applet_list = MATE_PANEL_APPLETS_MANAGER_GET_CLASS (manager)->get_applets (manager); for (l = applet_list, i = 1; l; l = g_list_next (l), i++) { MatePanelAppletInfo *info = (MatePanelAppletInfo *)l->data; gtk_list_store_append (model, &iter); gtk_list_store_set (model, &iter, COLUMN_TEXT, g_strdup (mate_panel_applet_info_get_name (info)), COLUMN_ITEM, g_strdup (mate_panel_applet_info_get_iid (info)), -1); } g_list_free (applet_list); g_object_unref (manager); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (applet_combo), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (applet_combo), renderer, "text", COLUMN_TEXT, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (applet_combo), 0); setup_combo (size_combo, size_items, "Size", G_N_ELEMENTS (size_items)); setup_combo (orient_combo, orient_items, "Orientation", G_N_ELEMENTS (orient_items)); for (i = 0; !unique_key_found; i++) { unique_key = g_strdup_printf ("mate-panel-test-applet-%d", i); unique_key_found = TRUE; dconf_paths = panel_dconf_list_subdirs ("/tmp/", TRUE); for (j = 0; dconf_paths[j] != NULL; j++) { if (g_strcmp0(unique_key, dconf_paths[j]) == 0) { unique_key_found = FALSE; break; } } if (dconf_paths) g_strfreev (dconf_paths); } prefs_path = g_strdup_printf ("/tmp/%s/", unique_key); if (unique_key) g_free (unique_key); gtk_entry_set_text (GTK_ENTRY (prefs_path_entry), prefs_path); g_free (prefs_path); }
static char * panel_layout_find_free_id (const char *id_list_key, const char *schema, const char *path_prefix, const char *try_id, int screen_for_toplevels) { char *unique_id; char **existing_ids; char **existing_dirs; gboolean existing; int index; int i; existing_ids = g_settings_get_strv (layout_settings, id_list_key); existing_dirs = panel_dconf_list_subdirs (path_prefix, TRUE); index = 0; existing = TRUE; /* If a specific id is specified, try to use it; it might be * free */ if (try_id) { if (screen_for_toplevels != -1 && g_strcmp0 (schema, PANEL_TOPLEVEL_SCHEMA) == 0) unique_id = g_strdup_printf ("%s-screen%d", try_id, screen_for_toplevels); else unique_id = g_strdup (try_id); existing = FALSE; for (i = 0; !existing && existing_ids[i] != NULL; i++) { if (g_strcmp0 (unique_id, existing_ids[i]) == 0) existing = TRUE; } for (i = 0; !existing && existing_dirs[i] != NULL; i++) { if (g_strcmp0 (unique_id, existing_dirs[i]) == 0) existing = TRUE; break; } if (existing) g_free (unique_id); } else { if (g_strcmp0 (schema, PANEL_TOPLEVEL_SCHEMA) == 0) try_id = "toplevel"; else if (g_strcmp0 (schema, PANEL_OBJECT_SCHEMA) == 0) try_id = "object"; else g_assert_not_reached (); } /* Append an index at the end of the id to find a unique * id, not used yet */ while (existing) { if (screen_for_toplevels != -1 && g_strcmp0 (schema, PANEL_TOPLEVEL_SCHEMA) == 0) unique_id = g_strdup_printf ("%s-screen%d-%d", try_id, screen_for_toplevels, index); else unique_id = g_strdup_printf ("%s-%d", try_id, index); existing = FALSE; for (i = 0; !existing && existing_ids[i] != NULL; i++) { if (g_strcmp0 (unique_id, existing_ids[i]) == 0) existing = TRUE; } for (i = 0; !existing && existing_dirs[i] != NULL; i++) { if (g_strcmp0 (unique_id, existing_dirs[i]) == 0) existing = TRUE; } if (existing) g_free (unique_id); index++; } g_strfreev (existing_dirs); g_strfreev (existing_ids); return unique_id; }
static gboolean panel_layout_append_group_helper (GKeyFile *keyfile, const char *group, int set_screen_to, const char *group_prefix, char *id_list_key, const char *schema, const char *path_prefix, const char *default_prefix, PanelLayoutKeyDefinition *key_definitions, int key_definitions_len, const char *type_for_error_message) { gboolean retval = FALSE; const char *id; char *unique_id = NULL; char *path = NULL; GSettings *settings = NULL; char **keyfile_keys = NULL; char *value_str; int value_int; gboolean value_boolean; int i, j; GError *error = NULL; gchar **existing_ids; gboolean existing_id = FALSE; gchar *dir = NULL; gchar *dconf_path = NULL; PanelGSettingsKeyType type; /* Try to extract an id from the group, by stripping the prefix, * and create a unique id out of that */ id = group + strlen (group_prefix); while (g_ascii_isspace (*id)) id++; if (!*id) id = NULL; if (id && !panel_gsettings_is_valid_keyname (id, &error)) { g_warning ("Invalid id name in layout '%s' (%s)", id, error->message); g_error_free (error); return FALSE; } if (g_strcmp0 (id_list_key, PANEL_TOPLEVEL_ID_LIST_KEY) == 0) { dir = "toplevels"; type = PANEL_GSETTINGS_TOPLEVELS; } if (g_strcmp0 (id_list_key, PANEL_OBJECT_ID_LIST_KEY) == 0) { dir = "objects"; type = PANEL_GSETTINGS_OBJECTS; } dconf_path = g_strdup_printf (PANEL_RESOURCE_PATH "/%s", dir); existing_ids = panel_dconf_list_subdirs (dconf_path, TRUE); if (id) { for (i = 0; existing_ids[i]; i++) { if (!strcmp (existing_ids[i], id)) { existing_id = TRUE; } } } g_strfreev (existing_ids); g_free (dconf_path); if (existing_id || !id) unique_id = panel_profile_find_new_id (type); else unique_id = g_strdup (id); path = g_strdup_printf ("%s%s/", path_prefix, unique_id); settings = g_settings_new_with_path (schema, path); g_free (path); keyfile_keys = g_key_file_get_keys (keyfile, group, NULL, NULL); if (keyfile_keys) { /* validate/add keys from the keyfile */ for (i = 0; keyfile_keys[i] != NULL; i++) { gboolean found = FALSE; for (j = 0; j < key_definitions_len; j++) { if (g_strcmp0 (keyfile_keys[i], key_definitions[j].name) == 0) { found = TRUE; break; } } if (!found) { g_warning ("Unknown key '%s' for %s", keyfile_keys[i], unique_id); return FALSE; } switch (key_definitions[j].type) { case G_TYPE_STRING: value_str = g_key_file_get_string (keyfile, group, keyfile_keys[i], NULL); if (value_str) g_settings_set_string (settings, key_definitions[j].name, value_str); g_free (value_str); break; case G_TYPE_INT: value_int = g_key_file_get_integer (keyfile, group, keyfile_keys[i], NULL); g_settings_set_int (settings, key_definitions[j].name, value_int); break; case G_TYPE_BOOLEAN: value_boolean = g_key_file_get_boolean (keyfile, group, keyfile_keys[i], NULL); g_settings_set_boolean (settings, key_definitions[j].name, value_boolean); break; default: g_assert_not_reached (); break; } } if (set_screen_to != -1 && g_strcmp0 (schema, PANEL_TOPLEVEL_SCHEMA) == 0) g_settings_set_int (settings, PANEL_TOPLEVEL_SCREEN_KEY, set_screen_to); GSettings *panel_settings; panel_settings = g_settings_new (PANEL_SCHEMA); panel_gsettings_append_strv (panel_settings, id_list_key, unique_id); g_object_unref (panel_settings); retval = TRUE; } if (keyfile_keys) g_strfreev (keyfile_keys); if (settings) g_object_unref (settings); if (unique_id) g_free (unique_id); return retval; }