/** 
 * mate_vfs_connect_to_server:
 * @uri: The string representation of the server to connect to.
 * @display_name: The display name that is used to identify the server connection.
 * @icon: The icon that is used to identify the server connection.
 *
 * This function adds a server connection to the specified @uri, which is displayed
 * in user interfaces with the specified @display_name and @icon.
 *
 * If this function is invoked successfully, the created server shows up in the
 * list of mounted volumes of the #MateVFSVolumeMonitor, which can be queried
 * using mate_vfs_volume_monitor_get_mounted_volumes().
 *
 * <note>
 * <para>
 * This function does not have a return value. Hence, you can't easily detect
 * whether the specified server was successfully created. The actual creation and
 * consumption of the new server through the #MateVFSVolumeMonitor is done
 * asynchronously.
 * </para>
 * <para>
 * @uri, @display_name, and @icon can be freely chosen, but should be meaningful:
 * </para>
 * <para>
 * @uri should refer to a valid location. You can check the validity of the
 * location by calling mate_vfs_uri_new() with @uri, and checking whether
 * the return value is not %NULL.
 * </para>
 * <para>
 * The @display_name should be queried from the user, and an empty string
 * should not be considered valid.
 * </para>
 * <para>
 * @icon typically references an icon from the icon theme. Some
 * implementations currently use <literal>mate-fs-smb</literal>,
 * <literal>mate-fs-ssh</literal>, <literal>mate-fs-ftp</literal> and
 * <literal>mate-fs-share</literal>, depending on the type of the server
 * referenced by @uri. The icon naming conventions might change in the
 * future, though. Obeying the <ulink
 * url="http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html">
 * freedesktop.org Icon Naming Specification</ulink> is suggested.
 * </para>
 * </note>
 *
 * Since: 2.6
 */
void
mate_vfs_connect_to_server (const char               *uri,
			     const char               *display_name,
			     const char               *icon)
{
	MateConfClient *client;
	GSList *dirs, *l;
	char *dir, *dir_id;
	int max_id, mateconf_id;
	char *key;
	char *id;

	client = mateconf_client_get_default ();

	max_id = 0;
	dirs = mateconf_client_all_dirs (client,
				      CONNECTED_SERVERS_DIR, NULL);
	for (l = dirs; l != NULL; l = l->next) {
		dir = l->data;

		dir_id = strrchr (dir, '/');
		if (dir_id != NULL) {
			dir_id++;
			mateconf_id = strtol (dir_id, NULL, 10);
			max_id = MAX (max_id, mateconf_id);
		}
		
		g_free (dir);
	}
	g_slist_free (dirs);

	id = g_strdup_printf ("%d", max_id + 1);
	
	key = g_strconcat (CONNECTED_SERVERS_DIR "/",
			   id,
			   "/icon", NULL);
	mateconf_client_set_string (client, key, icon, NULL);
	g_free (key);
	
	key = g_strconcat (CONNECTED_SERVERS_DIR "/",
			   id,
			   "/display_name", NULL);
	mateconf_client_set_string (client, key, display_name, NULL);
	g_free (key);

	/* Uri key creation triggers creation, do this last */
	key = g_strconcat (CONNECTED_SERVERS_DIR "/",
			   id,
			   "/uri", NULL);
	mateconf_client_set_string (client, key, uri, NULL);
	g_free (key);
	
	g_free (id);
	g_object_unref (client);
}
Exemple #2
0
static char
*get_all_applets (void)
{
	MateConfClient *client;
	GError *error;
	GSList *list, *l;
	char *key, *oafiid, *name;
	GHashTable *hash_table;
	GString *string;

	error = NULL;
	hash_table = g_hash_table_new (g_str_hash, g_str_equal);
	insert_oafiids (hash_table);

	string = g_string_new ("");

	client = mateconf_client_get_default ();

	mateconf_client_suggest_sync (client, NULL);
	
	list = mateconf_client_all_dirs (client,
		"/apps/panel/applets",
		&error);

	if (error)
	{
		g_warning ("Error: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	for (l = list; l; l = l->next)
	{
	    key = g_strdup_printf ("%s/matecomponent_iid", (gchar *)l->data);
		oafiid = mateconf_client_get_string (client, key, &error);
		if (error)
		{
			g_warning ("Error: %s", error->message);
			g_error_free (error);
			error = NULL;
		}
		g_free (key);
	
		if (oafiid)
		{
			name = g_hash_table_lookup (hash_table, oafiid);
			if (name)
			{
				mateconf_client_recursive_unset (client, l->data,
					MATECONF_UNSET_INCLUDING_SCHEMA_NAMES,
					&error);
				if (error)
				{
					g_warning ("Error: %s", error->message);
					g_error_free (error);
					error = NULL;
				}
				g_string_append_printf (string,
						"    • %s\n", name);
			}
			g_free (oafiid);
		}
		g_free (l->data);
	}

	g_slist_free (list);
	g_hash_table_destroy (hash_table);
	
	return g_string_free (string, FALSE);
}