summaryrefslogtreecommitdiff
path: root/src/connection-editor/page-bridge-port.c
blob: e4afa61a2642f6c4e6bb515a5f1574ba49cae57a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager Connection editor -- Connection editor for NetworkManager
 *
 * Dan Williams <dcbw@redhat.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Copyright 2008 - 2014 Red Hat, Inc.
 */

#include "nm-default.h"

#include <string.h>

#include "page-bridge-port.h"

G_DEFINE_TYPE (CEPageBridgePort, ce_page_bridge_port, CE_TYPE_PAGE)

#define CE_PAGE_BRIDGE_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_BRIDGE_PORT, CEPageBridgePortPrivate))

typedef struct {
	NMSettingBridgePort *setting;

	GtkSpinButton *priority;
	GtkSpinButton *path_cost;
	GtkToggleButton *hairpin_mode;

} CEPageBridgePortPrivate;

static void
bridge_port_private_init (CEPageBridgePort *self)
{
	CEPageBridgePortPrivate *priv = CE_PAGE_BRIDGE_PORT_GET_PRIVATE (self);
	GtkBuilder *builder;

	builder = CE_PAGE (self)->builder;

	priv->priority = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "bridge_port_priority"));
	priv->path_cost = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "bridge_port_path_cost"));
	priv->hairpin_mode = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "bridge_port_hairpin_mode"));
}

static void
stuff_changed (GtkWidget *w, gpointer user_data)
{
	ce_page_changed (CE_PAGE (user_data));
}

static void
populate_ui (CEPageBridgePort *self)
{
	CEPageBridgePortPrivate *priv = CE_PAGE_BRIDGE_PORT_GET_PRIVATE (self);
	NMSettingBridgePort *s_port = priv->setting;

	gtk_spin_button_set_value (priv->priority, (gdouble) nm_setting_bridge_port_get_priority (s_port));
	gtk_spin_button_set_value (priv->path_cost, (gdouble) nm_setting_bridge_port_get_path_cost (s_port));
	gtk_toggle_button_set_active (priv->hairpin_mode, nm_setting_bridge_port_get_hairpin_mode (s_port));
}

static void
finish_setup (CEPageBridgePort *self, gpointer user_data)
{
	CEPageBridgePortPrivate *priv = CE_PAGE_BRIDGE_PORT_GET_PRIVATE (self);

	populate_ui (self);

	g_signal_connect (priv->priority, "value-changed", G_CALLBACK (stuff_changed), self);
	g_signal_connect (priv->path_cost, "value-changed", G_CALLBACK (stuff_changed), self);
	g_signal_connect (priv->hairpin_mode, "toggled", G_CALLBACK (stuff_changed), self);
}

CEPage *
ce_page_bridge_port_new (NMConnectionEditor *editor,
                         NMConnection *connection,
                         GtkWindow *parent_window,
                         NMClient *client,
                         const char **out_secrets_setting_name,
                         GError **error)
{
	CEPageBridgePort *self;
	CEPageBridgePortPrivate *priv;

	self = CE_PAGE_BRIDGE_PORT (ce_page_new (CE_TYPE_PAGE_BRIDGE_PORT,
	                                         editor,
	                                         connection,
	                                         parent_window,
	                                         client,
	                                         "/org/gnome/nm_connection_editor/ce-page-bridge-port.ui",
	                                         "BridgePortPage",
	                                         /* Translators: a "Bridge Port" is a network
	                                          * device that is part of a bridge.
	                                          */
	                                         _("Bridge Port")));
	if (!self) {
		g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load bridge port user interface."));
		return NULL;
	}

	bridge_port_private_init (self);
	priv = CE_PAGE_BRIDGE_PORT_GET_PRIVATE (self);

	priv->setting = nm_connection_get_setting_bridge_port (connection);
	if (!priv->setting) {
		priv->setting = NM_SETTING_BRIDGE_PORT (nm_setting_bridge_port_new ());
		nm_connection_add_setting (connection, NM_SETTING (priv->setting));
	}

	g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);

	return CE_PAGE (self);
}

static void
ui_to_setting (CEPageBridgePort *self)
{
	CEPageBridgePortPrivate *priv = CE_PAGE_BRIDGE_PORT_GET_PRIVATE (self);

	g_object_set (priv->setting,
	              NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, gtk_toggle_button_get_active (priv->hairpin_mode),
	              NM_SETTING_BRIDGE_PORT_PRIORITY, gtk_spin_button_get_value_as_int (priv->priority),
	              NM_SETTING_BRIDGE_PORT_PATH_COST, gtk_spin_button_get_value_as_int (priv->path_cost),
	              NULL);
}

static gboolean
ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
{
	CEPageBridgePort *self = CE_PAGE_BRIDGE_PORT (page);
	CEPageBridgePortPrivate *priv = CE_PAGE_BRIDGE_PORT_GET_PRIVATE (self);

	ui_to_setting (self);
	return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
}

static void
ce_page_bridge_port_init (CEPageBridgePort *self)
{
}

static void
ce_page_bridge_port_class_init (CEPageBridgePortClass *bridge_port_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (bridge_port_class);
	CEPageClass *parent_class = CE_PAGE_CLASS (bridge_port_class);

	g_type_class_add_private (object_class, sizeof (CEPageBridgePortPrivate));

	/* virtual methods */
	parent_class->ce_page_validate_v = ce_page_validate_v;
}