diff options
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 12 | ||||
-rw-r--r-- | mail/mail-accounts.c | 380 | ||||
-rw-r--r-- | mail/mail-accounts.h | 77 | ||||
-rw-r--r-- | mail/mail-config-druid.c | 45 | ||||
-rw-r--r-- | mail/mail-config-druid.h | 1 |
5 files changed, 512 insertions, 3 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 1225491d10..804d042a0d 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,5 +1,17 @@ 2001-01-05 Jeffrey Stedfast <fejj@helixcode.com> + * mail-accounts.c (mail_add): Since the druid now handles adding + the new account to the config, we'll just connect to the destroy + event and show the druid. + (mail_add_finished): Just reload the account list here. + + * mail-config-druid.c (druid_finish): New callback to handle the + "finish" signal. On second thought, it seems it would be best for + the finish callback to be here rather than in mail-accounts.c. + + * mail-accounts.[c,h]: Added. Contains source for the Account manager + window. And just like mail-config-druid.c, it's not yet complete. + * mail-config-druid.c (mail_config_druid_get_incoming_keep_mail): Renamed from _delete_mail (mail_config_druid_get_transport_url): New convenience function diff --git a/mail/mail-accounts.c b/mail/mail-accounts.c new file mode 100644 index 0000000000..832e0173bc --- /dev/null +++ b/mail/mail-accounts.c @@ -0,0 +1,380 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast <fejj@helixcode.com> + * + * Copyright 2001 Helix Code, Inc. (www.helixcode.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#include "mail-config.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <camel/camel-url.h> + +static void mail_accounts_dialog_class_init (MailAccountsDialogClass *class); +static void mail_accounts_dialog_init (MailAccountsDialog *dialog); +static void mail_accounts_dialog_finalise (GtkObject *obj); + +static GnomeDialogClass *parent_class; + +GtkType +mail_accounts_dialog_get_type () +{ + static GtkType type = 0; + + if (!type) { + GtkTypeInfo type_info = { + "MailAccountsDialog", + sizeof (MailAccountsDialog), + sizeof (MailAccountsDialogClass), + (GtkClassInitFunc) mail_accounts_dialog_class_init, + (GtkObjectInitFunc) mail_accounts_dialog_init, + (GtkArgSetFunc) NULL, + (GtkArgGetFunc) NULL + }; + + type = gtk_type_unique (gnome_dialog_get_type (), &type_info); + } + + return type; +} + +static void +mail_accounts_dialog_class_init (MailConfigDruidClass *class) +{ + GtkObjectClass *object_class; + + object_class = (GtkObjectClass *) class; + parent_class = gtk_type_class (gnome_dialog_get_type ()); + + object_class->finalize = mail_accounts_dialog_finalise; + /* override methods */ + +} + +static void +mail_accounts_dialog_init (MailAccountsDialog *o) +{ + ; +} + +static void +mail_accounts_dialog_finalise (GtkObject *obj) +{ + MailAccountsDialog *dialog = (MailConfigDruid *) obj; + + gtk_object_unref (GTK_OBJECT (dialog->gui)); + + ((GtkObjectClass *)(parent_class))->finalize (obj); +} + +static void +load_accounts (MailAccountsDialog *dialog) +{ + const MailConfigAccount *account; + const GList *node = dialog->accounts; + int i = 0; + + gtk_clist_freeze (dialog->mail_accounts); + + gtk_clist_clear (dialog->mail_accounts); + + while (node) { + CamelURL *url; + gchar *text[2]; + + account = node->data; + + url = camel_url_new (account->source->url, NULL); + text[0] = g_strdup (account->name); + text[1] = g_strdup_printf ("%s%s", url->protocol, + account->default ? " (default)" : ""); + camel_url_free (url); + + gtk_clist_append (dialog->mail_accounts, text); + g_free (text[0]); + g_free (text[1]); + + /* set the account on the row */ + gtk_clist_set_row_data (dialog->mail_accounts, i, account); + + node = node->next; + i++; + } + + gtk_clist_thaw (dialog->mail_accounts); +} + +static void +load_news (MailAccountsDialog *dialog) +{ + /* FIXME: implement */ + ; +} + +/* mail callbacks */ +static void +mail_select (GtkCList *clist, gint row, gint column, GdkEventButton *event, gpointer data) +{ + MailAccountsDialog *dialog = data; + + dialog->accounts_row = row; + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_edit), TRUE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_delete), TRUE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_default), TRUE); +} + +static void +mail_unselect (GtkCList *clist, gint row, gint column, GdkEventButton *event, gpointer data) +{ + MailAccountsDialog *dialog = data; + + dialog->accounts_row = -1; + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_edit), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_delete), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_default), FALSE); +} + +static void +mail_add_finished (GtkWidget *widget, gpointer data) +{ + /* Either Cancel or Finished was clicked in the druid so reload the accounts */ + MailAccountsDialog *dialog = data; + + dialog->accounts = mail_config_get_accounts (); + load_accounts (dialog); +} + +static void +mail_add (GtkButton *button, gpointer data) +{ + MailAccountsDialog *dialog = data; + MailConfigDruid *druid; + + druid = mail_config_druid_new (); + gtk_signal_connect (GTK_OBJECT (druid), "destroy" + GTK_SIGNAL_FUNC (mail_add_finished), dialog); + + gtk_widget_show (GTK_WIDGET (druid)); +} + +static void +mail_edit (GtkButton *button, gpointer data) +{ + MailAccountsDialog *dialog = data; + MailConfigAccount *account; + + /* open the editor and stuff */ +} + +static void +mail_delete (GtkButton *button, gpointer data) +{ + MailAccountsDialog *dialog = data; + MailConfigAccount *account; + + if (dialog->accounts_row >= 0) { + int row, len; + + account = gtk_clist_get_row_data (dialog->mail_accounts, dialog->accounts_row); + g_list_remove ((GList *)dialog->accounts, account); + account_destroy (account); + gtk_clist_remove (dialog->mail_accounts, dialog->accounts_row); + + len = g_list_length (dialog->accounts); + if (len > 0) { + row = dialog->accounts_row; + row = row >= len ? len - 1 : row; + gtk_clist_select_row (dialog->mail_accounts, row, 0); + } else { + dialog->accounts_row = -1; + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_edit), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_delete), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_default), FALSE); + } + } +} + +static void +mail_default (GtkButton *button, gpointer data) +{ + MailAccountsDialog *dialog = data; + const MailConfigAccount *account; + + if (dialog->accounts_row >= 0) { + account = gtk_clist_get_row_data (dialog->mail_accounts, dialog->accounts_row); + mail_config_set_default_account (account); + } +} + +/* news callbacks */ +static void +news_select (GtkCList *clist, gint row, gint column, GdkEventButton *event, gpointer data) +{ + MailAccountsDialog *dialog = data; + + dialog->news_row = row; + gtk_widget_set_sensitive (GTK_WIDGET (dialog->news_edit), TRUE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->news_delete), TRUE); +} + +static void +news_unselect (GtkCList *clist, gint row, gint column, GdkEventButton *event, gpointer data) +{ + MailAccountsDialog *dialog = data; + + dialog->news_row = -1; + gtk_widget_set_sensitive (GTK_WIDGET (dialog->news_edit), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->news_delete), FALSE); +} + +static void +news_add_finish_clicked () +{ + /* FIXME: uhm, yea... */ + ; +} + +static void +news_add (GtkButton *button, gpointer data) +{ + /* FIXME: do stuff */ + ; +} + +static void +news_edit (GtkButton *button, gpointer data) +{ + MailAccountsDialog *dialog = data; + MailConfigService *server; + + /* FIXME: open the editor and stuff */ +} + +static void +news_delete (GtkButton *button, gpointer data) +{ + MailAccountsDialog *dialog = data; + MailConfigService *server; + + if (dialog->news_row >= 0) { + int row, len; + + server = gtk_clist_get_row_data (dialog->news_accounts, dialog->news_row); + g_list_remove ((GList *)dialog->news, server); + service_destroy (server); + gtk_clist_remove (dialog->news_accounts, dialog->news_row); + + len = g_list_length (dialog->news); + if (len > 0) { + row = dialog->news_row; + row = row >= len ? len - 1 : row; + gtk_clist_select_row (dialog->news_accounts, row, 0); + } else { + dialog->news_row = -1; + gtk_widget_set_sensitive (GTK_WIDGET (dialog->news_edit), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->news_delete), FALSE); + } + } +} + +static void +construct (MailAccountsDialog *dialog) +{ + GladeXML *gui; + GtkWidget *notebook; + + gui = glade_xml_new (EVOLUTION_DATA_DIR "/mail-config-druid.glade", "mail-accounts-dialog"); + dialog->gui = gui; + + /* get our toplevel widget */ + notebook = glade_xml_get_widget (gui, "notebook"); + + /* reparent */ + gtk_widget_reparent (widget, GTK_WIDGET (dialog)); + + /* give our dialog an OK button and title */ + gnome_dialog_construct (GNOME_DIALOG (dialog), _("Evolution Accounts"), + GNOME_STOCK_BUTTON_OK); + + dialog->mail_accounts = GTK_CLIST (glade_xml_get_widget (gui, "clistAccounts")); + gtk_signal_connect (GTK_OBJECT (dialog->mail_accounts), "select-row", + GTK_SIGNAL_FUNC (mail_select), dialog); + gtk_signal_connect (GTK_OBJECT (dialog->mail_accounts), "unselect-row", + GTK_SIGNAL_FUNC (mail_unselect), dialog); + dialog->mail_add = GTK_BUTTON (glade_xml_get_widget (gui, "cmdMailAdd")); + gtk_signal_connect (GTK_OBJECT (dialog->mail_add), "clicked", + GTK_SIGNAL_FUNC (mail_add), dialog); + dialog->mail_edit = GTK_BUTTON (glade_xml_get_widget (gui, "cmdMailEdit")); + gtk_signal_connect (GTK_OBJECT (dialog->mail_edit), "clicked", + GTK_SIGNAL_FUNC (mail_edit), dialog); + dialog->mail_delete = GTK_BUTTON (glade_xml_get_widget (gui, "cmdMailDelete")); + gtk_signal_connect (GTK_OBJECT (dialog->mail_delete), "clicked", + GTK_SIGNAL_FUNC (mail_delete), dialog); + dialog->mail_default = GTK_BUTTON (glade_xml_get_widget (gui, "cmdMailDefault")); + gtk_signal_connect (GTK_OBJECT (dialog->mail_default), "clicked", + GTK_SIGNAL_FUNC (mail_default), dialog); + + dialog->news_accounts = GTK_CLIST (glade_xml_get_widget (gui, "clistAccounts")); + gtk_signal_connect (GTK_OBJECT (dialog->news_accounts), "select-row", + GTK_SIGNAL_FUNC (news_select), dialog); + gtk_signal_connect (GTK_OBJECT (dialog->news_accounts), "unselect-row", + GTK_SIGNAL_FUNC (news_unselect), dialog); + dialog->news_add = GTK_BUTTON (glade_xml_get_widget (gui, "cmdNewsAdd")); + gtk_signal_connect (GTK_OBJECT (dialog->news_add), "clicked", + GTK_SIGNAL_FUNC (news_add), dialog); + dialog->news_edit = GTK_BUTTON (glade_xml_get_widget (gui, "cmdNewsEdit")); + gtk_signal_connect (GTK_OBJECT (dialog->news_edit), "clicked", + GTK_SIGNAL_FUNC (news_edit), dialog); + dialog->news_delete = GTK_BUTTON (glade_xml_get_widget (gui, "cmdNewsDelete")); + gtk_signal_connect (GTK_OBJECT (dialog->news_delete), "clicked", + GTK_SIGNAL_FUNC (news_delete), dialog); + + /* now to fill in the clists */ + dialog->accounts_row = -1; + dialog->accounts = mail_config_get_accounts (); + if (dialog->accounts) { + load_accounts (dialog); + gtk_clist_select_row (dialog->mail_accounts, 0, 0); + } else { + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_edit), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_delete), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->mail_default), FALSE); + } + + dialog->news_row = -1; + dialog->news = mail_config_get_news (); + if (dialog->news) { + load_news (dialog); + gtk_clist_select_row (dialog->news_accounts, 0, 0); + } else { + gtk_widget_set_sensitive (GTK_WIDGET (dialog->news_edit), FALSE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->news_delete), FALSE); + } +} + +MailAccountsDialog * +mail_accounts_dialog_new () +{ + MailAccountsDialog *new; + + new = (MailAccountsDialog *) gtk_type_new (mail_accounts_dialog_get_type ()); + construct (new); + + return new; +} diff --git a/mail/mail-accounts.h b/mail/mail-accounts.h new file mode 100644 index 0000000000..9de7ec0f98 --- /dev/null +++ b/mail/mail-accounts.h @@ -0,0 +1,77 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast <fejj@helixcode.com> + * + * Copyright 2001 Helix Code, Inc. (www.helixcode.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef MAIL_ACCOUNTS_H +#define MAIL_ACCOUNTS_H + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#include <gnome.h> +#include <glade/glade.h> +#include <camel.h> + +#define MAIL_ACCOUNTS_DIALOG_TYPE (mail_accounts_dialog_get_type ()) +#define MAIL_ACCOUNTS_DIALOG(o) (GTK_CHECK_CAST ((o), MAIL_ACCOUNTS_DIALOG_TYPE, MailAccountsDialog)) +#define MAIL_ACCOUNTS_DIALOG_CLASS(k) (GTK_CHECK_CLASS_CAST((k), MAIL_ACCOUNTS_DIALOG_TYPE, MailAccountsDialogClass)) +#define IS_MAIL_ACCOUNTS_DIALOG(o) (GTK_CHECK_TYPE ((o), MAIL_ACCOUNTS_DIALOG_TYPE)) +#define IS_MAIL_ACCOUNTS_DIALOG_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), MAIL_ACCOUNTS_DIALOG_TYPE)) + +struct _MailAccountsDialog { + GnomeDialog parent; + + GladeXML *gui; + + const GList *accounts; + GtkClist *mail_accounts; + GtkButton *mail_add; + GtkButton *mail_edit; + GtkButton *mail_delete; + GtkButton *mail_default; + + const GList *news; + GtkClist *news_accounts; + GtkButton *news_add; + GtkButton *news_edit; + GtkButton *news_delete; +}; + +typedef struct _MailAccountsDialog MailAccountsDialog; + +typedef struct { + GnomeDialogClass parent_class; + + /* signals */ + +} MailAccountsDialogClass; + +GtkType mail_accounts_dialog_get_type (void); + +MailAccountsDialog *mail_accounts_dialog_new (void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* MAIL_ACCOUNTS_H */ diff --git a/mail/mail-config-druid.c b/mail/mail-config-druid.c index 788679b3e3..b8f2bbbf8e 100644 --- a/mail/mail-config-druid.c +++ b/mail/mail-config-druid.c @@ -171,7 +171,7 @@ mail_config_create_html (const char *name, const char *str1, const char *str2, } static void -druid_cancel (GtkWidget *widget, gpointer user_data) +druid_cancel (GnomeDruidPage *page, gpointer arg1, gpointer user_data) { /* Cancel the setup of the account */ MailConfigDruid *druid = user_data; @@ -179,6 +179,47 @@ druid_cancel (GtkWidget *widget, gpointer user_data) gtk_widget_destroy (GTK_WIDGET (druid)); } +static void +druid_finish (GnomeDruidPage *page, gpointer arg1, gpointer user_data) +{ + /* Cancel the setup of the account */ + MailConfigDruid *druid = user_data; + MailConfigAccount *account; + MailConfigIdentity *id; + MailConfigService *source; + MailConfigService *transport; + + account = g_new0 (MailConfigAccount, 1); + account->name = mail_config_druid_get_account_name (druid); + account->default = mail_config_druid_get_default_account (druid); + + /* construct the identity */ + id = g_new0 (MailConfigIdentity, 1); + id->name = mail_config_druid_get_full_name (druid); + id->address = mail_config_druid_get_email_address (druid); + id->reply_to = mail_config_druid_get_reply_to (druid); + id->organization = mail_config_druid_get_organization (druid); + id->signature = mail_config_druid_get_sigfile (druid); + + /* construct the source */ + source = g_new0 (MailConfigService, 1); + source->url = mail_config_druid_get_source_url (druid); + source->keep_mail_on_server = mail_config_druid_get_keep_mail_on_server (druid); + source->save_password = mail_config_druid_get_save_password (druid); + + /* construct the transport */ + transport = g_new0 (MailConfigService, 1); + transport->url = mail_config_druid_get_transport_url (druid); + + account->id = id; + account->source = source; + account->transport = transport; + + mail_config_add_accounts (account); + + gtk_widget_destroy (GTK_WIDGET (druid)); +} + /* Identity Page */ static void identity_check (MailConfigDruid *druid) @@ -894,7 +935,7 @@ mail_config_druid_get_transport_url (MailConfigDruid *druid) url = g_new0 (CamelURL, 1); /* FIXME: get the real protocol */ url->protocol = g_strdup ("smtp"); - host = g_strdup (gtk_entry_get_text (druid->incoming_hostname)); + host = g_strdup (gtk_entry_get_text (druid->outgoing_hostname)); if (host && (pport = strchr (host, ':'))) { port = atoi (pport + 1); *pport = '\0'; diff --git a/mail/mail-config-druid.h b/mail/mail-config-druid.h index 814aafc3a4..8301d45c4b 100644 --- a/mail/mail-config-druid.h +++ b/mail/mail-config-druid.h @@ -82,7 +82,6 @@ struct _MailConfigDruid { const CamelProvider *source_provider; const CamelProvider *transport_provider; - }; typedef struct _MailConfigDruid MailConfigDruid; |