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