aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-10-02 00:27:02 +0800
committerDan Winship <danw@src.gnome.org>2001-10-02 00:27:02 +0800
commitd74b078aeb365e099c2070ce2269c98ab6158f6f (patch)
treebc96e1c91384147d9400fad30385aa933adeebff
parentb0dd4c8d2aa8575f7e7df36be60378ed4ed6c20b (diff)
downloadgsoc2013-evolution-d74b078aeb365e099c2070ce2269c98ab6158f6f.tar
gsoc2013-evolution-d74b078aeb365e099c2070ce2269c98ab6158f6f.tar.gz
gsoc2013-evolution-d74b078aeb365e099c2070ce2269c98ab6158f6f.tar.bz2
gsoc2013-evolution-d74b078aeb365e099c2070ce2269c98ab6158f6f.tar.lz
gsoc2013-evolution-d74b078aeb365e099c2070ce2269c98ab6158f6f.tar.xz
gsoc2013-evolution-d74b078aeb365e099c2070ce2269c98ab6158f6f.tar.zst
gsoc2013-evolution-d74b078aeb365e099c2070ce2269c98ab6158f6f.zip
New, copied/renamed from mailer and gnome-libs.
* e-passwords.c (e_passwords_ask_password): New, copied/renamed from mailer and gnome-libs. svn path=/trunk/; revision=13261
-rw-r--r--e-util/ChangeLog5
-rw-r--r--e-util/e-passwords.c102
-rw-r--r--e-util/e-passwords.h14
3 files changed, 121 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 98b7a75de9..39ecbff390 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,8 @@
+2001-10-01 Dan Winship <danw@ximian.com>
+
+ * e-passwords.c (e_passwords_ask_password): New, copied/renamed
+ from mailer and gnome-libs.
+
2001-09-30 Chris Toshok <toshok@ximian.com>
* Makefile.am (libeutil_la_SOURCES): add e-passwords.[ch]
diff --git a/e-util/e-passwords.c b/e-util/e-passwords.c
index c1de3fc44e..f9c8780180 100644
--- a/e-util/e-passwords.c
+++ b/e-util/e-passwords.c
@@ -23,8 +23,19 @@
* USA.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include "e-passwords.h"
+#include <libgnome/gnome-defs.h>
+#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-config.h>
+#include <libgnomeui/gnome-dialog.h>
+#include <libgnomeui/gnome-messagebox.h>
+#include <libgnomeui/gnome-stock.h>
+#include <gtk/gtkentry.h>
+#include <gtk/gtkcheckbutton.h>
static char *decode_base64 (char *base64);
@@ -138,6 +149,97 @@ e_passwords_add_password (const char *key, const char *passwd)
g_hash_table_insert (passwords, (gpointer)key, (gpointer)passwd);
}
+
+/**
+ * e_passwords_ask_password:
+ * @title: title for the password dialog
+ * @key: key to store the password under
+ * @prompt: prompt string
+ * @secret: whether or not the password text should be ***ed out
+ * @remember_type: whether or not to offer to remember the password,
+ * and for how long.
+ * @remember: on input, the default state of the remember checkbox.
+ * on output, the state of the checkbox when the dialog was closed.
+ * @parent: parent window of the dialog, or %NULL
+ *
+ * Asks the user for a password.
+ *
+ * Return value: the password, or %NULL if the user cancelled the
+ * operation. *@remember will be set if the return value is non-%NULL
+ * and @remember_type is not E_PASSWORDS_DO_NOT_REMEMBER.
+ **/
+char *
+e_passwords_ask_password (const char *title, const char *key,
+ const char *prompt, gboolean secret,
+ EPasswordsRememberType remember_type,
+ gboolean *remember,
+ GtkWindow *parent)
+{
+ GtkWidget *dialog;
+ GtkWidget *check, *entry;
+ char *password;
+ int button;
+
+ dialog = gnome_message_box_new (prompt, GNOME_MESSAGE_BOX_QUESTION,
+ GNOME_STOCK_BUTTON_OK,
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL);
+ gtk_window_set_title (GTK_WINDOW (dialog), title);
+ if (parent)
+ gnome_dialog_set_parent (GNOME_DIALOG (dialog), parent);
+ gnome_dialog_set_default (GNOME_DIALOG (dialog), 0);
+ gnome_dialog_set_close (GNOME_DIALOG (dialog), FALSE);
+
+ /* Password entry */
+ entry = gtk_entry_new();
+ if (secret)
+ gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
+
+ gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
+ entry, FALSE, FALSE, 4);
+ gtk_widget_show (entry);
+ gtk_widget_grab_focus (entry);
+
+ /* If Return is pressed in the text entry, propagate to the buttons */
+ gnome_dialog_editable_enters (GNOME_DIALOG(dialog), GTK_EDITABLE(entry));
+
+ /* Remember the password? */
+ if (remember_type != E_PASSWORDS_DO_NOT_REMEMBER) {
+ const char *label;
+
+ if (remember_type == E_PASSWORDS_REMEMBER_FOREVER)
+ label = _("Remember this password");
+ else
+ label = _("Remember this password for the remainder of this session");
+ check = gtk_check_button_new_with_label (label);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
+ *remember);
+
+ gtk_box_pack_end (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
+ check, TRUE, FALSE, 4);
+ gtk_widget_show (check);
+ }
+
+ gtk_widget_show (dialog);
+ button = gnome_dialog_run (GNOME_DIALOG (dialog));
+
+ if (button == 0) {
+ password = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
+ *remember = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+ if (*remember || remember_type == E_PASSWORDS_REMEMBER_FOREVER)
+ e_passwords_add_password (key, password);
+ if (*remember && remember_type == E_PASSWORDS_REMEMBER_FOREVER)
+ e_passwords_remember_password (key);
+ } else
+ password = NULL;
+
+ gnome_dialog_close (GNOME_DIALOG (dialog));
+ return password;
+}
+
+
+
static char *base64_alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
diff --git a/e-util/e-passwords.h b/e-util/e-passwords.h
index 7b675b964e..9bc0de6540 100644
--- a/e-util/e-passwords.h
+++ b/e-util/e-passwords.h
@@ -26,6 +26,7 @@
#include <glib.h>
#include <bonobo/bonobo-ui-component.h>
+#include <gtk/gtkwindow.h>
#ifdef __cplusplus
extern "C" {
@@ -34,12 +35,25 @@ extern "C" {
void e_passwords_init (void);
void e_passwords_shutdown (void);
+
void e_passwords_remember_password (const char *key);
void e_passwords_add_password (const char *key, const char *passwd);
const char *e_passwords_get_password (const char *key);
void e_passwords_forget_password (const char *key);
void e_passwords_forget_passwords (void);
+typedef enum {
+ E_PASSWORDS_DO_NOT_REMEMBER,
+ E_PASSWORDS_REMEMBER_FOR_SESSION,
+ E_PASSWORDS_REMEMBER_FOREVER
+} EPasswordsRememberType;
+
+char * e_passwords_ask_password (const char *title, const char *key,
+ const char *prompt, gboolean secret,
+ EPasswordsRememberType remember_type,
+ gboolean *remember,
+ GtkWindow *parent);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */