aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mail-remote/evolution-mail-listener.c
blob: 842edf4f4f8434954b42fd8470de22a27c403cf2 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* 
 * Copyright (C) 2005  Novell, 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.
 *
 * Author: Michael Zucchi <notzed@novell.com>
 */

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

#include <errno.h>
#include <string.h>
#include <bonobo/bonobo-shlib-factory.h>
#include <bonobo/bonobo-control.h>
#include <bonobo/bonobo-i18n.h>
#include <bonobo/bonobo-exception.h>
#include "evolution-mail-listener.h"

#include "evolution-mail-store.h"

#include "evolution-mail-marshal.h"

#define PARENT_TYPE bonobo_object_get_type ()

static BonoboObjectClass *parent_class = NULL;

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

struct _EvolutionMailListenerPrivate {
    int dummy;
};

enum {
    EML_SESSION_CHANGED,
    EML_STORE_CHANGED,
    EML_FOLDER_CHANGED,
    EML_LAST_SIGNAL
};

static guint eml_signals[EML_LAST_SIGNAL];

/* GObject methods */

static void
impl_dispose (GObject *object)
{
    struct _EvolutionMailListenerPrivate *p = _PRIVATE(object);

    p = p;

    (* G_OBJECT_CLASS (parent_class)->dispose) (object);
}

static void
impl_finalize (GObject *object)
{
    printf("EvolutionMailListener finalised!\n");

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

/* Evolution.Mail.Listener */
static const char *change_type_name(int type)
{
    switch (type) {
    case GNOME_Evolution_Mail_ADDED:
        return "added";
        break;
    case GNOME_Evolution_Mail_CHANGED:
        return "changed";
        break;
    case GNOME_Evolution_Mail_REMOVED:
        return "removed";
        break;
    default:
        return "";
    }
}

static void
impl_sessionChanged(PortableServer_Servant _servant,
            const GNOME_Evolution_Mail_Session session,
            const GNOME_Evolution_Mail_SessionChanges *changes, CORBA_Environment * ev)
{
    EvolutionMailListener *eml = (EvolutionMailListener *)bonobo_object_from_servant(_servant);
    int i, j;

    printf("session changed!\n");
    for (i=0;i<changes->_length;i++) {
        printf(" %d %s", changes->_buffer[i].stores._length, change_type_name(changes->_buffer[i].type));
        for (j=0;j<changes->_buffer[i].stores._length;j++) {
            printf(" %s %s\n", changes->_buffer[i].stores._buffer[j].uid, changes->_buffer[i].stores._buffer[j].name);
        }
    }

    g_signal_emit(eml, eml_signals[EML_SESSION_CHANGED], 0, session, changes);
}

static void
impl_storeChanged(PortableServer_Servant _servant,
          const GNOME_Evolution_Mail_Session session,
          const GNOME_Evolution_Mail_Store store,
          const GNOME_Evolution_Mail_StoreChanges * changes,
          CORBA_Environment * ev)
{
    EvolutionMailListener *eml = (EvolutionMailListener *)bonobo_object_from_servant(_servant);
    int i, j;

    printf("store changed!\n");
    for (i=0;i<changes->_length;i++) {
        printf(" %d %s", changes->_buffer[i].folders._length, change_type_name(changes->_buffer[i].type));
        for (j=0;j<changes->_buffer[i].folders._length;j++) {
            printf(" %s %s\n", changes->_buffer[i].folders._buffer[j].full_name, changes->_buffer[i].folders._buffer[j].name);
        }
    }

    g_signal_emit(eml, eml_signals[EML_STORE_CHANGED], 0, session, store, changes);
}

static void
impl_folderChanged(PortableServer_Servant _servant,
           const GNOME_Evolution_Mail_Session session,
           const GNOME_Evolution_Mail_Store store,
           const GNOME_Evolution_Mail_Folder folder,
           const GNOME_Evolution_Mail_FolderChanges *changes, CORBA_Environment * ev)
{
    EvolutionMailListener *eml = (EvolutionMailListener *)bonobo_object_from_servant(_servant);
    int i, j;

    printf("folder changed!\n");
    for (i=0;i<changes->_length;i++) {
        printf(" %d %s", changes->_buffer[i].messages._length, change_type_name(changes->_buffer[i].type));
        for (j=0;j<changes->_buffer[i].messages._length;j++) {
            printf(" %s %s\n", changes->_buffer[i].messages._buffer[j].uid, changes->_buffer[i].messages._buffer[j].subject);
        }
    }

    g_signal_emit(eml, eml_signals[EML_STORE_CHANGED], 0, session, store, folder, changes);
}

/* Initialization */

static void
evolution_mail_listener_class_init (EvolutionMailListenerClass *klass)
{
    POA_GNOME_Evolution_Mail_Listener__epv *epv = &klass->epv;
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    parent_class = g_type_class_peek_parent (klass);

    epv->sessionChanged = impl_sessionChanged;
    epv->storeChanged = impl_storeChanged;
    epv->folderChanged = impl_folderChanged;

    object_class->dispose = impl_dispose;
    object_class->finalize = impl_finalize;

    g_type_class_add_private(klass, sizeof(struct _EvolutionMailListenerPrivate));

    eml_signals[EML_SESSION_CHANGED] =
        g_signal_new("session-changed",
                 G_OBJECT_CLASS_TYPE (klass),
                 G_SIGNAL_RUN_LAST,
                 G_STRUCT_OFFSET (EvolutionMailListenerClass, session_changed),
                 NULL, NULL,
                 evolution_mail_marshal_VOID__POINTER_POINTER,
                 G_TYPE_NONE, 2,
                 G_TYPE_POINTER, G_TYPE_POINTER);

    eml_signals[EML_STORE_CHANGED] =
        g_signal_new("store-changed",
                 G_OBJECT_CLASS_TYPE (klass),
                 G_SIGNAL_RUN_LAST,
                 G_STRUCT_OFFSET (EvolutionMailListenerClass, store_changed),
                 NULL, NULL,
                 evolution_mail_marshal_VOID__POINTER_POINTER_POINTER,
                 G_TYPE_NONE, 3,
                 G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);

    eml_signals[EML_FOLDER_CHANGED] =
        g_signal_new("folder-changed",
                 G_OBJECT_CLASS_TYPE (klass),
                 G_SIGNAL_RUN_LAST,
                 G_STRUCT_OFFSET (EvolutionMailListenerClass, folder_changed),
                 NULL, NULL,
                 evolution_mail_marshal_VOID__POINTER_POINTER_POINTER_POINTER,
                 G_TYPE_NONE, 4,
                 G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
}

static void
evolution_mail_listener_init (EvolutionMailListener *ems, EvolutionMailListenerClass *klass)
{
    struct _EvolutionMailListenerPrivate *p = _PRIVATE(ems);

    p = p;
}

EvolutionMailListener *
evolution_mail_listener_new(void)
{
    EvolutionMailListener *eml;
#if 0
    static PortableServer_POA poa = NULL;

    /* NB: to simplify signal handling, we should only run in the idle loop? */

    if (poa == NULL)
        poa = bonobo_poa_get_threaded (ORBIT_THREAD_HINT_PER_REQUEST, NULL);
    eml = g_object_new(evolution_mail_listener_get_type(), "poa", poa, NULL);
#else
    eml = g_object_new(evolution_mail_listener_get_type(), NULL);
#endif
    return eml;
}

BONOBO_TYPE_FUNC_FULL (EvolutionMailListener, GNOME_Evolution_Mail_Listener, PARENT_TYPE, evolution_mail_listener)