# HG changeset patch # User Evan Schoenberg # Date 1165727161 0 # Node ID a56c93f12f8fd21bc0bdfdf6efee882f983020dd # Parent b5a8193edb627906daabc0106a9e61830aca4ea8 [gaim-migrate @ 17935] Improved handling of GaimNotifyUserInfoEntry types; an enum now specifies them. Fixed gaim_notify_user_info_get_text() not to have newlines before and after the horizontal line for section breaks. committer: Tailor Script diff -r b5a8193edb62 -r a56c93f12f8f libgaim/notify.c --- a/libgaim/notify.c Sun Dec 10 03:44:35 2006 +0000 +++ b/libgaim/notify.c Sun Dec 10 05:06:01 2006 +0000 @@ -43,7 +43,7 @@ { char *label; char *value; - gboolean is_header; + GaimNotifyUserInfoEntryType type; }; struct _GaimNotifyUserInfo @@ -483,7 +483,7 @@ user_info_entry = g_new0(GaimNotifyUserInfoEntry, 1); user_info_entry->label = g_strdup(label); user_info_entry->value = g_strdup(value); - user_info_entry->is_header = FALSE; + user_info_entry->type = GAIM_NOTIFY_USER_INFO_ENTRY_PAIR; return user_info_entry; } @@ -541,9 +541,12 @@ for (l = user_info->user_info_entries; l != NULL; l = l->next) { GaimNotifyUserInfoEntry *user_info_entry = l->data; - if (user_info_entry->is_header) + /* Add a newline before a section header */ + if (user_info_entry->type == GAIM_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER) g_string_append(text, newline); + /* Handle the label/value pair itself */ + /* XXX Todo: Use a larger size for a section header? */ if (user_info_entry->label) g_string_append_printf(text, "%s", user_info_entry->label); if (user_info_entry->label && user_info_entry->value) @@ -551,10 +554,17 @@ if (user_info_entry->value) g_string_append(text, user_info_entry->value); - if (user_info_entry->is_header) + /* Display a section break as a horizontal line */ + if (user_info_entry->type == GAIM_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK) + g_string_append(text, "
"); + + /* Don't insert a new line before or after a section break;
does that for us */ + if ((user_info_entry->type != GAIM_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK) && + (l->next && ((((GaimNotifyUserInfoEntry *)(l->next->data))->type != GAIM_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK)))) g_string_append(text, newline); - - if (l->next) + + /* Add an extra newline after a section header */ + if (user_info_entry->type == GAIM_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER) g_string_append(text, newline); } @@ -602,29 +612,27 @@ GaimNotifyUserInfoEntry *entry; entry = gaim_notify_user_info_entry_new(label, NULL); - entry->is_header = TRUE; + entry->type = GAIM_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER; user_info->user_info_entries = g_list_append(user_info->user_info_entries, entry); } -/** - * Remove the last item which was added to user_info - * This is helpful for removing a section header if the section was empty. - */ -void -gaim_notify_user_info_remove_last_item(GaimNotifyUserInfo *user_info) -{ - user_info->user_info_entries = g_list_remove(user_info->user_info_entries, - g_list_last(user_info->user_info_entries)->data); -} - void gaim_notify_user_info_add_section_break(GaimNotifyUserInfo *user_info) { - /* This is for future expansion; section breaks should be marked as such so the UI - * can format them differently if desired. - */ - gaim_notify_user_info_add_pair(user_info, NULL, "
"); + GaimNotifyUserInfoEntry *entry; + + entry = gaim_notify_user_info_entry_new(NULL, NULL); + entry->type = GAIM_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK; + + user_info->user_info_entries = g_list_append(user_info->user_info_entries, entry); +} + +void +gaim_notify_user_info_remove_last_item(GaimNotifyUserInfo *user_info) +{ + user_info->user_info_entries = g_list_remove(user_info->user_info_entries, + g_list_last(user_info->user_info_entries)->data); } void * diff -r b5a8193edb62 -r a56c93f12f8f libgaim/notify.h --- a/libgaim/notify.h Sun Dec 10 03:44:35 2006 +0000 +++ b/libgaim/notify.h Sun Dec 10 05:06:01 2006 +0000 @@ -94,6 +94,15 @@ } GaimNotifySearchResults; +/** + * Types of GaimNotifyUserInfoEntry objects + */ +typedef enum +{ + GAIM_NOTIFY_USER_INFO_ENTRY_PAIR = 0, + GAIM_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK, + GAIM_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER +} GaimNotifyUserInfoEntryType; /** * Single column of a search result.