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>
44 #include <hildon-widgets/hildon-caption.h>
45 #include <hildon-widgets/hildon-get-password-dialog.h>
52 #define _(String) dgettext(PACKAGE, String)
54 static GtkDialogClass * parent_class;
56 typedef struct _HildonGetPasswordDialogPrivate
57 HildonGetPasswordDialogPrivate;
59 struct _HildonGetPasswordDialogPrivate {
61 GtkButton *cancelButton;
63 GtkLabel *domainLabel;
64 HildonCaption *passwordEntry;
68 #define HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(obj) \
69 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
70 HILDON_TYPE_GET_PASSWORD_DIALOG, HildonGetPasswordDialogPrivate));
73 hildon_get_password_dialog_class_init(HildonGetPasswordDialogClass *
76 static void hildon_get_password_dialog_init(HildonGetPasswordDialog *
79 static void hildon_get_password_set_property(GObject * object,
83 static void hildon_get_password_get_property(GObject * object,
84 guint prop_id, GValue * value,
87 void hildon_get_password_dialog_set_domain(HildonGetPasswordDialog *dialog,
90 static void _invalid_input(GtkWidget *widget, GtkInvalidInputType reason,
99 /* Private functions */
101 hildon_get_password_set_property(GObject * object,
103 const GValue * value, GParamSpec * pspec)
105 HildonGetPasswordDialog *dialog = HILDON_GET_PASSWORD_DIALOG(object);
106 HildonGetPasswordDialogPrivate *priv;
108 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
111 case PROP_DOMAIN: /* Implemented othervise, here just for completeness */
112 gtk_label_set_text(priv->domainLabel, g_value_get_string(value));
115 gtk_entry_set_text(GTK_ENTRY
116 (gtk_bin_get_child(GTK_BIN(priv->passwordEntry))),
117 g_value_get_string(value));
120 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
126 hildon_get_password_get_property(GObject * object,
128 GValue * value, GParamSpec * pspec)
130 HildonGetPasswordDialog *dialog = HILDON_GET_PASSWORD_DIALOG(object);
131 HildonGetPasswordDialogPrivate *priv;
134 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
138 string = gtk_label_get_text(priv->domainLabel);
139 g_value_set_string(value, string);
141 string = gtk_entry_get_text(GTK_ENTRY(priv->passwordEntry));
142 g_value_set_string(value, string);
145 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
150 hildon_get_password_dialog_class_init(HildonGetPasswordDialogClass * class)
153 GObjectClass *object_class = G_OBJECT_CLASS(class);
155 parent_class = g_type_class_peek_parent(class);
157 object_class->set_property = hildon_get_password_set_property;
158 object_class->get_property = hildon_get_password_get_property;
160 g_object_class_install_property
163 g_param_spec_string ("domain",
165 "Set domain(content) for optional label.",
170 g_object_class_install_property
173 g_param_spec_string ("password",
175 "Set content for password entry",
179 g_type_class_add_private(class,
180 sizeof(HildonGetPasswordDialogPrivate));
184 hildon_get_password_dialog_init(HildonGetPasswordDialog * dialog)
186 GtkSizeGroup * group;
189 HildonGetPasswordDialogPrivate *priv =
190 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
191 group = GTK_SIZE_GROUP(gtk_size_group_new
192 (GTK_SIZE_GROUP_HORIZONTAL));
194 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
196 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
199 gtk_window_set_title(GTK_WINDOW(dialog),
200 _(HILDON_GET_PASSWORD_DIALOG_TITLE));
202 priv->domainLabel = GTK_LABEL(gtk_label_new(NULL));
205 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
206 _(HILDON_GET_PASSWORD_DIALOG_OK),
209 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
210 _(HILDON_GET_PASSWORD_DIALOG_CANCEL),
211 GTK_RESPONSE_CANCEL));
213 control = gtk_entry_new();
214 gtk_entry_set_visibility(GTK_ENTRY(control), FALSE);
215 priv->passwordEntry = HILDON_CAPTION
216 (hildon_caption_new(group,
217 _(HILDON_GET_PASSWORD_DIALOG_PASSWORD ),
219 HILDON_CAPTION_OPTIONAL));
220 hildon_caption_set_separator(HILDON_CAPTION(priv->passwordEntry), "");
222 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
223 GTK_WIDGET(priv->domainLabel), FALSE, FALSE, 0);
224 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
225 GTK_WIDGET(priv->passwordEntry), FALSE, FALSE, 0);
226 gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
228 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
232 /* Public functions */
235 * hildon_get_password_dialog_get_type:
237 * Returns GType for HildonGetPasswordDialog as produced by
238 * g_type_register_static().
240 * Return value: HildonGetPasswordDialog type
242 GType hildon_get_password_dialog_get_type()
244 static GType dialog_type = 0;
247 static const GTypeInfo dialog_info = {
248 sizeof(HildonGetPasswordDialogClass),
249 NULL, /* base_init */
250 NULL, /* base_finalize */
251 (GClassInitFunc) hildon_get_password_dialog_class_init,
252 NULL, /* class_finalize */
253 NULL, /* class_data */
254 sizeof(HildonGetPasswordDialog),
256 (GInstanceInitFunc) hildon_get_password_dialog_init
259 dialog_type = g_type_register_static(GTK_TYPE_DIALOG,
260 "HildonGetPasswordDialog",
267 * hildon_get_password_dialog_new:
268 * @parent: parent window; can be NULL
269 * @get_old_password_title: FALSE creates a new get password dialog and
270 * TRUE creates a new get old password dialog
272 * Construct a new HildonGetPasswordDialog.
274 * Return value: a new #GtkWidget of type HildonGetPasswordDialog
276 GtkWidget *hildon_get_password_dialog_new(GtkWindow * parent,
277 gboolean get_old_password_title)
279 HildonGetPasswordDialog *dialog = g_object_new
280 (HILDON_TYPE_GET_PASSWORD_DIALOG,
283 if (get_old_password_title == FALSE) {
284 HildonGetPasswordDialogPrivate *priv;
285 gtk_window_set_title(GTK_WINDOW(dialog),
286 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_TITLE));
287 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
288 gtk_button_set_label(priv->okButton,
289 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_OK));
290 gtk_button_set_label(priv->cancelButton,
291 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_CANCEL));
292 hildon_caption_set_label(priv->passwordEntry,
293 _(HILDON_GET_PASSWORD_VERIFY_DIALOG_PASSWORD)
295 } /* The other logical strings are set in class init */
297 if (parent != NULL) {
298 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
301 return GTK_WIDGET(dialog);
305 * hildon_get_password_dialog_new:
306 * @parent: parent window; can be NULL
307 * @password: a default password to be shown in password field.
308 * @get_old_password_title: FALSE creates a new get password dialog and
309 * TRUE creates a new get old password dialog
311 * Same as #hildon_get_password_dialog_new but with a default password
314 * Return value: a new #GtkWidget of type HildonGetPasswordDialog
316 GtkWidget *hildon_get_password_dialog_new_with_default (GtkWindow * parent,
318 gboolean get_old_password_title)
322 dialog = hildon_get_password_dialog_new(parent, get_old_password_title);
324 g_object_set(G_OBJECT(dialog), "password", password, NULL);
326 return GTK_WIDGET(dialog);
330 * hildon_get_password_dialog_get_password:
331 * @dialog: pointer to HildonSetPasswordDialog
333 * Gets the currently inputted password.
335 * Return value: current password ( if the dialog is successfully
336 * accepted with 'OK' )
339 *hildon_get_password_dialog_get_password(HildonGetPasswordDialog *
345 HildonGetPasswordDialogPrivate *priv;
347 priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
349 entry1 = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(
350 priv->passwordEntry)));
352 text1 = GTK_ENTRY(entry1)->text;
358 * hildon_get_password_dialog_set_domain(GtkWidget *dialog,
359 * @dialog: the dialog
360 * @domain: the domain or some other descriptive text to be set.
362 * sets the optional descriptive text
365 void hildon_get_password_dialog_set_domain(HildonGetPasswordDialog *dialog,
368 HildonGetPasswordDialogPrivate *priv =
369 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
370 gtk_label_set_text(priv->domainLabel, domain);
375 * hildon_get_password_dialog_set_dialog_title
376 * (HildonGetPasswordDialog *dialog, gchar *new_title)
377 * @dialog: the dialog
378 * @new_ title: the text to be set as the dialog title.
380 * sets the dialog title
382 void hildon_get_password_dialog_set_title(HildonGetPasswordDialog *dialog,
386 g_return_if_fail (new_title !=NULL);
387 gtk_window_set_title(GTK_WINDOW(dialog),
393 * hildon_get_password_dialog_set_caption_label
394 * (HildonGetPasswordDialog *dialog, gchar *new_caption)
395 * @dialog: the dialog
396 * @new_caption: the text to be set as the caption label.
398 * sets the password entry field's neigbouring label.
402 void hildon_get_password_dialog_set_caption(HildonGetPasswordDialog *dialog,
407 HildonGetPasswordDialogPrivate *priv =
408 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
409 g_return_if_fail (new_caption !=NULL);
410 hildon_caption_set_label(priv->passwordEntry, new_caption);
415 * hildon_get_password_dialog_set_max_characters
416 * (HildonGetPasswordDialog *dialog, gint max_characters,
417 * gchar *error_ib_message)
418 * @dialog: the dialog
419 * @max_characters: the maximum number of characters the password dialog
421 * @new_caption: the text to be set as the caption label.
423 * sets the password entry field's neigbouring label.
426 void hildon_get_password_dialog_set_max_characters (HildonGetPasswordDialog *dialog, gint max_characters )
429 HildonGetPasswordDialogPrivate *priv =
430 HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(dialog);
432 g_return_if_fail(max_characters >0);
433 g_return_if_fail(dialog);
435 gtk_entry_set_max_length(GTK_ENTRY
436 (hildon_caption_get_control
437 (priv->passwordEntry)),
440 g_signal_connect(GTK_ENTRY
441 (hildon_caption_get_control
442 (priv->passwordEntry)),
444 G_CALLBACK(_invalid_input),
450 static void _invalid_input(GtkWidget *widget, GtkInvalidInputType reason,
453 if (reason==GTK_INVALID_INPUT_MAX_CHARS_REACHED) {
454 gtk_infoprint(GTK_WINDOW(widget), _(HILDON_GET_PASSWORD_DIALOG_MAX_CHARS));