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

Revision 18142, 5.9 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-offline.c - Configuration page for offline synchronization.
3 *
4 * Copyright (C) 2002 Ximian, Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 *
20 * Author: Ettore Perazzoli <ettore@ximian.com>
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27
28#include "e-shell-config-offline.h"
29
30#include "evolution-config-control.h"
31#include "e-storage-set-view.h"
32
33#include "Evolution.h"
34
35#include <bonobo-conf/Bonobo_Config.h>
36#include <bonobo/bonobo-exception.h>
37
38#include <gal/widgets/e-scroll-frame.h>
39#include <gtk/gtkwidget.h>
40
41
42struct _PageData {
43        EShell *shell;
44        GtkWidget *storage_set_view;
45        EvolutionConfigControl *config_control;
46};
47typedef struct _PageData PageData;
48
49
50/* Callbacks.  */
51
52static void
53config_control_destroy_callback (GtkObject *object,
54                                 void *data)
55{
56        PageData *page_data;
57
58        page_data = (PageData *) data;
59        gtk_widget_destroy (page_data->storage_set_view);
60        g_free (page_data);
61}
62
63static void
64config_control_apply_callback (EvolutionConfigControl *config_control,
65                               void *data)
66{
67        CORBA_Environment ev;
68        CORBA_sequence_CORBA_string *paths;
69        CORBA_any any;
70        PageData *page_data;
71        GList *checked_paths;
72        GList *p;
73        int i;
74
75        page_data = (PageData *) data;
76
77        checked_paths = e_storage_set_view_get_checkboxes_list (E_STORAGE_SET_VIEW (page_data->storage_set_view));
78
79        paths = CORBA_sequence_CORBA_string__alloc ();
80        paths->_maximum = paths->_length = g_list_length (checked_paths);
81        paths->_buffer = CORBA_sequence_CORBA_string_allocbuf (paths->_maximum);
82
83        CORBA_sequence_set_release (paths, TRUE);
84
85        for (p = checked_paths, i = 0; p != NULL; p = p->next, i ++)
86                paths->_buffer[i] = CORBA_string_dup ((const char *) p->data);
87
88        any._type = TC_CORBA_sequence_CORBA_string;
89        any._value = paths;
90
91        CORBA_exception_init (&ev);
92
93        Bonobo_ConfigDatabase_setValue (e_shell_get_config_db (page_data->shell),
94                                        "/OfflineFolders/paths", &any, &ev);
95        if (BONOBO_EX (&ev))
96                g_warning ("Cannot set /OfflineFolders/paths from ConfigDatabase -- %s", BONOBO_EX_ID (&ev));
97
98        CORBA_exception_free (&ev);
99
100        g_list_free (checked_paths);
101}
102
103static void
104storage_set_view_checkboxes_changed_callback (EStorageSetView *storage_set_view,
105                                              void *data)
106{
107        PageData *page_data;
108
109        page_data = (PageData *) data;
110        evolution_config_control_changed (page_data->config_control);
111}
112
113
114/* Construction.  */
115
116static void
117init_storage_set_view_status_from_config (EStorageSetView *storage_set_view,
118                                          EShell *shell)
119{
120        Bonobo_ConfigDatabase config_db;
121        CORBA_Environment ev;
122        CORBA_any *any;
123        CORBA_sequence_CORBA_string *sequence;
124        GList *list;
125        int i;
126
127        config_db = e_shell_get_config_db (shell);
128        g_assert (config_db != CORBA_OBJECT_NIL);
129
130        CORBA_exception_init (&ev);
131
132        any = Bonobo_ConfigDatabase_getValue (config_db, "/OfflineFolders/paths", "", &ev);
133        if (BONOBO_EX (&ev)) {
134                g_warning ("Cannot get /OfflineFolders/paths from ConfigDatabase -- %s", BONOBO_EX_ID (&ev));
135                CORBA_exception_free (&ev);
136                return;
137        }
138
139        if (! CORBA_TypeCode_equal (any->_type, TC_CORBA_sequence_CORBA_string, &ev) || BONOBO_EX (&ev)) {
140                g_warning ("/OfflineFolders/Paths in ConfigDatabase is not the expected type");
141                CORBA_free (any);
142                CORBA_exception_free (&ev);
143                return;
144        }
145
146        sequence = (CORBA_sequence_CORBA_string *) any->_value;
147
148        list = NULL;
149        for (i = 0; i < sequence->_length; i ++)
150                list = g_list_prepend (list, sequence->_buffer[i]);
151
152        e_storage_set_view_set_checkboxes_list (storage_set_view, list);
153
154        g_list_free (list);
155        CORBA_free (any);
156
157        CORBA_exception_free (&ev);
158}
159
160static gboolean
161storage_set_view_has_checkbox_func (EStorageSet *storage_set,
162                                    const char *path,
163                                    void *data)
164{
165        EFolder *folder;
166
167        folder = e_storage_set_get_folder (storage_set, path);
168        if (folder == NULL)
169                return FALSE;
170
171        return e_folder_get_can_sync_offline (folder);
172}
173
174GtkWidget *
175e_shell_config_offline_create_widget (EShell *shell, EvolutionConfigControl *control)
176{
177        PageData *page_data;
178        GtkWidget *scroll_frame;
179
180        g_return_val_if_fail (E_IS_SHELL (shell), NULL);
181
182        page_data = g_new (PageData, 1);
183        page_data->shell = shell;
184
185        page_data->storage_set_view = e_storage_set_create_new_view (e_shell_get_storage_set (shell), NULL);
186        e_storage_set_view_set_show_checkboxes (E_STORAGE_SET_VIEW (page_data->storage_set_view), TRUE,
187                                                storage_set_view_has_checkbox_func, NULL);
188        gtk_widget_show (page_data->storage_set_view);
189
190        init_storage_set_view_status_from_config (E_STORAGE_SET_VIEW (page_data->storage_set_view), shell);
191        gtk_signal_connect (GTK_OBJECT (page_data->storage_set_view), "checkboxes_changed",
192                            GTK_SIGNAL_FUNC (storage_set_view_checkboxes_changed_callback), page_data);
193
194        scroll_frame = e_scroll_frame_new (NULL, NULL);
195        e_scroll_frame_set_shadow_type (E_SCROLL_FRAME (scroll_frame), GTK_SHADOW_IN);
196        e_scroll_frame_set_policy (E_SCROLL_FRAME (scroll_frame),
197                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
198        gtk_container_add (GTK_CONTAINER (scroll_frame), page_data->storage_set_view);
199        gtk_widget_show (scroll_frame);
200
201        page_data->config_control = control;
202
203        gtk_signal_connect (GTK_OBJECT (page_data->config_control), "destroy",
204                            GTK_SIGNAL_FUNC (config_control_destroy_callback), page_data);
205        gtk_signal_connect (GTK_OBJECT (page_data->config_control), "apply",
206                            GTK_SIGNAL_FUNC (config_control_apply_callback), page_data);
207
208        return scroll_frame;
209}
Note: See TracBrowser for help on using the repository browser.