mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 12:30:24 +01:00
tui: implement deactivation in "nmtui connect"
This commit is contained in:
parent
0fe46a5839
commit
1d40b9f872
3 changed files with 89 additions and 17 deletions
|
|
@ -57,6 +57,7 @@ typedef struct {
|
|||
NMConnection *conn;
|
||||
NMAccessPoint *ap;
|
||||
NMDevice *device;
|
||||
NMActiveConnection *active;
|
||||
} NmtConnectConnection;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -89,6 +90,7 @@ nmt_connect_connection_free (NmtConnectConnection *nmtconn)
|
|||
{
|
||||
g_clear_object (&nmtconn->conn);
|
||||
g_clear_object (&nmtconn->ap);
|
||||
g_clear_object (&nmtconn->active);
|
||||
g_free (nmtconn->ssid);
|
||||
}
|
||||
|
||||
|
|
@ -374,9 +376,9 @@ sort_nmt_devices (gconstpointer a,
|
|||
return strcmp (nmta->name, nmtb->name);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
connection_is_active (NMConnection *conn,
|
||||
const GPtrArray *acs)
|
||||
static NMActiveConnection *
|
||||
connection_find_ac (NMConnection *conn,
|
||||
const GPtrArray *acs)
|
||||
{
|
||||
NMActiveConnection *ac;
|
||||
const char *path, *ac_path;
|
||||
|
|
@ -388,10 +390,10 @@ connection_is_active (NMConnection *conn,
|
|||
ac_path = nm_active_connection_get_connection (ac);
|
||||
|
||||
if (!strcmp (path, ac_path))
|
||||
return TRUE;
|
||||
return ac;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -448,9 +450,12 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
|
|||
for (citer = nmtdev->conns; citer; citer = citer->next) {
|
||||
nmtconn = citer->data;
|
||||
|
||||
if (nmtconn->conn && connection_is_active (nmtconn->conn, acs))
|
||||
if (nmtconn->conn)
|
||||
nmtconn->active = connection_find_ac (nmtconn->conn, acs);
|
||||
if (nmtconn->active) {
|
||||
g_object_ref (nmtconn->active);
|
||||
active_col = '*';
|
||||
else
|
||||
} else
|
||||
active_col = ' ';
|
||||
|
||||
if (nmtconn->ap) {
|
||||
|
|
@ -481,6 +486,9 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
|
|||
}
|
||||
|
||||
priv->nmt_devices = nmt_devices;
|
||||
|
||||
g_object_notify (G_OBJECT (listbox), "active");
|
||||
g_object_notify (G_OBJECT (listbox), "active-key");
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -548,6 +556,8 @@ nmt_connect_connection_list_class_init (NmtConnectConnectionListClass *list_clas
|
|||
* @connection: (out) (transfer none): the #NMConnection to be activated
|
||||
* @device: (out) (transfer none): the #NMDevice to activate @connection on
|
||||
* @specific_object: (out) (transfer none): the "specific object" to connect to
|
||||
* @active: (out) (transfer none): the #NMActiveConnection corresponding
|
||||
* to the selection, if any.
|
||||
*
|
||||
* Gets information about the indicated connection.
|
||||
*
|
||||
|
|
@ -558,7 +568,8 @@ nmt_connect_connection_list_get_connection (NmtConnectConnectionList *list,
|
|||
const char *identifier,
|
||||
NMConnection **connection,
|
||||
NMDevice **device,
|
||||
NMObject **specific_object)
|
||||
NMObject **specific_object,
|
||||
NMActiveConnection **active)
|
||||
{
|
||||
NmtConnectConnectionListPrivate *priv = NMT_CONNECT_CONNECTION_LIST_GET_PRIVATE (list);
|
||||
GSList *diter, *citer;
|
||||
|
|
@ -612,6 +623,8 @@ nmt_connect_connection_list_get_connection (NmtConnectConnectionList *list,
|
|||
*device = nmtconn->device;
|
||||
if (specific_object)
|
||||
*specific_object = NM_OBJECT (nmtconn->ap);
|
||||
if (active)
|
||||
*active = nmtconn->active;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -622,6 +635,8 @@ nmt_connect_connection_list_get_connection (NmtConnectConnectionList *list,
|
|||
* @connection: (out) (transfer none): the #NMConnection to be activated
|
||||
* @device: (out) (transfer none): the #NMDevice to activate @connection on
|
||||
* @specific_object: (out) (transfer none): the "specific object" to connect to
|
||||
* @active: (out) (transfer none): the #NMActiveConnection corresponding
|
||||
* to the selection, if any.
|
||||
*
|
||||
* Gets information about the selected row.
|
||||
*
|
||||
|
|
@ -631,7 +646,8 @@ gboolean
|
|||
nmt_connect_connection_list_get_selection (NmtConnectConnectionList *list,
|
||||
NMConnection **connection,
|
||||
NMDevice **device,
|
||||
NMObject **specific_object)
|
||||
NMObject **specific_object,
|
||||
NMActiveConnection **active)
|
||||
{
|
||||
NmtConnectConnection *nmtconn;
|
||||
|
||||
|
|
@ -645,6 +661,8 @@ nmt_connect_connection_list_get_selection (NmtConnectConnectionList *list,
|
|||
*device = nmtconn->device;
|
||||
if (specific_object)
|
||||
*specific_object = NM_OBJECT (nmtconn->ap);
|
||||
if (active)
|
||||
*active = nmtconn->active;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,11 +48,13 @@ gboolean nmt_connect_connection_list_get_connection (NmtConnectConnectionList *
|
|||
const char *identifier,
|
||||
NMConnection **connection,
|
||||
NMDevice **device,
|
||||
NMObject **specific_object);
|
||||
NMObject **specific_object,
|
||||
NMActiveConnection **active);
|
||||
gboolean nmt_connect_connection_list_get_selection (NmtConnectConnectionList *list,
|
||||
NMConnection **connection,
|
||||
NMDevice **device,
|
||||
NMObject **specific_object);
|
||||
NMObject **specific_object,
|
||||
NMActiveConnection **active);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -159,11 +159,19 @@ listbox_activated (NmtNewtListbox *listbox,
|
|||
NMConnection *connection;
|
||||
NMDevice *device;
|
||||
NMObject *specific_object;
|
||||
NMActiveConnection *ac;
|
||||
|
||||
if (!nmt_connect_connection_list_get_selection (list, &connection, &device, &specific_object))
|
||||
if (!nmt_connect_connection_list_get_selection (list,
|
||||
&connection,
|
||||
&device,
|
||||
&specific_object,
|
||||
&ac))
|
||||
return;
|
||||
|
||||
activate_connection (connection, device, specific_object);
|
||||
if (ac)
|
||||
nm_client_deactivate_connection (nm_client, ac);
|
||||
else
|
||||
activate_connection (connection, device, specific_object);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -173,6 +181,41 @@ activate_clicked (NmtNewtButton *button,
|
|||
listbox_activated (listbox, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
listbox_active_changed (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer button)
|
||||
{
|
||||
NmtConnectConnectionList *list = NMT_CONNECT_CONNECTION_LIST (object);
|
||||
static const char *activate, *deactivate;
|
||||
static int deactivate_padding, activate_padding;
|
||||
NMActiveConnection *ac;
|
||||
gboolean has_selection;
|
||||
|
||||
if (G_UNLIKELY (activate == NULL)) {
|
||||
int activate_len, deactivate_len;
|
||||
|
||||
activate = _("Activate");
|
||||
activate_len = g_utf8_strlen (activate, -1);
|
||||
deactivate = _("Deactivate");
|
||||
deactivate_len = g_utf8_strlen (deactivate, -1);
|
||||
|
||||
activate_padding = MAX (0, deactivate_len - activate_len);
|
||||
deactivate_padding = MAX (0, activate_len - deactivate_len);
|
||||
}
|
||||
|
||||
has_selection = nmt_connect_connection_list_get_selection (list, NULL, NULL, NULL, &ac);
|
||||
|
||||
nmt_newt_component_set_sensitive (button, has_selection);
|
||||
if (has_selection && ac) {
|
||||
nmt_newt_button_set_label (button, deactivate);
|
||||
nmt_newt_widget_set_padding (button, 0, 0, deactivate_padding, 0);
|
||||
} else {
|
||||
nmt_newt_button_set_label (button, activate);
|
||||
nmt_newt_widget_set_padding (button, 0, 0, activate_padding, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
quit_clicked (NmtNewtButton *button,
|
||||
gpointer user_data)
|
||||
|
|
@ -209,6 +252,8 @@ nmt_connect_connection_list (void)
|
|||
nmt_newt_widget_set_padding (bbox, 1, 1, 0, 1);
|
||||
|
||||
activate = nmt_newt_button_box_add_start (NMT_NEWT_BUTTON_BOX (bbox), _("Activate"));
|
||||
g_signal_connect (list, "notify::active", G_CALLBACK (listbox_active_changed), activate);
|
||||
listbox_active_changed (G_OBJECT (list), NULL, activate);
|
||||
g_signal_connect (activate, "clicked", G_CALLBACK (activate_clicked), list);
|
||||
|
||||
quit = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (bbox), _("Quit"));
|
||||
|
|
@ -227,13 +272,20 @@ nmt_connect_connection (const char *identifier)
|
|||
NMConnection *connection;
|
||||
NMDevice *device;
|
||||
NMObject *specific_object;
|
||||
NMActiveConnection *ac;
|
||||
|
||||
list = nmt_connect_connection_list_new ();
|
||||
if (nmt_connect_connection_list_get_connection (NMT_CONNECT_CONNECTION_LIST (list), identifier,
|
||||
&connection, &device, &specific_object))
|
||||
activate_connection (connection, device, specific_object);
|
||||
else
|
||||
if (!nmt_connect_connection_list_get_connection (NMT_CONNECT_CONNECTION_LIST (list),
|
||||
identifier,
|
||||
&connection,
|
||||
&device,
|
||||
&specific_object,
|
||||
&ac))
|
||||
nmt_newt_message_dialog (_("No such connection '%s'"), identifier);
|
||||
else if (ac)
|
||||
nmt_newt_message_dialog (_("Connection is already active"));
|
||||
else
|
||||
activate_connection (connection, device, specific_object);
|
||||
g_object_unref (list);
|
||||
|
||||
nmtui_quit ();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue