static void *prplcb_notify_userinfo( PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info ) { struct im_connection *ic = purple_ic_by_gc( gc ); GString *info = g_string_new( "" ); GList *l = purple_notify_user_info_get_entries( user_info ); char *key; const char *value; int n; while( l ) { PurpleNotifyUserInfoEntry *e = l->data; switch( purple_notify_user_info_entry_get_type( e ) ) { case PURPLE_NOTIFY_USER_INFO_ENTRY_PAIR: case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER: key = g_strdup( purple_notify_user_info_entry_get_label( e ) ); value = purple_notify_user_info_entry_get_value( e ); if( key ) { strip_html( key ); g_string_append_printf( info, "%s: ", key ); if( value ) { n = strlen( value ) - 1; while( isspace( value[n] ) ) n --; g_string_append_len( info, value, n + 1 ); } g_string_append_c( info, '\n' ); g_free( key ); } break; case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK: g_string_append( info, "------------------------\n" ); break; } l = l->next; } imcb_log( ic, "User %s info:\n%s", who, info->str ); g_string_free( info, TRUE ); return NULL; }
static void notify_user_info(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info){ PurpleAccount* account = purple_connection_get_account (gc); PurpleBuddy* buddy = purple_find_buddy (account, who); if(user_info_handler != Qnil){ VALUE args[2]; args[0] = RB_BLIST_BUDDY( buddy ); GList *l; VALUE hash = rb_hash_new(); for (l = purple_notify_user_info_get_entries(user_info); l != NULL; l = l->next) { //PurpleNotifyUserInfoEntry *user_info_entry = l->data; if (purple_notify_user_info_entry_get_label(l->data) && purple_notify_user_info_entry_get_value(l->data)){ rb_hash_aset(hash, rb_str_new2(purple_notify_user_info_entry_get_label(l->data)), rb_str_new2(purple_notify_user_info_entry_get_value(l->data))); } } args[1] = hash; rb_funcall2(user_info_handler, CALL, 2, args); } }
static char * purple_notify_user_info_get_xhtml(PurpleNotifyUserInfo *user_info) { GList *l; GString *text; text = g_string_new("<span>"); for (l = purple_notify_user_info_get_entries(user_info); l != NULL; l = l->next) { PurpleNotifyUserInfoEntry *user_info_entry = l->data; PurpleNotifyUserInfoEntryType type = purple_notify_user_info_entry_get_type(user_info_entry); const char *label = purple_notify_user_info_entry_get_label(user_info_entry); const char *value = purple_notify_user_info_entry_get_value(user_info_entry); /* Handle the label/value pair itself */ if (type == PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER) g_string_append(text, "<u>"); if (label) g_string_append_printf(text, "<b>%s</b>", label); g_string_append(text, "<span>"); if (label && value) g_string_append(text, ": "); if (value) { char *strip = purple_markup_strip_html(value); g_string_append(text, strip); g_free(strip); } g_string_append(text, "</span>"); if (type == PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER) g_string_append(text, "</u>"); else if (type == PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK) g_string_append(text, "<HR/>"); g_string_append(text, "<BR/>"); } g_string_append(text, "</span>"); return g_string_free(text, FALSE); }
void Notify::UserInfoDialog::update(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info) { treeview->clear(); CppConsUI::TreeView::NodeReference parent; CppConsUI::Button *button; // local information PurpleAccount *account = purple_connection_get_account(gc); PurpleBuddy *buddy = purple_find_buddy(account, who); if (buddy) { /* Note that we should always be able to find the specified buddy, unless * something goes very wrong. */ button = new CppConsUI::TreeView::ToggleCollapseButton( _("Local information")); parent = treeview->appendNode(treeview->getRootNode(), *button); button = new CppConsUI::Button(CppConsUI::Button::FLAG_VALUE, _("Alias"), purple_buddy_get_alias(buddy)); treeview->appendNode(parent, *button); time_t saved_time; struct tm local_time; const char *formatted_time; // last_seen if (PURPLE_BUDDY_IS_ONLINE(buddy)) formatted_time = _("Now"); else { saved_time = static_cast<time_t>(purple_blist_node_get_int( PURPLE_BLIST_NODE(buddy), "last_seen")); if (saved_time && localtime_r(&saved_time, &local_time)) formatted_time = purple_date_format_long(&local_time); else formatted_time = _("Unknown"); } button = new CppConsUI::Button(CppConsUI::Button::FLAG_VALUE, _("Last seen"), formatted_time); treeview->appendNode(parent, *button); // last_activity saved_time = static_cast<time_t>(purple_blist_node_get_int( PURPLE_BLIST_NODE(buddy), "last_activity")); if (saved_time && localtime_r(&saved_time, &local_time)) formatted_time = purple_date_format_long(&local_time); else formatted_time = _("Unknown"); button = new CppConsUI::Button(CppConsUI::Button::FLAG_VALUE, _("Last activity"), formatted_time); treeview->appendNode(parent, *button); } // remote information button = new CppConsUI::TreeView::ToggleCollapseButton( _("Remote information")); parent = treeview->appendNode(treeview->getRootNode(), *button); CppConsUI::TreeView::NodeReference subparent = parent; for (GList *i = purple_notify_user_info_get_entries(user_info); i; i = i->next) { PurpleNotifyUserInfoEntry *entry = reinterpret_cast<PurpleNotifyUserInfoEntry*>(i->data); PurpleNotifyUserInfoEntryType type = purple_notify_user_info_entry_get_type(entry); const char *label = purple_notify_user_info_entry_get_label(entry); if (!label) continue; const char *value = purple_notify_user_info_entry_get_value(entry); char *nohtml = purple_markup_strip_html(value); switch (type) { case PURPLE_NOTIFY_USER_INFO_ENTRY_PAIR: button = new CppConsUI::Button( nohtml ? CppConsUI::Button::FLAG_VALUE : 0, label, nohtml); treeview->appendNode(subparent, *button); break; case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK: // ignore section breaks break; case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER: button = new CppConsUI::TreeView::ToggleCollapseButton(label); subparent = treeview->appendNode(parent, *button); break; default: LOG->error(_("Unhandled userinfo entry type '%d'."), type); break; } g_free(nohtml); } treeview->grabFocus(); }