Mercurial > pidgin
annotate src/gtkstatusbox.c @ 11993:aa77da6c7f21
[gaim-migrate @ 14286]
<nosnilmot> marv: status_type = g_list_nth_data((GList *)l, active) doesn't work too well if you have non-user settable statuses that have been skipped
<marv> hm, that's true. oops.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Sun, 06 Nov 2005 22:53:21 +0000 |
parents | 94ba447a6a5c |
children | 9d451c9cc3d9 |
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 | |
11627 | 26 #include "account.h" |
10643 | 27 #include "internal.h" |
11627 | 28 #include "savedstatuses.h" |
10643 | 29 #include "status.h" |
11732 | 30 #include "debug.h" |
11627 | 31 |
10643 | 32 #include "gtkgaim.h" |
11729 | 33 #include "gtksavedstatuses.h" |
10643 | 34 #include "gtkstock.h" |
35 #include "gtkstatusbox.h" | |
36 | |
37 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); | |
11562 | 38 static void remove_typing_cb(GtkGaimStatusBox *box); |
10643 | 39 |
11967 | 40 static void gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box); |
11732 | 41 static void gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box); |
10643 | 42 static void gtk_gaim_status_box_changed(GtkComboBox *box); |
43 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
44 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
45 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); | |
46 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
47 | |
48 static void (*combo_box_size_request)(GtkWidget *widget, GtkRequisition *requisition); | |
49 static void (*combo_box_size_allocate)(GtkWidget *widget, GtkAllocation *allocation); | |
50 static gboolean (*combo_box_expose_event)(GtkWidget *widget, GdkEventExpose *event); | |
51 static void (*combo_box_forall) (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
11739 | 52 |
10643 | 53 enum { |
11739 | 54 TYPE_COLUMN, /* A GtkGaimStatusBoxItemType */ |
11738 | 55 ICON_COLUMN, /* This is a GdkPixbuf (the other columns are strings) */ |
56 TEXT_COLUMN, /* A string */ | |
57 TITLE_COLUMN, /* The plain-English title of this item */ | |
58 DESC_COLUMN, /* A plain-English description of this item */ | |
10643 | 59 NUM_COLUMNS |
60 }; | |
61 | |
11499 | 62 enum { |
63 PROP_0, | |
64 PROP_ACCOUNT | |
65 }; | |
66 | |
10643 | 67 static void gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass); |
68 static void gtk_gaim_status_box_init (GtkGaimStatusBox *status_box); | |
69 | |
70 GType | |
71 gtk_gaim_status_box_get_type (void) | |
72 { | |
10861 | 73 static GType status_box_type = 0; |
10643 | 74 |
10861 | 75 if (!status_box_type) |
76 { | |
77 static const GTypeInfo status_box_info = | |
78 { | |
79 sizeof (GtkGaimStatusBoxClass), | |
80 NULL, /* base_init */ | |
81 NULL, /* base_finalize */ | |
82 (GClassInitFunc) gtk_gaim_status_box_class_init, | |
83 NULL, /* class_finalize */ | |
84 NULL, /* class_data */ | |
85 sizeof (GtkGaimStatusBox), | |
86 0, | |
87 (GInstanceInitFunc) gtk_gaim_status_box_init | |
88 }; | |
10643 | 89 |
10861 | 90 status_box_type = g_type_register_static(GTK_TYPE_COMBO_BOX, |
91 "GtkGaimStatusBox", | |
92 &status_box_info, | |
93 0); | |
94 } | |
10643 | 95 |
10861 | 96 return status_box_type; |
10643 | 97 } |
98 | |
99 static void | |
11499 | 100 gtk_gaim_status_box_get_property(GObject *object, guint param_id, |
101 GValue *value, GParamSpec *psec) | |
102 { | |
103 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
104 | |
105 switch (param_id) { | |
106 case PROP_ACCOUNT: | |
107 g_value_set_pointer(value, statusbox->account); | |
108 break; | |
109 default: | |
110 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, psec); | |
111 break; | |
112 } | |
113 } | |
114 | |
115 static void | |
11967 | 116 update_to_reflect_account_status(GtkGaimStatusBox *status_box, GaimAccount *account, GaimStatus *newstatus) |
11960 | 117 { |
11967 | 118 const GList *l; |
119 int status_no = -1; | |
120 const GaimStatusType *statustype = NULL; | |
121 | |
122 statustype = gaim_status_type_find_with_id((GList *)gaim_account_get_status_types(account), | |
123 (char *)gaim_status_type_get_id(gaim_status_get_type(newstatus))); | |
124 | |
125 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) { | |
126 GaimStatusType *status_type = (GaimStatusType *)l->data; | |
127 | |
128 if (!gaim_status_type_is_user_settable(status_type)) | |
129 continue; | |
130 status_no++; | |
131 if (statustype == status_type) | |
132 break; | |
133 } | |
134 | |
135 if (status_no != -1) { | |
136 gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE); | |
137 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), status_no); | |
138 gtk_gaim_status_box_refresh(status_box); | |
139 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); | |
140 } | |
141 | |
142 } | |
143 | |
144 static void | |
145 account_status_changed_cb(GaimAccount *account, GaimStatus *oldstatus, GaimStatus *newstatus, GtkGaimStatusBox *status_box) | |
146 { | |
147 if (status_box->account == account) | |
148 update_to_reflect_account_status(status_box, account, newstatus); | |
11960 | 149 } |
150 | |
151 static void | |
11499 | 152 gtk_gaim_status_box_set_property(GObject *object, guint param_id, |
153 const GValue *value, GParamSpec *pspec) | |
154 { | |
155 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
156 | |
157 switch (param_id) { | |
158 case PROP_ACCOUNT: | |
159 statusbox->account = g_value_get_pointer(value); | |
11960 | 160 |
161 /* FIXME: call this in the destroy function too, if we had one */ | |
11967 | 162 if (statusbox->status_changed_signal) { |
163 gaim_signal_disconnect(gaim_accounts_get_handle(), "account-status-changed", | |
164 statusbox, GAIM_CALLBACK(account_status_changed_cb)); | |
165 statusbox->status_changed_signal = 0; | |
166 } | |
11960 | 167 if (statusbox->account) |
11967 | 168 statusbox->status_changed_signal = gaim_signal_connect(gaim_accounts_get_handle(), "account-status-changed", |
11960 | 169 statusbox, GAIM_CALLBACK(account_status_changed_cb), |
170 statusbox); | |
11732 | 171 gtk_gaim_status_box_regenerate(statusbox); |
11499 | 172 break; |
173 default: | |
174 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | |
175 break; | |
176 } | |
177 } | |
178 | |
179 | |
180 static void | |
10643 | 181 gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass) |
182 { | |
10861 | 183 GObjectClass *object_class; |
184 GtkWidgetClass *widget_class; | |
185 GtkComboBoxClass *parent_class = (GtkComboBoxClass*)klass; | |
186 GtkContainerClass *container_class = (GtkContainerClass*)klass; | |
10643 | 187 |
10861 | 188 parent_class->changed = gtk_gaim_status_box_changed; |
189 widget_class = (GtkWidgetClass*)klass; | |
190 combo_box_size_request = widget_class->size_request; | |
191 widget_class->size_request = gtk_gaim_status_box_size_request; | |
192 combo_box_size_allocate = widget_class->size_allocate; | |
193 widget_class->size_allocate = gtk_gaim_status_box_size_allocate; | |
194 combo_box_expose_event = widget_class->expose_event; | |
195 widget_class->expose_event = gtk_gaim_status_box_expose_event; | |
10643 | 196 |
10861 | 197 combo_box_forall = container_class->forall; |
198 container_class->forall = gtk_gaim_status_box_forall; | |
199 | |
200 object_class = (GObjectClass *)klass; | |
11499 | 201 |
202 object_class->get_property = gtk_gaim_status_box_get_property; | |
203 object_class->set_property = gtk_gaim_status_box_set_property; | |
204 | |
205 g_object_class_install_property(object_class, | |
206 PROP_ACCOUNT, | |
207 g_param_spec_pointer("account", | |
208 "Account", | |
209 "The account, or NULL for all accounts", | |
210 G_PARAM_READWRITE | |
211 ) | |
212 ); | |
10643 | 213 } |
214 | |
215 static void | |
216 gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box) | |
217 { | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
218 char *text, *title; |
10643 | 219 char aa_color[8]; |
220 GdkPixbuf *pixbuf; | |
10702 | 221 GtkTreePath *path; |
11870 | 222 GtkStyle *style; |
10643 | 223 |
11870 | 224 style = gtk_widget_get_style(GTK_WIDGET(status_box)); |
10643 | 225 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", |
226 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
227 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
228 style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
229 |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
230 title = status_box->title; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
231 if (!title) |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
232 title = ""; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
233 |
11960 | 234 |
10643 | 235 if (status_box->error) { |
11499 | 236 text = g_strdup_printf("%s\n<span size=\"smaller\" weight=\"bold\" color=\"red\">%s</span>", |
10861 | 237 title, status_box->error); |
10643 | 238 } else if (status_box->typing) { |
10861 | 239 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
240 title, aa_color, _("Typing")); | |
10643 | 241 } else if (status_box->connecting) { |
10861 | 242 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
243 title, aa_color, _("Connecting")); | |
244 } else if (status_box->desc) { | |
245 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", | |
246 title, aa_color, status_box->desc); | |
10643 | 247 } else { |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
248 text = g_strdup_printf("%s", title); |
10643 | 249 } |
10861 | 250 |
11960 | 251 if (status_box->account) { |
252 char *text2 = g_strdup_printf("%s\n<span size=\"smaller\">%s</span>", gaim_account_get_username(status_box->account), text); | |
253 g_free(text); | |
254 text = text2; | |
255 } | |
256 | |
257 | |
11523 | 258 if (status_box->connecting) |
259 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; | |
260 else if (status_box->error) | |
10643 | 261 pixbuf = status_box->error_pixbuf; |
262 else if (status_box->typing) | |
263 pixbuf = status_box->typing_pixbufs[status_box->typing_index]; | |
264 else | |
265 pixbuf = status_box->pixbuf; | |
266 | |
267 gtk_list_store_set(status_box->store, &(status_box->iter), | |
11755 | 268 TYPE_COLUMN, -1, /* This field is not used in this list store */ |
10643 | 269 ICON_COLUMN, pixbuf, |
10861 | 270 TEXT_COLUMN, text, |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
271 TITLE_COLUMN, title, |
10861 | 272 DESC_COLUMN, status_box->desc, |
11739 | 273 -1); |
10702 | 274 path = gtk_tree_path_new_from_string("0"); |
275 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); | |
276 gtk_tree_path_free(path); | |
10643 | 277 |
278 g_free(text); | |
279 } | |
280 | |
11732 | 281 static GdkPixbuf * |
11983 | 282 load_icon(GaimAccount *account, GaimStatusType *status_type) |
11732 | 283 { |
284 char basename2[BUFSIZ]; | |
285 char *filename; | |
11983 | 286 GaimPluginProtocolInfo *prpl_info = NULL; |
287 GaimPlugin *plugin; | |
288 const char *proto_name, *type_name; | |
289 GdkPixbuf *pixbuf, *scale = NULL, *emblem; | |
11732 | 290 |
11983 | 291 |
292 plugin = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
11732 | 293 |
11983 | 294 if (plugin != NULL) { |
295 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin); | |
296 proto_name = prpl_info->list_icon(account, NULL); | |
297 } | |
298 | |
11732 | 299 g_snprintf(basename2, sizeof(basename2), "%s.png", |
11983 | 300 proto_name); |
301 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", | |
11732 | 302 basename2, NULL); |
303 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
304 g_free(filename); | |
305 | |
306 if (pixbuf != NULL) { | |
11983 | 307 scale = gdk_pixbuf_scale_simple(pixbuf, 32, 32, |
11732 | 308 GDK_INTERP_BILINEAR); |
309 g_object_unref(G_OBJECT(pixbuf)); | |
310 } | |
311 | |
11983 | 312 |
313 /* TODO: let the prpl pick the emblem on a per status bases, and only | |
314 * use the primitive as a fallback */ | |
315 type_name = gaim_primitive_get_id_from_type(gaim_status_type_get_primitive(status_type)); | |
316 if (!strcmp(type_name, "hidden")) | |
317 type_name = "invisible"; | |
318 if (!strcmp(type_name, "unavailable")) | |
319 type_name = "na"; | |
320 g_snprintf(basename2, sizeof(basename2), "%s.png", | |
321 type_name); | |
322 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", | |
323 basename2, NULL); | |
324 emblem = gdk_pixbuf_new_from_file(filename, NULL); | |
325 g_free(filename); | |
326 | |
327 if (emblem) { | |
328 gdk_pixbuf_composite(emblem, | |
329 scale, 32-15, 32-15, | |
330 15, 15, | |
331 32-15, 32-15, | |
332 1, 1, | |
333 GDK_INTERP_BILINEAR, | |
334 255); | |
335 | |
336 g_object_unref(emblem); | |
337 } | |
11732 | 338 return scale; |
339 } | |
340 | |
11870 | 341 /** |
342 * This updates the GtkTreeView so that it correctly shows the state | |
343 * we are currently using. It is used when the current state is | |
344 * updated from somewhere other than the GtkStatusBox (from a plugin, | |
345 * or when signing on with the "-n" option, for example). It is | |
346 * also used when the user selects the "Custom..." option. | |
347 * | |
348 * Maybe we could accomplish this by triggering off the mouse and | |
349 * keyboard signals instead of the changed signal? | |
350 */ | |
351 static void | |
352 update_to_reflect_current_status(GtkGaimStatusBox *status_box) | |
353 { | |
354 const char *current_savedstatus_name; | |
355 GaimSavedStatus *saved_status; | |
356 | |
11983 | 357 /* this function is inappropriate for ones with accounts */ |
358 if (status_box->account) | |
359 return; | |
360 | |
11870 | 361 current_savedstatus_name = gaim_prefs_get_string("/core/status/current"); |
362 saved_status = gaim_savedstatus_find(current_savedstatus_name); | |
11951 | 363 |
364 /* | |
365 * Suppress the "changed" signal because the status | |
366 * was changed programmatically. | |
367 */ | |
368 gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE); | |
369 | |
11870 | 370 if (saved_status == NULL) |
371 { | |
372 /* Default to "available" */ | |
373 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
374 } | |
375 else | |
376 { | |
377 GaimStatusPrimitive primitive; | |
378 const char *message; | |
379 | |
380 primitive = gaim_savedstatus_get_type(saved_status); | |
381 if (gaim_savedstatus_has_substatuses(saved_status) || | |
382 ((primitive != GAIM_STATUS_AVAILABLE) && | |
383 (primitive != GAIM_STATUS_OFFLINE) && | |
384 (primitive != GAIM_STATUS_AWAY) && | |
385 (primitive != GAIM_STATUS_HIDDEN))) | |
386 { | |
387 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 4); | |
388 } | |
389 else | |
390 { | |
391 if (primitive == GAIM_STATUS_AVAILABLE) | |
392 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
393 if (primitive == GAIM_STATUS_OFFLINE) | |
394 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3); | |
395 else if (primitive == GAIM_STATUS_AWAY) | |
396 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1); | |
397 else if (primitive == GAIM_STATUS_HIDDEN) | |
398 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2); | |
399 } | |
400 | |
401 message = gaim_savedstatus_get_message(saved_status); | |
11954 | 402 if (message == NULL) |
11951 | 403 { |
11954 | 404 status_box->imhtml_visible = FALSE; |
405 } | |
406 else | |
407 { | |
408 status_box->imhtml_visible = TRUE; | |
409 | |
11951 | 410 /* |
411 * Suppress the "changed" signal because the status | |
412 * was changed programmatically. | |
413 */ | |
414 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), FALSE); | |
11954 | 415 |
416 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
11870 | 417 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); |
11951 | 418 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), TRUE); |
419 } | |
11870 | 420 } |
11951 | 421 |
422 /* Stop suppressing the "changed" signal. */ | |
423 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); | |
11870 | 424 } |
425 | |
11732 | 426 static void |
427 gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) | |
428 { | |
11739 | 429 GaimAccount *account; |
11732 | 430 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; |
431 GtkIconSize icon_size; | |
432 | |
433 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
434 | |
435 gtk_list_store_clear(status_box->dropdown_store); | |
436 | |
11739 | 437 account = GTK_GAIM_STATUS_BOX(status_box)->account; |
438 if (account == NULL) | |
439 { | |
11756 | 440 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_ONLINE, |
11732 | 441 icon_size, "GtkGaimStatusBox"); |
11756 | 442 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_AWAY, |
11732 | 443 icon_size, "GtkGaimStatusBox"); |
11756 | 444 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
11732 | 445 icon_size, "GtkGaimStatusBox"); |
11756 | 446 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_INVISIBLE, |
11732 | 447 icon_size, "GtkGaimStatusBox"); |
448 /* hacks */ | |
11739 | 449 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AVAILABLE, pixbuf, _("Available"), NULL); |
450 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AWAY, pixbuf2, _("Away"), NULL); | |
451 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_HIDDEN, pixbuf4, _("Invisible"), NULL); | |
452 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_OFFLINE, pixbuf3, _("Offline"), NULL); | |
11738 | 453 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box)); |
11739 | 454 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("Custom..."), NULL); |
455 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL); | |
11732 | 456 |
11870 | 457 update_to_reflect_current_status(status_box); |
11732 | 458 |
459 } else { | |
460 const GList *l; | |
11739 | 461 |
462 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
463 { | |
11732 | 464 GaimStatusType *status_type = (GaimStatusType *)l->data; |
465 | |
466 if (!gaim_status_type_is_user_settable(status_type)) | |
467 continue; | |
468 | |
11739 | 469 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), |
470 gaim_status_type_get_primitive(status_type), | |
11983 | 471 load_icon(account, status_type), |
11739 | 472 gaim_status_type_get_name(status_type), |
473 NULL); | |
11732 | 474 } |
11967 | 475 update_to_reflect_account_status(status_box, account, gaim_account_get_active_status(account)); |
11732 | 476 } |
477 | |
478 } | |
479 | |
11753 | 480 #if GTK_CHECK_VERSION(2,6,0) |
11738 | 481 static gboolean |
482 dropdown_store_row_separator_func(GtkTreeModel *model, | |
483 GtkTreeIter *iter, gpointer data) | |
484 { | |
11739 | 485 GtkGaimStatusBoxItemType type; |
11738 | 486 |
11885 | 487 gtk_tree_model_get(model, iter, TYPE_COLUMN, &type, -1); |
11738 | 488 |
11739 | 489 if (type == GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR) |
11738 | 490 return TRUE; |
491 | |
492 return FALSE; | |
493 } | |
11753 | 494 #endif |
11738 | 495 |
10643 | 496 static void |
11954 | 497 current_status_pref_changed_cb(const char *name, GaimPrefType type, |
498 gpointer val, gpointer data) | |
499 { | |
500 update_to_reflect_current_status(data); | |
501 } | |
502 | |
503 static void | |
10643 | 504 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) |
505 { | |
11400 | 506 GtkCellRenderer *text_rend; |
507 GtkCellRenderer *icon_rend; | |
10643 | 508 GtkTextBuffer *buffer; |
11732 | 509 GtkTreePath *path; |
11400 | 510 GtkIconSize icon_size; |
511 | |
512 text_rend = gtk_cell_renderer_text_new(); | |
513 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
514 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
10643 | 515 |
516 status_box->imhtml_visible = FALSE; | |
517 status_box->connecting = FALSE; | |
518 status_box->typing = FALSE; | |
519 status_box->title = NULL; | |
10861 | 520 status_box->pixbuf = NULL; |
10643 | 521 status_box->cell_view = gtk_cell_view_new(); |
522 gtk_widget_show (status_box->cell_view); | |
10861 | 523 |
11739 | 524 status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
525 status_box->dropdown_store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); | |
10643 | 526 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
527 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
528 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
529 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
530 gtk_gaim_status_box_refresh(status_box); | |
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
531 path = gtk_tree_path_new_from_string("0"); |
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
532 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); |
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
533 gtk_tree_path_free(path); |
10643 | 534 gtk_container_add(GTK_CONTAINER(status_box), status_box->cell_view); |
10861 | 535 |
10643 | 536 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
537 status_box->text_rend = gtk_cell_renderer_text_new(); | |
538 | |
539 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
10861 | 540 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 541 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
542 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
543 | |
544 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
11499 | 545 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 546 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
547 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
548 | |
549 status_box->vbox = gtk_vbox_new(0, FALSE); | |
550 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
551 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
552 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
11562 | 553 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 554 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
555 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
556 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
557 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
558 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
559 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
560 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
11654 | 561 |
11850 | 562 |
563 #if GTK_CHECK_VERSION(2,6,0) | |
564 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); | |
565 #endif | |
566 | |
11756 | 567 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
568 icon_size, "GtkGaimStatusBox"); | |
569 status_box->connecting_index = 0; | |
570 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT0, | |
571 icon_size, "GtkGaimStatusBox"); | |
572 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT1, | |
573 icon_size, "GtkGaimStatusBox"); | |
574 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT2, | |
575 icon_size, "GtkGaimStatusBox"); | |
576 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT3, | |
577 icon_size, "GtkGaimStatusBox"); | |
578 | |
579 status_box->typing_index = 0; | |
580 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING0, | |
581 icon_size, "GtkGaimStatusBox"); | |
582 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING1, | |
583 icon_size, "GtkGaimStatusBox"); | |
584 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING2, | |
585 icon_size, "GtkGaimStatusBox"); | |
586 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING3, | |
587 icon_size, "GtkGaimStatusBox"); | |
588 | |
11732 | 589 gtk_gaim_status_box_regenerate(status_box); |
11954 | 590 |
591 /* Monitor changes in the "/core/status/current" preference */ | |
592 gaim_prefs_connect_callback(status_box, "/core/status/current", | |
593 current_status_pref_changed_cb, status_box); | |
594 | |
595 /* TODO: Need to override the destroy method for this object and put the following line in it */ | |
596 /* gaim_prefs_disconnect_by_handle(status_box); */ | |
10643 | 597 } |
598 | |
599 static void | |
10861 | 600 gtk_gaim_status_box_size_request(GtkWidget *widget, |
601 GtkRequisition *requisition) | |
10643 | 602 { |
603 GtkRequisition box_req; | |
604 combo_box_size_request(widget, requisition); | |
10861 | 605 |
10643 | 606 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
607 if (box_req.height > 1) | |
608 requisition->height = requisition->height + box_req.height + 6; | |
10861 | 609 |
10643 | 610 requisition->width = 1; |
611 | |
612 } | |
613 | |
614 static void | |
10861 | 615 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
616 GtkAllocation *allocation) | |
10643 | 617 { |
618 GtkRequisition req = {0,0}; | |
11400 | 619 GtkAllocation parent_alc, box_alc; |
620 | |
621 parent_alc = *allocation; | |
622 box_alc = *allocation; | |
10643 | 623 combo_box_size_request(widget, &req); |
10861 | 624 |
11991 | 625 box_alc.height = allocation->height - req.height - 6; |
10861 | 626 /* box_alc.height = MAX(1,box_alc.height - req.height - 6); */ |
627 | |
10643 | 628 box_alc.y = box_alc.y + req.height + 6; |
629 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | |
10861 | 630 |
10643 | 631 parent_alc.height = MAX(1,req.height); |
632 combo_box_size_allocate(widget, &parent_alc); | |
633 widget->allocation = *allocation; | |
634 } | |
635 | |
636 | |
637 static gboolean | |
10861 | 638 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
639 GdkEventExpose *event) | |
10643 | 640 { |
10861 | 641 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
642 combo_box_expose_event(widget, event); | |
10643 | 643 |
10861 | 644 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
645 status_box->vbox, event); | |
646 return FALSE; | |
10643 | 647 } |
648 | |
649 static void | |
10861 | 650 gtk_gaim_status_box_forall(GtkContainer *container, |
651 gboolean include_internals, | |
652 GtkCallback callback, | |
653 gpointer callback_data) | |
10643 | 654 { |
10861 | 655 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 656 |
10861 | 657 if (include_internals) |
658 { | |
659 (* callback) (status_box->vbox, callback_data); | |
660 } | |
10643 | 661 |
10861 | 662 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 663 } |
664 | |
665 GtkWidget * | |
666 gtk_gaim_status_box_new() | |
667 { | |
668 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
669 } | |
670 | |
11499 | 671 GtkWidget * |
672 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
673 { | |
674 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
675 } | |
10643 | 676 |
677 void | |
11739 | 678 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *text, const char *sec_text) |
10643 | 679 { |
680 GtkTreeIter iter; | |
681 char *t; | |
10861 | 682 |
10643 | 683 if (sec_text) { |
684 char aa_color[8]; | |
685 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
686 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
687 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
688 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 689 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 690 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
691 } else { | |
692 t = g_strdup(text); | |
693 } | |
10861 | 694 |
10643 | 695 gtk_list_store_append(status_box->dropdown_store, &iter); |
696 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 697 TYPE_COLUMN, type, |
10643 | 698 ICON_COLUMN, pixbuf, |
10861 | 699 TEXT_COLUMN, t, |
10643 | 700 TITLE_COLUMN, text, |
10861 | 701 DESC_COLUMN, sec_text, |
11739 | 702 -1); |
11638 | 703 g_free(t); |
10643 | 704 } |
705 | |
706 void | |
11738 | 707 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
708 { | |
11756 | 709 /* Don't do anything unless GTK actually supports |
710 * gtk_combo_box_set_row_separator_func */ | |
711 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 712 GtkTreeIter iter; |
713 | |
714 gtk_list_store_append(status_box->dropdown_store, &iter); | |
715 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 716 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
717 -1); | |
11756 | 718 #endif |
11738 | 719 } |
720 | |
721 void | |
10643 | 722 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
723 { | |
11523 | 724 if (status_box->error) |
725 g_free(status_box->error); | |
11891 | 726 status_box->error = NULL; |
727 if (error != NULL) | |
728 status_box->error = g_strdup(error); | |
10643 | 729 gtk_gaim_status_box_refresh(status_box); |
730 } | |
731 | |
732 void | |
733 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
734 { | |
735 if (!status_box) | |
736 return; | |
737 status_box->connecting = connecting; | |
738 gtk_gaim_status_box_refresh(status_box); | |
739 } | |
740 | |
741 void | |
742 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
743 { | |
744 if (!status_box) | |
745 return; | |
746 if (status_box->connecting_index == 3) | |
747 status_box->connecting_index = 0; | |
10861 | 748 else |
10643 | 749 status_box->connecting_index++; |
750 gtk_gaim_status_box_refresh(status_box); | |
751 } | |
752 | |
753 void | |
754 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
755 { | |
756 if (status_box->typing_index == 3) | |
757 status_box->typing_index = 0; | |
10861 | 758 else |
10643 | 759 status_box->typing_index++; |
760 gtk_gaim_status_box_refresh(status_box); | |
761 } | |
762 | |
11993 | 763 static GaimStatusType |
764 *find_status_type_by_index(const GaimAccount *account, gint active) | |
765 { | |
766 const GList *l = gaim_account_get_status_types(account); | |
767 gint i; | |
768 | |
769 for (i = 0; l; l = l->next) { | |
770 GaimStatusType *status_type = l->data; | |
771 if (!gaim_status_type_is_user_settable(status_type)) | |
772 continue; | |
773 | |
774 if (active == i) | |
775 return status_type; | |
776 i++; | |
777 } | |
778 | |
779 return NULL; | |
780 } | |
781 | |
11654 | 782 static void |
783 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 784 { |
11739 | 785 GtkGaimStatusBoxItemType type; |
786 gchar *title; | |
10643 | 787 GtkTreeIter iter; |
11654 | 788 char *message; |
789 GaimSavedStatus *saved_status; | |
10643 | 790 |
11951 | 791 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) |
792 return; | |
11654 | 793 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
11739 | 794 TYPE_COLUMN, &type, |
11638 | 795 TITLE_COLUMN, &title, -1); |
11654 | 796 message = gtk_gaim_status_box_get_message(status_box); |
11739 | 797 |
798 /* | |
799 * If the currently selected status is "Custom..." or | |
11954 | 800 * "Saved..." then do nothing. Custom statuses are |
801 * activated elsewhere, and we update the status_box | |
802 * accordingly by monitoring the preference | |
803 * "/core/status/current" and then calling | |
804 * update_to_reflect_current_status() | |
11739 | 805 */ |
806 if ((type < 0) || (type >= GAIM_STATUS_NUM_PRIMITIVES)) | |
807 return; | |
11654 | 808 |
809 /* TODO: Should save the previous status as a transient status? */ | |
810 | |
11981 | 811 if (status_box->account) { |
812 gint active; | |
813 GaimStatusType *status_type; | |
814 | |
815 g_object_get(G_OBJECT(status_box), "active", &active, NULL); | |
11654 | 816 |
11993 | 817 status_type = find_status_type_by_index(status_box->account, active); |
11981 | 818 if (message) |
819 gaim_account_set_status(status_box->account, gaim_status_type_get_id(status_type), | |
820 TRUE, "message", message, NULL); | |
821 else | |
822 gaim_account_set_status(status_box->account, gaim_status_type_get_id(status_type), | |
823 TRUE, NULL); | |
824 | |
825 } else { | |
826 /* Save the newly selected status to prefs.xml and status.xml */ | |
827 /* TODO: This should be saved as transient. */ | |
828 saved_status = gaim_savedstatus_find(_("Default")); | |
829 if (saved_status == NULL) | |
830 saved_status = gaim_savedstatus_new(_("Default"), type); | |
831 gaim_savedstatus_set_type(saved_status, type); | |
832 gaim_savedstatus_set_message(saved_status, message); | |
833 gaim_prefs_set_string("/core/status/current", _("Default")); | |
834 | |
835 /* Set the status for each account */ | |
836 gaim_savedstatus_activate(saved_status); | |
837 } | |
11627 | 838 |
11638 | 839 g_free(title); |
11654 | 840 g_free(message); |
841 } | |
842 | |
843 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
844 { | |
845 activate_currently_selected_status(status_box); | |
846 | |
847 g_source_remove(status_box->typing); | |
848 status_box->typing = 0; | |
849 gtk_gaim_status_box_refresh(status_box); | |
10643 | 850 } |
851 | |
852 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
853 { | |
11400 | 854 GtkGaimStatusBox *status_box; |
10643 | 855 GtkTreeIter iter; |
11739 | 856 GtkGaimStatusBoxItemType type; |
10643 | 857 char *text, *sec_text; |
858 GdkPixbuf *pixbuf; | |
11960 | 859 GList *accounts = NULL, *node; |
10643 | 860 |
11400 | 861 status_box = GTK_GAIM_STATUS_BOX(box); |
862 | |
10643 | 863 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
11739 | 864 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
865 TYPE_COLUMN, &type, | |
866 TITLE_COLUMN, &text, | |
10861 | 867 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
11739 | 868 -1); |
10643 | 869 if (status_box->title) |
870 g_free(status_box->title); | |
11638 | 871 status_box->title = text; |
10643 | 872 if (status_box->desc && sec_text) |
11638 | 873 g_free(status_box->desc); |
874 status_box->desc = sec_text; | |
10643 | 875 if (status_box->pixbuf) |
876 g_object_unref(status_box->pixbuf); | |
877 status_box->pixbuf = pixbuf; | |
11638 | 878 if (status_box->typing) |
879 g_source_remove(status_box->typing); | |
880 status_box->typing = 0; | |
10861 | 881 |
11951 | 882 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11729 | 883 { |
11951 | 884 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
885 { | |
886 gaim_gtk_status_editor_show(NULL); | |
887 update_to_reflect_current_status(status_box); | |
888 return; | |
889 } | |
11729 | 890 |
11951 | 891 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
892 { | |
893 gaim_gtk_status_window_show(); | |
894 update_to_reflect_current_status(status_box); | |
895 return; | |
896 } | |
11729 | 897 } |
898 | |
11654 | 899 /* |
11755 | 900 * Show the message box whenever 'type' allows for a |
11960 | 901 * message attribute on any protocol that is enabled, |
902 * or our protocol, if we have account set | |
11654 | 903 */ |
11960 | 904 if (status_box->account) |
905 accounts = g_list_prepend(accounts, status_box->account); | |
906 else | |
907 accounts = gaim_accounts_get_all_active(); | |
11755 | 908 status_box->imhtml_visible = FALSE; |
909 for (node = accounts; node != NULL; node = node->next) | |
910 { | |
911 GaimAccount *account; | |
912 GaimStatusType *status_type; | |
913 | |
914 account = node->data; | |
915 status_type = gaim_account_get_status_type_with_primitive(account, type); | |
916 if ((status_type != NULL) && | |
917 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
918 { | |
919 status_box->imhtml_visible = TRUE; | |
920 break; | |
921 } | |
922 } | |
923 g_list_free(accounts); | |
11654 | 924 |
925 if (status_box->imhtml_visible) | |
926 { | |
10643 | 927 gtk_widget_show_all(status_box->vbox); |
11951 | 928 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
929 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
10643 | 930 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); |
931 gtk_widget_grab_focus(status_box->imhtml); | |
11654 | 932 } |
933 else | |
934 { | |
10643 | 935 gtk_widget_hide_all(status_box->vbox); |
11951 | 936 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11981 | 937 activate_currently_selected_status(status_box); /* This is where we actually set the status */ |
10643 | 938 } |
939 gtk_gaim_status_box_refresh(status_box); | |
940 } | |
941 | |
942 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
943 { | |
944 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
11951 | 945 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(box))) |
946 { | |
947 if (box->typing) { | |
948 gtk_gaim_status_box_pulse_typing(box); | |
949 g_source_remove(box->typing); | |
950 } | |
951 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); | |
10861 | 952 } |
10643 | 953 gtk_gaim_status_box_refresh(box); |
954 } | |
10649 | 955 |
11739 | 956 GtkGaimStatusBoxItemType gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
10649 | 957 { |
958 GtkTreeIter iter; | |
11739 | 959 GtkGaimStatusBoxItemType type; |
10649 | 960 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
10861 | 961 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 962 TYPE_COLUMN, &type, -1); |
963 return type; | |
964 } | |
965 | |
11638 | 966 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 967 { |
968 if (status_box->imhtml_visible) | |
969 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
970 else | |
971 return NULL; | |
972 } |