Mercurial > pidgin
annotate src/gtkstatusbox.c @ 11552:11d30825c1bb
[gaim-migrate @ 13812]
Source Forge patch 1273590 from Casey Harkins to move all sound playing events into gtksound.[ch] as well as a few other clean ups to make sure that all sounds are being played by the ui.
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Sat, 17 Sep 2005 03:00:12 +0000 |
parents | 1116993aadd2 |
children | 9f521a61ef58 |
rev | line source |
---|---|
10643 | 1 /* |
2 * @file gtkstatusbox.c GTK+ Status Selection Widget | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 | |
26 #include "internal.h" | |
27 #include "account.h" | |
28 #include "status.h" | |
29 #include "gtkgaim.h" | |
30 #include "gtkstock.h" | |
31 #include "gtkstatusbox.h" | |
32 | |
33 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); | |
34 | |
35 static void gtk_gaim_status_box_changed(GtkComboBox *box); | |
36 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
37 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
38 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); | |
39 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
40 | |
41 static void (*combo_box_size_request)(GtkWidget *widget, GtkRequisition *requisition); | |
42 static void (*combo_box_size_allocate)(GtkWidget *widget, GtkAllocation *allocation); | |
43 static gboolean (*combo_box_expose_event)(GtkWidget *widget, GdkEventExpose *event); | |
44 static void (*combo_box_forall) (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
45 enum { | |
46 ICON_COLUMN, | |
47 TEXT_COLUMN, | |
48 TITLE_COLUMN, | |
49 DESC_COLUMN, | |
50 TYPE_COLUMN, | |
51 NUM_COLUMNS | |
52 }; | |
53 | |
11499 | 54 enum { |
55 PROP_0, | |
56 PROP_ACCOUNT | |
57 }; | |
58 | |
10643 | 59 static void gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass); |
60 static void gtk_gaim_status_box_init (GtkGaimStatusBox *status_box); | |
61 | |
62 GType | |
63 gtk_gaim_status_box_get_type (void) | |
64 { | |
10861 | 65 static GType status_box_type = 0; |
10643 | 66 |
10861 | 67 if (!status_box_type) |
68 { | |
69 static const GTypeInfo status_box_info = | |
70 { | |
71 sizeof (GtkGaimStatusBoxClass), | |
72 NULL, /* base_init */ | |
73 NULL, /* base_finalize */ | |
74 (GClassInitFunc) gtk_gaim_status_box_class_init, | |
75 NULL, /* class_finalize */ | |
76 NULL, /* class_data */ | |
77 sizeof (GtkGaimStatusBox), | |
78 0, | |
79 (GInstanceInitFunc) gtk_gaim_status_box_init | |
80 }; | |
10643 | 81 |
10861 | 82 status_box_type = g_type_register_static(GTK_TYPE_COMBO_BOX, |
83 "GtkGaimStatusBox", | |
84 &status_box_info, | |
85 0); | |
86 } | |
10643 | 87 |
10861 | 88 return status_box_type; |
10643 | 89 } |
90 | |
91 static void | |
11499 | 92 gtk_gaim_status_box_get_property(GObject *object, guint param_id, |
93 GValue *value, GParamSpec *psec) | |
94 { | |
95 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
96 | |
97 switch (param_id) { | |
98 case PROP_ACCOUNT: | |
99 g_value_set_pointer(value, statusbox->account); | |
100 break; | |
101 default: | |
102 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, psec); | |
103 break; | |
104 } | |
105 } | |
106 | |
107 static void | |
108 gtk_gaim_status_box_set_property(GObject *object, guint param_id, | |
109 const GValue *value, GParamSpec *pspec) | |
110 { | |
111 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
112 | |
113 switch (param_id) { | |
114 case PROP_ACCOUNT: | |
115 statusbox->account = g_value_get_pointer(value); | |
116 break; | |
117 default: | |
118 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | |
119 break; | |
120 } | |
121 } | |
122 | |
123 | |
124 static void | |
10643 | 125 gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass) |
126 { | |
10861 | 127 GObjectClass *object_class; |
128 GtkWidgetClass *widget_class; | |
129 GtkComboBoxClass *parent_class = (GtkComboBoxClass*)klass; | |
130 GtkContainerClass *container_class = (GtkContainerClass*)klass; | |
10643 | 131 |
10861 | 132 parent_class->changed = gtk_gaim_status_box_changed; |
133 widget_class = (GtkWidgetClass*)klass; | |
134 combo_box_size_request = widget_class->size_request; | |
135 widget_class->size_request = gtk_gaim_status_box_size_request; | |
136 combo_box_size_allocate = widget_class->size_allocate; | |
137 widget_class->size_allocate = gtk_gaim_status_box_size_allocate; | |
138 combo_box_expose_event = widget_class->expose_event; | |
139 widget_class->expose_event = gtk_gaim_status_box_expose_event; | |
10643 | 140 |
10861 | 141 combo_box_forall = container_class->forall; |
142 container_class->forall = gtk_gaim_status_box_forall; | |
143 | |
144 object_class = (GObjectClass *)klass; | |
11499 | 145 |
146 object_class->get_property = gtk_gaim_status_box_get_property; | |
147 object_class->set_property = gtk_gaim_status_box_set_property; | |
148 | |
149 g_object_class_install_property(object_class, | |
150 PROP_ACCOUNT, | |
151 g_param_spec_pointer("account", | |
152 "Account", | |
153 "The account, or NULL for all accounts", | |
154 G_PARAM_READWRITE | |
155 ) | |
156 ); | |
10643 | 157 } |
158 | |
159 static void | |
160 gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box) | |
161 { | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
162 char *text, *title; |
10643 | 163 char aa_color[8]; |
164 GdkPixbuf *pixbuf; | |
10702 | 165 GtkTreePath *path; |
10643 | 166 |
167 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
168 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
169 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
170 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
171 style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
172 |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
173 title = status_box->title; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
174 if (!title) |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
175 title = ""; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
176 |
10643 | 177 if (status_box->error) { |
11499 | 178 text = g_strdup_printf("%s\n<span size=\"smaller\" weight=\"bold\" color=\"red\">%s</span>", |
10861 | 179 title, status_box->error); |
10643 | 180 } else if (status_box->typing) { |
10861 | 181 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
182 title, aa_color, _("Typing")); | |
10643 | 183 } else if (status_box->connecting) { |
10861 | 184 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
185 title, aa_color, _("Connecting")); | |
186 } else if (status_box->desc) { | |
187 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", | |
188 title, aa_color, status_box->desc); | |
10643 | 189 } else { |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
190 text = g_strdup_printf("%s", title); |
10643 | 191 } |
10861 | 192 |
11523 | 193 if (status_box->connecting) |
194 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; | |
195 else if (status_box->error) | |
10643 | 196 pixbuf = status_box->error_pixbuf; |
197 else if (status_box->typing) | |
198 pixbuf = status_box->typing_pixbufs[status_box->typing_index]; | |
199 else | |
200 pixbuf = status_box->pixbuf; | |
201 | |
202 gtk_list_store_set(status_box->store, &(status_box->iter), | |
203 ICON_COLUMN, pixbuf, | |
10861 | 204 TEXT_COLUMN, text, |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
205 TITLE_COLUMN, title, |
10861 | 206 DESC_COLUMN, status_box->desc, |
10643 | 207 TYPE_COLUMN, NULL, -1); |
10702 | 208 path = gtk_tree_path_new_from_string("0"); |
209 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); | |
210 gtk_tree_path_free(path); | |
10643 | 211 |
212 g_free(text); | |
213 } | |
214 | |
215 static void | |
216 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) | |
217 { | |
11400 | 218 GtkCellRenderer *text_rend; |
219 GtkCellRenderer *icon_rend; | |
10643 | 220 GtkTextBuffer *buffer; |
221 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; | |
11400 | 222 GtkIconSize icon_size; |
223 | |
224 text_rend = gtk_cell_renderer_text_new(); | |
225 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
226 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
10643 | 227 |
228 status_box->imhtml_visible = FALSE; | |
229 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
230 icon_size, "GtkGaimStatusBox"); | |
231 status_box->connecting_index = 0; | |
10861 | 232 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT0, |
10643 | 233 icon_size, "GtkGaimStatusBox"); |
10861 | 234 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT1, |
10643 | 235 icon_size, "GtkGaimStatusBox"); |
10861 | 236 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT2, |
10643 | 237 icon_size, "GtkGaimStatusBox"); |
10861 | 238 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT3, |
10643 | 239 icon_size, "GtkGaimStatusBox"); |
240 | |
241 status_box->typing_index = 0; | |
242 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING0, | |
243 icon_size, "GtkGaimStatusBox"); | |
244 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING1, | |
245 icon_size, "GtkGaimStatusBox"); | |
246 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING2, | |
247 icon_size, "GtkGaimStatusBox"); | |
248 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING3, | |
249 icon_size, "GtkGaimStatusBox"); | |
250 status_box->connecting = FALSE; | |
251 status_box->typing = FALSE; | |
252 status_box->title = NULL; | |
10861 | 253 status_box->pixbuf = NULL; |
10643 | 254 status_box->cell_view = gtk_cell_view_new(); |
255 gtk_widget_show (status_box->cell_view); | |
10861 | 256 |
10643 | 257 status_box->store = gtk_list_store_new(NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
258 status_box->dropdown_store = gtk_list_store_new(NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); | |
259 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); | |
260 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
261 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
262 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
263 gtk_gaim_status_box_refresh(status_box); | |
264 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), gtk_tree_path_new_from_string("0")); | |
265 gtk_container_add(GTK_CONTAINER(status_box), status_box->cell_view); | |
10861 | 266 |
10643 | 267 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
268 status_box->text_rend = gtk_cell_renderer_text_new(); | |
269 | |
270 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
10861 | 271 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 272 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
273 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
274 | |
275 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
11499 | 276 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 277 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
278 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
279 | |
280 status_box->vbox = gtk_vbox_new(0, FALSE); | |
281 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
282 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
283 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
284 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); | |
285 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
286 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
287 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
288 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
289 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
290 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
291 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_ONLINE, | |
292 icon_size, "GtkGaimStatusBox"); | |
293 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_AWAY, | |
294 icon_size, "GtkGaimStatusBox"); | |
295 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
296 icon_size, "GtkGaimStatusBox"); | |
297 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_INVISIBLE, | |
298 icon_size, "GtkGaimStatusBox"); | |
299 /* hacks */ | |
300 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Available"), NULL, "available"); | |
301 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf2, _("Away"), NULL, "away"); | |
302 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf4, _("Invisible"), NULL, "invisible"); | |
303 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf3, _("Offline"), NULL, "offline"); | |
11306 | 304 /* |
305 * TODO: This triggers a callback of gaim_gtk_status_box_changed(). | |
306 * That's bad. We should at least try not figure out what | |
307 * status the user's accounts are set to instead of always | |
308 * using "Available." | |
309 */ | |
11347 | 310 /* gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); */ |
10643 | 311 |
312 } | |
313 | |
314 | |
315 static void | |
10861 | 316 gtk_gaim_status_box_size_request(GtkWidget *widget, |
317 GtkRequisition *requisition) | |
10643 | 318 { |
319 GtkRequisition box_req; | |
320 combo_box_size_request(widget, requisition); | |
10861 | 321 |
10643 | 322 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
323 if (box_req.height > 1) | |
324 requisition->height = requisition->height + box_req.height + 6; | |
10861 | 325 |
10643 | 326 requisition->width = 1; |
327 | |
328 } | |
329 | |
330 static void | |
10861 | 331 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
332 GtkAllocation *allocation) | |
10643 | 333 { |
334 GtkRequisition req = {0,0}; | |
11400 | 335 GtkAllocation parent_alc, box_alc; |
336 | |
337 parent_alc = *allocation; | |
338 box_alc = *allocation; | |
10643 | 339 combo_box_size_request(widget, &req); |
10861 | 340 |
10643 | 341 /* EVIL XXX */ |
10861 | 342 box_alc.height = 80; |
343 /* box_alc.height = MAX(1,box_alc.height - req.height - 6); */ | |
344 | |
10643 | 345 box_alc.y = box_alc.y + req.height + 6; |
346 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | |
10861 | 347 |
10643 | 348 parent_alc.height = MAX(1,req.height); |
349 combo_box_size_allocate(widget, &parent_alc); | |
350 widget->allocation = *allocation; | |
351 } | |
352 | |
353 | |
354 static gboolean | |
10861 | 355 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
356 GdkEventExpose *event) | |
10643 | 357 { |
10861 | 358 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
359 combo_box_expose_event(widget, event); | |
10643 | 360 |
10861 | 361 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
362 status_box->vbox, event); | |
363 return FALSE; | |
10643 | 364 } |
365 | |
366 static void | |
10861 | 367 gtk_gaim_status_box_forall(GtkContainer *container, |
368 gboolean include_internals, | |
369 GtkCallback callback, | |
370 gpointer callback_data) | |
10643 | 371 { |
10861 | 372 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 373 |
10861 | 374 if (include_internals) |
375 { | |
376 (* callback) (status_box->vbox, callback_data); | |
377 } | |
10643 | 378 |
10861 | 379 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 380 } |
381 | |
382 GtkWidget * | |
383 gtk_gaim_status_box_new() | |
384 { | |
385 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
386 } | |
387 | |
11499 | 388 GtkWidget * |
389 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
390 { | |
391 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
392 } | |
10643 | 393 |
394 void | |
395 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GdkPixbuf *pixbuf, const char *text, const char *sec_text, char *edit) | |
396 { | |
397 GtkTreeIter iter; | |
398 char *t; | |
10861 | 399 |
10643 | 400 if (sec_text) { |
401 char aa_color[8]; | |
402 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
403 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
404 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
405 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 406 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 407 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
408 } else { | |
409 t = g_strdup(text); | |
410 } | |
10861 | 411 |
10643 | 412 gtk_list_store_append(status_box->dropdown_store, &iter); |
413 gtk_list_store_set(status_box->dropdown_store, &iter, | |
414 ICON_COLUMN, pixbuf, | |
10861 | 415 TEXT_COLUMN, t, |
10643 | 416 TITLE_COLUMN, text, |
10861 | 417 DESC_COLUMN, sec_text, |
10643 | 418 TYPE_COLUMN, edit, -1); |
419 } | |
420 | |
421 void | |
422 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) | |
423 { | |
11523 | 424 if (status_box->error) |
425 g_free(status_box->error); | |
10643 | 426 status_box->error = g_strdup(error); |
427 gtk_gaim_status_box_refresh(status_box); | |
428 } | |
429 | |
430 void | |
431 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
432 { | |
433 if (!status_box) | |
434 return; | |
435 status_box->connecting = connecting; | |
436 gtk_gaim_status_box_refresh(status_box); | |
437 } | |
438 | |
439 void | |
440 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
441 { | |
442 if (!status_box) | |
443 return; | |
444 if (status_box->connecting_index == 3) | |
445 status_box->connecting_index = 0; | |
10861 | 446 else |
10643 | 447 status_box->connecting_index++; |
448 gtk_gaim_status_box_refresh(status_box); | |
449 } | |
450 | |
451 void | |
452 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
453 { | |
454 if (status_box->typing_index == 3) | |
455 status_box->typing_index = 0; | |
10861 | 456 else |
10643 | 457 status_box->typing_index++; |
458 gtk_gaim_status_box_refresh(status_box); | |
459 } | |
460 | |
461 static void remove_typing_cb(GtkGaimStatusBox *box) | |
462 { | |
463 gchar *status_type_id; | |
464 GList *l; | |
465 GtkTreeIter iter; | |
466 | |
467 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(box), &iter); | |
468 gtk_tree_model_get(GTK_TREE_MODEL(box->dropdown_store), &iter, TYPE_COLUMN, &status_type_id, -1); | |
469 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
470 GaimAccount *account = (GaimAccount*)l->data; | |
471 GaimStatusType *status_type; | |
10861 | 472 |
10643 | 473 if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) |
474 continue; | |
475 | |
476 status_type = gaim_account_get_status_type(account, status_type_id); | |
477 | |
478 if (status_type == NULL) | |
479 continue; | |
10861 | 480 gaim_account_set_status(account, status_type_id, TRUE, |
10643 | 481 "message",gtk_imhtml_get_markup(GTK_IMHTML(box->imhtml)), NULL); |
482 } | |
483 g_source_remove(box->typing); | |
484 box->typing = 0; | |
485 gtk_gaim_status_box_refresh(box); | |
486 } | |
487 | |
488 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
489 { | |
11400 | 490 GtkGaimStatusBox *status_box; |
10643 | 491 GtkTreeIter iter; |
492 char *text, *sec_text; | |
493 GdkPixbuf *pixbuf; | |
494 gchar *status_type_id; | |
495 GList *l; | |
496 | |
11400 | 497 status_box = GTK_GAIM_STATUS_BOX(box); |
498 | |
10643 | 499 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
500 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, TITLE_COLUMN, &text, | |
10861 | 501 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
10643 | 502 TYPE_COLUMN, &status_type_id, -1); |
503 if (status_box->title) | |
504 g_free(status_box->title); | |
505 status_box->title = g_strdup(text); | |
506 if (status_box->desc && sec_text) | |
10861 | 507 g_free(status_box->desc); |
10643 | 508 status_box->desc = g_strdup(sec_text); |
509 if (status_box->pixbuf) | |
510 g_object_unref(status_box->pixbuf); | |
511 status_box->pixbuf = pixbuf; | |
10861 | 512 |
10643 | 513 if (!strcmp(status_type_id, "away")) { |
514 gtk_widget_show_all(status_box->vbox); | |
515 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
516 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
517 gtk_widget_grab_focus(status_box->imhtml); | |
518 } else { | |
519 if (status_box->typing) { | |
520 g_source_remove(status_box->typing); | |
521 status_box->typing = 0; | |
522 } | |
523 gtk_widget_hide_all(status_box->vbox); | |
524 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
525 GaimAccount *account = (GaimAccount*)l->data; | |
526 GaimStatusType *status_type; | |
527 | |
528 if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) | |
529 continue; | |
530 | |
531 status_type = gaim_account_get_status_type(account, status_type_id); | |
532 | |
533 if (status_type == NULL) | |
534 continue; | |
535 gaim_account_set_status(account, status_type_id, TRUE, NULL); | |
536 } | |
537 } | |
538 gtk_gaim_status_box_refresh(status_box); | |
539 } | |
540 | |
541 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
542 { | |
543 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
544 if (box->typing) { | |
545 gtk_gaim_status_box_pulse_typing(box); | |
546 g_source_remove(box->typing); | |
10861 | 547 } |
10643 | 548 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); |
549 gtk_gaim_status_box_refresh(box); | |
550 } | |
10649 | 551 |
552 const char *gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) | |
553 { | |
554 GtkTreeIter iter; | |
555 char *type; | |
556 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); | |
10861 | 557 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 558 TYPE_COLUMN, &type, -1); |
559 return type; | |
560 } | |
561 | |
562 const char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) | |
563 { | |
564 if (status_box->imhtml_visible) | |
565 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
566 else | |
567 return NULL; | |
568 } |