summaryrefslogtreecommitdiff
path: root/src/vcard-manager.h
blob: 7c4cb44d93ca028dd7e60a252ac83ed69fa02a7e (plain)
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
/*
 * vcard-manager.h - vCard lookup helper for Gabble connections
 *
 * Copyright (C) 2006-2010 Collabora Ltd.
 * Copyright (C) 2006-2010 Nokia Corporation
 *
 * This library 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.1 of the License, or (at your option) any later version.
 *
 * This library 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 this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef __GABBLE_VCARD_MANAGER_H__
#define __GABBLE_VCARD_MANAGER_H__

#include <glib-object.h>
#include <loudmouth/loudmouth.h>

#include "types.h"

G_BEGIN_DECLS

typedef struct _GabbleVCardManagerPrivate GabbleVCardManagerPrivate;
typedef struct _GabbleVCardManagerClass GabbleVCardManagerClass;
typedef struct _GabbleVCardManagerRequest GabbleVCardManagerRequest;
typedef struct _GabbleVCardManagerEditRequest GabbleVCardManagerEditRequest;
typedef struct _GabbleVCardManagerEditInfo GabbleVCardManagerEditInfo;

/**
 * GabbleVCardManagerError:
 * @GABBLE_VCARD_MANAGER_ERROR_CANCELLED: The vCard request was cancelled
 * @GABBLE_VCARD_MANAGER_ERROR_TIMEOUT: The vCard request timed out
 * @GABBLE_VCARD_MANAGER_ERROR_UNKNOWN: An unknown error occured
 */
typedef enum
{
  GABBLE_VCARD_MANAGER_ERROR_CANCELLED,
  GABBLE_VCARD_MANAGER_ERROR_TIMEOUT,
  GABBLE_VCARD_MANAGER_ERROR_UNKNOWN
} GabbleVCardManagerError;

GQuark gabble_vcard_manager_error_quark (void);
#define GABBLE_VCARD_MANAGER_ERROR gabble_vcard_manager_error_quark ()

GType gabble_vcard_manager_get_type (void);

/* TYPE MACROS */
#define GABBLE_TYPE_VCARD_MANAGER \
  (gabble_vcard_manager_get_type ())
#define GABBLE_VCARD_MANAGER(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST((obj), GABBLE_TYPE_VCARD_MANAGER, \
                              GabbleVCardManager))
#define GABBLE_VCARD_MANAGER_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_CAST((klass), GABBLE_TYPE_VCARD_MANAGER, \
                           GabbleVCardManagerClass))
#define GABBLE_IS_VCARD_MANAGER(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE((obj), GABBLE_TYPE_VCARD_MANAGER))
#define GABBLE_IS_VCARD_MANAGER_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_TYPE((klass), GABBLE_TYPE_VCARD_MANAGER))
#define GABBLE_VCARD_MANAGER_GET_CLASS(obj) \
  (G_TYPE_INSTANCE_GET_CLASS ((obj), GABBLE_TYPE_VCARD_MANAGER, \
                              GabbleVCardManagerClass))

struct _GabbleVCardManagerClass {
    GObjectClass parent_class;
};

struct _GabbleVCardManager {
    GObject parent;
    GabbleVCardManagerPrivate *priv;
};

typedef enum {
    GABBLE_VCARD_EDIT_REPLACE,
    GABBLE_VCARD_EDIT_APPEND,
    GABBLE_VCARD_EDIT_DELETE,
    GABBLE_VCARD_EDIT_CLEAR,
    GABBLE_VCARD_EDIT_SET_ALIAS
} GabbleVCardEditType;

typedef void (*GabbleVCardManagerCb)(GabbleVCardManager *self,
                                    GabbleVCardManagerRequest *request,
                                    TpHandle handle,
                                    LmMessageNode *vcard,
                                    GError *error,
                                    gpointer user_data);

GabbleVCardManager *gabble_vcard_manager_new (GabbleConnection *);

GQuark gabble_vcard_manager_cache_quark (void);

GabbleVCardManagerRequest *gabble_vcard_manager_request (GabbleVCardManager *,
                                                       TpHandle,
                                                       guint timeout,
                                                       GabbleVCardManagerCb,
                                                       gpointer user_data,
                                                       GObject *object);

void gabble_vcard_manager_cancel_request (GabbleVCardManager *manager,
                                          GabbleVCardManagerRequest *request);

const gchar *gabble_vcard_manager_get_cached_alias (GabbleVCardManager *,
                                                   TpHandle);
gboolean gabble_vcard_manager_has_cached_alias (GabbleVCardManager *manager,
                                                TpHandle handle);

gboolean gabble_vcard_manager_get_cached (GabbleVCardManager *,
                                          TpHandle,
                                          LmMessageNode **);
void gabble_vcard_manager_invalidate_cache (GabbleVCardManager *, TpHandle);

typedef void (*GabbleVCardManagerEditCb)(GabbleVCardManager *self,
                                         GabbleVCardManagerEditRequest *request,
                                         LmMessageNode *vcard,
                                         GError *error,
                                         gpointer user_data);

GabbleVCardManagerEditRequest *gabble_vcard_manager_edit (GabbleVCardManager *,
                                                          guint timeout,
                                                          GabbleVCardManagerEditCb,
                                                          gpointer user_data,
                                                          GObject *object,
                                                          GList *edits);

void gabble_vcard_manager_remove_edit_request (GabbleVCardManagerEditRequest *);

gchar *vcard_get_avatar_sha1 (LmMessageNode *vcard);

GabbleVCardManagerEditInfo *gabble_vcard_manager_edit_info_new (
    const gchar *element_name,
    const gchar *element_value,
    GabbleVCardEditType edit_type,
    ...) G_GNUC_NULL_TERMINATED;

void gabble_vcard_manager_edit_info_add_child (
    GabbleVCardManagerEditInfo *edit_info, const gchar *key,
    const gchar *value);

void gabble_vcard_manager_edit_info_free (GabbleVCardManagerEditInfo *info);

gboolean gabble_vcard_manager_has_limited_vcard_fields (
    GabbleVCardManager *self);
gboolean gabble_vcard_manager_can_use_vcard_field (GabbleVCardManager *self,
    const gchar *field_name);

/* For unit tests only */
void gabble_vcard_manager_set_suspend_reply_timeout (guint timeout);
void gabble_vcard_manager_set_default_request_timeout (guint timeout);

G_END_DECLS

#endif