~ubuntu-branches/ubuntu/precise/folks/precise-201306070638

« back to all changes in this revision

Viewing changes to folks/has-presence.c

  • Committer: Bazaar Package Importer
  • Author(s): Brian Curtis
  • Date: 2011-02-02 14:22:14 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110202142214-ngpuu3mhjxyl430f
Tags: 0.3.4-0ubuntu1
* New Upstream Release
  - libfolks-telepathy.so exports private symbols
  - Add a HACKING file that outlines development policies and coding style
  - Review coding conventions in folks
  - Add folks command line application
  - libfolks hard-codes backend names for debugging
  - Print stack traces for failed tests to improve remote debugging
  - Add static aggregation tests
  - Logger service unavailable in make check
  - Add tests for LinkedHashSet
  - Use better interface names
* debian/control
  -changed Maintainer to XSBC-Original-Maintainer
  -added Maintainer of Ubuntu Core Developers
  -changed libfolks19* > libfolks20*
* debian
  -changed .install and .symbols files from 19 > 20

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* has-presence.c generated by valac 0.11.2.25-30b2-dirty, the Vala compiler
2
 
 * generated from has-presence.vala, do not modify */
3
 
 
4
 
/*
5
 
 * Copyright (C) 2010 Collabora Ltd.
6
 
 *
7
 
 * This library is free software: you can redistribute it and/or modify
8
 
 * it under the terms of the GNU Lesser General Public License as published by
9
 
 * the Free Software Foundation, either version 2.1 of the License, or
10
 
 * (at your option) any later version.
11
 
 *
12
 
 * This library is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU Lesser General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Lesser General Public License
18
 
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
19
 
 *
20
 
 * Authors:
21
 
 *       Travis Reitter <travis.reitter@collabora.co.uk>
22
 
 */
23
 
 
24
 
#include <glib.h>
25
 
#include <glib-object.h>
26
 
#include <stdlib.h>
27
 
#include <string.h>
28
 
 
29
 
 
30
 
#define FOLKS_TYPE_PRESENCE_TYPE (folks_presence_type_get_type ())
31
 
 
32
 
#define FOLKS_TYPE_HAS_PRESENCE (folks_has_presence_get_type ())
33
 
#define FOLKS_HAS_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_TYPE_HAS_PRESENCE, FolksHasPresence))
34
 
#define FOLKS_IS_HAS_PRESENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_TYPE_HAS_PRESENCE))
35
 
#define FOLKS_HAS_PRESENCE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), FOLKS_TYPE_HAS_PRESENCE, FolksHasPresenceIface))
36
 
 
37
 
typedef struct _FolksHasPresence FolksHasPresence;
38
 
typedef struct _FolksHasPresenceIface FolksHasPresenceIface;
39
 
 
40
 
typedef enum  {
41
 
        FOLKS_PRESENCE_TYPE_UNSET,
42
 
        FOLKS_PRESENCE_TYPE_OFFLINE,
43
 
        FOLKS_PRESENCE_TYPE_AVAILABLE,
44
 
        FOLKS_PRESENCE_TYPE_AWAY,
45
 
        FOLKS_PRESENCE_TYPE_EXTENDED_AWAY,
46
 
        FOLKS_PRESENCE_TYPE_HIDDEN,
47
 
        FOLKS_PRESENCE_TYPE_BUSY,
48
 
        FOLKS_PRESENCE_TYPE_UNKNOWN,
49
 
        FOLKS_PRESENCE_TYPE_ERROR
50
 
} FolksPresenceType;
51
 
 
52
 
struct _FolksHasPresenceIface {
53
 
        GTypeInterface parent_iface;
54
 
        FolksPresenceType (*get_presence_type) (FolksHasPresence* self);
55
 
        void (*set_presence_type) (FolksHasPresence* self, FolksPresenceType value);
56
 
        const gchar* (*get_presence_message) (FolksHasPresence* self);
57
 
        void (*set_presence_message) (FolksHasPresence* self, const gchar* value);
58
 
};
59
 
 
60
 
 
61
 
 
62
 
GType folks_presence_type_get_type (void) G_GNUC_CONST;
63
 
GType folks_has_presence_get_type (void) G_GNUC_CONST;
64
 
static guint folks_has_presence_type_availability (FolksPresenceType type);
65
 
gint folks_has_presence_typecmp (FolksPresenceType type_a, FolksPresenceType type_b);
66
 
gboolean folks_has_presence_is_online (FolksHasPresence* self);
67
 
FolksPresenceType folks_has_presence_get_presence_type (FolksHasPresence* self);
68
 
void folks_has_presence_set_presence_type (FolksHasPresence* self, FolksPresenceType value);
69
 
const gchar* folks_has_presence_get_presence_message (FolksHasPresence* self);
70
 
void folks_has_presence_set_presence_message (FolksHasPresence* self, const gchar* value);
71
 
 
72
 
 
73
 
