comparison src/savedstatuses.c @ 11651:723487d07aa0

[gaim-migrate @ 13935] Getting some stuff out of my tree. I think I mostly just added a "transient" boolean to savedstatuses. If a savedstatus is transient, it means it was created on the fly by Gaim when the user set himself to "away." Transient statuses will hang around for a few days in case the user wants to use it again, but eventually it'll disappear. They should also not appear in the saved status editor. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 13 Oct 2005 01:29:43 +0000
parents 519dc2186438
children a8ec0a291d14
comparison
equal deleted inserted replaced
11650:1f95b6308195 11651:723487d07aa0
44 * 44 *
45 * TODO: This should probably just use a GaimStatus... 45 * TODO: This should probably just use a GaimStatus...
46 */ 46 */
47 struct _GaimSavedStatus 47 struct _GaimSavedStatus
48 { 48 {
49 /**
50 * A "transient" status is one that was used recently by
51 * a Gaim user, but was not explicitly created using the
52 * saved status UI. For example, Gaim's previous status
53 * is saved in the status.xml file, but should not show
54 * up in the UI.
55 */
56 gboolean transient;
57
49 char *title; 58 char *title;
50 GaimStatusPrimitive type; 59 GaimStatusPrimitive type;
51 char *message; 60 char *message;
52 61
53 GList *substatuses; /**< A list of GaimSavedStatusSub's. */ 62 GList *substatuses; /**< A list of GaimSavedStatusSub's. */
131 140
132 static xmlnode * 141 static xmlnode *
133 status_to_xmlnode(GaimSavedStatus *status) 142 status_to_xmlnode(GaimSavedStatus *status)
134 { 143 {
135 xmlnode *node, *child; 144 xmlnode *node, *child;
145 char transient[2];
136 GList *cur; 146 GList *cur;
137 147
148 snprintf(transient, sizeof(transient), "%d", status->transient);
149
138 node = xmlnode_new("status"); 150 node = xmlnode_new("status");
151 xmlnode_set_attrib(node, "transient", transient);
139 xmlnode_set_attrib(node, "name", status->title); 152 xmlnode_set_attrib(node, "name", status->title);
140 153
141 child = xmlnode_new_child(node, "state"); 154 child = xmlnode_new_child(node, "state");
142 xmlnode_insert_data(child, gaim_primitive_get_id_from_type(status->type), -1); 155 xmlnode_insert_data(child, gaim_primitive_get_id_from_type(status->type), -1);
143 156
144 child = xmlnode_new_child(node, "message"); 157 if (status->message != NULL)
145 xmlnode_insert_data(child, status->message, -1); 158 {
159 child = xmlnode_new_child(node, "message");
160 xmlnode_insert_data(child, status->message, -1);
161 }
146 162
147 for (cur = status->substatuses; cur != NULL; cur = cur->next) 163 for (cur = status->substatuses; cur != NULL; cur = cur->next)
148 { 164 {
149 child = substatus_to_xmlnode(cur->data); 165 child = substatus_to_xmlnode(cur->data);
150 xmlnode_insert_child(node, child); 166 xmlnode_insert_child(node, child);
291 char *data; 307 char *data;
292 int i; 308 int i;
293 309
294 ret = g_new0(GaimSavedStatus, 1); 310 ret = g_new0(GaimSavedStatus, 1);
295 311
312 /* Read the transient property */
313 attrib = xmlnode_get_attrib(status, "transient");
314 if ((attrib != NULL) && (attrib[0] == '1'))
315 ret->transient = TRUE;
316
296 /* Read the title */ 317 /* Read the title */
297 attrib = xmlnode_get_attrib(status, "name"); 318 attrib = xmlnode_get_attrib(status, "name");
298 if (attrib == NULL) 319 if (attrib == NULL)
299 attrib = "No Title"; 320 attrib = "No Title";
300 /* Ensure the title is unique */ 321 /* Ensure the title is unique */
385 406
386 return status; 407 return status;
387 } 408 }
388 409
389 void 410 void
411 gaim_savedstatus_set_type(GaimSavedStatus *status, GaimStatusPrimitive type)
412 {
413 g_return_if_fail(status != NULL);
414
415 status->type = type;
416
417 schedule_save();
418 }
419
420 void
390 gaim_savedstatus_set_message(GaimSavedStatus *status, const char *message) 421 gaim_savedstatus_set_message(GaimSavedStatus *status, const char *message)
391 { 422 {
392 g_return_if_fail(status != NULL); 423 g_return_if_fail(status != NULL);
393 424
394 g_free(status->message); 425 g_free(status->message);
435 } 466 }
436 467
437 return NULL; 468 return NULL;
438 } 469 }
439 470
471 gboolean
472 gaim_savedstatus_is_transient(const GaimSavedStatus *saved_status)
473 {
474 return saved_status->transient;
475 }
476
440 const char * 477 const char *
441 gaim_savedstatus_get_title(const GaimSavedStatus *saved_status) 478 gaim_savedstatus_get_title(const GaimSavedStatus *saved_status)
442 { 479 {
443 return saved_status->title; 480 return saved_status->title;
444 } 481 }
451 488
452 const char * 489 const char *
453 gaim_savedstatus_get_message(const GaimSavedStatus *saved_status) 490 gaim_savedstatus_get_message(const GaimSavedStatus *saved_status)
454 { 491 {
455 return saved_status->message; 492 return saved_status->message;
493 }
494
495 gboolean
496 gaim_savedstatus_has_substatuses(const GaimSavedStatus *saved_status)
497 {
498 return (saved_status->substatuses != NULL);
456 } 499 }
457 500
458 void * 501 void *
459 gaim_savedstatuses_get_handle(void) 502 gaim_savedstatuses_get_handle(void)
460 { 503 {