2 * This file is part of hildon-libs
4 * Copyright (C) 2005, 2006 Nokia Corporation.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-name-password-dialog
27 * @short_description: A widget which allows a user to enter an username
29 * @see_also: #HildonGetPasswordDialog, #HildonSetPasswordDialog
31 * #HildonNamePasswordDialog is used to enter a username and password
32 * when accessing a password protected function. The widget performs no
33 * input checking and is used only for retrieving a user name and a
45 #include <hildon-name-password-dialog.h>
46 #include <hildon-widgets/hildon-caption.h>
53 #define _(String) dgettext(PACKAGE, String)
55 static GtkDialogClass *parent_class;
57 typedef struct _HildonNamePasswordDialogPrivate
58 HildonNamePasswordDialogPrivate;
60 struct _HildonNamePasswordDialogPrivate {
62 GtkButton *closeButton;
64 GtkLabel *domainLabel;
66 GtkEntry *passwordEntry;
69 /* Macro to access the private data of the object instance */
70 #define HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(o) \
71 (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_NAME_PASSWORD_DIALOG,\
72 HildonNamePasswordDialogPrivate))
82 hildon_name_password_dialog_class_init(HildonNamePasswordDialogClass *class);
83 static void hildon_name_password_dialog_init(HildonNamePasswordDialog *widget);
84 static void hildon_name_password_dialog_set_property(GObject * object,
88 static void hildon_name_password_dialog_get_property(GObject * object,
94 hildon_name_password_dialog_set_property(GObject * object,
96 const GValue * value, GParamSpec * pspec)
98 HildonNamePasswordDialog *dialog = NULL;
99 HildonNamePasswordDialogPrivate *priv = NULL;
101 dialog = HILDON_NAME_PASSWORD_DIALOG(object);
102 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
106 /* Set the password domain text */
107 hildon_name_password_dialog_set_domain(dialog, g_value_get_string(value));
110 /* Set the current username displayed in the dialog */
111 gtk_entry_set_text(priv->nameEntry, g_value_get_string(value));
114 /* Set the currently entered password */
115 gtk_entry_set_text(priv->passwordEntry, g_value_get_string(value));
118 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
124 hildon_name_password_dialog_get_property(GObject * object,
126 GValue * value, GParamSpec * pspec)
128 HildonNamePasswordDialog *dialog = NULL;
129 HildonNamePasswordDialogPrivate *priv = NULL;
131 dialog = HILDON_NAME_PASSWORD_DIALOG(object);
132 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
136 g_value_set_string(value, gtk_label_get_text(priv->domainLabel));
139 g_value_set_string(value, hildon_name_password_dialog_get_name(dialog));
142 g_value_set_string(value, hildon_name_password_dialog_get_password(dialog));
145 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
151 hildon_name_password_dialog_class_init(HildonNamePasswordDialogClass *class)
153 GObjectClass *object_class = G_OBJECT_CLASS(class);
155 parent_class = g_type_class_peek_parent(class);
157 /* Override virtual functions */
158 object_class->set_property = hildon_name_password_dialog_set_property;
159 object_class->get_property = hildon_name_password_dialog_get_property;
161 /* Install new properties */
162 g_object_class_install_property(object_class,
164 g_param_spec_string ("content",
166 "Set content for content label.",
170 g_object_class_install_property(object_class,
172 g_param_spec_string ("name",
174 "Set content for name entry.",
178 g_object_class_install_property(object_class,
180 g_param_spec_string ("password",
182 "Set content for password entry",
186 /* Install private data structure */
187 g_type_class_add_private(class,
188 sizeof(HildonNamePasswordDialogPrivate));
192 hildon_name_password_dialog_init(HildonNamePasswordDialog * dialog)
194 /* Access private structure */
195 HildonNamePasswordDialogPrivate *priv =
196 HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
198 /* Size group for captions */
199 GtkSizeGroup *group =
200 GTK_SIZE_GROUP(gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL));
201 HildonCaption *caption;
203 /* Initialize dialog */
204 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
205 gtk_window_set_title(GTK_WINDOW(dialog), _(HILDON_NAME_PASSWORD_DIALOG_TITLE));
207 /* Optional domain name label */
208 priv->domainLabel = GTK_LABEL(gtk_label_new(NULL));
209 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
210 GTK_WIDGET(priv->domainLabel), FALSE, FALSE, 0);
214 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
215 _(HILDON_NAME_PASSWORD_DIALOG_OK),
218 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
219 _(HILDON_NAME_PASSWORD_DIALOG_CANCEL),
220 GTK_RESPONSE_CANCEL));
222 /* Setup user name entry */
223 priv->nameEntry = GTK_ENTRY(gtk_entry_new());
224 caption = HILDON_CAPTION(hildon_caption_new
226 _(HILDON_NAME_PASSWORD_DIALOG_NAME ),
227 GTK_WIDGET(priv->nameEntry), NULL,
228 HILDON_CAPTION_OPTIONAL));
229 hildon_caption_set_separator(caption, "");
230 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
231 GTK_WIDGET(caption), FALSE, FALSE, 0);
233 /* Setup password entry */
234 priv->passwordEntry = GTK_ENTRY(gtk_entry_new());
235 gtk_entry_set_visibility(GTK_ENTRY(priv->passwordEntry), FALSE);
237 HILDON_CAPTION(hildon_caption_new(group,
238 _(HILDON_NAME_PASSWORD_DIALOG_PASSWORD),
239 GTK_WIDGET(priv->passwordEntry),
241 HILDON_CAPTION_OPTIONAL));
242 hildon_caption_set_separator(caption, "");
243 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
244 GTK_WIDGET(caption), FALSE, FALSE, 0);
246 gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
247 gtk_widget_show_all(GTK_DIALOG(dialog)->action_area);
248 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
250 /* Ensure group is freed when all its contents have been removed */
251 g_object_unref(group);
254 GType hildon_name_password_dialog_get_type(void)
256 static GType dialog_type = 0;
259 static const GTypeInfo dialog_info = {
260 sizeof(HildonNamePasswordDialogClass),
261 NULL, /* base_init */
262 NULL, /* base_finalize */
263 (GClassInitFunc) hildon_name_password_dialog_class_init,
264 NULL, /* class_finalize */
265 NULL, /* class_data */
266 sizeof(HildonNamePasswordDialog),
268 (GInstanceInitFunc) hildon_name_password_dialog_init
270 dialog_type = g_type_register_static(GTK_TYPE_DIALOG,
271 "HildonNamePasswordDialog",
279 * hildon_name_password_dialog_new:
280 * @parent: the parent window of the dialog
282 * Creates a new #HildonNamePasswordDialog widget with Ok and Close
285 * Returns: the newly created #HildonNamePasswordDialog
287 GtkWidget *hildon_name_password_dialog_new(GtkWindow * parent)
289 GtkWidget *self = g_object_new(HILDON_TYPE_NAME_PASSWORD_DIALOG,NULL);
292 gtk_window_set_transient_for(GTK_WINDOW(self), parent);
298 * hildon_name_password_dialog_new_with_default:
299 * @parent: the parent window of the dialog
300 * @name: default name, NULL if unset
301 * @password: default password, NULL if unset
303 * Same as #hildon_name_password_dialog_new, but with a
304 * default name and password.
306 * Returns: the newly created #HildonNamePasswordDialog
308 GtkWidget *hildon_name_password_dialog_new_with_default(GtkWindow *parent,
310 const gchar *password)
312 GtkWidget *self = hildon_name_password_dialog_new(parent);
315 g_object_set(G_OBJECT(self), "name", name, NULL);
317 g_object_set(G_OBJECT(self), "password", password, NULL);
323 * hildon_name_password_dialog_get_name:
324 * @dialog: the dialog
326 * Gets the text that's in the name entry.
328 * Returns: a pointer to the name string.
330 const gchar *hildon_name_password_dialog_get_name(HildonNamePasswordDialog
333 HildonNamePasswordDialogPrivate *priv;
335 g_return_val_if_fail(HILDON_IS_NAME_PASSWORD_DIALOG(dialog), NULL);
337 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
339 return gtk_entry_get_text(priv->nameEntry);
343 * hildon_name_password_dialog_get_password:
344 * @dialog: the dialog
346 * Gets the text that's in the password entry.
348 * Returns: a pointer to the password string
350 const gchar *hildon_name_password_dialog_get_password(HildonNamePasswordDialog
353 HildonNamePasswordDialogPrivate *priv;
355 g_return_val_if_fail(HILDON_IS_NAME_PASSWORD_DIALOG(dialog), NULL);
357 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
359 return gtk_entry_get_text(priv->passwordEntry);
363 * hildon_name_password_dialog_set_domain(GtkWidget *dialog,
364 * @dialog: the dialog
365 * @domain: the domain or some other descriptive text to be set
367 * sets the optional descriptive text
370 void hildon_name_password_dialog_set_domain(HildonNamePasswordDialog *dialog,
373 HildonNamePasswordDialogPrivate *priv;
375 g_return_if_fail(HILDON_IS_NAME_PASSWORD_DIALOG(dialog));
377 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
378 gtk_label_set_text(priv->domainLabel, domain);