Increment version number
[pidgin-git.git] / libpurple / whiteboard.c
blob3ac4c4e010035b5903ba1cc30f378f9e85437d32
1 /*
2 * purple
4 * Purple 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.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
24 #include "internal.h"
25 #include "whiteboard.h"
26 #include "prpl.h"
28 /******************************************************************************
29 * Globals
30 *****************************************************************************/
31 static PurpleWhiteboardUiOps *whiteboard_ui_ops = NULL;
32 /* static PurpleWhiteboardPrplOps *whiteboard_prpl_ops = NULL; */
34 static GList *wbList = NULL;
36 /*static gboolean auto_accept = TRUE; */
38 /******************************************************************************
39 * API
40 *****************************************************************************/
41 void purple_whiteboard_set_ui_ops(PurpleWhiteboardUiOps *ops)
43 whiteboard_ui_ops = ops;
46 void purple_whiteboard_set_prpl_ops(PurpleWhiteboard *wb, PurpleWhiteboardPrplOps *ops)
48 wb->prpl_ops = ops;
51 PurpleWhiteboard *purple_whiteboard_create(PurpleAccount *account, const char *who, int state)
53 PurplePluginProtocolInfo *prpl_info;
54 PurpleWhiteboard *wb = g_new0(PurpleWhiteboard, 1);
56 wb->account = account;
57 wb->state = state;
58 wb->who = g_strdup(who);
60 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(
61 purple_account_get_connection(account)));
62 purple_whiteboard_set_prpl_ops(wb, prpl_info->whiteboard_prpl_ops);
64 /* Start up protocol specifics */
65 if(wb->prpl_ops && wb->prpl_ops->start)
66 wb->prpl_ops->start(wb);
68 wbList = g_list_append(wbList, wb);
70 return wb;
73 void purple_whiteboard_destroy(PurpleWhiteboard *wb)
75 g_return_if_fail(wb != NULL);
77 if(wb->ui_data)
79 /* Destroy frontend */
80 if(whiteboard_ui_ops && whiteboard_ui_ops->destroy)
81 whiteboard_ui_ops->destroy(wb);
84 /* Do protocol specific session ending procedures */
85 if(wb->prpl_ops && wb->prpl_ops->end)
86 wb->prpl_ops->end(wb);
88 g_free(wb->who);
89 wbList = g_list_remove(wbList, wb);
90 g_free(wb);
93 void purple_whiteboard_start(PurpleWhiteboard *wb)
95 /* Create frontend for whiteboard */
96 if(whiteboard_ui_ops && whiteboard_ui_ops->create)
97 whiteboard_ui_ops->create(wb);
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.
104 PurpleWhiteboard *purple_whiteboard_get_session(const PurpleAccount *account, const char *who)
106 PurpleWhiteboard *wb;
108 GList *l = wbList;
110 /* Look for a whiteboard session between the local user and the remote user
112 while(l != NULL)
114 wb = l->data;
116 if(wb->account == account && purple_strequal(wb->who, who))
117 return wb;
119 l = l->next;
122 return NULL;
125 void purple_whiteboard_draw_list_destroy(GList *draw_list)
127 g_list_free(draw_list);
130 gboolean purple_whiteboard_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height)
132 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
134 if (prpl_ops && prpl_ops->get_dimensions)
136 prpl_ops->get_dimensions(wb, width, height);
137 return TRUE;
140 return FALSE;
143 void purple_whiteboard_set_dimensions(PurpleWhiteboard *wb, int width, int height)
145 if(whiteboard_ui_ops && whiteboard_ui_ops->set_dimensions)
146 whiteboard_ui_ops->set_dimensions(wb, width, height);
149 void purple_whiteboard_send_draw_list(PurpleWhiteboard *wb, GList *list)
151 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
153 if (prpl_ops && prpl_ops->send_draw_list)
154 prpl_ops->send_draw_list(wb, list);
157 void purple_whiteboard_draw_point(PurpleWhiteboard *wb, int x, int y, int color, int size)
159 if(whiteboard_ui_ops && whiteboard_ui_ops->draw_point)
160 whiteboard_ui_ops->draw_point(wb, x, y, color, size);
163 void purple_whiteboard_draw_line(PurpleWhiteboard *wb, int x1, int y1, int x2, int y2, int color, int size)
165 if(whiteboard_ui_ops && whiteboard_ui_ops->draw_line)
166 whiteboard_ui_ops->draw_line(wb, x1, y1, x2, y2, color, size);
169 void purple_whiteboard_clear(PurpleWhiteboard *wb)
171 if(whiteboard_ui_ops && whiteboard_ui_ops->clear)
172 whiteboard_ui_ops->clear(wb);
175 void purple_whiteboard_send_clear(PurpleWhiteboard *wb)
177 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
179 if (prpl_ops && prpl_ops->clear)
180 prpl_ops->clear(wb);
183 void purple_whiteboard_send_brush(PurpleWhiteboard *wb, int size, int color)
185 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
187 if (prpl_ops && prpl_ops->set_brush)
188 prpl_ops->set_brush(wb, size, color);
191 gboolean purple_whiteboard_get_brush(const PurpleWhiteboard *wb, int *size, int *color)
193 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
195 if (prpl_ops && prpl_ops->get_brush)
197 prpl_ops->get_brush(wb, size, color);
198 return TRUE;
200 return FALSE;
203 void purple_whiteboard_set_brush(PurpleWhiteboard *wb, int size, int color)
205 if (whiteboard_ui_ops && whiteboard_ui_ops->set_brush)
206 whiteboard_ui_ops->set_brush(wb, size, color);