aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/backend/pas/pas-card-cursor.c
blob: 9637bb1fb753e2feb8d7f8f2fb00f2e98c58282f (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * pas-card-cursor.c: Implements card cursors.
 *
 * Author:
 *   Christopher James Lahey <clahey@ximian.com.
 */

#include <config.h>
#include <bonobo/bonobo-main.h>
#include "addressbook.h"
#include "pas-card-cursor.h"

struct _PASCardCursorPrivate {
    long     (*get_length) (PASCardCursor *cursor, gpointer data);
    char *   (*get_nth)    (PASCardCursor *cursor, long n, gpointer data);
    gpointer   data;
};

/*
 * A pointer to our parent object class
 */
static BonoboObjectClass *parent_class;

/*
 * Implemented GObject::dispose
 */
static void
pas_card_cursor_dispose (GObject *object)
{
    PASCardCursor *cursor = PAS_CARD_CURSOR (object);

    if ( cursor->priv ) {
        g_free ( cursor->priv );
        cursor->priv = NULL;
    }

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

/*
 * CORBA Demo::Echo::echo method implementation
 */
static CORBA_long
impl_pas_card_cursor_get_length (PortableServer_Servant  servant,
                   CORBA_Environment      *ev)
{
    PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object (servant));
    if ( cursor->priv->get_length )
        return cursor->priv->get_length( cursor, cursor->priv->data );
    else
        return 0;
}

/*
 * CORBA Demo::Echo::echo method implementation
 */
static char *
impl_pas_card_cursor_get_nth (PortableServer_Servant  servant,
                const CORBA_long        n,
                CORBA_Environment      *ev)
{
    PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object (servant));
    if ( cursor->priv->get_nth ) {
        char *vcard = cursor->priv->get_nth( cursor, n, cursor->priv->data );
        char *retval = CORBA_string_dup (vcard);
        g_free (vcard);
        return retval;
    } else
        return CORBA_string_dup ("");
}

static void
pas_card_cursor_class_init (PASCardCursorClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    POA_GNOME_Evolution_Addressbook_CardCursor__epv *epv;

    parent_class = g_type_class_peek_parent (klass);

    object_class->dispose = pas_card_cursor_dispose;


    epv = &klass->epv;

    epv->count  = impl_pas_card_cursor_get_length;
    epv->getNth = impl_pas_card_cursor_get_nth;
}

static void
pas_card_cursor_init (PASCardCursor *cursor)
{
    cursor->priv = g_new0(PASCardCursorPrivate, 1);
    cursor->priv->get_length = NULL;
    cursor->priv->get_nth = NULL;
    cursor->priv->data = NULL;
}

static void
pas_card_cursor_construct (PASCardCursor           *cursor,
               PASCardCursorLengthFunc  get_length,
               PASCardCursorNthFunc     get_nth,
               gpointer data)
{
    PASCardCursorPrivate *priv;

    g_return_if_fail (cursor != NULL);
    g_return_if_fail (PAS_IS_CARD_CURSOR (cursor));

    priv = cursor->priv;

    priv->get_length   = get_length;
    priv->get_nth = get_nth;
    priv->data = data;
}

PASCardCursor *
pas_card_cursor_new (PASCardCursorLengthFunc  get_length,
             PASCardCursorNthFunc     get_nth,
             gpointer data)
{
    PASCardCursor *cursor;

    cursor = g_object_new (PAS_TYPE_CARD_CURSOR, NULL);

    pas_card_cursor_construct (cursor,
                   get_length,
                   get_nth,
                   data);

    return cursor;
}

BONOBO_TYPE_FUNC_FULL (
               PASCardCursor,
               GNOME_Evolution_Addressbook_CardCursor,
               BONOBO_TYPE_OBJECT,
               pas_card_cursor);