[accounts-dialog/control-center-panel: 13/15] More widgetification
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [accounts-dialog/control-center-panel: 13/15] More widgetification
- Date: Mon, 14 Jun 2010 05:06:28 +0000 (UTC)
commit b8fc3bb9c03d0cee2ff669370df01a663afcb505
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jun 14 00:41:56 2010 -0400
More widgetification
Rename UmEditableButton to UmEditableEntry, and introduce a
UmEditableButton widget which is used for the password field.
data/user-accounts-dialog.ui | 33 +---
src/Makefile.am | 2 +
src/um-editable-button.c | 98 +--------
src/um-editable-button.h | 2 +-
src/um-editable-entry.c | 487 ++++++++++++++++++++++++++++++++++++++++++
src/um-editable-entry.h | 72 ++++++
src/um-user-panel.c | 162 ++++----------
7 files changed, 614 insertions(+), 242 deletions(-)
---
diff --git a/data/user-accounts-dialog.ui b/data/user-accounts-dialog.ui
index 49c3d45..e6e4f8c 100644
--- a/data/user-accounts-dialog.ui
+++ b/data/user-accounts-dialog.ui
@@ -214,7 +214,7 @@
</packing>
</child>
<child>
- <object class="UmEditableButton" id="account-location-button">
+ <object class="UmEditableEntry" id="account-location-entry">
<property name="visible">True</property>
</object>
<packing>
@@ -301,7 +301,7 @@
</packing>
</child>
<child>
- <object class="UmEditableButton" id="full-name-button">
+ <object class="UmEditableEntry" id="full-name-entry">
<property name="visible">True</property>
<property name="scale">1.2</property>
<property name="weight">700</property>
@@ -332,33 +332,8 @@
</packing>
</child>
<child>
- <object class="GtkNotebook" id="account-password-notebook">
+ <object class="UmEditableButton" id="account-password-button">
<property name="visible">True</property>
- <property name="show_tabs">False</property>
- <property name="show_border">False</property>
- <child>
- <object class="GtkLabel" id="account-password-value-label">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="account-password-button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="relief">none</property>
- <child>
- <object class="GtkLabel" id="account-password-button-label">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
</object>
<packing>
<property name="left_attach">1</property>
@@ -383,7 +358,7 @@
</packing>
</child>
<child>
- <object class="UmEditableButton" id="account-email-button">
+ <object class="UmEditableEntry" id="account-email-entry">
<property name="visible">True</property>
</object>
<packing>
diff --git a/src/Makefile.am b/src/Makefile.am
index a6c6398..7477704 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -65,6 +65,8 @@ libuser_properties_la_SOURCES = \
$(MARSHALFILES) \
um-editable-button.h \
um-editable-button.c \
+ um-editable-entry.h \
+ um-editable-entry.c \
um-editable-combo.h \
um-editable-combo.c \
um-user-panel.h \
diff --git a/src/um-editable-button.c b/src/um-editable-button.c
index 59b792b..4a75046 100644
--- a/src/um-editable-button.c
+++ b/src/um-editable-button.c
@@ -28,7 +28,6 @@ struct _UmEditableButtonPrivate {
GtkNotebook *notebook;
GtkLabel *label;
GtkButton *button;
- GtkEntry *entry;
gchar *text;
gboolean editable;
@@ -51,7 +50,7 @@ enum {
};
enum {
- EDITING_DONE,
+ START_EDITING,
LAST_SIGNAL
};
@@ -73,8 +72,6 @@ um_editable_button_set_text (UmEditableButton *button,
g_free (priv->text);
priv->text = tmp;
- gtk_entry_set_text (priv->entry, tmp);
-
if (tmp == NULL || tmp[0] == '\0')
tmp = EMPTY_TEXT;
@@ -115,36 +112,6 @@ um_editable_button_get_editable (UmEditableButton *button)
}
static void
-update_entry_font (GtkWidget *widget,
- GtkStyle *previous_style,
- UmEditableButton *button)
-{
- UmEditableButtonPrivate *priv = button->priv;
- PangoFontDescription *desc;
- gint size;
-
- if (!priv->weight_set && !priv->scale_set)
- return;
-
- g_signal_handlers_block_by_func (widget, update_entry_font, button);
-
- gtk_widget_modify_font (widget, NULL);
-
- desc = pango_font_description_copy (widget->style->font_desc);
- if (priv->weight_set)
- pango_font_description_set_weight (desc, priv->weight);
- if (priv->scale_set) {
- size = pango_font_description_get_size (desc);
- pango_font_description_set_size (desc, priv->scale * size);
- }
- gtk_widget_modify_font (widget, desc);
-
- pango_font_description_free (desc);
-
- g_signal_handlers_unblock_by_func (widget, update_entry_font, button);
-}
-
-static void
update_fonts (UmEditableButton *button)
{
PangoAttrList *attrs;
@@ -169,8 +136,6 @@ update_fonts (UmEditableButton *button)
gtk_label_set_attributes (GTK_LABEL (label), attrs);
pango_attr_list_unref (attrs);
-
- update_entry_font ((GtkWidget *)priv->entry, NULL, button);
}
void
@@ -314,11 +279,11 @@ um_editable_button_class_init (UmEditableButtonClass *class)
object_class->get_property = um_editable_button_get_property;
object_class->finalize = um_editable_button_finalize;
- signals[EDITING_DONE] =
- g_signal_new ("editing-done",
+ signals[START_EDITING] =
+ g_signal_new ("start-editing",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (UmEditableButtonClass, editing_done),
+ G_STRUCT_OFFSET (UmEditableButtonClass, start_editing),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
@@ -365,25 +330,7 @@ um_editable_button_class_init (UmEditableButtonClass *class)
static void
start_editing (UmEditableButton *button)
{
- gtk_notebook_set_current_page (button->priv->notebook, 2);
-}
-
-static void
-stop_editing (UmEditableButton *button)
-{
- um_editable_button_set_text (button,
- gtk_entry_get_text (button->priv->entry));
- gtk_notebook_set_current_page (button->priv->notebook, 1);
-
- g_signal_emit (button, signals[EDITING_DONE], 0);
-}
-
-static void
-cancel_editing (UmEditableButton *button)
-{
- gtk_entry_set_text (button->priv->entry,
- um_editable_button_get_text (button));
- gtk_notebook_set_current_page (button->priv->notebook, 1);
+ g_signal_emit (button, signals[START_EDITING], 0);
}
static void
@@ -394,32 +341,6 @@ button_clicked (GtkWidget *widget,
}
static void
-entry_activated (GtkWidget *widget,
- UmEditableButton *button)
-{
- stop_editing (button);
-}
-
-static gboolean
-entry_focus_out (GtkWidget *widget,
- GdkEventFocus *event,
- UmEditableButton *button)
-{
- stop_editing (button);
- return FALSE;
-}
-
-static gboolean
-entry_key_press (GtkWidget *widget,
- GdkEventKey *event,
- UmEditableButton *button)
-{
- if (event->keyval == GDK_Escape)
- cancel_editing (button);
- return FALSE;
-}
-
-static void
update_button_padding (GtkWidget *widget,
GtkAllocation *allocation,
UmEditableButton *button)
@@ -464,14 +385,6 @@ um_editable_button_init (UmEditableButton *button)
gtk_button_set_alignment (priv->button, 0.0, 0.5);
gtk_notebook_append_page (priv->notebook, (GtkWidget*)priv->button, NULL);
g_signal_connect (priv->button, "clicked", G_CALLBACK (button_clicked), button);
-
- priv->entry = (GtkEntry*)gtk_entry_new ();
- gtk_notebook_append_page (priv->notebook, (GtkWidget*)priv->entry, NULL);
-
- g_signal_connect (priv->entry, "activate", G_CALLBACK (entry_activated), button);
- g_signal_connect (priv->entry, "focus-out-event", G_CALLBACK (entry_focus_out), button);
- g_signal_connect (priv->entry, "key-press-event", G_CALLBACK (entry_key_press), button);
- g_signal_connect (priv->entry, "style-set", G_CALLBACK (update_entry_font), button);
g_signal_connect (gtk_bin_get_child (GTK_BIN (priv->button)), "size-allocate", G_CALLBACK (update_button_padding), button);
gtk_container_add (GTK_CONTAINER (button), (GtkWidget*)priv->notebook);
@@ -479,7 +392,6 @@ um_editable_button_init (UmEditableButton *button)
gtk_widget_show ((GtkWidget*)priv->notebook);
gtk_widget_show ((GtkWidget*)priv->label);
gtk_widget_show ((GtkWidget*)priv->button);
- gtk_widget_show ((GtkWidget*)priv->entry);
gtk_notebook_set_current_page (priv->notebook, 0);
}
diff --git a/src/um-editable-button.h b/src/um-editable-button.h
index a378ba1..36af622 100644
--- a/src/um-editable-button.h
+++ b/src/um-editable-button.h
@@ -49,7 +49,7 @@ struct _UmEditableButtonClass
{
GtkAlignmentClass parent_class;
- void (* editing_done) (UmEditableButton *button);
+ void (* start_editing) (UmEditableButton *button);
};
GType um_editable_button_get_type (void) G_GNUC_CONST;
diff --git a/src/um-editable-entry.c b/src/um-editable-entry.c
new file mode 100644
index 0000000..5b9b0e5
--- /dev/null
+++ b/src/um-editable-entry.c
@@ -0,0 +1,487 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2009-2010 Red Hat, Inc,
+ *
+ * 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 3 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.
+ *
+ * Written by: Matthias Clasen <mclasen redhat com>
+ */
+
+#include <gdk/gdkkeysyms.h>
+#include "um-editable-entry.h"
+
+#define EMPTY_TEXT "\xe2\x80\x94"
+
+struct _UmEditableEntryPrivate {
+ GtkNotebook *notebook;
+ GtkLabel *label;
+ GtkButton *button;
+ GtkEntry *entry;
+
+ gchar *text;
+ gboolean editable;
+ gint weight;
+ gboolean weight_set;
+ gdouble scale;
+ gboolean scale_set;
+};
+
+#define UM_EDITABLE_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), UM_TYPE_EDITABLE_ENTRY, UmEditableEntryPrivate))
+
+enum {
+ PROP_0,
+ PROP_TEXT,
+ PROP_EDITABLE,
+ PROP_SCALE,
+ PROP_SCALE_SET,
+ PROP_WEIGHT,
+ PROP_WEIGHT_SET
+};
+
+enum {
+ EDITING_DONE,
+ LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL] = { 0, };
+
+G_DEFINE_TYPE (UmEditableEntry, um_editable_entry, GTK_TYPE_ALIGNMENT);
+
+void
+um_editable_entry_set_text (UmEditableEntry *e,
+ const gchar *text)
+{
+ UmEditableEntryPrivate *priv;
+ gchar *tmp;
+ GtkWidget *label;
+
+ priv = e->priv;
+
+ tmp = g_strdup (text);
+ g_free (priv->text);
+ priv->text = tmp;
+
+ gtk_entry_set_text (priv->entry, tmp);
+
+ if (tmp == NULL || tmp[0] == '\0')
+ tmp = EMPTY_TEXT;
+
+ gtk_label_set_text (priv->label, tmp);
+ label = gtk_bin_get_child (GTK_BIN (priv->button));
+ gtk_label_set_text (GTK_LABEL (label), tmp);
+
+ g_object_notify (G_OBJECT (e), "text");
+}
+
+const gchar *
+um_editable_entry_get_text (UmEditableEntry *e)
+{
+ return e->priv->text;
+}
+
+void
+um_editable_entry_set_editable (UmEditableEntry *e,
+ gboolean editable)
+{
+ UmEditableEntryPrivate *priv;
+
+ priv = e->priv;
+
+ if (priv->editable != editable) {
+ priv->editable = editable;
+
+ gtk_notebook_set_current_page (priv->notebook, editable ? 1 : 0);
+
+ g_object_notify (G_OBJECT (e), "editable");
+ }
+}
+
+gboolean
+um_editable_entry_get_editable (UmEditableEntry *e)
+{
+ return e->priv->editable;
+}
+
+static void
+update_entry_font (GtkWidget *widget,
+ GtkStyle *previous_style,
+ UmEditableEntry *e)
+{
+ UmEditableEntryPrivate *priv = e->priv;
+ PangoFontDescription *desc;
+ gint size;
+
+ if (!priv->weight_set && !priv->scale_set)
+ return;
+
+ g_signal_handlers_block_by_func (widget, update_entry_font, e);
+
+ gtk_widget_modify_font (widget, NULL);
+
+ desc = pango_font_description_copy (widget->style->font_desc);
+ if (priv->weight_set)
+ pango_font_description_set_weight (desc, priv->weight);
+ if (priv->scale_set) {
+ size = pango_font_description_get_size (desc);
+ pango_font_description_set_size (desc, priv->scale * size);
+ }
+ gtk_widget_modify_font (widget, desc);
+
+ pango_font_description_free (desc);
+
+ g_signal_handlers_unblock_by_func (widget, update_entry_font, e);
+}
+
+static void
+update_fonts (UmEditableEntry *e)
+{
+ PangoAttrList *attrs;
+ PangoAttribute *attr;
+ GtkWidget *label;
+
+ UmEditableEntryPrivate *priv = e->priv;
+
+ attrs = pango_attr_list_new ();
+ if (priv->scale_set) {
+ attr = pango_attr_scale_new (priv->scale);
+ pango_attr_list_insert (attrs, attr);
+ }
+ if (priv->weight_set) {
+ attr = pango_attr_weight_new (priv->weight);
+ pango_attr_list_insert (attrs, attr);
+ }
+
+ gtk_label_set_attributes (priv->label, attrs);
+
+ label = gtk_bin_get_child (GTK_BIN (priv->button));
+ gtk_label_set_attributes (GTK_LABEL (label), attrs);
+
+ pango_attr_list_unref (attrs);
+
+ update_entry_font ((GtkWidget *)priv->entry, NULL, e);
+}
+
+void
+um_editable_entry_set_weight (UmEditableEntry *e,
+ gint weight)
+{
+ UmEditableEntryPrivate *priv = e->priv;
+
+ if (priv->weight == weight && priv->weight_set)
+ return;
+
+ priv->weight = weight;
+ priv->weight_set = TRUE;
+
+ update_fonts (e);
+
+ g_object_notify (G_OBJECT (e), "weight");
+ g_object_notify (G_OBJECT (e), "weight-set");
+}
+
+gint
+um_editable_entry_get_weight (UmEditableEntry *e)
+{
+ return e->priv->weight;
+}
+
+void
+um_editable_entry_set_scale (UmEditableEntry *e,
+ gdouble scale)
+{
+ UmEditableEntryPrivate *priv = e->priv;
+
+ if (priv->scale == scale && priv->scale_set)
+ return;
+
+ priv->scale = scale;
+ priv->scale_set = TRUE;
+
+ update_fonts (e);
+
+ g_object_notify (G_OBJECT (e), "scale");
+ g_object_notify (G_OBJECT (e), "scale-set");
+}
+
+gdouble
+um_editable_entry_get_scale (UmEditableEntry *e)
+{
+ return e->priv->scale;
+}
+
+static void
+um_editable_entry_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ UmEditableEntry *e = UM_EDITABLE_ENTRY (object);
+
+ switch (prop_id) {
+ case PROP_TEXT:
+ um_editable_entry_set_text (e, g_value_get_string (value));
+ break;
+ case PROP_EDITABLE:
+ um_editable_entry_set_editable (e, g_value_get_boolean (value));
+ break;
+ case PROP_WEIGHT:
+ um_editable_entry_set_weight (e, g_value_get_int (value));
+ break;
+ case PROP_WEIGHT_SET:
+ e->priv->weight_set = g_value_get_boolean (value);
+ break;
+ case PROP_SCALE:
+ um_editable_entry_set_scale (e, g_value_get_double (value));
+ break;
+ case PROP_SCALE_SET:
+ e->priv->scale_set = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+um_editable_entry_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ UmEditableEntry *e = UM_EDITABLE_ENTRY (object);
+
+ switch (prop_id) {
+ case PROP_TEXT:
+ g_value_set_string (value,
+ um_editable_entry_get_text (e));
+ break;
+ case PROP_EDITABLE:
+ g_value_set_boolean (value,
+ um_editable_entry_get_editable (e));
+ break;
+ case PROP_WEIGHT:
+ g_value_set_int (value,
+ um_editable_entry_get_weight (e));
+ break;
+ case PROP_WEIGHT_SET:
+ g_value_set_boolean (value, e->priv->weight_set);
+ break;
+ case PROP_SCALE:
+ g_value_set_double (value,
+ um_editable_entry_get_scale (e));
+ break;
+ case PROP_SCALE_SET:
+ g_value_set_boolean (value, e->priv->scale_set);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+um_editable_entry_finalize (GObject *object)
+{
+ UmEditableEntry *e = (UmEditableEntry*)object;
+
+ g_free (e->priv->text);
+
+ G_OBJECT_CLASS (um_editable_entry_parent_class)->finalize (object);
+}
+
+static void
+um_editable_entry_class_init (UmEditableEntryClass *class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (class);
+
+ object_class->set_property = um_editable_entry_set_property;
+ object_class->get_property = um_editable_entry_get_property;
+ object_class->finalize = um_editable_entry_finalize;
+
+ signals[EDITING_DONE] =
+ g_signal_new ("editing-done",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (UmEditableEntryClass, editing_done),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_object_class_install_property (object_class, PROP_TEXT,
+ g_param_spec_string ("text",
+ "Text", "The text of the button",
+ NULL,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, PROP_EDITABLE,
+ g_param_spec_boolean ("editable",
+ "Editable", "Whether the text can be edited",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, PROP_WEIGHT,
+ g_param_spec_int ("weight",
+ "Font Weight", "The font weight to use",
+ 0, G_MAXINT, PANGO_WEIGHT_NORMAL,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, PROP_WEIGHT_SET,
+ g_param_spec_boolean ("weight-set",
+ "Font Weight Set", "Whether a font weight is set",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, PROP_SCALE,
+ g_param_spec_double ("scale",
+ "Font Scale", "The font scale to use",
+ 0.0, G_MAXDOUBLE, 1.0,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, PROP_SCALE_SET,
+ g_param_spec_boolean ("scale-set",
+ "Font Scale Set", "Whether a font scale is set",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (class, sizeof (UmEditableEntryPrivate));
+}
+
+static void
+start_editing (UmEditableEntry *e)
+{
+ gtk_notebook_set_current_page (e->priv->notebook, 2);
+}
+
+static void
+stop_editing (UmEditableEntry *e)
+{
+ um_editable_entry_set_text (e, gtk_entry_get_text (e->priv->entry));
+ gtk_notebook_set_current_page (e->priv->notebook, 1);
+ g_signal_emit (e, signals[EDITING_DONE], 0);
+}
+
+static void
+cancel_editing (UmEditableEntry *e)
+{
+ gtk_entry_set_text (e->priv->entry, um_editable_entry_get_text (e));
+ gtk_notebook_set_current_page (e->priv->notebook, 1);
+}
+
+static void
+button_clicked (GtkWidget *widget,
+ UmEditableEntry *e)
+{
+ start_editing (e);
+}
+
+static void
+entry_activated (GtkWidget *widget,
+ UmEditableEntry *e)
+{
+ stop_editing (e);
+}
+
+static gboolean
+entry_focus_out (GtkWidget *widget,
+ GdkEventFocus *event,
+ UmEditableEntry *e)
+{
+ stop_editing (e);
+ return FALSE;
+}
+
+static gboolean
+entry_key_press (GtkWidget *widget,
+ GdkEventKey *event,
+ UmEditableEntry *e)
+{
+ if (event->keyval == GDK_Escape) {
+ cancel_editing (e);
+ }
+ return FALSE;
+}
+
+static void
+update_button_padding (GtkWidget *widget,
+ GtkAllocation *allocation,
+ UmEditableEntry *e)
+{
+ UmEditableEntryPrivate *priv = e->priv;
+ GtkAllocation alloc;
+ gint offset;
+ gint pad;
+
+ gtk_widget_get_allocation (gtk_widget_get_parent (widget), &alloc);
+
+ offset = allocation->x - alloc.x;
+
+ gtk_misc_get_padding (GTK_MISC (priv->label), &pad, NULL);
+ if (offset != pad)
+ gtk_misc_set_padding (GTK_MISC (priv->label), offset, 0);
+}
+
+static void
+um_editable_entry_init (UmEditableEntry *e)
+{
+ UmEditableEntryPrivate *priv;
+
+ priv = e->priv = UM_EDITABLE_ENTRY_GET_PRIVATE (e);
+
+ priv->weight = PANGO_WEIGHT_NORMAL;
+ priv->weight_set = FALSE;
+ priv->scale = 1.0;
+ priv->scale_set = FALSE;
+
+ priv->notebook = (GtkNotebook*)gtk_notebook_new ();
+ gtk_notebook_set_show_tabs (priv->notebook, FALSE);
+ gtk_notebook_set_show_border (priv->notebook, FALSE);
+
+ priv->label = (GtkLabel*)gtk_label_new (EMPTY_TEXT);
+ gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
+ gtk_notebook_append_page (priv->notebook, (GtkWidget*)priv->label, NULL);
+
+ priv->button = (GtkButton*)gtk_button_new_with_label (EMPTY_TEXT);
+ gtk_widget_set_receives_default ((GtkWidget*)priv->button, TRUE);
+ gtk_button_set_relief (priv->button, GTK_RELIEF_NONE);
+ gtk_button_set_alignment (priv->button, 0.0, 0.5);
+ gtk_notebook_append_page (priv->notebook, (GtkWidget*)priv->button, NULL);
+ g_signal_connect (priv->button, "clicked", G_CALLBACK (button_clicked), e);
+
+ priv->entry = (GtkEntry*)gtk_entry_new ();
+ gtk_notebook_append_page (priv->notebook, (GtkWidget*)priv->entry, NULL);
+
+ g_signal_connect (priv->entry, "activate", G_CALLBACK (entry_activated), e);
+ g_signal_connect (priv->entry, "focus-out-event", G_CALLBACK (entry_focus_out), e);
+ g_signal_connect (priv->entry, "key-press-event", G_CALLBACK (entry_key_press), e);
+ g_signal_connect (priv->entry, "style-set", G_CALLBACK (update_entry_font), e);
+ g_signal_connect (gtk_bin_get_child (GTK_BIN (priv->button)), "size-allocate", G_CALLBACK (update_button_padding), e);
+
+ gtk_container_add (GTK_CONTAINER (e), (GtkWidget*)priv->notebook);
+
+ gtk_widget_show ((GtkWidget*)priv->notebook);
+ gtk_widget_show ((GtkWidget*)priv->label);
+ gtk_widget_show ((GtkWidget*)priv->button);
+ gtk_widget_show ((GtkWidget*)priv->entry);
+
+ gtk_notebook_set_current_page (priv->notebook, 0);
+}
+
+GtkWidget *
+um_editable_entry_new (void)
+{
+ return (GtkWidget *) g_object_new (UM_TYPE_EDITABLE_ENTRY, NULL);
+}
diff --git a/src/um-editable-entry.h b/src/um-editable-entry.h
new file mode 100644
index 0000000..1f5f3f4
--- /dev/null
+++ b/src/um-editable-entry.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2009-2010 Red Hat, Inc,
+ *
+ * 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 3 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.
+ *
+ * Written by: Matthias Clasen <mclasen redhat com>
+ */
+
+#ifndef _UM_EDITABLE_ENTRY_H_
+#define _UM_EDITABLE_ENTRY_H_
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define UM_TYPE_EDITABLE_ENTRY um_editable_entry_get_type()
+
+#define UM_EDITABLE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UM_TYPE_EDITABLE_ENTRY, UmEditableEntry))
+#define UM_EDITABLE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UM_TYPE_EDITABLE_ENTRY, UmEditableEntryClass))
+#define UM_IS_EDITABLE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UM_TYPE_EDITABLE_ENTRY))
+#define UM_IS_EDITABLE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UM_TYPE_EDITABLE_ENTRY))
+#define UM_EDITABLE_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UM_TYPE_EDITABLE_ENTRY, UmEditableEntryClass))
+
+typedef struct _UmEditableEntry UmEditableEntry;
+typedef struct _UmEditableEntryClass UmEditableEntryClass;
+typedef struct _UmEditableEntryPrivate UmEditableEntryPrivate;
+
+struct _UmEditableEntry
+{
+ GtkAlignment parent;
+
+ UmEditableEntryPrivate *priv;
+};
+
+struct _UmEditableEntryClass
+{
+ GtkAlignmentClass parent_class;
+
+ void (* editing_done) (UmEditableEntry *entry);
+};
+
+GType um_editable_entry_get_type (void) G_GNUC_CONST;
+GtkWidget *um_editable_entry_new (void);
+void um_editable_entry_set_text (UmEditableEntry *entry,
+ const gchar *text);
+const gchar *um_editable_entry_get_text (UmEditableEntry *entry);
+void um_editable_entry_set_editable (UmEditableEntry *entry,
+ gboolean editable);
+gboolean um_editable_entry_get_editable (UmEditableEntry *entry);
+void um_editable_entry_set_weight (UmEditableEntry *entry,
+ gint weight);
+gint um_editable_entry_get_weight (UmEditableEntry *entry);
+void um_editable_entry_set_scale (UmEditableEntry *entry,
+ gdouble scale);
+gdouble um_editable_entry_get_scale (UmEditableEntry *entry);
+
+G_END_DECLS
+
+#endif /* _UM_EDITABLE_ENTRY_H_ */
diff --git a/src/um-user-panel.c b/src/um-user-panel.c
index e7e7112..83ab051 100644
--- a/src/um-user-panel.c
+++ b/src/um-user-panel.c
@@ -47,6 +47,7 @@
#include "um-strength-bar.h"
#include "um-editable-button.h"
+#include "um-editable-entry.h"
#include "um-editable-combo.h"
#include "um-account-dialog.h"
@@ -454,12 +455,6 @@ delete_user (GtkButton *button, UmUserPanelPrivate *d)
}
-static const char *
-nonempty (const char *str)
-{
- return (str == NULL || str[0] == 0) ? "\xe2\x80\x94" : str;
-}
-
static void
show_user (UmUser *user, UmUserPanelPrivate *d)
{
@@ -483,8 +478,8 @@ show_user (UmUser *user, UmUserPanelPrivate *d)
um_photo_dialog_set_user (d->photo_dialog, user);
- label = get_widget (d, "full-name-button");
- um_editable_button_set_text (UM_EDITABLE_BUTTON (label), um_user_get_real_name (user));
+ label = get_widget (d, "full-name-entry");
+ um_editable_entry_set_text (UM_EDITABLE_ENTRY (label), um_user_get_real_name (user));
gtk_widget_set_tooltip_text (label, um_user_get_user_name (user));
label = get_widget (d, "account-type-combo");
@@ -508,14 +503,12 @@ show_user (UmUser *user, UmUserPanelPrivate *d)
g_assert_not_reached ();
}
}
- label = get_widget (d, "account-password-value-label");
- gtk_label_set_text (GTK_LABEL (label), text);
- label = get_widget (d, "account-password-button-label");
- gtk_label_set_text (GTK_LABEL (label), text);
+ widget = get_widget (d, "account-password-button");
+ um_editable_button_set_text (UM_EDITABLE_BUTTON (widget), text);
text = um_user_get_email (user);
- widget = get_widget (d, "account-email-button");
- um_editable_button_set_text (UM_EDITABLE_BUTTON (widget), text);
+ widget = get_widget (d, "account-email-entry");
+ um_editable_entry_set_text (UM_EDITABLE_ENTRY (widget), text);
widget = get_widget (d, "account-language-combo");
model = um_editable_combo_get_model (UM_EDITABLE_COMBO (widget));
@@ -529,8 +522,8 @@ show_user (UmUser *user, UmUserPanelPrivate *d)
g_free (lang);
text = um_user_get_location (user);
- label = get_widget (d, "account-location-button");
- um_editable_button_set_text (UM_EDITABLE_BUTTON (label), text);
+ label = get_widget (d, "account-location-entry");
+ um_editable_entry_set_text (UM_EDITABLE_ENTRY (label), text);
widget = get_widget (d, "account-fingerprint-notebook");
label = get_widget (d, "account-fingerprint-label");
@@ -566,24 +559,6 @@ selected_user_changed (GtkTreeSelection *selection, UmUserPanelPrivate *d)
}
static void
-name_style_set (GtkWidget *widget, GtkStyle *previous_style, UmUserPanelPrivate *d)
-{
- PangoFontDescription *desc;
- gint size;
-
- desc = pango_font_description_copy (widget->style->font_desc);
- size = pango_font_description_get_size (desc);
- pango_font_description_set_size (desc, 1.2 * size);
- pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
-
- g_signal_handlers_block_by_func (widget, name_style_set, d);
- gtk_widget_modify_font (widget, desc);
- g_signal_handlers_unblock_by_func (widget, name_style_set, d);
-
- pango_font_description_free (desc);
-}
-
-static void
change_name_done (GtkWidget *entry,
UmUserPanelPrivate *d)
{
@@ -592,7 +567,7 @@ change_name_done (GtkWidget *entry,
user = get_selected_user (d);
- text = um_editable_button_get_text (UM_EDITABLE_BUTTON (entry));
+ text = um_editable_entry_get_text (UM_EDITABLE_ENTRY (entry));
if (g_strcmp0 (text, um_user_get_location (user)) != 0) {
um_user_set_real_name (user, text);
}
@@ -602,20 +577,14 @@ static void
account_type_changed (UmEditableCombo *combo,
UmUserPanelPrivate *d)
{
- gint active;
- gint account_type;
UmUser *user;
GtkTreeModel *model;
- GtkTreePath *path;
GtkTreeIter iter;
+ gint account_type;
user = get_selected_user (d);
- active = um_editable_combo_get_active (combo);
-
model = um_editable_combo_get_model (combo);
- gtk_tree_path_new_from_indices (active, -1);
- gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_path_free (path);
+ um_editable_combo_get_active_iter (combo, &iter);
gtk_tree_model_get (model, &iter, 1, &account_type, -1);
if (account_type != um_user_get_account_type (user)) {
@@ -631,7 +600,6 @@ language_response (GtkDialog *dialog,
GtkWidget *combo;
UmUser *user;
gchar *lang;
- const gchar *text;
GtkTreeModel *model;
GtkTreeIter iter;
@@ -731,7 +699,7 @@ change_password (GtkButton *button, UmUserPanelPrivate *d)
}
static void
-change_email_done (UmEditableButton *button,
+change_email_done (UmEditableEntry *e,
UmUserPanelPrivate *d)
{
const gchar *text;
@@ -739,7 +707,7 @@ change_email_done (UmEditableButton *button,
user = get_selected_user (d);
- text = um_editable_button_get_text (button);
+ text = um_editable_entry_get_text (e);
if (g_strcmp0 (text, um_user_get_email (user)) != 0) {
um_user_set_email (user, text);
}
@@ -754,7 +722,7 @@ change_location_done (GtkWidget *entry,
user = get_selected_user (d);
- text = um_editable_button_get_text (UM_EDITABLE_BUTTON (entry));
+ text = um_editable_entry_get_text (UM_EDITABLE_ENTRY (entry));
if (g_strcmp0 (text, um_user_get_location (user)) != 0) {
um_user_set_location (user, text);
}
@@ -775,44 +743,6 @@ change_fingerprint (GtkButton *button, UmUserPanelPrivate *d)
g_object_unref (user);
}
-static void
-toggle_login_options (GtkButton *button, UmUserPanelPrivate *d)
-{
- GtkWidget *widget;
- gboolean active;
- GtkWidget *list;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
- widget = get_widget (d, "top-level-notebook");
- list = get_widget (d, "list-treeview");
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list));
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
- if (active) {
- gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 1);
- gtk_tree_selection_unselect_all (selection);
- }
- else {
- gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 0);
- if (!gtk_tree_selection_get_selected (selection, NULL, NULL)) {
- gtk_tree_model_get_iter_first (model, &iter);
- do {
- gint sort_key;
-
- gtk_tree_model_get (model, &iter, SORT_KEY_COL, &sort_key, -1);
-
- if (sort_key == 1) {
- /* select the current user */
- gtk_tree_selection_select_iter (selection, &iter);
- break;
- }
- } while (gtk_tree_model_iter_next (model, &iter));
- }
- }
-}
-
static gint
sort_users (GtkTreeModel *model,
GtkTreeIter *a,
@@ -973,38 +903,42 @@ lockbutton_changed (PolkitLockButton *button,
gtk_widget_show (get_widget (d, "user-icon-button"));
gtk_widget_hide (get_widget (d, "user-icon-nonbutton"));
- um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "full-name-button")), TRUE);
- remove_unlock_tooltip (get_widget (d, "full-name-button"));
+ um_editable_entry_set_editable (UM_EDITABLE_ENTRY (get_widget (d, "full-name-entry")), TRUE);
+ remove_unlock_tooltip (get_widget (d, "full-name-entry"));
- um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "account-email-button")), TRUE);
- remove_unlock_tooltip (get_widget (d, "account-email-button"));
+ um_editable_entry_set_editable (UM_EDITABLE_ENTRY (get_widget (d, "account-email-entry")), TRUE);
+ remove_unlock_tooltip (get_widget (d, "account-email-entry"));
- um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "account-location-button")), TRUE);
- remove_unlock_tooltip (get_widget (d, "account-location-button"));
+ um_editable_entry_set_editable (UM_EDITABLE_ENTRY (get_widget (d, "account-location-entry")), TRUE);
+ remove_unlock_tooltip (get_widget (d, "account-location-entry"));
um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-language-combo")), TRUE);
remove_unlock_tooltip (get_widget (d, "account-language-combo"));
- gtk_notebook_set_current_page (GTK_NOTEBOOK (get_widget (d, "account-password-notebook")), 1);
+ um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "account-password-button")), TRUE);
+ remove_unlock_tooltip (get_widget (d, "account-password-button"));
+
gtk_notebook_set_current_page (GTK_NOTEBOOK (get_widget (d, "account-fingerprint-notebook")), 1);
}
else {
gtk_widget_hide (get_widget (d, "user-icon-button"));
gtk_widget_show (get_widget (d, "user-icon-nonbutton"));
- um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "full-name-button")), FALSE);
- add_unlock_tooltip (get_widget (d, "full-name-button"));
+ um_editable_entry_set_editable (UM_EDITABLE_ENTRY (get_widget (d, "full-name-entry")), FALSE);
+ add_unlock_tooltip (get_widget (d, "full-name-entry"));
- um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "account-email-button")), FALSE);
- add_unlock_tooltip (get_widget (d, "account-email-button"));
+ um_editable_entry_set_editable (UM_EDITABLE_ENTRY (get_widget (d, "account-email-entry")), FALSE);
+ add_unlock_tooltip (get_widget (d, "account-email-entry"));
- um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "account-location-button")), FALSE);
- add_unlock_tooltip (get_widget (d, "account-location-button"));
+ um_editable_entry_set_editable (UM_EDITABLE_ENTRY (get_widget (d, "account-location-entry")), FALSE);
+ add_unlock_tooltip (get_widget (d, "account-location-entry"));
um_editable_combo_set_editable (UM_EDITABLE_COMBO (get_widget (d, "account-language-combo")), FALSE);
add_unlock_tooltip (get_widget (d, "account-language-combo"));
- gtk_notebook_set_current_page (GTK_NOTEBOOK (get_widget (d, "account-password-notebook")), 0);
+ um_editable_button_set_editable (UM_EDITABLE_BUTTON (get_widget (d, "account-password-button")), FALSE);
+ add_unlock_tooltip (get_widget (d, "account-password-button"));
+
gtk_notebook_set_current_page (GTK_NOTEBOOK (get_widget (d, "account-fingerprint-notebook")), 0);
}
@@ -1111,7 +1045,7 @@ setup_main_window (UmUserPanelPrivate *d)
gtk_widget_style_get (userlist, "expander-size", &expander_size, NULL);
gtk_tree_view_set_level_indentation (GTK_TREE_VIEW (userlist), - (expander_size + 6));
- title = g_strdup_printf ("<small><span foreground=\"#555555\"></span></small>", _("My Account"));
+ title = g_strdup_printf ("<small><span foreground=\"#555555\">%s</span></small>", _("My Account"));
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
TITLE_COL, title,
@@ -1120,7 +1054,7 @@ setup_main_window (UmUserPanelPrivate *d)
-1);
g_free (title);
- title = g_strdup_printf ("<small><span foreground=\"#555555\"></span></small>", _("Other Accounts"));
+ title = g_strdup_printf ("<small><span foreground=\"#555555\">%s</span></small>", _("Other Accounts"));
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
TITLE_COL, title,
@@ -1165,34 +1099,23 @@ setup_main_window (UmUserPanelPrivate *d)
g_signal_connect (button, "button-release-event",
G_CALLBACK (show_tooltip_now), NULL);
- button = get_widget (d, "full-name-button");
- g_signal_connect (button, "editing-done",
- G_CALLBACK (change_name_done), d);
+ button = get_widget (d, "full-name-entry");
+ g_signal_connect (button, "editing-done", G_CALLBACK (change_name_done), d);
button = get_widget (d, "account-type-combo");
g_signal_connect (button, "editing-done", G_CALLBACK (account_type_changed), d);
- button = get_widget (d, "account-password-value-label");
- setup_tooltip_with_embedded_icon (button,
- _("To make changes,\nclick the * icon first"),
- "*",
- "security-medium");
- g_signal_connect (button, "button-release-event",
- G_CALLBACK (show_tooltip_now), NULL);
-
button = get_widget (d, "account-password-button");
- g_signal_connect (button, "clicked", G_CALLBACK (change_password), d);
+ g_signal_connect (button, "start-editing", G_CALLBACK (change_password), d);
- button = get_widget (d, "account-email-button");
- g_signal_connect (button, "editing-done",
- G_CALLBACK (change_email_done), d);
+ button = get_widget (d, "account-email-entry");
+ g_signal_connect (button, "editing-done", G_CALLBACK (change_email_done), d);
button = get_widget (d, "account-language-combo");
g_signal_connect (button, "editing-done", G_CALLBACK (language_changed), d);
- button = get_widget (d, "account-location-button");
- g_signal_connect (button, "editing-done",
- G_CALLBACK (change_location_done), d);
+ button = get_widget (d, "account-location-entry");
+ g_signal_connect (button, "editing-done", G_CALLBACK (change_location_done), d);
button = get_widget (d, "account-fingerprint-button");
g_signal_connect (button, "clicked",
@@ -1236,6 +1159,7 @@ um_user_panel_init (UmUserPanel *self)
/* register types that the builder might need */
type = um_strength_bar_get_type ();
type = um_editable_button_get_type ();
+ type = um_editable_entry_get_type ();
type = um_editable_combo_get_type ();
d->builder = gtk_builder_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]