Commit e37f298d authored by Dan Williams's avatar Dan Williams Committed by Dan Williams
Browse files

Refactor connection editor page handling in preparation for making

2008-02-27  Dan Williams  <dcbw@redhat.com>

	Refactor connection editor page handling in preparation
	for making Add/Edit work.

	* src/connection-editor/Makefile.am
	  connection-editor/ce-page.c
	  connection-editor/ce-page.h
		- Add the base CEPage class from which all other connection editor pages
			derive

	* connection-editor/page-ip4-address.c
	  connection-editor/page-ip4-address.h
	  connection-editor/page-ip4.c
	  connection-editor/page-ip4.h
	  connection-editor/page-wired.c
	  connection-editor/page-wired.h
	  connection-editor/page-wireless-security.c
	  connection-editor/page-wireless-security.h
	  connection-editor/page-wireless.c
	  connection-editor/page-wireless.h
		- Make each page a subclass of CEPage

	* connection-editor/nm-connection-editor.c
	  connection-editor/nm-connection-editor.h
		- Update for these changes; handle CEPage objects instead of just
			GtkWidgets


svn path=/trunk/; revision=561
parent e25adf62
2008-02-27 Dan Williams <dcbw@redhat.com>
* src/connection-editor/Makefile.am
connection-editor/ce-page.c
connection-editor/ce-page.h
- Add the base CEPage class from which all other connection editor pages
derive
* connection-editor/page-ip4-address.c
connection-editor/page-ip4-address.h
connection-editor/page-ip4.c
connection-editor/page-ip4.h
connection-editor/page-wired.c
connection-editor/page-wired.h
connection-editor/page-wireless-security.c
connection-editor/page-wireless-security.h
connection-editor/page-wireless.c
connection-editor/page-wireless.h
- Make each page a subclass of CEPage
* connection-editor/nm-connection-editor.c
connection-editor/nm-connection-editor.h
- Update for these changes; handle CEPage objects instead of just
GtkWidgets
2008-02-25 Dan Williams <dcbw@redhat.com>
* src/connection-editor/page-wireless.c
......
......@@ -24,6 +24,8 @@ nm_connection_editor_SOURCES = \
nm-connection-list.c \
nm-connection-list.h \
main.c \
ce-page.h \
ce-page.c \
page-wired.h \
page-wired.c \
page-wireless.h \
......
/* -*- 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2008 Red Hat, Inc.
*/
#include "ce-page.h"
G_DEFINE_ABSTRACT_TYPE (CEPage, ce_page, G_TYPE_OBJECT)
gboolean
ce_page_validate (CEPage *self)
{
if (CE_PAGE_GET_CLASS (self)->validate)
return CE_PAGE_GET_CLASS (self)->validate (self);
return TRUE;
}
void
ce_page_update_connection (CEPage *self, NMConnection *connection)
{
CE_PAGE_GET_CLASS (self)->update_connection (self, connection);
}
static void
ce_page_init (CEPage *self)
{
self->disposed = FALSE;
}
static void
dispose (GObject *object)
{
CEPage *self = CE_PAGE (object);
if (self->disposed)
return;
self->disposed = TRUE;
if (self->page)
g_object_unref (self->page);
if (self->xml)
g_object_unref (self->xml);
G_OBJECT_CLASS (ce_page_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
CEPage *self = CE_PAGE (object);
if (self->title)
g_free (self->title);
G_OBJECT_CLASS (ce_page_parent_class)->finalize (object);
}
GtkWidget *
ce_page_get_page (CEPage *self)
{
g_return_val_if_fail (CE_IS_PAGE (self), NULL);
return self->page;
}
const char *
ce_page_get_title (CEPage *self)
{
g_return_val_if_fail (CE_IS_PAGE (self), NULL);
return self->title;
}
static void
ce_page_class_init (CEPageClass *page_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (page_class);
/* virtual methods */
object_class->dispose = dispose;
object_class->finalize = finalize;
}
/* -*- 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2008 Red Hat, Inc.
*/
#ifndef __CE_PAGE_H__
#define __CE_PAGE_H__
#include <glib/gtypes.h>
#include <glib-object.h>
#include <gtk/gtkwidget.h>
#include <glade/glade.h>
#include <nm-connection.h>
#define CE_TYPE_PAGE (ce_page_get_type ())
#define CE_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE, CEPage))
#define CE_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE, CEPageClass))
#define CE_IS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE))
#define CE_IS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), CE_TYPE_PAGE))
#define CE_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE, CEPageClass))
typedef struct {
GObject parent;
GladeXML *xml;
GtkWidget *page;
char *title;
gboolean disposed;
} CEPage;
typedef struct {
GObjectClass parent;
/* Virtual functions */
gboolean (*validate) (CEPage *self);
void (*update_connection) (CEPage *self, NMConnection *connection);
} CEPageClass;
GType ce_page_get_type (void);
GtkWidget * ce_page_get_page (CEPage *self);
const char * ce_page_get_title (CEPage *self);
gboolean ce_page_validate (CEPage *self);
void ce_page_update_connection (CEPage *self, NMConnection *connection);
#endif /* __CE_PAGE_H__ */
......@@ -44,6 +44,7 @@
#include "nm-connection-editor.h"
#include "utils.h"
#include "ce-page.h"
#include "page-wired.h"
#include "page-wireless.h"
#include "page-wireless-security.h"
......@@ -90,19 +91,6 @@ ce_get_property_default (NMSetting *setting, const char *property_name)
return 0;
}
static void
add_page (NMConnectionEditor *editor,
GtkWidget *page,
const char *title)
{
GtkWidget *notebook;
GtkWidget *label;
notebook = glade_xml_get_widget (editor->xml, "notebook");
label = gtk_label_new (title);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
}
static void
nm_connection_editor_update_title (NMConnectionEditor *editor)
{
......@@ -170,20 +158,26 @@ nm_connection_editor_init (NMConnectionEditor *editor)
widget = glade_xml_get_widget (editor->xml, "connection_name");
g_signal_connect (G_OBJECT (widget), "changed",
G_CALLBACK (connection_name_changed), editor);
editor->pages = NULL;
}
static void
nm_connection_editor_finalize (GObject *object)
dispose (GObject *object)
{
NMConnectionEditor *editor = NM_CONNECTION_EDITOR (object);
g_slist_foreach (editor->pages, (GFunc) g_object_unref, NULL);
g_slist_free (editor->pages);
editor->pages = NULL;
if (editor->connection)
g_object_unref (editor->connection);
gtk_widget_destroy (editor->dialog);
g_object_unref (editor->xml);
G_OBJECT_CLASS (nm_connection_editor_parent_class)->finalize (object);
G_OBJECT_CLASS (nm_connection_editor_parent_class)->dispose (object);
}
static void
......@@ -192,7 +186,7 @@ nm_connection_editor_class_init (NMConnectionEditorClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
/* virtual methods */
object_class->finalize = nm_connection_editor_finalize;
object_class->dispose = dispose;
}
NMConnectionEditor *
......@@ -256,13 +250,25 @@ fill_connection_values (NMConnectionEditor *editor)
}
}
static void
add_page (NMConnectionEditor *editor, CEPage *page)
{
GtkWidget *widget;
GtkWidget *notebook;
GtkWidget *label;
notebook = glade_xml_get_widget (editor->xml, "notebook");
label = gtk_label_new (ce_page_get_title (page));
widget = ce_page_get_page (page);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label);
editor->pages = g_slist_append (editor->pages, page);
}
void
nm_connection_editor_set_connection (NMConnectionEditor *editor, NMConnection *connection)
{
NMSettingConnection *s_con;
GtkWidget *widget;
char *title = NULL;
GtkWidget *ok_button;
g_return_if_fail (NM_IS_CONNECTION_EDITOR (editor));
g_return_if_fail (connection != NULL);
......@@ -276,49 +282,30 @@ nm_connection_editor_set_connection (NMConnectionEditor *editor, NMConnection *c
editor->connection = (NMConnection *) g_object_ref (connection);
nm_connection_editor_update_title (editor);
ok_button = glade_xml_get_widget (editor->xml, "ok_button");
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
g_assert (s_con);
if (!strcmp (s_con->type, NM_SETTING_WIRED_SETTING_NAME)) {
widget = page_wired_new (editor->connection, (const char **) &title);
if (widget)
add_page (editor, widget, title);
widget = page_ip4_address_new (editor->connection, (const char **) &title);
if (widget)
add_page (editor, widget, title);
widget = page_ip4_new (editor->connection, (const char **) &title);
if (widget)
add_page (editor, widget, title);
add_page (editor, CE_PAGE (ce_page_wired_new (editor->connection)));
add_page (editor, CE_PAGE (ce_page_ip4_address_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)) {
GtkWidget *wireless_page;
wireless_page = page_wireless_new (editor->connection, (const char **) &title);
if (wireless_page)
add_page (editor, wireless_page, title);
CEPageWireless *wireless_page;
CEPageWirelessSecurity *wireless_security_page;
GtkWidget *ok_button;
widget = page_wireless_security_new (editor->connection, ok_button, wireless_page, (const char **) &title);
if (widget)
add_page (editor, widget, title);
wireless_page = ce_page_wireless_new (editor->connection);
add_page (editor, CE_PAGE (wireless_page));
widget = page_ip4_address_new (editor->connection, (const char **) &title);
if (widget)
add_page (editor, widget, title);
ok_button = glade_xml_get_widget (editor->xml, "ok_button");
wireless_security_page = ce_page_wireless_security_new (editor->connection, ok_button, wireless_page);
add_page (editor, CE_PAGE (wireless_security_page));
widget = page_ip4_new (editor->connection, (const char **) &title);
if (widget)
add_page (editor, widget, title);
add_page (editor, CE_PAGE (ce_page_ip4_address_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)) {
widget = page_ip4_address_new (editor->connection, (const char **) &title);
if (widget)
add_page (editor, widget, title);
widget = page_ip4_new (editor->connection, (const char **) &title);
if (widget)
add_page (editor, widget, title);
add_page (editor, CE_PAGE (ce_page_ip4_address_new (editor->connection)));
add_page (editor, CE_PAGE (ce_page_ip4_new (editor->connection)));
} else {
g_warning ("Unhandled setting type '%s'", s_con->type);
}
......
......@@ -38,7 +38,7 @@ typedef struct {
/* private data */
NMConnection *connection;
GHashTable *pages;
GSList *pages;
GtkWidget *dialog;
GladeXML *xml;
} NMConnectionEditor;
......
......@@ -30,29 +30,53 @@
#include "page-ip4-address.h"
GtkWidget *
page_ip4_address_new (NMConnection *connection, const char **title)
G_DEFINE_TYPE (CEPageIP4Address, ce_page_ip4_address, CE_TYPE_PAGE)
CEPageIP4Address *
ce_page_ip4_address_new (NMConnection *connection)
{
GladeXML *xml;
GtkWidget *page;
CEPageIP4Address *self;
CEPage *parent;
NMSettingIP4Config *s_ip4;
xml = glade_xml_new (GLADEDIR "/ce-page-ip4-address.glade", "IP4AddressPage", NULL);
g_return_val_if_fail (xml != NULL, NULL);
*title = _("IPv4 Addresses");
self = CE_PAGE_IP4_ADDRESS (g_object_new (CE_TYPE_PAGE_IP4_ADDRESS, NULL));
parent = CE_PAGE (self);
parent->xml = glade_xml_new (GLADEDIR "/ce-page-ip4-address.glade", "IP4AddressPage", NULL);
if (!parent->xml) {
g_warning ("%s: Couldn't load wired page glade file.", __func__);
g_object_unref (self);
return NULL;
}
parent->page = glade_xml_get_widget (parent->xml, "IP4AddressPage");
if (!parent->page) {
g_warning ("%s: Couldn't load wired page from glade file.", __func__);
g_object_unref (self);
return NULL;
}
g_object_ref_sink (parent->page);
page = glade_xml_get_widget (xml, "IP4AddressPage");
g_return_val_if_fail (page != NULL, NULL);
g_object_set_data_full (G_OBJECT (page),
"glade-xml", xml,
(GDestroyNotify) g_object_unref);
parent->title = g_strdup (_("IPv4 Addresses"));
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG));
if (s_ip4 == NULL)
goto out;
// FIXME: fill in the UI
out:
return page;
return self;
}
static void
ce_page_ip4_address_init (CEPageIP4Address *self)
{
}
static void
ce_page_ip4_address_class_init (CEPageIP4AddressClass *ip4_address_class)
{
}
......@@ -23,10 +23,31 @@
#ifndef __PAGE_IP4_ADDRESS_H__
#define __PAGE_IP4_ADDRESS_H__
#include "nm-connection-editor.h"
#include <nm-connection.h>
GtkWidget *page_ip4_address_new (NMConnection *connection, const char **title);
#include <glib/gtypes.h>
#include <glib-object.h>
#include "ce-page.h"
#define CE_TYPE_PAGE_IP4_ADDRESS (ce_page_ip4_address_get_type ())
#define CE_PAGE_IP4_ADDRESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE_IP4_ADDRESS, CEPageIP4Address))
#define CE_PAGE_IP4_ADDRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE_IP4_ADDRESS, CEPageIP4AddressClass))
#define CE_IS_PAGE_IP4_ADDRESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE_IP4_ADDRESS))
#define CE_IS_PAGE_IP4_ADDRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), CE_TYPE_PAGE_IP4_ADDRESS))
#define CE_PAGE_IP4_ADDRESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE_IP4_ADDRESS, CEPageIP4AddressClass))
typedef struct {
CEPage parent;
} CEPageIP4Address;
typedef struct {
CEPageClass parent;
} CEPageIP4AddressClass;
GType ce_page_ip4_address_get_type (void);
CEPageIP4Address *ce_page_ip4_address_new (NMConnection *connection);
#endif /* __PAGE_IP4_ADDRESS_H__ */
......@@ -30,29 +30,53 @@
#include "page-ip4.h"
GtkWidget *
page_ip4_new (NMConnection *connection, const char **title)
G_DEFINE_TYPE (CEPageIP4, ce_page_ip4, CE_TYPE_PAGE)
CEPageIP4 *
ce_page_ip4_new (NMConnection *connection)
{
GladeXML *xml;
GtkWidget *page;
CEPageIP4 *self;
CEPage *parent;
NMSettingIP4Config *s_ip4;
xml = glade_xml_new (GLADEDIR "/ce-page-ip4.glade", "IP4Page", NULL);
g_return_val_if_fail (xml != NULL, NULL);
*title = _("IPv4 Settings");
self = CE_PAGE_IP4 (g_object_new (CE_TYPE_PAGE_IP4, NULL));
parent = CE_PAGE (self);
parent->xml = glade_xml_new (GLADEDIR "/ce-page-ip4.glade", "IP4Page", NULL);
if (!parent->xml) {
g_warning ("%s: Couldn't load wired page glade file.", __func__);
g_object_unref (self);
return NULL;
}
parent->page = glade_xml_get_widget (parent->xml, "IP4Page");
if (!parent->page) {
g_warning ("%s: Couldn't load wired page from glade file.", __func__);
g_object_unref (self);
return NULL;
}
g_object_ref_sink (parent->page);
page = glade_xml_get_widget (xml, "IP4Page");
g_return_val_if_fail (page != NULL, NULL);
g_object_set_data_full (G_OBJECT (page),
"glade-xml", xml,
(GDestroyNotify) g_object_unref);
parent->title = g_strdup (_("IPv4 Settings"));
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG));
if (s_ip4 == NULL)
goto out;
// FIXME: fill in UI from setting
out:
return page;
return self;
}
static void
ce_page_ip4_init (CEPageIP4 *self)
{
}
static void
ce_page_ip4_class_init (CEPageIP4Class *ip4_class)
{
}
......@@ -23,10 +23,31 @@
#ifndef __PAGE_IP4_H__
#define __PAGE_IP4_H__
#include "nm-connection-editor.h"
#include <nm-connection.h>
GtkWidget *page_ip4_new (NMConnection *connection, const char **title);
#include <glib/gtypes.h>
#include <glib-object.h>
#include "ce-page.h"
#define CE_TYPE_PAGE_IP4 (ce_page_ip4_get_type ())
#define CE_PAGE_IP4(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE_IP4, CEPageIP4))
#define CE_PAGE_IP4_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE_IP4, CEPageIP4Class))
#define CE_IS_PAGE_IP4(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE_IP4))
#define CE_IS_PAGE_IP4_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), CE_TYPE_PAGE_IP4))
#define CE_PAGE_IP4_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE_IP4, CEPageIP4Class))
typedef struct {
CEPage parent;
} CEPageIP4;
typedef struct {
CEPageClass parent;
} CEPageIP4Class;
GType ce_page_ip4_get_type (void);
CEPageIP4 *ce_page_ip4_new (NMConnection *connection);
#endif /* __PAGE_IP4_H__ */
......@@ -29,12 +29,15 @@
#include <nm-setting-wired.h>
#include "page-wired.h"
#include "nm-connection-editor.h"
GtkWidget *
page_wired_new (NMConnection *connection, const char **title)
G_DEFINE_TYPE (CEPageWired, ce_page_wired, CE_TYPE_PAGE)
CEPageWired *
ce_page_wired_new (NMConnection *connection)
{
GladeXML *xml;
GtkWidget *page;
CEPageWired *self;
CEPage *parent;
NMSettingWired *s_wired;
GtkWidget *port;
int port_idx = 0;
......@@ -45,25 +48,39 @@ page_wired_new (NMConnection *connection, const char **title)
GtkWidget *mtu;
int mtu_def;
self = CE_PAGE_WIRED (g_object_new