コード例 #1
0
bool PurpleIMContactList::removeContactCbk(void * dataIn)
{
//	Mutex::ScopedLock lock(PurpleIMContactList::_mutex);
	Mutex::ScopedLock lock(PurpleIMContactList::_mutexContact);	//VOXOX - JRT - 2009.07.14 

	PurpleIMContactListCallbackData* cbData = (PurpleIMContactListCallbackData*)dataIn;
	PurpleAccount *gAccount = getPurpleAccount( cbData->getInstance() );

	PurpleGroup *gGroup = NULL;
	PurpleBuddy *gBuddy = NULL;

	if ( !cbData->getGroupName().empty() )
	{
		gGroup = purple_find_group( cbData->getGroupName().c_str() );
		gBuddy = purple_find_buddy_in_group(gAccount, cbData->getContactId().c_str(), gGroup );
	}
	else
	{
		gBuddy = purple_find_buddy(gAccount, cbData->getContactId().c_str() );
	}

	if (gBuddy) 
	{
		purple_account_remove_buddy(gAccount, gBuddy, gGroup);
		purple_blist_remove_buddy(gBuddy);
	}

	timeoutRemove( cbData );

	delete cbData;

	return TRUE;
}
コード例 #2
0
ファイル: gevo-util.c プロジェクト: Draghtnod/pidgin
void
gevo_add_buddy(PurpleAccount *account, const char *group_name,
			   const char *buddy_name, const char *alias)
{
	PurpleConversation *conv = NULL;
	PurpleBuddy *buddy;
	PurpleGroup *group;

	conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, buddy_name, account);

	group = purple_find_group(group_name);
	if (group == NULL)
	{
		group = purple_group_new(group_name);
		purple_blist_add_group(group, NULL);
	}

	buddy = purple_find_buddy_in_group(account, buddy_name, group);
	if (buddy == NULL)
	{
		buddy = purple_buddy_new(account, buddy_name, alias);
		purple_blist_add_buddy(buddy, NULL, group, NULL);
	}

	purple_account_add_buddy(account, buddy);

	if (conv != NULL)
	{
		purple_buddy_icon_update(purple_conv_im_get_icon(PURPLE_CONV_IM(conv)));
		purple_conversation_update(conv, PURPLE_CONV_UPDATE_ADD);
	}
}
コード例 #3
0
bool PurpleIMContactList::moveContactToGroupCbk(void * dataIn)
{
	Mutex::ScopedLock lock(PurpleIMContactList::_mutex);

	PurpleIMContactListCallbackData* cbData = (PurpleIMContactListCallbackData*)dataIn;

	PurpleAccount* gAccount  = getPurpleAccount( cbData->getInstance() );
	PurpleGroup*   gOldGroup = purple_find_group( cbData->getOldGroupName().c_str() );

	if (gOldGroup) 
	{
		PurpleBuddy *gBuddy = purple_find_buddy_in_group(gAccount, cbData->getContactId().c_str(), gOldGroup);
		if (gBuddy) 
		{
			PurpleGroup *gNewGroup = purple_find_group( cbData->getNewGroupName().c_str() );
			if (gNewGroup) 
			{
				gNewGroup = purple_group_new(cbData->getNewGroupName().c_str());
				purple_blist_add_buddy(gBuddy, NULL, gNewGroup, NULL);
			}
		}
	}

	timeoutRemove( cbData );

	delete cbData;

	return TRUE;
}
コード例 #4
0
ファイル: BuddyList.cpp プロジェクト: transacid/CenterIM5
void BuddyList::add_buddy_ok_cb(PurpleRequestFields *fields)
{
  PurpleAccount *account = purple_request_fields_get_account(fields, "account");
  const char *name = purple_request_fields_get_string(fields, "name");
  const char *alias = purple_request_fields_get_string(fields, "alias");
  int selected = purple_request_fields_get_choice(fields, "group");
  GList *list = purple_request_field_choice_get_labels(
      purple_request_fields_get_field(fields, "group"));
  const char *group
    = reinterpret_cast<const char*>(g_list_nth_data(list, selected));

  bool err = false;
  if (!account) {
    LOG->Message(_("No account specified."));
    err = true;
  }
  else if (!purple_account_is_connected(account)) {
    LOG->Message(_("Selected account is not connected."));
    err = true;
  }
  if (!name || !name[0]) {
    LOG->Message(_("No buddy name specified."));
    err = true;
  }
  if (!group || !group[0]) {
    LOG->Message(_("No group name specified."));
    err = true;
  }
  if (err) {
    purple_blist_request_add_buddy(account, name, group, alias);
    return;
  }

  PurpleGroup *g = purple_find_group(group);
  if (!g) {
    g = purple_group_new(group);
    purple_blist_add_group(g, NULL);
  }
  PurpleBuddy *b = purple_find_buddy_in_group(account, name, g);
  if (b) {
    LOG->Message(_("Specified buddy is already in the list."));
    return;
  }

  if (alias && !alias[0])
    alias = NULL;
  b = purple_buddy_new(account, name, alias);
  purple_blist_add_buddy(b, NULL, g, NULL);
  purple_account_add_buddy(account, b);
}
コード例 #5
0
ファイル: dialog.c プロジェクト: bf4/pidgin-mac
/* Remove the buddy referenced by the MsnAddRemData before the serverside list is changed.
 * If the buddy will be added, he'll be added back; if he will be removed, he won't be. */
