Commit 8bf378d2 authored by Dan Williams's avatar Dan Williams
Browse files

Merge commit 'origin/master' into cert-paths

Conflicts:
	src/connection-editor/nm-connection-list.c
parents 1a5eaae3 55ee9460
This diff is collapsed.
......@@ -154,11 +154,14 @@ bt_add_menu_item (NMDevice *device,
gtk_widget_show (item);
/* Notify user of unmanaged or unavailable device */
item = nma_menu_device_check_unusable (device, NULL);
item = nma_menu_device_get_menu_item (device, applet, NULL);
if (item) {
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
} else {
}
if (!nma_menu_device_check_unusable (device)) {
/* Add menu items for existing bluetooth connections for this device */
if (g_slist_length (connections))
add_connection_items (device, connections, carrier, active, menu, applet);
}
......
......@@ -225,50 +225,6 @@ add_default_connection_item (NMDevice *device,
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
static void
cdma_menu_item_deactivate (GtkMenuItem *item, gpointer user_data)
{
CdmaMenuItemInfo *info = (CdmaMenuItemInfo *) user_data;
NMActiveConnection *active = NULL;
applet_find_active_connection_for_device (info->device, info->applet, &active);
if (active)
nm_client_deactivate_connection (info->applet->nm_client, active);
else
g_warning ("%s: couldn't find active connection to deactive", __func__);
}
static void
add_disconnect_item (NMDevice *device,
GtkWidget *menu,
NMApplet *applet)
{
NMDeviceState state;
GtkWidget *item;
CdmaMenuItemInfo *info;
state = nm_device_get_state (device);
if ( state == NM_DEVICE_STATE_UNKNOWN
|| state == NM_DEVICE_STATE_UNMANAGED
|| state == NM_DEVICE_STATE_UNAVAILABLE
|| state == NM_DEVICE_STATE_DISCONNECTED
|| state == NM_DEVICE_STATE_FAILED)
return;
item = gtk_menu_item_new_with_label (_("Disconnect"));
info = g_slice_new0 (CdmaMenuItemInfo);
info->applet = applet;
info->device = g_object_ref (G_OBJECT (device));
g_signal_connect_data (item, "activate",
G_CALLBACK (cdma_menu_item_deactivate),
info,
(GClosureNotify) cdma_menu_item_info_destroy, 0);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
static void
cdma_add_menu_item (NMDevice *device,
guint32 n_devices,
......@@ -313,20 +269,19 @@ cdma_add_menu_item (NMDevice *device,
gtk_widget_show (item);
/* Notify user of unmanaged or unavailable device */
item = nma_menu_device_check_unusable (device, NULL);
item = nma_menu_device_get_menu_item (device, applet, NULL);
if (item) {
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
goto out;
}
if (g_slist_length (connections))
add_connection_items (device, connections, active, menu, applet);
else
add_default_connection_item (device, menu, applet);
add_disconnect_item (device, menu, applet);
if (!nma_menu_device_check_unusable (device)) {
if (g_slist_length (connections))
add_connection_items (device, connections, active, menu, applet);
else
add_default_connection_item (device, menu, applet);
}
out:
g_slist_free (connections);
}
......
......@@ -227,50 +227,6 @@ add_default_connection_item (NMDevice *device,
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
static void
gsm_menu_item_deactivate (GtkMenuItem *item, gpointer user_data)
{
GSMMenuItemInfo *info = (GSMMenuItemInfo *) user_data;
NMActiveConnection *active = NULL;
applet_find_active_connection_for_device (info->device, info->applet, &active);
if (active)
nm_client_deactivate_connection (info->applet->nm_client, active);
else
g_warning ("%s: couldn't find active connection to deactive", __func__);
}
static void
add_disconnect_item (NMDevice *device,
GtkWidget *menu,
NMApplet *applet)
{
NMDeviceState state;
GtkWidget *item;
GSMMenuItemInfo *info;
state = nm_device_get_state (device);
if ( state == NM_DEVICE_STATE_UNKNOWN
|| state == NM_DEVICE_STATE_UNMANAGED
|| state == NM_DEVICE_STATE_UNAVAILABLE
|| state == NM_DEVICE_STATE_DISCONNECTED
|| state == NM_DEVICE_STATE_FAILED)
return;
item = gtk_menu_item_new_with_label (_("Disconnect"));
info = g_slice_new0 (GSMMenuItemInfo);
info->applet = applet;
info->device = g_object_ref (G_OBJECT (device));
g_signal_connect_data (item, "activate",
G_CALLBACK (gsm_menu_item_deactivate),
info,
(GClosureNotify) gsm_menu_item_info_destroy, 0);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
static void
gsm_add_menu_item (NMDevice *device,
guint32 n_devices,
......@@ -315,20 +271,19 @@ gsm_add_menu_item (NMDevice *device,
gtk_widget_show (item);
/* Notify user of unmanaged or unavailable device */
item = nma_menu_device_check_unusable (device, NULL);
item = nma_menu_device_get_menu_item (device, applet, NULL);
if (item) {
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
goto out;
}
if (g_slist_length (connections))
add_connection_items (device, connections, active, menu, applet);
else
add_default_connection_item (device, menu, applet);
add_disconnect_item (device, menu, applet);
if (!nma_menu_device_check_unusable (device)) {
if (g_slist_length (connections))
add_connection_items (device, connections, active, menu, applet);
else
add_default_connection_item (device, menu, applet);
}
out:
g_slist_free (connections);
}
......
......@@ -713,26 +713,34 @@ wireless_add_menu_item (NMDevice *device,
/* Notify user of unmanaged or unavailable device */
wireless_enabled = nm_client_wireless_get_enabled (applet->nm_client);
item = nma_menu_device_check_unusable (device, wireless_enabled ? NULL : _("wireless is disabled"));
item = nma_menu_device_get_menu_item (device, applet, wireless_enabled ? NULL : _("wireless is disabled"));
if (item) {
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
goto out;
}
active_ap = nm_device_wifi_get_active_access_point (wdev);
/* Add all networks in our network list to the menu */
for (i = 0; aps && (i < aps->len); i++)
sorted_aps = g_slist_append (sorted_aps, g_ptr_array_index (aps, i));
if (!nma_menu_device_check_unusable (device)) {
active_ap = nm_device_wifi_get_active_access_point (wdev);
/* Add all networks in our network list to the menu */
for (i = 0; aps && (i < aps->len); i++)
sorted_aps = g_slist_append (sorted_aps, g_ptr_array_index (aps, i));
sorted_aps = g_slist_sort (sorted_aps, sort_wireless_networks);
for (iter = sorted_aps; iter; iter = g_slist_next (iter)) {
add_one_ap_menu_item (wdev,
NM_ACCESS_POINT (iter->data),
connections,
active_ap,
active,
menu,
applet);
}
sorted_aps = g_slist_sort (sorted_aps, sort_wireless_networks);
for (iter = sorted_aps; iter; iter = g_slist_next (iter))
add_one_ap_menu_item (wdev, NM_ACCESS_POINT (iter->data), connections, active_ap, active, menu, applet);
g_slist_free (sorted_aps);
}
out:
g_slist_free (connections);
g_slist_free (sorted_aps);
}
static gboolean
......
......@@ -226,19 +226,19 @@ wired_add_menu_item (NMDevice *device,
gtk_widget_show (item);
/* Notify user of unmanaged or unavailable device */
item = nma_menu_device_check_unusable (device, carrier ? NULL : _("disconnected"));
item = nma_menu_device_get_menu_item (device, applet, carrier ? NULL : _("disconnected"));
if (item) {
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
goto out;
}
if (g_slist_length (connections))
add_connection_items (device, connections, carrier, active, menu, applet);
else
add_default_connection_item (device, carrier, menu, applet);
if (!nma_menu_device_check_unusable (device)) {
if (g_slist_length (connections))
add_connection_items (device, connections, carrier, active, menu, applet);
else
add_default_connection_item (device, carrier, menu, applet);
}
out:
g_slist_free (connections);
}
......
......@@ -358,6 +358,27 @@ applet_menu_item_activate_helper_part2 (NMConnection *connection,
applet_item_activate_info_destroy (info);
}
static void
disconnect_cb (NMDevice *device, GError *error, gpointer user_data)
{
if (error) {
g_warning ("%s: device disconnect failed: (%d) %s",
__func__,
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
}
}
void
applet_menu_item_disconnect_helper (NMDevice *device,
NMApplet *applet)
{
g_return_if_fail (NM_IS_DEVICE (device));
nm_device_disconnect (device, disconnect_cb, NULL);
}
void
applet_menu_item_activate_helper (NMDevice *device,
NMConnection *connection,
......@@ -1061,9 +1082,50 @@ applet_find_active_connection_for_device (NMDevice *device,
return connection;
}
gboolean
nma_menu_device_check_unusable (NMDevice *device)
{
switch (nm_device_get_state (device)) {
case NM_DEVICE_STATE_UNKNOWN:
case NM_DEVICE_STATE_UNAVAILABLE:
case NM_DEVICE_STATE_UNMANAGED:
return TRUE;
default:
break;
}
return FALSE;
}
struct AppletDeviceMenuInfo {
NMDevice *device;
NMApplet *applet;
};
static void
applet_device_info_destroy (struct AppletDeviceMenuInfo *info)
{
g_return_if_fail (info != NULL);
if (info->device)
g_object_unref (info->device);
memset (info, 0, sizeof (struct AppletDeviceMenuInfo));
g_free (info);
}
static void
applet_device_disconnect_db (GtkMenuItem *item, gpointer user_data)
{
struct AppletDeviceMenuInfo *info = user_data;
applet_menu_item_disconnect_helper (info->device,
info->applet);
}
GtkWidget *
nma_menu_device_check_unusable (NMDevice *device,
const char *unavailable_msg)
nma_menu_device_get_menu_item (NMDevice *device,
NMApplet *applet,
const char *unavailable_msg)
{
GtkWidget *item = NULL;
gboolean managed = TRUE;
......@@ -1075,20 +1137,42 @@ nma_menu_device_check_unusable (NMDevice *device,
case NM_DEVICE_STATE_UNKNOWN:
case NM_DEVICE_STATE_UNAVAILABLE:
item = gtk_menu_item_new_with_label (unavailable_msg);
gtk_widget_set_sensitive (item, FALSE);
break;
case NM_DEVICE_STATE_DISCONNECTED:
unavailable_msg = _("disconnected");
item = gtk_menu_item_new_with_label (unavailable_msg);
gtk_widget_set_sensitive (item, FALSE);
break;
case NM_DEVICE_STATE_UNMANAGED:
managed = FALSE;
break;
case NM_DEVICE_STATE_PREPARE:
case NM_DEVICE_STATE_CONFIG:
case NM_DEVICE_STATE_NEED_AUTH:
case NM_DEVICE_STATE_IP_CONFIG:
case NM_DEVICE_STATE_ACTIVATED:
{
struct AppletDeviceMenuInfo *info = g_new0 (struct AppletDeviceMenuInfo, 1);
info->device = g_object_ref (device);
info->applet = applet;
item = gtk_menu_item_new_with_label (_(" Disconnect"));
g_signal_connect_data (item, "activate",
G_CALLBACK (applet_device_disconnect_db),
info,
(GClosureNotify) applet_device_info_destroy, 0);
gtk_widget_set_sensitive (item, TRUE);
break;
}
default:
managed = nm_device_get_managed (device);
break;
}
if (!managed)
if (!managed) {
item = gtk_menu_item_new_with_label (_("device not managed"));
if (item)
gtk_widget_set_sensitive (item, FALSE);
}
return item;
}
......
......@@ -204,7 +204,10 @@ NMSettingsInterface *applet_get_settings (NMApplet *applet);
GSList *applet_get_all_connections (NMApplet *applet);
GtkWidget *nma_menu_device_check_unusable (NMDevice *device,
gboolean nma_menu_device_check_unusable (NMDevice *device);
GtkWidget * nma_menu_device_get_menu_item (NMDevice *device,
NMApplet *applet,
const char *unavailable_msg);
void applet_menu_item_activate_helper (NMDevice *device,
......@@ -213,6 +216,9 @@ void applet_menu_item_activate_helper (NMDevice *device,
NMApplet *applet,
gpointer dclass_data);
void applet_menu_item_disconnect_helper (NMDevice *device,
NMApplet *applet);
NMSettingsConnectionInterface *applet_get_exported_connection_for_device (NMDevice *device, NMApplet *applet);
void applet_do_notify (NMApplet *applet,
......
......@@ -311,6 +311,10 @@ dispose (GObject *object)
g_object_unref (editor->connection);
editor->connection = NULL;
}
if (editor->orig_connection) {
g_object_unref (editor->orig_connection);
editor->orig_connection = NULL;
}
if (editor->window) {
gtk_widget_destroy (editor->window);
editor->window = NULL;
......@@ -406,7 +410,24 @@ nm_connection_editor_get_connection (NMConnectionEditor *editor)
{
g_return_val_if_fail (NM_IS_CONNECTION_EDITOR (editor), NULL);
return editor->connection;
return editor->orig_connection;
}
gboolean
nm_connection_editor_update_connection (NMConnectionEditor *editor, GError **error)
{
GHashTable *settings;
g_return_val_if_fail (NM_IS_CONNECTION_EDITOR (editor), FALSE);
if (!nm_connection_verify (editor->connection, error))
return FALSE;
/* Copy the modified connection to the original connection */
settings = nm_connection_to_hash (editor->connection);
nm_connection_replace_settings (editor->orig_connection, settings, NULL);
g_hash_table_destroy (settings);
return TRUE;
}
static void
......@@ -541,8 +562,10 @@ nm_connection_editor_set_connection (NMConnectionEditor *editor,
if (editor->connection)
g_object_unref (editor->connection);
editor->connection = g_object_ref (connection);
editor->orig_scope = nm_connection_get_scope (connection);
editor->connection = nm_connection_duplicate (connection);
editor->orig_connection = g_object_ref (connection);
editor->orig_scope = nm_connection_get_scope (editor->connection);
nm_connection_editor_update_title (editor);
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (editor->connection, NM_TYPE_SETTING_CONNECTION));
......
......@@ -39,6 +39,7 @@ typedef struct {
/* private data */
NMConnection *connection;
NMConnection *orig_connection;
gboolean initialized;
NMConnectionScope orig_scope;
......@@ -69,6 +70,7 @@ void nm_connection_editor_present (NMConnectionEditor *editor);
void nm_connection_editor_run (NMConnectionEditor *editor);
void nm_connection_editor_save_vpn_secrets (NMConnectionEditor *editor);
NMConnection * nm_connection_editor_get_connection (NMConnectionEditor *editor);
gboolean nm_connection_editor_update_connection (NMConnectionEditor *editor, GError **error);
GtkWindow * nm_connection_editor_get_window (NMConnectionEditor *editor);
#endif
......@@ -583,12 +583,27 @@ static void
add_response_cb (NMConnectionEditor *editor, gint response, GError *error, gpointer user_data)
{
ActionInfo *info = (ActionInfo *) user_data;
const char *message = _("An unknown error ocurred.");
GError *add_error = NULL;
if (response == GTK_RESPONSE_OK) {
add_connection (info->list, editor, add_finished_cb, editor);
return;
/* Verify and commit user changes */
if (nm_connection_editor_update_connection (editor, &add_error)) {
/* Yay we can try to add the connection; it'll get removed from
* list->editors when the add finishes.
*/
add_connection (info->list, editor, add_finished_cb, editor);
return;
} else {
error_dialog (GTK_WINDOW (editor->window),
_("Error editing connection: property '%s' / '%s' invalid: %d"),
g_type_name (nm_connection_lookup_setting_type_by_quark (add_error->domain)),
(add_error && add_error->message) ? add_error->message : "(unknown)",
add_error ? add_error->code : -1);
g_clear_error (&add_error);
}
} else if (response == GTK_RESPONSE_NONE) {
const char *message = _("An unknown error ocurred.");
if (error && error->message)
message = error->message;
error_dialog (GTK_WINDOW (editor->window),
......@@ -711,8 +726,8 @@ edit_done_cb (NMConnectionEditor *editor, gint response, GError *error, gpointer
switch (response) {
case GTK_RESPONSE_OK:
/* Make sure the connection is valid */
if (nm_connection_verify (connection, &edit_error)) {
/* Verify and commit user changes */
if (nm_connection_editor_update_connection (editor, &edit_error)) {
/* Save the connection to backing storage */
update_connection (info->list,
editor,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment