Mercurial > pidgin
annotate src/gtkstatusbox.c @ 11850:0d793b594a23
[gaim-migrate @ 14141]
patch from Richard Stellingwerff to fix my CVS crash. I think I might put him up for sainthood.
(I could have sworn that I tried this, and it didn't work before, but it works now)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 27 Oct 2005 14:40:48 +0000 |
parents | 86cdfd6b32a6 |
children | 678ef9ad7a0d |
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; |
10643 | 181 |
182 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
183 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
184 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
185 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
186 style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
187 |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
188 title = status_box->title; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
189 if (!title) |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
190 title = ""; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
191 |
10643 | 192 if (status_box->error) { |
11499 | 193 text = g_strdup_printf("%s\n<span size=\"smaller\" weight=\"bold\" color=\"red\">%s</span>", |
10861 | 194 title, status_box->error); |
10643 | 195 } else if (status_box->typing) { |
10861 | 196 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
197 title, aa_color, _("Typing")); | |
10643 | 198 } else if (status_box->connecting) { |
10861 | 199 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
200 title, aa_color, _("Connecting")); | |
201 } else if (status_box->desc) { | |
202 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", | |
203 title, aa_color, status_box->desc); | |
10643 | 204 } else { |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
205 text = g_strdup_printf("%s", title); |
10643 | 206 } |
10861 | 207 |
11523 | 208 if (status_box->connecting) |
209 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; | |
210 else if (status_box->error) | |
10643 | 211 pixbuf = status_box->error_pixbuf; |
212 else if (status_box->typing) | |
213 pixbuf = status_box->typing_pixbufs[status_box->typing_index]; | |
214 else | |
215 pixbuf = status_box->pixbuf; | |
216 | |
217 gtk_list_store_set(status_box->store, &(status_box->iter), | |
11755 | 218 TYPE_COLUMN, -1, /* This field is not used in this list store */ |
10643 | 219 ICON_COLUMN, pixbuf, |
10861 | 220 TEXT_COLUMN, text, |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
221 TITLE_COLUMN, title, |
10861 | 222 DESC_COLUMN, status_box->desc, |
11739 | 223 -1); |
10702 | 224 path = gtk_tree_path_new_from_string("0"); |
225 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); | |
226 gtk_tree_path_free(path); | |
10643 | 227 |
228 g_free(text); | |
229 } | |
230 | |
11732 | 231 static GdkPixbuf * |
232 load_icon(const char *basename) | |
233 { | |
234 char basename2[BUFSIZ]; | |
235 char *filename; | |
236 GdkPixbuf *pixbuf, *scale = NULL; | |
237 | |
238 if (!strcmp(basename, "available")) | |
239 basename = "online"; | |
240 else if (!strcmp(basename, "hidden")) | |
241 basename = "invisible"; | |
242 | |
243 /* | |
244 * TODO: Find a way to fallback to the GaimStatusPrimitive | |
245 * if an icon for this id does not exist. | |
246 */ | |
247 g_snprintf(basename2, sizeof(basename2), "%s.png", | |
248 basename); | |
249 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", | |
250 basename2, NULL); | |
251 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
252 g_free(filename); | |
253 | |
254 if (pixbuf != NULL) { | |
255 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
256 GDK_INTERP_BILINEAR); | |
257 | |
258 g_object_unref(G_OBJECT(pixbuf)); | |
259 } else { | |
260 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
261 "default", basename, NULL); | |
262 scale = gdk_pixbuf_new_from_file(filename, NULL); | |
263 g_free(filename); | |
264 } | |
265 | |
266 return scale; | |
267 } | |
268 | |
269 static void | |
270 gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) | |
271 { | |
11739 | 272 GaimAccount *account; |
11732 | 273 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; |
274 GtkIconSize icon_size; | |
275 const char *current_savedstatus_name; | |
276 GaimSavedStatus *saved_status; | |
277 | |
278 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
279 | |
280 gtk_list_store_clear(status_box->dropdown_store); | |
281 | |
11739 | 282 account = GTK_GAIM_STATUS_BOX(status_box)->account; |
283 if (account == NULL) | |
284 { | |
11756 | 285 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_ONLINE, |
11732 | 286 icon_size, "GtkGaimStatusBox"); |
11756 | 287 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_AWAY, |
11732 | 288 icon_size, "GtkGaimStatusBox"); |
11756 | 289 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
11732 | 290 icon_size, "GtkGaimStatusBox"); |
11756 | 291 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_INVISIBLE, |
11732 | 292 icon_size, "GtkGaimStatusBox"); |
293 /* hacks */ | |
11739 | 294 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AVAILABLE, pixbuf, _("Available"), NULL); |
295 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AWAY, pixbuf2, _("Away"), NULL); | |
296 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_HIDDEN, pixbuf4, _("Invisible"), NULL); | |
297 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_OFFLINE, pixbuf3, _("Offline"), NULL); | |
11738 | 298 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box)); |
11739 | 299 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("Custom..."), NULL); |
300 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL); | |
11732 | 301 |
302 current_savedstatus_name = gaim_prefs_get_string("/core/status/current"); | |
303 saved_status = gaim_savedstatus_find(current_savedstatus_name); | |
304 if (saved_status == NULL) | |
305 { | |
306 /* Default to "available" */ | |
307 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
308 } | |
309 else | |
310 { | |
311 GaimStatusPrimitive primitive; | |
312 const char *message; | |
313 | |
314 primitive = gaim_savedstatus_get_type(saved_status); | |
315 if (gaim_savedstatus_has_substatuses(saved_status) || | |
316 ((primitive != GAIM_STATUS_AVAILABLE) && | |
317 (primitive != GAIM_STATUS_OFFLINE) && | |
318 (primitive != GAIM_STATUS_AWAY) && | |
319 (primitive != GAIM_STATUS_HIDDEN))) | |
320 { | |
321 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 4); | |
322 } | |
323 else | |
324 { | |
325 if (primitive == GAIM_STATUS_AVAILABLE) | |
326 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
327 if (primitive == GAIM_STATUS_OFFLINE) | |
328 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3); | |
329 else if (primitive == GAIM_STATUS_AWAY) | |
330 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1); | |
331 else if (primitive == GAIM_STATUS_HIDDEN) | |
332 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2); | |
333 } | |
334 | |
335 message = gaim_savedstatus_get_message(saved_status); | |
336 if (message != NULL) | |
337 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); | |
338 } | |
339 | |
340 | |
341 } else { | |
342 const GList *l; | |
11739 | 343 |
344 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
345 { | |
11732 | 346 GaimStatusType *status_type = (GaimStatusType *)l->data; |
347 | |
348 if (!gaim_status_type_is_user_settable(status_type)) | |
349 continue; | |
350 | |
11739 | 351 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), |
352 gaim_status_type_get_primitive(status_type), | |
353 load_icon(gaim_status_type_get_id(status_type)), | |
354 gaim_status_type_get_name(status_type), | |
355 NULL); | |
11732 | 356 } |
357 } | |
358 | |
359 } | |
360 | |
11753 | 361 #if GTK_CHECK_VERSION(2,6,0) |
11738 | 362 static gboolean |
363 dropdown_store_row_separator_func(GtkTreeModel *model, | |
364 GtkTreeIter *iter, gpointer data) | |
365 { | |
11739 | 366 GtkGaimStatusBoxItemType type; |
11738 | 367 GdkPixbuf *pixbuf; |
11739 | 368 gchar *text, *title, *description; |
11738 | 369 |
370 gtk_tree_model_get(model, iter, | |
11739 | 371 TYPE_COLUMN, &type, |
11738 | 372 ICON_COLUMN, &pixbuf, |
373 TEXT_COLUMN, &text, | |
374 TITLE_COLUMN, &title, | |
375 DESC_COLUMN, &description, | |
376 -1); | |
377 | |
11739 | 378 if (type == GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR) |
11738 | 379 return TRUE; |
380 | |
381 return FALSE; | |
382 } | |
11753 | 383 #endif |
11738 | 384 |
10643 | 385 static void |
386 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) | |
387 { | |
11400 | 388 GtkCellRenderer *text_rend; |
389 GtkCellRenderer *icon_rend; | |
10643 | 390 GtkTextBuffer *buffer; |
11732 | 391 GtkTreePath *path; |
11400 | 392 GtkIconSize icon_size; |
393 | |
394 text_rend = gtk_cell_renderer_text_new(); | |
395 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
396 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
10643 | 397 |
398 status_box->imhtml_visible = FALSE; | |
399 status_box->connecting = FALSE; | |
400 status_box->typing = FALSE; | |
401 status_box->title = NULL; | |
10861 | 402 status_box->pixbuf = NULL; |
10643 | 403 status_box->cell_view = gtk_cell_view_new(); |
404 gtk_widget_show (status_box->cell_view); | |
10861 | 405 |
11739 | 406 status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
407 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 | 408 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
409 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
410 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
411 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
412 gtk_gaim_status_box_refresh(status_box); | |
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
413 path = gtk_tree_path_new_from_string("0"); |
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
414 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
|
415 gtk_tree_path_free(path); |
10643 | 416 gtk_container_add(GTK_CONTAINER(status_box), status_box->cell_view); |
10861 | 417 |
10643 | 418 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
419 status_box->text_rend = gtk_cell_renderer_text_new(); | |
420 | |
421 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
10861 | 422 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 423 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
424 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
425 | |
426 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
11499 | 427 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 428 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
429 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
430 | |
431 status_box->vbox = gtk_vbox_new(0, FALSE); | |
432 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
433 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
434 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
11562 | 435 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 436 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
437 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
438 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
439 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
440 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
441 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
442 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
11654 | 443 |
11850 | 444 |
445 #if GTK_CHECK_VERSION(2,6,0) | |
446 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); | |
447 #endif | |
448 | |
11756 | 449 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
450 icon_size, "GtkGaimStatusBox"); | |
451 status_box->connecting_index = 0; | |
452 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT0, | |
453 icon_size, "GtkGaimStatusBox"); | |
454 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT1, | |
455 icon_size, "GtkGaimStatusBox"); | |
456 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT2, | |
457 icon_size, "GtkGaimStatusBox"); | |
458 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT3, | |
459 icon_size, "GtkGaimStatusBox"); | |
460 | |
461 status_box->typing_index = 0; | |
462 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING0, | |
463 icon_size, "GtkGaimStatusBox"); | |
464 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING1, | |
465 icon_size, "GtkGaimStatusBox"); | |
466 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING2, | |
467 icon_size, "GtkGaimStatusBox"); | |
468 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING3, | |
469 icon_size, "GtkGaimStatusBox"); | |
470 | |
11732 | 471 gtk_gaim_status_box_regenerate(status_box); |
10643 | 472 } |
473 | |
474 | |
475 static void | |
10861 | 476 gtk_gaim_status_box_size_request(GtkWidget *widget, |
477 GtkRequisition *requisition) | |
10643 | 478 { |
479 GtkRequisition box_req; | |
480 combo_box_size_request(widget, requisition); | |
10861 | 481 |
10643 | 482 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
483 if (box_req.height > 1) | |
484 requisition->height = requisition->height + box_req.height + 6; | |
10861 | 485 |
10643 | 486 requisition->width = 1; |
487 | |
488 } | |
489 | |
490 static void | |
10861 | 491 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
492 GtkAllocation *allocation) | |
10643 | 493 { |
494 GtkRequisition req = {0,0}; | |
11400 | 495 GtkAllocation parent_alc, box_alc; |
496 | |
497 parent_alc = *allocation; | |
498 box_alc = *allocation; | |
10643 | 499 combo_box_size_request(widget, &req); |
10861 | 500 |
10643 | 501 /* EVIL XXX */ |
10861 | 502 box_alc.height = 80; |
503 /* box_alc.height = MAX(1,box_alc.height - req.height - 6); */ | |
504 | |
10643 | 505 box_alc.y = box_alc.y + req.height + 6; |
506 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | |
10861 | 507 |
10643 | 508 parent_alc.height = MAX(1,req.height); |
509 combo_box_size_allocate(widget, &parent_alc); | |
510 widget->allocation = *allocation; | |
511 } | |
512 | |
513 | |
514 static gboolean | |
10861 | 515 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
516 GdkEventExpose *event) | |
10643 | 517 { |
10861 | 518 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
519 combo_box_expose_event(widget, event); | |
10643 | 520 |
10861 | 521 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
522 status_box->vbox, event); | |
523 return FALSE; | |
10643 | 524 } |
525 | |
526 static void | |
10861 | 527 gtk_gaim_status_box_forall(GtkContainer *container, |
528 gboolean include_internals, | |
529 GtkCallback callback, | |
530 gpointer callback_data) | |
10643 | 531 { |
10861 | 532 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 533 |
10861 | 534 if (include_internals) |
535 { | |
536 (* callback) (status_box->vbox, callback_data); | |
537 } | |
10643 | 538 |
10861 | 539 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 540 } |
541 | |
542 GtkWidget * | |
543 gtk_gaim_status_box_new() | |
544 { | |
545 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
546 } | |
547 | |
11499 | 548 GtkWidget * |
549 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
550 { | |
551 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
552 } | |
10643 | 553 |
554 void | |
11739 | 555 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *text, const char *sec_text) |
10643 | 556 { |
557 GtkTreeIter iter; | |
558 char *t; | |
10861 | 559 |
10643 | 560 if (sec_text) { |
561 char aa_color[8]; | |
562 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
563 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
564 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
565 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 566 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 567 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
568 } else { | |
569 t = g_strdup(text); | |
570 } | |
10861 | 571 |
10643 | 572 gtk_list_store_append(status_box->dropdown_store, &iter); |
573 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 574 TYPE_COLUMN, type, |
10643 | 575 ICON_COLUMN, pixbuf, |
10861 | 576 TEXT_COLUMN, t, |
10643 | 577 TITLE_COLUMN, text, |
10861 | 578 DESC_COLUMN, sec_text, |
11739 | 579 -1); |
11638 | 580 g_free(t); |
10643 | 581 } |
582 | |
583 void | |
11738 | 584 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
585 { | |
11756 | 586 /* Don't do anything unless GTK actually supports |
587 * gtk_combo_box_set_row_separator_func */ | |
588 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 589 GtkTreeIter iter; |
590 | |
591 gtk_list_store_append(status_box->dropdown_store, &iter); | |
592 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 593 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
594 -1); | |
11756 | 595 #endif |
11738 | 596 } |
597 | |
598 void | |
10643 | 599 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
600 { | |
11523 | 601 if (status_box->error) |
602 g_free(status_box->error); | |
10643 | 603 status_box->error = g_strdup(error); |
604 gtk_gaim_status_box_refresh(status_box); | |
605 } | |
606 | |
607 void | |
608 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
609 { | |
610 if (!status_box) | |
611 return; | |
612 status_box->connecting = connecting; | |
613 gtk_gaim_status_box_refresh(status_box); | |
614 } | |
615 | |
616 void | |
617 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
618 { | |
619 if (!status_box) | |
620 return; | |
621 if (status_box->connecting_index == 3) | |
622 status_box->connecting_index = 0; | |
10861 | 623 else |
10643 | 624 status_box->connecting_index++; |
625 gtk_gaim_status_box_refresh(status_box); | |
626 } | |
627 | |
628 void | |
629 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
630 { | |
631 if (status_box->typing_index == 3) | |
632 status_box->typing_index = 0; | |
10861 | 633 else |
10643 | 634 status_box->typing_index++; |
635 gtk_gaim_status_box_refresh(status_box); | |
636 } | |
637 | |
11654 | 638 static void |
639 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 640 { |
11739 | 641 GtkGaimStatusBoxItemType type; |
642 gchar *title; | |
10643 | 643 GtkTreeIter iter; |
11654 | 644 char *message; |
645 GaimSavedStatus *saved_status; | |
10643 | 646 |
11654 | 647 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
648 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, | |
11739 | 649 TYPE_COLUMN, &type, |
11638 | 650 TITLE_COLUMN, &title, -1); |
11654 | 651 message = gtk_gaim_status_box_get_message(status_box); |
11739 | 652 |
653 /* | |
654 * If the currently selected status is "Custom..." or | |
655 * "Saved..." then do nothing. | |
656 */ | |
657 if ((type < 0) || (type >= GAIM_STATUS_NUM_PRIMITIVES)) | |
658 return; | |
11654 | 659 |
660 /* TODO: Should save the previous status as a transient status? */ | |
661 | |
662 /* Save the newly selected status to prefs.xml and status.xml */ | |
663 saved_status = gaim_savedstatus_find(_("Default")); | |
664 if (saved_status == NULL) | |
11739 | 665 saved_status = gaim_savedstatus_new(_("Default"), type); |
666 gaim_savedstatus_set_type(saved_status, type); | |
11654 | 667 gaim_savedstatus_set_message(saved_status, message); |
668 gaim_prefs_set_string("/core/status/current", _("Default")); | |
669 | |
670 /* Set the status for each account */ | |
11806 | 671 gaim_savedstatus_activate(saved_status); |
11627 | 672 |
11638 | 673 g_free(title); |
11654 | 674 g_free(message); |
675 } | |
676 | |
677 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
678 { | |
679 activate_currently_selected_status(status_box); | |
680 | |
681 g_source_remove(status_box->typing); | |
682 status_box->typing = 0; | |
683 gtk_gaim_status_box_refresh(status_box); | |
10643 | 684 } |
685 | |
686 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
687 { | |
11400 | 688 GtkGaimStatusBox *status_box; |
10643 | 689 GtkTreeIter iter; |
11739 | 690 GtkGaimStatusBoxItemType type; |
10643 | 691 char *text, *sec_text; |
692 GdkPixbuf *pixbuf; | |
11755 | 693 GList *accounts, *node; |
10643 | 694 |
11400 | 695 status_box = GTK_GAIM_STATUS_BOX(box); |
696 | |
10643 | 697 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
11739 | 698 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
699 TYPE_COLUMN, &type, | |
700 TITLE_COLUMN, &text, | |
10861 | 701 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
11739 | 702 -1); |
10643 | 703 if (status_box->title) |
704 g_free(status_box->title); | |
11638 | 705 status_box->title = text; |
10643 | 706 if (status_box->desc && sec_text) |
11638 | 707 g_free(status_box->desc); |
708 status_box->desc = sec_text; | |
10643 | 709 if (status_box->pixbuf) |
710 g_object_unref(status_box->pixbuf); | |
711 status_box->pixbuf = pixbuf; | |
11638 | 712 if (status_box->typing) |
713 g_source_remove(status_box->typing); | |
714 status_box->typing = 0; | |
10861 | 715 |
11739 | 716 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
11729 | 717 { |
718 gaim_gtk_status_editor_show(NULL); | |
719 return; | |
720 } | |
721 | |
11739 | 722 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
11729 | 723 { |
724 gaim_gtk_status_window_show(); | |
725 return; | |
726 } | |
727 | |
11654 | 728 /* |
11755 | 729 * Show the message box whenever 'type' allows for a |
730 * message attribute on any protocol that is enabled. | |
11654 | 731 */ |
11755 | 732 accounts = gaim_accounts_get_all_active(); |
733 status_box->imhtml_visible = FALSE; | |
734 for (node = accounts; node != NULL; node = node->next) | |
735 { | |
736 GaimAccount *account; | |
737 GaimStatusType *status_type; | |
738 | |
739 account = node->data; | |
740 status_type = gaim_account_get_status_type_with_primitive(account, type); | |
741 if ((status_type != NULL) && | |
742 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
743 { | |
744 status_box->imhtml_visible = TRUE; | |
745 break; | |
746 } | |
747 } | |
748 g_list_free(accounts); | |
11654 | 749 |
750 if (status_box->imhtml_visible) | |
751 { | |
10643 | 752 gtk_widget_show_all(status_box->vbox); |
753 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
754 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
755 gtk_widget_grab_focus(status_box->imhtml); | |
11654 | 756 } |
757 else | |
758 { | |
10643 | 759 gtk_widget_hide_all(status_box->vbox); |
11654 | 760 activate_currently_selected_status(status_box); |
10643 | 761 } |
762 gtk_gaim_status_box_refresh(status_box); | |
763 } | |
764 | |
765 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
766 { | |
767 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
768 if (box->typing) { | |
769 gtk_gaim_status_box_pulse_typing(box); | |
770 g_source_remove(box->typing); | |
10861 | 771 } |
10643 | 772 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); |
773 gtk_gaim_status_box_refresh(box); | |
774 } | |
10649 | 775 |
11739 | 776 GtkGaimStatusBoxItemType gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
10649 | 777 { |
778 GtkTreeIter iter; | |
11739 | 779 GtkGaimStatusBoxItemType type; |
10649 | 780 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
10861 | 781 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 782 TYPE_COLUMN, &type, -1); |
783 return type; | |
784 } | |
785 | |
11638 | 786 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 787 { |
788 if (status_box->imhtml_visible) | |
789 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
790 else | |
791 return NULL; | |
792 } |