static void
msn_complete_sync_issue(MsnAddRemData *data)
{
	PurpleBuddy *buddy;
	PurpleGroup *group = NULL;

	if (data->group != NULL)
		group = purple_find_group(data->group);
	
	if (group != NULL)
		buddy = purple_find_buddy_in_group(purple_connection_get_account(data->gc), data->who, group);
	else
		buddy = purple_find_buddy(purple_connection_get_account(data->gc), data->who);
	
	if (buddy != NULL)
		purple_blist_remove_buddy(buddy);
}
コード例 #6
0
void rc_push_contact(PurpleAccount *acct,
    const char * buddyname)
{
  PurpleGroup * grp = purple_find_group(GROUP_NAME);
  if (!grp) {
    trace("Group %s Not Found. Create one.", GROUP_NAME);
    grp = purple_group_new(GROUP_NAME);
  }

  PurpleBuddy * buddy;
  // if we can find it in 'Recent Contacts', skip
  if ((buddy = purple_find_buddy_in_group(acct, buddyname, grp)) != NULL) {
    trace("Buddy %s is already in %s", buddyname, GROUP_NAME);
    purple_blist_add_buddy(buddy, NULL, grp, NULL);
    return;
  }

  buddy = purple_find_buddy(acct, buddyname);
  if (!buddy) {
    trace("Buddy %s Not Found. You SUCK!", buddyname);
    return;
  }

  PurpleBlistNode * node = PURPLE_BLIST_NODE(buddy); 

  // back up group info
  PurpleGroup * orig_grp = 	purple_buddy_get_group(buddy);
  purple_blist_node_set_string(node, NODE_GROUP_KEY, orig_grp->name);

  // back up offline info
  gboolean offline = purple_blist_node_get_bool(node, NODE_OFFLINE_KEY);
  purple_blist_node_set_bool(node, NODE_ORIG_OFFLINE_KEY, offline);
  purple_blist_node_set_bool(node, NODE_OFFLINE_KEY, TRUE);

  // Add to Recent Contacts Group
  trace(">>>>>>> Add %s", buddyname);
  purple_blist_add_buddy(buddy, NULL, grp, NULL);

  // Clean up old group if needed
  rc_pop_contacts(grp);
}
コード例 #7
0
ファイル: user.c プロジェクト: Mons/libpurple-mini
/*add group id to User object*/
void
msn_user_add_group_id(MsnUser *user, const char* group_id)
{
	MsnUserList *userlist;
	PurpleAccount *account;
	PurpleBuddy *b;
	PurpleGroup *g;
	const char *passport;
	const char *group_name;

	g_return_if_fail(user != NULL);
	g_return_if_fail(group_id != NULL);

	user->group_ids = g_list_append(user->group_ids, g_strdup(group_id));

	userlist = user->userlist;
	account = userlist->session->account;
	passport = msn_user_get_passport(user);

	group_name = msn_userlist_find_group_name(userlist, group_id);

	purple_debug_info("msn", "User: group id:%s,name:%s,user:%s\n", group_id, group_name, passport);

	g = purple_find_group(group_name);

	if ((group_id == NULL) && (g == NULL))
	{
		g = purple_group_new(group_name);
		purple_blist_add_group(g, NULL);
	}

	b = purple_find_buddy_in_group(account, passport, g);
	if (b == NULL)
	{
		b = purple_buddy_new(account, passport, NULL);
		purple_blist_add_buddy(b, NULL, g, NULL);
	}
	purple_buddy_set_protocol_data(b, user);
	/*Update the blist Node info*/
}
コード例 #8
0
ファイル: remove_buddy.c プロジェクト: benquike/emacs.d
xmlnode * _h_elim_remove_buddy ( const char *name ,
                                 const char *id   ,
                                 SEXP_VALUE *args ,
                                 gpointer data    )
{
    ASSERT_ALISTP( args, id, name );

    fprintf( stderr, "(elim-remove-buddy)\n" );

    elim_ping();
    
    const char    *aname = ALIST_VAL_STR( args, "account-name" );
    const char    *proto = ALIST_VAL_STR( args, "im-protocol"  );
    gpointer       auid  = ALIST_VAL_PTR( args, "account-uid"  );
    PurpleAccount *acct  = NULL;

    gpointer       b_uid = ALIST_VAL_PTR( args, "bnode-uid" );
    const char    *b_arg = NULL;
    const char    *bname = NULL;
    const char    *gname = NULL; 
    PurpleGroup   *group = NULL; 
    PurpleBuddy   *buddy = NULL;
    gboolean       gone  = FALSE;

    if( b_uid )
    {
        PurpleBlistNodeType type = PURPLE_BLIST_OTHER_NODE;
        PurpleBlistNode    *node = find_blist_node_by_uid( b_uid , TRUE );

        if( !node )
        {
            sexp_val_free( args );
            return response_error( EINVAL, id, name, "rogue buddy pointer" );
        }
        type = purple_blist_node_get_type( node );

        // ===========================================================
        // groups, contacts and chats can safely be removed here:
        // buddies should instead be noted for removal in the next
        // block of code as they require client<->server interaction:
        switch( type )
        {
          case PURPLE_BLIST_GROUP_NODE  :
            purple_blist_remove_group  ( (PurpleGroup   *)node );
            gone = TRUE;
            break;
          case PURPLE_BLIST_CONTACT_NODE:
            purple_blist_remove_contact( (PurpleContact *)node );
            gone = TRUE;
            break;
          case PURPLE_BLIST_CHAT_NODE   :
            FIND_ACCOUNT( args, id, name, acct, auid, aname, proto );
            BNODE_ACCOUNT_CHECK(chat,(PurpleChat *)node, acct, args, id, name);
            purple_blist_remove_chat   ( (PurpleChat    *)node );
            gone = TRUE;
            break;
          case PURPLE_BLIST_BUDDY_NODE  :
            buddy = (PurpleBuddy *)node;
            FIND_ACCOUNT( args, id, name, acct, auid, aname, proto );
            BNODE_ACCOUNT_CHECK( buddy, buddy, acct, args, id, name );
            b_arg = purple_buddy_get_name( buddy );
            bname = purple_normalize( acct, b_arg );
            break;
          default:
            sexp_val_free( args );
            return response_error( EINVAL, id, name, 
                                   "Unknown buddy list node type" );
        }

        if( gone )
        {
            xmlnode *rval = xnode_new( "alist" );
            if( acct )
            {
                AL_STR( rval, "account-name", aname );
                AL_STR( rval, "im-protocol" , proto );
                AL_PTR( rval, "account-uid" , acct  );
            }
            AL_PTR ( rval, "bnode-uid" , buddy );
            AL_ENUM( rval, "bnode-type", type  , ":blist-node-type" );

            sexp_val_free( args );
            return response_value( 0, id, name, rval );
        }
    }
    else
    {
        b_arg = ALIST_VAL_STRING( args, "bnode-name" );
        FIND_ACCOUNT( args, id, name, acct, auid, aname, proto );

        if( b_arg )
        {
            bname = purple_normalize( acct, b_arg   );
            gname = ALIST_VAL_STRING( args, "group" );
            group = ( gname && *gname ) ? purple_find_group( gname ) : NULL;
            buddy = ( group ?
                      purple_find_buddy_in_group( acct, bname, group ) :
                      purple_find_buddy         ( acct, bname        ) );
        }
    }

    if( !b_arg || !*b_arg )
    {
        sexp_val_free( args );
        return response_error( EINVAL, id, name, "buddy not specified" );
    }

    // buddy must be in our local list or libpurple won't remove it from the
    // server list ( determined empirically, confirmed by inspecting code ):
    if( !buddy )
    {
        buddy = purple_buddy_new( acct, bname, bname );
        purple_blist_add_buddy  ( buddy, NULL, NULL, NULL );
    }

    if( buddy )
    {
        // the order of the remove operations is important: it has to be
        // this way round, as noted above: account buddy removal won't 
        // happen if the buddy is not in the blist when we try:
        if( !group ) group = purple_buddy_get_group( buddy );
        // is this correct? what if we have more than one copy of said buddy?
        // potentially confusing. dunno what the right thing to do is here.
        purple_account_remove_buddy( acct, buddy, group );
        purple_blist_remove_buddy( buddy );
    }
    else 
    {
        sexp_val_free( args );
        return response_error( ENXIO, id, name, "no such buddy" );
    }
    
    xmlnode *rval = xnode_new( "alist" );
    AL_STR ( rval, "account-name", purple_account_get_username   ( acct ) );
    AL_STR ( rval, "im-protocol" , purple_account_get_protocol_id( acct ) );
    AL_PTR ( rval, "account-uid" , acct  );
    AL_PTR ( rval, "bnode-uid"   , buddy );
    AL_ENUM( rval, "bnode-type", PURPLE_BLIST_BUDDY_NODE, ":blist-node-type" );
    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}