Exemplo n.º 1
0
 Tag *MRIMProtocol::getVCardTag(AbstractUser *user, GList *vcardEntries) {
     PurpleNotifyUserInfoEntry *vcardEntry;
     std::string label;
     std::string firstName;
     std::string lastName;
     std::string header;
  
     Tag *N = new Tag("N");
     Tag *head = new Tag("ADR");
     Tag *vcard = new Tag( "vCard" );
     vcard->addAttribute( "xmlns", "vcard-temp" );
  
     while (vcardEntries) {
         vcardEntry = (PurpleNotifyUserInfoEntry *)(vcardEntries->data);
         if (purple_notify_user_info_entry_get_label(vcardEntry) && purple_notify_user_info_entry_get_value(vcardEntry)){
             label=(std::string)purple_notify_user_info_entry_get_label(vcardEntry);
             Log("vcard label", label << " => " << (std::string)purple_notify_user_info_entry_get_value(vcardEntry));
             if (label=="Firstname"){
                 N->addChild( new Tag("GIVEN", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
                 firstName = (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
             }
             else if (label=="Lastname"){
                 N->addChild( new Tag("FAMILY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
                 lastName = (std::string)purple_notify_user_info_entry_get_value(vcardEntry);
             }
             else if (label=="Nickname"){
                 vcard->addChild( new Tag("NICKNAME", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
             }
             else if (label=="Sex"){
                 vcard->addChild( new Tag("GENDER", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
             }
             else if (label=="Birthday"){
                 vcard->addChild( new Tag("BDAY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
             }
            else if (label=="E-Mail"){
                vcard->addChild( new Tag("UID", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
            }
         }
         vcardEntries = vcardEntries->next;
     }
     if (!firstName.empty() || !lastName.empty())
         vcard->addChild( new Tag("FN", firstName + " " + lastName));
         // add photo ant N if any
         if(!N->children().empty())
             vcard->addChild(N);
  
     return vcard;
 }
void purpleTooltipInfo::Init(PurpleNotifyUserInfoEntry *aEntry)
{
  mType = purple_notify_user_info_entry_get_type(aEntry);
  mLabel = purple_notify_user_info_entry_get_label(aEntry);
  char *value =
    purple_unescape_html(purple_notify_user_info_entry_get_value(aEntry));
  mValue = value;
  g_free(value);
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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);	
	}
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
Tag *FacebookProtocol::getVCardTag(User *user, GList *vcardEntries) {
	PurpleNotifyUserInfoEntry *vcardEntry;
	std::string firstName;
	std::string lastName;
	std::string header;
	std::string label;
	std::string description("");

	Tag *vcard = new Tag( "vCard" );
	vcard->addAttribute( "xmlns", "vcard-temp" );

	while (vcardEntries) {
		vcardEntry = (PurpleNotifyUserInfoEntry *)(vcardEntries->data);
		if (purple_notify_user_info_entry_get_label(vcardEntry) && purple_notify_user_info_entry_get_value(vcardEntry)){
			label = (std::string) purple_notify_user_info_entry_get_label(vcardEntry);
			Log("vcard label", label << " => " << (std::string)purple_notify_user_info_entry_get_value(vcardEntry));
			if (label==tr(user->getLang(),"Gender")){
				vcard->addChild( new Tag("GENDER", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
			}
			else if (label==tr(user->getLang(),"Name")){
				vcard->addChild( new Tag("FN", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
			}
			else if (label==tr(user->getLang(),"Birthday")){
				vcard->addChild( new Tag("BDAY", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)));
			}
			else if (label==tr(user->getLang(),"Mobile")) {
				Tag *tel = new Tag("TEL");
				tel->addChild ( new Tag("CELL") );
				tel->addChild ( new Tag("NUMBER", (std::string)purple_notify_user_info_entry_get_value(vcardEntry)) );
				vcard->addChild(tel);
			}
			else {
				std::string k(purple_notify_user_info_entry_get_value(vcardEntry));
				if (!k.empty()) {
					description+= label + ": " + k + "\n\n";
				}
			}
		}
		else if (purple_notify_user_info_entry_get_type(vcardEntry)==PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER){
			header = (std::string)purple_notify_user_info_entry_get_label(vcardEntry);
			Log("vcard header", header);
// 			if (head)
// 				if (!head->children().empty())
// 					vcard->addChild(head);
// 			if (header=="Home Address"){
// 				head = new Tag("ADR");
// 				head->addChild(new Tag("HOME"));
// 			}
// 			if (header=="Work Address"){
// 				head = new Tag("ADR");
// 				head->addChild(new Tag("WORK"));
// 			}
// 			if (header=="Work Information"){
// 				head = new Tag("ORG");
// 			}
		}
		vcardEntries = vcardEntries->next;
	}

	// add last head if any
// 	if (head)
// 		if (!head->children().empty())
// 			vcard->addChild(head);
	vcard->addChild( new Tag("DESC", description));


	return vcard;
}
Exemplo n.º 7
0
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();
}