aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-cal-config.c
blob: fb1d6c28e7412dd9df14e21ff441940d0712562a (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Authors:
 *      David Trowbridge <trowbrds@cs.colorado.edu>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

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

#include <gtk/gtk.h>
#include "e-cal-config.h"

static GObjectClass *ecp_parent_class;
static GObjectClass *ecph_parent_class;

struct _ECalConfigPrivate {
    guint source_changed_id;
};

#define _PRIVATE(o) (g_type_instance_get_private ((GTypeInstance *)o, e_cal_config_get_type ()))

static void
ecp_init (GObject *o)
{
}

static void
ecp_target_free (EConfig *ec, EConfigTarget *t)
{
    struct _ECalConfigPrivate *p = _PRIVATE (ec);

    if (ec->target == t) {
        switch (t->type) {
        case EC_CONFIG_TARGET_SOURCE: {
            ECalConfigTargetSource *s = (ECalConfigTargetSource *)t;

            if (p->source_changed_id) {
                g_signal_handler_disconnect (s->source, p->source_changed_id);
                p->source_changed_id = 0;
            }
            break; }
        case EC_CONFIG_TARGET_PREFS: {
            /* ECalConfigTargetPrefs *s = (ECalConfigTargetPrefs *)t; */
            break; }
        }
    }

    switch (t->type) {
    case EC_CONFIG_TARGET_SOURCE: {
        ECalConfigTargetSource *s = (ECalConfigTargetSource *)t;
        if (s->source)
            g_object_unref (s->source);
        break; }
    case EC_CONFIG_TARGET_PREFS: {
        ECalConfigTargetPrefs *s = (ECalConfigTargetPrefs *)t;
        if (s->gconf)
            g_object_unref (s->gconf);
        break; }
    }

    ((EConfigClass *) ecp_parent_class)->target_free (ec, t);
}

static void
ecp_source_changed (struct _ESource *source, EConfig *ec)
{
    e_config_target_changed (ec, E_CONFIG_TARGET_CHANGED_STATE);
}

static void
ecp_set_target (EConfig *ec, EConfigTarget *t)
{
    struct _ECalConfigPrivate *p = _PRIVATE(ec);

    ((EConfigClass *)ecp_parent_class)->set_target(ec, t);

    if (t) {
        switch (t->type) {
        case EC_CONFIG_TARGET_SOURCE: {
            ECalConfigTargetSource *s = (ECalConfigTargetSource *)t;

            p->source_changed_id = g_signal_connect (s->source, "changed", G_CALLBACK (ecp_source_changed), ec);
            break; }
        case EC_CONFIG_TARGET_PREFS: {
            /* ECalConfigTargetPrefs *s = (ECalConfigTargetPrefs *)t; */
            break; }
        }
    }
}

static void
ecp_class_init (GObjectClass *klass)
{
    ((EConfigClass *)klass)->set_target = ecp_set_target;
    ((EConfigClass *)klass)->target_free = ecp_target_free;

    g_type_class_add_private (klass, sizeof (struct _ECalConfigPrivate));
}

GType
e_cal_config_get_type (void)
{
    static GType type = 0;

    if (!type) {
        static const GTypeInfo info = {
            sizeof (ECalConfigClass),
            NULL, NULL,
            (GClassInitFunc) ecp_class_init,
            NULL, NULL,
            sizeof (ECalConfig), 0,
            (GInstanceInitFunc) ecp_init
        };

        ecp_parent_class = g_type_class_ref (e_config_get_type ());
        type = g_type_register_static (e_config_get_type (), "ECalConfig", &info, 0);
    }

    return type;
}

ECalConfig *
e_cal_config_new (int type, const char *menuid)
{
    ECalConfig *ecp = g_object_new (e_cal_config_get_type(), NULL);
    e_config_construct (&ecp->config, type, menuid);
    return ecp;
}

ECalConfigTargetSource *
e_cal_config_target_new_source (ECalConfig *ecp, struct _ESource *source)
{
    ECalConfigTargetSource *t = e_config_target_new (&ecp->config, EC_CONFIG_TARGET_SOURCE, sizeof (*t));

    t->source = source;
    g_object_ref (source);

    return t;
}

ECalConfigTargetPrefs *
e_cal_config_target_new_prefs (ECalConfig *ecp, struct _GConfClient *gconf)
{
    ECalConfigTargetPrefs *t = e_config_target_new (&ecp->config, EC_CONFIG_TARGET_PREFS, sizeof (*t));

    t->gconf = gconf;
    if (gconf)
        g_object_ref (gconf);

    return t;
}

static const EConfigHookTargetMask ecph_no_masks[] = {
    { NULL }
};

static const EConfigHookTargetMap ecph_targets[] = {
    { "source", EC_CONFIG_TARGET_SOURCE, ecph_no_masks },
    { "prefs", EC_CONFIG_TARGET_PREFS, ecph_no_masks },
    { NULL },
};

static void
ecph_class_init (EPluginHookClass *klass)
{
    int i;

    klass->id = "org.gnome.evolution.calendar.config:1.0";

    for (i = 0; ecph_targets[i].type; i++) {
        e_config_hook_class_add_target_map ((EConfigHookClass *)klass, &ecph_targets[i]);
    }

    ((EConfigHookClass *)klass)->config_class = g_type_class_ref (e_cal_config_get_type ());
}

GType
e_cal_config_hook_get_type (void)
{
    static GType type = 0;

    if (!type) {
        static const GTypeInfo info = {
            sizeof (ECalConfigHookClass),
            NULL, NULL,
            (GClassInitFunc) ecph_class_init,
            NULL, NULL,
            sizeof (ECalConfigHook), 0,
            (GInstanceInitFunc) NULL
        };

        ecph_parent_class = g_type_class_ref (e_config_hook_get_type ());
        type = g_type_register_static (e_config_hook_get_type (), "ECalConfigHook", &info, 0);
    }

    return type;
}