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