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