1 /*
2  * purple
3  *
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
21  *
22  */
23 
24 #include "internal.h"
25 #include "whiteboard.h"
26 #include "prpl.h"
27 
28 /******************************************************************************
29  * Globals
30  *****************************************************************************/
31 static PurpleWhiteboardUiOps *whiteboard_ui_ops = NULL;
32 /* static PurpleWhiteboardPrplOps *whiteboard_prpl_ops = NULL; */
33 
34 static GList *wbList = NULL;
35 
36 /*static gboolean auto_accept = TRUE; */
37 
38 /******************************************************************************
39  * API
40  *****************************************************************************/
purple_whiteboard_set_ui_ops(PurpleWhiteboardUiOps * ops)41 void purple_whiteboard_set_ui_ops(PurpleWhiteboardUiOps *ops)
42 {
43 	whiteboard_ui_ops = ops;
44 }
45 
purple_whiteboard_set_prpl_ops(PurpleWhiteboard * wb,PurpleWhiteboardPrplOps * ops)46 void purple_whiteboard_set_prpl_ops(PurpleWhiteboard *wb, PurpleWhiteboardPrplOps *ops)
47 {
48 	wb->prpl_ops = ops;
49 }
50 
purple_whiteboard_create(PurpleAccount * account,const char * who,int state)51 PurpleWhiteboard *purple_whiteboard_create(PurpleAccount *account, const char *who, int state)
52 {
53 	PurplePluginProtocolInfo *prpl_info;
54 	PurpleWhiteboard *wb = g_new0(PurpleWhiteboard, 1);
55 
56 	wb->account = account;
57 	wb->state   = state;
58 	wb->who     = g_strdup(who);
59 
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);
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 
purple_whiteboard_destroy(PurpleWhiteboard * wb)73 void purple_whiteboard_destroy(PurpleWhiteboard *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 
purple_whiteboard_start(PurpleWhiteboard * wb)93 void purple_whiteboard_start(PurpleWhiteboard *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  */
purple_whiteboard_get_session(const PurpleAccount * account,const char * who)104 PurpleWhiteboard *purple_whiteboard_get_session(const PurpleAccount *account, const char *who)
105 {
106 	PurpleWhiteboard *wb;
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 && purple_strequal(wb->who, who))
117 			return wb;
118 
119 		l = l->next;
120 	}
121 
122 	return NULL;
123 }
124 
purple_whiteboard_draw_list_destroy(GList * draw_list)125 void purple_whiteboard_draw_list_destroy(GList *draw_list)
126 {
127 	g_list_free(draw_list);
128 }
129 
purple_whiteboard_get_dimensions(const PurpleWhiteboard * wb,int * width,int * height)130 gboolean purple_whiteboard_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height)
131 {
132 	PurpleWhiteboardPrplOps *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 
purple_whiteboard_set_dimensions(PurpleWhiteboard * wb,int width,int height)143 void purple_whiteboard_set_dimensions(PurpleWhiteboard *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 
purple_whiteboard_send_draw_list(PurpleWhiteboard * wb,GList * list)149 void purple_whiteboard_send_draw_list(PurpleWhiteboard *wb, GList *list)
150 {
151 	PurpleWhiteboardPrplOps *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 
purple_whiteboard_draw_point(PurpleWhiteboard * wb,int x,int y,int color,int size)157 void purple_whiteboard_draw_point(PurpleWhiteboard *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 
purple_whiteboard_draw_line(PurpleWhiteboard * wb,int x1,int y1,int x2,int y2,int color,int size)163 void purple_whiteboard_draw_line(PurpleWhiteboard *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 
purple_whiteboard_clear(PurpleWhiteboard * wb)169 void purple_whiteboard_clear(PurpleWhiteboard *wb)
170 {
171 	if(whiteboard_ui_ops && whiteboard_ui_ops->clear)
172 		whiteboard_ui_ops->clear(wb);
173 }
174 
purple_whiteboard_send_clear(PurpleWhiteboard * wb)175 void purple_whiteboard_send_clear(PurpleWhiteboard *wb)
176 {
177 	PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
178 
179 	if (prpl_ops && prpl_ops->clear)
180 		prpl_ops->clear(wb);
181 }
182 
purple_whiteboard_send_brush(PurpleWhiteboard * wb,int size,int color)183 void purple_whiteboard_send_brush(PurpleWhiteboard *wb, int size, int color)
184 {
185 	PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
186 
187 	if (prpl_ops && prpl_ops->set_brush)
188 		prpl_ops->set_brush(wb, size, color);
189 }
190 
purple_whiteboard_get_brush(const PurpleWhiteboard * wb,int * size,int * color)191 gboolean purple_whiteboard_get_brush(const PurpleWhiteboard *wb, int *size, int *color)
192 {
193 	PurpleWhiteboardPrplOps *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 
purple_whiteboard_set_brush(PurpleWhiteboard * wb,int size,int color)203 void purple_whiteboard_set_brush(PurpleWhiteboard *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 
209