Ejemplo n.º 1
0
static PanelToplevel *
create_drawer_toplevel (const char *drawer_id)
{
	PanelToplevel *toplevel;
	GConfClient   *client;
	const char    *key;
	char          *toplevel_id;

	client  = panel_gconf_get_client ();

	toplevel_id = panel_profile_find_new_id (PANEL_GCONF_TOPLEVELS);
	
	toplevel = panel_profile_load_toplevel (client, PANEL_CONFIG_DIR,
						PANEL_GCONF_TOPLEVELS, toplevel_id);

	if (!toplevel) {
		g_free (toplevel_id);
		return NULL;
	}

	key = panel_gconf_full_key (PANEL_GCONF_OBJECTS, drawer_id, "attached_toplevel_id");
	gconf_client_set_string (client, key, toplevel_id, NULL);
	g_free (toplevel_id);

	panel_profile_set_toplevel_enable_buttons (toplevel, TRUE);
	panel_profile_set_toplevel_enable_arrows (toplevel, TRUE);

	return toplevel;
}
Ejemplo n.º 2
0
static void
panel_drawer_prepare (const char  *drawer_id,
                      GIcon       *custom_icon,
                      gboolean     use_custom_icon,
                      const char  *tooltip,
                      char       **attached_toplevel_id)
{
    GSettings *settings;
    char *path;

    path = g_strdup_printf ("%s%s/", PANEL_OBJECT_PATH, drawer_id);
    settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
    g_free (path);

    if (tooltip) {
        g_settings_set_string (settings, PANEL_OBJECT_TOOLTIP_KEY, tooltip);
    }

    g_settings_set_boolean (settings, PANEL_OBJECT_USE_CUSTOM_ICON_KEY, use_custom_icon);

    if (custom_icon) {
	gchar *icon_name;
	icon_name = g_icon_to_string(custom_icon);
	g_settings_set_string (settings, PANEL_OBJECT_CUSTOM_ICON_KEY, icon_name);
	g_free(icon_name);
    }

    if (attached_toplevel_id) {
        char *toplevel_id;
        char *toplevel_path;
        GSettings *toplevel_settings;

        toplevel_id = panel_profile_find_new_id (PANEL_GSETTINGS_TOPLEVELS);

        toplevel_path = g_strdup_printf (PANEL_TOPLEVEL_PATH "%s/", toplevel_id);

        toplevel_settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA, toplevel_path);

        g_settings_set_string (settings, PANEL_OBJECT_ATTACHED_TOPLEVEL_ID_KEY, toplevel_id);
        g_settings_set_boolean (toplevel_settings, PANEL_TOPLEVEL_ENABLE_BUTTONS_KEY, TRUE);
        g_settings_set_boolean (toplevel_settings, PANEL_TOPLEVEL_ENABLE_ARROWS_KEY, TRUE);

        *attached_toplevel_id = toplevel_id;

        g_object_unref (toplevel_settings);
        g_free (toplevel_path);
    }
    g_object_unref (settings);
}
Ejemplo n.º 3
0
static void
panel_drawer_prepare (const char  *drawer_id,
		      const char  *custom_icon,
		      gboolean     use_custom_icon,
		      const char  *tooltip,
		      char       **attached_toplevel_id)
{
	GConfClient *client;
	const char  *key;

	client  = panel_gconf_get_client ();

	if (tooltip) {
		key = panel_gconf_full_key (PANEL_GCONF_OBJECTS, drawer_id, "tooltip");
		gconf_client_set_string (client, key, tooltip, NULL);
	}

	key = panel_gconf_full_key (PANEL_GCONF_OBJECTS, drawer_id, "use_custom_icon");
	gconf_client_set_bool (client, key, use_custom_icon, NULL);

	if (custom_icon) {
		key = panel_gconf_full_key (PANEL_GCONF_OBJECTS, drawer_id, "custom_icon");
		gconf_client_set_string (client, key, custom_icon, NULL);
	}

	if (attached_toplevel_id) {
		char *toplevel_id;
		char *toplevel_dir;

		toplevel_id = panel_profile_find_new_id (PANEL_GCONF_TOPLEVELS);

		toplevel_dir = g_strdup_printf (PANEL_CONFIG_DIR "/toplevels/%s",
						toplevel_id);
		panel_gconf_associate_schemas_in_dir (client, toplevel_dir, PANEL_SCHEMAS_DIR "/toplevels");
	
		key = panel_gconf_full_key (PANEL_GCONF_OBJECTS, drawer_id, "attached_toplevel_id");
		gconf_client_set_string (client, key, toplevel_id, NULL);
		
		key = panel_gconf_full_key (PANEL_GCONF_TOPLEVELS, toplevel_id, "enable_buttons");
		gconf_client_set_bool (client, key, TRUE, NULL);

		key = panel_gconf_full_key (PANEL_GCONF_TOPLEVELS, toplevel_id, "enable_arrows");
		gconf_client_set_bool (client, key, TRUE, NULL);

		*attached_toplevel_id = toplevel_id;
	}
}
Ejemplo n.º 4
0
static PanelToplevel *
create_drawer_toplevel (const char *drawer_id, GSettings *settings)
{
	PanelToplevel *toplevel;
	char          *toplevel_id;

	toplevel_id = panel_profile_find_new_id (PANEL_GSETTINGS_TOPLEVELS);
	toplevel = panel_profile_load_toplevel (toplevel_id);

	if (!toplevel) {
		g_free (toplevel_id);
		return NULL;
	}

	g_settings_set_string (settings, PANEL_OBJECT_ATTACHED_TOPLEVEL_ID_KEY, toplevel_id);
	g_free (toplevel_id);

	panel_profile_set_toplevel_enable_buttons (toplevel, TRUE);
	panel_profile_set_toplevel_enable_arrows (toplevel, TRUE);

	return toplevel;
}
Ejemplo n.º 5
0
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;
}