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