Mercurial > pidgin
annotate src/gtkstatusbox.c @ 12036:4fc3ea5a362d
[gaim-migrate @ 14329]
oops
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Thu, 10 Nov 2005 15:24:28 +0000 |
parents | 191cbb614925 |
children | f7d2f637ff03 |
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; | |
11997 | 288 const char *proto_name = NULL, *type_name; |
11983 | 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); | |
11997 | 297 } else { |
298 return NULL; | |
11983 | 299 } |
300 | |
11732 | 301 g_snprintf(basename2, sizeof(basename2), "%s.png", |
11983 | 302 proto_name); |
303 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", | |
11732 | 304 basename2, NULL); |
305 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
306 g_free(filename); | |
307 | |
308 if (pixbuf != NULL) { | |
11983 | 309 scale = gdk_pixbuf_scale_simple(pixbuf, 32, 32, |
11732 | 310 GDK_INTERP_BILINEAR); |
311 g_object_unref(G_OBJECT(pixbuf)); | |
312 } | |
313 | |
11983 | 314 |
315 /* TODO: let the prpl pick the emblem on a per status bases, and only | |
316 * use the primitive as a fallback */ | |
317 type_name = gaim_primitive_get_id_from_type(gaim_status_type_get_primitive(status_type)); | |
318 if (!strcmp(type_name, "hidden")) | |
319 type_name = "invisible"; | |
320 if (!strcmp(type_name, "unavailable")) | |
321 type_name = "na"; | |
322 g_snprintf(basename2, sizeof(basename2), "%s.png", | |
323 type_name); | |
324 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", | |
325 basename2, NULL); | |
326 emblem = gdk_pixbuf_new_from_file(filename, NULL); | |
327 g_free(filename); | |
328 | |
329 if (emblem) { | |
330 gdk_pixbuf_composite(emblem, | |
331 scale, 32-15, 32-15, | |
332 15, 15, | |
333 32-15, 32-15, | |
334 1, 1, | |
335 GDK_INTERP_BILINEAR, | |
336 255); | |
337 | |
338 g_object_unref(emblem); | |
339 } | |
11732 | 340 return scale; |
341 } | |
342 | |
11870 | 343 /** |
344 * This updates the GtkTreeView so that it correctly shows the state | |
345 * we are currently using. It is used when the current state is | |
346 * updated from somewhere other than the GtkStatusBox (from a plugin, | |
347 * or when signing on with the "-n" option, for example). It is | |
348 * also used when the user selects the "Custom..." option. | |
349 * | |
350 * Maybe we could accomplish this by triggering off the mouse and | |
351 * keyboard signals instead of the changed signal? | |
352 */ | |
353 static void | |
354 update_to_reflect_current_status(GtkGaimStatusBox *status_box) | |
355 { | |
356 const char *current_savedstatus_name; | |
357 GaimSavedStatus *saved_status; | |
358 | |
11983 | 359 /* this function is inappropriate for ones with accounts */ |
360 if (status_box->account) | |
361 return; | |
362 | |
11870 | 363 current_savedstatus_name = gaim_prefs_get_string("/core/status/current"); |
364 saved_status = gaim_savedstatus_find(current_savedstatus_name); | |
11951 | 365 |
366 /* | |
367 * Suppress the "changed" signal because the status | |
368 * was changed programmatically. | |
369 */ | |
370 gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE); | |
371 | |
11870 | 372 if (saved_status == NULL) |
373 { | |
374 /* Default to "available" */ | |
375 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
376 } | |
377 else | |
378 { | |
379 GaimStatusPrimitive primitive; | |
380 const char *message; | |
381 | |
382 primitive = gaim_savedstatus_get_type(saved_status); | |
383 if (gaim_savedstatus_has_substatuses(saved_status) || | |
384 ((primitive != GAIM_STATUS_AVAILABLE) && | |
385 (primitive != GAIM_STATUS_OFFLINE) && | |
386 (primitive != GAIM_STATUS_AWAY) && | |
387 (primitive != GAIM_STATUS_HIDDEN))) | |
388 { | |
389 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 4); | |
390 } | |
391 else | |
392 { | |
393 if (primitive == GAIM_STATUS_AVAILABLE) | |
394 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
395 if (primitive == GAIM_STATUS_OFFLINE) | |
396 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3); | |
397 else if (primitive == GAIM_STATUS_AWAY) | |
398 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1); | |
399 else if (primitive == GAIM_STATUS_HIDDEN) | |
400 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2); | |
401 } | |
402 | |
403 message = gaim_savedstatus_get_message(saved_status); | |
11954 | 404 if (message == NULL) |
11951 | 405 { |
11954 | 406 status_box->imhtml_visible = FALSE; |
407 } | |
408 else | |
409 { | |
410 status_box->imhtml_visible = TRUE; | |
411 | |
11951 | 412 /* |
413 * Suppress the "changed" signal because the status | |
414 * was changed programmatically. | |
415 */ | |
416 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), FALSE); | |
11954 | 417 |
418 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
11870 | 419 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); |
11951 | 420 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), TRUE); |
421 } | |
11870 | 422 } |
11951 | 423 |
424 /* Stop suppressing the "changed" signal. */ | |
425 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); | |
11870 | 426 } |
427 | |
11732 | 428 static void |
429 gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) | |
430 { | |
11739 | 431 GaimAccount *account; |
11732 | 432 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; |
433 GtkIconSize icon_size; | |
434 | |
435 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
436 | |
437 gtk_list_store_clear(status_box->dropdown_store); | |
438 | |
11739 | 439 account = GTK_GAIM_STATUS_BOX(status_box)->account; |
440 if (account == NULL) | |
441 { | |
11756 | 442 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_ONLINE, |
11732 | 443 icon_size, "GtkGaimStatusBox"); |
11756 | 444 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_AWAY, |
11732 | 445 icon_size, "GtkGaimStatusBox"); |
11756 | 446 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
11732 | 447 icon_size, "GtkGaimStatusBox"); |
11756 | 448 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_INVISIBLE, |
11732 | 449 icon_size, "GtkGaimStatusBox"); |
450 /* hacks */ | |
11739 | 451 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AVAILABLE, pixbuf, _("Available"), NULL); |
452 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AWAY, pixbuf2, _("Away"), NULL); | |
453 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_HIDDEN, pixbuf4, _("Invisible"), NULL); | |
454 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_OFFLINE, pixbuf3, _("Offline"), NULL); | |
11738 | 455 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box)); |
11739 | 456 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("Custom..."), NULL); |
457 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL); | |
11732 | 458 |
11870 | 459 update_to_reflect_current_status(status_box); |
11732 | 460 |
461 } else { | |
462 const GList *l; | |
11739 | 463 |
464 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
465 { | |
11732 | 466 GaimStatusType *status_type = (GaimStatusType *)l->data; |
467 | |
468 if (!gaim_status_type_is_user_settable(status_type)) | |
469 continue; | |
470 | |
11739 | 471 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), |
472 gaim_status_type_get_primitive(status_type), | |
11983 | 473 load_icon(account, status_type), |
11739 | 474 gaim_status_type_get_name(status_type), |
475 NULL); | |
11732 | 476 } |
11967 | 477 update_to_reflect_account_status(status_box, account, gaim_account_get_active_status(account)); |
11732 | 478 } |
479 | |
480 } | |
481 | |
11753 | 482 #if GTK_CHECK_VERSION(2,6,0) |
11738 | 483 static gboolean |
484 dropdown_store_row_separator_func(GtkTreeModel *model, | |
485 GtkTreeIter *iter, gpointer data) | |
486 { | |
11739 | 487 GtkGaimStatusBoxItemType type; |
11738 | 488 |
11885 | 489 gtk_tree_model_get(model, iter, TYPE_COLUMN, &type, -1); |
11738 | 490 |
11739 | 491 if (type == GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR) |
11738 | 492 return TRUE; |
493 | |
494 return FALSE; | |
495 } | |
11753 | 496 #endif |
11738 | 497 |
10643 | 498 static void |
11954 | 499 current_status_pref_changed_cb(const char *name, GaimPrefType type, |
500 gpointer val, gpointer data) | |
501 { | |
502 update_to_reflect_current_status(data); | |
503 } | |
504 | |
505 static void | |
10643 | 506 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) |
507 { | |
11400 | 508 GtkCellRenderer *text_rend; |
509 GtkCellRenderer *icon_rend; | |
10643 | 510 GtkTextBuffer *buffer; |
11732 | 511 GtkTreePath *path; |
11400 | 512 GtkIconSize icon_size; |
513 | |
514 text_rend = gtk_cell_renderer_text_new(); | |
515 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
516 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
10643 | 517 |
518 status_box->imhtml_visible = FALSE; | |
519 status_box->connecting = FALSE; | |
520 status_box->typing = FALSE; | |
521 status_box->title = NULL; | |
10861 | 522 status_box->pixbuf = NULL; |
10643 | 523 status_box->cell_view = gtk_cell_view_new(); |
524 gtk_widget_show (status_box->cell_view); | |
10861 | 525 |
11739 | 526 status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
527 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 | 528 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
529 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
530 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
531 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
532 gtk_gaim_status_box_refresh(status_box); | |
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
533 path = gtk_tree_path_new_from_string("0"); |
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
534 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
|
535 gtk_tree_path_free(path); |
10643 | 536 gtk_container_add(GTK_CONTAINER(status_box), status_box->cell_view); |
10861 | 537 |
10643 | 538 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
539 status_box->text_rend = gtk_cell_renderer_text_new(); | |
540 | |
541 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
10861 | 542 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 543 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
544 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
545 | |
546 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
11499 | 547 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 548 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
549 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
550 | |
551 status_box->vbox = gtk_vbox_new(0, FALSE); | |
552 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
553 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
554 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
11562 | 555 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 556 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
557 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
558 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
559 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
560 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
561 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
562 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
11654 | 563 |
11850 | 564 |
565 #if GTK_CHECK_VERSION(2,6,0) | |
566 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); | |
567 #endif | |
568 | |
11756 | 569 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
570 icon_size, "GtkGaimStatusBox"); | |
571 status_box->connecting_index = 0; | |
572 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT0, | |
573 icon_size, "GtkGaimStatusBox"); | |
574 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT1, | |
575 icon_size, "GtkGaimStatusBox"); | |
576 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT2, | |
577 icon_size, "GtkGaimStatusBox"); | |
578 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT3, | |
579 icon_size, "GtkGaimStatusBox"); | |
580 | |
581 status_box->typing_index = 0; | |
582 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING0, | |
583 icon_size, "GtkGaimStatusBox"); | |
584 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING1, | |
585 icon_size, "GtkGaimStatusBox"); | |
586 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING2, | |
587 icon_size, "GtkGaimStatusBox"); | |
588 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING3, | |
589 icon_size, "GtkGaimStatusBox"); | |
590 | |
11732 | 591 gtk_gaim_status_box_regenerate(status_box); |
11954 | 592 |
593 /* Monitor changes in the "/core/status/current" preference */ | |
594 gaim_prefs_connect_callback(status_box, "/core/status/current", | |
595 current_status_pref_changed_cb, status_box); | |
596 | |
597 /* TODO: Need to override the destroy method for this object and put the following line in it */ | |
598 /* gaim_prefs_disconnect_by_handle(status_box); */ | |
10643 | 599 } |
600 | |
601 static void | |
10861 | 602 gtk_gaim_status_box_size_request(GtkWidget *widget, |
603 GtkRequisition *requisition) | |
10643 | 604 { |
605 GtkRequisition box_req; | |
606 combo_box_size_request(widget, requisition); | |
10861 | 607 |
10643 | 608 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
609 if (box_req.height > 1) | |
610 requisition->height = requisition->height + box_req.height + 6; | |
10861 | 611 |
10643 | 612 requisition->width = 1; |
613 | |
614 } | |
615 | |
616 static void | |
10861 | 617 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
618 GtkAllocation *allocation) | |
10643 | 619 { |
620 GtkRequisition req = {0,0}; | |
11400 | 621 GtkAllocation parent_alc, box_alc; |
622 | |
623 parent_alc = *allocation; | |
624 box_alc = *allocation; | |
10643 | 625 combo_box_size_request(widget, &req); |
10861 | 626 |
11998 | 627 box_alc.height = MAX(1, ((allocation->height) - (req.height) - (6))); |
10861 | 628 |
10643 | 629 box_alc.y = box_alc.y + req.height + 6; |
630 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | |
10861 | 631 |
10643 | 632 parent_alc.height = MAX(1,req.height); |
633 combo_box_size_allocate(widget, &parent_alc); | |
634 widget->allocation = *allocation; | |
635 } | |
636 | |
637 | |
638 static gboolean | |
10861 | 639 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
640 GdkEventExpose *event) | |
10643 | 641 { |
10861 | 642 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
643 combo_box_expose_event(widget, event); | |
10643 | 644 |
10861 | 645 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
646 status_box->vbox, event); | |
647 return FALSE; | |
10643 | 648 } |
649 | |
650 static void | |
10861 | 651 gtk_gaim_status_box_forall(GtkContainer *container, |
652 gboolean include_internals, | |
653 GtkCallback callback, | |
654 gpointer callback_data) | |
10643 | 655 { |
10861 | 656 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 657 |
10861 | 658 if (include_internals) |
659 { | |
660 (* callback) (status_box->vbox, callback_data); | |
661 } | |
10643 | 662 |
10861 | 663 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 664 } |
665 | |
666 GtkWidget * | |
667 gtk_gaim_status_box_new() | |
668 { | |
669 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
670 } | |
671 | |
11499 | 672 GtkWidget * |
673 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
674 { | |
675 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
676 } | |
10643 | 677 |
678 void | |
11739 | 679 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *text, const char *sec_text) |
10643 | 680 { |
681 GtkTreeIter iter; | |
682 char *t; | |
10861 | 683 |
10643 | 684 if (sec_text) { |
685 char aa_color[8]; | |
686 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
687 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
688 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
689 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 690 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 691 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
692 } else { | |
693 t = g_strdup(text); | |
694 } | |
10861 | 695 |
10643 | 696 gtk_list_store_append(status_box->dropdown_store, &iter); |
697 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 698 TYPE_COLUMN, type, |
10643 | 699 ICON_COLUMN, pixbuf, |
10861 | 700 TEXT_COLUMN, t, |
10643 | 701 TITLE_COLUMN, text, |
10861 | 702 DESC_COLUMN, sec_text, |
11739 | 703 -1); |
11638 | 704 g_free(t); |
10643 | 705 } |
706 | |
707 void | |
11738 | 708 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
709 { | |
11756 | 710 /* Don't do anything unless GTK actually supports |
711 * gtk_combo_box_set_row_separator_func */ | |
712 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 713 GtkTreeIter iter; |
714 | |
715 gtk_list_store_append(status_box->dropdown_store, &iter); | |
716 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 717 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
718 -1); | |
11756 | 719 #endif |
11738 | 720 } |
721 | |
722 void | |
10643 | 723 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
724 { | |
11523 | 725 if (status_box->error) |
726 g_free(status_box->error); | |
11891 | 727 status_box->error = NULL; |
728 if (error != NULL) | |
729 status_box->error = g_strdup(error); | |
10643 | 730 gtk_gaim_status_box_refresh(status_box); |
731 } | |
732 | |
733 void | |
734 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
735 { | |
736 if (!status_box) | |
737 return; | |
738 status_box->connecting = connecting; | |
739 gtk_gaim_status_box_refresh(status_box); | |
740 } | |
741 | |
742 void | |
743 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
744 { | |
745 if (!status_box) | |
746 return; | |
747 if (status_box->connecting_index == 3) | |
748 status_box->connecting_index = 0; | |
10861 | 749 else |
10643 | 750 status_box->connecting_index++; |
751 gtk_gaim_status_box_refresh(status_box); | |
752 } | |
753 | |
754 void | |
755 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
756 { | |
757 if (status_box->typing_index == 3) | |
758 status_box->typing_index = 0; | |
10861 | 759 else |
10643 | 760 status_box->typing_index++; |
761 gtk_gaim_status_box_refresh(status_box); | |
762 } | |
763 | |
11993 | 764 static GaimStatusType |
765 *find_status_type_by_index(const GaimAccount *account, gint active) | |
766 { | |
767 const GList *l = gaim_account_get_status_types(account); | |
768 gint i; | |
769 | |
770 for (i = 0; l; l = l->next) { | |
771 GaimStatusType *status_type = l->data; | |
772 if (!gaim_status_type_is_user_settable(status_type)) | |
773 continue; | |
774 | |
775 if (active == i) | |
776 return status_type; | |
777 i++; | |
778 } | |
779 | |
780 return NULL; | |
781 } | |
782 | |
11654 | 783 static void |
784 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 785 { |
11739 | 786 GtkGaimStatusBoxItemType type; |
787 gchar *title; | |
10643 | 788 GtkTreeIter iter; |
11654 | 789 char *message; |
790 GaimSavedStatus *saved_status; | |
10643 | 791 |
11951 | 792 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) |
793 return; | |
11654 | 794 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
11739 | 795 TYPE_COLUMN, &type, |
11638 | 796 TITLE_COLUMN, &title, -1); |
11654 | 797 message = gtk_gaim_status_box_get_message(status_box); |
11739 | 798 |
799 /* | |
800 * If the currently selected status is "Custom..." or | |
11954 | 801 * "Saved..." then do nothing. Custom statuses are |
802 * activated elsewhere, and we update the status_box | |
803 * accordingly by monitoring the preference | |
804 * "/core/status/current" and then calling | |
805 * update_to_reflect_current_status() | |
11739 | 806 */ |
807 if ((type < 0) || (type >= GAIM_STATUS_NUM_PRIMITIVES)) | |
808 return; | |
11654 | 809 |
810 /* TODO: Should save the previous status as a transient status? */ | |
811 | |
11981 | 812 if (status_box->account) { |
813 gint active; | |
814 GaimStatusType *status_type; | |
815 | |
816 g_object_get(G_OBJECT(status_box), "active", &active, NULL); | |
11654 | 817 |
11993 | 818 status_type = find_status_type_by_index(status_box->account, active); |
11981 | 819 if (message) |
820 gaim_account_set_status(status_box->account, gaim_status_type_get_id(status_type), | |
821 TRUE, "message", message, NULL); | |
822 else | |
823 gaim_account_set_status(status_box->account, gaim_status_type_get_id(status_type), | |
824 TRUE, NULL); | |
825 | |
826 } else { | |
827 /* Save the newly selected status to prefs.xml and status.xml */ | |
828 /* TODO: This should be saved as transient. */ | |
829 saved_status = gaim_savedstatus_find(_("Default")); | |
830 if (saved_status == NULL) | |
831 saved_status = gaim_savedstatus_new(_("Default"), type); | |
832 gaim_savedstatus_set_type(saved_status, type); | |
833 gaim_savedstatus_set_message(saved_status, message); | |
834 gaim_prefs_set_string("/core/status/current", _("Default")); | |
835 | |
836 /* Set the status for each account */ | |
837 gaim_savedstatus_activate(saved_status); | |
838 } | |
11627 | 839 |
11638 | 840 g_free(title); |
11654 | 841 g_free(message); |
842 } | |
843 | |
844 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
845 { | |
846 activate_currently_selected_status(status_box); | |
847 | |
848 g_source_remove(status_box->typing); | |
849 status_box->typing = 0; | |
850 gtk_gaim_status_box_refresh(status_box); | |
10643 | 851 } |
852 | |
853 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
854 { | |
11400 | 855 GtkGaimStatusBox *status_box; |
10643 | 856 GtkTreeIter iter; |
11739 | 857 GtkGaimStatusBoxItemType type; |
10643 | 858 char *text, *sec_text; |
859 GdkPixbuf *pixbuf; | |
11960 | 860 GList *accounts = NULL, *node; |
10643 | 861 |
11400 | 862 status_box = GTK_GAIM_STATUS_BOX(box); |
863 | |
10643 | 864 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
11739 | 865 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
866 TYPE_COLUMN, &type, | |
867 TITLE_COLUMN, &text, | |
10861 | 868 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
11739 | 869 -1); |
10643 | 870 if (status_box->title) |
871 g_free(status_box->title); | |
11638 | 872 status_box->title = text; |
10643 | 873 if (status_box->desc && sec_text) |
11638 | 874 g_free(status_box->desc); |
875 status_box->desc = sec_text; | |
10643 | 876 if (status_box->pixbuf) |
877 g_object_unref(status_box->pixbuf); | |
878 status_box->pixbuf = pixbuf; | |
11638 | 879 if (status_box->typing) |
880 g_source_remove(status_box->typing); | |
881 status_box->typing = 0; | |
10861 | 882 |
11951 | 883 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11729 | 884 { |
11951 | 885 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
886 { | |
887 gaim_gtk_status_editor_show(NULL); | |
888 update_to_reflect_current_status(status_box); | |
889 return; | |
890 } | |
11729 | 891 |
11951 | 892 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
893 { | |
894 gaim_gtk_status_window_show(); | |
895 update_to_reflect_current_status(status_box); | |
896 return; | |
897 } | |
11729 | 898 } |
899 | |
11654 | 900 /* |
11755 | 901 * Show the message box whenever 'type' allows for a |
11960 | 902 * message attribute on any protocol that is enabled, |
903 * or our protocol, if we have account set | |
11654 | 904 */ |
11960 | 905 if (status_box->account) |
906 accounts = g_list_prepend(accounts, status_box->account); | |
907 else | |
908 accounts = gaim_accounts_get_all_active(); | |
11755 | 909 status_box->imhtml_visible = FALSE; |
910 for (node = accounts; node != NULL; node = node->next) | |
911 { | |
912 GaimAccount *account; | |
913 GaimStatusType *status_type; | |
914 | |
915 account = node->data; | |
916 status_type = gaim_account_get_status_type_with_primitive(account, type); | |
917 if ((status_type != NULL) && | |
918 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
919 { | |
920 status_box->imhtml_visible = TRUE; | |
921 break; | |
922 } | |
923 } | |
924 g_list_free(accounts); | |
11654 | 925 |
926 if (status_box->imhtml_visible) | |
927 { | |
10643 | 928 gtk_widget_show_all(status_box->vbox); |
11951 | 929 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
930 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
10643 | 931 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); |
932 gtk_widget_grab_focus(status_box->imhtml); | |
11654 | 933 } |
934 else | |
935 { | |
10643 | 936 gtk_widget_hide_all(status_box->vbox); |
11951 | 937 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11981 | 938 activate_currently_selected_status(status_box); /* This is where we actually set the status */ |
10643 | 939 } |
940 gtk_gaim_status_box_refresh(status_box); | |
941 } | |
942 | |
943 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
944 { | |
945 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
11951 | 946 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(box))) |
947 { | |
948 if (box->typing) { | |
949 gtk_gaim_status_box_pulse_typing(box); | |
950 g_source_remove(box->typing); | |
951 } | |
952 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); | |
10861 | 953 } |
10643 | 954 gtk_gaim_status_box_refresh(box); |
955 } | |
10649 | 956 |
11739 | 957 GtkGaimStatusBoxItemType gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
10649 | 958 { |
959 GtkTreeIter iter; | |
11739 | 960 GtkGaimStatusBoxItemType type; |
10649 | 961 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
10861 | 962 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 963 TYPE_COLUMN, &type, -1); |
964 return type; | |
965 } | |
966 | |
11638 | 967 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 968 { |
969 if (status_box->imhtml_visible) | |
970 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
971 else | |
972 return NULL; | |
973 } |