2 * This file is part of hildon-libs
4 * Copyright (C) 2005 Nokia Corporation.
6 * Contact: Luc Pionchon <luc.pionchon@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; either version 2.1 of
11 * the License, or (at your option) any later version.
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
27 * @shortdesc: GetPasswordDialog is a dialog for getting the user
29 * @longdesc: GetPasswordDialog implements two specified dialogs,
30 * which are pretty much functionally the same, but have
42 #include <hildon-lgpl/hildon-widgets/gtk-infoprint.h>
43 #include <hildon-lgpl/hildon-widgets/hildon-input-mode-hint.h>
45 #include <hildon-widgets/hildon-caption.h>
46 #include <hildon-widgets/hildon-get-password-dialog.h>
53 #define _(String) dgettext(PACKAGE, String)
55 static GtkDialogClass * parent_class;
57 typedef struct _HildonGetPasswordDialogPrivate
58 HildonGetPasswordDialogPrivate;
60 struct _HildonGetPasswordDialogPrivate {
62 GtkButton *cancelButton;
64 GtkLabel *domainLabel;
65 HildonCaption *passwordEntry;
69 #define HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(obj) \
70 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
71 HILDON_TYPE_GET_PASSWORD_DIALOG, HildonGetPasswordDialogPrivate));
74 hildon_get_password_dialog_class_init(HildonGetPasswordDialogClass *
77 static void hildon_get_password_dialog_init(HildonGetPasswordDialog *
80 static void hildon_get_password_set_property(GObject * object,
84 static void hildon_get_password_get_property(GObject * object,
85 guint prop_id, GValue * value,
88 void hildon_get_password_dialog_set_domain(HildonGetPasswordDialog *dialog,
91 static void _invalid_input(GtkWidget *widget, GtkInvalidInputType reason,
103 /* Private functions */
105 hildon_get_password_set_property(GObject * object,
107 const GValue * value, GParamSpec * pspec)
109 HildonGetPasswordDialog *dialog = HILDON_GET_PASSWORD_DIALOG(object);
110 HildonGetPasswordDialogPrivate *priv;
112 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
115 case PROP_DOMAIN: /* Implemented othervise, here just for completeness */
116 gtk_label_set_text(priv->domainLabel, g_value_get_string(value));
119 gtk_entry_set_text(GTK_ENTRY
120 (gtk_bin_get_child(GTK_BIN(priv->passwordEntry))),
121 g_value_get_string(value));
123 case PROP_NUMBERS_ONLY:
124 g_object_set( G_OBJECT
125 (gtk_bin_get_child(GTK_BIN(priv->passwordEntry))),
126 "input-mode", HILDON_INPUT_MODE_HINT_NUMERIC, NULL );
128 case PROP_CAPTION_LABEL:
129 hildon_get_password_dialog_set_caption(dialog, g_value_get_string(value));
132 hildon_get_password_dialog_set_max_characters(dialog,
133 g_value_get_string(value));
136 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
142 hildon_get_password_get_property(GObject * object,
144 GValue * value, GParamSpec * pspec)
146 HildonGetPasswordDialog *dialog = HILDON_GET_PASSWORD_DIALOG(object);
147 HildonGetPasswordDialogPrivate *priv;
151 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
155 string = gtk_label_get_text(priv->domainLabel);
156 g_value_set_string(value, string);
158 string = gtk_entry_get_text(GTK_ENTRY(priv->passwordEntry));
159 g_value_set_string(value, string);
161 case PROP_CAPTION_LABEL:
162 string = hildon_caption_get_label(priv->passwordEntry);
163 g_value_set_string(value, string);
166 max_length = gtk_entry_get_max_length(
167 GTK_ENTRY (hildon_caption_get_control (priv->passwordEntry)));
168 g_value_set_int(value, max_length);
171 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
177 hildon_get_password_dialog_class_init(HildonGetPasswordDialogClass * class)
180 GObjectClass *object_class = G_OBJECT_CLASS(class);
182 parent_class = g_type_class_peek_parent(class);
184 object_class->set_property = hildon_get_password_set_property;
185 object_class->get_property = hildon_get_password_get_property;
187 g_object_class_install_property
190 g_param_spec_string ("domain",
192 "Set domain(content) for optional label.",
197 g_object_class_install_property
200 g_param_spec_string ("password",
202 "Set content for password entry",
206 g_object_class_install_property
209 g_param_spec_boolean ("numbers_only",
211 "Set entry to accept only numeric values",
215 g_object_class_install_property
218 g_param_spec_string ("caption-label",
220 "The text to be set as the caption label",
224 g_object_class_install_property
227 g_param_spec_int ("max-characters",
228 "Maximum Characters",
229 "The maximum number of characters the password"
236 g_type_class_add_private(class,
237 sizeof(HildonGetPasswordDialogPrivate));
241 hildon_get_password_dialog_init(HildonGetPasswordDialog * dialog)
243 GtkSizeGroup * group;
246 HildonGetPasswordDialogPrivate *priv =
247 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
248 group = GTK_SIZE_GROUP(gtk_size_group_new
249 (GTK_SIZE_GROUP_HORIZONTAL));
251 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
253 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
256 gtk_window_set_title(GTK_WINDOW(dialog),
257 _(HILDON_GET_PASSWORD_DIALOG_TITLE));
259 priv->domainLabel = GTK_LABEL(gtk_label_new(NULL));
262 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
263 _(HILDON_GET_PASSWORD_DIALOG_OK),
266 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
267 _(HILDON_GET_PASSWORD_DIALOG_CANCEL),
268 GTK_RESPONSE_CANCEL));
270 control = gtk_entry_new();
271 gtk_entry_set_visibility(GTK_ENTRY(control), FALSE);
272 priv->passwordEntry = HILDON_CAPTION
273 (hildon_caption_new(group,
274 _(HILDON_GET_PASSWORD_DIALOG_PASSWORD ),
276 HILDON_CAPTION_OPTIONAL));
277 hildon_caption_set_separator(HILDON_CAPTION(priv->passwordEntry), "");
279 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
280 GTK_WIDGET(priv->domainLabel), FALSE, FALSE, 0);
281 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
282 GTK_WIDGET(priv->passwordEntry), FALSE, FALSE, 0);
283 gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
285 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
289 /* Public functions */
292 * hildon_get_password_dialog_get_type:
294 * Returns GType for HildonGetPasswordDialog as produced by
295 * g_type_register_static().
297 * Return value: HildonGetPasswordDialog type
299 GType hildon_get_password_dialog_get_type()
301 static GType dialog_type = 0;
304 static const GTypeInfo dialog_info = {
305 sizeof(HildonGetPasswordDialogClass),
306 NULL, /* base_init */
307 NULL, /* base_finalize */
308 (GClassInitFunc) hildon_get_password_dialog_class_init,
309 NULL, /* class_finalize */
310 NULL, /* class_data */
311 sizeof(HildonGetPasswordDialog),
313 (GInstanceInitFunc) hildon_get_password_dialog_init
316 dialog_type = g_type_register_static(GTK_TYPE_DIALOG,
317 "HildonGetPasswordDialog",
324 * hildon_get_password_dialog_new:
325 * @parent: parent window; can be NULL
326 * @get_old_password_title: FALSE creates a new get password dialog and
327 * TRUE creates a new get old password dialog
329 * Construct a new HildonGetPasswordDialog.
331 * Return value: a new #GtkWidget of type HildonGetPasswordDialog
333 GtkWidget *hildon_get_password_dialog_new(GtkWindow * parent,
334 gboolean get_old_password_title)
336 HildonGetPasswordDialog *dialog = g_object_new
337 (HILDON_TYPE_GET_PASSWORD_DIALOG,
340 if (get_old_password_title == FALSE) {
341 HildonGetPasswordDialogPrivate *priv;
342 gtk_window_set_title(GTK_WINDOW(dialog),
343 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_TITLE));
344 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
345 gtk_button_set_label(priv->okButton,
346 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_OK));
347 gtk_button_set_label(priv->cancelButton,
348 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_CANCEL));
349 hildon_caption_set_label(priv->passwordEntry,
350 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_PASSWORD)
352 } /* The other logical strings are set in class init */
354 if (parent != NULL) {
355 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
358 return GTK_WIDGET(dialog);
362 * hildon_get_password_dialog_new:
363 * @parent: parent window; can be NULL
364 * @password: a default password to be shown in password field.
365 * @get_old_password_title: FALSE creates a new get password dialog and
366 * TRUE creates a new get old password dialog
368 * Same as #hildon_get_password_dialog_new but with a default password
371 * Return value: a new #GtkWidget of type HildonGetPasswordDialog
373 GtkWidget *hildon_get_password_dialog_new_with_default (GtkWindow * parent,
375 gboolean get_old_password_title)
379 dialog = hildon_get_password_dialog_new(parent, get_old_password_title);
381 g_object_set(G_OBJECT(dialog), "password", password, NULL);
383 return GTK_WIDGET(dialog);
387 * hildon_get_password_dialog_get_password:
388 * @dialog: pointer to HildonSetPasswordDialog
390 * Gets the currently inputted password.
392 * Return value: current password ( if the dialog is successfully
393 * accepted with 'OK' )
396 *hildon_get_password_dialog_get_password(HildonGetPasswordDialog *
402 HildonGetPasswordDialogPrivate *priv;
404 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
406 entry1 = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(
407 priv->passwordEntry)));
409 text1 = GTK_ENTRY(entry1)->text;
415 * hildon_get_password_dialog_set_domain(GtkWidget *dialog,
416 * @dialog: the dialog
417 * @domain: the domain or some other descriptive text to be set.
419 * sets the optional descriptive text
422 void hildon_get_password_dialog_set_domain(HildonGetPasswordDialog *dialog,
425 HildonGetPasswordDialogPrivate *priv =
426 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
427 gtk_label_set_text(priv->domainLabel, domain);
432 * hildon_get_password_dialog_set_dialog_title
433 * (HildonGetPasswordDialog *dialog, gchar *new_title)
434 * @dialog: the dialog
435 * @new_ title: the text to be set as the dialog title.
437 * sets the dialog title
439 void hildon_get_password_dialog_set_title(HildonGetPasswordDialog *dialog,
443 g_return_if_fail (new_title !=NULL);
444 gtk_window_set_title(GTK_WINDOW(dialog),
450 * hildon_get_password_dialog_set_caption
451 * (HildonGetPasswordDialog *dialog, gchar *new_caption)
452 * @dialog: the dialog
453 * @new_caption: the text to be set as the caption label.
455 * sets the password entry field's neigbouring label.
459 void hildon_get_password_dialog_set_caption(HildonGetPasswordDialog *dialog,
464 HildonGetPasswordDialogPrivate *priv =
465 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
466 g_return_if_fail (new_caption !=NULL);
467 hildon_caption_set_label(priv->passwordEntry, new_caption);
472 * hildon_get_password_dialog_set_max_characters
473 * (HildonGetPasswordDialog *dialog, gint max_characters,
474 * gchar *error_ib_message)
475 * @dialog: the dialog
476 * @max_characters: the maximum number of characters the password dialog
478 * @new_caption: the text to be set as the caption label.
480 * sets the password entry field's neigbouring label.
483 void hildon_get_password_dialog_set_max_characters (HildonGetPasswordDialog *dialog, gint max_characters )
486 HildonGetPasswordDialogPrivate *priv =
487 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
489 g_return_if_fail(max_characters >0);
490 g_return_if_fail(dialog);
492 gtk_entry_set_max_length(GTK_ENTRY
493 (hildon_caption_get_control
494 (priv->passwordEntry)),
497 g_signal_connect(GTK_ENTRY
498 (hildon_caption_get_control
499 (priv->passwordEntry)),
501 G_CALLBACK(_invalid_input),
507 static void _invalid_input(GtkWidget *widget, GtkInvalidInputType reason,
510 if (reason==GTK_INVALID_INPUT_MAX_CHARS_REACHED) {
511 gtk_infoprint(GTK_WINDOW(widget), _(HILDON_GET_PASSWORD_DIALOG_MAX_CHARS));