comparison libpurple/notify.c @ 32819:2c6510167895 default tip

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 02 Jun 2012 02:30:49 +0000
parents 8878ea011fa1
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
51 PurpleNotifyUserInfoEntryType type; 51 PurpleNotifyUserInfoEntryType type;
52 }; 52 };
53 53
54 struct _PurpleNotifyUserInfo 54 struct _PurpleNotifyUserInfo
55 { 55 {
56 GList *user_info_entries; 56 GQueue entries;
57 };
58
59 /**
60 * Single column of a search result.
61 */
62 struct _PurpleNotifySearchColumn
63 {
64 char *title; /**< Title of the column. */
65 gboolean visible; /**< Should the column be visible to the user. Defaults to TRUE. */
66
57 }; 67 };
58 68
59 void * 69 void *
60 purple_notify_message(void *handle, PurpleNotifyMsgType type, 70 purple_notify_message(void *handle, PurpleNotifyMsgType type,
61 const char *title, const char *primary, 71 const char *title, const char *primary,
361 371
362 g_return_val_if_fail(title != NULL, NULL); 372 g_return_val_if_fail(title != NULL, NULL);
363 373
364 sc = g_new0(PurpleNotifySearchColumn, 1); 374 sc = g_new0(PurpleNotifySearchColumn, 1);
365 sc->title = g_strdup(title); 375 sc->title = g_strdup(title);
376 sc->visible = TRUE;
366 377
367 return sc; 378 return sc;
368 } 379 }
369 380
370 guint 381 const char *purple_notify_searchresult_column_get_title(const PurpleNotifySearchColumn *column)
371 purple_notify_searchresults_get_columns_count(PurpleNotifySearchResults *results) 382 {
372 { 383 g_return_val_if_fail(column != NULL, NULL);
373 g_return_val_if_fail(results != NULL, 0); 384
374 385 return column->title;
375 return g_list_length(results->columns); 386 }
376 } 387
377 388 void purple_notify_searchresult_column_set_visible(PurpleNotifySearchColumn *column, gboolean visible)
378 guint 389 {
379 purple_notify_searchresults_get_rows_count(PurpleNotifySearchResults *results) 390 g_return_if_fail(column != NULL);
380 { 391
381 g_return_val_if_fail(results != NULL, 0); 392 column->visible = visible;
382 393 }
383 return g_list_length(results->rows); 394
384 } 395 gboolean
385 396 purple_notify_searchresult_column_is_visible(const PurpleNotifySearchColumn *column)
386 char * 397 {
387 purple_notify_searchresults_column_get_title(PurpleNotifySearchResults *results, 398 g_return_val_if_fail(column != NULL, FALSE);
388 unsigned int column_id) 399
389 { 400 return column->visible;
390 g_return_val_if_fail(results != NULL, NULL);
391
392 return ((PurpleNotifySearchColumn *)g_list_nth_data(results->columns, column_id))->title;
393 }
394
395 GList *
396 purple_notify_searchresults_row_get(PurpleNotifySearchResults *results,
397 unsigned int row_id)
398 {
399 g_return_val_if_fail(results != NULL, NULL);
400
401 return g_list_nth_data(results->rows, row_id);
402 } 401 }
403 402
404 void * 403 void *
405 purple_notify_userinfo(PurpleConnection *gc, const char *who, 404 purple_notify_userinfo(PurpleConnection *gc, const char *who,
406 PurpleNotifyUserInfo *user_info, PurpleNotifyCloseCallback cb, gpointer user_data) 405 PurpleNotifyUserInfo *user_info, PurpleNotifyCloseCallback cb, gpointer user_data)
470 { 469 {
471 PurpleNotifyUserInfo *user_info; 470 PurpleNotifyUserInfo *user_info;
472 471
473 user_info = g_new0(PurpleNotifyUserInfo, 1); 472 user_info = g_new0(PurpleNotifyUserInfo, 1);
474 PURPLE_DBUS_REGISTER_POINTER(user_info, PurpleNotifyUserInfo); 473 PURPLE_DBUS_REGISTER_POINTER(user_info, PurpleNotifyUserInfo);
475 user_info->user_info_entries = NULL; 474 g_queue_init(&user_info->entries);
476 475
477 return user_info; 476 return user_info;
478 } 477 }
479 478
480 void 479 void
481 purple_notify_user_info_destroy(PurpleNotifyUserInfo *user_info) 480 purple_notify_user_info_destroy(PurpleNotifyUserInfo *user_info)
482 { 481 {
483 GList *l; 482 GList *l;
484 483
485 for (l = user_info->user_info_entries; l != NULL; l = l->next) { 484 for (l = user_info->entries.head; l != NULL; l = l->next) {
486 PurpleNotifyUserInfoEntry *user_info_entry = l->data; 485 PurpleNotifyUserInfoEntry *user_info_entry = l->data;
487 486
488 purple_notify_user_info_entry_destroy(user_info_entry); 487 purple_notify_user_info_entry_destroy(user_info_entry);
489 } 488 }
490 489
491 g_list_free(user_info->user_info_entries); 490 g_queue_clear(&user_info->entries);
492 PURPLE_DBUS_UNREGISTER_POINTER(user_info); 491 PURPLE_DBUS_UNREGISTER_POINTER(user_info);
493 g_free(user_info); 492 g_free(user_info);
494 } 493 }
495 494
496 GList * 495 GQueue *
497 purple_notify_user_info_get_entries(PurpleNotifyUserInfo *user_info) 496 purple_notify_user_info_get_entries(PurpleNotifyUserInfo *user_info)
498 { 497 {
499 g_return_val_if_fail(user_info != NULL, NULL); 498 g_return_val_if_fail(user_info != NULL, NULL);
500 499
501 return user_info->user_info_entries; 500 return &user_info->entries;
502 } 501 }
503 502
504 char * 503 char *
505 purple_notify_user_info_get_text_with_newline(PurpleNotifyUserInfo *user_info, const char *newline) 504 purple_notify_user_info_get_text_with_newline(PurpleNotifyUserInfo *user_info, const char *newline)
506 { 505 {
507 GList *l; 506 GList *l;
508 GString *text; 507 GString *text;
509 508
510 text = g_string_new(""); 509 text = g_string_new("");
511 510
512 for (l = user_info->user_info_entries; l != NULL; l = l->next) { 511 for (l = user_info->entries.head; l != NULL; l = l->next) {
513 PurpleNotifyUserInfoEntry *user_info_entry = l->data; 512 PurpleNotifyUserInfoEntry *user_info_entry = l->data;
514 /* Add a newline before a section header */ 513 /* Add a newline before a section header */
515 if (user_info_entry->type == PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER) 514 if (user_info_entry->type == PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER)
516 g_string_append(text, newline); 515 g_string_append(text, newline);
517 516
591 590
592 user_info_entry->type = type; 591 user_info_entry->type = type;
593 } 592 }
594 593
595 void 594 void
596 purple_notify_user_info_add_pair(PurpleNotifyUserInfo *user_info, const char *label, const char *value) 595 purple_notify_user_info_add_pair_html(PurpleNotifyUserInfo *user_info, const char *label, const char *value)
597 { 596 {
598 PurpleNotifyUserInfoEntry *entry; 597 PurpleNotifyUserInfoEntry *entry;
599 598
600 entry = purple_notify_user_info_entry_new(label, value); 599 entry = purple_notify_user_info_entry_new(label, value);
601 user_info->user_info_entries = g_list_append(user_info->user_info_entries, entry); 600 g_queue_push_tail(&user_info->entries, entry);
602 } 601 }
603 602
604 void 603 void
605 purple_notify_user_info_add_pair_plaintext(PurpleNotifyUserInfo *user_info, const char *label, const char *value) 604 purple_notify_user_info_add_pair_plaintext(PurpleNotifyUserInfo *user_info, const char *label, const char *value)
606 { 605 {
607 gchar *escaped; 606 gchar *escaped;
607
608 escaped = g_markup_escape_text(value, -1);
609 purple_notify_user_info_add_pair_html(user_info, label, escaped);
610 g_free(escaped);
611 }
612
613 void
614 purple_notify_user_info_prepend_pair_html(PurpleNotifyUserInfo *user_info, const char *label, const char *value)
615 {
608 PurpleNotifyUserInfoEntry *entry; 616 PurpleNotifyUserInfoEntry *entry;
609 617
618 entry = purple_notify_user_info_entry_new(label, value);
619 g_queue_push_head(&user_info->entries, entry);
620 }
621
622 void
623 purple_notify_user_info_prepend_pair_plaintext(PurpleNotifyUserInfo *user_info, const char *label, const char *value)
624 {
625 gchar *escaped;
626
610 escaped = g_markup_escape_text(value, -1); 627 escaped = g_markup_escape_text(value, -1);
611 entry = purple_notify_user_info_entry_new(label, escaped); 628 purple_notify_user_info_prepend_pair_html(user_info, label, escaped);
612 g_free(escaped); 629 g_free(escaped);
613 user_info->user_info_entries = g_list_append(user_info->user_info_entries, entry);
614 }
615
616 void
617 purple_notify_user_info_prepend_pair(PurpleNotifyUserInfo *user_info, const char *label, const char *value)
618 {
619 PurpleNotifyUserInfoEntry *entry;
620
621 entry = purple_notify_user_info_entry_new(label, value);
622 user_info->user_info_entries = g_list_prepend(user_info->user_info_entries, entry);
623 } 630 }
624 631
625 void 632 void
626 purple_notify_user_info_remove_entry(PurpleNotifyUserInfo *user_info, PurpleNotifyUserInfoEntry *entry) 633 purple_notify_user_info_remove_entry(PurpleNotifyUserInfo *user_info, PurpleNotifyUserInfoEntry *entry)
627 { 634 {
628 g_return_if_fail(user_info != NULL); 635 g_return_if_fail(user_info != NULL);
629 g_return_if_fail(entry != NULL); 636 g_return_if_fail(entry != NULL);
630 637
631 user_info->user_info_entries = g_list_remove(user_info->user_info_entries, entry); 638 g_queue_remove(&user_info->entries, entry);
632 } 639 }
633 640
634 void 641 void
635 purple_notify_user_info_add_section_header(PurpleNotifyUserInfo *user_info, const char *label) 642 purple_notify_user_info_add_section_header(PurpleNotifyUserInfo *user_info, const char *label)
636 { 643 {
637 PurpleNotifyUserInfoEntry *entry; 644 PurpleNotifyUserInfoEntry *entry;
638 645
639 entry = purple_notify_user_info_entry_new(label, NULL); 646 entry = purple_notify_user_info_entry_new(label, NULL);
640 entry->type = PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER; 647 entry->type = PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER;
641 648
642 user_info->user_info_entries = g_list_append(user_info->user_info_entries, entry); 649 g_queue_push_tail(&user_info->entries, entry);
643 } 650 }
644 651
645 void 652 void
646 purple_notify_user_info_prepend_section_header(PurpleNotifyUserInfo *user_info, const char *label) 653 purple_notify_user_info_prepend_section_header(PurpleNotifyUserInfo *user_info, const char *label)
647 { 654 {
648 PurpleNotifyUserInfoEntry *entry; 655 PurpleNotifyUserInfoEntry *entry;
649 656
650 entry = purple_notify_user_info_entry_new(label, NULL); 657 entry = purple_notify_user_info_entry_new(label, NULL);
651 entry->type = PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER; 658 entry->type = PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER;
652 659
653 user_info->user_info_entries = g_list_prepend(user_info->user_info_entries, entry); 660 g_queue_push_head(&user_info->entries, entry);
654 } 661 }
655 662
656 void 663 void
657 purple_notify_user_info_add_section_break(PurpleNotifyUserInfo *user_info) 664 purple_notify_user_info_add_section_break(PurpleNotifyUserInfo *user_info)
658 { 665 {
659 PurpleNotifyUserInfoEntry *entry; 666 PurpleNotifyUserInfoEntry *entry;
660 667
661 entry = purple_notify_user_info_entry_new(NULL, NULL); 668 entry = purple_notify_user_info_entry_new(NULL, NULL);
662 entry->type = PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK; 669 entry->type = PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK;
663 670
664 user_info->user_info_entries = g_list_append(user_info->user_info_entries, entry); 671 g_queue_push_tail(&user_info->entries, entry);
665 } 672 }
666 673
667 void 674 void
668 purple_notify_user_info_prepend_section_break(PurpleNotifyUserInfo *user_info) 675 purple_notify_user_info_prepend_section_break(PurpleNotifyUserInfo *user_info)
669 { 676 {
670 PurpleNotifyUserInfoEntry *entry; 677 PurpleNotifyUserInfoEntry *entry;
671 678
672 entry = purple_notify_user_info_entry_new(NULL, NULL); 679 entry = purple_notify_user_info_entry_new(NULL, NULL);
673 entry->type = PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK; 680 entry->type = PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK;
674 681
675 user_info->user_info_entries = g_list_prepend(user_info->user_info_entries, entry); 682 g_queue_push_head(&user_info->entries, entry);
676 } 683 }
677 684
678 void 685 void
679 purple_notify_user_info_remove_last_item(PurpleNotifyUserInfo *user_info) 686 purple_notify_user_info_remove_last_item(PurpleNotifyUserInfo *user_info)
680 { 687 {
681 GList *last = g_list_last(user_info->user_info_entries); 688 PurpleNotifyUserInfoEntry *entry;
682 if (last) { 689
683 purple_notify_user_info_entry_destroy(last->data); 690 entry = g_queue_pop_tail(&user_info->entries);
684 user_info->user_info_entries = g_list_delete_link(user_info->user_info_entries, last); 691 if (entry)
685 } 692 purple_notify_user_info_entry_destroy(entry);
686 } 693 }
687 694
688 void * 695 void *
689 purple_notify_uri(void *handle, const char *uri) 696 purple_notify_uri(void *handle, const char *uri)
690 { 697 {