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"
|
5170
|
31 #include "list.h"
|
|
32 #include "gtklist.h"
|
3630
|
33 #ifdef _WIN32
|
|
34 #include "win32dep.h"
|
|
35 #endif
|
3391
|
36
|
3867
|
37 #ifndef GAIM_PLUGINS
|
|
38 #define GAIM_PLUGINS
|
|
39 #endif
|
|
40
|
3391
|
41 static GtkWidget *tickerwindow = NULL;
|
|
42 static GtkWidget *ticker;
|
|
43 static GModule *handle;
|
|
44
|
|
45 typedef struct {
|
5170
|
46 struct buddy *buddy;
|
3391
|
47 GtkWidget *ebox;
|
|
48 GtkWidget *label;
|
5170
|
49 GtkWidget *icon;
|
3391
|
50 } TickerData;
|
|
51
|
5170
|
52 GList *tickerbuds = NULL;
|
3391
|
53
|
3630
|
54 /* for win32 compatability */
|
|
55 G_MODULE_IMPORT GSList *connections;
|
|
56
|
5170
|
57 static void buddy_ticker_destroy_window(GtkWidget *window, gpointer data) {
|
|
58 gtk_widget_hide(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);
|
|
68 g_signal_connect(G_OBJECT(tickerwindow), "destroy",
|
|
69 G_CALLBACK (buddy_ticker_destroy_window), NULL);
|
|
70 gtk_window_set_title (GTK_WINDOW(tickerwindow), _("Buddy Ticker"));
|
4850
|
71 gtk_window_set_role (GTK_WINDOW(tickerwindow), "ticker");
|
3391
|
72
|
4850
|
73 ticker = gtk_ticker_new();
|
5170
|
74 gtk_ticker_set_spacing(GTK_TICKER(ticker), 20);
|
|
75 gtk_container_add(GTK_CONTAINER(tickerwindow), ticker);
|
|
76 gtk_ticker_set_interval(GTK_TICKER(ticker), 500);
|
|
77 gtk_ticker_set_scootch(GTK_TICKER(ticker), 10);
|
|
78 gtk_ticker_start_scroll(GTK_TICKER(ticker));
|
|
79 gtk_widget_set_size_request(ticker, 500, -1);
|
3391
|
80
|
5170
|
81 gtk_widget_show_all(tickerwindow);
|
3391
|
82 }
|
|
83
|
5170
|
84 static gboolean buddy_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data) {
|
|
85 struct buddy *b = user_data;
|
4850
|
86
|
5170
|
87 gaim_conversation_new(GAIM_CONV_IM, b->account, b->name);
|
3391
|
88 return TRUE;
|
|
89 }
|
|
90
|
5170
|
91 static TickerData *buddy_ticker_find_buddy(struct buddy *b) {
|
|
92 GList *tb;
|
|
93 for(tb = tickerbuds; tb; tb = tb->next) {
|
|
94 TickerData *td = tb->data;
|
|
95 if(td->buddy == b)
|
|
96 return td;
|
|
97 }
|
|
98 return NULL;
|
|
99 }
|
|
100
|
|
101 static void buddy_ticker_set_pixmap(struct buddy *b) {
|
|
102 TickerData *td = buddy_ticker_find_buddy(b);
|
|
103 GdkPixbuf *pixbuf;
|
3391
|
104
|
5170
|
105 if(!td)
|
3391
|
106 return;
|
5170
|
107
|
|
108 if(!td->icon)
|
|
109 td->icon = gtk_image_new();
|
3391
|
110
|
5170
|
111 pixbuf = gaim_gtk_blist_get_status_icon(b, GAIM_STATUS_ICON_SMALL);
|
|
112 gtk_image_set_from_pixbuf(GTK_IMAGE(td->icon), pixbuf);
|
|
113 g_object_unref(G_OBJECT(pixbuf));
|
|
114 }
|
|
115
|
|
116 static void buddy_ticker_add_buddy(struct buddy *b) {
|
|
117 GtkWidget *hbox;
|
|
118 TickerData *td;
|
|
119
|
|
120 buddy_ticker_create_window();
|
3391
|
121 if (!ticker)
|
|
122 return;
|
|
123
|
5170
|
124 if(buddy_ticker_find_buddy(b))
|
3391
|
125 return;
|
|
126
|
5170
|
127 td = g_new0(TickerData, 1);
|
|
128 td->buddy = b;
|
|
129 tickerbuds = g_list_append(tickerbuds, td);
|
3391
|
130
|
5170
|
131 td->ebox = gtk_event_box_new();
|
|
132 gtk_ticker_add(GTK_TICKER(ticker), td->ebox);
|
|
133 hbox = gtk_hbox_new(FALSE, 0);
|
|
134 gtk_container_add(GTK_CONTAINER(td->ebox), hbox);
|
|
135 buddy_ticker_set_pixmap(b);
|
|
136 gtk_box_pack_start(GTK_BOX(hbox), td->icon, FALSE, FALSE, 5);
|
3391
|
137
|
5170
|
138 g_signal_connect(G_OBJECT(td->ebox), "button-press-event",
|
|
139 G_CALLBACK(buddy_click_cb), b);
|
3391
|
140
|
5170
|
141 td->label = gtk_label_new(gaim_get_buddy_alias(b));
|
|
142 gtk_box_pack_start(GTK_BOX(hbox), td->label, FALSE, FALSE, 5);
|
|
143
|
|
144 gtk_widget_show_all(td->ebox);
|
|
145 gtk_widget_show(tickerwindow);
|
3391
|
146 }
|
|
147
|
5170
|
148 static void buddy_ticker_remove_buddy(struct buddy *b) {
|
|
149 TickerData *td = buddy_ticker_find_buddy(b);
|
3391
|
150
|
5170
|
151 if (!td)
|
|
152 return;
|
3391
|
153
|
5170
|
154 gtk_ticker_remove(GTK_TICKER(ticker), td->ebox);
|
|
155 tickerbuds = g_list_remove(tickerbuds, td);
|
|
156 g_free(td);
|
3391
|
157 }
|
|
158
|
5170
|
159 static void buddy_ticker_show()
|
3391
|
160 {
|
5170
|
161 struct gaim_buddy_list *list = gaim_get_blist();
|
|
162 GaimBlistNode *gnode, *bnode;
|
|
163 struct buddy *b;
|
3391
|
164
|
5170
|
165 if(!list)
|
|
166 return;
|
3391
|
167
|
5170
|
168 for(gnode = list->root; gnode; gnode = gnode->next) {
|
|
169 if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
|
|
170 continue;
|
|
171 for(bnode = gnode->child; bnode; bnode = bnode->next) {
|
|
172 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
|
|
173 continue;
|
|
174 b = (struct buddy *)bnode;
|
|
175 if(GAIM_BUDDY_IS_ONLINE(b))
|
|
176 buddy_ticker_add_buddy(b);
|
3391
|
177 }
|
|
178 }
|
|
179 }
|
|
180
|
|
181 void signon_cb(struct gaim_connection *gc, char *who) {
|
4850
|
182 struct buddy *b = gaim_find_buddy(gc->account, who);
|
5170
|
183 if(buddy_ticker_find_buddy(b))
|
|
184 buddy_ticker_set_pixmap(b);
|
|
185 else
|
|
186 buddy_ticker_add_buddy(b);
|
3391
|
187 }
|
|
188
|
|
189 void signoff_cb(struct gaim_connection *gc) {
|
5170
|
190 if (!connections) {
|
3391
|
191 gtk_widget_destroy(tickerwindow);
|
|
192 tickerwindow = NULL;
|
|
193 ticker = NULL;
|
|
194 }
|
|
195 }
|
|
196
|
|
197 void buddy_signoff_cb(struct gaim_connection *gc, char *who) {
|
5170
|
198 struct buddy *b = gaim_find_buddy(gc->account, who);
|
|
199
|
|
200 buddy_ticker_remove_buddy(b);
|
3391
|
201 }
|
|
202
|
|
203 void away_cb(struct gaim_connection *gc, char *who) {
|
4850
|
204 struct buddy *b = gaim_find_buddy(gc->account, who);
|
5170
|
205 if(buddy_ticker_find_buddy(b))
|
|
206 buddy_ticker_set_pixmap(b);
|
|
207 else
|
|
208 buddy_ticker_add_buddy(b);
|
3391
|
209 }
|
|
210
|
3630
|
211 /*
|
|
212 * EXPORTED FUNCTIONS
|
|
213 */
|
|
214
|
|
215 G_MODULE_EXPORT char *name() {
|
4585
|
216 return _("Buddy Ticker");
|
3630
|
217 }
|
|
218
|
|
219 G_MODULE_EXPORT char *description() {
|
4606
|
220 return _("A horizontal scrolling version of the buddy list.");
|
3630
|
221 }
|
|
222
|
|
223 G_MODULE_EXPORT char *gaim_plugin_init(GModule *h) {
|
3391
|
224 handle = h;
|
5170
|
225
|
3391
|
226 gaim_signal_connect(h, event_buddy_signon, signon_cb, NULL);
|
|
227 gaim_signal_connect(h, event_signoff, signoff_cb, NULL);
|
|
228 gaim_signal_connect(h, event_buddy_signoff, buddy_signoff_cb, NULL);
|
|
229 gaim_signal_connect(h, event_buddy_away, away_cb, NULL);
|
5170
|
230 gaim_signal_connect(h, event_buddy_back, away_cb, NULL);
|
3391
|
231
|
|
232 if (connections)
|
5170
|
233 buddy_ticker_show();
|
3391
|
234 return NULL;
|
|
235 }
|
|
236
|
3630
|
237 G_MODULE_EXPORT void gaim_plugin_remove() {
|
5170
|
238 buddy_ticker_destroy_window(tickerwindow, NULL);
|
3391
|
239 }
|
5170
|
240
|
|
241 struct gaim_plugin_description desc;
|
3630
|
242 G_MODULE_EXPORT struct gaim_plugin_description *gaim_plugin_desc() {
|
3551
|
243 desc.api_version = PLUGIN_API_VERSION;
|
4585
|
244 desc.name = g_strdup(_("Buddy Ticker"));
|
3551
|
245 desc.version = g_strdup(VERSION);
|
4585
|
246 desc.description = g_strdup(_("A horizontal scrolling version of the buddy list."));
|
3551
|
247 desc.authors = g_strdup("Syd Logan");
|
|
248 desc.url = g_strdup(WEBSITE);
|
|
249 return &desc;
|
|
250 }
|