⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yahoo_doodle.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	g_list_free(d_list);}void yahoo_doodle_command_got_clear(PurpleConnection *gc, const char *from){	PurpleAccount *account;	PurpleWhiteboard *wb;	purple_debug_info("yahoo", "doodle: Got Clear (%s)\n", from);	account = purple_connection_get_account(gc);	/* Only handle this if local client requested Doodle session (else local	 * client would have sent one)	 */	wb = purple_whiteboard_get_session(account, from);	if(wb == NULL)		return;	if(wb->state == DOODLE_STATE_ESTABLISHED)	{		/* TODO Ask user whether to save the image before clearing it */		purple_whiteboard_clear(wb);	}}voidyahoo_doodle_command_got_extra(PurpleConnection *gc, const char *from, const char *message){	purple_debug_info("yahoo", "doodle: Got Extra (%s)\n", from);	/* I do not like these 'extra' features, so I'll only handle them in one	 * way, which is returning them with the command/packet to turn them off	 */	yahoo_doodle_command_send_extra(gc, from, DOODLE_EXTRA_NONE);}void yahoo_doodle_command_got_confirm(PurpleConnection *gc, const char *from){	PurpleAccount *account;	PurpleWhiteboard *wb;	purple_debug_info("yahoo", "doodle: Got Confirm (%s)\n", from);	/* Get the doodle session */	account = purple_connection_get_account(gc);	/* Only handle this if local client requested Doodle session (else local	 * client would have sent one)	 */	wb = purple_whiteboard_get_session(account, from);	if(wb == NULL)		return;	/* TODO Combine the following IF's? */	/* Check if we requested a doodle session */	if(wb->state == DOODLE_STATE_REQUESTING)	{		wb->state = DOODLE_STATE_ESTABLISHED;		purple_whiteboard_start(wb);		yahoo_doodle_command_send_confirm(gc, from);	}	/* Check if we accepted a request for a doodle session */	if(wb->state == DOODLE_STATE_REQUESTED)	{		wb->state = DOODLE_STATE_ESTABLISHED;		purple_whiteboard_start(wb);	}}void yahoo_doodle_command_got_shutdown(PurpleConnection *gc, const char *from){	PurpleAccount *account;	PurpleWhiteboard *wb;	g_return_if_fail(from != NULL);	purple_debug_info("yahoo", "doodle: Got Shutdown (%s)\n", from);	account = purple_connection_get_account(gc);	/* Only handle this if local client requested Doodle session (else local	 * client would have sent one)	 */	wb = purple_whiteboard_get_session(account, from);	/* TODO Ask if user wants to save picture before the session is closed */	/* If this session doesn't exist, don't try and kill it */	if(wb == NULL)		return;	else	{		purple_whiteboard_destroy(wb);		/* yahoo_doodle_command_send_shutdown(gc, from); */	}}static void yahoo_doodle_command_send_generic(const char *type,											  PurpleConnection *gc,											  const char *to,											  const char *message,											  const char *thirteen,											  const char *sixtythree,											  const char *sixtyfour){	struct yahoo_data *yd;	struct yahoo_packet *pkt;	purple_debug_info("yahoo", "doodle: Sent %s (%s)\n", type, to);	yd = gc->proto_data;	/* Make and send an acknowledge (ready) Doodle packet */	pkt = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0);	yahoo_packet_hash_str(pkt, 49,  "IMVIRONMENT");	yahoo_packet_hash_str(pkt, 1,    purple_account_get_username(gc->account));	yahoo_packet_hash_str(pkt, 14,   message);	yahoo_packet_hash_str(pkt, 13,   thirteen);	yahoo_packet_hash_str(pkt, 5,    to);	yahoo_packet_hash_str(pkt, 63,   sixtythree ? sixtythree : "doodle;11");	yahoo_packet_hash_str(pkt, 64,   sixtyfour);	yahoo_packet_hash_str(pkt, 1002, "1");	yahoo_packet_send_and_free(pkt, yd);}void yahoo_doodle_command_send_request(PurpleConnection *gc, const char *to){	yahoo_doodle_command_send_generic("Request", gc, to, "1", "1", NULL, "1");}void yahoo_doodle_command_send_ready(PurpleConnection *gc, const char *to){	yahoo_doodle_command_send_generic("Ready", gc, to, "", "0", NULL, "0");}void yahoo_doodle_command_send_draw(PurpleConnection *gc, const char *to, const char *message){	yahoo_doodle_command_send_generic("Draw", gc, to, message, "3", NULL, "1");}void yahoo_doodle_command_send_clear(PurpleConnection *gc, const char *to){	yahoo_doodle_command_send_generic("Clear", gc, to, " ", "2", NULL, "1");}void yahoo_doodle_command_send_extra(PurpleConnection *gc, const char *to, const char *message){	yahoo_doodle_command_send_generic("Extra", gc, to, message, "4", NULL, "1");}void yahoo_doodle_command_send_confirm(PurpleConnection *gc, const char *to){	yahoo_doodle_command_send_generic("Confirm", gc, to, "1", "5", NULL, "1");}void yahoo_doodle_command_send_shutdown(PurpleConnection *gc, const char *to){	yahoo_doodle_command_send_generic("Shutdown", gc, to, "", "0", ";0", "0");}void yahoo_doodle_start(PurpleWhiteboard *wb){	doodle_session *ds = g_new0(doodle_session, 1);	/* purple_debug_debug("yahoo", "doodle: yahoo_doodle_start()\n"); */	/* Set default brush size and color */	ds->brush_size  = DOODLE_BRUSH_SMALL;	ds->brush_color = DOODLE_COLOR_RED;	wb->proto_data = ds;}void yahoo_doodle_end(PurpleWhiteboard *wb){	PurpleConnection *gc = purple_account_get_connection(wb->account);	/* g_debug_debug("yahoo", "doodle: yahoo_doodle_end()\n"); */	yahoo_doodle_command_send_shutdown(gc, wb->who);	g_free(wb->proto_data);}void yahoo_doodle_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height){	/* standard Doodle canvases are of one size:  368x256 */	*width = DOODLE_CANVAS_WIDTH;	*height = DOODLE_CANVAS_HEIGHT;}static char *yahoo_doodle_build_draw_string(doodle_session *ds, GList *draw_list){	GString *message;	g_return_val_if_fail(draw_list != NULL, NULL);	message = g_string_new("");	g_string_printf(message, "\"%d,%d", ds->brush_color, ds->brush_size);	for(; draw_list != NULL; draw_list = draw_list->next)	{		g_string_append_printf(message, ",%d", GPOINTER_TO_INT(draw_list->data));	}	g_string_append_c(message, '"');	return g_string_free(message, FALSE);}void yahoo_doodle_send_draw_list(PurpleWhiteboard *wb, GList *draw_list){	doodle_session *ds = wb->proto_data;	char *message;	g_return_if_fail(draw_list != NULL);	message = yahoo_doodle_build_draw_string(ds, draw_list);		yahoo_doodle_command_send_draw(wb->account->gc, wb->who, message);	g_free(message);}void yahoo_doodle_clear(PurpleWhiteboard *wb){	yahoo_doodle_command_send_clear(wb->account->gc, wb->who);}/* Traverse through the list and draw the points and lines */void yahoo_doodle_draw_stroke(PurpleWhiteboard *wb, GList *draw_list){	int brush_color;	int brush_size;	int x;	int y;	g_return_if_fail(draw_list != NULL);	brush_color = GPOINTER_TO_INT(draw_list->data);	draw_list = draw_list->next;	g_return_if_fail(draw_list != NULL);	brush_size = GPOINTER_TO_INT(draw_list->data);	draw_list = draw_list->next;	g_return_if_fail(draw_list != NULL);	x = GPOINTER_TO_INT(draw_list->data);	draw_list = draw_list->next;	g_return_if_fail(draw_list != NULL);	y = GPOINTER_TO_INT(draw_list->data);	draw_list = draw_list->next;	g_return_if_fail(draw_list != NULL);	/*	purple_debug_debug("yahoo", "doodle: Drawing: color=%d, size=%d, (%d,%d)\n", brush_color, brush_size, x, y);	*/	while(draw_list != NULL && draw_list->next != NULL)	{		int dx = GPOINTER_TO_INT(draw_list->data);		int dy = GPOINTER_TO_INT(draw_list->next->data);		purple_whiteboard_draw_line(wb,								  x, y,								  x + dx, y + dy,								  brush_color, brush_size);		x += dx;		y += dy;		draw_list = draw_list->next->next;	}}void yahoo_doodle_get_brush(const PurpleWhiteboard *wb, int *size, int *color){	doodle_session *ds = (doodle_session *)wb->proto_data;	*size = ds->brush_size;	*color = ds->brush_color;}void yahoo_doodle_set_brush(PurpleWhiteboard *wb, int size, int color){	doodle_session *ds = (doodle_session *)wb->proto_data;	ds->brush_size = size;	ds->brush_color = color;	/* Notify the core about the changes */	purple_whiteboard_set_brush(wb, size, color);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -