| 52 /****************************************************************************** |
50 /****************************************************************************** |
| 53 * Private Setters |
51 * Private Setters |
| 54 *****************************************************************************/ |
52 *****************************************************************************/ |
| 55 static void |
53 static void |
| 56 purple_attachment_set_content_type(PurpleAttachment *attachment, |
54 purple_attachment_set_content_type(PurpleAttachment *attachment, |
| 57 const gchar *content_type) |
55 const char *content_type) |
| 58 { |
56 { |
| 59 if(g_set_str(&attachment->content_type, content_type)) { |
57 if(g_set_str(&attachment->content_type, content_type)) { |
| 60 g_object_notify_by_pspec(G_OBJECT(attachment), |
58 g_object_notify_by_pspec(G_OBJECT(attachment), |
| 61 properties[PROP_CONTENT_TYPE]); |
59 properties[PROP_CONTENT_TYPE]); |
| 62 } |
60 } |
| 63 } |
61 } |
| 64 |
62 |
| 65 /****************************************************************************** |
63 /****************************************************************************** |
| 66 * GObject Implementation |
64 * GObject Implementation |
| 67 *****************************************************************************/ |
65 *****************************************************************************/ |
| 68 static void |
66 G_DEFINE_FINAL_TYPE(PurpleAttachment, purple_attachment, G_TYPE_OBJECT); |
| 69 purple_attachment_get_property(GObject *obj, guint prop_id, GValue *value, GParamSpec *pspec) { |
67 |
| |
68 static void |
| |
69 purple_attachment_get_property(GObject *obj, guint prop_id, GValue *value, |
| |
70 GParamSpec *pspec) |
| |
71 { |
| 70 PurpleAttachment *attachment = PURPLE_ATTACHMENT(obj); |
72 PurpleAttachment *attachment = PURPLE_ATTACHMENT(obj); |
| 71 |
73 |
| 72 switch(prop_id) { |
74 switch(prop_id) { |
| 73 case PROP_ID: |
75 case PROP_ID: |
| 74 g_value_set_uint64(value, purple_attachment_get_id(attachment)); |
76 g_value_set_uint64(value, purple_attachment_get_id(attachment)); |
| 75 break; |
77 break; |
| 76 case PROP_CONTENT_TYPE: |
78 case PROP_CONTENT_TYPE: |
| 77 g_value_set_string(value, purple_attachment_get_content_type(attachment)); |
79 g_value_set_string(value, |
| 78 break; |
80 purple_attachment_get_content_type(attachment)); |
| 79 case PROP_LOCAL_URI: |
81 break; |
| 80 g_value_set_string(value, purple_attachment_get_local_uri(attachment)); |
82 case PROP_LOCAL_URI: |
| 81 break; |
83 g_value_set_string(value, purple_attachment_get_local_uri(attachment)); |
| 82 case PROP_REMOTE_URI: |
84 break; |
| 83 g_value_set_string(value, purple_attachment_get_remote_uri(attachment)); |
85 case PROP_REMOTE_URI: |
| 84 break; |
86 g_value_set_string(value, |
| 85 case PROP_SIZE: |
87 purple_attachment_get_remote_uri(attachment)); |
| 86 g_value_set_uint64(value, purple_attachment_get_size(attachment)); |
88 break; |
| 87 break; |
89 case PROP_SIZE: |
| 88 default: |
90 g_value_set_uint64(value, purple_attachment_get_size(attachment)); |
| 89 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); |
91 break; |
| 90 break; |
92 default: |
| 91 } |
93 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); |
| 92 } |
94 break; |
| 93 |
95 } |
| 94 static void |
96 } |
| 95 purple_attachment_set_property(GObject *obj, guint prop_id, const GValue *value, GParamSpec *pspec) { |
97 |
| |
98 static void |
| |
99 purple_attachment_set_property(GObject *obj, guint prop_id, |
| |
100 const GValue *value, GParamSpec *pspec) |
| |
101 { |
| 96 PurpleAttachment *attachment = PURPLE_ATTACHMENT(obj); |
102 PurpleAttachment *attachment = PURPLE_ATTACHMENT(obj); |
| 97 |
103 |
| 98 switch(prop_id) { |
104 switch(prop_id) { |
| 99 case PROP_ID: |
105 case PROP_ID: |
| 100 purple_attachment_set_id(attachment, g_value_get_uint64(value)); |
106 purple_attachment_set_id(attachment, g_value_get_uint64(value)); |
| 101 break; |
107 break; |
| 102 case PROP_CONTENT_TYPE: |
108 case PROP_CONTENT_TYPE: |
| 103 purple_attachment_set_content_type(attachment, g_value_get_string(value)); |
109 purple_attachment_set_content_type(attachment, |
| 104 break; |
110 g_value_get_string(value)); |
| 105 case PROP_LOCAL_URI: |
111 break; |
| 106 purple_attachment_set_local_uri(attachment, g_value_get_string(value)); |
112 case PROP_LOCAL_URI: |
| 107 break; |
113 purple_attachment_set_local_uri(attachment, g_value_get_string(value)); |
| 108 case PROP_REMOTE_URI: |
114 break; |
| 109 purple_attachment_set_remote_uri(attachment, g_value_get_string(value)); |
115 case PROP_REMOTE_URI: |
| 110 break; |
116 purple_attachment_set_remote_uri(attachment, |
| 111 case PROP_SIZE: |
117 g_value_get_string(value)); |
| 112 purple_attachment_set_size(attachment, g_value_get_uint64(value)); |
118 break; |
| 113 break; |
119 case PROP_SIZE: |
| 114 default: |
120 purple_attachment_set_size(attachment, g_value_get_uint64(value)); |
| 115 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); |
121 break; |
| 116 break; |
122 default: |
| |
123 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); |
| |
124 break; |
| 117 } |
125 } |
| 118 } |
126 } |
| 119 |
127 |
| 120 static void |
128 static void |
| 121 purple_attachment_finalize(GObject *obj) { |
129 purple_attachment_finalize(GObject *obj) { |
| 201 * The size of the attachment in bytes. |
205 * The size of the attachment in bytes. |
| 202 * |
206 * |
| 203 * Since: 3.0 |
207 * Since: 3.0 |
| 204 */ |
208 */ |
| 205 properties[PROP_SIZE] = g_param_spec_uint64( |
209 properties[PROP_SIZE] = g_param_spec_uint64( |
| 206 "size", "size", |
210 "size", NULL, NULL, |
| 207 "The file size of the attachment in bytes.", |
|
| 208 0, G_MAXUINT64, 0, |
211 0, G_MAXUINT64, 0, |
| 209 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
212 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 210 |
213 |
| 211 g_object_class_install_properties(obj_class, N_PROPERTIES, properties); |
214 g_object_class_install_properties(obj_class, N_PROPERTIES, properties); |
| 212 } |
215 } |
| 213 |
216 |
| 214 /****************************************************************************** |
217 /****************************************************************************** |
| 215 * Public API |
218 * Public API |
| 216 *****************************************************************************/ |
219 *****************************************************************************/ |
| 217 |
|
| 218 PurpleAttachment * |
220 PurpleAttachment * |
| 219 purple_attachment_new(guint64 id, const gchar *content_type) { |
221 purple_attachment_new(guint64 id, const char *content_type) { |
| 220 g_return_val_if_fail(content_type != NULL, NULL); |
222 g_return_val_if_fail(content_type != NULL, NULL); |
| 221 |
223 |
| 222 return g_object_new( |
224 return g_object_new( |
| 223 PURPLE_TYPE_ATTACHMENT, |
225 PURPLE_TYPE_ATTACHMENT, |
| 224 "id", id, |
226 "id", id, |
| 251 attachment->id = id; |
253 attachment->id = id; |
| 252 |
254 |
| 253 g_object_notify_by_pspec(G_OBJECT(attachment), properties[PROP_ID]); |
255 g_object_notify_by_pspec(G_OBJECT(attachment), properties[PROP_ID]); |
| 254 } |
256 } |
| 255 |
257 |
| 256 const gchar * |
258 const char * |
| 257 purple_attachment_get_content_type(PurpleAttachment *attachment) { |
259 purple_attachment_get_content_type(PurpleAttachment *attachment) { |
| 258 g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), NULL); |
260 g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), NULL); |
| 259 |
261 |
| 260 return attachment->content_type; |
262 return attachment->content_type; |
| 261 } |
263 } |
| 262 |
264 |
| 263 const gchar * |
265 const char * |
| 264 purple_attachment_get_local_uri(PurpleAttachment *attachment) { |
266 purple_attachment_get_local_uri(PurpleAttachment *attachment) { |
| 265 g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), NULL); |
267 g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), NULL); |
| 266 |
268 |
| 267 return attachment->local_uri; |
269 return attachment->local_uri; |
| 268 } |
270 } |
| 269 |
271 |
| 270 void |
272 void |
| 271 purple_attachment_set_local_uri(PurpleAttachment *attachment, |
273 purple_attachment_set_local_uri(PurpleAttachment *attachment, |
| 272 const gchar *local_uri) |
274 const char *local_uri) |
| 273 { |
275 { |
| 274 g_return_if_fail(PURPLE_IS_ATTACHMENT(attachment)); |
276 g_return_if_fail(PURPLE_IS_ATTACHMENT(attachment)); |
| 275 |
277 |
| 276 if(attachment->local_uri == local_uri) { |
278 if(attachment->local_uri == local_uri) { |
| 277 return; |
279 return; |
| 278 } |
280 } |
| 279 |
281 |
| 280 g_free(attachment->local_uri); |
282 g_free(attachment->local_uri); |
| 281 |
283 |
| 282 if(local_uri != NULL) { |
284 if(local_uri != NULL) { |
| 283 gchar *scheme = g_uri_parse_scheme(local_uri); |
285 char *scheme = g_uri_parse_scheme(local_uri); |
| 284 if(scheme == NULL) { |
286 if(scheme == NULL) { |
| 285 attachment->local_uri = g_filename_to_uri(local_uri, NULL, NULL); |
287 attachment->local_uri = g_filename_to_uri(local_uri, NULL, NULL); |
| 286 } else { |
288 } else { |
| 287 g_free(scheme); |
289 g_free(scheme); |
| 288 attachment->local_uri = g_strdup(local_uri); |
290 attachment->local_uri = g_strdup(local_uri); |
| 292 } |
294 } |
| 293 |
295 |
| 294 g_object_notify_by_pspec(G_OBJECT(attachment), properties[PROP_LOCAL_URI]); |
296 g_object_notify_by_pspec(G_OBJECT(attachment), properties[PROP_LOCAL_URI]); |
| 295 } |
297 } |
| 296 |
298 |
| 297 const gchar * |
299 const char * |
| 298 purple_attachment_get_remote_uri(PurpleAttachment *attachment) { |
300 purple_attachment_get_remote_uri(PurpleAttachment *attachment) { |
| 299 g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), NULL); |
301 g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), NULL); |
| 300 |
302 |
| 301 return attachment->remote_uri; |
303 return attachment->remote_uri; |
| 302 } |
304 } |
| 303 |
305 |
| 304 void |
306 void |
| 305 purple_attachment_set_remote_uri(PurpleAttachment *attachment, |
307 purple_attachment_set_remote_uri(PurpleAttachment *attachment, |
| 306 const gchar *remote_uri) |
308 const char *remote_uri) |
| 307 { |
309 { |
| 308 g_return_if_fail(PURPLE_IS_ATTACHMENT(attachment)); |
310 g_return_if_fail(PURPLE_IS_ATTACHMENT(attachment)); |
| 309 |
311 |
| 310 if(g_set_str(&attachment->remote_uri, remote_uri)) { |
312 if(g_set_str(&attachment->remote_uri, remote_uri)) { |
| 311 g_object_notify_by_pspec(G_OBJECT(attachment), |
313 g_object_notify_by_pspec(G_OBJECT(attachment), |