source: trunk/third/evolution/mail/mail-account-editor.c @ 16787

Revision 16787, 5.2 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16786, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 *  Authors:
4 *    Jeffrey Stedfast <fejj@ximian.com>
5 *    Dan Winship <danw@ximian.com>
6 *
7 *  Copyright 2001 Ximian, Inc. (www.ximian.com)
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 *
23 */
24
25#ifdef HAVE_CONFIG_H
26#include <config.h>
27#endif
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <libgnomeui/gnome-messagebox.h>
33#include <libgnomeui/gnome-stock.h>
34#include <camel/camel-url.h>
35#include <gal/widgets/e-unicode.h>
36#include <gal/widgets/e-gui-utils.h>
37
38#include "mail-account-editor.h"
39#include "mail-session.h"
40
41static void mail_account_editor_class_init (MailAccountEditorClass *class);
42static void mail_account_editor_finalize   (GtkObject *obj);
43
44static GnomeDialogClass *parent_class;
45
46
47GtkType
48mail_account_editor_get_type ()
49{
50        static GtkType type = 0;
51
52        if (!type) {
53                GtkTypeInfo type_info = {
54                        "MailAccountEditor",
55                        sizeof (MailAccountEditor),
56                        sizeof (MailAccountEditorClass),
57                        (GtkClassInitFunc) mail_account_editor_class_init,
58                        (GtkObjectInitFunc) NULL,
59                        (GtkArgSetFunc) NULL,
60                        (GtkArgGetFunc) NULL
61                };
62
63                type = gtk_type_unique (gnome_dialog_get_type (), &type_info);
64        }
65
66        return type;
67}
68
69static void
70mail_account_editor_class_init (MailAccountEditorClass *class)
71{
72        GtkObjectClass *object_class;
73       
74        object_class = (GtkObjectClass *) class;
75        parent_class = gtk_type_class (gnome_dialog_get_type ());
76       
77        object_class->finalize = mail_account_editor_finalize;
78}
79
80static void
81mail_account_editor_finalize (GtkObject *obj)
82{
83        MailAccountEditor *editor = (MailAccountEditor *) obj;
84       
85        mail_account_gui_destroy (editor->gui);
86        ((GtkObjectClass *)(parent_class))->finalize (obj);
87}
88
89static gboolean
90apply_changes (MailAccountEditor *editor)
91{
92        MailConfigAccount *account;
93        GtkWidget *incomplete;
94        int page = -1;
95       
96        if (!mail_account_gui_identity_complete (editor->gui, &incomplete) ||
97            !mail_account_gui_management_complete (editor->gui, &incomplete))
98                page = 0;
99        else if (!mail_account_gui_source_complete (editor->gui, &incomplete))
100                page = 1;
101        else if (!mail_account_gui_transport_complete (editor->gui, &incomplete))
102                page = 3;
103       
104        if (page != -1) {
105                gtk_notebook_set_page (editor->notebook, page);
106                gtk_widget_grab_focus (incomplete);
107                e_notice (NULL, GNOME_MESSAGE_BOX_ERROR, _("You have not filled in all of the required information."));
108                return FALSE;
109        }
110       
111        if (mail_account_gui_save (editor->gui) == FALSE)
112                return FALSE;
113       
114        /* save any changes we may have */
115        mail_config_write ();
116       
117        /* FIXME: #1549: if the account was a remote store, delete it from the folder-tree and re-add it */
118        /* FIXME: preferably, we'd only do this if there were changes... oh well */
119       
120        return TRUE;
121}
122
123static void
124apply_clicked (GtkWidget *widget, gpointer data)
125{
126        MailAccountEditor *editor = data;
127       
128        apply_changes (editor);
129}
130
131static void
132ok_clicked (GtkWidget *widget, gpointer data)
133{
134        MailAccountEditor *editor = data;
135
136        if (apply_changes (editor))
137                gtk_widget_destroy (GTK_WIDGET (editor));
138}
139
140static void
141cancel_clicked (GtkWidget *widget, gpointer data)
142{
143        MailAccountEditor *editor = data;
144
145        gtk_widget_destroy (GTK_WIDGET (editor));
146}
147
148static void
149construct (MailAccountEditor *editor, MailConfigAccount *account)
150{
151        MailConfigService *source = account->source;
152       
153        editor->gui = mail_account_gui_new (account);
154       
155        /* get our toplevel widget and reparent it */
156        editor->notebook = GTK_NOTEBOOK (glade_xml_get_widget (editor->gui->xml, "account_editor_notebook"));
157        gtk_widget_reparent (GTK_WIDGET (editor->notebook), GNOME_DIALOG (editor)->vbox);
158       
159        /* give our dialog an OK button and title */
160        gtk_window_set_title (GTK_WINDOW (editor), _("Evolution Account Editor"));
161        gtk_window_set_policy (GTK_WINDOW (editor), FALSE, TRUE, TRUE);
162        gtk_window_set_modal (GTK_WINDOW (editor), FALSE);
163        gnome_dialog_append_buttons (GNOME_DIALOG (editor),
164                                     GNOME_STOCK_BUTTON_OK,
165                                     GNOME_STOCK_BUTTON_APPLY,
166                                     GNOME_STOCK_BUTTON_CANCEL,
167                                     NULL);
168       
169        gnome_dialog_button_connect (GNOME_DIALOG (editor), 0 /* OK */,
170                                     GTK_SIGNAL_FUNC (ok_clicked),
171                                     editor);
172        gnome_dialog_button_connect (GNOME_DIALOG (editor), 1 /* APPLY */,
173                                     GTK_SIGNAL_FUNC (apply_clicked),
174                                     editor);
175        gnome_dialog_button_connect (GNOME_DIALOG (editor), 2 /* CANCEL */,
176                                     GTK_SIGNAL_FUNC (cancel_clicked),
177                                     editor);
178       
179        mail_account_gui_setup (editor->gui, GTK_WIDGET (editor));
180       
181        mail_account_gui_build_extra_conf (editor->gui, source->url);
182}
183
184MailAccountEditor *
185mail_account_editor_new (MailConfigAccount *account)
186{
187        MailAccountEditor *new;
188       
189        new = (MailAccountEditor *) gtk_type_new (mail_account_editor_get_type ());
190        construct (new, account);
191       
192        return new;
193}
Note: See TracBrowser for help on using the repository browser.