PurpleWhiteboard *silcpurple_wb_init_ch(SilcPurple sg, SilcChannelEntry channel) { PurpleWhiteboard *wb; SilcPurpleWb wbs; wb = purple_whiteboard_get_session(sg->account, channel->channel_name); if (!wb) wb = purple_whiteboard_create(sg->account, channel->channel_name, 0); if (!wb) return NULL; if (!wb->proto_data) { wbs = silc_calloc(1, sizeof(*wbs)); if (!wbs) return NULL; wbs->type = 1; wbs->u.channel = channel; wbs->width = SILCPURPLE_WB_WIDTH; wbs->height = SILCPURPLE_WB_HEIGHT; wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; wb->proto_data = wbs; /* Start the whiteboard */ purple_whiteboard_start(wb); purple_whiteboard_clear(wb); } return wb; }
PurpleWhiteboard *silcpurple_wb_init(SilcPurple sg, SilcClientEntry client_entry) { SilcClientConnection conn; PurpleWhiteboard *wb; SilcPurpleWb wbs; conn = sg->conn; wb = purple_whiteboard_get_session(sg->account, client_entry->nickname); if (!wb) wb = purple_whiteboard_create(sg->account, client_entry->nickname, 0); if (!wb) return NULL; if (!wb->proto_data) { wbs = silc_calloc(1, sizeof(*wbs)); if (!wbs) return NULL; wbs->type = 0; wbs->u.client = client_entry; wbs->width = SILCPURPLE_WB_WIDTH; wbs->height = SILCPURPLE_WB_HEIGHT; wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; wb->proto_data = wbs; /* Start the whiteboard */ purple_whiteboard_start(wb); purple_whiteboard_clear(wb); } return wb; }
static void silcpurple_wb_parse(SilcPurpleWb wbs, PurpleWhiteboard *wb, unsigned char *message, SilcUInt32 message_len) { SilcUInt8 command; SilcUInt16 width, height, brush_size; SilcUInt32 brush_color, x, y, dx, dy; SilcBufferStruct buf; int ret; /* Parse the packet */ silc_buffer_set(&buf, message, message_len); ret = silc_buffer_unformat(&buf, SILC_STR_UI_CHAR(&command), SILC_STR_UI_SHORT(&width), SILC_STR_UI_SHORT(&height), SILC_STR_UI_INT(&brush_color), SILC_STR_UI_SHORT(&brush_size), SILC_STR_END); if (ret < 0) return; silc_buffer_pull(&buf, ret); /* Update whiteboard if its dimensions changed */ if (width != wbs->width || height != wbs->height) silcpurple_wb_set_dimensions(wb, height, width); if (command == SILCPURPLE_WB_DRAW) { /* Parse data and draw it */ ret = silc_buffer_unformat(&buf, SILC_STR_UI_INT(&dx), SILC_STR_UI_INT(&dy), SILC_STR_END); if (ret < 0) return; silc_buffer_pull(&buf, 8); x = dx; y = dy; while (silc_buffer_len(&buf) > 0) { ret = silc_buffer_unformat(&buf, SILC_STR_UI_INT(&dx), SILC_STR_UI_INT(&dy), SILC_STR_END); if (ret < 0) return; silc_buffer_pull(&buf, 8); purple_whiteboard_draw_line(wb, x, y, x + dx, y + dy, brush_color, brush_size); x += dx; y += dy; } } if (command == SILCPURPLE_WB_CLEAR) purple_whiteboard_clear(wb); }
static void yahoo_doodle_command_got_ready(PurpleConnection *gc, const char *from, const char *imv_key) { PurpleAccount *account; PurpleWhiteboard *wb; purple_debug_info("yahoo", "doodle: Got Ready(%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_REQUESTING) { doodle_session *ds = wb->proto_data; purple_whiteboard_start(wb); wb->state = DOODLE_STATE_ESTABLISHED; yahoo_doodle_command_send_confirm(gc, from, imv_key); /* Let's steal the imv_key and reuse it */ g_free(ds->imv_key); ds->imv_key = g_strdup(imv_key); } else if(wb->state == DOODLE_STATE_ESTABLISHED) { /* TODO Ask whether to save picture too */ purple_whiteboard_clear(wb); } /* NOTE Not sure about this... I am trying to handle if the remote user * already thinks we're in a session with them (when their chat message * contains the doodle imv key) */ else if(wb->state == DOODLE_STATE_REQUESTED) { /* purple_whiteboard_start(wb); */ yahoo_doodle_command_send_ready(gc, from, imv_key); } }
static 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); } }