aboutsummaryrefslogtreecommitdiffstats
path: root/shell/importer/evolution-intelligent-importer.c
blob: d867c120b8d7b34a92911c8dd4b1e7b28da72521 (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
/*
 * 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:
 *      Iain Holmes  <iain@ximian.com>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

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

#include "evolution-intelligent-importer.h"

#include <bonobo/bonobo-object.h>

#include "GNOME_Evolution_Importer.h"

#define PARENT_TYPE BONOBO_OBJECT_TYPE
static BonoboObjectClass *parent_class = NULL;

struct _EvolutionIntelligentImporterPrivate {
    EvolutionIntelligentImporterCanImportFn can_import_fn;
    EvolutionIntelligentImporterImportDataFn import_data_fn;

    char *importername;
    char *message;
    void *closure;
};


static inline EvolutionIntelligentImporter *
evolution_intelligent_importer_from_servant (PortableServer_Servant servant)
{
    return EVOLUTION_INTELLIGENT_IMPORTER (bonobo_object_from_servant (servant));
}

static CORBA_char *
impl_GNOME_Evolution_IntelligentImporter__get_importername (PortableServer_Servant servant,
                                CORBA_Environment *ev)
{
    EvolutionIntelligentImporter *ii;

    ii = evolution_intelligent_importer_from_servant (servant);

    return CORBA_string_dup (ii->priv->importername ?
                 ii->priv->importername : "");
}

static CORBA_char *
impl_GNOME_Evolution_IntelligentImporter__get_message (PortableServer_Servant servant,
                               CORBA_Environment *ev)
{
    EvolutionIntelligentImporter *ii;

    ii = evolution_intelligent_importer_from_servant (servant);

    return CORBA_string_dup (ii->priv->message ?
                 ii->priv->message : "");
}

static CORBA_boolean
impl_GNOME_Evolution_IntelligentImporter_canImport (PortableServer_Servant servant,
                            CORBA_Environment *ev)
{
    EvolutionIntelligentImporter *ii;
    EvolutionIntelligentImporterPrivate *priv;

    ii = evolution_intelligent_importer_from_servant (servant);
    priv = ii->priv;

    if (priv->can_import_fn != NULL)
        return (priv->can_import_fn) (ii, priv->closure);
    else
        return FALSE;
}

static void
impl_GNOME_Evolution_IntelligentImporter_importData (PortableServer_Servant servant,
                             CORBA_Environment *ev)
{
    EvolutionIntelligentImporter *ii;
    EvolutionIntelligentImporterPrivate *priv;

    ii = evolution_intelligent_importer_from_servant (servant);
    priv = ii->priv;

    if (priv->import_data_fn)
        (priv->import_data_fn) (ii, priv->closure);
}


static void
finalise (GObject *object)
{
    EvolutionIntelligentImporter *ii;

    ii = EVOLUTION_INTELLIGENT_IMPORTER (object);

    if (ii->priv == NULL)
        return;

    g_free (ii->priv->importername);
    g_free (ii->priv);
    ii->priv = NULL;

    G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
evolution_intelligent_importer_class_init (EvolutionIntelligentImporterClass *klass)
{
    GObjectClass *object_class;
    POA_GNOME_Evolution_IntelligentImporter__epv *epv = &klass->epv;

    object_class = G_OBJECT_CLASS (klass);
    object_class->finalize = finalise;

    parent_class = g_type_class_ref(PARENT_TYPE);
    epv->_get_importername = impl_GNOME_Evolution_IntelligentImporter__get_importername;
    epv->_get_message = impl_GNOME_Evolution_IntelligentImporter__get_message;
    epv->canImport = impl_GNOME_Evolution_IntelligentImporter_canImport;
    epv->importData = impl_GNOME_Evolution_IntelligentImporter_importData;
}

static void
evolution_intelligent_importer_init (EvolutionIntelligentImporter *ii)
{
    ii->priv = g_new0 (EvolutionIntelligentImporterPrivate, 1);
}


static void
evolution_intelligent_importer_construct (EvolutionIntelligentImporter *ii,
                      EvolutionIntelligentImporterCanImportFn can_import_fn,
                      EvolutionIntelligentImporterImportDataFn import_data_fn,
                      const char *importername,
                      const char *message,
                      void *closure)
{
    g_return_if_fail (ii != NULL);
    ii->priv->importername = g_strdup (importername);
    ii->priv->message = g_strdup (message);

    ii->priv->can_import_fn = can_import_fn;
    ii->priv->import_data_fn = import_data_fn;
    ii->priv->closure = closure;
}

/**
 * evolution_intelligent_importer_new:
 * can_import_fn: The function that will be called to see if this importer can do
 * anything.
 * import_data_fn: The function that will be called when the importer should
 * import the data.
 * importername: The name of this importer.
 * message: The message that will be displayed when the importer can import.
 * closure: The data to be passed to @can_import_fn and @import_data_fn.
 *
 * Creates a new IntelligentImporter.
 *
 * Returns: A newly allocated EvolutionIntelligentImporter.
 */
EvolutionIntelligentImporter *
evolution_intelligent_importer_new (EvolutionIntelligentImporterCanImportFn can_import_fn,
                    EvolutionIntelligentImporterImportDataFn import_data_fn,
                    const char *importername,
                    const char *message,
                    void *closure)
{
    EvolutionIntelligentImporter *ii;

    ii = g_object_new (evolution_intelligent_importer_get_type (), NULL);
    evolution_intelligent_importer_construct (ii, can_import_fn,
                          import_data_fn, importername,
                          message, closure);
    return ii;
}

BONOBO_TYPE_FUNC_FULL (EvolutionIntelligentImporter,
               GNOME_Evolution_IntelligentImporter,
               PARENT_TYPE,
               evolution_intelligent_importer);