/**
74
 
 * The possible presence states an object implementing {@link HasPresence} could
75
 
 * be in.
76
 
 *
77
 
 * These closely follow the
78
 
 * [[http://telepathy.freedesktop.org/spec/Connection_Interface_Simple_Presence.html#Connection_Presence_Type|SimplePresence]]
79
 
 * interface in the Telepathy specification.
80
 
 */
81
 
GType folks_presence_type_get_type (void) {
82
 
        static volatile gsize folks_presence_type_type_id__volatile = 0;
83
 
        if (g_once_init_enter (&folks_presence_type_type_id__volatile)) {
84
 
                static const GEnumValue values[] = {{FOLKS_PRESENCE_TYPE_UNSET, "FOLKS_PRESENCE_TYPE_UNSET", "unset"}, {FOLKS_PRESENCE_TYPE_OFFLINE, "FOLKS_PRESENCE_TYPE_OFFLINE", "offline"}, {FOLKS_PRESENCE_TYPE_AVAILABLE, "FOLKS_PRESENCE_TYPE_AVAILABLE", "available"}, {FOLKS_PRESENCE_TYPE_AWAY, "FOLKS_PRESENCE_TYPE_AWAY", "away"}, {FOLKS_PRESENCE_TYPE_EXTENDED_AWAY, "FOLKS_PRESENCE_TYPE_EXTENDED_AWAY", "extended-away"}, {FOLKS_PRESENCE_TYPE_HIDDEN, "FOLKS_PRESENCE_TYPE_HIDDEN", "hidden"}, {FOLKS_PRESENCE_TYPE_BUSY, "FOLKS_PRESENCE_TYPE_BUSY", "busy"}, {FOLKS_PRESENCE_TYPE_UNKNOWN, "FOLKS_PRESENCE_TYPE_UNKNOWN", "unknown"}, {FOLKS_PRESENCE_TYPE_ERROR, "FOLKS_PRESENCE_TYPE_ERROR", "error"}, {0, NULL, NULL}};
85
 
                GType folks_presence_type_type_id;
86
 
                folks_presence_type_type_id = g_enum_register_static ("FolksPresenceType", values);
87
 
                g_once_init_leave (&folks_presence_type_type_id__volatile, folks_presence_type_type_id);
88
 
        }
89
 
        return folks_presence_type_type_id__volatile;
90
 
}
91
 
 
92
 
 
93
 
static guint folks_has_presence_type_availability (FolksPresenceType type) {
94
 
        guint result = 0U;
95
 
        switch (type) {
96
 
                case FOLKS_PRESENCE_TYPE_UNSET:
97
 
                {
98
 
                        result = (guint) 0;
99
 
                        return result;
100
 
                }
101
 
                case FOLKS_PRESENCE_TYPE_UNKNOWN:
102
 
                {
103
 
                        result = (guint) 1;
104
 
                        return result;
105
 
                }
106
 
                case FOLKS_PRESENCE_TYPE_ERROR:
107
 
                {
108
 
                        result = (guint) 2;
109
 
                        return result;
110
 
                }
111
 
                case FOLKS_PRESENCE_TYPE_OFFLINE:
112
 
                {
113
 
                        result = (guint) 3;
114
 
                        return result;
115
 
                }
116
 
                case FOLKS_PRESENCE_TYPE_HIDDEN:
117
 
                {
118
 
                        result = (guint) 4;
119
 
                        return result;
120
 
                }
121
 
                case FOLKS_PRESENCE_TYPE_EXTENDED_AWAY:
122
 
                {
123
 
                        result = (guint) 5;
124
 
                        return result;
125
 
                }
126
 
                case FOLKS_PRESENCE_TYPE_AWAY:
127
 
                {
128
 
                        result = (guint) 6;
129
 
                        return result;
130
 
                }
131
 
                case FOLKS_PRESENCE_TYPE_BUSY:
132
 
                {
133
 
                        result = (guint) 7;
134
 
                        return result;
135
 
                }
136
 
                case FOLKS_PRESENCE_TYPE_AVAILABLE:
137
 
                {
138
 
                        result = (guint) 8;
139
 
                        return result;
140
 
                }
141
 
                default:
142
 
                {
143
 
                        result = (guint) 1;
144
 
                        return result;
145
 
                }
146
 
        }
147
 
}
148
 
 
149
 
 
150
 
/**
151
 
   * Compare two {@link PresenceType}s.
152
 
   *
153
 
   * `0` will be returned if the types are equal, a positive number will be
154
 
   * returned if `type_a` is more available than `type_b`, and a negative
155
 
   * number will be returned if the opposite is true.
156
 
   *
157
 
   * @param type_a the first {@link PresenceType} to compare
158
 
   * @param type_b the second {@link PresenceType} to compare
159
 
   * @return a number representing the similarity of the two types
160
 
   * @since 0.1.11
161
 
   */
162
 
