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