diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-06-07 22:09:33 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-06-07 22:09:33 +0100 | 
| commit | 6ef906557277b71fc278e3f612542bd4d7d75ab5 (patch) | |
| tree | cc7ed74c2c11ef8d8554ff154e24307cca9feaed | |
| parent | 619dd1882deb7f507882748982744cc275dd92a9 (diff) | |
Restored nick_hint/nick_source functionality.
| -rw-r--r-- | irc_im.c | 46 | ||||
| -rw-r--r-- | protocols/bee.h | 1 | ||||
| -rw-r--r-- | protocols/nogaim.c | 38 | 
3 files changed, 52 insertions, 33 deletions
| @@ -219,6 +219,8 @@ static gboolean bee_irc_user_typing( bee_t *bee, bee_user_t *bu, uint32_t flags  	return TRUE;  } +static gboolean bee_irc_user_nick_hint( bee_t *bee, bee_user_t *bu, const char *hint ); +  static gboolean bee_irc_user_fullname( bee_t *bee, bee_user_t *bu )  {  	irc_user_t *iu = (irc_user_t *) bu->ui_data; @@ -252,7 +254,7 @@ static gboolean bee_irc_user_fullname( bee_t *bee, bee_user_t *bu )  			name[i] = '\0';  		} -		imcb_buddy_nick_hint( bu->ic, bu->handle, name ); +		bee_irc_user_nick_hint( bee, bu, name );  		g_free( name );  	} @@ -260,6 +262,47 @@ static gboolean bee_irc_user_fullname( bee_t *bee, bee_user_t *bu )  	return TRUE;  } +static gboolean bee_irc_user_nick_hint( bee_t *bee, bee_user_t *bu, const char *hint ) +{ +	irc_user_t *iu = bu->ui_data; +	char newnick[MAX_NICK_LENGTH+1], *translit; +	 +	if( bu->flags & BEE_USER_ONLINE ) +		/* Ignore if the user is visible already. */ +		return TRUE; +	 +	if( nick_saved( bu->ic->acc, bu->handle ) ) +		/* The user already assigned a nickname to this person. */ +		return TRUE; +	 +	/* Credits to Josay_ in #bitlbee for this idea. //TRANSLIT should +	   do lossy/approximate conversions, so letters with accents don't +	   just get stripped. Note that it depends on LC_CTYPE being set to +	   something other than C/POSIX. */ +	translit = g_convert( hint, -1, "ASCII//TRANSLIT//IGNORE", "UTF-8", +	                      NULL, NULL, NULL ); +	 +	strncpy( newnick, translit ? : hint, MAX_NICK_LENGTH ); +	newnick[MAX_NICK_LENGTH] = 0; +	g_free( translit ); +	 +	/* Some processing to make sure this string is a valid IRC nickname. */ +	nick_strip( newnick ); +	if( set_getbool( &bee->set, "lcnicks" ) ) +		nick_lc( newnick ); +	 +	if( strcmp( iu->nick, newnick ) != 0 ) +	{ +		/* Only do this if newnick is different from the current one. +		   If rejoining a channel, maybe we got this nick already +		   (and dedupe would only add an underscore. */ +		nick_dedupe( bu->ic->acc, bu->handle, newnick ); +		irc_user_set_nick( iu, newnick ); +	} +	 +	return TRUE; +} +  static gboolean bee_irc_user_group( bee_t *bee, bee_user_t *bu )  {  	irc_user_t *iu = (irc_user_t *) bu->ui_data; @@ -721,6 +764,7 @@ const struct bee_ui_funcs irc_ui_funcs = {  	bee_irc_user_new,  	bee_irc_user_free,  	bee_irc_user_fullname, +	bee_irc_user_nick_hint,  	bee_irc_user_group,  	bee_irc_user_status,  	bee_irc_user_msg, diff --git a/protocols/bee.h b/protocols/bee.h index c57b4ab5..c3230f47 100644 --- a/protocols/bee.h +++ b/protocols/bee.h @@ -84,6 +84,7 @@ typedef struct bee_ui_funcs  	gboolean (*user_new)( bee_t *bee, struct bee_user *bu );  	gboolean (*user_free)( bee_t *bee, struct bee_user *bu );  	gboolean (*user_fullname)( bee_t *bee, bee_user_t *bu ); +	gboolean (*user_nick_hint)( bee_t *bee, bee_user_t *bu, const char *hint );  	gboolean (*user_group)( bee_t *bee, bee_user_t *bu );  	gboolean (*user_status)( bee_t *bee, struct bee_user *bu, struct bee_user *old );  	gboolean (*user_msg)( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at ); diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 499e4d1d..6ecdfe12 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -417,39 +417,13 @@ void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *grou     modules to suggest a nickname for a handle. */  void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick )  { -#if 0 -	user_t *u = user_findhandle( ic, handle ); -	char newnick[MAX_NICK_LENGTH+1], *orig_nick; +	bee_t *bee = ic->bee; +	bee_user_t *bu = bee_user_by_handle( bee, ic, handle ); -	if( u && !u->online && !nick_saved( ic->acc, handle ) ) -	{ -		/* Only do this if the person isn't online yet (which should -		   be the case if we just added it) and if the user hasn't -		   assigned a nickname to this buddy already. */ -		 -		strncpy( newnick, nick, MAX_NICK_LENGTH ); -		newnick[MAX_NICK_LENGTH] = 0; -		 -		/* Some processing to make sure this string is a valid IRC nickname. */ -		nick_strip( newnick ); -		if( set_getbool( &ic->bee->set, "lcnicks" ) ) -			nick_lc( newnick ); -		 -		if( strcmp( u->nick, newnick ) != 0 ) -		{ -			/* Only do this if newnick is different from the current one. -			   If rejoining a channel, maybe we got this nick already -			   (and dedupe would only add an underscore. */ -			nick_dedupe( ic->acc, handle, newnick ); -			 -			/* u->nick will be freed halfway the process, so it can't be -			   passed as an argument. */ -			orig_nick = g_strdup( u->nick ); -			user_rename( ic->irc, orig_nick, newnick ); -			g_free( orig_nick ); -		} -	} -#endif +	if( !bu || !nick ) return; +	 +	if( bee->ui->user_nick_hint ) +		bee->ui->user_nick_hint( bee, bu, nick );  } | 