gint folks_has_presence_typecmp (FolksPresenceType type_a, FolksPresenceType type_b) {
163
 
        gint result = 0;
164
 
        guint _tmp0_;
165
 
        guint _tmp1_;
166
 
        _tmp0_ = folks_has_presence_type_availability (type_a);
167
 
        _tmp1_ = folks_has_presence_type_availability (type_b);
168
 
        result = ((gint) _tmp0_) - ((gint) _tmp1_);
169
 
        return result;
170
 
}
171
 
 
172
 
 
173
 
/**
174
 
   * Whether the contact is online.
175
 
   *
176
 
   * This will be `true` if the contact's presence type is higher than
177
 
   * {@link PresenceType.OFFLINE}, as determined by {@link HasPresence.typecmp}.
178
 
   *
179
 
   * @return `true` if the contact is online, `false` otherwise
180
 
   */
181
 
gboolean folks_has_presence_is_online (FolksHasPresence* self) {
182
 
        gboolean result = FALSE;
183
 
        FolksPresenceType _tmp0_;
184
 
        gint _tmp1_;
185
 
        _tmp0_ = folks_has_presence_get_presence_type (self);
186
 
        _tmp1_ = folks_has_presence_typecmp (_tmp0_, FOLKS_PRESENCE_TYPE_OFFLINE);
187
 
        result = _tmp1_ > 0;
188
 
        return result;
189
 
}
190
 
 
191
 
 
192
 
FolksPresenceType folks_has_presence_get_presence_type (FolksHasPresence* self) {
193
 
        return FOLKS_HAS_PRESENCE_GET_INTERFACE (self)->get_presence_type (self);
194
 
}
195
 
 
196
 
 
197
 
void folks_has_presence_set_presence_type (FolksHasPresence* self, FolksPresenceType value) {
198
 
        FOLKS_HAS_PRESENCE_GET_INTERFACE (self)->set_presence_type (self, value);
199
 
}
200
 
 
201
 
 
202
 
const gchar* folks_has_presence_get_presence_message (FolksHasPresence* self) {
203
 
        return FOLKS_HAS_PRESENCE_GET_INTERFACE (self)->get_presence_message (self);
204
 
}
205
 
 
206
 
 
207
 
void folks_has_presence_set_presence_message (FolksHasPresence* self, const gchar* value) {
208
 
        FOLKS_HAS_PRESENCE_GET_INTERFACE (self)->set_presence_message (self, value);
209
 
}
210
 
 
211
 
 
212
 
static void folks_has_presence_base_init (FolksHasPresenceIface * iface) {
213
 
        static gboolean initialized = FALSE;
214
 
        if (!initialized) {
215
 
                initialized = TRUE;
216
 
                /**
217
 
                   * The contact's presence type.
218
 
                   *
219
 
                   * Each contact can have one and only one presence type at any one time,
220
 
                   * representing their availability for communication. The default presence
221
 
                   * type is {@link PresenceType.UNSET}.
222
 
                   */
223
 
                g_object_interface_install_property (iface, g_param_spec_enum ("presence-type", "presence-type", "presence-type", FOLKS_TYPE_PRESENCE_TYPE, FOLKS_PRESENCE_TYPE_UNSET, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
224
 
                /**
225
 
                   * The contact's presence message.
226
 
                   *
227
 
                   * This is a short message written by the contact to add detail to their
228
 
                   * presence type ({@link Folks.HasPresence.presence_type}). If the contact
229
 
                   * hasn't set a message, it will be an empty string.
230
 
                   */
231
 
                g_object_interface_install_property (iface, g_param_spec_string ("presence-message", "presence-message", "presence-message", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
232
 
        }
233
 
}
234
 
 
235
 
 
236
 
/**
237
 
 * Interface exposing a {@link Persona}'s or {@link Individual}'s presence;
238
 
 * their current availability, such as for chatting.
239
 
 *
240
 
 * If the {@link Backend} providing the {@link Persona} doesn't support
241
 
 * presence, the {@link Persona}'s `presence_type` will be set to
242
 
 * {@link PresenceType.UNSET} and their `presence_message` will be an empty
243
 
 * string.
244
 
 */
245
 
GType folks_has_presence_get_type (void) {
246
 
        static volatile gsize folks_has_presence_type_id__volatile = 0;
247
 
        if (g_once_init_enter (&folks_has_presence_type_id__volatile)) {
248
 
                static const GTypeInfo g_define_type_info = { sizeof (FolksHasPresenceIface), (GBaseInitFunc) folks_has_presence_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
249
 
                GType folks_has_presence_type_id;
250
 
                folks_has_presence_type_id = g_type_register_static (G_TYPE_INTERFACE, "FolksHasPresence", &g_define_type_info, 0);
251
 
                g_type_interface_add_prerequisite (folks_has_presence_type_id, G_TYPE_OBJECT);
252
 
                g_once_init_leave (&folks_has_presence_type_id__volatile, folks_has_presence_type_id);
253
 
        }
254
 
        return folks_has_presence_type_id__volatile;
255
 
}
256
 
 
257
 
 
258