Patch to use gnome-config
- From: Peter Williams <peter newton cx>
- To: balsa-list gnome org
- cc: dsp rci rutgers edu, pavlov pavlov net, bapm camoes rnl ist utl pt
- Subject: Patch to use gnome-config
- Date: Mon, 4 Oct 1999 20:41:34 -0400 (EDT)
This should do it. There are still a few things to be worked out:
* Should I be using global config variables so that the Balsa
configuration is always the same?
* IMAP and POP3 seem to save and load correctly but are not known
to work.
* There's an infrastructure for session management but not much
there (particularly, I'd like Balsa to remember what desktop
it's on... does anyone know how to do this?)
* I have yet to whale on the code to make sure it's clean and
happy.
==============================
Peter Williams peter@newton.cx
diff -u --recursive balsa/libbalsa/mailbox.c balsa-new/libbalsa/mailbox.c
--- balsa/libbalsa/mailbox.c Sun Sep 26 17:14:37 1999
+++ balsa-new/libbalsa/mailbox.c Sun Oct 3 14:43:19 1999
@@ -358,6 +341,9 @@
mailbox->messages = 0;
mailbox->new_messages = 0;
mailbox->message_list = NULL;
+
+ /*PKGW*/
+ mailbox->config_serial = config_next_serial();
return mailbox;
}
diff -u --recursive balsa/libbalsa/mailbox.h balsa-new/libbalsa/mailbox.h
--- balsa/libbalsa/mailbox.h Sun Sep 26 17:14:37 1999
+++ balsa-new/libbalsa/mailbox.h Sun Oct 3 14:41:45 1999
@@ -140,6 +140,8 @@
glong unread_messages; /* number of unread messages in the mailbox */
glong total_messages; /* total number of messages in the mailbox */
+ /*PKGW -- serial number for config file.*/
+ guint32 config_serial;
};
diff -u --recursive balsa/libmutt/mbox.c balsa-new/libmutt/mbox.c
--- balsa/libmutt/mbox.c Sun Sep 6 13:54:19 1998
+++ balsa-new/libmutt/mbox.c Sun Aug 15 17:13:37 1999
@@ -212,6 +212,10 @@
struct utimbuf newtime;
#endif
+ /*PKGW*/
+ int dummy_message;
+ /*PKGW*/
+
/* Save information about the folder at the time we opened it. */
if (stat (ctx->path, &sb) == -1)
{
@@ -238,11 +242,19 @@
date received */
tz = mutt_local_tz ();
+ /*PKGW*/
+ dummy_message = 0;
+ /*PKGW*/
+
loc = ftell (ctx->fp);
while (fgets (buf, sizeof (buf), ctx->fp) != NULL)
{
if ((t = is_from (buf, return_path, sizeof (return_path))))
{
+ /*PKGW*/
+ dummy_message = 0;
+ /*PKGW*/
+
/* Save the Content-Length of the previous message */
if (count > 0)
{
@@ -350,9 +362,20 @@
lines = 0;
}
- else
- lines++;
-
+ else {
+ /*PKGW*/
+ if( !dummy_message ) {
+#define MARKER "X-IMAP: "
+ if( strncmp( buf, MARKER, strlen( MARKER ) ) == 0 ) {
+ mutt_free_header( curhdr );
+ ctx->msgcount--;
+ dummy_message = 0;
+ } else {
+ /*PKGW*/
+ lines++;
+ }
+ }
+ }
loc = ftell (ctx->fp);
}
diff -u --recursive balsa/src/balsa-app.h balsa-new/src/balsa-app.h
--- balsa/src/balsa-app.h Sat Jul 31 15:23:15 1999
+++ balsa-new/src/balsa-app.h Sun Oct 3 16:05:47 1999
@@ -20,7 +20,6 @@
#define __BALSA_APP_H__
#include <gnome.h>
-#include <proplist.h>
#include "mailbox.h"
#include "balsa-mblist.h"
#include "index-child.h"
@@ -46,7 +45,7 @@
/* global balsa application structure */
extern struct BalsaApplication
{
- proplist_t proplist;
+/* proplist_t proplist;*/
/* personal information */
Address *address;
gchar *replyto;
diff -u --recursive balsa/src/balsa-mblist.c balsa-new/src/balsa-mblist.c
--- balsa/src/balsa-mblist.c Sat Jul 31 15:23:15 1999
+++ balsa-new/src/balsa-mblist.c Sun Aug 15 18:35:47 1999
@@ -258,6 +258,10 @@
{
GtkCTreeNode *ctnode;
gchar *text[1];
+
+ if( mblist == NULL || mailbox == NULL )
+ return;
+
text[0] = mailbox->name;
ctnode = gtk_ctree_insert_node (GTK_CTREE (mblist),
NULL, NULL, text, 5,
diff -u --recursive balsa/src/local-mailbox.c balsa-new/src/local-mailbox.c
--- balsa/src/local-mailbox.c Sat Jul 31 15:23:15 1999
+++ balsa-new/src/local-mailbox.c Sun Oct 3 16:41:00 1999
@@ -252,6 +252,9 @@
{
DIR *dp;
struct dirent *d;
+
+ /*Duplicates mailboxes!*/
+ return;
dp = opendir (balsa_app.local_mail_directory);
if (!dp)
diff -u --recursive balsa/src/mailbox-conf.c balsa-new/src/mailbox-conf.c
--- balsa/src/mailbox-conf.c Sat Jul 31 15:23:15 1999
+++ balsa-new/src/mailbox-conf.c Sun Oct 3 14:57:38 1999
@@ -200,7 +200,10 @@
}
}
/* Delete it from the config file and internal nodes */
+ /*PKGW
config_mailbox_delete (mailbox->name);
+ */
+ config_mailbox_delete_new( mailbox );
/* Close the mailbox, in case it was open */
if (mailbox->type != MAILBOX_POP3)
diff -u --recursive balsa/src/main.c balsa-new/src/main.c
--- balsa/src/main.c Sat Jul 31 15:23:15 1999
+++ balsa-new/src/main.c Sun Oct 3 16:05:28 1999
@@ -108,6 +108,8 @@
static void
config_init (void)
{
+ init_session();
+
if (config_load (BALSA_CONFIG_FILE) == FALSE)
{
fprintf (stderr, "*** Could not load config file %s!\n",
@@ -286,7 +288,7 @@
mailbox_open_unref (mailbox);
}
- if (balsa_app.proplist)
+/* if (balsa_app.proplist)*/
config_global_save ();
gnome_sound_shutdown ();
diff -u --recursive balsa/src/save-restore.c balsa-new/src/save-restore.c
--- balsa/src/save-restore.c Sun Sep 26 17:14:37 1999
+++ balsa-new/src/save-restore.c Sun Oct 3 16:44:42 1999
@@ -26,10 +26,6 @@
#include <assert.h>
#include <gnome.h>
-#include <proplist.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
#include <string.h>
#include "balsa-app.h"
#include "mailbox.h"
@@ -37,952 +33,634 @@
#include "save-restore.h"
#include "../libmutt/mutt.h"
-static proplist_t pl_dict_add_str_str (proplist_t dict_arg, gchar * string1,
- gchar * string2);
-static gchar *pl_dict_get_str (proplist_t dict, gchar * str);
-static proplist_t config_mailbox_get_by_name (gchar * name);
-static proplist_t config_mailbox_get_key (proplist_t mailbox);
-static gint config_mailbox_init (proplist_t mbox, gchar * key);
-static gint config_mailbox_get_highest_number (proplist_t accounts);
-static gchar *rot (gchar * pass);
+/*PKGW -- our session management thingie*/
-static gchar *
-rot (gchar * pass)
-{
- gchar *buff;
- gint len = 0, i = 0;
- len = strlen (pass);
- buff = g_strdup (pass);
-
-
- assert (pass != NULL);
- assert (buff != NULL); /* TODO: using assert for this case is wrong!
- * The error should be handled gracefully.
- */
-
- for (i = 0; i < len; i++)
- {
- if ((buff[i] <= 'M' && buff[i] >= 'A')
- || (buff[i] <= 'm' && buff[i] >= 'a'))
- buff[i] += 13;
- else if ((buff[i] <= 'Z' && buff[i] >= 'N')
- || (buff[i] <= 'z' && buff[i] >= 'n'))
- buff[i] -= 13;
- }
- return buff;
-}
+static GnomeClient *master_client = NULL;
+static gboolean use_sm = 1;
+static guint32 serial = 0;
+static gchar *this_section = NULL;
-/* Load the configuration from the specified file. The filename is
- taken to be relative to the user's home directory, as if "~/" had
- been prepended. Returns TRUE on success and FALSE on failure. */
-gint
-config_load (gchar * user_filename)
-{
- char *filename;
+static void safe_get_string( gchar *str, gchar **dest, gboolean *okay );
+static void safe_get_dstring( gchar *str, gchar **dest, gboolean *okay );
+static void safe_get_pstring( gchar *str, gchar **dest, gboolean *okay );
+static void get_dint( gchar *key, gint dflt, gint *dest, gboolean *okay );
- /* Deallocate the internal proplist first */
- if (balsa_app.proplist != NULL)
- PLRelease (balsa_app.proplist);
+static guint32 get_config_serial( void );
- /* Construct the filename by appending 'user_filename' to the user's
- home directory. */
+static void check_magic_box( Mailbox *box );
+static void set_magic_box( Mailbox *box );
- filename = g_strdup_printf("%s/%s", g_get_home_dir(), user_filename);
+static gboolean load_user_prefs( void );
+static void save_user_prefs( void );
- balsa_app.proplist = PLGetProplistWithPath (filename);
+static gboolean load_imap( void );
+static void save_imap( Mailbox *mbox );
- g_free (filename);
+static gboolean load_pop3( void );
+static void save_pop3( Mailbox *mbox );
- if (balsa_app.proplist == NULL)
- return FALSE;
+static gboolean load_mbox( void );
+static void save_mbox( Mailbox *mbox );
- return TRUE;
-} /* config_load */
-
-/* Save the internal configuration information into the specified
- file. Just as with load_config, the specified filename is taken to
- be relative to the user's home directory. Returns TRUE on success
- and FALSE on failure. */
-gint
-config_save (gchar * user_filename)
-{
- proplist_t temp_str;
- char *filename;
- int fd;
-
- /* Be sure that there is data to save first */
- if (balsa_app.proplist == NULL)
- {
- fprintf (stderr, "config_save: proplist is NULL!\n");
- return FALSE;
- }
-
- /* Construct the filename by appending 'user_filename' to the user's
- home directory. */
- filename = g_strdup_printf("%s/%s", g_get_home_dir(), user_filename);
-
- /* Set the property list's filename */
- temp_str = PLMakeString (filename);
- balsa_app.proplist = PLSetFilename (balsa_app.proplist, temp_str);
- PLRelease (temp_str);
-
- /* There might be passwords and things in the file, so we chmod the
- file to 0600 BEFORE we write any data into it. This involves
- creating the file independently of PLSave. */
- fd = creat (filename, S_IRUSR | S_IWUSR);
- if (fd < 0)
- {
- fprintf (stderr, "config_save: Error writing config file %s!\n",
- filename);
- g_free (filename);
- return FALSE;
- }
- close (fd);
-
- if (!PLSave (balsa_app.proplist, 0))
- {
- fprintf (stderr, "config_save: Error writing %s!\n", filename);
- return FALSE;
- }
-
- g_free (filename);
-
- return TRUE;
-} /* config_save */
-
-
-/* This routine inserts a new mailbox into the configuration's
- * accounts vector, modifying both the resident and on-disk
- * configurations. The mailbox is specified by 'mailbox', and 'key'
- * actually refers to whether this is a special mailbox, such as
- * "Inbox", "Outbox", or "Trash", or whether it is a "generic"
- * mailbox. If key is NULL, the mailbox's key is determine
- * automatically. The function returns TRUE on success and FALSE on
- * failure.
- */
-gint
-config_mailbox_add (Mailbox * mailbox, char *key_arg)
-{
- proplist_t mbox_dict, accounts, temp_str;
- char key[MAX_PROPLIST_KEY_LEN];
-
- /* Initialize the key in case it is accidentally used uninitialized */
- strcpy (key, "AnErrorOccurred");
-
- /* Each mailbox is stored as a Proplist dictionary of mailbox settings.
- First create the dictionary, then add it to the "accounts" section
- of the global configuration. */
- switch (mailbox->type)
- {
- case MAILBOX_MBOX:
- case MAILBOX_MH:
- case MAILBOX_MAILDIR:
- /* Create a new mailbox configuration with the following entries:
- Type = local;
- Name = ... ;
- Path = ... ;
- */
- mbox_dict = pl_dict_add_str_str (NULL, "Type", "local");
- pl_dict_add_str_str (mbox_dict, "Name", mailbox->name);
- pl_dict_add_str_str (mbox_dict, "Path", MAILBOX_LOCAL (mailbox)->path);
+static void load_data( const gchar *filename );
+static void save_data( const gchar *filename );
+static gboolean save_mailbox( Mailbox *box );
+static gint node_save( gpointer key, gpointer value, gpointer data );
- break;
+static gint save_session( GnomeClient *client, gint phase, GnomeSaveStyle style, gint shutdown,
+ GnomeInteractStyle interact_style, gint fast, gpointer data );
+static void end_session( GnomeClient *client, gpointer data );
+void load_session( void );
+void toggle_restart_session( int restart );
+void init_session( void );
- case MAILBOX_POP3:
- /* Create a new mailbox configuration with the following entries:
- Type = POP3;
- Name = ...;
- Username = ...;
- Password = ...;
- Server = ...;
- Check = 0 | 1;
- Delete = 0 | 1;
- */
- mbox_dict = pl_dict_add_str_str (NULL, "Type", "POP3");
- pl_dict_add_str_str (mbox_dict, "Name", mailbox->name);
- pl_dict_add_str_str (mbox_dict, "Username",
- MAILBOX_POP3 (mailbox)->user);
- /* Do not save the password if the field is NULL. This is here
- so that asving the password to the balsarc file can be optional */
- if (MAILBOX_POP3 (mailbox)->passwd)
- {
- gchar *buff;
- buff = rot (MAILBOX_POP3 (mailbox)->passwd);
- pl_dict_add_str_str (mbox_dict, "Password",
- buff);
- g_free (buff);
- }
- pl_dict_add_str_str (mbox_dict, "Server",
- MAILBOX_POP3 (mailbox)->server);
- {
- char tmp[32];
-
- snprintf (tmp, sizeof (tmp), "%d", MAILBOX_POP3 (mailbox)->check);
- pl_dict_add_str_str (mbox_dict, "Check", tmp);
-
- snprintf (tmp, sizeof (tmp), "%d", MAILBOX_POP3 (mailbox)->delete_from_server);
- pl_dict_add_str_str (mbox_dict, "Delete", tmp);
- }
-
- pl_dict_add_str_str (mbox_dict, "LastUID", MAILBOX_POP3 (mailbox)->last_popped_uid);
-
- break;
+/****************************************************************************/
- case MAILBOX_IMAP:
- /* Create a new mailbox configuration with the following entries:
- Type = IMAP;
- Name = ...;
- Server = ...;
- Port = ...;
- Path = ...;
- Username = ...;
- Password = ...;
- */
- mbox_dict = pl_dict_add_str_str (NULL, "Type", "IMAP");
- pl_dict_add_str_str (mbox_dict, "Name", mailbox->name);
- pl_dict_add_str_str (mbox_dict, "Server",
- MAILBOX_IMAP (mailbox)->server);
-
- /* Add the Port entry */
- {
- char tmp[MAX_PROPLIST_KEY_LEN];
- snprintf (tmp, sizeof (tmp), "%d", MAILBOX_IMAP (mailbox)->port);
- pl_dict_add_str_str (mbox_dict, "Port", tmp);
- }
-
- pl_dict_add_str_str (mbox_dict, "Path", MAILBOX_IMAP (mailbox)->path);
- pl_dict_add_str_str (mbox_dict, "Username",
- MAILBOX_IMAP (mailbox)->user);
- if (MAILBOX_IMAP (mailbox)->passwd != NULL)
- {
- gchar *buff;
- buff = rot (MAILBOX_IMAP (mailbox)->passwd);
- pl_dict_add_str_str (mbox_dict, "Password",
- buff);
- g_free (buff);
- }
- break;
+static void safe_get_string( gchar *key, gchar **dest, gboolean *okay )
+{
+ if( (*okay) == FALSE )
+ return;
- default:
- fprintf (stderr, "config_mailbox_add: Unknown mailbox type!\n");
- return FALSE;
+ if( (*dest) != NULL ) {
+ g_free( (*dest) );
+ (*dest) = NULL;
}
- /* If the configuration file has not been started, create it */
- if (balsa_app.proplist == NULL)
- {
- /* This is the special undocumented way to create an empty dictionary */
- balsa_app.proplist =
- PLMakeDictionaryFromEntries (NULL, NULL, NULL);
- }
-
- /* Now, add this newly created account to the list of mailboxes in
- the configuration file. */
- temp_str = PLMakeString ("Accounts");
- accounts = PLGetDictionaryEntry (balsa_app.proplist, temp_str);
- PLRelease (temp_str);
-
- if (accounts == NULL)
- {
- if (key_arg == NULL)
- strcpy (key, "m1");
- else
- snprintf (key, sizeof (key), "%s", key_arg);
-
- /* If there is no Accounts list in the global proplist, create
- one and add it to the global configuration dictionary. */
- temp_str = PLMakeString (key);
- accounts = PLMakeDictionaryFromEntries (temp_str, mbox_dict, NULL);
- PLRelease (temp_str);
-
- temp_str = PLMakeString ("Accounts");
- PLInsertDictionaryEntry (balsa_app.proplist, temp_str, accounts);
- PLRelease (temp_str);
- }
- else
- {
- /* Before we can add the mailbox to the configuration, we need
- to pick a unique key for it. "Inbox", "Outbox" and "Trash"
- all have unique keys, but for all other mailboxes, we are
- simply passed NULL, meaning that we must supply the key ourselves. */
- if (key_arg == NULL)
- {
- int mbox_max;
-
- mbox_max = config_mailbox_get_highest_number (accounts);
- snprintf (key, sizeof (key), "m%d", mbox_max + 1);
- }
- else
- snprintf (key, sizeof (key), "%s", key_arg);
+ (*dest) = gnome_config_get_string( key );
- /* If there is already an Accounts list, just add this new mailbox */
- temp_str = PLMakeString (key);
- PLInsertDictionaryEntry (accounts, temp_str, mbox_dict);
- PLRelease (temp_str);
- }
-
- return config_save (BALSA_CONFIG_FILE);
-} /* config_mailbox_add */
-
-/* Remove the specified mailbox from the list of accounts. Note that
- the mailbox is referenced by its 'Name' field here, so you had
- better make sure those stay unique. Returns TRUE if the mailbox
- was succesfully deleted and FALSE otherwise. */
-gint
-config_mailbox_delete (gchar * name)
-{
- proplist_t accounts, mbox, mbox_key, temp_str;
-
- if (balsa_app.proplist == NULL)
- {
- fprintf (stderr, "config_mailbox_delete: No configuration loaded!\n");
- return FALSE;
- }
-
- /* Grab the list of accounts */
- temp_str = PLMakeString ("Accounts");
- accounts = PLGetDictionaryEntry (balsa_app.proplist, temp_str);
- PLRelease (temp_str);
- if (accounts == NULL)
- return FALSE;
-
- /* Grab the specified mailbox */
- mbox = config_mailbox_get_by_name (name);
- if (mbox == NULL)
- return FALSE;
+ if( (*dest) == NULL ) {
+ (*okay) = FALSE;
+ g_warning( "Lookup of config item \"%s\" failed", key );
+ }
+}
- /* Now grab the associated key */
- mbox_key = config_mailbox_get_key (mbox);
- if (mbox_key == NULL)
- return FALSE;
+static void safe_get_dstring( gchar *key, gchar **dest, gboolean *okay )
+{
+ if( (*okay) == FALSE )
+ return;
- accounts = PLRemoveDictionaryEntry (accounts, mbox_key);
+ if( (*dest) != NULL ) {
+ g_free( (*dest) );
+ (*dest) = NULL;
+ }
- config_save (BALSA_CONFIG_FILE);
- return TRUE;
-} /* config_mailbox_delete */
+ (*dest) = gnome_config_get_string( key );
-/* Update the configuration information for the specified mailbox. */
-gint
-config_mailbox_update (Mailbox * mailbox, gchar * old_mbox_name)
+ if( (*dest) == NULL ) {
+ (*okay) = FALSE;
+ g_warning( "Lookup of config item \"%s\" failed", key );
+ }
+}
+static void safe_get_pstring( gchar *key, gchar **dest, gboolean *okay )
{
- proplist_t mbox, mbox_key;
- gchar key[MAX_PROPLIST_KEY_LEN];
+ if( (*okay) == FALSE )
+ return;
+ if( (*dest) != NULL ) {
+ g_free( (*dest) );
+ (*dest) = NULL;
+ }
- mbox = config_mailbox_get_by_name (old_mbox_name);
- mbox_key = config_mailbox_get_key (mbox);
+ (*dest) = gnome_config_private_get_string( key );
- if (mbox_key == NULL)
- {
- strcpy (key, "generic");
- }
- else
- {
- strcpy (key, PLGetString (mbox_key));
+ if( (*dest) == NULL ) {
+ (*okay) = FALSE;
+ g_warning( "Lookup of config item \"%s\" failed", key );
}
+}
- config_mailbox_delete (old_mbox_name);
- config_mailbox_add (mailbox, key);
+static void get_dint( gchar *key, gint dflt, gint *dest, gboolean *okay )
+{
+ gchar *fullkey;
+ if( (*okay) == FALSE )
+ return;
- return config_save (BALSA_CONFIG_FILE);
-} /* config_mailbox_update */
+ fullkey = g_strdup_printf( "%s=%d", key, dflt );
+ (*dest) = gnome_config_get_int( fullkey );
+ g_free( fullkey );
+}
-/* This function initializes all the mailboxes internally, going through
- the list of all the mailboxes in the configuration file one by one. */
-gint
-config_mailboxes_init (void)
+/*****************************************************************************/
+
+static guint32 get_config_serial( void )
{
- proplist_t accounts, temp_str, mbox, key;
- int num_elements, i;
+ guint32 me;
- g_assert (balsa_app.proplist != NULL);
+ /*Skip the leading name*/
+ sscanf( &( this_section[5] ), "%d", &me );
+
+ if( me > serial )
+ serial = me + 1;
- temp_str = PLMakeString ("Accounts");
- accounts = PLGetDictionaryEntry (balsa_app.proplist, temp_str);
- PLRelease (temp_str);
+ return me;
+}
- if (accounts == NULL)
- return FALSE;
+/*****************************************************************************/
- num_elements = PLGetNumberOfElements (accounts);
- for (i = 0; i < num_elements; i++)
- {
- key = PLGetArrayElement (accounts, i);
- mbox = PLGetDictionaryEntry (accounts, key);
- config_mailbox_init (mbox, PLGetString (key));
- }
-
- return TRUE;
-} /* config_mailboxes_init */
-
-/* Initialize the specified mailbox, creating the internal data
- structures which represent the mailbox. */
-static gint
-config_mailbox_init (proplist_t mbox, gchar * key)
-{
- proplist_t accounts, temp_str;
- MailboxType mailbox_type;
- Mailbox *mailbox;
- gchar *mailbox_name, *type, *field;
- GNode *node;
-
- g_assert (mbox != NULL);
- g_assert (key != NULL);
-
- mailbox_type = MAILBOX_UNKNOWN;
- mailbox = NULL;
-
- /* Grab the list of mailboxes */
- temp_str = PLMakeString ("Accounts");
- accounts = PLGetDictionaryEntry (balsa_app.proplist, temp_str);
- PLRelease (temp_str);
- if (accounts == NULL)
- return FALSE;
+static void check_magic_box( Mailbox *box )
+{
+ gchar *magic;
+ GNode *node;
- /* All mailboxes have a type and a name. Grab those. */
- type = pl_dict_get_str (mbox, "Type");
- if (type == NULL)
- {
- fprintf (stderr, "config_mailbox_init: mailbox type not set\n");
- return FALSE;
- }
- mailbox_name = g_strdup (pl_dict_get_str (mbox, "Name"));
- if (mailbox_name == NULL)
- mailbox_name = g_strdup ("Friendly Mailbox Name");
-
- /* Now grab the mailbox-type-specific fields */
- if (!strcasecmp (type, "local")) /* Local mailbox */
- {
- gchar *path;
+/*
+ g_message( "Checking whether box \"%s\" is magic...", box->name );
+*/
- path = pl_dict_get_str (mbox, "Path");
- if (path == NULL)
- return FALSE;
+ magic = gnome_config_get_string( "special_type" );
- mailbox_type = mailbox_valid (path);
- if (mailbox_type != MAILBOX_UNKNOWN)
- {
- mailbox = mailbox_new (mailbox_type);
- mailbox->name = mailbox_name;
- MAILBOX_LOCAL (mailbox)->path = g_strdup (path);
+ if( magic == NULL ) {
+ if( box->type == MAILBOX_MH ) {
+ node = g_node_new( mailbox_node_new( g_strdup( box->name ), box, TRUE ) );
+ } else {
+ node = g_node_new( mailbox_node_new( g_strdup( box->name ), box, FALSE ) );
}
- else
- {
- fprintf (stderr, "config_mailbox_init: Cannot identify type of "
- "local mailbox %s\n", mailbox_name);
- return FALSE;
+ g_node_append( balsa_app.mailbox_nodes, node );
+ } else if( strcmp( magic, "Inbox" ) == 0 ) {
+ balsa_app.inbox = box;
+ } else if( strcmp( magic, "Outbox" ) == 0 ) {
+ balsa_app.outbox = box;
+ } else if( strcmp( magic, "Sentbox" ) == 0 ) {
+ balsa_app.sentbox = box;
+ } else if( strcmp( magic, "Draftbox" ) == 0 ) {
+ balsa_app.draftbox = box;
+ } else if( strcmp( magic, "Trash" ) == 0 ) {
+ balsa_app.trash = box;
+ } else {
+ g_warning( "Unknown magic type \"%s\" for mailbox \"%s\", making it normal.", magic, box->name );
+ if( box->type == MAILBOX_MH ) {
+ node = g_node_new( mailbox_node_new( g_strdup( box->name ), box, TRUE ) );
+ } else {
+ node = g_node_new( mailbox_node_new( g_strdup( box->name ), box, FALSE ) );
}
+ g_node_append( balsa_app.mailbox_nodes, node );
}
- else if (!strcasecmp (type, "POP3")) /* POP3 mailbox */
- {
- mailbox = mailbox_new (MAILBOX_POP3);
- mailbox->name = mailbox_name;
- if ((field = pl_dict_get_str (mbox, "Username")) == NULL)
- return FALSE;
- MAILBOX_POP3 (mailbox)->user = g_strdup (field);
+// return TRUE;
+}
- if ((field = pl_dict_get_str (mbox, "Password")) != NULL)
- {
- gchar *buff;
- buff = rot (field);
- MAILBOX_POP3 (mailbox)->passwd = g_strdup (buff);
- g_free (buff);
- }
- else
- MAILBOX_POP3 (mailbox)->passwd = NULL;
+static void set_magic_box( Mailbox *box )
+{
+ gchar *magic = NULL;
- if ((field = pl_dict_get_str (mbox, "Server")) == NULL)
- return FALSE;
- MAILBOX_POP3 (mailbox)->server = g_strdup (field);
+ if( balsa_app.inbox == box || (strcmp( box->name, "Inbox" ) == 0) ) {
+ magic = "Inbox";
+ } else if( balsa_app.outbox == box || (strcmp( box->name, "Outbox" ) == 0) ) {
+ magic = "Outbox";
+ } else if( balsa_app.sentbox == box || (strcmp( box->name, "Sentbox" ) == 0) ) {
+ magic = "Sentbox";
+ } else if( balsa_app.draftbox == box || (strcmp( box->name, "Draftbox" ) == 0) ) {
+ magic = "Draftbox";
+ } else if( balsa_app.trash == box || (strcmp( box->name, "Trash" ) == 0) ) {
+ magic = "Trash";
+ }
+
+ if( magic )
+ gnome_config_set_string( "special_type", magic );
+}
- if ((field = pl_dict_get_str (mbox, "Check")) == NULL)
- MAILBOX_POP3 (mailbox)->check = FALSE;
- else
- MAILBOX_POP3 (mailbox)->check = atol (field);
+/*****************************************************************************/
- if ((field = pl_dict_get_str (mbox, "Delete")) == NULL)
- MAILBOX_POP3 (mailbox)->delete_from_server = FALSE;
- else
- MAILBOX_POP3 (mailbox)->delete_from_server = atol (field);
+static gboolean load_user_prefs( void )
+{
+ gboolean okay = TRUE;
+ gchar *speckey;
- if ((field = pl_dict_get_str (mbox, "LastUID")) == NULL)
- MAILBOX_POP3 (mailbox)->last_popped_uid = NULL;
- else
- MAILBOX_POP3 (mailbox)->last_popped_uid = g_strdup (field);
+ safe_get_string( "realname=Joe User", &( balsa_app.address->personal ), &okay );
+ safe_get_string( "email=joe@place.domain", &( balsa_app.address->mailbox ), &okay );
+ safe_get_string( "replyto=", &( balsa_app.replyto ), &okay );
+ safe_get_string( "SMTP_server=", &( balsa_app.smtp_server ), &okay );
+ safe_get_dstring( "reply_leading=> ", &( balsa_app.quote_str ), &okay );
+ safe_get_dstring( "msg_font=" DEFAULT_MESSAGE_FONT, &( balsa_app.message_font ), &okay );
+ safe_get_dstring( "charset=" DEFAULT_CHARSET, &( balsa_app.charset ), &okay );
+ get_dint( "encoding", 2, &( balsa_app.encoding_style ), &okay );
+ get_dint( "toolbar_style", GTK_TOOLBAR_BOTH, (gint *) &( balsa_app.toolbar_style ), &okay );
+ get_dint( "use_preview_pane", TRUE, &( balsa_app.previewpane ), &okay );
+#ifdef BALSA_SHOW_INFO
+ get_dint( "show_content_info", TRUE, &( balsa_app.mblist_show_mb_content_info ), &okay );
+#endif
+ get_dint( "use_debug", FALSE, &( balsa_app.debug ), &okay );
+ get_dint( "main_width", 640, &( balsa_app.mw_width ), &okay );
+ get_dint( "main_height", 480, &( balsa_app.mw_height ), &okay );
+ get_dint( "mblist_width", 100, &( balsa_app.mblist_width ), &okay );
+ get_dint( "mblist_width", 170, &( balsa_app.mblist_height ), &okay );
+
+ speckey = g_strdup_printf( "signature_path=%s/.signature", g_get_home_dir() );
+ safe_get_dstring( speckey, &( balsa_app.signature_path ), &okay );
+ g_free( speckey );
+
+ speckey = g_strdup_printf( "maildir=%s/balsa", g_get_home_dir() );
+ safe_get_dstring( speckey, &( balsa_app.local_mail_directory ), &okay );
+ g_free( speckey );
+ return okay;
+}
+static void save_user_prefs( void )
+{
+ gnome_config_set_string( "realname", balsa_app.address->personal );
+ gnome_config_set_string( "email", balsa_app.address->mailbox );
+ gnome_config_set_string( "replyto", balsa_app.replyto );
+ gnome_config_set_string( "maildir", balsa_app.local_mail_directory );
+ gnome_config_set_string( "SMTP_server", balsa_app.smtp_server );
+ gnome_config_set_string( "reply_leading", balsa_app.quote_str );
+ gnome_config_set_string( "msg_font", balsa_app.message_font );
+ gnome_config_set_string( "charset", balsa_app.charset );
+ gnome_config_set_string( "signature_path", balsa_app.signature_path );
+ gnome_config_set_int( "encoding", balsa_app.encoding_style );
+ gnome_config_set_int( "toolbar_style", balsa_app.toolbar_style );
+ gnome_config_set_int( "use_preview_pane", balsa_app.previewpane );
+#ifdef BALSA_SHOW_INFO
+ gnome_config_set_int( "show_content_info", balsa_app.mblist_show_mb_content_info );
+#endif
+ gnome_config_set_int( "use_debug", balsa_app.debug );
+ gnome_config_set_int( "main_width", balsa_app.mw_width );
+ gnome_config_set_int( "main_height", balsa_app.mw_height );
+ gnome_config_set_int( "mblist_width", balsa_app.mblist_width );
+ gnome_config_set_int( "mblist_width", balsa_app.mblist_height );
+}
- balsa_app.inbox_input =
- g_list_append (balsa_app.inbox_input, mailbox);
- }
- else if (!strcasecmp (type, "IMAP")) /* IMAP Mailbox */
- {
- mailbox = mailbox_new (MAILBOX_IMAP);
- mailbox->name = mailbox_name;
+/****************************************************************************/
- if ((field = pl_dict_get_str (mbox, "Username")) == NULL)
+static gboolean load_mbox( void )
+{
+ MailboxType mbtype;
+ Mailbox *mb = NULL;
+ gchar *path = NULL;
+ gboolean okay = TRUE;
+
+ safe_get_string( "path", &path, &okay );
+ mbtype = mailbox_valid( path );
+ if( mbtype == MAILBOX_UNKNOWN ) {
+ g_warning( "cannot load local mailbox at path \"%s\"", path );
return FALSE;
- MAILBOX_IMAP (mailbox)->user = g_strdup (field);
+ }
- if ((field = pl_dict_get_str (mbox, "Password")) != NULL)
- {
- gchar *buff;
- buff = rot (field);
- MAILBOX_IMAP (mailbox)->passwd = g_strdup (buff);
- g_free (buff);
- }
- else
- MAILBOX_IMAP (mailbox)->passwd = NULL;
+ mb = mailbox_new( mbtype );
+ mb->config_serial = get_config_serial();
+ safe_get_dstring( "name=Local Mailbox Name", &( mb->name ), &okay );
+ (MAILBOX_LOCAL( mb ))->path = path;
- if ((field = pl_dict_get_str (mbox, "Server")) == NULL)
- return FALSE;
- MAILBOX_IMAP (mailbox)->server = g_strdup (field);
+ check_magic_box( mb );
+ return okay;
+}
- if ((field = pl_dict_get_str (mbox, "Port")) == NULL)
- return FALSE;
- MAILBOX_IMAP (mailbox)->port = atol (field);
+static void save_mbox( Mailbox *mbox )
+{
+ MailboxLocal *ml;
+ g_assert( mbox->type == MAILBOX_MBOX ||
+ mbox->type == MAILBOX_MH ||
+ mbox->type == MAILBOX_MAILDIR );
+ ml = MAILBOX_LOCAL( mbox );
+
+ gnome_config_set_string( "name", mbox->name );
+ gnome_config_set_string( "path", ml->path );
+ set_magic_box( mbox );
+}
- if ((field = pl_dict_get_str (mbox, "Path")) == NULL)
- return FALSE;
- MAILBOX_IMAP (mailbox)->path = g_strdup (field);
+/****************************************************************************/
- }
- else
- {
- fprintf (stderr, "config_mailbox_init: Unknown mailbox type \"%s\" "
- "on mailbox %s\n", type, mailbox_name);
- }
+static gboolean load_pop3( void )
+{
+ Mailbox *mb;
+ gboolean okay = TRUE;
- if (strcmp ("Inbox", key) == 0)
- {
- balsa_app.inbox = mailbox;
- }
- else if (strcmp ("Outbox", key) == 0)
- {
- balsa_app.outbox = mailbox;
- }
- else if (strcmp ("Sentbox", key) == 0)
- {
- balsa_app.sentbox = mailbox;
- }
- else if (strcmp ("Draftbox", key) == 0)
- {
- balsa_app.draftbox = mailbox;
- }
- else if (strcmp ("Trash", key) == 0)
- {
- balsa_app.trash = mailbox;
+ mb = mailbox_new( MAILBOX_POP3 );
+ mb->config_serial = get_config_serial();
+ safe_get_dstring( "name=POP3 Mailbox Name", &( mb->name ), &okay );
+ safe_get_string( "username", &( (MAILBOX_POP3( mb ))->user ), &okay );
+ safe_get_pstring( "password", &( (MAILBOX_POP3( mb ))->passwd ), &okay );
+ safe_get_string( "server", &( (MAILBOX_POP3( mb ))->server ), &okay );
+ get_dint( "check", 0, &( (MAILBOX_POP3( mb ))->check ), &okay );
+ get_dint( "delete_from_server", 0, &( (MAILBOX_POP3( mb ))->delete_from_server ), &okay );
+
+ if( okay ) {
+ check_magic_box( mb );
+ balsa_app.inbox_input = g_list_append( balsa_app.inbox_input, mb );
+ return TRUE;
}
- else
- {
- if (mailbox_type == MAILBOX_MH)
- node = g_node_new (mailbox_node_new (g_strdup (mailbox->name),
- mailbox, TRUE));
- else
- node = g_node_new (mailbox_node_new (g_strdup (mailbox->name),
- mailbox, FALSE));
- g_node_append (balsa_app.mailbox_nodes, node);
- }
-
- return TRUE;
-} /* config_mailbox_init */
+ return FALSE;
+}
-/* Load Balsa's global settings */
-gint
-config_global_load (void)
+static void save_pop3( Mailbox *mbox )
{
- proplist_t globals, temp_str;
- gchar *field;
+ MailboxPOP3 *mp;
+ g_assert( mbox->type == MAILBOX_POP3 );
+ mp = MAILBOX_POP3( mbox );
+
+ gnome_config_set_int( "check", mp->check );
+ gnome_config_set_int( "delete_from_server", mp->delete_from_server );
+ gnome_config_set_string( "server", mp->server );
+ gnome_config_set_string( "name", mbox->name );
+ gnome_config_set_string( "username", mp->user );
+ gnome_config_private_set_string( "password", mp->passwd );
+ set_magic_box( mbox );
+}
+
+/****************************************************************************/
- g_assert (balsa_app.proplist != NULL);
+static gboolean load_imap( void )
+{
+ Mailbox *mb;
+ gboolean okay = TRUE;
- temp_str = PLMakeString ("Globals");
- globals = PLGetDictionaryEntry (balsa_app.proplist, temp_str);
- PLRelease (temp_str);
- if (globals == NULL)
- {
- fprintf (stderr, "config_global_load: Global settings not "
- "present in config file!\n");
- return FALSE;
+ mb = mailbox_new( MAILBOX_IMAP );
+ mb->config_serial = get_config_serial();
+ safe_get_dstring( "name=IMAP Mailbox Name", &( mb->name ), &okay );
+ safe_get_string( "username", &( (MAILBOX_IMAP( mb ))->user ), &okay );
+ safe_get_pstring( "password", &( (MAILBOX_IMAP( mb ))->passwd ), &okay );
+ safe_get_string( "server", &( (MAILBOX_IMAP( mb ))->server ), &okay );
+ safe_get_string( "path", &( (MAILBOX_IMAP( mb ))->path ), &okay );
+ get_dint( "port", 143, &( (MAILBOX_IMAP( mb ))->port ), &okay );
+
+ if( okay ) {
+ check_magic_box( mb );
+ balsa_app.inbox_input = g_list_append( balsa_app.inbox_input, mb );
+ return TRUE;
}
- /* user's real name */
- if ((field = pl_dict_get_str (globals, "RealName")) == NULL)
return FALSE;
- g_free (balsa_app.address->personal);
- balsa_app.address->personal = g_strdup (field);
+}
- /* user's email address */
- if ((field = pl_dict_get_str (globals, "Email")) == NULL)
- return FALSE;
- g_free (balsa_app.address->mailbox);
- balsa_app.address->mailbox = g_strdup (field);
+static void save_imap( Mailbox *mbox )
+{
+ MailboxIMAP *mi;
+ g_assert( mbox->type == MAILBOX_IMAP );
+ mi = MAILBOX_IMAP( mbox );
+
+ gnome_config_set_int( "port", mi->port );
+ gnome_config_set_string( "path", mi->path );
+ gnome_config_set_string( "server", mi->server );
+ gnome_config_set_string( "name", mbox->name );
+ gnome_config_set_string( "username", mi->user );
+ gnome_config_private_set_string( "password", mi->passwd );
+ set_magic_box( mbox );
+}
- /* users's replyto address */
- g_free (balsa_app.replyto);
- if ((field = pl_dict_get_str (globals, "ReplyTo")) == NULL)
- balsa_app.replyto = g_strdup (balsa_app.address->mailbox);
- else
- balsa_app.replyto = g_strdup (field);
+/****************************************************************************/
- /* directory */
- if ((field = pl_dict_get_str (globals, "LocalMailDir")) == NULL)
- return FALSE;
- g_free (balsa_app.local_mail_directory);
- balsa_app.local_mail_directory = g_strdup (field);
+static void load_data( const gchar *filename )
+{
+ gpointer iter;
+ gchar *key, *val;
+ gchar *combined;
+ gboolean done_prefs = FALSE;
+
+ iter = gnome_config_init_iterator_sections( filename );
+ while( (iter = gnome_config_iterator_next( iter, &key, &val )) != NULL ) {
+ this_section = key;
+
+ combined = g_strconcat( filename, key, "/", NULL );
+// g_message( "Checking config prefix \"%s\".", combined );
+ gnome_config_push_prefix( combined );
+ g_free( combined );
+
+ if( strcmp( key, "user-prefs" ) == 0 ) {
+ load_user_prefs();
+ done_prefs = TRUE;
+ } else if( strncmp( key, "mbox ", 5 ) == 0 ) {
+ load_mbox();
+ } else if( strncmp( key, "imap ", 5 ) == 0 ) {
+ load_imap();
+ } else if( strncmp( key, "pop3 ", 5 ) == 0 ) {
+ load_pop3();
+ } else if( strncmp( key, "Placement", 9 ) == 0 ) {
+ /*Skip stuff we don't want*/
+ } else if( strncmp( key, "History:", 8 ) == 0 ) {
+ /*Skip stuff we don't want*/
+ } else {
+ g_warning( "Unknown config section \"%s\", skipping it.", key );
+ }
- /* signature file path */
- g_free (balsa_app.signature_path);
- if ((field = pl_dict_get_str (globals, "SignaturePath")) == NULL)
- {
- balsa_app.signature_path = g_malloc (strlen (g_get_home_dir ()) + 12);
- sprintf (balsa_app.signature_path, "%s/.signature", g_get_home_dir ());
- }
- else
- balsa_app.signature_path = g_strdup (field);
-
- /* smtp server */
- if ((field = pl_dict_get_str (globals, "SMTPServer")) == NULL)
- ; /* an optional field for now */
- g_free (balsa_app.smtp_server);
- balsa_app.smtp_server = g_strdup (field);
-
- /* toolbar style */
- if ((field = pl_dict_get_str (globals, "ToolbarStyle")) == NULL)
- balsa_app.toolbar_style = GTK_TOOLBAR_BOTH;
- else
- balsa_app.toolbar_style = atoi (field);
-
- /* use the preview pane */
- if ((field = pl_dict_get_str (globals, "UsePreviewPane")) == NULL)
- balsa_app.previewpane = TRUE;
- else
- balsa_app.previewpane = atoi (field);
-#ifdef BALSA_SHOW_INFO
- /* show mailbox content info */
- if ((field = pl_dict_get_str (globals, "ShowMailboxContentInfo")) == NULL)
- balsa_app.mblist_show_mb_content_info = TRUE;
- else
- balsa_app.mblist_show_mb_content_info = atoi (field);
-#endif
- /* debugging enabled */
- if ((field = pl_dict_get_str (globals, "Debug")) == NULL)
- balsa_app.debug = FALSE;
- else
- balsa_app.debug = atoi (field);
-
- /* window sizes */
- if ((field = pl_dict_get_str (globals, "MainWindowWidth")) == NULL)
- balsa_app.mw_width = 640;
- else
- balsa_app.mw_width = atoi (field);
-
- if ((field = pl_dict_get_str (globals, "MainWindowHeight")) == NULL)
- balsa_app.mw_height = 480;
- else
- balsa_app.mw_height = atoi (field);
-
- if ((field = pl_dict_get_str (globals, "MailboxListWidth")) == NULL)
- balsa_app.mblist_width = 100;
- else
- balsa_app.mblist_width = atoi (field);
- /* FIXME this can be removed later */
- // if (balsa_app.mblist_width < 100)
- // balsa_app.mblist_width = 170;
- if ((field = pl_dict_get_str (globals, "MailboxListHeight")) == NULL)
- balsa_app.mblist_height = 170;
- else
- balsa_app.mblist_height = atoi (field);
- /* FIXME this can be removed later */
- // if (balsa_app.mblist_height < 100)
- // balsa_app.mblist_height = 200;
-
-
-
- /* arp --- LeadinStr for "reply to" leadin. */
- g_free (balsa_app.quote_str);
- if ((field = pl_dict_get_str (globals, "LeadinStr")) == NULL)
- balsa_app.quote_str = g_strdup ("> ");
- else
- balsa_app.quote_str = g_strdup (field);
-
- /* font used to display messages */
- if ((field = pl_dict_get_str (globals, "MessageFont")) == NULL)
- balsa_app.message_font = g_strdup (DEFAULT_MESSAGE_FONT);
- else
- balsa_app.message_font = g_strdup (field);
-
- /* more here */
- g_free(balsa_app.charset);
- if (( field = pl_dict_get_str (globals, "Charset")) == NULL)
- balsa_app.charset = g_strdup(DEFAULT_CHARSET);
- else
- balsa_app.charset = g_strdup(field);
- mutt_set_charset (balsa_app.charset);
-
- if (( field = pl_dict_get_str (globals, "EncodingStyle")) == NULL)
- balsa_app.encoding_style = /*DEFAULT_ENCODING*/ 2;
- else
- balsa_app.encoding_style = atoi(field);
-
- return TRUE;
-} /* config_global_load */
-
-gint
-config_global_save (void)
-{
- proplist_t globals, temp_str;
-
- g_assert (balsa_app.proplist != NULL);
-
- temp_str = PLMakeString ("Globals");
- globals = PLGetDictionaryEntry (balsa_app.proplist, temp_str);
- if (globals != NULL)
- {
- /* Out with the old */
- PLRemoveDictionaryEntry (balsa_app.proplist, temp_str);
- }
- PLRelease (temp_str);
-
- /* Create a new dictionary of global configurations */
- if (balsa_app.address->personal != NULL)
- globals = pl_dict_add_str_str (NULL, "RealName", balsa_app.address->personal);
- if (balsa_app.address->mailbox != NULL)
- pl_dict_add_str_str (globals, "Email", balsa_app.address->mailbox);
- if (balsa_app.replyto != NULL)
- pl_dict_add_str_str (globals, "ReplyTo", balsa_app.replyto);
-
- if (balsa_app.local_mail_directory != NULL)
- pl_dict_add_str_str (globals, "LocalMailDir",
- balsa_app.local_mail_directory);
- if (balsa_app.smtp_server != NULL)
- pl_dict_add_str_str (globals, "SMTPServer", balsa_app.smtp_server);
-
- if (balsa_app.signature_path != NULL)
- pl_dict_add_str_str (globals, "SignaturePath",
- balsa_app.signature_path);
-
-
- {
- char tmp[MAX_PROPLIST_KEY_LEN];
- snprintf (tmp, sizeof (tmp), "%d", balsa_app.toolbar_style);
- pl_dict_add_str_str (globals, "ToolbarStyle", tmp);
+ gnome_config_pop_prefix();
+ }
- snprintf (tmp, sizeof (tmp), "%d", balsa_app.debug);
- pl_dict_add_str_str (globals, "Debug", tmp);
+ if( !done_prefs ) {
+ combined = g_strconcat( filename, "user-prefs/", NULL );
+// g_message( "Forcing config prefix \"%s\".", combined );
+ gnome_config_push_prefix( combined );
+ g_free( combined );
- snprintf (tmp, sizeof (tmp), "%d", balsa_app.previewpane);
- pl_dict_add_str_str (globals, "UsePreviewPane", tmp);
-#ifdef BALSA_SHOW_INFO
- snprintf (tmp, sizeof (tmp), "%d", balsa_app.mblist_show_mb_content_info);
- pl_dict_add_str_str (globals, "ShowMailboxContentInfo", tmp);
-#endif
- snprintf (tmp, sizeof (tmp), "%d", balsa_app.mw_width);
- pl_dict_add_str_str (globals, "MainWindowWidth", tmp);
+ load_user_prefs();
+ done_prefs = TRUE;
+ }
+}
- snprintf (tmp, sizeof (tmp), "%d", balsa_app.mw_height);
- pl_dict_add_str_str (globals, "MainWindowHeight", tmp);
+static gboolean save_mailbox( Mailbox *box )
+{
+ gchar *prefix = NULL;
- snprintf (tmp, sizeof (tmp), "%d", balsa_app.mblist_width);
- pl_dict_add_str_str (globals, "MailboxListWidth", tmp);
+ if( !box )
+ return FALSE;
- snprintf (tmp, sizeof (tmp), "%d", balsa_app.mblist_height);
- pl_dict_add_str_str (globals, "MailboxListHeight", tmp);
-
- snprintf (tmp, sizeof (tmp), "%d", balsa_app.encoding_style);
- pl_dict_add_str_str (globals, "EncodingStyle", tmp);
- }
-
-
- /* arp --- "LeadinStr" into cfg. */
- if (balsa_app.quote_str != NULL)
- pl_dict_add_str_str (globals, "LeadinStr", balsa_app.quote_str);
- else
- pl_dict_add_str_str (globals, "LeadinStr", "> ");
-
- /* message font */
- if (balsa_app.message_font != NULL)
- pl_dict_add_str_str (globals, "MessageFont", balsa_app.message_font);
- else
- pl_dict_add_str_str (globals, "MessageFont", DEFAULT_MESSAGE_FONT);
-
- /* encoding */
- if (balsa_app.charset != NULL)
- pl_dict_add_str_str(globals, "Charset", balsa_app.charset);
- else
- pl_dict_add_str_str(globals, "Charset", DEFAULT_CHARSET);
-
- /* Add it to configuration file */
- temp_str = PLMakeString ("Globals");
- PLInsertDictionaryEntry (balsa_app.proplist, temp_str, globals);
- PLRelease (temp_str);
-
- return config_save (BALSA_CONFIG_FILE);
-
-} /* config_global_save */
-
-/* This is a little helper routine which adds a simple entry of the
- form "string1 = string2;" to a dictionary. If dict_arg is NULL,
- a new dictionary is created and returned. */
-static proplist_t
-pl_dict_add_str_str (proplist_t dict_arg, gchar * string1, gchar * string2)
-{
- proplist_t prop_string1, prop_string2, dict;
-
- dict = dict_arg;
- prop_string1 = PLMakeString (string1);
- prop_string2 = PLMakeString (string2);
-
- /* If we are passed a null dictionary, then we are expected to
- create the dictionary from the entry and return it */
- if (dict == NULL)
- dict = PLMakeDictionaryFromEntries (prop_string1, prop_string2, NULL);
- else
- PLInsertDictionaryEntry (dict, prop_string1, prop_string2);
-
- PLRelease (prop_string1);
- PLRelease (prop_string2);
-
- return dict;
-} /* pl_dict_add_str_str */
-
-/* A helper routine to get the corresponding value for the string-type
- key 'str' in 'dict'. Returns the string-value of the corresponding
- value on success and NULL on failure. */
-static gchar *
-pl_dict_get_str (proplist_t dict, gchar * str)
-{
- proplist_t temp_str, elem;
-
- temp_str = PLMakeString (str);
- elem = PLGetDictionaryEntry (dict, temp_str);
- PLRelease (temp_str);
-
- if (elem == NULL)
- return NULL;
-
- if (!PLIsString (elem))
- return NULL;
-
- return PLGetString (elem);
-} /* pl_dict_get_str */
-
-/* Grab the mailbox whose 'Name' field's string value matches 'name'.
- Returns a handle to the proplist_t for the mailbox if it exists and
- NULL otherwise. */
-static proplist_t
-config_mailbox_get_by_name (gchar * name)
-{
- proplist_t temp_str, accounts, mbox, name_prop, mbox_key;
- int num_elements, i;
-
- g_assert (balsa_app.proplist != NULL);
-
- /* Grab the list of accounts */
- temp_str = PLMakeString ("Accounts");
- accounts = PLGetDictionaryEntry (balsa_app.proplist, temp_str);
- PLRelease (temp_str);
-
- if (accounts == NULL)
- return NULL;
-
- /* Walk the list of all mailboxes until one with a matching "Name" field
- is found. */
- num_elements = PLGetNumberOfElements (accounts);
- temp_str = PLMakeString ("Name");
- for (i = 0; i < num_elements; i++)
- {
- mbox_key = PLGetArrayElement (accounts, i);
- if (mbox_key == NULL)
- continue;
-
- mbox = PLGetDictionaryEntry (accounts, mbox_key);
- if (mbox == NULL)
- continue;
-
- name_prop = PLGetDictionaryEntry (mbox, temp_str);
- if (name_prop == NULL)
- continue;
-
- if (!strcmp (PLGetString (name_prop), name))
- {
- PLRelease (temp_str);
- return mbox;
- }
+// g_message( "Saving mailbox \"%s\"", box->name );
+ switch( box->type ) {
+ case MAILBOX_MH:
+ case MAILBOX_MAILDIR:
+ case MAILBOX_MBOX:
+ prefix = g_strdup_printf( "%smbox %d/", gnome_client_get_config_prefix( master_client ), box->config_serial );
+ gnome_config_push_prefix( prefix );
+// g_message( "Config prefix: %s", prefix );
+ save_mbox( box );
+ break;
+ case MAILBOX_IMAP:
+ prefix = g_strdup_printf( "%simap %d/", gnome_client_get_config_prefix( master_client ), box->config_serial );
+ gnome_config_push_prefix( prefix );
+// g_message( "Config prefix: %s", prefix );
+ save_imap( box );
+ break;
+ case MAILBOX_POP3:
+ prefix = g_strdup_printf( "%spop3 %d/", gnome_client_get_config_prefix( master_client ), box->config_serial );
+ gnome_config_push_prefix( prefix );
+// g_message( "Config prefix: %s", prefix );
+ save_pop3( box );
+ break;
+ default:
+ g_warning( "Unknown mailbox type %d for box \"%s\".", box->type, box->name );
}
- PLRelease (temp_str);
+ if( prefix ) {
+ g_free( prefix );
+ gnome_config_pop_prefix();
+ }
+ return TRUE;
+}
- return NULL;
-} /* config_mailbox_get_by_name */
+static gint node_save( gpointer key, gpointer value, gpointer data )
+{
+ if( balsa_app.inbox != value &&
+ balsa_app.outbox != value &&
+ balsa_app.sentbox != value &&
+ balsa_app.draftbox != value &&
+ balsa_app.trash != value )
+ save_mailbox( value );
+ return 0;
+}
-static proplist_t
-config_mailbox_get_key (proplist_t mailbox)
+static void save_data( const gchar *filename )
{
- proplist_t temp_str, accounts, mbox, mbox_key;
- int num_elements, i;
+ gchar *combined;
- g_assert (balsa_app.proplist != NULL);
+ /* Save global preferences */
+ combined = g_strconcat( filename, "user-prefs/", NULL );
+// g_message( "Saving config prefix \"%s\".", combined );
+ gnome_config_push_prefix( combined );
+ g_free( combined );
+ save_user_prefs();
+ gnome_config_pop_prefix();
+
+ save_mailbox( balsa_app.inbox );
+ save_mailbox( balsa_app.outbox );
+ save_mailbox( balsa_app.sentbox );
+ save_mailbox( balsa_app.draftbox );
+ save_mailbox( balsa_app.trash );
+
+ g_node_traverse( balsa_app.mailbox_nodes, G_IN_ORDER, G_TRAVERSE_ALL, 1024, (GNodeTraverseFunc) node_save, NULL );
+// g_message( "Syncing configuration." );
+ gnome_config_sync();
+}
- /* Grab the list of accounts */
- temp_str = PLMakeString ("Accounts");
- accounts = PLGetDictionaryEntry (balsa_app.proplist, temp_str);
- PLRelease (temp_str);
+/******************************************************************************/
+// These are hooks for the old config system.
- if (accounts == NULL)
- return NULL;
+guint32 config_next_serial( void )
+{
+ return serial++;
+}
- /* Walk the list of all mailboxes until the matching mailbox is found */
- num_elements = PLGetNumberOfElements (accounts);
- for (i = 0; i < num_elements; i++)
- {
- mbox_key = PLGetArrayElement (accounts, i);
- if (mbox_key == NULL)
- continue;
+gint config_load( gchar *filename )
+{
+// g_message( "config load()" );
+ filename = gnome_client_get_config_prefix( master_client );
+ load_data( filename );
+ return TRUE;
+}
- mbox = PLGetDictionaryEntry (accounts, mbox_key);
+gint config_save( gchar *filename )
+{
+// g_message( "config save()" );
+ filename = gnome_client_get_config_prefix( master_client );
+ save_data( filename );
+ return TRUE;
+}
- if (mbox == mailbox)
- return mbox_key;
+gint config_mailbox_add( Mailbox *mbox, char *key_arg )
+{
+ return save_mailbox( mbox );
+}
+gint config_mailbox_delete( gchar *name )
+{
+ g_warning( "Mailbox delete will fail, use config_mailbox_delete_new!!!" );
+ return FALSE;
+}
+
+gint config_mailbox_delete_new( Mailbox *mb )
+{
+ gchar *name;
+ gchar *type;
+
+ switch( mb->type ) {
+ case MAILBOX_MH:
+ case MAILBOX_MAILDIR:
+ case MAILBOX_MBOX:
+ type = "mbox";
+ break;
+ case MAILBOX_IMAP:
+ type = "imap";
+ break;
+ case MAILBOX_POP3:
+ type = "pop3";
+ break;
+ default:
+ g_warning( "Unknown mailbox type %d for box \"%s\".", mb->type, mb->name );
+ type = "uhoh";
}
- return NULL;
-} /* config_mailbox_get_key */
+ name = g_strdup_printf( "%s/%s %d", gnome_client_get_config_prefix( master_client ), type, mb->config_serial );
+ gnome_config_clean_section( name );
+ g_free( name );
+ return TRUE;
+}
-static gint
-config_mailbox_get_highest_number (proplist_t accounts)
+gint config_mailbox_update( Mailbox *mailbox, gchar *oldname )
{
- int num_elements, i, max = 0, curr;
- proplist_t mbox_name;
- char *name;
+ return save_mailbox( mailbox );
+}
- num_elements = PLGetNumberOfElements (accounts);
- for (i = 0; i < num_elements; i++)
- {
- mbox_name = PLGetArrayElement (accounts, i);
+gint config_mailboxes_init( void )
+{
+ /*Save this for config_load()*/
+ return TRUE;
+}
- if (mbox_name == NULL)
- {
- fprintf (stderr, "config_mailbox_get_highest_number: "
- "error getting mailbox key!\n");
- abort ();
- }
+gint config_global_load( void )
+{
+// g_message( "global load()" );
+ return TRUE;
+// return config_load( NULL );
+}
- name = PLGetString (mbox_name);
+gint config_global_save( void )
+{
+// g_message( "global save()" );
+ return config_save( NULL );
+}
+
+/******************************************************************************/
+
+static gint save_session( GnomeClient *client, gint phase, GnomeSaveStyle style, gint shutdown,
+ GnomeInteractStyle interact_style, gint fast, gpointer data )
+{
+ gchar *discard[] = { "rm", NULL };
+ gchar *prefix = gnome_client_get_config_prefix( client );
+
+// g_message( "save_session()" );
+ save_data( prefix );
+
+ discard[1] = gnome_config_get_real_path( prefix );
+ gnome_client_set_discard_command( client, 2, discard );
+ g_free( discard[1] );
- curr = 0;
+ return TRUE;
+}
- if (strlen (name) > 1)
- curr = atoi (name + 1);
+static void end_session( GnomeClient *client, gpointer data )
+{
+// g_message( "end_session()" );
+ balsa_exit();
+}
+
+void load_session( void )
+{
+ gchar *filename;
- if (curr > max)
- max = curr;
+// g_message( "load_session()" );
+
+ filename = gnome_client_get_config_prefix( master_client );
+ load_data( filename );
+}
+
+void toggle_restart_session( int restart )
+{
+ if( restart ) {
+ gnome_client_set_restart_style( master_client, GNOME_RESTART_IMMEDIATELY );
+ } else {
+ gnome_client_set_restart_style( master_client, GNOME_RESTART_NEVER );
}
+}
- return max;
-} /* config_mailbox_get_highest_number */
+void init_session( void )
+{
+// g_message( "init_session()" );
+
+ master_client = gnome_master_client();
+ use_sm = (gboolean)(gnome_client_get_flags( master_client ) & GNOME_CLIENT_IS_CONNECTED);
+
+ gtk_signal_connect( GTK_OBJECT( master_client ), "save_yourself",
+ (GtkSignalFunc) save_session, NULL );
+ gtk_signal_connect( GTK_OBJECT( master_client ), "die",
+ (GtkSignalFunc) end_session, NULL );
+ toggle_restart_session( FALSE );
+}
diff -u --recursive balsa/src/save-restore.h balsa-new/src/save-restore.h
--- balsa/src/save-restore.h Sat Dec 12 09:04:04 1998
+++ balsa-new/src/save-restore.h Sun Oct 3 15:50:52 1999
@@ -44,4 +44,13 @@
gint config_global_load (void);
gint config_global_save (void);
+/*PKGW*/
+gint config_mailbox_delete_new( Mailbox *mailbox );
+guint32 config_next_serial( void );
+
+void load_session( void );
+void toggle_restart_session( int restart );
+void init_session( void );
+/*end PKGW*/
+
#endif /* __SAVE_RESTORE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]