Mercurial > pidgin
comparison plugins/ticker/ticker.c @ 13150:d4698cf18986
[gaim-migrate @ 15513]
SF Patch #1417663 from Sadrul
It compiles and appears to work in a quick test. Nobody is maintaining the ticker plugin these days, so I'm going to trust Sadrul on this one.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 07 Feb 2006 03:21:48 +0000 |
parents | cb73483c9f63 |
children |
comparison
equal
deleted
inserted
replaced
13149:18e621aa8a43 | 13150:d4698cf18986 |
---|---|
43 | 43 |
44 static GtkWidget *tickerwindow = NULL; | 44 static GtkWidget *tickerwindow = NULL; |
45 static GtkWidget *ticker; | 45 static GtkWidget *ticker; |
46 | 46 |
47 typedef struct { | 47 typedef struct { |
48 GaimBuddy *buddy; | 48 GaimContact *contact; |
49 GtkWidget *ebox; | 49 GtkWidget *ebox; |
50 GtkWidget *label; | 50 GtkWidget *label; |
51 GtkWidget *icon; | 51 GtkWidget *icon; |
52 guint timeout; | 52 guint timeout; |
53 } TickerData; | 53 } TickerData; |
54 | 54 |
55 GList *tickerbuds = NULL; | 55 GList *tickerbuds = NULL; |
56 | |
57 static void buddy_ticker_update_contact(GaimContact *contact); | |
56 | 58 |
57 static gboolean buddy_ticker_destroy_window(GtkWidget *window, | 59 static gboolean buddy_ticker_destroy_window(GtkWidget *window, |
58 GdkEventAny *event, gpointer data) { | 60 GdkEventAny *event, gpointer data) { |
59 if(window) | 61 if(window) |
60 gtk_widget_hide(window); | 62 gtk_widget_hide(window); |
85 | 87 |
86 gtk_widget_show_all(tickerwindow); | 88 gtk_widget_show_all(tickerwindow); |
87 } | 89 } |
88 | 90 |
89 static gboolean buddy_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { | 91 static gboolean buddy_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { |
90 GaimBuddy *b = user_data; | 92 GaimContact *contact = user_data; |
93 GaimBuddy *b = gaim_contact_get_priority_buddy(contact); | |
91 | 94 |
92 gaim_conversation_new(GAIM_CONV_TYPE_IM, b->account, b->name); | 95 gaim_conversation_new(GAIM_CONV_TYPE_IM, b->account, b->name); |
93 return TRUE; | 96 return TRUE; |
94 } | 97 } |
95 | 98 |
96 static TickerData *buddy_ticker_find_buddy(GaimBuddy *b) { | 99 static TickerData *buddy_ticker_find_contact(GaimContact *c) { |
97 GList *tb; | 100 GList *tb; |
98 for(tb = tickerbuds; tb; tb = tb->next) { | 101 for(tb = tickerbuds; tb; tb = tb->next) { |
99 TickerData *td = tb->data; | 102 TickerData *td = tb->data; |
100 if(td->buddy == b) | 103 if(td->contact == c) |
101 return td; | 104 return td; |
102 } | 105 } |
103 return NULL; | 106 return NULL; |
104 } | 107 } |
105 | 108 |
106 static void buddy_ticker_set_pixmap(GaimBuddy *b) { | 109 static void buddy_ticker_set_pixmap(GaimContact *c) { |
107 TickerData *td = buddy_ticker_find_buddy(b); | 110 TickerData *td = buddy_ticker_find_contact(c); |
108 GdkPixbuf *pixbuf; | 111 GdkPixbuf *pixbuf; |
109 | 112 |
110 if(!td) | 113 if(!td) |
111 return; | 114 return; |
112 | 115 |
113 if(!td->icon) | 116 if(!td->icon) |
114 td->icon = gtk_image_new(); | 117 td->icon = gtk_image_new(); |
115 | 118 |
116 pixbuf = gaim_gtk_blist_get_status_icon((GaimBlistNode*)b, | 119 pixbuf = gaim_gtk_blist_get_status_icon((GaimBlistNode*)c, |
117 GAIM_STATUS_ICON_SMALL); | 120 GAIM_STATUS_ICON_SMALL); |
118 gtk_image_set_from_pixbuf(GTK_IMAGE(td->icon), pixbuf); | 121 gtk_image_set_from_pixbuf(GTK_IMAGE(td->icon), pixbuf); |
119 g_object_unref(G_OBJECT(pixbuf)); | 122 g_object_unref(G_OBJECT(pixbuf)); |
120 } | 123 } |
121 | 124 |
122 static gboolean buddy_ticker_set_pixmap_cb(gpointer data) { | 125 static gboolean buddy_ticker_set_pixmap_cb(gpointer data) { |
123 TickerData *td = data; | 126 TickerData *td = data; |
124 | 127 |
125 gaim_debug(GAIM_DEBUG_ERROR, "XXX", "we're updating the pixmap, you bitch\n"); | 128 buddy_ticker_update_contact(td->contact); |
126 buddy_ticker_set_pixmap(td->buddy); | |
127 td->timeout = 0; | 129 td->timeout = 0; |
128 | 130 |
129 return FALSE; | 131 return FALSE; |
130 } | 132 } |
131 | 133 |
132 static void buddy_ticker_add_buddy(GaimBuddy *b) { | 134 static void buddy_ticker_add_buddy(GaimBuddy *b) { |
133 GtkWidget *hbox; | 135 GtkWidget *hbox; |
134 TickerData *td; | 136 TickerData *td; |
137 GaimContact *contact; | |
138 | |
139 contact = gaim_buddy_get_contact(b); | |
135 | 140 |
136 buddy_ticker_create_window(); | 141 buddy_ticker_create_window(); |
137 | 142 |
138 if (!ticker) | 143 if (!ticker) |
139 return; | 144 return; |
140 | 145 |
141 if (buddy_ticker_find_buddy(b)) | 146 if (buddy_ticker_find_contact(contact)) |
142 return; | 147 { |
148 buddy_ticker_update_contact(contact); | |
149 return; | |
150 } | |
143 | 151 |
144 td = g_new0(TickerData, 1); | 152 td = g_new0(TickerData, 1); |
145 td->buddy = b; | 153 td->contact = contact; |
146 tickerbuds = g_list_append(tickerbuds, td); | 154 tickerbuds = g_list_append(tickerbuds, td); |
147 | 155 |
148 td->ebox = gtk_event_box_new(); | 156 td->ebox = gtk_event_box_new(); |
149 gtk_ticker_add(GTK_TICKER(ticker), td->ebox); | 157 gtk_ticker_add(GTK_TICKER(ticker), td->ebox); |
150 hbox = gtk_hbox_new(FALSE, 0); | 158 hbox = gtk_hbox_new(FALSE, 0); |
151 gtk_container_add(GTK_CONTAINER(td->ebox), hbox); | 159 gtk_container_add(GTK_CONTAINER(td->ebox), hbox); |
152 buddy_ticker_set_pixmap(b); | 160 buddy_ticker_set_pixmap(contact); |
153 gtk_box_pack_start(GTK_BOX(hbox), td->icon, FALSE, FALSE, 5); | 161 gtk_box_pack_start(GTK_BOX(hbox), td->icon, FALSE, FALSE, 0); |
154 | 162 |
155 g_signal_connect(G_OBJECT(td->ebox), "button-press-event", | 163 g_signal_connect(G_OBJECT(td->ebox), "button-press-event", |
156 G_CALLBACK(buddy_click_cb), b); | 164 G_CALLBACK(buddy_click_cb), contact); |
157 | 165 |
158 td->label = gtk_label_new(gaim_buddy_get_alias(b)); | 166 td->label = gtk_label_new(gaim_contact_get_alias(contact)); |
159 gtk_box_pack_start(GTK_BOX(hbox), td->label, FALSE, FALSE, 5); | 167 gtk_box_pack_start(GTK_BOX(hbox), td->label, FALSE, FALSE, 2); |
160 | 168 |
161 gtk_widget_show_all(td->ebox); | 169 gtk_widget_show_all(td->ebox); |
162 gtk_widget_show(tickerwindow); | 170 gtk_widget_show(tickerwindow); |
163 | 171 |
164 /* | 172 /* |
166 * changed). This is somewhat ugly. | 174 * changed). This is somewhat ugly. |
167 */ | 175 */ |
168 td->timeout = g_timeout_add(11000, buddy_ticker_set_pixmap_cb, td); | 176 td->timeout = g_timeout_add(11000, buddy_ticker_set_pixmap_cb, td); |
169 } | 177 } |
170 | 178 |
171 static void buddy_ticker_remove_buddy(GaimBuddy *b) { | 179 static void buddy_ticker_remove(TickerData *td) { |
172 TickerData *td = buddy_ticker_find_buddy(b); | |
173 | |
174 if (!td) | |
175 return; | |
176 | |
177 /* pop up the ticker window again */ | |
178 buddy_ticker_create_window(); | |
179 | |
180 gtk_ticker_remove(GTK_TICKER(ticker), td->ebox); | 180 gtk_ticker_remove(GTK_TICKER(ticker), td->ebox); |
181 tickerbuds = g_list_remove(tickerbuds, td); | 181 tickerbuds = g_list_remove(tickerbuds, td); |
182 if (td->timeout != 0) | 182 if (td->timeout != 0) |
183 g_source_remove(td->timeout); | 183 g_source_remove(td->timeout); |
184 g_free(td); | 184 g_free(td); |
185 } | |
186 | |
187 static void buddy_ticker_update_contact(GaimContact *contact) { | |
188 TickerData *td = buddy_ticker_find_contact(contact); | |
189 | |
190 if (!td) | |
191 return; | |
192 | |
193 /* pop up the ticker window again */ | |
194 buddy_ticker_create_window(); | |
195 if (gaim_contact_get_priority_buddy(contact) == NULL) | |
196 buddy_ticker_remove(td); | |
197 else { | |
198 buddy_ticker_set_pixmap(contact); | |
199 gtk_label_set_text(GTK_LABEL(td->label), gaim_contact_get_alias(contact)); | |
200 } | |
201 } | |
202 | |
203 static void buddy_ticker_remove_buddy(GaimBuddy *b) { | |
204 GaimContact *c = gaim_buddy_get_contact(b); | |
205 TickerData *td = buddy_ticker_find_contact(c); | |
206 | |
207 if (!td) | |
208 return; | |
209 | |
210 gaim_contact_invalidate_priority_buddy(c); | |
211 | |
212 /* pop up the ticker window again */ | |
213 buddy_ticker_create_window(); | |
214 buddy_ticker_update_contact(c); | |
185 } | 215 } |
186 | 216 |
187 static void buddy_ticker_show() | 217 static void buddy_ticker_show() |
188 { | 218 { |
189 GaimBuddyList *list = gaim_get_blist(); | 219 GaimBuddyList *list = gaim_get_blist(); |
211 } | 241 } |
212 | 242 |
213 static void | 243 static void |
214 buddy_signon_cb(GaimBuddy *b) | 244 buddy_signon_cb(GaimBuddy *b) |
215 { | 245 { |
216 if(buddy_ticker_find_buddy(b)) | 246 GaimContact *c = gaim_buddy_get_contact(b); |
217 buddy_ticker_set_pixmap(b); | 247 gaim_contact_invalidate_priority_buddy(c); |
248 if(buddy_ticker_find_contact(c)) | |
249 buddy_ticker_update_contact(c); | |
218 else | 250 else |
219 buddy_ticker_add_buddy(b); | 251 buddy_ticker_add_buddy(b); |
220 } | 252 } |
221 | 253 |
222 static void | 254 static void |
228 } | 260 } |
229 | 261 |
230 static void | 262 static void |
231 status_changed_cb(GaimBuddy *b, GaimStatus *os, GaimStatus *s) | 263 status_changed_cb(GaimBuddy *b, GaimStatus *os, GaimStatus *s) |
232 { | 264 { |
233 if(buddy_ticker_find_buddy(b)) | 265 GaimContact *c = gaim_buddy_get_contact(b); |
234 buddy_ticker_set_pixmap(b); | 266 if(buddy_ticker_find_contact(c)) |
267 buddy_ticker_set_pixmap(c); | |
235 else | 268 else |
236 buddy_ticker_add_buddy(b); | 269 buddy_ticker_add_buddy(b); |
237 } | 270 } |
238 | 271 |
239 static void | 272 static void |
254 } else { | 287 } else { |
255 GList *t = tickerbuds; | 288 GList *t = tickerbuds; |
256 while (t) { | 289 while (t) { |
257 td = t->data; | 290 td = t->data; |
258 t = t->next; | 291 t = t->next; |
259 if (td->buddy->account == gc->account) { | 292 buddy_ticker_update_contact(td->contact); |
260 buddy_signoff_cb(td->buddy); | |
261 } | |
262 } | 293 } |
263 } | 294 } |
264 } | 295 } |
265 | 296 |
266 | 297 |