| 1 /* |
|
| 2 * gaim |
|
| 3 * |
|
| 4 * Gaim is the legal property of its developers, whose names are too numerous |
|
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
| 6 * source distribution. |
|
| 7 * |
|
| 8 * This program is free software; you can redistribute it and/or modify |
|
| 9 * it under the terms of the GNU General Public License as published by |
|
| 10 * the Free Software Foundation; either version 2 of the License, or |
|
| 11 * (at your option) any later version. |
|
| 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 * You should have received a copy of the GNU General Public License |
|
| 19 * along with this program; if not, write to the Free Software |
|
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 21 * |
|
| 22 */ |
|
| 23 |
|
| 24 #include <string.h> |
|
| 25 |
|
| 26 #include "whiteboard.h" |
|
| 27 #include "prpl.h" |
|
| 28 |
|
| 29 /****************************************************************************** |
|
| 30 * Globals |
|
| 31 *****************************************************************************/ |
|
| 32 static GaimWhiteboardUiOps *whiteboard_ui_ops = NULL; |
|
| 33 /* static GaimWhiteboardPrplOps *whiteboard_prpl_ops = NULL; */ |
|
| 34 |
|
| 35 static GList *wbList = NULL; |
|
| 36 |
|
| 37 /*static gboolean auto_accept = TRUE; */ |
|
| 38 |
|
| 39 /****************************************************************************** |
|
| 40 * API |
|
| 41 *****************************************************************************/ |
|
| 42 void gaim_whiteboard_set_ui_ops(GaimWhiteboardUiOps *ops) |
|
| 43 { |
|
| 44 whiteboard_ui_ops = ops; |
|
| 45 } |
|
| 46 |
|
| 47 void gaim_whiteboard_set_prpl_ops(GaimWhiteboard *wb, GaimWhiteboardPrplOps *ops) |
|
| 48 { |
|
| 49 wb->prpl_ops = ops; |
|
| 50 } |
|
| 51 |
|
| 52 GaimWhiteboard *gaim_whiteboard_create(GaimAccount *account, const char *who, int state) |
|
| 53 { |
|
| 54 GaimPluginProtocolInfo *prpl_info; |
|
| 55 GaimWhiteboard *wb = g_new0(GaimWhiteboard, 1); |
|
| 56 |
|
| 57 wb->account = account; |
|
| 58 wb->state = state; |
|
| 59 wb->who = g_strdup(who); |
|
| 60 |
|
| 61 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); |
|
| 62 gaim_whiteboard_set_prpl_ops(wb, prpl_info->whiteboard_prpl_ops); |
|
| 63 |
|
| 64 /* Start up protocol specifics */ |
|
| 65 if(wb->prpl_ops && wb->prpl_ops->start) |
|
| 66 wb->prpl_ops->start(wb); |
|
| 67 |
|
| 68 wbList = g_list_append(wbList, wb); |
|
| 69 |
|
| 70 return wb; |
|
| 71 } |
|
| 72 |
|
| 73 void gaim_whiteboard_destroy(GaimWhiteboard *wb) |
|
| 74 { |
|
| 75 g_return_if_fail(wb != NULL); |
|
| 76 |
|
| 77 if(wb->ui_data) |
|
| 78 { |
|
| 79 /* Destroy frontend */ |
|
| 80 if(whiteboard_ui_ops && whiteboard_ui_ops->destroy) |
|
| 81 whiteboard_ui_ops->destroy(wb); |
|
| 82 } |
|
| 83 |
|
| 84 /* Do protocol specific session ending procedures */ |
|
| 85 if(wb->prpl_ops && wb->prpl_ops->end) |
|
| 86 wb->prpl_ops->end(wb); |
|
| 87 |
|
| 88 g_free(wb->who); |
|
| 89 wbList = g_list_remove(wbList, wb); |
|
| 90 g_free(wb); |
|
| 91 } |
|
| 92 |
|
| 93 void gaim_whiteboard_start(GaimWhiteboard *wb) |
|
| 94 { |
|
| 95 /* Create frontend for whiteboard */ |
|
| 96 if(whiteboard_ui_ops && whiteboard_ui_ops->create) |
|
| 97 whiteboard_ui_ops->create(wb); |
|
| 98 } |
|
| 99 |
|
| 100 /* Looks through the list of whiteboard sessions for one that is between |
|
| 101 * usernames 'me' and 'who'. Returns a pointer to a matching whiteboard |
|
| 102 * session; if none match, it returns NULL. |
|
| 103 */ |
|
| 104 GaimWhiteboard *gaim_whiteboard_get_session(GaimAccount *account, const char *who) |
|
| 105 { |
|
| 106 GaimWhiteboard *wb = NULL; |
|
| 107 |
|
| 108 GList *l = wbList; |
|
| 109 |
|
| 110 /* Look for a whiteboard session between the local user and the remote user |
|
| 111 */ |
|
| 112 while(l != NULL) |
|
| 113 { |
|
| 114 wb = l->data; |
|
| 115 |
|
| 116 if(wb->account == account && !strcmp(wb->who, who)) |
|
| 117 return wb; |
|
| 118 |
|
| 119 l = l->next; |
|
| 120 } |
|
| 121 |
|
| 122 return NULL; |
|
| 123 } |
|
| 124 |
|
| 125 void gaim_whiteboard_draw_list_destroy(GList *draw_list) |
|
| 126 { |
|
| 127 g_list_free(draw_list); |
|
| 128 } |
|
| 129 |
|
| 130 gboolean gaim_whiteboard_get_dimensions(GaimWhiteboard *wb, int *width, int *height) |
|
| 131 { |
|
| 132 GaimWhiteboardPrplOps *prpl_ops = wb->prpl_ops; |
|
| 133 |
|
| 134 if (prpl_ops && prpl_ops->get_dimensions) |
|
| 135 { |
|
| 136 prpl_ops->get_dimensions(wb, width, height); |
|
| 137 return TRUE; |
|
| 138 } |
|
| 139 |
|
| 140 return FALSE; |
|
| 141 } |
|
| 142 |
|
| 143 void gaim_whiteboard_set_dimensions(GaimWhiteboard *wb, int width, int height) |
|
| 144 { |
|
| 145 if(whiteboard_ui_ops && whiteboard_ui_ops->set_dimensions) |
|
| 146 whiteboard_ui_ops->set_dimensions(wb, width, height); |
|
| 147 } |
|
| 148 |
|
| 149 void gaim_whiteboard_send_draw_list(GaimWhiteboard *wb, GList *list) |
|
| 150 { |
|
| 151 GaimWhiteboardPrplOps *prpl_ops = wb->prpl_ops; |
|
| 152 |
|
| 153 if (prpl_ops && prpl_ops->send_draw_list) |
|
| 154 prpl_ops->send_draw_list(wb, list); |
|
| 155 } |
|
| 156 |
|
| 157 void gaim_whiteboard_draw_point(GaimWhiteboard *wb, int x, int y, int color, int size) |
|
| 158 { |
|
| 159 if(whiteboard_ui_ops && whiteboard_ui_ops->draw_point) |
|
| 160 whiteboard_ui_ops->draw_point(wb, x, y, color, size); |
|
| 161 } |
|
| 162 |
|
| 163 void gaim_whiteboard_draw_line(GaimWhiteboard *wb, int x1, int y1, int x2, int y2, int color, int size) |
|
| 164 { |
|
| 165 if(whiteboard_ui_ops && whiteboard_ui_ops->draw_line) |
|
| 166 whiteboard_ui_ops->draw_line(wb, x1, y1, x2, y2, color, size); |
|
| 167 } |
|
| 168 |
|
| 169 void gaim_whiteboard_clear(GaimWhiteboard *wb) |
|
| 170 { |
|
| 171 if(whiteboard_ui_ops && whiteboard_ui_ops->clear) |
|
| 172 whiteboard_ui_ops->clear(wb); |
|
| 173 } |
|
| 174 |
|
| 175 void gaim_whiteboard_send_clear(GaimWhiteboard *wb) |
|
| 176 { |
|
| 177 GaimWhiteboardPrplOps *prpl_ops = wb->prpl_ops; |
|
| 178 |
|
| 179 if (prpl_ops && prpl_ops->clear) |
|
| 180 prpl_ops->clear(wb); |
|
| 181 } |
|
| 182 |
|
| 183 void gaim_whiteboard_send_brush(GaimWhiteboard *wb, int size, int color) |
|
| 184 { |
|
| 185 GaimWhiteboardPrplOps *prpl_ops = wb->prpl_ops; |
|
| 186 |
|
| 187 if (prpl_ops && prpl_ops->set_brush) |
|
| 188 prpl_ops->set_brush(wb, size, color); |
|
| 189 } |
|
| 190 |
|
| 191 gboolean gaim_whiteboard_get_brush(GaimWhiteboard *wb, int *size, int *color) |
|
| 192 { |
|
| 193 GaimWhiteboardPrplOps *prpl_ops = wb->prpl_ops; |
|
| 194 |
|
| 195 if (prpl_ops && prpl_ops->get_brush) |
|
| 196 { |
|
| 197 prpl_ops->get_brush(wb, size, color); |
|
| 198 return TRUE; |
|
| 199 } |
|
| 200 return FALSE; |
|
| 201 } |
|
| 202 |
|
| 203 void gaim_whiteboard_set_brush(GaimWhiteboard *wb, int size, int color) |
|
| 204 { |
|
| 205 if (whiteboard_ui_ops && whiteboard_ui_ops->set_brush) |
|
| 206 whiteboard_ui_ops->set_brush(wb, size, color); |
|
| 207 } |
|
| 208 |
|