|
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:nmtui-edit
|
|
Packit |
5756e2 |
* @short_description: nm-connection-editor-like functionality
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* nmtui-edit implements editing #NMConnections.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit Service |
2bceb2 |
#include "libnm/nm-default-client.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include <stdlib.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 |
#include "nmt-utils.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-editor-utils.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
list_add_connection(NmtEditConnectionList *list, gpointer form)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nmt_add_connection();
|
|
Packit Service |
a1bd4f |
nmt_newt_form_set_focus(form, NMT_NEWT_WIDGET(list));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
list_edit_connection(NmtEditConnectionList *list, NMConnection *connection, gpointer form)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nmt_edit_connection(connection);
|
|
Packit Service |
a1bd4f |
nmt_newt_form_set_focus(form, NMT_NEWT_WIDGET(list));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
list_remove_connection(NmtEditConnectionList *list, NMRemoteConnection *connection, gpointer form)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nmt_remove_connection(connection);
|
|
Packit Service |
a1bd4f |
nmt_newt_form_set_focus(form, NMT_NEWT_WIDGET(list));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
edit_connection_list_filter(NmtEditConnectionList *list,
|
|
Packit Service |
a1bd4f |
NMConnection * connection,
|
|
Packit Service |
a1bd4f |
gpointer user_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingConnection *s_con;
|
|
Packit Service |
a1bd4f |
const char * master, *slave_type;
|
|
Packit Service |
a1bd4f |
const char * uuid, *ifname;
|
|
Packit Service |
a1bd4f |
const GPtrArray * conns;
|
|
Packit Service |
a1bd4f |
int i;
|
|
Packit Service |
a1bd4f |
gboolean found_master = FALSE;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
s_con = nm_connection_get_setting_connection(connection);
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(s_con != NULL, FALSE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
master = nm_setting_connection_get_master(s_con);
|
|
Packit Service |
a1bd4f |
if (!master)
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit Service |
a1bd4f |
slave_type = nm_setting_connection_get_slave_type(s_con);
|
|
Packit Service |
a1bd4f |
if (g_strcmp0(slave_type, NM_SETTING_BOND_SETTING_NAME) != 0
|
|
Packit Service |
a1bd4f |
&& g_strcmp0(slave_type, NM_SETTING_TEAM_SETTING_NAME) != 0
|
|
Packit Service |
a1bd4f |
&& g_strcmp0(slave_type, NM_SETTING_BRIDGE_SETTING_NAME) != 0)
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
conns = nm_client_get_connections(nm_client);
|
|
Packit Service |
a1bd4f |
for (i = 0; i < conns->len; i++) {
|
|
Packit Service |
a1bd4f |
NMConnection *candidate = conns->pdata[i];
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
uuid = nm_connection_get_uuid(candidate);
|
|
Packit Service |
a1bd4f |
ifname = nm_connection_get_interface_name(candidate);
|
|
Packit Service |
a1bd4f |
if (!g_strcmp0(master, uuid) || !g_strcmp0(master, ifname)) {
|
|
Packit Service |
a1bd4f |
found_master = TRUE;
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return !found_master;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NmtNewtForm *
|
|
Packit Service |
a1bd4f |
nmt_edit_main_connection_list(gboolean is_top)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
int screen_width, screen_height;
|
|
Packit Service |
a1bd4f |
NmtNewtForm * form;
|
|
Packit Service |
a1bd4f |
NmtNewtWidget *quit, *list;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
newtGetScreenSize(&screen_width, &screen_height);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
form = g_object_new(NMT_TYPE_NEWT_FORM,
|
|
Packit Service |
a1bd4f |
"y",
|
|
Packit Service |
a1bd4f |
2,
|
|
Packit Service |
a1bd4f |
"height",
|
|
Packit Service |
a1bd4f |
screen_height - 4,
|
|
Packit Service |
a1bd4f |
"escape-exits",
|
|
Packit Service |
a1bd4f |
TRUE,
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
quit = nmt_newt_button_new(is_top ? _("Quit") : _("Back"));
|
|
Packit Service |
a1bd4f |
nmt_newt_widget_set_exit_on_activate(quit, TRUE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
list = g_object_new(NMT_TYPE_EDIT_CONNECTION_LIST,
|
|
Packit Service |
a1bd4f |
"extra-widget",
|
|
Packit Service |
a1bd4f |
quit,
|
|
Packit Service |
a1bd4f |
"connection-filter",
|
|
Packit Service |
a1bd4f |
edit_connection_list_filter,
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_signal_connect(list, "add-connection", G_CALLBACK(list_add_connection), form);
|
|
Packit Service |
a1bd4f |
g_signal_connect(list, "edit-connection", G_CALLBACK(list_edit_connection), form);
|
|
Packit Service |
a1bd4f |
g_signal_connect(list, "remove-connection", G_CALLBACK(list_remove_connection), form);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nmt_newt_form_set_content(form, list);
|
|
Packit Service |
a1bd4f |
return form;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NMT_TYPE_ADD_CONNECTION (nmt_add_connection_get_type())
|
|
Packit Service |
a1bd4f |
#define NMT_ADD_CONNECTION(obj) \
|
|
Packit Service |
a1bd4f |
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_ADD_CONNECTION, NmtAddConnection))
|
|
Packit Service |
a1bd4f |
#define NMT_IS_ADD_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_ADD_CONNECTION))
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
typedef NmtNewtForm NmtAddConnection;
|
|
Packit |
5756e2 |
typedef NmtNewtFormClass NmtAddConnectionClass;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
GType nmt_add_connection_get_type(void);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_DEFINE_TYPE(NmtAddConnection, nmt_add_connection, NMT_TYPE_NEWT_FORM)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NMT_ADD_CONNECTION_GET_PRIVATE(o) \
|
|
Packit Service |
a1bd4f |
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_ADD_CONNECTION, NmtAddConnectionPrivate))
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
NmtNewtTextbox *textbox;
|
|
Packit Service |
a1bd4f |
NmtNewtListbox *listbox;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
char * primary_text;
|
|
Packit Service |
a1bd4f |
char * secondary_text;
|
|
Packit Service |
a1bd4f |
NMConnection * master;
|
|
Packit Service |
a1bd4f |
NmtAddConnectionTypeFilter type_filter;
|
|
Packit Service |
a1bd4f |
gpointer type_filter_data;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
gboolean single_type;
|
|
Packit |
5756e2 |
} NmtAddConnectionPrivate;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
enum {
|
|
Packit Service |
a1bd4f |
PROP_0,
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
PROP_PRIMARY_TEXT,
|
|
Packit Service |
a1bd4f |
PROP_SECONDARY_TEXT,
|
|
Packit Service |
a1bd4f |
PROP_MASTER,
|
|
Packit Service |
a1bd4f |
PROP_TYPE_FILTER,
|
|
Packit Service |
a1bd4f |
PROP_TYPE_FILTER_DATA,
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
LAST_PROP
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
create_connection(NmtNewtWidget *widget, gpointer list)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE(list);
|
|
Packit Service |
a1bd4f |
GType type = (GType) GPOINTER_TO_SIZE(nmt_newt_listbox_get_active_key(priv->listbox));
|
|
Packit Service |
a1bd4f |
NMConnection *connection;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
connection = nm_editor_utils_create_connection(type, priv->master, nm_client);
|
|
Packit Service |
a1bd4f |
nmt_edit_connection(connection);
|
|
Packit Service |
a1bd4f |
g_object_unref(connection);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
create_connection_and_quit(NmtNewtWidget *widget, gpointer list)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
create_connection(widget, list);
|
|
Packit Service |
a1bd4f |
nmt_newt_form_quit(list);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nmt_add_connection_init(NmtAddConnection *form)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE(form);
|
|
Packit Service |
a1bd4f |
NmtNewtWidget * textbox, *listbox, *button;
|
|
Packit Service |
a1bd4f |
NmtNewtGrid * grid, *buttons;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
grid = NMT_NEWT_GRID(nmt_newt_grid_new());
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
textbox = nmt_newt_textbox_new(0, 60);
|
|
Packit Service |
a1bd4f |
priv->textbox = NMT_NEWT_TEXTBOX(textbox);
|
|
Packit Service |
a1bd4f |
nmt_newt_grid_add(grid, textbox, 0, 0);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
listbox = nmt_newt_listbox_new(5, NMT_NEWT_LISTBOX_SCROLL);
|
|
Packit Service |
a1bd4f |
priv->listbox = NMT_NEWT_LISTBOX(listbox);
|
|
Packit Service |
a1bd4f |
g_signal_connect(priv->listbox, "activated", G_CALLBACK(create_connection_and_quit), form);
|
|
Packit Service |
a1bd4f |
nmt_newt_grid_add(grid, listbox, 0, 1);
|
|
Packit Service |
a1bd4f |
nmt_newt_widget_set_padding(listbox, 0, 1, 0, 0);
|
|
Packit Service |
a1bd4f |
nmt_newt_grid_set_flags(grid, listbox, NMT_NEWT_GRID_EXPAND_X);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
// FIXME: VPN description textbox
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
buttons = NMT_NEWT_GRID(nmt_newt_grid_new());
|
|
Packit Service |
a1bd4f |
nmt_newt_grid_add(grid, NMT_NEWT_WIDGET(buttons), 0, 2);
|
|
Packit Service |
a1bd4f |
nmt_newt_widget_set_padding(NMT_NEWT_WIDGET(buttons), 0, 1, 0, 0);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
button = g_object_ref_sink(nmt_newt_button_new(_("Cancel")));
|
|
Packit Service |
a1bd4f |
nmt_newt_widget_set_exit_on_activate(button, TRUE);
|
|
Packit Service |
a1bd4f |
nmt_newt_grid_add(NMT_NEWT_GRID(buttons), button, 0, 0);
|
|
Packit Service |
a1bd4f |
nmt_newt_widget_set_padding(button, 0, 0, 1, 0);
|
|
Packit Service |
a1bd4f |
nmt_newt_grid_set_flags(NMT_NEWT_GRID(buttons),
|
|
Packit Service |
a1bd4f |
button,
|
|
Packit Service |
a1bd4f |
NMT_NEWT_GRID_EXPAND_X | NMT_NEWT_GRID_ANCHOR_RIGHT
|
|
Packit Service |
a1bd4f |
| NMT_NEWT_GRID_FILL_Y);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
button = g_object_ref_sink(nmt_newt_button_new(_("Create")));
|
|
Packit Service |
a1bd4f |
g_signal_connect(button, "clicked", G_CALLBACK(create_connection_and_quit), form);
|
|
Packit Service |
a1bd4f |
nmt_newt_grid_add(NMT_NEWT_GRID(buttons), button, 1, 0);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nmt_newt_form_set_content(NMT_NEWT_FORM(form), NMT_NEWT_WIDGET(grid));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nmt_add_connection_constructed(GObject *object)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtAddConnectionPrivate * priv = NMT_ADD_CONNECTION_GET_PRIVATE(object);
|
|
Packit Service |
a1bd4f |
NMEditorConnectionTypeData **types;
|
|
Packit Service |
a1bd4f |
char * text;
|
|
Packit Service |
a1bd4f |
int i, num_types;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (priv->secondary_text) {
|
|
Packit Service |
a1bd4f |
text = g_strdup_printf("%s\n\n%s", priv->primary_text, priv->secondary_text);
|
|
Packit Service |
a1bd4f |
} else
|
|
Packit Service |
a1bd4f |
text = g_strdup(priv->primary_text);
|
|
Packit Service |
a1bd4f |
nmt_newt_textbox_set_text(priv->textbox, text);
|
|
Packit Service |
a1bd4f |
g_free(text);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
types = nm_editor_utils_get_connection_type_list();
|
|
Packit Service |
a1bd4f |
for (i = num_types = 0; types[i]; i++) {
|
|
Packit Service |
a1bd4f |
if (priv->type_filter && !priv->type_filter(types[i]->setting_type, priv->type_filter_data))
|
|
Packit Service |
a1bd4f |
continue;
|
|
Packit Service |
a1bd4f |
nmt_newt_listbox_append(priv->listbox,
|
|
Packit Service |
a1bd4f |
types[i]->name,
|
|
Packit Service |
a1bd4f |
GSIZE_TO_POINTER(types[i]->setting_type));
|
|
Packit Service |
a1bd4f |
num_types++;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (num_types == 1)
|
|
Packit Service |
a1bd4f |
priv->single_type = TRUE;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
G_OBJECT_CLASS(nmt_add_connection_parent_class)->constructed(object);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nmt_add_connection_show(NmtNewtForm *form)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE(form);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
if (priv->single_type) {
|
|
Packit Service |
a1bd4f |
nmt_newt_listbox_set_active(priv->listbox, 0);
|
|
Packit Service |
a1bd4f |
create_connection(NMT_NEWT_WIDGET(priv->listbox), g_object_ref(form));
|
|
Packit Service |
a1bd4f |
} else
|
|
Packit Service |
a1bd4f |
NMT_NEWT_FORM_CLASS(nmt_add_connection_parent_class)->show(form);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nmt_add_connection_finalize(GObject *object)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE(object);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_free(priv->primary_text);
|
|
Packit Service |
a1bd4f |
g_free(priv->secondary_text);
|
|
Packit Service |
a1bd4f |
g_clear_object(&priv->master);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_OBJECT_CLASS(nmt_add_connection_parent_class)->finalize(object);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nmt_add_connection_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 |
NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE(object);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (prop_id) {
|
|
Packit Service |
a1bd4f |
case PROP_PRIMARY_TEXT:
|
|
Packit Service |
a1bd4f |
priv->primary_text = g_value_dup_string(value);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_SECONDARY_TEXT:
|
|
Packit Service |
a1bd4f |
priv->secondary_text = g_value_dup_string(value);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_MASTER:
|
|
Packit Service |
a1bd4f |
priv->master = g_value_dup_object(value);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_TYPE_FILTER:
|
|
Packit Service |
a1bd4f |
priv->type_filter = g_value_get_pointer(value);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_TYPE_FILTER_DATA:
|
|
Packit Service |
a1bd4f |
priv->type_filter_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_add_connection_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE(object);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (prop_id) {
|
|
Packit Service |
a1bd4f |
case PROP_PRIMARY_TEXT:
|
|
Packit Service |
a1bd4f |
g_value_set_string(value, priv->primary_text);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_SECONDARY_TEXT:
|
|
Packit Service |
a1bd4f |
g_value_set_string(value, priv->secondary_text);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_MASTER:
|
|
Packit Service |
a1bd4f |
g_value_set_object(value, priv->master);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_TYPE_FILTER:
|
|
Packit Service |
a1bd4f |
g_value_set_pointer(value, priv->type_filter);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_TYPE_FILTER_DATA:
|
|
Packit Service |
a1bd4f |
g_value_set_pointer(value, priv->type_filter_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_add_connection_class_init(NmtAddConnectionClass *add_class)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
GObjectClass * object_class = G_OBJECT_CLASS(add_class);
|
|
Packit Service |
a1bd4f |
NmtNewtFormClass *form_class = NMT_NEWT_FORM_CLASS(add_class);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_type_class_add_private(add_class, sizeof(NmtAddConnectionPrivate));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* virtual methods */
|
|
Packit Service |
a1bd4f |
object_class->constructed = nmt_add_connection_constructed;
|
|
Packit Service |
a1bd4f |
object_class->set_property = nmt_add_connection_set_property;
|
|
Packit Service |
a1bd4f |
object_class->get_property = nmt_add_connection_get_property;
|
|
Packit Service |
a1bd4f |
object_class->finalize = nmt_add_connection_finalize;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
form_class->show = nmt_add_connection_show;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_object_class_install_property(
|
|
Packit Service |
a1bd4f |
object_class,
|
|
Packit Service |
a1bd4f |
PROP_PRIMARY_TEXT,
|
|
Packit Service |
a1bd4f |
g_param_spec_string("primary-text",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
_("Select the type of connection you wish to create."),
|
|
Packit Service |
a1bd4f |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
Packit Service |
a1bd4f |
g_object_class_install_property(
|
|
Packit Service |
a1bd4f |
object_class,
|
|
Packit Service |
a1bd4f |
PROP_SECONDARY_TEXT,
|
|
Packit Service |
a1bd4f |
g_param_spec_string("secondary-text",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit |
5756e2 |
#if 0
|
|
Packit Service |
a1bd4f |
_("If you are creating a VPN, and the VPN connection you "
|
|
Packit Service |
a1bd4f |
"wish to create does not appear in the list, you may "
|
|
Packit Service |
a1bd4f |
"not have the correct VPN plugin installed."),
|
|
Packit |
5756e2 |
#else
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit |
5756e2 |
#endif
|
|
Packit Service |
a1bd4f |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
Packit Service |
a1bd4f |
g_object_class_install_property(
|
|
Packit Service |
a1bd4f |
object_class,
|
|
Packit Service |
a1bd4f |
PROP_MASTER,
|
|
Packit Service |
a1bd4f |
g_param_spec_object("master",
|
|
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 |
g_object_class_install_property(
|
|
Packit Service |
a1bd4f |
object_class,
|
|
Packit Service |
a1bd4f |
PROP_TYPE_FILTER,
|
|
Packit Service |
a1bd4f |
g_param_spec_pointer("type-filter",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
Packit Service |
a1bd4f |
g_object_class_install_property(
|
|
Packit Service |
a1bd4f |
object_class,
|
|
Packit Service |
a1bd4f |
PROP_TYPE_FILTER_DATA,
|
|
Packit Service |
a1bd4f |
g_param_spec_pointer("type-filter-data",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
void
|
|
Packit Service |
a1bd4f |
nmt_add_connection(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtNewtForm *form;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
form = g_object_new(NMT_TYPE_ADD_CONNECTION, "title", _("New Connection"), NULL);
|
|
Packit Service |
a1bd4f |
nmt_newt_form_show(form);
|
|
Packit Service |
a1bd4f |
g_object_unref(form);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
void
|
|
Packit Service |
a1bd4f |
nmt_add_connection_full(const char * primary_text,
|
|
Packit Service |
a1bd4f |
const char * secondary_text,
|
|
Packit Service |
a1bd4f |
NMConnection * master,
|
|
Packit Service |
a1bd4f |
NmtAddConnectionTypeFilter type_filter,
|
|
Packit Service |
a1bd4f |
gpointer type_filter_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtNewtForm *form;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
form = g_object_new(NMT_TYPE_ADD_CONNECTION,
|
|
Packit Service |
a1bd4f |
"title",
|
|
Packit Service |
a1bd4f |
_("New Connection"),
|
|
Packit Service |
a1bd4f |
"primary-text",
|
|
Packit Service |
a1bd4f |
primary_text,
|
|
Packit Service |
a1bd4f |
"secondary-text",
|
|
Packit Service |
a1bd4f |
secondary_text,
|
|
Packit Service |
a1bd4f |
"master",
|
|
Packit Service |
a1bd4f |
master,
|
|
Packit Service |
a1bd4f |
"type-filter",
|
|
Packit Service |
a1bd4f |
type_filter,
|
|
Packit Service |
a1bd4f |
"type-filter-data",
|
|
Packit Service |
a1bd4f |
type_filter_data,
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit Service |
a1bd4f |
nmt_newt_form_show(form);
|
|
Packit Service |
a1bd4f |
g_object_unref(form);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
void
|
|
Packit Service |
a1bd4f |
nmt_edit_connection(NMConnection *connection)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NmtNewtForm *editor;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
editor = nmt_editor_new(connection);
|
|
Packit Service |
a1bd4f |
if (!editor)
|
|
Packit Service |
a1bd4f |
return;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nmt_newt_form_show(editor);
|
|
Packit Service |
a1bd4f |
g_object_unref(editor);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
NmtSyncOp op;
|
|
Packit Service |
a1bd4f |
gboolean got_callback, got_signal;
|
|
Packit Service |
a1bd4f |
NMRemoteConnection *connection;
|
|
Packit |
5756e2 |
} ConnectionDeleteData;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
connection_deleted_callback(GObject *connection, GAsyncResult *result, gpointer user_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
ConnectionDeleteData *data = user_data;
|
|
Packit Service |
a1bd4f |
GError * error = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!nm_remote_connection_delete_finish(data->connection, result, &error)) {
|
|
Packit Service |
a1bd4f |
nmt_newt_message_dialog(_("Unable to delete connection: %s"), error->message);
|
|
Packit Service |
a1bd4f |
} else
|
|
Packit Service |
a1bd4f |
data->got_callback = TRUE;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (error || (data->got_callback && data->got_signal))
|
|
Packit Service |
a1bd4f |
nmt_sync_op_complete_boolean(&data->op, error == NULL, error);
|
|
Packit Service |
a1bd4f |
g_clear_error(&error);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
connection_removed_signal(NMClient *client, NMRemoteConnection *connection, gpointer user_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
ConnectionDeleteData *data = user_data;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
if (connection == data->connection) {
|
|
Packit Service |
a1bd4f |
data->got_signal = TRUE;
|
|
Packit Service |
a1bd4f |
if (data->got_callback && data->got_signal)
|
|
Packit Service |
a1bd4f |
nmt_sync_op_complete_boolean(&data->op, TRUE, NULL);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
remove_one_connection(NMRemoteConnection *connection)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
ConnectionDeleteData data;
|
|
Packit Service |
a1bd4f |
GError * error = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
data.got_callback = data.got_signal = FALSE;
|
|
Packit Service |
a1bd4f |
nmt_sync_op_init(&data.op);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
data.connection = connection;
|
|
Packit Service |
a1bd4f |
g_signal_connect(nm_client,
|
|
Packit Service |
a1bd4f |
NM_CLIENT_CONNECTION_REMOVED,
|
|
Packit Service |
a1bd4f |
G_CALLBACK(connection_removed_signal),
|
|
Packit Service |
a1bd4f |
&data);
|
|
Packit Service |
a1bd4f |
nm_remote_connection_delete_async(connection, NULL, connection_deleted_callback, &data);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!nmt_sync_op_wait_boolean(&data.op, &error)) {
|
|
Packit Service |
a1bd4f |
nmt_newt_message_dialog(_("Could not delete connection '%s': %s"),
|
|
Packit Service |
a1bd4f |
nm_connection_get_id(NM_CONNECTION(connection)),
|
|
Packit Service |
a1bd4f |
error->message);
|
|
Packit Service |
a1bd4f |
g_error_free(error);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_signal_handlers_disconnect_by_func(nm_client, G_CALLBACK(connection_removed_signal), &data);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
void
|
|
Packit Service |
a1bd4f |
nmt_remove_connection(NMRemoteConnection *connection)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
const GPtrArray * all_conns;
|
|
Packit Service |
a1bd4f |
GSList * slaves, *iter;
|
|
Packit Service |
a1bd4f |
int i;
|
|
Packit Service |
a1bd4f |
NMRemoteConnection * slave;
|
|
Packit Service |
a1bd4f |
NMSettingConnection *s_con;
|
|
Packit Service |
a1bd4f |
const char * uuid, *iface, *master;
|
|
Packit Service |
a1bd4f |
int choice;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
choice = nmt_newt_choice_dialog(_("Cancel"),
|
|
Packit Service |
a1bd4f |
_("Delete"),
|
|
Packit Service |
a1bd4f |
_("Are you sure you want to delete the connection '%s'?"),
|
|
Packit Service |
a1bd4f |
nm_connection_get_id(NM_CONNECTION(connection)));
|
|
Packit Service |
a1bd4f |
if (choice == 1)
|
|
Packit Service |
a1bd4f |
return;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_object_ref(connection);
|
|
Packit Service |
a1bd4f |
remove_one_connection(connection);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
uuid = nm_connection_get_uuid(NM_CONNECTION(connection));
|
|
Packit Service |
a1bd4f |
iface = nm_connection_get_interface_name(NM_CONNECTION(connection));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
all_conns = nm_client_get_connections(nm_client);
|
|
Packit Service |
a1bd4f |
slaves = NULL;
|
|
Packit Service |
a1bd4f |
for (i = 0; i < all_conns->len; i++) {
|
|
Packit Service |
a1bd4f |
slave = all_conns->pdata[i];
|
|
Packit Service |
a1bd4f |
s_con = nm_connection_get_setting_connection(NM_CONNECTION(slave));
|
|
Packit Service |
a1bd4f |
master = nm_setting_connection_get_master(s_con);
|
|
Packit Service |
a1bd4f |
if (master) {
|
|
Packit Service |
a1bd4f |
if (!g_strcmp0(master, uuid) || !g_strcmp0(master, iface))
|
|
Packit Service |
a1bd4f |
slaves = g_slist_prepend(slaves, g_object_ref(slave));
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
for (iter = slaves; iter; iter = iter->next)
|
|
Packit Service |
a1bd4f |
remove_one_connection(iter->data);
|
|
Packit Service |
a1bd4f |
g_slist_free_full(slaves, g_object_unref);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_object_unref(connection);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
NmtNewtForm *
|
|
Packit Service |
a1bd4f |
nmtui_edit(gboolean is_top, int argc, char **argv)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMConnection *conn = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (argc == 2) {
|
|
Packit Service |
a1bd4f |
if (nm_utils_is_uuid(argv[1]))
|
|
Packit Service |
a1bd4f |
conn = NM_CONNECTION(nm_client_get_connection_by_uuid(nm_client, argv[1]));
|
|
Packit Service |
a1bd4f |
if (!conn)
|
|
Packit Service |
a1bd4f |
conn = NM_CONNECTION(nm_client_get_connection_by_id(nm_client, argv[1]));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!conn) {
|
|
Packit Service |
a1bd4f |
nmt_newt_message_dialog("%s: no such connection '%s'\n", argv[0], argv[1]);
|
|
Packit Service |
a1bd4f |
return NULL;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return nmt_editor_new(conn);
|
|
Packit Service |
a1bd4f |
} else
|
|
Packit Service |
a1bd4f |
return nmt_edit_main_connection_list(is_top);
|
|
Packit |
5756e2 |
}
|