GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dialog-userpass.c
1 /********************************************************************\
2  * dialog-userpass.c -- dialog for username/password entry *
3  * Copyright (C) 2001 Gnumatic, Inc. *
4  * Author: Dave Peticolas <[email protected]> *
5  * *
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public License as *
8  * published by the Free Software Foundation; either version 2 of *
9  * the License, or (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License*
17  * along with this program; if not, contact: *
18  * *
19  * Free Software Foundation Voice: +1-617-542-5942 *
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
21  * Boston, MA 02110-1301, USA [email protected] *
22 \********************************************************************/
23 
24 #include "config.h"
25 #include <gtk/gtk.h>
26 
27 #include "dialog-utils.h"
28 #include "gnc-ui.h"
29 
30 
31 gboolean
32 gnc_get_username_password (GtkWidget *parent,
33  const char *heading,
34  const char *initial_username,
35  const char *initial_password,
36  char **username,
37  char **password)
38 {
39  GtkWidget *dialog;
40  GtkWidget *heading_label;
41  GtkWidget *username_entry;
42  GtkWidget *password_entry;
43  GtkBuilder *builder;
44  gint result;
45 
46  g_return_val_if_fail (username != NULL, FALSE);
47  g_return_val_if_fail (password != NULL, FALSE);
48 
49  builder = gtk_builder_new();
50  gnc_builder_add_from_file (builder, "dialog-userpass.glade", "Username Password Dialog");
51 
52  dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Username Password Dialog"));
53 
54  if (parent)
55  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
56 
57  heading_label = GTK_WIDGET(gtk_builder_get_object (builder, "heading_label"));
58  username_entry = GTK_WIDGET(gtk_builder_get_object (builder, "username_entry"));
59  password_entry = GTK_WIDGET(gtk_builder_get_object (builder, "password_entry"));
60 
61  if (heading)
62  gtk_label_set_text (GTK_LABEL (heading_label), heading);
63 
64  if (initial_username)
65  gtk_entry_set_text (GTK_ENTRY (username_entry), initial_username);
66  gtk_editable_select_region (GTK_EDITABLE (username_entry), 0, -1);
67 
68  if (initial_password)
69  gtk_entry_set_text (GTK_ENTRY (password_entry), initial_password);
70 
71  result = gtk_dialog_run(GTK_DIALOG (dialog));
72  gtk_widget_hide(dialog);
73 
74  if (result == GTK_RESPONSE_OK)
75  {
76  *username = gtk_editable_get_chars (GTK_EDITABLE (username_entry), 0, -1);
77  *password = gtk_editable_get_chars (GTK_EDITABLE (password_entry), 0, -1);
78 
79  gtk_widget_destroy(dialog);
80  return TRUE;
81  }
82 
83  *username = NULL;
84  *password = NULL;
85 
86  g_object_unref(G_OBJECT(builder));
87 
88  gtk_widget_destroy(dialog);
89  return FALSE;
90 }