GnuCash  5.6-150-g038405b370+
dialog-userpass.c
1 /********************************************************************\
2  * dialog-userpass.c -- dialog for username/password entry *
3  * Copyright (C) 2001 Gnumatic, Inc. *
4  * Author: Dave Peticolas <dave@krondo.com> *
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 gnu@gnu.org *
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  // Set the name for this dialog so it can be easily manipulated with css
55  gtk_widget_set_name (GTK_WIDGET(dialog), "gnc-id-user-password");
56 
57  if (parent)
58  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
59 
60  heading_label = GTK_WIDGET(gtk_builder_get_object (builder, "heading_label"));
61  username_entry = GTK_WIDGET(gtk_builder_get_object (builder, "username_entry"));
62  password_entry = GTK_WIDGET(gtk_builder_get_object (builder, "password_entry"));
63 
64  if (heading)
65  gtk_label_set_text (GTK_LABEL (heading_label), heading);
66 
67  if (initial_username)
68  gtk_entry_set_text (GTK_ENTRY (username_entry), initial_username);
69  gtk_editable_select_region (GTK_EDITABLE (username_entry), 0, -1);
70 
71  if (initial_password)
72  gtk_entry_set_text (GTK_ENTRY (password_entry), initial_password);
73 
74  result = gtk_dialog_run(GTK_DIALOG (dialog));
75  gtk_widget_hide(dialog);
76 
77  if (result == GTK_RESPONSE_OK)
78  {
79  *username = gtk_editable_get_chars (GTK_EDITABLE (username_entry), 0, -1);
80  *password = gtk_editable_get_chars (GTK_EDITABLE (password_entry), 0, -1);
81 
82  gtk_widget_destroy(dialog);
83  return TRUE;
84  }
85 
86  *username = NULL;
87  *password = NULL;
88 
89  g_object_unref(G_OBJECT(builder));
90 
91  gtk_widget_destroy(dialog);
92  return FALSE;
93 }