comparison src/whiteboard.c @ 11475:7fab28c991f3

[gaim-migrate @ 13717] merging gaim-doodle/whiteboard/whatever you like to call it. Needs some cleanups and doxygen comments, but has basic functionality committer: Tailor Script <tailor@pidgin.im>
author Gary Kramlich <grim@reaperworld.com>
date Fri, 09 Sep 2005 04:40:21 +0000
parents
children 88d504770c60
comparison
equal deleted inserted replaced
11474:7e9635b73ed6 11475:7fab28c991f3
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 // INCLUDES =============================================================================================
25
26 #include <string.h>
27
28 #include "whiteboard.h"
29 #include "prpl.h"
30
31 // DATATYPES ============================================================================================
32
33 // GLOBALS ==============================================================================================
34
35 static GaimWhiteboardUiOps *whiteboard_ui_ops = NULL;
36 //static GaimWhiteboardPrplOps *whiteboard_prpl_ops = NULL;
37
38 static GList *wbList = NULL;
39
40 //static gboolean auto_accept = TRUE;
41
42 // FUNCTIONS ============================================================================================
43
44 void gaim_whiteboard_set_ui_ops( GaimWhiteboardUiOps *ops )
45 {
46 whiteboard_ui_ops = ops;
47 }
48
49 // ------------------------------------------------------------------------------------------------------
50
51 void gaim_whiteboard_set_prpl_ops( GaimWhiteboard *wb, GaimWhiteboardPrplOps *ops )
52 {
53 wb->prpl_ops = ops;
54 }
55
56 // ------------------------------------------------------------------------------------------------------
57
58 GaimWhiteboard *gaim_whiteboard_create( GaimAccount *account, char *who, int state )
59 {
60 //g_print( "gaim_whiteboard_create()\n" );
61
62 GaimWhiteboard *wb = g_new0( GaimWhiteboard, 1 );
63
64 wb->account = account;
65 wb->state = state;
66 wb->who = g_strdup( who );
67
68 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO( account->gc->prpl );
69 gaim_whiteboard_set_prpl_ops( wb, prpl_info->whiteboard_prpl_ops );
70
71 // Start up protocol specifics
72 if( wb->prpl_ops && wb->prpl_ops->start )
73 wb->prpl_ops->start( wb );
74
75 wbList = g_list_append( wbList, ( gpointer )( wb ) );
76
77 return( wb );
78 }
79
80 // ------------------------------------------------------------------------------------------------------
81
82 void gaim_whiteboard_destroy( GaimWhiteboard *wb )
83 {
84 //g_print( "gaim_whiteboard_destroy()\n" );
85
86 if( wb->ui_data )
87 {
88 //g_print( "---wb->ui_data = %p\n", wb->ui_data );
89
90 // Destroy frontend
91 if( whiteboard_ui_ops && whiteboard_ui_ops->destroy )
92 whiteboard_ui_ops->destroy( wb );
93 }
94
95 // Do protocol specific session ending procedures
96 if( wb->prpl_ops && wb->prpl_ops->end )
97 wb->prpl_ops->end( wb );
98
99 if( wb )
100 {
101 //g_print( "---wb = %p\n", wb );
102
103 wb->account = NULL;
104 wb->state = 0;
105
106 if( wb->who )
107 g_free( wb->who );
108
109 wbList = g_list_remove( wbList, wb );
110
111 g_free( wb );
112 wb = NULL;
113 }
114 }
115
116 // ------------------------------------------------------------------------------------------------------
117
118 void gaim_whiteboard_start( GaimWhiteboard *wb )
119 {
120 //g_print( "gaim_whiteboard_start()\n" );
121
122 // Create frontend for whiteboard
123 if( whiteboard_ui_ops && whiteboard_ui_ops->create )
124 whiteboard_ui_ops->create( wb );
125 }
126
127 // ------------------------------------------------------------------------------------------------------
128
129 // Looks through the list of whiteboard sessions for one that is between usernames 'me' and 'who'
130 // Returns a pointer to a matching whiteboard session; if none match, it returns NULL
131 GaimWhiteboard *gaim_whiteboard_get_session( GaimAccount *account, char *who )
132 {
133 //g_print( "gaim_whiteboard_get_session()\n" );
134
135 GaimWhiteboard *wb = NULL;
136
137 GList *l = wbList;
138
139 // Look for a whiteboard session between the local user and the remote user
140 while( l )
141 {
142 wb = l->data;
143
144 if( !strcmp( gaim_account_get_username( wb->account ), gaim_account_get_username( account ) ) &&
145 !strcmp( wb->who, who ) )
146 return( wb );
147
148 l = l->next;
149 }
150
151 return( NULL );
152 }
153
154 // ------------------------------------------------------------------------------------------------------
155
156 GList *gaim_whiteboard_draw_list_destroy( GList *draw_list )
157 {
158 //g_print( "gaim_whiteboard_draw_list_destroy()\n" );
159
160 if( draw_list == NULL )
161 return( NULL );
162 else
163 {
164 // Destroy the contents of this list
165 int *n = NULL;
166 GList *l = draw_list;
167 while( l )
168 {
169 n = l->data;
170
171 if( n )
172 g_free( n );
173
174 l = l->next;
175 }
176
177 g_list_free( draw_list );
178 draw_list = NULL;
179 }
180
181 return( draw_list );
182 }
183
184 // ------------------------------------------------------------------------------------------------------
185
186 void gaim_whiteboard_set_dimensions( GaimWhiteboard *wb, int width, int height )
187 {
188 if( whiteboard_ui_ops && whiteboard_ui_ops->set_dimensions )
189 whiteboard_ui_ops->set_dimensions( wb, width, height );
190 }
191
192 // ------------------------------------------------------------------------------------------------------
193
194 void gaim_whiteboard_draw_point( GaimWhiteboard *wb, int x, int y, int color, int size )
195 {
196 if( whiteboard_ui_ops && whiteboard_ui_ops->draw_point )
197 whiteboard_ui_ops->draw_point( wb, x, y, color, size );
198 }
199
200 // ------------------------------------------------------------------------------------------------------
201
202 void gaim_whiteboard_draw_line( GaimWhiteboard *wb, int x1, int y1, int x2, int y2, int color, int size )
203 {
204 if( whiteboard_ui_ops && whiteboard_ui_ops->draw_line )
205 whiteboard_ui_ops->draw_line( wb, x1, y1, x2, y2, color, size );
206 }
207
208 // ------------------------------------------------------------------------------------------------------
209
210 void gaim_whiteboard_clear( GaimWhiteboard *wb )
211 {
212 if( whiteboard_ui_ops && whiteboard_ui_ops->clear )
213 whiteboard_ui_ops->clear( wb );
214 }
215
216 // ------------------------------------------------------------------------------------------------------