2020-12-23 22:21:36 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-12-02 16:20:26 -05:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2013 Red Hat, Inc.
|
2013-12-02 16:20:26 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:nmt-edit-connection-list
|
|
|
|
|
* @short_description: Connection list for "nmtui edit"
|
|
|
|
|
*
|
|
|
|
|
* #NmtEditConnectionList is the list of connections displayed by
|
|
|
|
|
* "nmtui edit".
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-19 15:23:34 +01:00
|
|
|
#include "libnm-client-aux-extern/nm-default-client.h"
|
2013-12-02 16:20:26 -05:00
|
|
|
|
|
|
|
|
#include "nmtui.h"
|
|
|
|
|
#include "nmtui-edit.h"
|
|
|
|
|
#include "nmt-edit-connection-list.h"
|
|
|
|
|
#include "nmt-editor.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-editor-utils.h"
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(NmtEditConnectionList, nmt_edit_connection_list, NMT_TYPE_NEWT_GRID)
|
|
|
|
|
|
|
|
|
|
#define NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(o) \
|
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionListPrivate))
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
GSList *connections;
|
|
|
|
|
|
|
|
|
|
gboolean grouped;
|
|
|
|
|
NmtEditConnectionListFilter connection_filter;
|
|
|
|
|
gpointer connection_filter_data;
|
|
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
NmtNewtListbox *listbox;
|
2013-12-02 16:20:26 -05:00
|
|
|
NmtNewtButtonBox *buttons;
|
|
|
|
|
|
|
|
|
|
NmtNewtWidget *add;
|
|
|
|
|
NmtNewtWidget *edit;
|
|
|
|
|
NmtNewtWidget *delete;
|
|
|
|
|
NmtNewtWidget *extra;
|
|
|
|
|
} NmtEditConnectionListPrivate;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
|
|
PROP_GROUPED,
|
|
|
|
|
PROP_CONNECTION_FILTER,
|
|
|
|
|
PROP_CONNECTION_FILTER_DATA,
|
|
|
|
|
PROP_EXTRA_WIDGET,
|
|
|
|
|
PROP_CONNECTIONS,
|
|
|
|
|
PROP_NUM_CONNECTIONS,
|
|
|
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
ADD_CONNECTION,
|
|
|
|
|
EDIT_CONNECTION,
|
|
|
|
|
REMOVE_CONNECTION,
|
|
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = {0};
|
|
|
|
|
|
|
|
|
|
static void add_clicked(NmtNewtButton *button, gpointer list);
|
|
|
|
|
static void edit_clicked(NmtNewtButton *button, gpointer list);
|
|
|
|
|
static void delete_clicked(NmtNewtButton *button, gpointer list);
|
|
|
|
|
static void listbox_activated(NmtNewtWidget *listbox, gpointer list);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nmt_edit_connection_list_init(NmtEditConnectionList *list)
|
|
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
2021-11-09 13:28:54 +01:00
|
|
|
NmtNewtWidget *listbox, *buttons;
|
|
|
|
|
NmtNewtGrid *grid = NMT_NEWT_GRID(list);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
listbox = g_object_new(NMT_TYPE_NEWT_LISTBOX,
|
|
|
|
|
"flags",
|
|
|
|
|
NMT_NEWT_LISTBOX_SCROLL | NMT_NEWT_LISTBOX_BORDER,
|
|
|
|
|
"skip-null-keys",
|
|
|
|
|
TRUE,
|
|
|
|
|
NULL);
|
|
|
|
|
priv->listbox = NMT_NEWT_LISTBOX(listbox);
|
|
|
|
|
nmt_newt_grid_add(grid, listbox, 0, 0);
|
|
|
|
|
nmt_newt_grid_set_flags(grid,
|
|
|
|
|
listbox,
|
|
|
|
|
NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y | NMT_NEWT_GRID_EXPAND_X
|
|
|
|
|
| NMT_NEWT_GRID_EXPAND_Y);
|
|
|
|
|
g_signal_connect(priv->listbox, "activated", G_CALLBACK(listbox_activated), list);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
buttons = nmt_newt_button_box_new(NMT_NEWT_BUTTON_BOX_VERTICAL);
|
|
|
|
|
priv->buttons = NMT_NEWT_BUTTON_BOX(buttons);
|
|
|
|
|
nmt_newt_grid_add(grid, buttons, 1, 0);
|
|
|
|
|
nmt_newt_widget_set_padding(buttons, 1, 1, 0, 1);
|
|
|
|
|
nmt_newt_grid_set_flags(grid,
|
|
|
|
|
buttons,
|
|
|
|
|
NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y | NMT_NEWT_GRID_EXPAND_Y);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
priv->add = nmt_newt_button_box_add_start(priv->buttons, _("Add"));
|
|
|
|
|
g_signal_connect(priv->add, "clicked", G_CALLBACK(add_clicked), list);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
priv->edit = nmt_newt_button_box_add_start(priv->buttons, _("Edit..."));
|
|
|
|
|
g_signal_connect(priv->edit, "clicked", G_CALLBACK(edit_clicked), list);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
priv->delete = nmt_newt_button_box_add_start(priv->buttons, _("Delete"));
|
|
|
|
|
g_signal_connect(priv->delete, "clicked", G_CALLBACK(delete_clicked), list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
sort_by_timestamp(gconstpointer a, gconstpointer b)
|
|
|
|
|
{
|
|
|
|
|
NMSettingConnection *s_con_a, *s_con_b;
|
|
|
|
|
guint64 time_a, time_b;
|
|
|
|
|
|
|
|
|
|
s_con_a = nm_connection_get_setting_connection((NMConnection *) a);
|
|
|
|
|
s_con_b = nm_connection_get_setting_connection((NMConnection *) b);
|
|
|
|
|
|
|
|
|
|
time_a = nm_setting_connection_get_timestamp(s_con_a);
|
|
|
|
|
time_b = nm_setting_connection_get_timestamp(s_con_b);
|
|
|
|
|
|
|
|
|
|
return (int) (time_b - time_a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void nmt_edit_connection_list_rebuild(NmtEditConnectionList *list);
|
|
|
|
|
|
|
|
|
|
static void
|
2014-08-03 12:08:31 -04:00
|
|
|
rebuild_on_connection_changed(NMRemoteConnection *connection, gpointer list)
|
2013-12-02 16:20:26 -05:00
|
|
|
{
|
|
|
|
|
nmt_edit_connection_list_rebuild(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_connections(NmtEditConnectionList *list)
|
|
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *conn;
|
|
|
|
|
GSList *iter;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
for (iter = priv->connections; iter; iter = iter->next) {
|
|
|
|
|
conn = iter->data;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-03 12:08:31 -04:00
|
|
|
g_signal_handlers_disconnect_by_func(conn, G_CALLBACK(rebuild_on_connection_changed), list);
|
2013-12-02 16:20:26 -05:00
|
|
|
g_object_unref(conn);
|
|
|
|
|
}
|
|
|
|
|
g_slist_free(priv->connections);
|
2014-10-22 12:32:46 -04:00
|
|
|
priv->connections = NULL;
|
2013-12-02 16:20:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nmt_edit_connection_list_rebuild(NmtEditConnectionList *list)
|
|
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
2021-11-09 13:28:54 +01:00
|
|
|
const GPtrArray *connections;
|
|
|
|
|
GSList *iter;
|
2013-12-02 16:20:26 -05:00
|
|
|
gboolean did_header = FALSE, did_vpn = FALSE;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMEditorConnectionTypeData **types;
|
|
|
|
|
NMConnection *conn, *selected_conn;
|
2014-02-27 14:03:22 -05:00
|
|
|
int i, row, selected_row;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-02-27 14:03:22 -05:00
|
|
|
selected_row = nmt_newt_listbox_get_active(priv->listbox);
|
|
|
|
|
selected_conn = nmt_newt_listbox_get_active_key(priv->listbox);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
free_connections(list);
|
2014-10-22 12:32:46 -04:00
|
|
|
connections = nm_client_get_connections(nm_client);
|
|
|
|
|
for (i = 0; i < connections->len; i++) {
|
|
|
|
|
conn = connections->pdata[i];
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
if (priv->connection_filter
|
2014-10-22 12:32:46 -04:00
|
|
|
&& !priv->connection_filter(list, conn, priv->connection_filter_data))
|
2013-12-02 16:20:26 -05:00
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-03 12:08:31 -04:00
|
|
|
g_signal_connect(conn,
|
|
|
|
|
NM_CONNECTION_CHANGED,
|
|
|
|
|
G_CALLBACK(rebuild_on_connection_changed),
|
|
|
|
|
list);
|
2014-10-22 12:32:46 -04:00
|
|
|
priv->connections = g_slist_prepend(priv->connections, g_object_ref(conn));
|
2013-12-02 16:20:26 -05:00
|
|
|
}
|
|
|
|
|
priv->connections = g_slist_sort(priv->connections, sort_by_timestamp);
|
|
|
|
|
g_object_notify(G_OBJECT(list), "connections");
|
|
|
|
|
g_object_notify(G_OBJECT(list), "num-connections");
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
nmt_newt_component_set_sensitive(NMT_NEWT_COMPONENT(priv->edit), priv->connections != NULL);
|
|
|
|
|
nmt_newt_component_set_sensitive(NMT_NEWT_COMPONENT(priv->delete), priv->connections != NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-02-27 14:03:22 -05:00
|
|
|
nmt_newt_listbox_clear(priv->listbox);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
if (!priv->grouped) {
|
|
|
|
|
/* Just add the connections in order */
|
2014-02-27 14:03:22 -05:00
|
|
|
for (iter = priv->connections, row = 0; iter; iter = iter->next, row++) {
|
2013-12-02 16:20:26 -05:00
|
|
|
conn = iter->data;
|
2014-02-27 14:03:22 -05:00
|
|
|
nmt_newt_listbox_append(priv->listbox, nm_connection_get_id(conn), conn);
|
|
|
|
|
if (conn == selected_conn)
|
|
|
|
|
selected_row = row;
|
2013-12-02 16:20:26 -05:00
|
|
|
}
|
2014-02-27 14:03:22 -05:00
|
|
|
if (selected_row >= row)
|
|
|
|
|
selected_row = row - 1;
|
|
|
|
|
nmt_newt_listbox_set_active(priv->listbox, selected_row);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
types = nm_editor_utils_get_connection_type_list();
|
2014-02-27 14:03:22 -05:00
|
|
|
for (i = row = 0; types[i]; i++) {
|
2013-12-02 16:20:26 -05:00
|
|
|
if (types[i]->setting_type == NM_TYPE_SETTING_VPN) {
|
|
|
|
|
if (did_vpn)
|
|
|
|
|
continue;
|
|
|
|
|
did_vpn = TRUE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
did_header = FALSE;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
for (iter = priv->connections; iter; iter = iter->next) {
|
|
|
|
|
NMSetting *setting;
|
2021-11-09 13:28:54 +01:00
|
|
|
char *indented;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
conn = iter->data;
|
|
|
|
|
setting = nm_connection_get_setting(conn, types[i]->setting_type);
|
|
|
|
|
if (!setting)
|
|
|
|
|
continue;
|
|
|
|
|
if (!nm_connection_is_type(conn, nm_setting_get_name(setting)))
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
if (!did_header) {
|
2014-02-27 14:03:22 -05:00
|
|
|
nmt_newt_listbox_append(priv->listbox, types[i]->name, NULL);
|
|
|
|
|
if (row == selected_row)
|
|
|
|
|
selected_row++;
|
|
|
|
|
row++;
|
2013-12-02 16:20:26 -05:00
|
|
|
did_header = TRUE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
indented = g_strdup_printf(" %s", nm_connection_get_id(conn));
|
2014-02-27 14:03:22 -05:00
|
|
|
nmt_newt_listbox_append(priv->listbox, indented, conn);
|
2013-12-02 16:20:26 -05:00
|
|
|
g_free(indented);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-02-27 14:03:22 -05:00
|
|
|
if (conn == selected_conn)
|
|
|
|
|
selected_row = row;
|
|
|
|
|
row++;
|
2013-12-02 16:20:26 -05:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-02-27 14:03:22 -05:00
|
|
|
if (selected_row >= row)
|
|
|
|
|
selected_row = row - 1;
|
|
|
|
|
nmt_newt_listbox_set_active(priv->listbox, selected_row);
|
2013-12-02 16:20:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-07-20 12:55:59 -04:00
|
|
|
rebuild_on_connections_changed(GObject *object, GParamSpec *pspec, gpointer list)
|
2013-12-02 16:20:26 -05:00
|
|
|
{
|
|
|
|
|
nmt_edit_connection_list_rebuild(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nmt_edit_connection_list_constructed(GObject *object)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NmtEditConnectionList *list = NMT_EDIT_CONNECTION_LIST(object);
|
2013-12-02 16:20:26 -05:00
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
|
|
|
|
|
|
|
|
|
if (priv->extra)
|
|
|
|
|
nmt_newt_button_box_add_widget_end(priv->buttons, priv->extra);
|
|
|
|
|
|
2014-09-29 10:58:16 -04:00
|
|
|
g_signal_connect(nm_client,
|
|
|
|
|
"notify::" NM_CLIENT_CONNECTIONS,
|
2014-07-20 12:55:59 -04:00
|
|
|
G_CALLBACK(rebuild_on_connections_changed),
|
|
|
|
|
list);
|
2013-12-02 16:20:26 -05:00
|
|
|
|
|
|
|
|
nmt_edit_connection_list_rebuild(list);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(nmt_edit_connection_list_parent_class)->constructed(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_clicked(NmtNewtButton *button, gpointer list)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit(list, signals[ADD_CONNECTION], 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
edit_clicked(NmtNewtButton *button, gpointer list)
|
|
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
2013-12-02 16:20:26 -05:00
|
|
|
|
|
|
|
|
connection = nmt_newt_listbox_get_active_key(priv->listbox);
|
|
|
|
|
g_return_if_fail(connection != NULL);
|
|
|
|
|
|
|
|
|
|
g_signal_emit(list, signals[EDIT_CONNECTION], 0, connection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
delete_clicked(NmtNewtButton *button, gpointer list)
|
|
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
2021-11-09 13:28:54 +01:00
|
|
|
NMRemoteConnection *connection;
|
2013-12-02 16:20:26 -05:00
|
|
|
|
|
|
|
|
connection = nmt_newt_listbox_get_active_key(priv->listbox);
|
|
|
|
|
g_return_if_fail(connection != NULL);
|
|
|
|
|
|
|
|
|
|
g_signal_emit(list, signals[REMOVE_CONNECTION], 0, connection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
listbox_activated(NmtNewtWidget *listbox, gpointer list)
|
|
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
|
|
|
|
|
|
|
|
|
edit_clicked(NMT_NEWT_BUTTON(priv->edit), list);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-20 19:05:42 +01:00
|
|
|
static void
|
|
|
|
|
connection_saved(GObject *conn, GAsyncResult *result, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
nm_remote_connection_save_finish(NM_REMOTE_CONNECTION(conn), result, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nmt_edit_connection_list_recommit(NmtEditConnectionList *list)
|
|
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *conn;
|
|
|
|
|
GSList *iter;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-02-20 19:05:42 +01:00
|
|
|
for (iter = priv->connections; iter; iter = iter->next) {
|
|
|
|
|
conn = iter->data;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-02-20 19:05:42 +01:00
|
|
|
if (NM_IS_REMOTE_CONNECTION(conn)
|
|
|
|
|
&& (nm_remote_connection_get_unsaved(NM_REMOTE_CONNECTION(conn)) == FALSE)) {
|
|
|
|
|
nm_remote_connection_save_async(NM_REMOTE_CONNECTION(conn),
|
|
|
|
|
NULL,
|
|
|
|
|
connection_saved,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
static void
|
|
|
|
|
nmt_edit_connection_list_finalize(GObject *object)
|
|
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(object);
|
|
|
|
|
|
|
|
|
|
free_connections(NMT_EDIT_CONNECTION_LIST(object));
|
|
|
|
|
g_clear_object(&priv->extra);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(nmt_edit_connection_list_parent_class)->finalize(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-11-09 13:28:54 +01:00
|
|
|
nmt_edit_connection_list_set_property(GObject *object,
|
2013-12-02 16:20:26 -05:00
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
2021-11-09 13:28:54 +01:00
|
|
|
GParamSpec *pspec)
|
2013-12-02 16:20:26 -05:00
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(object);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_GROUPED:
|
|
|
|
|
priv->grouped = g_value_get_boolean(value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_CONNECTION_FILTER:
|
|
|
|
|
priv->connection_filter = g_value_get_pointer(value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_CONNECTION_FILTER_DATA:
|
|
|
|
|
priv->connection_filter_data = g_value_get_pointer(value);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_EXTRA_WIDGET:
|
|
|
|
|
priv->extra = g_value_get_object(value);
|
|
|
|
|
if (priv->extra)
|
|
|
|
|
g_object_ref_sink(priv->extra);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-11-09 13:28:54 +01:00
|
|
|
nmt_edit_connection_list_get_property(GObject *object,
|
2013-12-02 16:20:26 -05:00
|
|
|
guint prop_id,
|
2021-11-09 13:28:54 +01:00
|
|
|
GValue *value,
|
2013-12-02 16:20:26 -05:00
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(object);
|
2021-11-09 13:28:54 +01:00
|
|
|
GPtrArray *connections;
|
|
|
|
|
GSList *iter;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_GROUPED:
|
|
|
|
|
g_value_set_boolean(value, priv->grouped);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_CONNECTION_FILTER:
|
|
|
|
|
g_value_set_pointer(value, priv->connection_filter);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_CONNECTION_FILTER_DATA:
|
|
|
|
|
g_value_set_pointer(value, priv->connection_filter_data);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_EXTRA_WIDGET:
|
|
|
|
|
g_value_set_object(value, priv->extra);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_CONNECTIONS:
|
|
|
|
|
connections = g_ptr_array_new_with_free_func(g_object_unref);
|
|
|
|
|
for (iter = priv->connections; iter; iter = iter->next)
|
|
|
|
|
g_ptr_array_add(connections, g_object_ref(iter->data));
|
|
|
|
|
g_value_take_boxed(value, connections);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_NUM_CONNECTIONS:
|
|
|
|
|
g_value_set_int(value, g_slist_length(priv->connections));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nmt_edit_connection_list_class_init(NmtEditConnectionListClass *list_class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS(list_class);
|
|
|
|
|
|
|
|
|
|
g_type_class_add_private(list_class, sizeof(NmtEditConnectionListPrivate));
|
|
|
|
|
|
|
|
|
|
/* virtual methods */
|
|
|
|
|
object_class->constructed = nmt_edit_connection_list_constructed;
|
|
|
|
|
object_class->set_property = nmt_edit_connection_list_set_property;
|
|
|
|
|
object_class->get_property = nmt_edit_connection_list_get_property;
|
|
|
|
|
object_class->finalize = nmt_edit_connection_list_finalize;
|
|
|
|
|
|
|
|
|
|
/* signals */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionList::add-connection:
|
|
|
|
|
* @list: the #NmtEditConnectionList
|
|
|
|
|
*
|
|
|
|
|
* Emitted when the user clicks the list's "Add" button.
|
|
|
|
|
*/
|
|
|
|
|
signals[ADD_CONNECTION] =
|
|
|
|
|
g_signal_new("add-connection",
|
|
|
|
|
G_OBJECT_CLASS_TYPE(object_class),
|
2014-01-24 10:24:29 -05:00
|
|
|
G_SIGNAL_RUN_FIRST,
|
2013-12-02 16:20:26 -05:00
|
|
|
G_STRUCT_OFFSET(NmtEditConnectionListClass, add_connection),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
0);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionList::edit-connection:
|
|
|
|
|
* @list: the #NmtEditConnectionList
|
|
|
|
|
* @connection: the connection to edit
|
|
|
|
|
*
|
|
|
|
|
* Emitted when the user clicks the list's "Edit" button, or
|
|
|
|
|
* hits "Return" on the listbox.
|
|
|
|
|
*/
|
|
|
|
|
signals[EDIT_CONNECTION] =
|
|
|
|
|
g_signal_new("edit-connection",
|
|
|
|
|
G_OBJECT_CLASS_TYPE(object_class),
|
2014-01-24 10:24:29 -05:00
|
|
|
G_SIGNAL_RUN_FIRST,
|
2013-12-02 16:20:26 -05:00
|
|
|
G_STRUCT_OFFSET(NmtEditConnectionListClass, edit_connection),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
1,
|
|
|
|
|
NM_TYPE_CONNECTION);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionList::remove-connection:
|
|
|
|
|
* @list: the #NmtEditConnectionList
|
|
|
|
|
* @connection: the connection to remove
|
|
|
|
|
*
|
|
|
|
|
* Emitted when the user clicks the list's "Delete" button.
|
|
|
|
|
*/
|
|
|
|
|
signals[REMOVE_CONNECTION] =
|
|
|
|
|
g_signal_new("remove-connection",
|
|
|
|
|
G_OBJECT_CLASS_TYPE(object_class),
|
2014-01-24 10:24:29 -05:00
|
|
|
G_SIGNAL_RUN_FIRST,
|
2013-12-02 16:20:26 -05:00
|
|
|
G_STRUCT_OFFSET(NmtEditConnectionListClass, remove_connection),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
1,
|
|
|
|
|
NM_TYPE_CONNECTION);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
/* properties */
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionList:grouped:
|
|
|
|
|
*
|
|
|
|
|
* If %TRUE, connections should be grouped by type, with headers
|
|
|
|
|
* indicating the types (as in the main connection list). If %FALSE,
|
|
|
|
|
* they will not be grouped (as in slave connection lists).
|
|
|
|
|
*/
|
2014-06-09 16:17:37 -04:00
|
|
|
g_object_class_install_property(
|
|
|
|
|
object_class,
|
|
|
|
|
PROP_GROUPED,
|
|
|
|
|
g_param_spec_boolean("grouped",
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
TRUE,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionListFilter:
|
|
|
|
|
* @list: the #NmtEditConnectionList
|
|
|
|
|
* @connection: an #NMConnection
|
|
|
|
|
* @user_data: the user data
|
|
|
|
|
*
|
|
|
|
|
* Decides whether @connection should be displayed in @list.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE or %FALSE
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionList:connection-filter:
|
|
|
|
|
*
|
|
|
|
|
* A callback function for filtering which connections appear in
|
|
|
|
|
* the list.
|
|
|
|
|
*/
|
2014-06-09 16:17:37 -04:00
|
|
|
g_object_class_install_property(
|
|
|
|
|
object_class,
|
|
|
|
|
PROP_CONNECTION_FILTER,
|
|
|
|
|
g_param_spec_pointer("connection-filter",
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2013-12-02 16:20:26 -05:00
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionList:connection-filter-data:
|
|
|
|
|
*
|
|
|
|
|
* Data for the #NmtEditConnectionList:connection-filter.
|
|
|
|
|
*/
|
2014-06-09 16:17:37 -04:00
|
|
|
g_object_class_install_property(
|
|
|
|
|
object_class,
|
|
|
|
|
PROP_CONNECTION_FILTER_DATA,
|
|
|
|
|
g_param_spec_pointer("connection-filter-data",
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionList:extra-widget:
|
|
|
|
|
*
|
|
|
|
|
* An extra button widget to display at the bottom of the button
|
|
|
|
|
* box.
|
|
|
|
|
*/
|
2014-06-09 16:17:37 -04:00
|
|
|
g_object_class_install_property(
|
|
|
|
|
object_class,
|
|
|
|
|
PROP_EXTRA_WIDGET,
|
|
|
|
|
g_param_spec_object("extra-widget",
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NMT_TYPE_NEWT_WIDGET,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionList:connections:
|
|
|
|
|
*
|
|
|
|
|
* The list of connections in the widget.
|
|
|
|
|
*
|
|
|
|
|
* Element-Type: #NMConnection
|
|
|
|
|
*/
|
2014-06-09 16:17:37 -04:00
|
|
|
g_object_class_install_property(object_class,
|
|
|
|
|
PROP_CONNECTIONS,
|
|
|
|
|
g_param_spec_boxed("connections",
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
G_TYPE_PTR_ARRAY,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-12-02 16:20:26 -05:00
|
|
|
/**
|
|
|
|
|
* NmtEditConnectionList:num-connections:
|
|
|
|
|
*
|
|
|
|
|
* The number of connections in the widget.
|
|
|
|
|
*/
|
2014-06-09 16:17:37 -04:00
|
|
|
g_object_class_install_property(object_class,
|
|
|
|
|
PROP_NUM_CONNECTIONS,
|
|
|
|
|
g_param_spec_int("num-connections",
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
0,
|
|
|
|
|
G_MAXINT,
|
|
|
|
|
0,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2013-12-02 16:20:26 -05:00
|
|
|
}
|