aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog8
-rw-r--r--e-util/Makefile.am2
-rw-r--r--e-util/e-passwords.c144
-rw-r--r--e-util/e-passwords.h10
4 files changed, 68 insertions, 96 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index e8da4f498d..8fa6a15d03 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,11 @@
+2002-11-12 Chris Toshok <toshok@ximian.com>
+
+ * Makefile.am
+ (eutilinclude_HEADERS): add e-password.h
+ (libeutil_la_SOURCES): add e-password.c
+
+ * e-passwords.[ch]: port this to gnome2's gnome-config-private.
+
2002-11-11 Ettore Perazzoli <ettore@ximian.com>
* e-config-listener.c (add_key): g_strdup() the value in the case
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index ef5a012da7..4a1b42d9dc 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -36,6 +36,7 @@ eutilinclude_HEADERS = \
e-memory.h \
e-mktemp.h \
e-msgport.h \
+ e-passwords.h \
e-path.h \
e-proxy.h \
e-request.h \
@@ -64,6 +65,7 @@ libeutil_la_SOURCES = \
e-memory.c \
e-mktemp.c \
e-msgport.c \
+ e-passwords.c \
e-path.c \
e-proxy.c \
e-request.c \
diff --git a/e-util/e-passwords.c b/e-util/e-passwords.c
index 7d5f25a545..48acd6297b 100644
--- a/e-util/e-passwords.c
+++ b/e-util/e-passwords.c
@@ -27,22 +27,15 @@
#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 <libgnome/gnome-i18n.h>
#include <gtk/gtkentry.h>
+#include <gtk/gtkbox.h>
#include <gtk/gtkcheckbutton.h>
-#include <bonobo-conf/bonobo-config-database.h>
-#include <bonobo/bonobo-object.h>
-#include <bonobo/bonobo-moniker-util.h>
-#include <bonobo/bonobo-exception.h>
+#include <gtk/gtkmessagedialog.h>
static char *decode_base64 (char *base64);
-Bonobo_ConfigDatabase db;
static GHashTable *passwords = NULL;
static char *component_name = NULL;
@@ -58,24 +51,7 @@ static int base64_encode_step(unsigned char *in, int len, gboolean break_lines,
void
e_passwords_init (const char *component)
{
- CORBA_Environment ev;
-
- /* open up our bonobo config database */
- CORBA_exception_init (&ev);
- db = bonobo_get_object ("wombat-private:", "Bonobo/ConfigDatabase", &ev);
-
- if (BONOBO_EX (&ev) || db == CORBA_OBJECT_NIL) {
- char *err;
- g_error ("Very serious error, cannot activate private config database '%s'",
- (err = bonobo_exception_get_text (&ev)));
- g_free (err);
- CORBA_exception_free (&ev);
- return;
- }
-
- CORBA_exception_free (&ev);
-
- /* and create the per-session hash table */
+ /* create the per-session hash table */
passwords = g_hash_table_new (g_str_hash, g_str_equal);
component_name = g_strdup (component);
@@ -98,14 +74,8 @@ free_entry (gpointer key, gpointer value, gpointer user_data)
void
e_passwords_shutdown ()
{
- CORBA_Environment ev;
-
- /* sync our db work */
- CORBA_exception_init (&ev);
- Bonobo_ConfigDatabase_sync (db, &ev);
- bonobo_object_release_unref (db, &ev);
- CORBA_exception_free (&ev);
- db = NULL;
+ /* shouldn't need this really - everything is synchronous */
+ gnome_config_private_sync_file ("/Evolution");
/* and destroy our per session hash */
g_hash_table_foreach_remove (passwords, free_entry, NULL);
@@ -125,13 +95,8 @@ e_passwords_shutdown ()
void
e_passwords_forget_passwords ()
{
- CORBA_Environment ev;
-
- /* remove all the persistent passwords */
- CORBA_exception_init (&ev);
- Bonobo_ConfigDatabase_removeDir (db, "/Passwords", &ev);
- Bonobo_ConfigDatabase_sync (db, &ev);
- CORBA_exception_free (&ev);
+ gnome_config_private_clean_section ("/Evolution/Passwords");
+ gnome_config_private_sync_file ("/Evolution");
/* free up the session passwords */
g_hash_table_foreach_remove (passwords, free_entry, NULL);
@@ -145,15 +110,12 @@ e_passwords_forget_passwords ()
void
e_passwords_clear_component_passwords ()
{
- CORBA_Environment ev;
char *path;
- path = g_strdup_printf ("/Passwords/%s", component_name);
+ path = g_strdup_printf ("/Evolution/Passwords-%s", component_name);
- CORBA_exception_init (&ev);
- Bonobo_ConfigDatabase_removeDir (db, path, &ev);
- Bonobo_ConfigDatabase_sync (db, &ev);
- CORBA_exception_free (&ev);
+ gnome_config_private_clean_section (path);
+ gnome_config_private_sync_file ("/Evolution");
g_free (path);
}
@@ -161,15 +123,17 @@ e_passwords_clear_component_passwords ()
static char *
password_path (const char *key)
{
- int len, state, save;
- char *key64, *path;
+ char *keycopy, *path;
+ int i;
+ keycopy = g_strdup (key);
- len = strlen (key);
- key64 = g_malloc0 ((len + 2) * 4 / 3 + 1);
- state = save = 0;
- base64_encode_close ((char*)key, len, FALSE, key64, &state, &save);
- path = g_strdup_printf ("/Passwords/%s/%s", component_name, key64);
- g_free (key64);
+ for (i = 0; i < strlen (keycopy); i ++)
+ if (keycopy[i] == '/' || keycopy[i] =='=')
+ keycopy[i] = '_';
+
+ path = g_strdup_printf ("/Evolution/Passwords-%s/%s", component_name, keycopy);
+
+ g_free (keycopy);
return path;
}
@@ -198,7 +162,9 @@ e_passwords_remember_password (const char *key)
state = save = 0;
base64_encode_close (value, len, FALSE, pass64, &state, &save);
- bonobo_config_set_string (db, path, pass64, NULL);
+ printf ("remembering password for (%s): %s\n", path, pass64);
+
+ gnome_config_private_set_string (path, pass64);
g_free (path);
g_free (pass64);
@@ -206,6 +172,8 @@ e_passwords_remember_password (const char *key)
g_hash_table_remove (passwords, key);
g_free (okey);
g_free (value);
+
+ gnome_config_private_sync_file ("/Evolution");
}
/**
@@ -218,7 +186,6 @@ void
e_passwords_forget_password (const char *key)
{
gpointer okey, value;
- CORBA_Environment ev;
char *path;
if (g_hash_table_lookup_extended (passwords, key, &okey, &value)) {
@@ -230,9 +197,8 @@ e_passwords_forget_password (const char *key)
/* clear it in the on disk db */
path = password_path (key);
- CORBA_exception_init (&ev);
- Bonobo_ConfigDatabase_removeValue (db, path, &ev);
- CORBA_exception_free (&ev);
+ gnome_config_private_clean_key (path);
+ gnome_config_private_sync_file ("/Evolution");
g_free (path);
}
@@ -247,24 +213,20 @@ char *
e_passwords_get_password (const char *key)
{
char *path, *passwd = g_hash_table_lookup (passwords, key);
- CORBA_Environment ev;
- char *encoded;
+ char *encoded = NULL;
if (passwd)
return g_strdup (passwd);
/* not part of the session hash, look it up in the on disk db */
path = password_path (key);
+
+ encoded = gnome_config_private_get_string_with_default (path, NULL);
- /* We need to pass an ev to bonobo-conf, or it will emit a
- * g_warning if the data isn't found.
- */
- CORBA_exception_init (&ev);
- encoded = bonobo_config_get_string (db, path, &ev);
- CORBA_exception_free (&ev);
+ printf ("getting password for (%s): %s\n", path, encoded);
g_free (path);
-
+
if (!encoded)
return NULL;
@@ -301,6 +263,12 @@ e_passwords_add_password (const char *key, const char *passwd)
}
+static void
+entry_activate (GtkEntry *entry, GtkDialog *dialog)
+{
+ gtk_dialog_response (dialog, GTK_RESPONSE_OK);
+}
+
/**
* e_passwords_ask_password:
* @title: title for the password dialog
@@ -330,30 +298,30 @@ e_passwords_ask_password (const char *title, const char *key,
GtkWidget *dialog;
GtkWidget *check = NULL, *entry;
char *password;
- int button;
+ int response;
+
+ dialog = gtk_message_dialog_new (parent,
+ 0,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_OK_CANCEL,
+ prompt);
- 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);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
/* 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),
+ gtk_box_pack_start (GTK_BOX (GTK_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));
+ g_signal_connect (entry, "activate",
+ G_CALLBACK (entry_activate), dialog);
/* Remember the password? */
if (remember_type != E_PASSWORDS_DO_NOT_REMEMBER) {
@@ -367,15 +335,14 @@ e_passwords_ask_password (const char *title, const char *key,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
*remember);
- gtk_box_pack_end (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
+ gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox),
check, TRUE, FALSE, 4);
gtk_widget_show (check);
}
- gtk_widget_show (dialog);
- button = gnome_dialog_run (GNOME_DIALOG (dialog));
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
- if (button == 0) {
+ if (response == GTK_RESPONSE_OK) {
password = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
if (remember_type != E_PASSWORDS_DO_NOT_REMEMBER) {
*remember = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
@@ -388,7 +355,8 @@ e_passwords_ask_password (const char *title, const char *key,
} else
password = NULL;
- gnome_dialog_close (GNOME_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
return password;
}
diff --git a/e-util/e-passwords.h b/e-util/e-passwords.h
index aad7e8569c..12d087fe97 100644
--- a/e-util/e-passwords.h
+++ b/e-util/e-passwords.h
@@ -24,13 +24,9 @@
#define _E_PASSWORD_H_
#include <glib.h>
-#include <bonobo/bonobo-ui-component.h>
#include <gtk/gtkwindow.h>
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus */
+G_BEGIN_DECLS
void e_passwords_init (const char *component);
void e_passwords_shutdown (void);
@@ -54,8 +50,6 @@ char * e_passwords_ask_password (const char *title, const char *key,
gboolean *remember,
GtkWindow *parent);
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+G_END_DECLS
#endif /* _E_PASSWORD_H_ */