source: trunk/third/evolution/shell/e-shell-config-default-folders.c @ 18142

Revision 18142, 6.5 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18141, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2/* e-shell-config-default-folders.c - Configuration page for specifying default
3 * folders.
4 *
5 * Copyright (C) 2002 Ximian, Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2 of the GNU General Public
9 * License as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 * Author: Dan Winship <danw@ximian.com>
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include "e-shell-config-default-folders.h"
29
30#include "evolution-folder-selector-button.h"
31
32#include <glade/glade-xml.h>
33#include <gtk/gtktogglebutton.h>
34#include <gtk/gtksignal.h>
35
36#include <libgnome/gnome-i18n.h>
37
38
39typedef struct {
40        GladeXML *glade;
41        EvolutionConfigControl *config_control;
42
43        char *mail_uri, *mail_path;
44        char *contacts_uri, *contacts_path;
45        char *calendar_uri, *calendar_path;
46        char *tasks_uri, *tasks_path;
47
48        Bonobo_ConfigDatabase db;
49        EvolutionShellClient *shell_client;
50} EvolutionDefaultFolderConfig;
51
52static void
53folder_selected (EvolutionFolderSelectorButton *button,
54                 GNOME_Evolution_Folder *folder,
55                 EvolutionDefaultFolderConfig *dfc)
56{
57        char **uri_ptr, **path_ptr;
58
59        uri_ptr = gtk_object_get_data (GTK_OBJECT (button), "uri_ptr");
60        path_ptr = gtk_object_get_data (GTK_OBJECT (button), "path_ptr");
61
62        g_free (*uri_ptr);
63        g_free (*path_ptr);
64        *uri_ptr = g_strdup (folder->physicalUri);
65        *path_ptr = g_strdup (folder->evolutionUri);
66
67        evolution_config_control_changed (dfc->config_control);
68}
69
70GtkWidget *e_shell_config_default_folder_selector_button_new (char *widget_name, char *string1, char *string2, int int1, int int2);
71
72GtkWidget *
73e_shell_config_default_folder_selector_button_new (char *widget_name,
74                                                   char *string1,
75                                                   char *string2,
76                                                   int int1, int int2)
77{
78        return (GtkWidget *)gtk_type_new (EVOLUTION_TYPE_FOLDER_SELECTOR_BUTTON);
79}
80
81static void
82config_control_apply_cb (EvolutionConfigControl *control,
83                         EvolutionDefaultFolderConfig *dfc)
84{
85        bonobo_config_set_string (dfc->db, "/DefaultFolders/mail_path", dfc->mail_path, NULL);
86        bonobo_config_set_string (dfc->db, "/DefaultFolders/mail_uri", dfc->mail_uri, NULL);
87        bonobo_config_set_string (dfc->db, "/DefaultFolders/contacts_path", dfc->contacts_path, NULL);
88        bonobo_config_set_string (dfc->db, "/DefaultFolders/contacts_uri", dfc->contacts_uri, NULL);
89        bonobo_config_set_string (dfc->db, "/DefaultFolders/calendar_path", dfc->calendar_path, NULL);
90        bonobo_config_set_string (dfc->db, "/DefaultFolders/calendar_uri", dfc->calendar_uri, NULL);
91        bonobo_config_set_string (dfc->db, "/DefaultFolders/tasks_path", dfc->tasks_path, NULL);
92        bonobo_config_set_string (dfc->db, "/DefaultFolders/tasks_uri", dfc->tasks_uri, NULL);
93}
94
95static void
96config_control_destroy_cb (EvolutionConfigControl *config_control,
97                           EvolutionDefaultFolderConfig *dfc)
98{
99        g_free (dfc->mail_uri);
100        g_free (dfc->mail_path);
101        g_free (dfc->contacts_uri);
102        g_free (dfc->contacts_path);
103        g_free (dfc->calendar_uri);
104        g_free (dfc->calendar_path);
105        g_free (dfc->tasks_uri);
106        g_free (dfc->tasks_path);
107
108        gtk_object_unref (GTK_OBJECT (dfc->glade));
109        bonobo_object_unref (BONOBO_OBJECT (dfc->shell_client));
110        g_free (dfc);
111}
112
113static const char *mail_types[] = { "mail", NULL };
114static const char *contacts_types[] = { "contacts", "contacts/ldap", NULL };
115static const char *calendar_types[] = { "calendar", NULL };
116static const char *tasks_types[] = { "tasks", NULL };
117
118static void
119setup_folder_selector (EvolutionDefaultFolderConfig *dfc,
120                       const char *widget_name,
121                       char **path_ptr, char *path_dbpath,
122                       char **uri_ptr, char *uri_dbpath,
123                       const char **types)
124{
125        GtkWidget *button;
126
127        *path_ptr = bonobo_config_get_string (dfc->db, path_dbpath, NULL);
128        *uri_ptr = bonobo_config_get_string (dfc->db, uri_dbpath, NULL);
129
130        button = glade_xml_get_widget (dfc->glade, widget_name);
131        evolution_folder_selector_button_construct (
132                EVOLUTION_FOLDER_SELECTOR_BUTTON (button),
133                dfc->shell_client, _("Select Default Folder"),
134                *uri_ptr, types);
135        gtk_object_set_data (GTK_OBJECT (button), "uri_ptr", uri_ptr);
136        gtk_object_set_data (GTK_OBJECT (button), "path_ptr", path_ptr);
137        gtk_signal_connect (GTK_OBJECT (button), "selected",
138                            GTK_SIGNAL_FUNC (folder_selected),
139                            dfc);
140}
141
142GtkWidget*
143e_shell_config_default_folders_create_widget (EShell *shell, EvolutionConfigControl *config_control)
144{
145        GNOME_Evolution_Shell shell_dup;
146        CORBA_Environment ev;
147        EvolutionDefaultFolderConfig *dfc;
148        GtkWidget *widget;
149
150        dfc = g_new0 (EvolutionDefaultFolderConfig, 1);
151        dfc->db = e_shell_get_config_db (shell);
152
153        CORBA_exception_init (&ev);
154        shell_dup = CORBA_Object_duplicate (bonobo_object_corba_objref (BONOBO_OBJECT (shell)), &ev);
155        CORBA_exception_free (&ev);
156        dfc->shell_client = evolution_shell_client_new (shell_dup);
157
158        dfc->glade = glade_xml_new (EVOLUTION_GLADEDIR "/e-shell-config-default-folders.glade", NULL);
159
160        setup_folder_selector (dfc, "default_mail_button",
161                               &dfc->mail_path, "/DefaultFolders/mail_path",
162                               &dfc->mail_uri, "/DefaultFolders/mail_uri",
163                               mail_types);
164        setup_folder_selector (dfc, "default_contacts_button",
165                               &dfc->contacts_path, "/DefaultFolders/contacts_path",
166                               &dfc->contacts_uri, "/DefaultFolders/contacts_uri",
167                               contacts_types);
168        setup_folder_selector (dfc, "default_calendar_button",
169                               &dfc->calendar_path, "/DefaultFolders/calendar_path",
170                               &dfc->calendar_uri, "/DefaultFolders/calendar_uri",
171                               calendar_types);
172        setup_folder_selector (dfc, "default_tasks_button",
173                               &dfc->tasks_path, "/DefaultFolders/tasks_path",
174                               &dfc->tasks_uri, "/DefaultFolders/tasks_uri",
175                               tasks_types);
176
177        widget = glade_xml_get_widget (dfc->glade, "default_folders_table");
178        gtk_widget_ref (widget);
179        gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
180        gtk_widget_show (widget);
181        dfc->config_control = config_control;
182
183        gtk_signal_connect (GTK_OBJECT (dfc->config_control), "apply",
184                            GTK_SIGNAL_FUNC (config_control_apply_cb), dfc);
185        gtk_signal_connect (GTK_OBJECT (dfc->config_control), "destroy",
186                            GTK_SIGNAL_FUNC (config_control_destroy_cb), dfc);
187
188        return widget;
189}
Note: See TracBrowser for help on using the repository browser.