diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-06-07 19:40:08 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-06-07 19:40:08 +0100 | 
| commit | 619dd1882deb7f507882748982744cc275dd92a9 (patch) | |
| tree | 12a32823ff18163a849cf2d18b2aa6e74efbf01c | |
| parent | a4d920bfc34db9ca9161ff3817385423e52b8c90 (diff) | |
Paste buffer functionality is back, now for users *and* rooms.
| -rw-r--r-- | irc.h | 9 | ||||
| -rw-r--r-- | irc_im.c | 78 | ||||
| -rw-r--r-- | irc_user.c | 4 | 
3 files changed, 80 insertions, 11 deletions
| @@ -108,10 +108,8 @@ typedef struct irc_user  	irc_user_flags_t flags; -	char *sendbuf; -	int sendbuf_len; -	guint sendbuf_timer; -	//int sendbuf_flags; +	GString *pastebuf; +	guint pastebuf_timer;  	struct bee_user *bu; @@ -150,6 +148,9 @@ typedef struct irc_channel  	GSList *users;  	struct set *set; +	GString *pastebuf; +	guint pastebuf_timer; +	  	const struct irc_channel_funcs *f;  	void *data;  } irc_channel_t; @@ -272,12 +272,46 @@ static gboolean bee_irc_user_group( bee_t *bee, bee_user_t *bu )  /* IRC->IM calls */ +static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond ); +  static gboolean bee_irc_user_privmsg( irc_user_t *iu, const char *msg )  { -	if( iu->bu ) -		return bee_user_msg( iu->irc->b, iu->bu, msg, 0 ); -	else +	if( iu->bu == NULL )  		return FALSE; +	else if( set_getbool( &iu->irc->b->set, "paste_buffer" ) ) +	{ +		int delay; +		 +		if( iu->pastebuf == NULL ) +			iu->pastebuf = g_string_new( msg ); +		else +		{ +			b_event_remove( iu->pastebuf_timer ); +			g_string_append_printf( iu->pastebuf, "\n%s", msg ); +		} +		 +		if( ( delay = set_getint( &iu->irc->b->set, "paste_buffer_delay" ) ) <= 5 ) +			delay *= 1000; +		 +		iu->pastebuf_timer = b_timeout_add( delay, bee_irc_user_privmsg_cb, iu ); +		 +		return TRUE; +	} +	else +		return bee_user_msg( iu->irc->b, iu->bu, msg, 0 ); +} + +static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond ) +{ +	irc_user_t *iu = data; +	 +	bee_user_msg( iu->irc->b, iu->bu, iu->pastebuf->str, 0 ); +	 +	g_string_free( iu->pastebuf, TRUE ); +	iu->pastebuf = 0; +	iu->pastebuf_timer = 0; +	 +	return FALSE;  }  static gboolean bee_irc_user_ctcp( irc_user_t *iu, char *const *ctcp ) @@ -467,18 +501,52 @@ static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const c  }  /* IRC->IM */ +static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond ); +  static gboolean bee_irc_channel_chat_privmsg( irc_channel_t *ic, const char *msg )  {  	struct groupchat *c = ic->data;  	if( c == NULL )  		return FALSE; -	 -	bee_chat_msg( ic->irc->b, c, msg, 0 ); +	else if( set_getbool( &ic->irc->b->set, "paste_buffer" ) ) +	{ +		int delay; +		 +		if( ic->pastebuf == NULL ) +			ic->pastebuf = g_string_new( msg ); +		else +		{ +			b_event_remove( ic->pastebuf_timer ); +			g_string_append_printf( ic->pastebuf, "\n%s", msg ); +		} +		 +		if( ( delay = set_getint( &ic->irc->b->set, "paste_buffer_delay" ) ) <= 5 ) +			delay *= 1000; +		 +		ic->pastebuf_timer = b_timeout_add( delay, bee_irc_channel_chat_privmsg_cb, ic ); +		 +		return TRUE; +	} +	else +		bee_chat_msg( ic->irc->b, c, msg, 0 );  	return TRUE;  } +static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond ) +{ +	irc_channel_t *ic = data; +	 +	bee_chat_msg( ic->irc->b, ic->data, ic->pastebuf->str, 0 ); +	 +	g_string_free( ic->pastebuf, TRUE ); +	ic->pastebuf = 0; +	ic->pastebuf_timer = 0; +	 +	return FALSE; +} +  static gboolean bee_irc_channel_chat_join( irc_channel_t *ic )  {  	char *acc_s, *room; @@ -103,8 +103,8 @@ int irc_user_free( irc_t *irc, irc_user_t *iu )  	if( iu->nick != iu->user ) g_free( iu->user );  	if( iu->nick != iu->host ) g_free( iu->host );  	if( iu->nick != iu->fullname ) g_free( iu->fullname ); -	g_free( iu->sendbuf ); -	if( iu->sendbuf_timer ) b_event_remove( iu->sendbuf_timer ); +	g_free( iu->pastebuf ); +	if( iu->pastebuf_timer ) b_event_remove( iu->pastebuf_timer );  	g_free( iu->key );  	return 1; | 
