2 * This file is part of hildon-libs
4 * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
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 ("username",
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 g_object_set (priv->nameEntry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL);
225 caption = HILDON_CAPTION(hildon_caption_new
227 _(HILDON_NAME_PASSWORD_DIALOG_NAME ),
228 GTK_WIDGET(priv->nameEntry), NULL,
229 HILDON_CAPTION_OPTIONAL));
230 hildon_caption_set_separator(caption, "");
231 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
232 GTK_WIDGET(caption), FALSE, FALSE, 0);
234 /* Setup password entry */
235 priv->passwordEntry = GTK_ENTRY(gtk_entry_new());
236 g_object_set (priv->passwordEntry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL);
237 gtk_entry_set_visibility(GTK_ENTRY(priv->passwordEntry), FALSE);
239 HILDON_CAPTION(hildon_caption_new(group,
240 _(HILDON_NAME_PASSWORD_DIALOG_PASSWORD),
241 GTK_WIDGET(priv->passwordEntry),
243 HILDON_CAPTION_OPTIONAL));
244 hildon_caption_set_separator(caption, "");
245 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
246 GTK_WIDGET(caption), FALSE, FALSE, 0);
248 gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
249 gtk_widget_show_all(GTK_DIALOG(dialog)->action_area);
250 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
252 /* Ensure group is freed when all its contents have been removed */
253 g_object_unref(group);
256 GType hildon_name_password_dialog_get_type(void)
258 static GType dialog_type = 0;
261 static const GTypeInfo dialog_info = {
262 sizeof(HildonNamePasswordDialogClass),
263 NULL, /* base_init */
264 NULL, /* base_finalize */
265 (GClassInitFunc) hildon_name_password_dialog_class_init,
266 NULL, /* class_finalize */
267 NULL, /* class_data */
268 sizeof(HildonNamePasswordDialog),
270 (GInstanceInitFunc) hildon_name_password_dialog_init
272 dialog_type = g_type_register_static(GTK_TYPE_DIALOG,
273 "HildonNamePasswordDialog",
281 * hildon_name_password_dialog_new:
282 * @parent: the parent window of the dialog
284 * Creates a new #HildonNamePasswordDialog widget with Ok and Close
287 * Returns: the newly created #HildonNamePasswordDialog
289 GtkWidget *hildon_name_password_dialog_new(GtkWindow * parent)
291 GtkWidget *self = g_object_new(HILDON_TYPE_NAME_PASSWORD_DIALOG,NULL);
294 gtk_window_set_transient_for(GTK_WINDOW(self), parent);
300 * hildon_name_password_dialog_new_with_default:
301 * @parent: the parent window of the dialog
302 * @name: default username, NULL if unset
303 * @password: default password, NULL if unset
305 * Same as #hildon_name_password_dialog_new, but with a
306 * default name and password.
308 * Returns: the newly created #HildonNamePasswordDialog
310 GtkWidget *hildon_name_password_dialog_new_with_default(GtkWindow *parent,
312 const gchar *password)
314 GtkWidget *self = hildon_name_password_dialog_new(parent);
317 g_object_set(G_OBJECT(self), "username", name, NULL);
319 g_object_set(G_OBJECT(self), "password", password, NULL);
325 * hildon_name_password_dialog_get_name:
326 * @dialog: the dialog
328 * Gets the text that's in the name entry.
330 * Returns: a pointer to the name string.
332 const gchar *hildon_name_password_dialog_get_name(HildonNamePasswordDialog
335 HildonNamePasswordDialogPrivate *priv;
337 g_return_val_if_fail(HILDON_IS_NAME_PASSWORD_DIALOG(dialog), NULL);
339 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
341 return gtk_entry_get_text(priv->nameEntry);
345 * hildon_name_password_dialog_get_password:
346 * @dialog: the dialog
348 * Gets the text that's in the password entry.
350 * Returns: a pointer to the password string
352 const gchar *hildon_name_password_dialog_get_password(HildonNamePasswordDialog
355 HildonNamePasswordDialogPrivate *priv;
357 g_return_val_if_fail(HILDON_IS_NAME_PASSWORD_DIALOG(dialog), NULL);
359 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
361 return gtk_entry_get_text(priv->passwordEntry);
365 * hildon_name_password_dialog_set_domain(GtkWidget *dialog,
366 * @dialog: the dialog
367 * @domain: the domain or some other descriptive text to be set
369 * sets the optional descriptive text
372 void hildon_name_password_dialog_set_domain(HildonNamePasswordDialog *dialog,
375 HildonNamePasswordDialogPrivate *priv;
377 g_return_if_fail(HILDON_IS_NAME_PASSWORD_DIALOG(dialog));
379 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
380 gtk_label_set_text(priv->domainLabel, domain);