| 18 * along with this program; if not, write to the Free Software |
18 * along with this program; if not, write to the Free Software |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 20 */ |
20 */ |
| 21 |
21 |
| 22 #include "internal.h" |
22 #include "internal.h" |
| |
23 #include "dbus-maybe.h" |
| 23 #include "glibcompat.h" |
24 #include "glibcompat.h" |
| 24 |
25 |
| 25 #include "debug.h" |
26 #include "debug.h" |
| 26 #include "message.h" |
27 #include "message.h" |
| 27 |
28 |
| 28 #define PURPLE_MESSAGE_GET_PRIVATE(obj) \ |
29 #define PURPLE_MESSAGE_GET_PRIVATE(obj) \ |
| 29 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_MESSAGE, PurpleMessagePrivate)) |
30 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_MESSAGE, PurpleMessagePrivate)) |
| 30 |
31 |
| 31 typedef struct { |
32 typedef struct { |
| |
33 guint id; |
| 32 gchar *who; |
34 gchar *who; |
| 33 gchar *contents; |
35 gchar *contents; |
| 34 PurpleMessageFlags flags; |
36 PurpleMessageFlags flags; |
| 35 } PurpleMessagePrivate; |
37 } PurpleMessagePrivate; |
| 36 |
38 |
| 37 enum |
39 enum |
| 38 { |
40 { |
| 39 PROP_0, |
41 PROP_0, |
| |
42 PROP_ID, |
| 40 PROP_WHO, |
43 PROP_WHO, |
| 41 PROP_CONTENTS, |
44 PROP_CONTENTS, |
| 42 PROP_FLAGS, |
45 PROP_FLAGS, |
| 43 PROP_LAST |
46 PROP_LAST |
| 44 }; |
47 }; |
| 45 |
48 |
| 46 static GObjectClass *parent_class; |
49 static GObjectClass *parent_class; |
| 47 static GParamSpec *properties[PROP_LAST]; |
50 static GParamSpec *properties[PROP_LAST]; |
| 48 |
51 |
| |
52 static GHashTable *messages = NULL; |
| |
53 |
| 49 /****************************************************************************** |
54 /****************************************************************************** |
| 50 * API implementation |
55 * API implementation |
| 51 ******************************************************************************/ |
56 ******************************************************************************/ |
| 52 |
57 |
| 53 PurpleMessage * |
58 PurpleMessage * |
| 62 "contents", contents, |
67 "contents", contents, |
| 63 "flags", flags, |
68 "flags", flags, |
| 64 NULL); |
69 NULL); |
| 65 } |
70 } |
| 66 |
71 |
| |
72 guint |
| |
73 purple_message_get_id(PurpleMessage *msg) |
| |
74 { |
| |
75 PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg); |
| |
76 |
| |
77 g_return_val_if_fail(priv != NULL, 0); |
| |
78 |
| |
79 return priv->id; |
| |
80 } |
| |
81 |
| |
82 PurpleMessage * |
| |
83 purple_message_find_by_id(guint id) |
| |
84 { |
| |
85 g_return_val_if_fail(id > 0, NULL); |
| |
86 |
| |
87 return g_hash_table_lookup(messages, GINT_TO_POINTER(id)); |
| |
88 } |
| |
89 |
| 67 /****************************************************************************** |
90 /****************************************************************************** |
| 68 * Object stuff |
91 * Object stuff |
| 69 ******************************************************************************/ |
92 ******************************************************************************/ |
| 70 |
93 |
| 71 static void |
94 static void |
| |
95 purple_message_init(GTypeInstance *instance, gpointer klass) |
| |
96 { |
| |
97 static guint max_id = 0; |
| |
98 |
| |
99 PurpleMessage *msg = PURPLE_MESSAGE(instance); |
| |
100 PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg); |
| |
101 PURPLE_DBUS_REGISTER_POINTER(msg, PurpleMessage); |
| |
102 |
| |
103 priv->id = ++max_id; |
| |
104 g_hash_table_insert(messages, GINT_TO_POINTER(max_id), msg); |
| |
105 } |
| |
106 |
| |
107 static void |
| 72 purple_message_finalize(GObject *obj) |
108 purple_message_finalize(GObject *obj) |
| 73 { |
109 { |
| 74 PurpleMessage *message = PURPLE_MESSAGE(obj); |
110 PurpleMessage *message = PURPLE_MESSAGE(obj); |
| 75 PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(message); |
111 PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(message); |
| 76 |
112 |
| 86 { |
122 { |
| 87 PurpleMessage *message = PURPLE_MESSAGE(object); |
123 PurpleMessage *message = PURPLE_MESSAGE(object); |
| 88 PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(message); |
124 PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(message); |
| 89 |
125 |
| 90 switch (par_id) { |
126 switch (par_id) { |
| |
127 case PROP_ID: |
| |
128 g_value_set_uint(value, priv->id); |
| |
129 break; |
| 91 case PROP_WHO: |
130 case PROP_WHO: |
| 92 g_value_set_string(value, priv->who); |
131 g_value_set_string(value, priv->who); |
| 93 break; |
132 break; |
| 94 case PROP_CONTENTS: |
133 case PROP_CONTENTS: |
| 95 g_value_set_string(value, priv->contents); |
134 g_value_set_string(value, priv->contents); |
| 139 |
178 |
| 140 gobj_class->finalize = purple_message_finalize; |
179 gobj_class->finalize = purple_message_finalize; |
| 141 gobj_class->get_property = purple_message_get_property; |
180 gobj_class->get_property = purple_message_get_property; |
| 142 gobj_class->set_property = purple_message_set_property; |
181 gobj_class->set_property = purple_message_set_property; |
| 143 |
182 |
| |
183 properties[PROP_ID] = g_param_spec_uint("id", |
| |
184 "ID", "The session-unique message id", |
| |
185 0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); |
| 144 properties[PROP_WHO] = g_param_spec_string("who", |
186 properties[PROP_WHO] = g_param_spec_string("who", |
| 145 "Author", "The nick of the person, who sent the message", |
187 "Author", "The nick of the person, who sent the message", |
| 146 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
188 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 147 properties[PROP_CONTENTS] = g_param_spec_string("contents", |
189 properties[PROP_CONTENTS] = g_param_spec_string("contents", |
| 148 "Contents", "The message text", |
190 "Contents", "The message text", |
| 163 |
205 |
| 164 if (G_UNLIKELY(type == 0)) { |
206 if (G_UNLIKELY(type == 0)) { |
| 165 static const GTypeInfo info = { |
207 static const GTypeInfo info = { |
| 166 .class_size = sizeof(PurpleMessageClass), |
208 .class_size = sizeof(PurpleMessageClass), |
| 167 .class_init = (GClassInitFunc)purple_message_class_init, |
209 .class_init = (GClassInitFunc)purple_message_class_init, |
| 168 .instance_size = sizeof(PurpleMessage) |
210 .instance_size = sizeof(PurpleMessage), |
| |
211 .instance_init = purple_message_init, |
| 169 }; |
212 }; |
| 170 |
213 |
| 171 type = g_type_register_static(G_TYPE_OBJECT, |
214 type = g_type_register_static(G_TYPE_OBJECT, |
| 172 "PurpleMessage", &info, 0); |
215 "PurpleMessage", &info, 0); |
| 173 } |
216 } |
| 174 |
217 |
| 175 return type; |
218 return type; |
| 176 } |
219 } |
| |
220 |
| |
221 void |
| |
222 _purple_message_init(void) |
| |
223 { |
| |
224 messages = g_hash_table_new_full(g_direct_hash, g_direct_equal, |
| |
225 NULL, g_object_unref); |
| |
226 } |
| |
227 |
| |
228 void |
| |
229 _purple_message_uninit(void) |
| |
230 { |
| |
231 g_hash_table_destroy(messages); |
| |
232 messages = NULL; |
| |
233 } |