[gnome-control-center/wip/enterprise-login: 2/15] user-accounts: Make UmAccountDialog a GtkDialog
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/enterprise-login: 2/15] user-accounts: Make UmAccountDialog a GtkDialog
- Date: Wed, 6 Jun 2012 23:03:58 +0000 (UTC)
commit df7126bbef472b45e9b76de9f396f14f053d15a7
Author: Stef Walter <stefw gnome org>
Date: Wed Jun 6 21:43:57 2012 +0200
user-accounts: Make UmAccountDialog a GtkDialog
The dialog will get much more complex due to 'enterprise login'
work and we want a proper object here.
https://bugzilla.gnome.org/show_bug.cgi?id=677548
panels/user-accounts/data/account-dialog.ui | 69 +----------------
panels/user-accounts/um-account-dialog.c | 110 +++++++++++++++++----------
panels/user-accounts/um-account-dialog.h | 6 +-
panels/user-accounts/um-user-panel.c | 2 +-
4 files changed, 78 insertions(+), 109 deletions(-)
---
diff --git a/panels/user-accounts/data/account-dialog.ui b/panels/user-accounts/data/account-dialog.ui
index 3ae2fc3..a1a174d 100644
--- a/panels/user-accounts/data/account-dialog.ui
+++ b/panels/user-accounts/data/account-dialog.ui
@@ -26,21 +26,7 @@
</row>
</data>
</object>
- <object class="GtkDialog" id="dialog">
- <property name="border_width">5</property>
- <property name="title"> </property>
- <property name="resizable">False</property>
- <property name="modal">True</property>
- <property name="window_position">center-on-parent</property>
- <property name="icon_name">system-users</property>
- <property name="type_hint">dialog</property>
- <child internal-child="vbox">
- <object class="GtkVBox" id="content-area">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">2</property>
- <child>
- <object class="GtkVBox" id="vbox1">
+ <object class="GtkVBox" id="account-dialog">
<property name="visible">True</property>
<property name="border_width">10</property>
<property name="spacing">6</property>
@@ -209,57 +195,4 @@
</packing>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area9">
- <property name="visible">True</property>
- <property name="layout_style">end</property>
- <child>
- <object class="GtkButton" id="cancel-button">
- <property name="label">gtk-cancel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="ok-button">
- <property name="label" translatable="yes">Cr_eate</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">True</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- </child>
- <action-widgets>
- <action-widget response="0">cancel-button</action-widget>
- <action-widget response="0">ok-button</action-widget>
- </action-widgets>
- </object>
</interface>
diff --git a/panels/user-accounts/um-account-dialog.c b/panels/user-accounts/um-account-dialog.c
index cdc8545..69557c1 100644
--- a/panels/user-accounts/um-account-dialog.c
+++ b/panels/user-accounts/um-account-dialog.c
@@ -29,12 +29,17 @@
#include "um-user-manager.h"
#include "um-utils.h"
+#define UM_ACCOUNT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UM_TYPE_ACCOUNT_DIALOG, \
+ UmAccountDialogClass))
+#define UM_IS_ACCOUNT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UM_TYPE_ACCOUNT_DIALOG))
+#define UM_ACCOUNT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UM_TYPE_ACCOUNT_DIALOG, \
+ UmAccountDialogClass))
+
struct _UmAccountDialog {
- GtkWidget *dialog;
+ GtkDialog parent;
GtkWidget *username_combo;
GtkWidget *name_entry;
GtkWidget *account_type_combo;
- GtkWidget *ok_button;
gboolean valid_name;
gboolean valid_username;
@@ -43,11 +48,16 @@ struct _UmAccountDialog {
gpointer user_created_data;
};
+typedef struct {
+ GtkDialogClass parent_class;
+} UmAccountDialogClass;
+
+G_DEFINE_TYPE (UmAccountDialog, um_account_dialog, GTK_TYPE_DIALOG);
+
static void
-cancel_account_dialog (GtkButton *button,
- UmAccountDialog *um)
+cancel_account_dialog (UmAccountDialog *um)
{
- gtk_widget_hide (um->dialog);
+ gtk_widget_hide (GTK_WIDGET (um));
}
static void
@@ -64,7 +74,7 @@ create_user_done (UmUserManager *manager,
if (!g_error_matches (error, UM_USER_MANAGER_ERROR, UM_USER_MANAGER_ERROR_PERMISSION_DENIED)) {
GtkWidget *dialog;
- dialog = gtk_message_dialog_new (gtk_window_get_transient_for (GTK_WINDOW (um->dialog)),
+ dialog = gtk_message_dialog_new (gtk_window_get_transient_for (GTK_WINDOW (um)),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
@@ -85,8 +95,7 @@ create_user_done (UmUserManager *manager,
}
static void
-accept_account_dialog (GtkButton *button,
- UmAccountDialog *um)
+accept_account_dialog (UmAccountDialog *um)
{
UmUserManager *manager;
const gchar *username;
@@ -111,7 +120,7 @@ accept_account_dialog (GtkButton *button,
NULL);
g_object_unref (manager);
- gtk_widget_hide (um->dialog);
+ gtk_widget_hide (GTK_WIDGET (um));
}
static void
@@ -126,7 +135,8 @@ username_changed (GtkComboBoxText *combo,
um->valid_username = is_valid_username (username, &tip);
- gtk_widget_set_sensitive (um->ok_button, um->valid_name && um->valid_username);
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (um), GTK_RESPONSE_OK,
+ um->valid_name && um->valid_username);
entry = gtk_bin_get_child (GTK_BIN (combo));
if (tip) {
@@ -155,7 +165,8 @@ name_changed (GtkEntry *name_entry,
name = gtk_entry_get_text (GTK_ENTRY (name_entry));
um->valid_name = is_valid_name (name);
- gtk_widget_set_sensitive (um->ok_button, um->valid_name && um->valid_username);
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (um), GTK_RESPONSE_OK,
+ um->valid_name && um->valid_username);
if (!um->valid_name) {
gtk_entry_set_text (GTK_ENTRY (entry), "");
@@ -167,14 +178,15 @@ name_changed (GtkEntry *name_entry,
gtk_combo_box_set_active (GTK_COMBO_BOX (um->username_combo), 0);
}
-UmAccountDialog *
-um_account_dialog_new (void)
+static void
+um_account_dialog_init (UmAccountDialog *um)
{
GtkBuilder *builder;
GtkWidget *widget;
- UmAccountDialog *um;
const gchar *filename;
GError *error = NULL;
+ GtkDialog *dialog;
+ GtkWidget *content;
builder = gtk_builder_new ();
@@ -184,25 +196,23 @@ um_account_dialog_new (void)
if (!gtk_builder_add_from_file (builder, filename, &error)) {
g_error ("%s", error->message);
g_error_free (error);
- return NULL;
+ return;
}
- um = g_new0 (UmAccountDialog, 1);
+ dialog = GTK_DIALOG (um);
+ content = gtk_dialog_get_content_area (dialog);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+ gtk_window_set_title (GTK_WINDOW (dialog), " ");
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "system-users");
- widget = (GtkWidget *) gtk_builder_get_object (builder, "dialog");
- g_signal_connect (widget, "delete-event",
- G_CALLBACK (gtk_widget_hide_on_delete), NULL);
- um->dialog = widget;
-
- widget = (GtkWidget *) gtk_builder_get_object (builder, "cancel-button");
- g_signal_connect (widget, "clicked",
- G_CALLBACK (cancel_account_dialog), um);
-
- widget = (GtkWidget *) gtk_builder_get_object (builder, "ok-button");
- g_signal_connect (widget, "clicked",
- G_CALLBACK (accept_account_dialog), um);
+ gtk_dialog_add_button (dialog, _("Cancel"), GTK_RESPONSE_CANCEL);
+ widget = gtk_dialog_add_button (dialog, _("Create"), GTK_RESPONSE_OK);
gtk_widget_grab_default (widget);
+ widget = (GtkWidget *) gtk_builder_get_object (builder, "account-dialog");
+ gtk_container_add (GTK_CONTAINER (content), widget);
+
widget = (GtkWidget *) gtk_builder_get_object (builder, "username-combo");
g_signal_connect (widget, "changed",
G_CALLBACK (username_changed), um);
@@ -213,19 +223,42 @@ um_account_dialog_new (void)
G_CALLBACK (name_changed), um);
um->name_entry = widget;
- um->ok_button = (GtkWidget *) gtk_builder_get_object (builder, "ok-button");
-
widget = (GtkWidget *) gtk_builder_get_object (builder, "account-type-combo");
um->account_type_combo = widget;
+}
- return um;
+static void
+um_account_dialog_response (GtkDialog *dialog,
+ gint response_id)
+{
+ UmAccountDialog *self = UM_ACCOUNT_DIALOG (dialog);
+
+ switch (response_id) {
+ case GTK_RESPONSE_OK:
+ accept_account_dialog (self);
+ break;
+ case GTK_RESPONSE_CANCEL:
+ case GTK_RESPONSE_DELETE_EVENT:
+ cancel_account_dialog (self);
+ break;
+ default:
+ g_warn_if_reached ();
+ break;
+ }
}
-void
-um_account_dialog_free (UmAccountDialog *um)
+static void
+um_account_dialog_class_init (UmAccountDialogClass *klass)
+{
+ GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
+
+ dialog_class->response = um_account_dialog_response;
+}
+
+UmAccountDialog *
+um_account_dialog_new (void)
{
- gtk_widget_destroy (um->dialog);
- g_free (um);
+ return g_object_new (UM_TYPE_ACCOUNT_DIALOG, NULL);
}
void
@@ -242,8 +275,9 @@ um_account_dialog_show (UmAccountDialog *um,
gtk_list_store_clear (GTK_LIST_STORE (model));
gtk_combo_box_set_active (GTK_COMBO_BOX (um->account_type_combo), 0);
- gtk_window_set_transient_for (GTK_WINDOW (um->dialog), parent);
- gtk_window_present (GTK_WINDOW (um->dialog));
+ gtk_window_set_modal (GTK_WINDOW (um), parent != NULL);
+ gtk_window_set_transient_for (GTK_WINDOW (um), parent);
+ gtk_window_present (GTK_WINDOW (um));
gtk_widget_grab_focus (um->name_entry);
um->valid_name = um->valid_username = TRUE;
@@ -251,5 +285,3 @@ um_account_dialog_show (UmAccountDialog *um,
um->user_created_callback = user_created_callback;
um->user_created_data = user_created_data;
}
-
-
diff --git a/panels/user-accounts/um-account-dialog.h b/panels/user-accounts/um-account-dialog.h
index e3b2ebc..0366ca3 100644
--- a/panels/user-accounts/um-account-dialog.h
+++ b/panels/user-accounts/um-account-dialog.h
@@ -27,12 +27,16 @@
G_BEGIN_DECLS
+#define UM_TYPE_ACCOUNT_DIALOG (um_account_dialog_get_type ())
+#define UM_ACCOUNT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UM_TYPE_ACCOUNT_DIALOG, UmAccountDialog))
+#define UM_IS_ACCOUNT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UM_TYPE_ACCOUNT_DIALOG))
+
typedef struct _UmAccountDialog UmAccountDialog;
typedef void (*UserCreatedCallback) (UmUser *user, gpointer data);
+GType um_account_dialog_get_type (void) G_GNUC_CONST;
UmAccountDialog *um_account_dialog_new (void);
-void um_account_dialog_free (UmAccountDialog *dialog);
void um_account_dialog_show (UmAccountDialog *dialog,
GtkWindow *parent,
UserCreatedCallback user_created,
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index b4b3809..3793862 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -1297,7 +1297,7 @@ um_user_panel_dispose (GObject *object)
priv->builder = NULL;
}
if (priv->account_dialog) {
- um_account_dialog_free (priv->account_dialog);
+ gtk_widget_destroy (GTK_WIDGET (priv->account_dialog));
priv->account_dialog = NULL;
}
if (priv->password_dialog) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]