aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-shell-config-autocompletion.c
blob: 51c6728dc82989c31f64ea3164100b1d39088fd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-shell-config-autocompletion.c - Configuration page for addressbook autocompletion.
 *
 * Copyright (C) 2002 Ximian, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * 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 Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Authors: Chris Lahey <clahey@ximian.com>
 *          Chris Toshok <toshok@ximian.com>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif


#include "e-shell-config-autocompletion.h"

#include "e-folder-list.h"

#include "Evolution.h"

#include <bonobo/bonobo-exception.h>

#include <libgnome/gnome-i18n.h>
#include <gtk/gtkwidget.h>
#include <gtk/gtksignal.h>


typedef struct {
    EvolutionConfigControl *config_control;

    GtkWidget *control_widget;

    EConfigListener *config_listener;
    EvolutionShellClient *shell_client;
} EvolutionAutocompletionConfig;

static void
folder_list_changed_callback (EFolderList *efl,
                  EvolutionAutocompletionConfig *ac)
{
    evolution_config_control_changed (ac->config_control);
}

static void
config_control_destroy_callback (EvolutionConfigControl *config_control,
                 EvolutionAutocompletionConfig *ac)
{
    bonobo_object_unref (BONOBO_OBJECT (ac->shell_client));

    g_object_unref (ac->config_listener);

    g_free (ac);
}


static void
config_control_apply_callback (EvolutionConfigControl *config_control,
                   EvolutionAutocompletionConfig *ac)
{
    char *xml;

    xml = e_folder_list_get_xml (E_FOLDER_LIST (ac->control_widget));
    e_config_listener_set_string (ac->config_listener, "/Addressbook/Completion/uris", xml);
    g_free (xml);
}

GtkWidget *
e_shell_config_autocompletion_create_widget (EShell *shell, EvolutionConfigControl *config_control)
{
    GNOME_Evolution_Shell shell_dup;
    EvolutionAutocompletionConfig *ac;
    char *xml;
    CORBA_Environment ev;
    static const char *possible_types[] = { "contacts/*", NULL };

    ac = g_new0 (EvolutionAutocompletionConfig, 1);
    ac->config_listener = e_config_listener_new ();

    CORBA_exception_init (&ev);

    shell_dup = CORBA_Object_duplicate (bonobo_object_corba_objref (BONOBO_OBJECT (shell)), &ev);
    ac->shell_client = evolution_shell_client_new (shell_dup);

    xml = e_config_listener_get_string_with_default (ac->config_listener,
                             "/Addressbook/Completion/uris",
                             NULL, NULL);

    ac->control_widget = e_folder_list_new (ac->shell_client, xml);
    g_free (xml);

    gtk_object_set (GTK_OBJECT (ac->control_widget),
            "title", _("Extra Completion folders"),
            "possible_types", possible_types,
            NULL);

    gtk_widget_show (ac->control_widget);

    ac->config_control = config_control;

    gtk_signal_connect (GTK_OBJECT (ac->control_widget), "changed",
                GTK_SIGNAL_FUNC (folder_list_changed_callback), ac);
    gtk_signal_connect (GTK_OBJECT (ac->config_control), "apply",
                GTK_SIGNAL_FUNC (config_control_apply_callback), ac);
    gtk_signal_connect (GTK_OBJECT (ac->config_control), "destroy",
                GTK_SIGNAL_FUNC (config_control_destroy_callback), ac);

    CORBA_exception_free (&ev);

    return ac->control_widget;
}