Commit 291f1f12 authored by Tambet Ingo's avatar Tambet Ingo Committed by Tambet Ingo
Browse files

src/connection-editor/ce-page.c src/connection-editor/ce-page.h

2008-06-20  Tambet Ingo  <tambet@gmail.com>

	* src/connection-editor/ce-page.c
	src/connection-editor/ce-page.h
	src/connection-editor/nm-connection-editor.c
	src/connection-editor/nm-connection-editor.h
	src/connection-editor/nm-connection-list.c
	src/connection-editor/page-dsl.c
	src/connection-editor/page-ip4.c
	src/connection-editor/page-mobile.c
	src/connection-editor/page-ppp.c
	src/connection-editor/page-vpn.c
	src/connection-editor/page-wired-security.c
	src/connection-editor/page-wired.c
	src/connection-editor/page-wireless-security.c
	src/connection-editor/page-wireless-security.h
	src/connection-editor/page-wireless.c

	Use a copy of the real connection in the connection editor. Fixes issues
	where the connection is updated but writing it fails for some reason.
	Keep the connection that's been edited updated after every UI change so
	that pages can act on changes to other pages.

svn path=/trunk/; revision=760
parent e1a21dbb
2008-06-20 Tambet Ingo <tambet@gmail.com>
* src/connection-editor/ce-page.c
src/connection-editor/ce-page.h
src/connection-editor/nm-connection-editor.c
src/connection-editor/nm-connection-editor.h
src/connection-editor/nm-connection-list.c
src/connection-editor/page-dsl.c
src/connection-editor/page-ip4.c
src/connection-editor/page-mobile.c
src/connection-editor/page-ppp.c
src/connection-editor/page-vpn.c
src/connection-editor/page-wired-security.c
src/connection-editor/page-wired.c
src/connection-editor/page-wireless-security.c
src/connection-editor/page-wireless-security.h
src/connection-editor/page-wireless.c
Use a copy of the real connection in the connection editor. Fixes issues
where the connection is updated but writing it fails for some reason.
Keep the connection that's been edited updated after every UI change so
that pages can act on changes to other pages.
2008-06-17 Dan Williams <dcbw@redhat.com>
* src/vpn-properties/*
......
......@@ -39,20 +39,17 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
gboolean
ce_page_validate (CEPage *self, GError **error)
ce_page_validate (CEPage *self, NMConnection *connection, GError **error)
{
g_return_val_if_fail (CE_IS_PAGE (self), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
if (CE_PAGE_GET_CLASS (self)->validate)
return CE_PAGE_GET_CLASS (self)->validate (self, error);
return CE_PAGE_GET_CLASS (self)->validate (self, connection, error);
return TRUE;
}
void
ce_page_update_connection (CEPage *self, NMConnection *connection)
{
CE_PAGE_GET_CLASS (self)->update_connection (self, connection);
}
void
ce_page_mac_to_entry (GByteArray *mac, GtkEntry *entry)
{
......
......@@ -53,8 +53,7 @@ typedef struct {
GObjectClass parent;
/* Virtual functions */
gboolean (*validate) (CEPage *self, GError **error);
void (*update_connection) (CEPage *self, NMConnection *connection);
gboolean (*validate) (CEPage *self, NMConnection *connection, GError **error);
/* Signals */
void (*changed) (CEPage *self);
......@@ -66,9 +65,7 @@ GtkWidget * ce_page_get_page (CEPage *self);
const char * ce_page_get_title (CEPage *self);
gboolean ce_page_validate (CEPage *self, GError **error);
void ce_page_update_connection (CEPage *self, NMConnection *connection);
gboolean ce_page_validate (CEPage *self, NMConnection *connection, GError **error);
void ce_page_changed (CEPage *self);
......
......@@ -71,7 +71,7 @@ enum {
static guint editor_signals[EDITOR_LAST_SIGNAL] = { 0 };
static void nm_connection_editor_set_connection (NMConnectionEditor *editor,
NMExportedConnection *exported);
NMConnection *connection);
static void
dialog_response_cb (GtkDialog *dialog, guint response, gpointer user_data)
......@@ -147,7 +147,7 @@ connection_editor_validate (NMConnectionEditor *editor)
for (iter = editor->pages; iter; iter = g_slist_next (iter)) {
GError *error = NULL;
if (!ce_page_validate (CE_PAGE (iter->data), &error)) {
if (!ce_page_validate (CE_PAGE (iter->data), editor->connection, &error)) {
/* FIXME: use the error to indicate which UI widgets are invalid */
if (error)
g_error_free (error);
......@@ -233,8 +233,8 @@ dispose (GObject *object)
g_slist_free (editor->pages);
editor->pages = NULL;
if (editor->exported)
g_object_unref (editor->exported);
if (editor->connection)
g_object_unref (editor->connection);
gtk_widget_destroy (editor->dialog);
g_object_unref (editor->xml);
......@@ -262,24 +262,24 @@ nm_connection_editor_class_init (NMConnectionEditorClass *klass)
}
NMConnectionEditor *
nm_connection_editor_new (NMExportedConnection *exported)
nm_connection_editor_new (NMConnection *connection)
{
NMConnectionEditor *editor;
g_return_val_if_fail (NM_IS_EXPORTED_CONNECTION (exported), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
editor = g_object_new (NM_TYPE_CONNECTION_EDITOR, NULL);
nm_connection_editor_set_connection (editor, exported);
nm_connection_editor_set_connection (editor, connection);
return editor;
}
NMExportedConnection *
NMConnection *
nm_connection_editor_get_connection (NMConnectionEditor *editor)
{
g_return_val_if_fail (NM_IS_CONNECTION_EDITOR (editor), NULL);
return editor->exported;
return editor->connection;
}
gint
......@@ -356,20 +356,18 @@ add_page (NMConnectionEditor *editor, CEPage *page)
}
static void
nm_connection_editor_set_connection (NMConnectionEditor *editor, NMExportedConnection *exported)
nm_connection_editor_set_connection (NMConnectionEditor *editor, NMConnection *connection)
{
NMSettingConnection *s_con;
g_return_if_fail (NM_IS_CONNECTION_EDITOR (editor));
g_return_if_fail (NM_IS_EXPORTED_CONNECTION (exported));
g_return_if_fail (NM_IS_CONNECTION (connection));
/* clean previous connection */
if (editor->exported)
g_object_unref (editor->exported);
editor->exported = g_object_ref (exported);
editor->connection = nm_exported_connection_get_connection (exported);
if (editor->connection)
g_object_unref (editor->connection);
editor->connection = g_object_ref (connection);
nm_connection_editor_update_title (editor);
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (editor->connection, NM_TYPE_SETTING_CONNECTION));
......@@ -380,15 +378,8 @@ nm_connection_editor_set_connection (NMConnectionEditor *editor, NMExportedConne
add_page (editor, CE_PAGE (ce_page_wired_security_new (editor->connection)));
add_page (editor, CE_PAGE (ce_page_ip4_new (editor->connection)));
} else if (!strcmp (s_con->type, NM_SETTING_WIRELESS_SETTING_NAME)) {
CEPageWireless *wireless_page;
CEPageWirelessSecurity *wireless_security_page;
wireless_page = ce_page_wireless_new (editor->connection);
add_page (editor, CE_PAGE (wireless_page));
wireless_security_page = ce_page_wireless_security_new (editor->connection, wireless_page);
add_page (editor, CE_PAGE (wireless_security_page));
add_page (editor, CE_PAGE (ce_page_wireless_new (editor->connection)));
add_page (editor, CE_PAGE (ce_page_wireless_security_new (editor->connection)));
add_page (editor, CE_PAGE (ce_page_ip4_new (editor->connection)));
} else if (!strcmp (s_con->type, NM_SETTING_VPN_SETTING_NAME)) {
add_page (editor, CE_PAGE (ce_page_vpn_new (editor->connection)));
......@@ -417,12 +408,6 @@ nm_connection_editor_present (NMConnectionEditor *editor)
gtk_window_present (GTK_WINDOW (editor->dialog));
}
static void
update_one_page (gpointer data, gpointer user_data)
{
ce_page_update_connection (CE_PAGE (data), NM_CONNECTION (user_data));
}
static void
connection_editor_update_connection (NMConnectionEditor *editor)
{
......@@ -448,8 +433,6 @@ connection_editor_update_connection (NMConnectionEditor *editor)
nm_connection_set_scope (editor->connection, NM_CONNECTION_SCOPE_SYSTEM);
else
nm_connection_set_scope (editor->connection, NM_CONNECTION_SCOPE_USER);
g_slist_foreach (editor->pages, update_one_page, editor->connection);
}
static void
......
......@@ -25,9 +25,7 @@
#include <glib-object.h>
#include <glade/glade-xml.h>
#include <gtk/gtksizegroup.h>
#include <gtk/gtkspinbutton.h>
#include <gconf/gconf-client.h>
#include <nm-settings.h>
#define NM_TYPE_CONNECTION_EDITOR (nm_connection_editor_get_type ())
......@@ -38,7 +36,6 @@ typedef struct {
GObject parent;
/* private data */
NMExportedConnection *exported;
NMConnection *connection;
GSList *pages;
......@@ -55,11 +52,11 @@ typedef struct {
} NMConnectionEditorClass;
GType nm_connection_editor_get_type (void);
NMConnectionEditor *nm_connection_editor_new (NMExportedConnection *exported);
NMConnectionEditor *nm_connection_editor_new (NMConnection *connection);
void nm_connection_editor_present (NMConnectionEditor *editor);
void nm_connection_editor_run (NMConnectionEditor *editor);
NMExportedConnection *nm_connection_editor_get_connection (NMConnectionEditor *editor);
NMConnection *nm_connection_editor_get_connection (NMConnectionEditor *editor);
gint ce_spin_output_with_default (GtkSpinButton *spin, gpointer user_data);
......
This diff is collapsed.
......@@ -39,7 +39,6 @@ G_DEFINE_TYPE (CEPageDsl, ce_page_dsl, CE_TYPE_PAGE)
typedef struct {
NMSettingPPPOE *setting;
NMConnection *connection; /* ugh */
GtkEntry *username;
GtkEntry *password;
......@@ -80,7 +79,7 @@ populate_ui (CEPageDsl *self, NMConnection *connection)
GValue *value;
secrets = nm_gconf_get_keyring_items (connection, connection_id,
nm_setting_get_name (NM_SETTING (priv->setting)),
nm_setting_get_name (NM_SETTING (setting)),
FALSE,
&error);
if (secrets) {
......@@ -121,7 +120,6 @@ ce_page_dsl_new (NMConnection *connection)
CEPageDsl *self;
CEPageDslPrivate *priv;
CEPage *parent;
NMSettingPPPOE *s_pppoe;
self = CE_PAGE_DSL (g_object_new (CE_TYPE_PAGE_DSL, NULL));
parent = CE_PAGE (self);
......@@ -146,13 +144,11 @@ ce_page_dsl_new (NMConnection *connection)
dsl_private_init (self);
priv = CE_PAGE_DSL_GET_PRIVATE (self);
s_pppoe = (NMSettingPPPOE *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPPOE);
if (s_pppoe)
priv->setting = NM_SETTING_PPPOE (nm_setting_duplicate (NM_SETTING (s_pppoe)));
else
priv->setting = (NMSettingPPPOE *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPPOE);
if (!priv->setting) {
priv->setting = NM_SETTING_PPPOE (nm_setting_pppoe_new ());
priv->connection = connection;
nm_connection_add_setting (connection, NM_SETTING (priv->setting));
}
populate_ui (self, connection);
......@@ -194,7 +190,7 @@ ui_to_setting (CEPageDsl *self)
}
static gboolean
validate (CEPage *page, GError **error)
validate (CEPage *page, NMConnection *connection, GError **error)
{
CEPageDsl *self = CE_PAGE_DSL (page);
CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (self);
......@@ -203,43 +199,18 @@ validate (CEPage *page, GError **error)
ui_to_setting (self);
foo = g_slist_append (NULL, nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_PPP));
foo = g_slist_append (NULL, nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP));
valid = nm_setting_verify (NM_SETTING (priv->setting), foo, error);
g_slist_free (foo);
return valid;
}
static void
update_connection (CEPage *page, NMConnection *connection)
{
CEPageDsl *self = CE_PAGE_DSL (page);
CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (self);
ui_to_setting (self);
g_object_ref (priv->setting); /* Add setting steals the reference. */
nm_connection_add_setting (connection, NM_SETTING (priv->setting));
}
static void
ce_page_dsl_init (CEPageDsl *self)
{
}
static void
dispose (GObject *object)
{
CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (object);
if (priv->disposed)
return;
priv->disposed = TRUE;
g_object_unref (priv->setting);
G_OBJECT_CLASS (ce_page_dsl_parent_class)->dispose (object);
}
static void
ce_page_dsl_class_init (CEPageDslClass *dsl_class)
{
......@@ -249,8 +220,5 @@ ce_page_dsl_class_init (CEPageDslClass *dsl_class)
g_type_class_add_private (object_class, sizeof (CEPageDslPrivate));
/* virtual methods */
object_class->dispose = dispose;
parent_class->validate = validate;
parent_class->update_connection = update_connection;
}
......@@ -428,7 +428,6 @@ ce_page_ip4_new (NMConnection *connection)
CEPageIP4 *self;
CEPageIP4Private *priv;
CEPage *parent;
NMSettingIP4Config *s_ip4;
GtkTreeSelection *selection;
gint offset;
GtkTreeViewColumn *column;
......@@ -458,11 +457,11 @@ ce_page_ip4_new (NMConnection *connection)
ip4_private_init (self);
priv = CE_PAGE_IP4_GET_PRIVATE (self);
s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
if (s_ip4)
priv->setting = NM_SETTING_IP4_CONFIG (nm_setting_duplicate (NM_SETTING (s_ip4)));
else
priv->setting = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
if (!priv->setting) {
priv->setting = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
nm_connection_add_setting (connection, NM_SETTING (priv->setting));
}
populate_ui (self);
......@@ -675,7 +674,7 @@ next:
}
static gboolean
validate (CEPage *page, GError **error)
validate (CEPage *page, NMConnection *connection, GError **error)
{
CEPageIP4 *self = CE_PAGE_IP4 (page);
CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
......@@ -684,36 +683,11 @@ validate (CEPage *page, GError **error)
return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
}
static void
update_connection (CEPage *page, NMConnection *connection)
{
CEPageIP4 *self = CE_PAGE_IP4 (page);
CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (page);
ui_to_setting (self);
g_object_ref (priv->setting); /* Add setting steals the reference. */
nm_connection_add_setting (connection, NM_SETTING (priv->setting));
}
static void
ce_page_ip4_init (CEPageIP4 *self)
{
}
static void
dispose (GObject *object)
{
CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (object);
if (priv->disposed)
return;
priv->disposed = TRUE;
g_object_unref (priv->setting);
G_OBJECT_CLASS (ce_page_ip4_parent_class)->dispose (object);
}
static void
ce_page_ip4_class_init (CEPageIP4Class *ip4_class)
{
......@@ -723,8 +697,5 @@ ce_page_ip4_class_init (CEPageIP4Class *ip4_class)
g_type_class_add_private (object_class, sizeof (CEPageIP4Private));
/* virtual methods */
object_class->dispose = dispose;
parent_class->validate = validate;
parent_class->update_connection = update_connection;
}
......@@ -247,7 +247,6 @@ ce_page_mobile_new (NMConnection *connection)
CEPageMobile *self;
CEPageMobilePrivate *priv;
CEPage *parent;
NMSetting *setting;
self = CE_PAGE_MOBILE (g_object_new (CE_TYPE_PAGE_MOBILE, NULL));
parent = CE_PAGE (self);
......@@ -272,18 +271,17 @@ ce_page_mobile_new (NMConnection *connection)
mobile_private_init (self);
priv = CE_PAGE_MOBILE_GET_PRIVATE (self);
setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_GSM);
if (!setting)
setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_CDMA);
priv->setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_GSM);
if (!priv->setting)
priv->setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_CDMA);
if (!setting) {
if (!priv->setting) {
/* FIXME: Support add. */
g_warning ("Adding mobile conneciton not supported yet.");
g_object_unref (self);
return NULL;
}
priv->setting = nm_setting_duplicate (setting);
populate_ui (self, connection);
g_signal_connect (priv->number, "changed", G_CALLBACK (stuff_changed), self);
......@@ -376,7 +374,7 @@ ui_to_setting (CEPageMobile *self)
}
static gboolean
validate (CEPage *page, GError **error)
validate (CEPage *page, NMConnection *connection, GError **error)
{
CEPageMobile *self = CE_PAGE_MOBILE (page);
CEPageMobilePrivate *priv = CE_PAGE_MOBILE_GET_PRIVATE (self);
......@@ -385,36 +383,11 @@ validate (CEPage *page, GError **error)
return nm_setting_verify (priv->setting, NULL, error);
}
static void
update_connection (CEPage *page, NMConnection *connection)
{
CEPageMobile *self = CE_PAGE_MOBILE (page);
CEPageMobilePrivate *priv = CE_PAGE_MOBILE_GET_PRIVATE (self);
ui_to_setting (self);
g_object_ref (priv->setting); /* Add setting steals the reference. */
nm_connection_add_setting (connection, priv->setting);
}
static void
ce_page_mobile_init (CEPageMobile *self)
{
}
static void
dispose (GObject *object)
{
CEPageMobilePrivate *priv = CE_PAGE_MOBILE_GET_PRIVATE (object);
if (priv->disposed)
return;
priv->disposed = TRUE;
g_object_unref (priv->setting);
G_OBJECT_CLASS (ce_page_mobile_parent_class)->dispose (object);
}
static void
ce_page_mobile_class_init (CEPageMobileClass *mobile_class)
{
......@@ -424,8 +397,5 @@ ce_page_mobile_class_init (CEPageMobileClass *mobile_class)
g_type_class_add_private (object_class, sizeof (CEPageMobilePrivate));
/* virtual methods */
object_class->dispose = dispose;
parent_class->validate = validate;
parent_class->update_connection = update_connection;
}
......@@ -174,7 +174,6 @@ ce_page_ppp_new (NMConnection *connection)
CEPagePpp *self;
CEPagePppPrivate *priv;
CEPage *parent;
NMSettingPPP *s_ppp;
GtkCellRenderer *renderer;
gint offset;
GtkTreeViewColumn *column;
......@@ -202,11 +201,11 @@ ce_page_ppp_new (NMConnection *connection)
ppp_private_init (self);
priv = CE_PAGE_PPP_GET_PRIVATE (self);
s_ppp = (NMSettingPPP *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP);
if (s_ppp)
priv->setting = NM_SETTING_PPP (nm_setting_duplicate (NM_SETTING (s_ppp)));
else
priv->setting = (NMSettingPPP *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP);
if (!priv->setting) {
priv->setting = NM_SETTING_PPP (nm_setting_ppp_new ());
nm_connection_add_setting (connection, NM_SETTING (priv->setting));
}
populate_ui (self, connection);
......@@ -326,7 +325,7 @@ ui_to_setting (CEPagePpp *self)
}
static gboolean
validate (CEPage *page, GError **error)
validate (CEPage *page, NMConnection *connection, GError **error)
{
CEPagePpp *self = CE_PAGE_PPP (page);
CEPagePppPrivate *priv = CE_PAGE_PPP_GET_PRIVATE (self);
......@@ -335,36 +334,11 @@ validate (CEPage *page, GError **error)
return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
}
static void
update_connection (CEPage *page, NMConnection *connection)
{
CEPagePpp *self = CE_PAGE_PPP (page);
CEPagePppPrivate *priv = CE_PAGE_PPP_GET_PRIVATE (self);
ui_to_setting (self);
g_object_ref (priv->setting); /* Add setting steals the reference. */
nm_connection_add_setting (connection, NM_SETTING (priv->setting));
}
static void
ce_page_ppp_init (CEPagePpp *self)
{
}
static void
dispose (GObject *object)
{
CEPagePppPrivate *priv = CE_PAGE_PPP_GET_PRIVATE (object);
if (priv->disposed)
return;
priv->disposed = TRUE;
g_object_unref (priv->setting);
G_OBJECT_CLASS (ce_page_ppp_parent_class)->dispose (object);
}
static void
ce_page_ppp_class_init (CEPagePppClass *ppp_class)
{
......@@ -374,8 +348,5 @@ ce_page_ppp_class_init (CEPagePppClass *ppp_class)
g_type_class_add_private (object_class, sizeof (CEPagePppPrivate));
/* virtual methods */
object_class->dispose = dispose;
parent_class->validate = validate;
parent_class->update_connection = update_connection;
}
......@@ -42,7 +42,6 @@ G_DEFINE_TYPE (CEPageVpn, ce_page_vpn, CE_TYPE_PAGE)
typedef struct {
NMSettingVPN *setting;
NMConnection *connection; /* ugh */
NMVpnPluginUiWidgetInterface *ui;
gboolean valid;
......@@ -67,7 +66,6 @@ ce_page_vpn_new (NMConnection *connection)
CEPageVpn *self;
CEPageVpnPrivate *priv;
CEPage *parent;
NMSettingVPN *s_vpn;
GError *error = NULL;
NMVpnPluginUiInterface *plugin;
......@@ -77,17 +75,14 @@ ce_page_vpn_new (NMConnection *connection)
parent->title = g_strdup (_("VPN"));
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
g_assert (s_vpn);
g_assert (s_vpn->service_type);
priv->setting = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
g_assert (priv->setting);
g_assert (priv->setting->service_type);
priv->setting = NM_SETTING_VPN (nm_setting_duplicate (NM_SETTING (s_vpn)));
priv->connection = connection;
plugin = vpn_get_plugin_by_service (s_vpn->service_type);
plugin = vpn_get_plugin_by_service (priv->setting->service_type);
if (!plugin) {
g_warning ("%s: couldn't find VPN plugin for service '%s'!",
__func__, s_vpn->service_type);
__func__, priv->setting->service_type);
g_object_unref (self);
return NULL;