コード例 #1
0
void
ce_page_complete_connection (NMConnection *connection,
                             const char *format,
                             const char *ctype,
                             gboolean autoconnect,
                             NMClient *client)
{
	NMSettingConnection *s_con;
	char *id, *uuid;
	const GPtrArray *connections;

	s_con = nm_connection_get_setting_connection (connection);
	if (!s_con) {
		s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
		nm_connection_add_setting (connection, NM_SETTING (s_con));
	}

	if (!nm_setting_connection_get_id (s_con)) {
		connections = nm_client_get_connections (client);
		id = ce_page_get_next_available_name (connections, format);
		g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL);
		g_free (id);
	}

	uuid = nm_utils_uuid_generate ();
	g_object_set (s_con,
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NM_SETTING_CONNECTION_TYPE, ctype,
	              NM_SETTING_CONNECTION_AUTOCONNECT, autoconnect,
	              NULL);
	g_free (uuid);
}
コード例 #2
0
ファイル: page-vpn.c プロジェクト: pavlix/nm-applet
static void
import_cb (NMConnection *connection, gpointer user_data)
{
	NewVpnInfo *info = (NewVpnInfo *) user_data;
	NMSettingConnection *s_con;
	NMSettingVPN *s_vpn;
	const char *service_type;
	char *s;
	GError *error = NULL;

	/* Basic sanity checks of the connection */
	s_con = nm_connection_get_setting_connection (connection);
	if (!s_con) {
		s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
		nm_connection_add_setting (connection, NM_SETTING (s_con));
	}

	s = (char *) nm_setting_connection_get_id (s_con);
	if (!s) {
		GSList *connections;

		connections = nm_remote_settings_list_connections (info->settings);
		s = ce_page_get_next_available_name (connections, _("VPN connection %d"));
		g_object_set (s_con, NM_SETTING_CONNECTION_ID, s, NULL);
		g_free (s);

		g_slist_free (connections);
	}

	s = (char *) nm_setting_connection_get_connection_type (s_con);
	if (!s || strcmp (s, NM_SETTING_VPN_SETTING_NAME))
		g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, NM_SETTING_VPN_SETTING_NAME, NULL);

	s = (char *) nm_setting_connection_get_uuid (s_con);
	if (!s) {
		s = nm_utils_uuid_generate ();
		g_object_set (s_con, NM_SETTING_CONNECTION_UUID, s, NULL);
		g_free (s);
	}

	s_vpn = nm_connection_get_setting_vpn (connection);
	service_type = s_vpn ? nm_setting_vpn_get_service_type (s_vpn) : NULL;

	if (!service_type || !strlen (service_type)) {
		g_object_unref (connection);
		connection = NULL;

		error = g_error_new_literal (NMA_ERROR, NMA_ERROR_GENERIC,
		                             _("The VPN plugin failed to import the VPN connection correctly\n\nError: no VPN service type."));
	}

	info->result_func (connection, FALSE, error, info->user_data);
	g_clear_error (&error);
	g_object_unref (info->settings);
	g_slice_free (NewVpnInfo, info);
}
コード例 #3
0
static void
add_profile (GtkButton *button, NetDeviceEthernet *device)
{
        NMRemoteSettings *settings;
        NMConnection *connection;
        NMSettingConnection *sc;
        gchar *uuid, *id;
        NetConnectionEditor *editor;
        GtkWidget *window;
        NMClient *client;
        NMDevice *nmdev;
        GSList *connections;

        connection = nm_connection_new ();
        sc = NM_SETTING_CONNECTION (nm_setting_connection_new ());
        nm_connection_add_setting (connection, NM_SETTING (sc));

        uuid = nm_utils_uuid_generate ();

        settings = net_object_get_remote_settings (NET_OBJECT (device));
        connections = nm_remote_settings_list_connections (settings);
        id = ce_page_get_next_available_name (connections, _("Profile %d"));
        g_slist_free (connections);

        g_object_set (sc,
                      NM_SETTING_CONNECTION_UUID, uuid,
                      NM_SETTING_CONNECTION_ID, id,
                      NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
                      NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
                      NULL);

        nm_connection_add_setting (connection, nm_setting_wired_new ());

        g_free (uuid);
        g_free (id);

        window = gtk_widget_get_toplevel (GTK_WIDGET (button));

        nmdev = net_device_get_nm_device (NET_DEVICE (device));
        client = net_object_get_client (NET_OBJECT (device));
        editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client, settings);
        g_signal_connect (editor, "done", G_CALLBACK (editor_done), device);
        net_connection_editor_run (editor);
}