Mercurial > pidgin
annotate plugins/ticker/ticker.c @ 5815:c900fc823a21
[gaim-migrate @ 6245]
Added the buttons to the dialog.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 08 Jun 2003 22:37:04 +0000 |
parents | eeba9205dd0f |
children | 059d95c67cda |
rev | line source |
---|---|
3391 | 1 /* GTK - The GIMP Toolkit |
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Library General Public | |
15 * License along with this library; if not, write to the | |
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 * Boston, MA 02111-1307, USA. | |
18 */ | |
19 | |
20 /* | |
21 * ticker.c -- Syd Logan, Summer 2000 | |
22 * pluginized- Sean Egan, Summer 2002 | |
23 */ | |
24 | |
25 | |
26 #include <gtk/gtk.h> | |
27 #include "gtkticker.h" | |
28 #include <string.h> | |
29 #include <stdlib.h> | |
30 #include "gaim.h" | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
31 #include "prpl.h" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
32 #include "gtkplugin.h" |
5234 | 33 #include "blist.h" |
34 #include "gtkblist.h" | |
3630 | 35 #ifdef _WIN32 |
36 #include "win32dep.h" | |
37 #endif | |
3391 | 38 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
39 #define TICKER_PLUGIN_ID "gtk-ticker" |
3867 | 40 |
3391 | 41 static GtkWidget *tickerwindow = NULL; |
42 static GtkWidget *ticker; | |
43 | |
44 typedef struct { | |
5170 | 45 struct buddy *buddy; |
3391 | 46 GtkWidget *ebox; |
47 GtkWidget *label; | |
5170 | 48 GtkWidget *icon; |
3391 | 49 } TickerData; |
50 | |
5170 | 51 GList *tickerbuds = NULL; |
3391 | 52 |
5172 | 53 static gboolean buddy_ticker_destroy_window(GtkWidget *window, |
54 GdkEventAny *event, gpointer data) { | |
55 if(window) | |
56 gtk_widget_hide(window); | |
57 | |
58 return TRUE; /* don't actually destroy the window */ | |
3391 | 59 } |
60 | |
5170 | 61 static void buddy_ticker_create_window() { |
62 if(tickerwindow) { | |
63 gtk_widget_show(tickerwindow); | |
64 return; | |
65 } | |
3391 | 66 |
5170 | 67 tickerwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
5286 | 68 gtk_window_set_default_size(GTK_WINDOW(tickerwindow), 500, -1); |
5172 | 69 g_signal_connect(G_OBJECT(tickerwindow), "delete_event", |
5170 | 70 G_CALLBACK (buddy_ticker_destroy_window), NULL); |
71 gtk_window_set_title (GTK_WINDOW(tickerwindow), _("Buddy Ticker")); | |
4850 | 72 gtk_window_set_role (GTK_WINDOW(tickerwindow), "ticker"); |
3391 | 73 |
4850 | 74 ticker = gtk_ticker_new(); |
5170 | 75 gtk_ticker_set_spacing(GTK_TICKER(ticker), 20); |
76 gtk_container_add(GTK_CONTAINER(tickerwindow), ticker); | |
77 gtk_ticker_set_interval(GTK_TICKER(ticker), 500); | |
78 gtk_ticker_set_scootch(GTK_TICKER(ticker), 10); | |
79 gtk_ticker_start_scroll(GTK_TICKER(ticker)); | |
5286 | 80 gtk_widget_set_size_request(ticker, 1, -1); |
3391 | 81 |
5170 | 82 gtk_widget_show_all(tickerwindow); |
3391 | 83 } |
84 | |
5170 | 85 static gboolean buddy_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { |
86 struct buddy *b = user_data; | |
4850 | 87 |
5170 | 88 gaim_conversation_new(GAIM_CONV_IM, b->account, b->name); |
3391 | 89 return TRUE; |
90 } | |
91 | |
5170 | 92 static TickerData *buddy_ticker_find_buddy(struct buddy *b) { |
93 GList *tb; | |
94 for(tb = tickerbuds; tb; tb = tb->next) { | |
95 TickerData *td = tb->data; | |
96 if(td->buddy == b) | |
97 return td; | |
98 } | |
99 return NULL; | |
100 } | |
101 | |
102 static void buddy_ticker_set_pixmap(struct buddy *b) { | |
103 TickerData *td = buddy_ticker_find_buddy(b); | |
104 GdkPixbuf *pixbuf; | |
3391 | 105 |
5170 | 106 if(!td) |
3391 | 107 return; |
5170 | 108 |
109 if(!td->icon) | |
110 td->icon = gtk_image_new(); | |
3391 | 111 |
5234 | 112 pixbuf = gaim_gtk_blist_get_status_icon((GaimBlistNode*)b, |
113 GAIM_STATUS_ICON_SMALL); | |
5170 | 114 gtk_image_set_from_pixbuf(GTK_IMAGE(td->icon), pixbuf); |
115 g_object_unref(G_OBJECT(pixbuf)); | |
116 } | |
117 | |
118 static void buddy_ticker_add_buddy(struct buddy *b) { | |
119 GtkWidget *hbox; | |
120 TickerData *td; | |
121 | |
122 buddy_ticker_create_window(); | |
5172 | 123 |
3391 | 124 if (!ticker) |
125 return; | |
126 | |
5170 | 127 if(buddy_ticker_find_buddy(b)) |
3391 | 128 return; |
129 | |
5170 | 130 td = g_new0(TickerData, 1); |
131 td->buddy = b; | |
132 tickerbuds = g_list_append(tickerbuds, td); | |
3391 | 133 |
5170 | 134 td->ebox = gtk_event_box_new(); |
135 gtk_ticker_add(GTK_TICKER(ticker), td->ebox); | |
136 hbox = gtk_hbox_new(FALSE, 0); | |
137 gtk_container_add(GTK_CONTAINER(td->ebox), hbox); | |
138 buddy_ticker_set_pixmap(b); | |
139 gtk_box_pack_start(GTK_BOX(hbox), td->icon, FALSE, FALSE, 5); | |
3391 | 140 |
5170 | 141 g_signal_connect(G_OBJECT(td->ebox), "button-press-event", |
142 G_CALLBACK(buddy_click_cb), b); | |
3391 | 143 |
5170 | 144 td->label = gtk_label_new(gaim_get_buddy_alias(b)); |
145 gtk_box_pack_start(GTK_BOX(hbox), td->label, FALSE, FALSE, 5); | |
146 | |
147 gtk_widget_show_all(td->ebox); | |
148 gtk_widget_show(tickerwindow); | |
3391 | 149 } |
150 | |
5170 | 151 static void buddy_ticker_remove_buddy(struct buddy *b) { |
152 TickerData *td = buddy_ticker_find_buddy(b); | |
3391 | 153 |
5170 | 154 if (!td) |
155 return; | |
3391 | 156 |
5172 | 157 /* pop up the ticker window again */ |
158 buddy_ticker_create_window(); | |
159 | |
5170 | 160 gtk_ticker_remove(GTK_TICKER(ticker), td->ebox); |
161 tickerbuds = g_list_remove(tickerbuds, td); | |
162 g_free(td); | |
3391 | 163 } |
164 | |
5170 | 165 static void buddy_ticker_show() |
3391 | 166 { |
5170 | 167 struct gaim_buddy_list *list = gaim_get_blist(); |
168 GaimBlistNode *gnode, *bnode; | |
169 struct buddy *b; | |
3391 | 170 |
5170 | 171 if(!list) |
172 return; | |
3391 | 173 |
5170 | 174 for(gnode = list->root; gnode; gnode = gnode->next) { |
175 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
176 continue; | |
177 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
178 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
179 continue; | |
180 b = (struct buddy *)bnode; | |
181 if(GAIM_BUDDY_IS_ONLINE(b)) | |
182 buddy_ticker_add_buddy(b); | |
3391 | 183 } |
184 } | |
185 } | |
186 | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5286
diff
changeset
|
187 void signon_cb(GaimConnection *gc, char *who) { |
4850 | 188 struct buddy *b = gaim_find_buddy(gc->account, who); |
5170 | 189 if(buddy_ticker_find_buddy(b)) |
190 buddy_ticker_set_pixmap(b); | |
191 else | |
192 buddy_ticker_add_buddy(b); | |
3391 | 193 } |
194 | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5286
diff
changeset
|
195 void signoff_cb(GaimConnection *gc) { |
5607 | 196 if (!gaim_connections_get_all()) { |
5185 | 197 while(tickerbuds) { |
198 g_free(tickerbuds->data); | |
199 tickerbuds = g_list_delete_link(tickerbuds, tickerbuds); | |
200 } | |
3391 | 201 gtk_widget_destroy(tickerwindow); |
202 tickerwindow = NULL; | |
203 ticker = NULL; | |
5185 | 204 } else { |
205 GList *t = tickerbuds; | |
206 while(t) { | |
207 TickerData *td = t->data; | |
208 t = t->next; | |
209 if(td->buddy->account == gc->account) { | |
210 g_free(td); | |
211 tickerbuds = g_list_remove(tickerbuds, td); | |
212 } | |
213 } | |
3391 | 214 } |
215 } | |
216 | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5286
diff
changeset
|
217 void buddy_signoff_cb(GaimConnection *gc, char *who) { |
5170 | 218 struct buddy *b = gaim_find_buddy(gc->account, who); |
219 | |
220 buddy_ticker_remove_buddy(b); | |
5185 | 221 if(!tickerbuds) |
222 gtk_widget_hide(tickerwindow); | |
3391 | 223 } |
224 | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5286
diff
changeset
|
225 void away_cb(GaimConnection *gc, char *who) { |
4850 | 226 struct buddy *b = gaim_find_buddy(gc->account, who); |
5170 | 227 if(buddy_ticker_find_buddy(b)) |
228 buddy_ticker_set_pixmap(b); | |
229 else | |
230 buddy_ticker_add_buddy(b); | |
3391 | 231 } |
232 | |
3630 | 233 /* |
234 * EXPORTED FUNCTIONS | |
235 */ | |
236 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
237 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
238 plugin_load(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
239 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
240 gaim_signal_connect(plugin, event_buddy_signon, signon_cb, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
241 gaim_signal_connect(plugin, event_signoff, signoff_cb, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
242 gaim_signal_connect(plugin, event_buddy_signoff, buddy_signoff_cb, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
243 gaim_signal_connect(plugin, event_buddy_away, away_cb, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
244 gaim_signal_connect(plugin, event_buddy_back, away_cb, NULL); |
3391 | 245 |
5607 | 246 if (gaim_connections_get_all()) |
5170 | 247 buddy_ticker_show(); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
248 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
249 return TRUE; |
3391 | 250 } |
251 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
252 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
253 plugin_unload(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
254 { |
5185 | 255 while(tickerbuds) { |
256 g_free(tickerbuds->data); | |
5186 | 257 tickerbuds = g_list_delete_link(tickerbuds, tickerbuds); |
5185 | 258 } |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
259 |
5181 | 260 gtk_widget_destroy(tickerwindow); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
261 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
262 return TRUE; |
3391 | 263 } |
5170 | 264 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
265 static GaimGtkPluginUiInfo ui_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
266 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
267 NULL /**< get_config_frame */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
268 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
269 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
270 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
271 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
272 2, /**< api_version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
273 GAIM_PLUGIN_STANDARD, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
274 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
275 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
276 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
277 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
278 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
279 TICKER_PLUGIN_ID, /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
280 N_("Buddy Ticker"), /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
281 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
282 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
283 N_("A horizontal scrolling version of the buddy list."), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
284 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
285 N_("A horizontal scrolling version of the buddy list."), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
286 "Syd Logan", /**< author */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
287 WEBSITE, /**< homepage */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
288 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
289 plugin_load, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
290 plugin_unload, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
291 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
292 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
293 &ui_info, /**< ui_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
294 NULL /**< extra_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
295 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
296 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
297 static void |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
298 __init_plugin(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
299 { |
3551 | 300 } |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
301 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5186
diff
changeset
|
302 GAIM_INIT_PLUGIN(ticker, __init_plugin, info); |