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
26 * @shortdesc: NamePasswordDialog is a dialog for getting the user name
28 * @longdesc: NamePasswordDialog is a simple dummy dialog for getting
29 * name&password from the user.
40 #include <hildon-name-password-dialog.h>
41 #include <hildon-widgets/hildon-caption.h>
48 #define _(String) dgettext(PACKAGE, String)
50 static GtkDialogClass *parent_class;
52 typedef struct _HildonNamePasswordDialogPrivate
53 HildonNamePasswordDialogPrivate;
55 struct _HildonNamePasswordDialogPrivate {
57 GtkButton *closeButton;
59 GtkLabel *domainLabel;
60 HildonCaption *nameEntry;
61 HildonCaption *passwordEntry;
64 #define HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(o) \
65 (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_NAME_PASSWORD_DIALOG,\
66 HildonNamePasswordDialogPrivate))
76 hildon_name_password_dialog_class_init(HildonNamePasswordDialogClass *class);
77 static void hildon_name_password_dialog_init(HildonNamePasswordDialog *widget);
78 static void hildon_name_password_dialog_set_property(GObject * object,
82 static void hildon_name_password_dialog_get_property(GObject * object,
87 hildon_name_password_dialog_set_property(GObject * object,
89 const GValue * value, GParamSpec * pspec)
91 HildonNamePasswordDialog *dialog = HILDON_NAME_PASSWORD_DIALOG(object);
92 HildonNamePasswordDialogPrivate *priv;
94 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
98 gtk_label_set_text(priv->domainLabel, g_value_get_string(value));
101 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child
104 g_value_get_string(value));
107 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child
109 priv->passwordEntry))),
110 g_value_get_string(value));
113 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
119 hildon_name_password_dialog_get_property(GObject * object,
121 GValue * value, GParamSpec * pspec)
123 HildonNamePasswordDialog *dialog = HILDON_NAME_PASSWORD_DIALOG(object);
124 HildonNamePasswordDialogPrivate *priv;
127 priv = HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
131 string = gtk_label_get_text(priv->domainLabel);
132 g_value_set_string(value, string);
135 string = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child
139 g_value_set_string(value, string);
142 string = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child
144 priv->passwordEntry))));
145 g_value_set_string(value, string);
148 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
153 hildon_name_password_dialog_class_init(HildonNamePasswordDialogClass *class)
155 GObjectClass *object_class = G_OBJECT_CLASS(class);
157 parent_class = g_type_class_peek_parent(class);
159 object_class->set_property = hildon_name_password_dialog_set_property;
160 object_class->get_property = hildon_name_password_dialog_get_property;
163 g_object_class_install_property(object_class,
165 g_param_spec_string ("content",
167 "Set content for content label.",
171 g_object_class_install_property(object_class,
173 g_param_spec_string ("name",
175 "Set content for name entry.",
179 g_object_class_install_property(object_class,
181 g_param_spec_string ("password",
183 "Set content for password entry",
187 g_type_class_add_private(class,
188 sizeof(HildonNamePasswordDialogPrivate));
192 hildon_name_password_dialog_init(HildonNamePasswordDialog * dialog)
194 HildonNamePasswordDialogPrivate *priv =
195 HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
196 GtkSizeGroup *group =
197 GTK_SIZE_GROUP(gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL));
200 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
201 gtk_window_set_title(GTK_WINDOW(dialog), _(HILDON_NAME_PASSWORD_DIALOG_TITLE));
203 priv->domainLabel = GTK_LABEL(gtk_label_new(NULL));
206 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
207 _(HILDON_NAME_PASSWORD_DIALOG_OK),
210 GTK_BUTTON(gtk_dialog_add_button(GTK_DIALOG(dialog),
211 _(HILDON_NAME_PASSWORD_DIALOG_CANCEL),
212 GTK_RESPONSE_CANCEL));
214 control = gtk_entry_new();
215 priv->nameEntry = HILDON_CAPTION(hildon_caption_new
217 _(HILDON_NAME_PASSWORD_DIALOG_NAME ),
219 HILDON_CAPTION_OPTIONAL));
220 hildon_caption_set_separator(priv->nameEntry, "");
222 control = gtk_entry_new();
223 gtk_entry_set_visibility(GTK_ENTRY(control), FALSE);
224 priv->passwordEntry =
225 HILDON_CAPTION(hildon_caption_new(group,
226 _(HILDON_NAME_PASSWORD_DIALOG_PASSWORD),
229 HILDON_CAPTION_OPTIONAL));
230 hildon_caption_set_separator(priv->passwordEntry, "");
232 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
233 GTK_WIDGET(priv->domainLabel), FALSE, FALSE, 0);
234 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
235 GTK_WIDGET(priv->nameEntry), FALSE, FALSE, 0);
236 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
237 GTK_WIDGET(priv->passwordEntry), FALSE, FALSE, 0);
239 gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
240 gtk_widget_show_all(GTK_DIALOG(dialog)->action_area);
241 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
244 GType hildon_name_password_dialog_get_type(void)
246 static GType dialog_type = 0;
249 static const GTypeInfo dialog_info = {
250 sizeof(HildonNamePasswordDialogClass),
251 NULL, /* base_init */
252 NULL, /* base_finalize */
253 (GClassInitFunc) hildon_name_password_dialog_class_init,
254 NULL, /* class_finalize */
255 NULL, /* class_data */
256 sizeof(HildonNamePasswordDialog),
258 (GInstanceInitFunc) hildon_name_password_dialog_init
260 dialog_type = g_type_register_static(GTK_TYPE_DIALOG,
261 "HildonNamePasswordDialog",
269 * hildon_name_password_dialog_new:
270 * @parent: the parent window of the dialog.
272 * Creates a new #HildonNamePasswordDialog widget with Ok and Close
275 * Return value: the newly created #HildonNamePasswordDialog
277 GtkWidget *hildon_name_password_dialog_new(GtkWindow * parent)
279 GtkWidget *self = g_object_new(HILDON_TYPE_NAME_PASSWORD_DIALOG,NULL);
282 gtk_window_set_transient_for(GTK_WINDOW(self), parent);
288 * hildon_name_password_dialog_new_with_default:
289 * @parent: the parent window of the dialog.
290 * @name: default name, nul-terminated string, if you want
291 * to leave it unset, pass a NULL pointer.
292 * @password: default password, nul-terminated string,
293 * if you want to leave it unset, pass a NULL pointer.
295 * Same as #hildon_name_password_dialog_new, but with a
296 * default name and password.
298 * Return value: the newly created #HildonNamePasswordDialog
300 GtkWidget *hildon_name_password_dialog_new_with_default
305 GtkWidget *self = hildon_name_password_dialog_new(parent);
308 g_object_set(G_OBJECT(self), "name", name, NULL);
310 g_object_set(G_OBJECT(self), "password", password, NULL);
316 * hildon_name_password_dialog_get_name:
317 * @dialog: the dialog.
319 * Gets the text that's in the name entry.
321 * Return value: a pointer to the name string.
323 const gchar *hildon_name_password_dialog_get_name(HildonNamePasswordDialog
326 HildonNamePasswordDialogPrivate *priv =
327 HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
328 return gtk_entry_get_text(GTK_ENTRY(
331 priv->nameEntry)))));
335 * hildon_name_password_dialog_get_password:
336 * @dialog: the dialog.
338 * Gets the text that's in the password entry.
340 * Return value: a pointer to the password string.
342 const gchar *hildon_name_password_dialog_get_password(HildonNamePasswordDialog
345 HildonNamePasswordDialogPrivate *priv =
346 HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
347 return gtk_entry_get_text(GTK_ENTRY
350 (priv->passwordEntry)))));
354 * hildon_name_password_dialog_set_domain(GtkWidget *dialog,
355 * @dialog: the dialog
356 * @domain: the domain or some other descriptive text to be set.
358 * sets the optional descriptive text
361 void hildon_name_password_dialog_set_domain(HildonNamePasswordDialog *dialog,
364 HildonNamePasswordDialogPrivate *priv =
365 HILDON_NAME_PASSWORD_DIALOG_GET_PRIVATE(dialog);
366 gtk_label_set_text(priv->domainLabel, domain);