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