Commit 0f4fedc5 authored by Dan Williams's avatar Dan Williams
Browse files

core: fix GtkBuilder-related performance issues

GtkBuilder isn't as quick as libglade when building the widget
tree from the XML file, so the previous handling of wireless
security and EAP methods caused connection editor display times
of 4 seconds or more on slower machines (like 1.7GHz Pentium M).

Previously, all security and EAP UI was stored in one glade/builder
file which was re-read from multiple places.  With glade that was
fine, but GtkBuilder's gtk_builder_add_from_file() takes quite a
bit longer than glade did.

So split each piece security and EAP UI description out into a
separate file, and consolidated handling of UI building into the
EAPMethod and WirelessSecurity classes instead of doing it in
the subclasses.
parent 4148adcb
......@@ -51,8 +51,19 @@ src/vpn-password-dialog.h
src/wired-dialog.c
src/wireless-dialog.c
src/wireless-security/eap-method.c
[type: gettext/glade]src/wireless-security/eap-method-leap.ui
src/wireless-security/eap-method-peap.c
[type: gettext/glade]src/wireless-security/eap-method-peap.ui
[type: gettext/glade]src/wireless-security/eap-method-simple.ui
src/wireless-security/eap-method-tls.c
[type: gettext/glade]src/wireless-security/eap-method-tls.ui
src/wireless-security/eap-method-ttls.c
[type: gettext/glade]src/wireless-security/eap-method-ttls.ui
[type: gettext/glade]src/wireless-security/nag-user-dialog.ui
src/wireless-security/wireless-security.c
[type: gettext/glade]src/wireless-security/ws-dynamic-wep.ui
[type: gettext/glade]src/wireless-security/ws-leap.ui
[type: gettext/glade]src/wireless-security/ws-wep-key.ui
[type: gettext/glade]src/wireless-security/ws-wpa-eap.ui
[type: gettext/glade]src/wireless-security/ws-wpa-psk.ui
......@@ -3011,7 +3011,7 @@ constructor (GType type,
g_set_application_name (_("NetworkManager Applet"));
gtk_window_set_default_icon_name (GTK_STOCK_NETWORK);
applet->ui_file = g_build_filename (UIDIR, "applet.ui", NULL);
applet->ui_file = g_build_filename (UIDIR, "/applet.ui", NULL);
if (!applet->ui_file || !g_file_test (applet->ui_file, G_FILE_TEST_IS_REGULAR)) {
GtkWidget *dialog;
dialog = applet_warning_dialog_show (_("The NetworkManager Applet could not find some required resources (the .ui file was not found)."));
......
This diff is collapsed.
......@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 - 2009 Red Hat, Inc.
* (C) Copyright 2008 - 2010 Red Hat, Inc.
*/
#include <config.h>
......@@ -229,6 +229,7 @@ ce_page_complete_init (CEPage *self,
static void
ce_page_init (CEPage *self)
{
self->builder = gtk_builder_new ();
}
static void
......@@ -431,3 +432,42 @@ ce_page_new_connection (const char *format,
return connection;
}
CEPage *
ce_page_new (GType page_type,
NMConnection *connection,
GtkWindow *parent_window,
const char *ui_file,
const char *widget_name,
const char *title)
{
CEPage *self;
GError *error = NULL;
g_return_val_if_fail (title != NULL, NULL);
if (ui_file)
g_return_val_if_fail (widget_name != NULL, NULL);
self = CE_PAGE (g_object_new (page_type,
CE_PAGE_CONNECTION, connection,
CE_PAGE_PARENT_WINDOW, parent_window,
NULL));
self->title = g_strdup (title);
if (ui_file) {
if (!gtk_builder_add_from_file (self->builder, ui_file, &error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
g_object_unref (self);
return NULL;
}
self->page = GTK_WIDGET (gtk_builder_get_object (self->builder, widget_name));
if (!self->page) {
g_warning ("Couldn't load page widget '%s' from %s", widget_name, ui_file);
g_object_unref (self);
return NULL;
}
g_object_ref_sink (self->page);
}
return self;
}
......@@ -54,8 +54,8 @@ typedef void (*PageNewConnectionFunc) (GtkWindow *parent,
#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))
#define CE_PAGE_CONNECTION "connection"
#define CE_PAGE_INITIALIZED "initialized"
#define CE_PAGE_CONNECTION "connection"
#define CE_PAGE_INITIALIZED "initialized"
#define CE_PAGE_PARENT_WINDOW "parent-window"
typedef struct {
......@@ -125,5 +125,12 @@ NMConnection *ce_page_new_connection (const char *format,
PageGetConnectionsFunc get_connections_func,
gpointer user_data);
CEPage *ce_page_new (GType page_type,
NMConnection *connection,
GtkWindow *parent_window,
const char *ui_file,
const char *widget_name,
const char *title);
#endif /* __CE_PAGE_H__ */
......@@ -272,31 +272,18 @@ system_checkbutton_toggled_cb (GtkWidget *widget, NMConnectionEditor *editor)
connection_editor_validate (editor);
}
#define NMCE_UI UIDIR "/nm-connection-editor.ui"
static void
nm_connection_editor_init (NMConnectionEditor *editor)
{
GtkWidget *dialog;
GError *error = NULL;
/* Yes, we mean applet.ui, not nm-connection-editor.ui. The wireless security bits
are taken from applet.ui. */
if (!g_file_test (UIDIR "/applet.ui", G_FILE_TEST_EXISTS)) {
dialog = gtk_message_dialog_new (NULL, 0,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s",
_("The connection editor could not find some required resources (the NetworkManager applet .ui file was not found)."));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
gtk_main_quit ();
return;
}
editor->builder = gtk_builder_new ();
editor->builder = gtk_builder_new();
if (!gtk_builder_add_from_file (editor->builder, UIDIR "/nm-connection-editor.ui", &error))
{
g_warning ("Couldn't load builder file: %s", error->message);
if (!gtk_builder_add_from_file (editor->builder, NMCE_UI, &error)) {
g_warning ("Couldn't load builder file " NMCE_UI ": %s", error->message);
g_error_free (error);
dialog = gtk_message_dialog_new (NULL, 0,
......@@ -526,9 +513,11 @@ idle_validate (gpointer user_data)
static void
recheck_initialization (NMConnectionEditor *editor)
{
if (!editor_is_initialized (editor))
if (!editor_is_initialized (editor) || editor->init_run)
return;
editor->init_run = TRUE;
populate_connection_ui (editor);
/* When everything is initialized, re-present the window to ensure it's on top */
......
......@@ -58,6 +58,7 @@ typedef struct {
GtkWidget *cancel_button;
gboolean busy;
gboolean init_run;
} NMConnectionEditor;
typedef struct {
......
......@@ -1493,7 +1493,7 @@ nm_connection_list_new (GType def_type)
return NULL;
/* load GUI */
list->gui = gtk_builder_new();
list->gui = gtk_builder_new ();
if (!gtk_builder_add_from_file (list->gui, UIDIR "/nm-connection-editor.ui", &error)) {
g_warning ("Couldn't load builder file: %s", error->message);
......
......@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 Red Hat, Inc.
* (C) Copyright 2008 - 2010 Red Hat, Inc.
*/
#include <string.h>
......@@ -127,32 +127,17 @@ ce_page_dsl_new (NMConnection *connection,
{
CEPageDsl *self;
CEPageDslPrivate *priv;
CEPage *parent;
self = CE_PAGE_DSL (g_object_new (CE_TYPE_PAGE_DSL,
CE_PAGE_CONNECTION, connection,
CE_PAGE_PARENT_WINDOW, parent_window,
NULL));
parent = CE_PAGE (self);
parent->builder = gtk_builder_new();
if (!gtk_builder_add_from_file (parent->builder, UIDIR "/ce-page-dsl.ui", error)) {
g_warning ("Couldn't load builder file: %s", (*error)->message);
g_set_error (error, 0, 0, "%s", _("Could not load DSL user interface."));
g_object_unref (self);
return NULL;
}
parent->page = GTK_WIDGET (gtk_builder_get_object (parent->builder, "DslPage"));
if (!parent->page) {
g_set_error (error, 0, 0, "%s", _("Could not load DSL user interface."));
g_object_unref (self);
self = CE_PAGE_DSL (ce_page_new (CE_TYPE_PAGE_DSL,
connection,
parent_window,
UIDIR "/ce-page-dsl.ui",
"DslPage",
_("DSL")));
if (!self) {
g_set_error_literal (error, 0, 0, _("Could not load DSL user interface."));
return NULL;
}
g_object_ref_sink (parent->page);
parent->title = g_strdup (_("DSL"));
dsl_private_init (self);
priv = CE_PAGE_DSL_GET_PRIVATE (self);
......
......@@ -805,33 +805,18 @@ ce_page_ip4_new (NMConnection *connection,
{
CEPageIP4 *self;
CEPageIP4Private *priv;
CEPage *parent;
NMSettingConnection *s_con;
self = CE_PAGE_IP4 (g_object_new (CE_TYPE_PAGE_IP4,
CE_PAGE_CONNECTION, connection,
CE_PAGE_PARENT_WINDOW, parent_window,
NULL));
parent = CE_PAGE (self);
parent->builder = gtk_builder_new();
if (!gtk_builder_add_from_file (parent->builder, UIDIR "/ce-page-ip4.ui", error)) {
g_warning ("Couldn't load builder file: %s", (*error)->message);
g_set_error (error, 0, 0, "%s", _("Could not load IPv4 user interface."));
g_object_unref (self);
return NULL;
}
parent->page = GTK_WIDGET (gtk_builder_get_object (parent->builder, "IP4Page"));
if (!parent->page) {
g_set_error (error, 0, 0, "%s", _("Could not load IPv4 user interface."));
g_object_unref (self);
self = CE_PAGE_IP4 (ce_page_new (CE_TYPE_PAGE_IP4,
connection,
parent_window,
UIDIR "/ce-page-ip4.ui",
"IP4Page",
_("IPv4 Settings")));
if (!self) {
g_set_error_literal (error, 0, 0, _("Could not load IPv4 user interface."));
return NULL;
}
g_object_ref_sink (parent->page);
parent->title = g_strdup (_("IPv4 Settings"));
ip4_private_init (self, connection);
priv = CE_PAGE_IP4_GET_PRIVATE (self);
......
......@@ -788,33 +788,18 @@ ce_page_ip6_new (NMConnection *connection,
{
CEPageIP6 *self;
CEPageIP6Private *priv;
CEPage *parent;
NMSettingConnection *s_con;
self = CE_PAGE_IP6 (g_object_new (CE_TYPE_PAGE_IP6,
CE_PAGE_CONNECTION, connection,
CE_PAGE_PARENT_WINDOW, parent_window,
NULL));
parent = CE_PAGE (self);
parent->builder = gtk_builder_new();
if (!gtk_builder_add_from_file (parent->builder, UIDIR "/ce-page-ip6.ui", error)) {
g_warning ("Couldn't load builder file: %s", (*error)->message);
g_set_error (error, 0, 0, "%s", _("Could not load IPv6 user interface."));
g_object_unref (self);
return NULL;
}
parent->page = GTK_WIDGET (gtk_builder_get_object (parent->builder, "IP6Page"));
if (!parent->page) {
g_set_error (error, 0, 0, "%s", _("Could not load IPv6 user interface."));
g_object_unref (self);
self = CE_PAGE_IP6 (ce_page_new (CE_TYPE_PAGE_IP6,
connection,
parent_window,
UIDIR "/ce-page-ip6.ui",
"IP6Page",
_("IPv6 Settings")));
if (!self) {
g_set_error_literal (error, 0, 0, _("Could not load IPv6 user interface."));
return NULL;
}
g_object_ref_sink (parent->page);
parent->title = g_strdup (_("IPv6 Settings"));
ip6_private_init (self, connection);
priv = CE_PAGE_IP6_GET_PRIVATE (self);
......
......@@ -356,32 +356,17 @@ ce_page_mobile_new (NMConnection *connection,
{
CEPageMobile *self;
CEPageMobilePrivate *priv;
CEPage *parent;
self = CE_PAGE_MOBILE (g_object_new (CE_TYPE_PAGE_MOBILE,
CE_PAGE_CONNECTION, connection,
CE_PAGE_PARENT_WINDOW, parent_window,
NULL));
parent = CE_PAGE (self);
parent->builder = gtk_builder_new();
if (!gtk_builder_add_from_file (parent->builder, UIDIR "/ce-page-mobile.ui", error)) {
g_warning ("Couldn't load builder file: %s", (*error)->message);
g_set_error (error, 0, 0, "%s", _("Could not load mobile broadband user interface."));
g_object_unref (self);
return NULL;
}
parent->page = GTK_WIDGET (gtk_builder_get_object (parent->builder, "MobilePage"));
if (!parent->page) {
g_set_error (error, 0, 0, "%s", _("Could not load mobile broadband user interface."));
g_object_unref (self);
self = CE_PAGE_MOBILE (ce_page_new (CE_TYPE_PAGE_MOBILE,
connection,
parent_window,
UIDIR "/ce-page-mobile.ui",
"MobilePage",
_("Mobile Broadband")));
if (!self) {
g_set_error_literal (error, 0, 0, _("Could not load mobile broadband user interface."));
return NULL;
}
g_object_ref_sink (parent->page);
parent->title = g_strdup (_("Mobile Broadband"));
mobile_private_init (self);
priv = CE_PAGE_MOBILE_GET_PRIVATE (self);
......
......@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 Red Hat, Inc.
* (C) Copyright 2008 - 2010 Red Hat, Inc.
*/
#include <string.h>
......@@ -269,33 +269,18 @@ ce_page_ppp_new (NMConnection *connection,
{
CEPagePpp *self;
CEPagePppPrivate *priv;
CEPage *parent;
NMSettingConnection *s_con;
self = CE_PAGE_PPP (g_object_new (CE_TYPE_PAGE_PPP,
CE_PAGE_CONNECTION, connection,
CE_PAGE_PARENT_WINDOW, parent_window,
NULL));
parent = CE_PAGE (self);
parent->builder = gtk_builder_new();
if (!gtk_builder_add_from_file (parent->builder, UIDIR "/ce-page-ppp.ui", error)) {
g_warning ("Couldn't load builder file: %s", (*error)->message);
g_set_error (error, 0, 0, "%s", _("Could not load PPP user interface."));
g_object_unref (self);
return NULL;
}
parent->page = GTK_WIDGET (gtk_builder_get_object (parent->builder, "PppPage"));
if (!parent->page) {
g_set_error (error, 0, 0, "%s", _("Could not load PPP user interface."));
g_object_unref (self);
self = CE_PAGE_PPP (ce_page_new (CE_TYPE_PAGE_PPP,
connection,
parent_window,
UIDIR "/ce-page-ppp.ui",
"PppPage",
_("PPP Settings")));
if (!self) {
g_set_error_literal (error, 0, 0, _("Could not load PPP user interface."));
return NULL;
}
g_object_ref_sink (parent->page);
parent->title = g_strdup (_("PPP Settings"));
ppp_private_init (self);
priv = CE_PAGE_PPP_GET_PRIVATE (self);
......
......@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 Red Hat, Inc.
* (C) Copyright 2008 - 2010 Red Hat, Inc.
*/
#include <string.h>
......@@ -95,17 +95,20 @@ ce_page_vpn_new (NMConnection *connection,
{
CEPageVpn *self;
CEPageVpnPrivate *priv;
CEPage *parent;
const char *service_type;
self = CE_PAGE_VPN (g_object_new (CE_TYPE_PAGE_VPN,
CE_PAGE_CONNECTION, connection,
CE_PAGE_PARENT_WINDOW, parent_window,
NULL));
parent = CE_PAGE (self);
priv = CE_PAGE_VPN_GET_PRIVATE (self);
self = CE_PAGE_VPN (ce_page_new (CE_TYPE_PAGE_VPN,
connection,
parent_window,
NULL,
NULL,
_("VPN")));
if (!self) {
g_set_error_literal (error, 0, 0, _("Could not load VPN user interface."));
return NULL;
}
parent->title = g_strdup (_("VPN"));
priv = CE_PAGE_VPN_GET_PRIVATE (self);
priv->setting = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
g_assert (priv->setting);
......
......@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 Red Hat, Inc.
* (C) Copyright 2008 - 2010 Red Hat, Inc.
*/
#include <string.h>
......@@ -72,12 +72,11 @@ finish_setup (CEPageWiredSecurity *self, gpointer unused, GError *error, gpointe
{
CEPage *parent = CE_PAGE (self);
CEPageWiredSecurityPrivate *priv = CE_PAGE_WIRED_SECURITY_GET_PRIVATE (self);
const char *ui_file = UIDIR "/applet.ui";
if (error)
return;
priv->security = (WirelessSecurity *) ws_wpa_eap_new (ui_file, parent->connection, TRUE);
priv->security = (WirelessSecurity *) ws_wpa_eap_new (parent->connection, TRUE);
if (!priv->security) {
g_warning ("Could not load wired 802.1x user interface.");
return;
......@@ -103,17 +102,23 @@ ce_page_wired_security_new (NMConnection *connection,
GError **error)
{
CEPageWiredSecurity *self;
CEPage *parent;
CEPageWiredSecurityPrivate *priv;
CEPage *parent;
self = CE_PAGE_WIRED_SECURITY (ce_page_new (CE_TYPE_PAGE_WIRED_SECURITY,
connection,
parent_window,
NULL,
NULL,
_("802.1x Security")));
if (!self) {
g_set_error_literal (error, 0, 0, _("Could not load Wired Security security user interface."));
return NULL;
}
self = CE_PAGE_WIRED_SECURITY (g_object_new (CE_TYPE_PAGE_WIRED_SECURITY,
CE_PAGE_CONNECTION, connection,
CE_PAGE_PARENT_WINDOW, parent_window,
NULL));
parent = CE_PAGE (self);
priv = CE_PAGE_WIRED_SECURITY_GET_PRIVATE (self);
parent->title = g_strdup (_("802.1x Security"));
parent->page = gtk_vbox_new (FALSE, 6);
g_object_ref_sink (G_OBJECT (parent->page));
gtk_container_set_border_width (GTK_CONTAINER (parent->page), 6);
......
......@@ -200,33 +200,18 @@ ce_page_wired_new (NMConnection *connection,
{
CEPageWired *self;
CEPageWiredPrivate *priv;
CEPage *parent;
self = CE_PAGE_WIRED (g_object_new (CE_TYPE_PAGE_WIRED,
CE_PAGE_CONNECTION, connection,
CE_PAGE_PARENT_WINDOW, parent_window,
NULL));
parent = CE_PAGE (self);
parent->builder = gtk_builder_new ();
if (!gtk_builder_add_from_file (parent->builder, UIDIR "/ce-page-wired.ui", error)) {
g_warning ("Couldn't load builder file: %s", (*error)->message);
g_set_error (error, 0, 0, "%s", _("Could not load wired user interface."));
g_object_unref (self);
self = CE_PAGE_WIRED (ce_page_new (CE_TYPE_PAGE_WIRED,
connection,
parent_window,
UIDIR "/ce-page-wired.ui",
"WiredPage",
_("Wired")));
if (!self) {
g_set_error_literal (error, 0, 0, _("Could not load wired user interface."));
return NULL;
}
parent->page = GTK_WIDGET (gtk_builder_get_object (parent->builder, "WiredPage"));
if (!parent->page) {
g_set_error (error, 0, 0, "%s", _("Could not load wired user interface."));
g_object_unref (self);
return NULL;
}
g_object_ref_sink (parent->page);
parent->title = g_strdup (_("Wired"));
wired_private_init (self);
priv = CE_PAGE_WIRED_GET_PRIVATE (self);
......@@ -368,4 +353,3 @@ wired_connection_new (GtkWindow *parent,
(*result_func) (connection, FALSE, NULL, user_data);
}
......@@ -200,7 +200,6 @@ finish_setup (CEPageWirelessSecurity *self, gpointer unused, GError *error, gpoi
NMUtilsSecurityType default_type = NMU_SEC_NONE;
int active = -1;
int item = 0;
const char *ui_file = UIDIR "/applet.ui";
GtkComboBox *combo;
if (error)
......@@ -257,7 +256,7 @@ finish_setup (CEPageWirelessSecurity *self, gpointer unused, GError *error, gpoi
wep_type = NM_WEP_KEY_TYPE_KEY;
}
ws_wep = ws_wep_key_new (ui_file, connection, NM_WEP_KEY_TYPE_KEY, FALSE, FALSE);
ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_KEY, FALSE, FALSE);
if (ws_wep) {
add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
&iter, _("WEP 40/128-bit Key (Hex or ASCII)"));
......@@ -266,7 +265,7 @@ finish_setup (CEPageWirelessSecurity *self, gpointer unused, GError *error, gpoi
item++;
}
ws_wep = ws_wep_key_new (ui_file, connection, NM_WEP_KEY_TYPE_PASSPHRASE, FALSE, FALSE);
ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_PASSPHRASE, FALSE, FALSE);
if (ws_wep) {
add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
&iter, _("WEP 128-bit Passphrase"));
......@@ -279,7 +278,7 @@ finish_setup (CEPageWirelessSecurity *self, gpointer unused, GError *error, gpoi
if (nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
WirelessSecurityLEAP *ws_leap;
ws_leap = ws_leap_new (ui_file, connection);
ws_leap = ws_leap_new (connection);
if (ws_leap) {
add_security_item (self, WIRELESS_SECURITY (ws_leap), sec_model,
&iter, _("LEAP"));
......@@ -292,7 +291,7 @@ finish_setup (CEPageWirelessSecurity *self, gpointer unused, GError *error, gpoi
if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {