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,
101 /* Private functions */
103 hildon_get_password_set_property(GObject * object,
105 const GValue * value, GParamSpec * pspec)
107 HildonGetPasswordDialog *dialog = HILDON_GET_PASSWORD_DIALOG(object);
108 HildonGetPasswordDialogPrivate *priv;
110 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
113 case PROP_DOMAIN: /* Implemented othervise, here just for completeness */
114 gtk_label_set_text(priv->domainLabel, g_value_get_string(value));
117 gtk_entry_set_text(GTK_ENTRY
118 (gtk_bin_get_child(GTK_BIN(priv->passwordEntry))),
119 g_value_get_string(value));
121 case PROP_NUMBERS_ONLY:
122 g_object_set( G_OBJECT
123 (gtk_bin_get_child(GTK_BIN(priv->passwordEntry))),
124 "input-mode", HILDON_INPUT_MODE_HINT_NUMERIC, NULL );
127 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
133 hildon_get_password_get_property(GObject * object,
135 GValue * value, GParamSpec * pspec)
137 HildonGetPasswordDialog *dialog = HILDON_GET_PASSWORD_DIALOG(object);
138 HildonGetPasswordDialogPrivate *priv;
141 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
145 string = gtk_label_get_text(priv->domainLabel);
146 g_value_set_string(value, string);
148 string = gtk_entry_get_text(GTK_ENTRY(priv->passwordEntry));
149 g_value_set_string(value, string);
152 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
157 hildon_get_password_dialog_class_init(HildonGetPasswordDialogClass * class)
160 GObjectClass *object_class = G_OBJECT_CLASS(class);
162 parent_class = g_type_class_peek_parent(class);
164 object_class->set_property = hildon_get_password_set_property;
165 object_class->get_property = hildon_get_password_get_property;
167 g_object_class_install_property
170 g_param_spec_string ("domain",
172 "Set domain(content) for optional label.",
177 g_object_class_install_property
180 g_param_spec_string ("password",
182 "Set content for password entry",
186 g_object_class_install_property
189 g_param_spec_boolean ("numbers_only",
191 "Set entry to accept only numeric values",
195 g_type_class_add_private(class,
196 sizeof(HildonGetPasswordDialogPrivate));
200 hildon_get_password_dialog_init(HildonGetPasswordDialog * dialog)
202 GtkSizeGroup * group;
205 HildonGetPasswordDialogPrivate *priv =
206 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
207 group = GTK_SIZE_GROUP(gtk_size_group_new
208 (GTK_SIZE_GROUP_HORIZONTAL));
210 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
212 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
215 gtk_window_set_title(GTK_WINDOW(dialog),
216 _(HILDON_GET_PASSWORD_DIALOG_TITLE));
218 priv->domainLabel = GTK_LABEL(gtk_label_new(NULL));
221 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
222 _(HILDON_GET_PASSWORD_DIALOG_OK),
225 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
226 _(HILDON_GET_PASSWORD_DIALOG_CANCEL),
227 GTK_RESPONSE_CANCEL));
229 control = gtk_entry_new();
230 gtk_entry_set_visibility(GTK_ENTRY(control), FALSE);
231 priv->passwordEntry = HILDON_CAPTION
232 (hildon_caption_new(group,
233 _(HILDON_GET_PASSWORD_DIALOG_PASSWORD ),
235 HILDON_CAPTION_OPTIONAL));
236 hildon_caption_set_separator(HILDON_CAPTION(priv->passwordEntry), "");
238 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
239 GTK_WIDGET(priv->domainLabel), FALSE, FALSE, 0);
240 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
241 GTK_WIDGET(priv->passwordEntry), FALSE, FALSE, 0);
242 gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
244 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
248 /* Public functions */
251 * hildon_get_password_dialog_get_type:
253 * Returns GType for HildonGetPasswordDialog as produced by
254 * g_type_register_static().
256 * Return value: HildonGetPasswordDialog type
258 GType hildon_get_password_dialog_get_type()
260 static GType dialog_type = 0;
263 static const GTypeInfo dialog_info = {
264 sizeof(HildonGetPasswordDialogClass),
265 NULL, /* base_init */
266 NULL, /* base_finalize */
267 (GClassInitFunc) hildon_get_password_dialog_class_init,
268 NULL, /* class_finalize */
269 NULL, /* class_data */
270 sizeof(HildonGetPasswordDialog),
272 (GInstanceInitFunc) hildon_get_password_dialog_init
275 dialog_type = g_type_register_static(GTK_TYPE_DIALOG,
276 "HildonGetPasswordDialog",
283 * hildon_get_password_dialog_new:
284 * @parent: parent window; can be NULL
285 * @get_old_password_title: FALSE creates a new get password dialog and
286 * TRUE creates a new get old password dialog
288 * Construct a new HildonGetPasswordDialog.
290 * Return value: a new #GtkWidget of type HildonGetPasswordDialog
292 GtkWidget *hildon_get_password_dialog_new(GtkWindow * parent,
293 gboolean get_old_password_title)
295 HildonGetPasswordDialog *dialog = g_object_new
296 (HILDON_TYPE_GET_PASSWORD_DIALOG,
299 if (get_old_password_title == FALSE) {
300 HildonGetPasswordDialogPrivate *priv;
301 gtk_window_set_title(GTK_WINDOW(dialog),
302 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_TITLE));
303 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
304 gtk_button_set_label(priv->okButton,
305 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_OK));
306 gtk_button_set_label(priv->cancelButton,
307 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_CANCEL));
308 hildon_caption_set_label(priv->passwordEntry,
309 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_PASSWORD)
311 } /* The other logical strings are set in class init */
313 if (parent != NULL) {
314 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
317 return GTK_WIDGET(dialog);
321 * hildon_get_password_dialog_new:
322 * @parent: parent window; can be NULL
323 * @password: a default password to be shown in password field.
324 * @get_old_password_title: FALSE creates a new get password dialog and
325 * TRUE creates a new get old password dialog
327 * Same as #hildon_get_password_dialog_new but with a default password
330 * Return value: a new #GtkWidget of type HildonGetPasswordDialog
332 GtkWidget *hildon_get_password_dialog_new_with_default (GtkWindow * parent,
334 gboolean get_old_password_title)
338 dialog = hildon_get_password_dialog_new(parent, get_old_password_title);
340 g_object_set(G_OBJECT(dialog), "password", password, NULL);
342 return GTK_WIDGET(dialog);
346 * hildon_get_password_dialog_get_password:
347 * @dialog: pointer to HildonSetPasswordDialog
349 * Gets the currently inputted password.
351 * Return value: current password ( if the dialog is successfully
352 * accepted with 'OK' )
355 *hildon_get_password_dialog_get_password(HildonGetPasswordDialog *
361 HildonGetPasswordDialogPrivate *priv;
363 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
365 entry1 = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(
366 priv->passwordEntry)));
368 text1 = GTK_ENTRY(entry1)->text;
374 * hildon_get_password_dialog_set_domain(GtkWidget *dialog,
375 * @dialog: the dialog
376 * @domain: the domain or some other descriptive text to be set.
378 * sets the optional descriptive text
381 void hildon_get_password_dialog_set_domain(HildonGetPasswordDialog *dialog,
384 HildonGetPasswordDialogPrivate *priv =
385 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
386 gtk_label_set_text(priv->domainLabel, domain);
391 * hildon_get_password_dialog_set_dialog_title
392 * (HildonGetPasswordDialog *dialog, gchar *new_title)
393 * @dialog: the dialog
394 * @new_ title: the text to be set as the dialog title.
396 * sets the dialog title
398 void hildon_get_password_dialog_set_title(HildonGetPasswordDialog *dialog,
402 g_return_if_fail (new_title !=NULL);
403 gtk_window_set_title(GTK_WINDOW(dialog),
409 * hildon_get_password_dialog_set_caption_label
410 * (HildonGetPasswordDialog *dialog, gchar *new_caption)
411 * @dialog: the dialog
412 * @new_caption: the text to be set as the caption label.
414 * sets the password entry field's neigbouring label.
418 void hildon_get_password_dialog_set_caption(HildonGetPasswordDialog *dialog,
423 HildonGetPasswordDialogPrivate *priv =
424 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
425 g_return_if_fail (new_caption !=NULL);
426 hildon_caption_set_label(priv->passwordEntry, new_caption);
431 * hildon_get_password_dialog_set_max_characters
432 * (HildonGetPasswordDialog *dialog, gint max_characters,
433 * gchar *error_ib_message)
434 * @dialog: the dialog
435 * @max_characters: the maximum number of characters the password dialog
437 * @new_caption: the text to be set as the caption label.
439 * sets the password entry field's neigbouring label.
442 void hildon_get_password_dialog_set_max_characters (HildonGetPasswordDialog *dialog, gint max_characters )
445 HildonGetPasswordDialogPrivate *priv =
446 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
448 g_return_if_fail(max_characters >0);
449 g_return_if_fail(dialog);
451 gtk_entry_set_max_length(GTK_ENTRY
452 (hildon_caption_get_control
453 (priv->passwordEntry)),
456 g_signal_connect(GTK_ENTRY
457 (hildon_caption_get_control
458 (priv->passwordEntry)),
460 G_CALLBACK(_invalid_input),
466 static void _invalid_input(GtkWidget *widget, GtkInvalidInputType reason,
469 if (reason==GTK_INVALID_INPUT_MAX_CHARS_REACHED) {
470 gtk_infoprint(GTK_WINDOW(widget), _(HILDON_GET_PASSWORD_DIALOG_MAX_CHARS));