|
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-editor
|
|
Packit |
5756e2 |
* @short_description: Connection editing form
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* #NmtEditor is the top-level form for editing a connection.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-default.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nmt-editor.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-utils.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nmtui.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-editor-utils.h"
|
|
Packit |
5756e2 |
#include "nmt-utils.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nmt-device-entry.h"
|
|
Packit |
5756e2 |
#include "nmt-mac-entry.h"
|
|
Packit |
5756e2 |
#include "nmt-mtu-entry.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nmt-page-bond.h"
|
|
Packit |
5756e2 |
#include "nmt-page-bridge.h"
|
|
Packit |
5756e2 |
#include "nmt-page-bridge-port.h"
|
|
Packit |
5756e2 |
#include "nmt-page-dsl.h"
|
|
Packit |
5756e2 |
#include "nmt-page-ethernet.h"
|
|
Packit |
5756e2 |
#include "nmt-page-infiniband.h"
|
|
Packit |
5756e2 |
#include "nmt-page-ip-tunnel.h"
|
|
Packit |
5756e2 |
#include "nmt-page-ip4.h"
|
|
Packit |
5756e2 |
#include "nmt-page-ip6.h"
|
|
Packit |
5756e2 |
#include "nmt-page-ppp.h"
|
|
Packit |
5756e2 |
#include "nmt-page-team.h"
|
|
Packit |
5756e2 |
#include "nmt-page-team-port.h"
|
|
Packit |
5756e2 |
#include "nmt-page-vlan.h"
|
|
Packit |
5756e2 |
#include "nmt-page-wifi.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-meta-setting-access.h"
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_DEFINE_TYPE(NmtEditor, nmt_editor, NMT_TYPE_NEWT_FORM)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NMT_EDITOR_GET_PRIVATE(o) \
|
|
Packit Service |
a1bd4f |
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_EDITOR, NmtEditorPrivate))
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
NMConnection *orig_connection;
|
|
Packit Service |
a1bd4f |
NMConnection *edit_connection;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NMEditorConnectionTypeData *type_data;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
GSList * pages;
|
|
Packit Service |
a1bd4f |
NmtNewtWidget *ok, *cancel;
|
|
Packit Service |
a1bd4f |
gboolean running;
|
|
Packit |
5756e2 |
} NmtEditorPrivate;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
enum {
|
|
Packit Service |
a1bd4f |
PROP_0,
|
|
Packit Service |
a1bd4f |
PROP_CONNECTION,
|
|
Packit Service |
a1bd4f |
PROP_TYPE_DATA,
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
LAST_PROP
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nmt_editor_new:
|
|
Packit |
5756e2 |
* @connection: the #NMConnection to edit
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Creates a new #NmtEditor to edit @connection.
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: a new #NmtEditor
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
NmtNewtForm *
|
|
Packit Service |
a1bd4f |
nmt_editor_new(NMConnection *connection)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMEditorConnectionTypeData *type_data;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
type_data = nm_editor_utils_get_connection_type_data(connection);
|
|
Packit Service |
a1bd4f |
if (!type_data) {
|
|
Packit Service |
a1bd4f |
NMSettingConnection *s_con;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
s_con = nm_connection_get_setting_connection(connection);
|
|
Packit Service |
a1bd4f |
if (s_con) {
|
|
Packit Service |
a1bd4f |
nmt_newt_message_dialog(_("Could not create editor for connection '%s' of type '%s'."),
|
|
Packit Service |
a1bd4f |
nm_connection_get_id(connection),
|
|
Packit Service |
a1bd4f |
nm_setting_connection_get_connection_type(s_con));
|
|
Packit Service |
a1bd4f |
} else {
|
|
Packit Service |
a1bd4f |
nmt_newt_message_dialog(_("Could not create editor for invalid connection '%s'."),
|
|
Packit Service |
a1bd4f |
nm_connection_get_id(connection));
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return NULL;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return g_object_new(NMT_TYPE_EDITOR,
|
|
Packit Service |
a1bd4f |
"connection",
|
|
Packit Service |
a1bd4f |
connection,
|
|
Packit Service |
a1bd4f |
"type-data",
|
|
Packit Service |
a1bd4f |
type_data,
|
|
Packit Service |
a1bd4f |
"title",
|
|
Packit Service |
a1bd4f |
_("Edit Connection"),
|
|
Packit Service |
a1bd4f |
"fullscreen-vertical",
|
|
Packit Service |
a1bd4f |
TRUE,
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nmt_editor_init(NmtEditor *entry)
|
|
Packit Service |
a1bd4f |
{}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
connection_updated(GObject *connection, GAsyncResult *result, gpointer op)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
GError *error = NULL;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_remote_connection_commit_changes_finish(NM_REMOTE_CONNECTION(connection), result, &error);
|
|
Packit Service |
a1bd4f |
nmt_sync_op_complete_boolean(op, error == NULL, error);
|
|
Packit Service |
a1bd4f |
g_clear_error(&error);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
connection_added(GObject *client, GAsyncResult *result, gpointer op)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMRemoteConnection *connection;
|
|
Packit Service |
a1bd4f |
GError * error = NULL;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
connection = nm_client_add_connection_finish(NM_CLIENT(client), result, &error);
|
|
Packit Service |
a1bd4f |
nmt_sync_op_complete_boolean(op, error == NULL, error);
|
|
Packit Service |
a1bd4f |
g_clear_object(&connection);
|
|
Packit Service |
a1bd4f |
g_clear_error(&error);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
page_saved(gpointer data, gpointer user_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtEditorPage *page = data;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nmt_editor_page_saved(page);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
save_connection_and_exit(NmtNewtButton *button, gpointer user_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtEditor * editor = user_data;
|
|
Packit Service |
a1bd4f |
NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE(editor);
|
|
Packit Service |
a1bd4f |
NmtSyncOp op;
|
|
Packit Service |
a1bd4f |
GError * error = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_connection_replace_settings_from_connection(priv->orig_connection, priv->edit_connection);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nmt_sync_op_init(&op);
|
|
Packit Service |
a1bd4f |
if (NM_IS_REMOTE_CONNECTION(priv->orig_connection)) {
|
|
Packit Service |
a1bd4f |
nm_remote_connection_commit_changes_async(NM_REMOTE_CONNECTION(priv->orig_connection),
|
|
Packit Service |
a1bd4f |
TRUE,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
connection_updated,
|
|
Packit Service |
a1bd4f |
&op);
|
|
Packit Service |
a1bd4f |
if (!nmt_sync_op_wait_boolean(&op, &error)) {
|
|
Packit Service |
a1bd4f |
nmt_newt_message_dialog(_("Unable to save connection: %s"), error->message);
|
|
Packit Service |
a1bd4f |
g_error_free(error);
|
|
Packit Service |
a1bd4f |
return;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Clear secrets so they don't lay around in memory; they'll get
|
|
Packit Service |
a1bd4f |
* requested again anyway next time the connection is edited.
|
|
Packit Service |
a1bd4f |
*/
|
|
Packit Service |
a1bd4f |
nm_connection_clear_secrets(priv->orig_connection);
|
|
Packit Service |
a1bd4f |
} else {
|
|
Packit Service |
a1bd4f |
nm_client_add_connection_async(nm_client,
|
|
Packit Service |
a1bd4f |
priv->orig_connection,
|
|
Packit Service |
a1bd4f |
TRUE,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
connection_added,
|
|
Packit Service |
a1bd4f |
&op);
|
|
Packit Service |
a1bd4f |
if (!nmt_sync_op_wait_boolean(&op, &error)) {
|
|
Packit Service |
a1bd4f |
nmt_newt_message_dialog(_("Unable to add new connection: %s"), error->message);
|
|
Packit Service |
a1bd4f |
g_error_free(error);
|
|
Packit Service |
a1bd4f |
return;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Let the page know that it was saved. */
|
|
Packit Service |
a1bd4f |
g_slist_foreach(priv->pages, page_saved, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nmt_newt_form_quit(NMT_NEWT_FORM(editor));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
got_secrets(GObject *object, GAsyncResult *result, gpointer op)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
GVariant *secrets;
|
|
Packit Service |
a1bd4f |
GError * error = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
secrets = nm_remote_connection_get_secrets_finish(NM_REMOTE_CONNECTION(object), result, &error);
|
|
Packit Service |
a1bd4f |
if (secrets)
|
|
Packit Service |
a1bd4f |
g_variant_ref(secrets);
|
|
Packit Service |
a1bd4f |
nmt_sync_op_complete_pointer(op, secrets, error);
|
|
Packit Service |
a1bd4f |
g_clear_error(&error);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NMConnection *
|
|
Packit Service |
a1bd4f |
build_edit_connection(NMConnection *orig_connection)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMConnection *edit_connection;
|
|
Packit Service |
a1bd4f |
GVariant * settings, *secrets;
|
|
Packit Service |
a1bd4f |
GVariantIter iter;
|
|
Packit Service |
a1bd4f |
const char * setting_name;
|
|
Packit Service |
a1bd4f |
NmtSyncOp op;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
edit_connection = nm_simple_connection_new_clone(orig_connection);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!NM_IS_REMOTE_CONNECTION(orig_connection))
|
|
Packit Service |
a1bd4f |
return edit_connection;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
settings = nm_connection_to_dbus(orig_connection, NM_CONNECTION_SERIALIZE_NO_SECRETS);
|
|
Packit Service |
a1bd4f |
g_variant_iter_init(&iter, settings);
|
|
Packit Service |
a1bd4f |
while (g_variant_iter_next(&iter, "{&s@a{sv}}", &setting_name, NULL)) {
|
|
Packit Service |
a1bd4f |
if (!nm_meta_setting_info_editor_has_secrets(
|
|
Packit Service |
a1bd4f |
nm_meta_setting_info_editor_find_by_name(setting_name, FALSE)))
|
|
Packit Service |
a1bd4f |
continue;
|
|
Packit Service |
a1bd4f |
nmt_sync_op_init(&op);
|
|
Packit Service |
a1bd4f |
nm_remote_connection_get_secrets_async(NM_REMOTE_CONNECTION(orig_connection),
|
|
Packit Service |
a1bd4f |
setting_name,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
got_secrets,
|
|
Packit Service |
a1bd4f |
&op);
|
|
Packit Service |
a1bd4f |
/* FIXME: error handling */
|
|
Packit Service |
a1bd4f |
secrets = nmt_sync_op_wait_pointer(&op, NULL);
|
|
Packit Service |
a1bd4f |
if (secrets) {
|
|
Packit Service |
a1bd4f |
(void) nm_connection_update_secrets(edit_connection, setting_name, secrets, NULL);
|
|
Packit Service |
a1bd4f |
g_variant_unref(secrets);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
g_variant_unref(settings);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return edit_connection;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
permissions_transform_to_allusers(GBinding * binding,
|
|
Packit Service |
a1bd4f |
const GValue *source_value,
|
|
Packit Service |
a1bd4f |
GValue * target_value,
|
|
Packit Service |
a1bd4f |
gpointer user_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
char **perms = g_value_get_boxed(source_value);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_value_set_boolean(target_value, g_strv_length(perms) == 0);
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
permissions_transform_from_allusers(GBinding * binding,
|
|
Packit Service |
a1bd4f |
const GValue *source_value,
|
|
Packit Service |
a1bd4f |
GValue * target_value,
|
|
Packit Service |
a1bd4f |
gpointer user_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
gboolean allusers = g_value_get_boolean(source_value);
|
|
Packit Service |
a1bd4f |
char ** perms = NULL;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
if (!allusers) {
|
|
Packit Service |
a1bd4f |
perms = g_new(char *, 2);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
perms[0] = g_strdup_printf("user:%s:", g_get_user_name());
|
|
Packit Service |
a1bd4f |
perms[1] = NULL;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
g_value_take_boxed(target_value, perms);
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NmtNewtWidget *
|
|
Packit Service |
a1bd4f |
add_sections_for_page(NmtEditor *editor, NmtEditorGrid *grid, NmtEditorPage *page)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE(editor);
|
|
Packit Service |
a1bd4f |
NmtNewtWidget * first_section = NULL;
|
|
Packit Service |
a1bd4f |
const GSList * sections, *iter;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NMT_IS_EDITOR_PAGE(page), NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
priv->pages = g_slist_prepend(priv->pages, page);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
sections = nmt_editor_page_get_sections(page);
|
|
Packit Service |
a1bd4f |
for (iter = sections; iter; iter = iter->next) {
|
|
Packit Service |
a1bd4f |
if (!first_section)
|
|
Packit Service |
a1bd4f |
first_section = iter->data;
|
|
Packit Service |
a1bd4f |
nmt_editor_grid_append(grid, NULL, iter->data, NULL);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return first_section;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nmt_editor_constructed(GObject *object)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtEditor * editor = NMT_EDITOR(object);
|
|
Packit Service |
a1bd4f |
NmtEditorPrivate * priv = NMT_EDITOR_GET_PRIVATE(editor);
|
|
Packit Service |
a1bd4f |
NMSettingConnection *s_con;
|
|
Packit Service |
a1bd4f |
NmtNewtWidget * vbox, *widget, *buttons;
|
|
Packit Service |
a1bd4f |
NmtEditorGrid * grid;
|
|
Packit Service |
a1bd4f |
const char * deventry_label;
|
|
Packit Service |
a1bd4f |
NmtDeviceEntry * deventry;
|
|
Packit Service |
a1bd4f |
GType hardware_type;
|
|
Packit Service |
a1bd4f |
const char * slave_type;
|
|
Packit Service |
a1bd4f |
NmtEditorPage * page;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (G_OBJECT_CLASS(nmt_editor_parent_class)->constructed)
|
|
Packit Service |
a1bd4f |
G_OBJECT_CLASS(nmt_editor_parent_class)->constructed(object);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
priv->edit_connection = build_edit_connection(priv->orig_connection);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
vbox = nmt_newt_grid_new();
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
s_con = nm_connection_get_setting_connection(priv->edit_connection);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
grid = NMT_EDITOR_GRID(nmt_editor_grid_new());
|
|
Packit Service |
a1bd4f |
nmt_newt_grid_add(NMT_NEWT_GRID(vbox), NMT_NEWT_WIDGET(grid), 0, 0);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Add the top widgets */
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
widget = nmt_newt_entry_new(40, NMT_NEWT_ENTRY_NONEMPTY);
|
|
Packit Service |
a1bd4f |
g_object_bind_property(s_con,
|
|
Packit Service |
a1bd4f |
NM_SETTING_CONNECTION_ID,
|
|
Packit Service |
a1bd4f |
widget,
|
|
Packit Service |
a1bd4f |
"text",
|
|
Packit Service |
a1bd4f |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
Packit Service |
a1bd4f |
nmt_editor_grid_append(grid, _("Profile name"), widget, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (priv->type_data->virtual)
|
|
Packit Service |
a1bd4f |
hardware_type = G_TYPE_NONE;
|
|
Packit Service |
a1bd4f |
else
|
|
Packit Service |
a1bd4f |
hardware_type = priv->type_data->device_type;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* For connections involving multiple network devices, clarify which one
|
|
Packit Service |
a1bd4f |
* NMSettingConnection:interface-name refers to.
|
|
Packit Service |
a1bd4f |
*/
|
|
Packit Service |
a1bd4f |
if (nm_connection_is_type(priv->edit_connection, NM_SETTING_PPPOE_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
deventry_label = _("Ethernet device");
|
|
Packit Service |
a1bd4f |
else
|
|
Packit Service |
a1bd4f |
deventry_label = _("Device");
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
widget = nmt_device_entry_new(deventry_label, 40, hardware_type);
|
|
Packit Service |
a1bd4f |
nmt_editor_grid_append(grid, NULL, widget, NULL);
|
|
Packit Service |
a1bd4f |
deventry = NMT_DEVICE_ENTRY(widget);
|
|
Packit Service |
a1bd4f |
g_object_bind_property(s_con,
|
|
Packit Service |
a1bd4f |
NM_SETTING_CONNECTION_INTERFACE_NAME,
|
|
Packit Service |
a1bd4f |
deventry,
|
|
Packit Service |
a1bd4f |
"interface-name",
|
|
Packit Service |
a1bd4f |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nmt_editor_grid_append(grid, NULL, nmt_newt_separator_new(), NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Now add the various pages... */
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (nm_connection_is_type(priv->edit_connection, NM_SETTING_BOND_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
page = nmt_page_bond_new(priv->edit_connection, deventry);
|
|
Packit Service |
a1bd4f |
else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_BRIDGE_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
page = nmt_page_bridge_new(priv->edit_connection, deventry);
|
|
Packit Service |
a1bd4f |
else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_INFINIBAND_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
page = nmt_page_infiniband_new(priv->edit_connection, deventry);
|
|
Packit Service |
a1bd4f |
else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_PPPOE_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
page = nmt_page_dsl_new(priv->edit_connection, deventry);
|
|
Packit Service |
a1bd4f |
else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_TEAM_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
page = nmt_page_team_new(priv->edit_connection, deventry);
|
|
Packit Service |
a1bd4f |
else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_VLAN_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
page = nmt_page_vlan_new(priv->edit_connection, deventry);
|
|
Packit Service |
a1bd4f |
else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_WIRED_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
page = nmt_page_ethernet_new(priv->edit_connection, deventry);
|
|
Packit Service |
a1bd4f |
else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_WIRELESS_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
page = nmt_page_wifi_new(priv->edit_connection, deventry);
|
|
Packit Service |
a1bd4f |
else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_IP_TUNNEL_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
page = nmt_page_ip_tunnel_new(priv->edit_connection, deventry);
|
|
Packit Service |
a1bd4f |
else
|
|
Packit Service |
a1bd4f |
g_assert_not_reached();
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
add_sections_for_page(editor, grid, page);
|
|
Packit Service |
a1bd4f |
nmt_editor_grid_append(grid, NULL, nmt_newt_separator_new(), NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
slave_type = nm_setting_connection_get_slave_type(s_con);
|
|
Packit Service |
a1bd4f |
if (slave_type) {
|
|
Packit Service |
a1bd4f |
if (!strcmp(slave_type, NM_SETTING_BRIDGE_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
add_sections_for_page(editor, grid, nmt_page_bridge_port_new(priv->edit_connection));
|
|
Packit Service |
a1bd4f |
else if (!strcmp(slave_type, NM_SETTING_TEAM_SETTING_NAME))
|
|
Packit Service |
a1bd4f |
add_sections_for_page(editor, grid, nmt_page_team_port_new(priv->edit_connection));
|
|
Packit Service |
a1bd4f |
} else {
|
|
Packit Service |
a1bd4f |
NmtNewtWidget *section;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
section = add_sections_for_page(editor, grid, nmt_page_ip4_new(priv->edit_connection));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Add a separator between ip4 and ip6 that's only visible if ip4 is open */
|
|
Packit Service |
a1bd4f |
widget = nmt_newt_separator_new();
|
|
Packit Service |
a1bd4f |
g_object_bind_property(section, "open", widget, "visible", G_BINDING_SYNC_CREATE);
|
|
Packit Service |
a1bd4f |
nmt_editor_grid_append(grid, NULL, widget, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
add_sections_for_page(editor, grid, nmt_page_ip6_new(priv->edit_connection));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nmt_editor_grid_append(grid, NULL, nmt_newt_separator_new(), NULL);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* And finally the bottom widgets */
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
widget = nmt_newt_checkbox_new(_("Automatically connect"));
|
|
Packit Service |
a1bd4f |
g_object_bind_property(s_con,
|
|
Packit Service |
a1bd4f |
NM_SETTING_CONNECTION_AUTOCONNECT,
|
|
Packit Service |
a1bd4f |
widget,
|
|
Packit Service |
a1bd4f |
"active",
|
|
Packit Service |
a1bd4f |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
Packit Service |
a1bd4f |
nmt_editor_grid_append(grid, NULL, widget, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
widget = nmt_newt_checkbox_new(_("Available to all users"));
|
|
Packit Service |
a1bd4f |
g_object_bind_property_full(s_con,
|
|
Packit Service |
a1bd4f |
NM_SETTING_CONNECTION_PERMISSIONS,
|
|
Packit Service |
a1bd4f |
widget,
|
|
Packit Service |
a1bd4f |
"active",
|
|
Packit Service |
a1bd4f |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
|
|
Packit Service |
a1bd4f |
permissions_transform_to_allusers,
|
|
Packit Service |
a1bd4f |
permissions_transform_from_allusers,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit Service |
a1bd4f |
nmt_editor_grid_append(grid, NULL, widget, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* And the button box */
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
buttons = nmt_newt_button_box_new(NMT_NEWT_BUTTON_BOX_HORIZONTAL);
|
|
Packit Service |
a1bd4f |
nmt_newt_grid_add(NMT_NEWT_GRID(vbox), buttons, 0, 1);
|
|
Packit Service |
a1bd4f |
nmt_newt_widget_set_padding(buttons, 0, 1, 0, 0);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
priv->cancel = nmt_newt_button_box_add_end(NMT_NEWT_BUTTON_BOX(buttons), _("Cancel"));
|
|
Packit Service |
a1bd4f |
nmt_newt_widget_set_exit_on_activate(priv->cancel, TRUE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
priv->ok = nmt_newt_button_box_add_end(NMT_NEWT_BUTTON_BOX(buttons), _("OK"));
|
|
Packit Service |
a1bd4f |
g_signal_connect(priv->ok, "clicked", G_CALLBACK(save_connection_and_exit), editor);
|
|
Packit Service |
a1bd4f |
g_object_bind_property(NMT_NEWT_WIDGET(grid),
|
|
Packit Service |
a1bd4f |
"valid",
|
|
Packit Service |
a1bd4f |
priv->ok,
|
|
Packit Service |
a1bd4f |
"sensitive",
|
|
Packit Service |
a1bd4f |
G_BINDING_SYNC_CREATE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nmt_newt_form_set_content(NMT_NEWT_FORM(editor), vbox);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nmt_editor_finalize(GObject *object)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE(object);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_clear_object(&priv->orig_connection);
|
|
Packit Service |
a1bd4f |
g_clear_object(&priv->edit_connection);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_slist_free_full(priv->pages, g_object_unref);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_clear_object(&priv->ok);
|
|
Packit Service |
a1bd4f |
g_clear_object(&priv->cancel);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_OBJECT_CLASS(nmt_editor_parent_class)->finalize(object);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nmt_editor_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE(object);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (prop_id) {
|
|
Packit Service |
a1bd4f |
case PROP_CONNECTION:
|
|
Packit Service |
a1bd4f |
priv->orig_connection = g_value_dup_object(value);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_TYPE_DATA:
|
|
Packit Service |
a1bd4f |
priv->type_data = g_value_get_pointer(value);
|
|
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_editor_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE(object);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (prop_id) {
|
|
Packit Service |
a1bd4f |
case PROP_CONNECTION:
|
|
Packit Service |
a1bd4f |
g_value_set_object(value, priv->orig_connection);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_TYPE_DATA:
|
|
Packit Service |
a1bd4f |
g_value_set_pointer(value, priv->type_data);
|
|
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_editor_class_init(NmtEditorClass *entry_class)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
GObjectClass *object_class = G_OBJECT_CLASS(entry_class);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_type_class_add_private(entry_class, sizeof(NmtEditorPrivate));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* virtual methods */
|
|
Packit Service |
a1bd4f |
object_class->constructed = nmt_editor_constructed;
|
|
Packit Service |
a1bd4f |
object_class->set_property = nmt_editor_set_property;
|
|
Packit Service |
a1bd4f |
object_class->get_property = nmt_editor_get_property;
|
|
Packit Service |
a1bd4f |
object_class->finalize = nmt_editor_finalize;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/**
|
|
Packit Service |
a1bd4f |
* NmtEditor:connection:
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* The connection being edited.
|
|
Packit Service |
a1bd4f |
*/
|
|
Packit Service |
a1bd4f |
g_object_class_install_property(
|
|
Packit Service |
a1bd4f |
object_class,
|
|
Packit Service |
a1bd4f |
PROP_CONNECTION,
|
|
Packit Service |
a1bd4f |
g_param_spec_object("connection",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
NM_TYPE_CONNECTION,
|
|
Packit Service |
a1bd4f |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
Packit Service |
a1bd4f |
/**
|
|
Packit Service |
a1bd4f |
* NmtEditor:type-data:
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* The #NmEditorConnectionTypeData for #NmtEditor:connection.
|
|
Packit Service |
a1bd4f |
*/
|
|
Packit Service |
a1bd4f |
g_object_class_install_property(
|
|
Packit Service |
a1bd4f |
object_class,
|
|
Packit Service |
a1bd4f |
PROP_TYPE_DATA,
|
|
Packit Service |
a1bd4f |
g_param_spec_pointer("type-data",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
Packit |
5756e2 |
}
|