libpurple/purpleattachment.c

changeset 42841
fbb5c5cb37f4
parent 42767
8cf1d11b59c1
child 43144
627ee13c5dee
equal deleted inserted replaced
42840:18ba0f636076 42841:fbb5c5cb37f4
26 26
27 struct _PurpleAttachment { 27 struct _PurpleAttachment {
28 GObject parent; 28 GObject parent;
29 29
30 guint64 id; 30 guint64 id;
31 gchar *content_type; 31 char *content_type;
32 32
33 gchar *local_uri; 33 char *local_uri;
34 gchar *remote_uri; 34 char *remote_uri;
35 35
36 guint64 size; 36 guint64 size;
37 }; 37 };
38
39 G_DEFINE_FINAL_TYPE(PurpleAttachment, purple_attachment, G_TYPE_OBJECT);
40 38
41 enum { 39 enum {
42 PROP_0 = 0, 40 PROP_0 = 0,
43 PROP_ID, 41 PROP_ID,
44 PROP_CONTENT_TYPE, 42 PROP_CONTENT_TYPE,
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) {
146 * The identifier of this attachment. 154 * The identifier of this attachment.
147 * 155 *
148 * Since: 3.0 156 * Since: 3.0
149 */ 157 */
150 properties[PROP_ID] = g_param_spec_uint64( 158 properties[PROP_ID] = g_param_spec_uint64(
151 "id", "id", 159 "id", NULL, NULL,
152 "The identifier of the attachment.",
153 0, G_MAXUINT64, 0, 160 0, G_MAXUINT64, 0,
154 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); 161 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
155 162
156 /** 163 /**
157 * PurpleAttachment:content-type: 164 * PurpleAttachment:content-type:
160 * mime type. 167 * mime type.
161 * 168 *
162 * Since: 3.0 169 * Since: 3.0
163 */ 170 */
164 properties[PROP_CONTENT_TYPE] = g_param_spec_string( 171 properties[PROP_CONTENT_TYPE] = g_param_spec_string(
165 "content-type", "content-type", 172 "content-type", NULL, NULL,
166 "The content type of the attachment.",
167 "application/octet-stream", 173 "application/octet-stream",
168 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); 174 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
169 175
170 /** 176 /**
171 * PurpleAttachment:local-uri: 177 * PurpleAttachment:local-uri:
174 * disk. 180 * disk.
175 * 181 *
176 * Since: 3.0 182 * Since: 3.0
177 */ 183 */
178 properties[PROP_LOCAL_URI] = g_param_spec_string( 184 properties[PROP_LOCAL_URI] = g_param_spec_string(
179 "local-uri", "local-uri", 185 "local-uri", NULL, NULL,
180 "The local URI of the attachment.",
181 NULL, 186 NULL,
182 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); 187 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
183 188
184 /** 189 /**
185 * PurpleAttachment:remote-uri: 190 * PurpleAttachment:remote-uri:
188 * filename. 193 * filename.
189 * 194 *
190 * Since: 3.0 195 * Since: 3.0
191 */ 196 */
192 properties[PROP_REMOTE_URI] = g_param_spec_string( 197 properties[PROP_REMOTE_URI] = g_param_spec_string(
193 "remote-uri", "remote-uri", 198 "remote-uri", NULL, NULL,
194 "The remote URI of the attachment.",
195 NULL, 199 NULL,
196 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); 200 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
197 201
198 /** 202 /**
199 * PurpleAttachment:size: 203 * PurpleAttachment:size:
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),
327 attachment->size = size; 329 attachment->size = size;
328 330
329 g_object_notify_by_pspec(G_OBJECT(attachment), properties[PROP_SIZE]); 331 g_object_notify_by_pspec(G_OBJECT(attachment), properties[PROP_SIZE]);
330 } 332 }
331 333
332 gchar * 334 char *
333 purple_attachment_get_filename(PurpleAttachment *attachment) { 335 purple_attachment_get_filename(PurpleAttachment *attachment) {
334 g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), NULL); 336 g_return_val_if_fail(PURPLE_IS_ATTACHMENT(attachment), NULL);
335 337
336 if(attachment->remote_uri != NULL && attachment->remote_uri[0] != '\0') { 338 if(attachment->remote_uri != NULL && attachment->remote_uri[0] != '\0') {
337 return g_path_get_basename(attachment->remote_uri); 339 return g_path_get_basename(attachment->remote_uri);

mercurial