Sun, 14 Oct 2007 18:07:19 +0000
Converted string literal UI hints to #define-ed constants and fixed two cast-warnings in gtkblist.c
| 12058 | 1 | /* |
| 2 | ||
| 3 | wb.c | |
| 4 | ||
| 5 | Author: Pekka Riikonen <priikone@silcnet.org> | |
| 6 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
7 | Copyright (C) 2005 - 2007 Pekka Riikonen |
| 12058 | 8 | |
| 9 | This program is free software; you can redistribute it and/or modify | |
| 10 | it under the terms of the GNU General Public License as published by | |
| 11 | the Free Software Foundation; version 2 of the License. | |
| 12 | ||
| 13 | This program is distributed in the hope that it will be useful, | |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | GNU General Public License for more details. | |
| 17 | ||
| 18 | */ | |
| 19 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
20 | #include "silc.h" |
| 12058 | 21 | #include "silcclient.h" |
| 15884 | 22 | #include "silcpurple.h" |
| 12058 | 23 | #include "wb.h" |
| 24 | ||
| 25 | /* | |
| 26 | SILC Whiteboard packet: | |
| 27 | ||
| 28 | 1 byte command | |
| 29 | 2 bytes width | |
| 30 | 2 bytes height | |
| 31 | 4 bytes brush color | |
| 32 | 2 bytes brush size | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
33 | n bytes data |
| 12058 | 34 | |
| 35 | Data: | |
| 36 | ||
| 37 | 4 bytes x | |
| 38 | 4 bytes y | |
| 39 | ||
| 40 | Commands: | |
| 41 | ||
| 42 | 0x01 draw | |
| 43 | 0x02 clear | |
| 44 | ||
| 45 | MIME: | |
| 46 | ||
| 47 | MIME-Version: 1.0 | |
| 48 | Content-Type: application/x-wb | |
| 49 | Content-Transfer-Encoding: binary | |
| 50 | ||
| 51 | */ | |
| 52 | ||
| 15884 | 53 | #define SILCPURPLE_WB_MIME "MIME-Version: 1.0\r\nContent-Type: application/x-wb\r\nContent-Transfer-Encoding: binary\r\n\r\n" |
| 54 | #define SILCPURPLE_WB_HEADER strlen(SILCPURPLE_WB_MIME) + 11 | |
| 12058 | 55 | |
| 15884 | 56 | #define SILCPURPLE_WB_WIDTH 500 |
| 57 | #define SILCPURPLE_WB_HEIGHT 400 | |
| 58 | #define SILCPURPLE_WB_WIDTH_MAX 1024 | |
| 59 | #define SILCPURPLE_WB_HEIGHT_MAX 1024 | |
| 12058 | 60 | |
| 61 | /* Commands */ | |
| 62 | typedef enum { | |
| 15884 | 63 | SILCPURPLE_WB_DRAW = 0x01, |
| 64 | SILCPURPLE_WB_CLEAR = 0x02, | |
| 65 | } SilcPurpleWbCommand; | |
| 12058 | 66 | |
| 67 | /* Brush size */ | |
| 68 | typedef enum { | |
| 15884 | 69 | SILCPURPLE_WB_BRUSH_SMALL = 2, |
| 70 | SILCPURPLE_WB_BRUSH_MEDIUM = 5, | |
| 71 | SILCPURPLE_WB_BRUSH_LARGE = 10, | |
| 72 | } SilcPurpleWbBrushSize; | |
| 12058 | 73 | |
| 15884 | 74 | /* Brush color (XXX Purple should provide default colors) */ |
| 12058 | 75 | typedef enum { |
| 15884 | 76 | SILCPURPLE_WB_COLOR_BLACK = 0, |
| 77 | SILCPURPLE_WB_COLOR_RED = 13369344, | |
| 78 | SILCPURPLE_WB_COLOR_GREEN = 52224, | |
| 79 | SILCPURPLE_WB_COLOR_BLUE = 204, | |
| 80 | SILCPURPLE_WB_COLOR_YELLOW = 15658496, | |
| 81 | SILCPURPLE_WB_COLOR_ORANGE = 16737792, | |
| 82 | SILCPURPLE_WB_COLOR_CYAN = 52428, | |
| 83 | SILCPURPLE_WB_COLOR_VIOLET = 5381277, | |
| 84 | SILCPURPLE_WB_COLOR_PURPLE = 13369548, | |
| 85 | SILCPURPLE_WB_COLOR_TAN = 12093547, | |
| 86 | SILCPURPLE_WB_COLOR_BROWN = 5256485, | |
| 87 | SILCPURPLE_WB_COLOR_GREY = 11184810, | |
| 88 | SILCPURPLE_WB_COLOR_WHITE = 16777215, | |
| 89 | } SilcPurpleWbColor; | |
| 12058 | 90 | |
| 91 | typedef struct { | |
| 92 | int type; /* 0 = buddy, 1 = channel */ | |
| 93 | union { | |
| 94 | SilcClientEntry client; | |
| 95 | SilcChannelEntry channel; | |
| 96 | } u; | |
| 97 | int width; | |
| 98 | int height; | |
| 99 | int brush_size; | |
| 100 | int brush_color; | |
| 15884 | 101 | } *SilcPurpleWb; |
| 12058 | 102 | |
| 103 | /* Initialize whiteboard */ | |
| 104 | ||
| 15884 | 105 | PurpleWhiteboard *silcpurple_wb_init(SilcPurple sg, SilcClientEntry client_entry) |
| 12058 | 106 | { |
| 107 | SilcClientConnection conn; | |
| 15884 | 108 | PurpleWhiteboard *wb; |
| 109 | SilcPurpleWb wbs; | |
| 12058 | 110 | |
| 111 | conn = sg->conn; | |
| 15884 | 112 | wb = purple_whiteboard_get_session(sg->account, client_entry->nickname); |
| 12058 | 113 | if (!wb) |
| 15884 | 114 | wb = purple_whiteboard_create(sg->account, client_entry->nickname, 0); |
| 12058 | 115 | if (!wb) |
| 116 | return NULL; | |
| 117 | ||
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
118 | if (!wb->proto_data) { |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
119 | wbs = silc_calloc(1, sizeof(*wbs)); |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
120 | if (!wbs) |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
121 | return NULL; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
122 | wbs->type = 0; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
123 | wbs->u.client = client_entry; |
| 15884 | 124 | wbs->width = SILCPURPLE_WB_WIDTH; |
| 125 | wbs->height = SILCPURPLE_WB_HEIGHT; | |
| 126 | wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; | |
| 127 | wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
128 | wb->proto_data = wbs; |
| 12058 | 129 | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
130 | /* Start the whiteboard */ |
| 15884 | 131 | purple_whiteboard_start(wb); |
| 132 | purple_whiteboard_clear(wb); | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
133 | } |
| 12058 | 134 | |
| 135 | return wb; | |
| 136 | } | |
| 137 | ||
| 15884 | 138 | PurpleWhiteboard *silcpurple_wb_init_ch(SilcPurple sg, SilcChannelEntry channel) |
| 12058 | 139 | { |
| 15884 | 140 | PurpleWhiteboard *wb; |
| 141 | SilcPurpleWb wbs; | |
| 12058 | 142 | |
| 15884 | 143 | wb = purple_whiteboard_get_session(sg->account, channel->channel_name); |
| 12058 | 144 | if (!wb) |
| 15884 | 145 | wb = purple_whiteboard_create(sg->account, channel->channel_name, 0); |
| 12058 | 146 | if (!wb) |
| 147 | return NULL; | |
| 148 | ||
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
149 | if (!wb->proto_data) { |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
150 | wbs = silc_calloc(1, sizeof(*wbs)); |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
151 | if (!wbs) |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
152 | return NULL; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
153 | wbs->type = 1; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
154 | wbs->u.channel = channel; |
| 15884 | 155 | wbs->width = SILCPURPLE_WB_WIDTH; |
| 156 | wbs->height = SILCPURPLE_WB_HEIGHT; | |
| 157 | wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; | |
| 158 | wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
159 | wb->proto_data = wbs; |
| 12058 | 160 | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
161 | /* Start the whiteboard */ |
| 15884 | 162 | purple_whiteboard_start(wb); |
| 163 | purple_whiteboard_clear(wb); | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
164 | } |
| 12058 | 165 | |
| 166 | return wb; | |
| 167 | } | |
| 168 | ||
| 169 | static void | |
| 15884 | 170 | silcpurple_wb_parse(SilcPurpleWb wbs, PurpleWhiteboard *wb, |
| 12058 | 171 | unsigned char *message, SilcUInt32 message_len) |
| 172 | { | |
| 173 | SilcUInt8 command; | |
| 174 | SilcUInt16 width, height, brush_size; | |
| 175 | SilcUInt32 brush_color, x, y, dx, dy; | |
| 176 | SilcBufferStruct buf; | |
| 177 | int ret; | |
| 178 | ||
| 179 | /* Parse the packet */ | |
| 180 | silc_buffer_set(&buf, message, message_len); | |
| 181 | ret = silc_buffer_unformat(&buf, | |
| 182 | SILC_STR_UI_CHAR(&command), | |
| 183 | SILC_STR_UI_SHORT(&width), | |
| 184 | SILC_STR_UI_SHORT(&height), | |
| 185 | SILC_STR_UI_INT(&brush_color), | |
| 186 | SILC_STR_UI_SHORT(&brush_size), | |
| 187 | SILC_STR_END); | |
| 188 | if (ret < 0) | |
| 189 | return; | |
| 190 | silc_buffer_pull(&buf, ret); | |
| 191 | ||
| 192 | /* Update whiteboard if its dimensions changed */ | |
| 193 | if (width != wbs->width || height != wbs->height) | |
| 15884 | 194 | silcpurple_wb_set_dimensions(wb, height, width); |
| 12058 | 195 | |
| 15884 | 196 | if (command == SILCPURPLE_WB_DRAW) { |
| 12058 | 197 | /* Parse data and draw it */ |
| 198 | ret = silc_buffer_unformat(&buf, | |
| 199 | SILC_STR_UI_INT(&dx), | |
| 200 | SILC_STR_UI_INT(&dy), | |
| 201 | SILC_STR_END); | |
| 202 | if (ret < 0) | |
| 203 | return; | |
| 204 | silc_buffer_pull(&buf, 8); | |
| 205 | x = dx; | |
| 206 | y = dy; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
207 | while (silc_buffer_len(&buf) > 0) { |
| 12058 | 208 | ret = silc_buffer_unformat(&buf, |
| 209 | SILC_STR_UI_INT(&dx), | |
| 210 | SILC_STR_UI_INT(&dy), | |
| 211 | SILC_STR_END); | |
| 212 | if (ret < 0) | |
| 213 | return; | |
| 214 | silc_buffer_pull(&buf, 8); | |
| 215 | ||
| 15884 | 216 | purple_whiteboard_draw_line(wb, x, y, x + dx, y + dy, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
217 | brush_color, brush_size); |
| 12058 | 218 | x += dx; |
| 219 | y += dy; | |
| 220 | } | |
| 221 | } | |
| 222 | ||
| 15884 | 223 | if (command == SILCPURPLE_WB_CLEAR) |
| 224 | purple_whiteboard_clear(wb); | |
| 12058 | 225 | } |
| 226 | ||
| 227 | typedef struct { | |
| 228 | unsigned char *message; | |
| 229 | SilcUInt32 message_len; | |
| 15884 | 230 | SilcPurple sg; |
| 12058 | 231 | SilcClientEntry sender; |
| 232 | SilcChannelEntry channel; | |
| 15884 | 233 | } *SilcPurpleWbRequest; |
| 12058 | 234 | |
| 235 | static void | |
| 15884 | 236 | silcpurple_wb_request_cb(SilcPurpleWbRequest req, gint id) |
| 12058 | 237 | { |
| 15884 | 238 | PurpleWhiteboard *wb; |
| 12058 | 239 | |
| 240 | if (id != 1) | |
| 241 | goto out; | |
| 242 | ||
| 243 | if (!req->channel) | |
| 15884 | 244 | wb = silcpurple_wb_init(req->sg, req->sender); |
| 12058 | 245 | else |
| 15884 | 246 | wb = silcpurple_wb_init_ch(req->sg, req->channel); |
| 12058 | 247 | |
| 15884 | 248 | silcpurple_wb_parse(wb->proto_data, wb, req->message, req->message_len); |
| 12058 | 249 | |
| 250 | out: | |
| 251 | silc_free(req->message); | |
| 252 | silc_free(req); | |
| 253 | } | |
| 254 | ||
| 255 | static void | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
256 | silcpurple_wb_request(SilcClient client, const unsigned char *message, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
257 | SilcUInt32 message_len, SilcClientEntry sender, |
| 12058 | 258 | SilcChannelEntry channel) |
| 259 | { | |
| 260 | char tmp[128]; | |
| 15884 | 261 | SilcPurpleWbRequest req; |
| 262 | PurpleConnection *gc; | |
| 263 | SilcPurple sg; | |
| 12058 | 264 | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
265 | gc = client->application; |
|
16492
4f0dc2d16e55
Update SILC to match resent request API changes
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16396
diff
changeset
|
266 | sg = gc->proto_data; |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
267 | |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
268 | /* Open whiteboard automatically if requested */ |
| 15884 | 269 | if (purple_account_get_bool(sg->account, "open-wb", FALSE)) { |
| 270 | PurpleWhiteboard *wb; | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
271 | |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
272 | if (!channel) |
| 15884 | 273 | wb = silcpurple_wb_init(sg, sender); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
274 | else |
| 15884 | 275 | wb = silcpurple_wb_init_ch(sg, channel); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
276 | |
| 15884 | 277 | silcpurple_wb_parse(wb->proto_data, wb, (unsigned char *)message, |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
278 | message_len); |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
279 | return; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
280 | } |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
281 | |
| 12058 | 282 | if (!channel) { |
| 283 | g_snprintf(tmp, sizeof(tmp), | |
| 284 | _("%s sent message to whiteboard. Would you like " | |
| 285 | "to open the whiteboard?"), sender->nickname); | |
| 286 | } else { | |
| 287 | g_snprintf(tmp, sizeof(tmp), | |
| 288 | _("%s sent message to whiteboard on %s channel. " | |
| 289 | "Would you like to open the whiteboard?"), | |
| 290 | sender->nickname, channel->channel_name); | |
| 291 | } | |
| 292 | ||
| 293 | req = silc_calloc(1, sizeof(*req)); | |
| 294 | if (!req) | |
| 295 | return; | |
| 296 | req->message = silc_memdup(message, message_len); | |
| 297 | req->message_len = message_len; | |
| 298 | req->sender = sender; | |
| 299 | req->channel = channel; | |
| 300 | req->sg = sg; | |
| 301 | ||
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
302 | purple_request_action_with_hint(gc, _("Whiteboard"), tmp, NULL, 1, |
|
21225
32d8e16cb7a9
Converted string literal UI hints to #define-ed constants and fixed two cast-warnings in gtkblist.c
Gabriel Schulhof <nix@go-nix.ca>
parents:
21174
diff
changeset
|
303 | sg->account, sender->nickname, NULL, PURPLE_REQUEST_HINT_BLIST, req, 2, |
| 15884 | 304 | _("Yes"), G_CALLBACK(silcpurple_wb_request_cb), |
| 305 | _("No"), G_CALLBACK(silcpurple_wb_request_cb)); | |
| 12058 | 306 | } |
| 307 | ||
| 308 | /* Process incoming whiteboard message */ | |
| 309 | ||
| 15884 | 310 | void silcpurple_wb_receive(SilcClient client, SilcClientConnection conn, |
| 12058 | 311 | SilcClientEntry sender, SilcMessagePayload payload, |
| 312 | SilcMessageFlags flags, const unsigned char *message, | |
| 313 | SilcUInt32 message_len) | |
| 314 | { | |
| 15884 | 315 | SilcPurple sg; |
| 316 | PurpleConnection *gc; | |
| 317 | PurpleWhiteboard *wb; | |
| 318 | SilcPurpleWb wbs; | |
| 12058 | 319 | |
| 320 | gc = client->application; | |
| 321 | sg = gc->proto_data; | |
| 322 | ||
| 15884 | 323 | wb = purple_whiteboard_get_session(sg->account, sender->nickname); |
| 12058 | 324 | if (!wb) { |
| 325 | /* Ask user if they want to open the whiteboard */ | |
| 15884 | 326 | silcpurple_wb_request(client, message, message_len, |
| 12058 | 327 | sender, NULL); |
| 328 | return; | |
| 329 | } | |
| 330 | ||
| 331 | wbs = wb->proto_data; | |
| 15884 | 332 | silcpurple_wb_parse(wbs, wb, (unsigned char *)message, message_len); |
| 12058 | 333 | } |
| 334 | ||
| 335 | /* Process incoming whiteboard message on channel */ | |
| 336 | ||
| 15884 | 337 | void silcpurple_wb_receive_ch(SilcClient client, SilcClientConnection conn, |
| 12058 | 338 | SilcClientEntry sender, SilcChannelEntry channel, |
| 339 | SilcMessagePayload payload, | |
| 340 | SilcMessageFlags flags, | |
| 341 | const unsigned char *message, | |
| 342 | SilcUInt32 message_len) | |
| 343 | { | |
| 15884 | 344 | SilcPurple sg; |
| 345 | PurpleConnection *gc; | |
| 346 | PurpleWhiteboard *wb; | |
| 347 | SilcPurpleWb wbs; | |
| 12058 | 348 | |
| 349 | gc = client->application; | |
| 350 | sg = gc->proto_data; | |
| 351 | ||
| 15884 | 352 | wb = purple_whiteboard_get_session(sg->account, channel->channel_name); |
| 12058 | 353 | if (!wb) { |
| 354 | /* Ask user if they want to open the whiteboard */ | |
| 15884 | 355 | silcpurple_wb_request(client, message, message_len, |
| 12058 | 356 | sender, channel); |
| 357 | return; | |
| 358 | } | |
| 359 | ||
| 360 | wbs = wb->proto_data; | |
| 15884 | 361 | silcpurple_wb_parse(wbs, wb, (unsigned char *)message, message_len); |
| 12058 | 362 | } |
| 363 | ||
| 364 | /* Send whiteboard message */ | |
| 365 | ||
| 15884 | 366 | void silcpurple_wb_send(PurpleWhiteboard *wb, GList *draw_list) |
| 12058 | 367 | { |
| 15884 | 368 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 369 | SilcBuffer packet; |
| 370 | GList *list; | |
| 371 | int len; | |
| 15884 | 372 | PurpleConnection *gc; |
| 373 | SilcPurple sg; | |
| 12058 | 374 | |
| 375 | g_return_if_fail(draw_list); | |
| 15884 | 376 | gc = purple_account_get_connection(wb->account); |
| 12058 | 377 | g_return_if_fail(gc); |
| 378 | sg = gc->proto_data; | |
| 379 | g_return_if_fail(sg); | |
| 380 | ||
| 15884 | 381 | len = SILCPURPLE_WB_HEADER; |
| 12058 | 382 | for (list = draw_list; list; list = list->next) |
| 383 | len += 4; | |
| 384 | ||
| 385 | packet = silc_buffer_alloc_size(len); | |
| 386 | if (!packet) | |
| 387 | return; | |
| 388 | ||
| 389 | /* Assmeble packet */ | |
| 390 | silc_buffer_format(packet, | |
| 15884 | 391 | SILC_STR_UI32_STRING(SILCPURPLE_WB_MIME), |
| 392 | SILC_STR_UI_CHAR(SILCPURPLE_WB_DRAW), | |
| 12058 | 393 | SILC_STR_UI_SHORT(wbs->width), |
| 394 | SILC_STR_UI_SHORT(wbs->height), | |
| 395 | SILC_STR_UI_INT(wbs->brush_color), | |
| 396 | SILC_STR_UI_SHORT(wbs->brush_size), | |
| 397 | SILC_STR_END); | |
| 15884 | 398 | silc_buffer_pull(packet, SILCPURPLE_WB_HEADER); |
| 12058 | 399 | for (list = draw_list; list; list = list->next) { |
| 400 | silc_buffer_format(packet, | |
| 401 | SILC_STR_UI_INT(GPOINTER_TO_INT(list->data)), | |
| 402 | SILC_STR_END); | |
| 403 | silc_buffer_pull(packet, 4); | |
| 404 | } | |
| 405 | ||
| 406 | /* Send the message */ | |
| 407 | if (wbs->type == 0) { | |
| 408 | /* Private message */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
409 | silc_client_send_private_message(sg->client, sg->conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
410 | wbs->u.client, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
411 | SILC_MESSAGE_FLAG_DATA, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
412 | packet->head, len); |
| 12058 | 413 | } else if (wbs->type == 1) { |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
414 | /* Channel message. Channel private keys are not supported. */ |
| 12058 | 415 | silc_client_send_channel_message(sg->client, sg->conn, |
| 416 | wbs->u.channel, NULL, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
417 | SILC_MESSAGE_FLAG_DATA, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
418 | packet->head, len); |
| 12058 | 419 | } |
| 420 | ||
| 421 | silc_buffer_free(packet); | |
| 422 | } | |
| 423 | ||
| 15884 | 424 | /* Purple Whiteboard operations */ |
| 12058 | 425 | |
| 15884 | 426 | void silcpurple_wb_start(PurpleWhiteboard *wb) |
| 12058 | 427 | { |
| 428 | /* Nothing here. Everything is in initialization */ | |
| 429 | } | |
| 430 | ||
| 15884 | 431 | void silcpurple_wb_end(PurpleWhiteboard *wb) |
| 12058 | 432 | { |
| 433 | silc_free(wb->proto_data); | |
| 434 | wb->proto_data = NULL; | |
| 435 | } | |
| 436 | ||
|
16396
2217b2765e58
Fix two minor compile warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
437 | void silcpurple_wb_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height) |
| 12058 | 438 | { |
| 15884 | 439 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 440 | *width = wbs->width; |
| 441 | *height = wbs->height; | |
| 442 | } | |
| 443 | ||
| 15884 | 444 | void silcpurple_wb_set_dimensions(PurpleWhiteboard *wb, int width, int height) |
| 12058 | 445 | { |
| 15884 | 446 | SilcPurpleWb wbs = wb->proto_data; |
| 447 | wbs->width = width > SILCPURPLE_WB_WIDTH_MAX ? SILCPURPLE_WB_WIDTH_MAX : | |
| 12058 | 448 | width; |
| 15884 | 449 | wbs->height = height > SILCPURPLE_WB_HEIGHT_MAX ? SILCPURPLE_WB_HEIGHT_MAX : |
| 12058 | 450 | height; |
| 451 | ||
| 452 | /* Update whiteboard */ | |
| 15884 | 453 | purple_whiteboard_set_dimensions(wb, wbs->width, wbs->height); |
| 12058 | 454 | } |
| 455 | ||
|
16396
2217b2765e58
Fix two minor compile warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
456 | void silcpurple_wb_get_brush(const PurpleWhiteboard *wb, int *size, int *color) |
| 12058 | 457 | { |
| 15884 | 458 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 459 | *size = wbs->brush_size; |
| 460 | *color = wbs->brush_color; | |
| 461 | } | |
| 462 | ||
| 15884 | 463 | void silcpurple_wb_set_brush(PurpleWhiteboard *wb, int size, int color) |
| 12058 | 464 | { |
| 15884 | 465 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 466 | wbs->brush_size = size; |
| 467 | wbs->brush_color = color; | |
| 468 | ||
| 469 | /* Update whiteboard */ | |
| 15884 | 470 | purple_whiteboard_set_brush(wb, size, color); |
| 12058 | 471 | } |
| 472 | ||
| 15884 | 473 | void silcpurple_wb_clear(PurpleWhiteboard *wb) |
| 12058 | 474 | { |
| 15884 | 475 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 476 | SilcBuffer packet; |
| 477 | int len; | |
| 15884 | 478 | PurpleConnection *gc; |
| 479 | SilcPurple sg; | |
| 12058 | 480 | |
| 15884 | 481 | gc = purple_account_get_connection(wb->account); |
| 12058 | 482 | g_return_if_fail(gc); |
| 483 | sg = gc->proto_data; | |
| 484 | g_return_if_fail(sg); | |
| 485 | ||
| 15884 | 486 | len = SILCPURPLE_WB_HEADER; |
| 12058 | 487 | packet = silc_buffer_alloc_size(len); |
| 488 | if (!packet) | |
| 489 | return; | |
| 490 | ||
| 491 | /* Assmeble packet */ | |
| 492 | silc_buffer_format(packet, | |
| 15884 | 493 | SILC_STR_UI32_STRING(SILCPURPLE_WB_MIME), |
| 494 | SILC_STR_UI_CHAR(SILCPURPLE_WB_CLEAR), | |
| 12058 | 495 | SILC_STR_UI_SHORT(wbs->width), |
| 496 | SILC_STR_UI_SHORT(wbs->height), | |
| 497 | SILC_STR_UI_INT(wbs->brush_color), | |
| 498 | SILC_STR_UI_SHORT(wbs->brush_size), | |
| 499 | SILC_STR_END); | |
| 500 | ||
| 501 | /* Send the message */ | |
| 502 | if (wbs->type == 0) { | |
| 503 | /* Private message */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
504 | silc_client_send_private_message(sg->client, sg->conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
505 | wbs->u.client, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
506 | SILC_MESSAGE_FLAG_DATA, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
507 | packet->head, len); |
| 12058 | 508 | } else if (wbs->type == 1) { |
| 509 | /* Channel message */ | |
| 510 | silc_client_send_channel_message(sg->client, sg->conn, | |
| 511 | wbs->u.channel, NULL, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
512 | SILC_MESSAGE_FLAG_DATA, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
513 | packet->head, len); |
| 12058 | 514 | } |
| 515 | ||
| 516 | silc_buffer_free(packet); | |
| 517 | } |