Mercurial > pidgin
annotate src/gtkstatusbox.c @ 11884:b1099e09eb33
[gaim-migrate @ 14175]
I *think* this will make sure we distribute the right pieces for dbus
support, but I don't currently have a sensible way of testing. Also, I
suspect we may want some of the code generation to happen at dist time
instead of build time. Something to think about.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 29 Oct 2005 02:06:36 +0000 |
parents | 678ef9ad7a0d |
children | 163104122522 |
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 GdkPixbuf *pixbuf; |
11739 | 389 gchar *text, *title, *description; |
11738 | 390 |
391 gtk_tree_model_get(model, iter, | |
11739 | 392 TYPE_COLUMN, &type, |
11738 | 393 ICON_COLUMN, &pixbuf, |
394 TEXT_COLUMN, &text, | |
395 TITLE_COLUMN, &title, | |
396 DESC_COLUMN, &description, | |
397 -1); | |
398 | |
11739 | 399 if (type == GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR) |
11738 | 400 return TRUE; |
401 | |
402 return FALSE; | |
403 } | |
11753 | 404 #endif |
11738 | 405 |
10643 | 406 static void |
407 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) | |
408 { | |
11400 | 409 GtkCellRenderer *text_rend; |
410 GtkCellRenderer *icon_rend; | |
10643 | 411 GtkTextBuffer *buffer; |
11732 | 412 GtkTreePath *path; |
11400 | 413 GtkIconSize icon_size; |
414 | |
415 text_rend = gtk_cell_renderer_text_new(); | |
416 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
417 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
10643 | 418 |
419 status_box->imhtml_visible = FALSE; | |
420 status_box->connecting = FALSE; | |
421 status_box->typing = FALSE; | |
422 status_box->title = NULL; | |
10861 | 423 status_box->pixbuf = NULL; |
10643 | 424 status_box->cell_view = gtk_cell_view_new(); |
425 gtk_widget_show (status_box->cell_view); | |
10861 | 426 |
11739 | 427 status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
428 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 | 429 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
430 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
431 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
432 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
433 gtk_gaim_status_box_refresh(status_box); | |
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
434 path = gtk_tree_path_new_from_string("0"); |
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
435 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
|
436 gtk_tree_path_free(path); |
10643 | 437 gtk_container_add(GTK_CONTAINER(status_box), status_box->cell_view); |
10861 | 438 |
10643 | 439 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
440 status_box->text_rend = gtk_cell_renderer_text_new(); | |
441 | |
442 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
10861 | 443 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 444 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
445 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
446 | |
447 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
11499 | 448 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 449 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
450 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
451 | |
452 status_box->vbox = gtk_vbox_new(0, FALSE); | |
453 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
454 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
455 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
11562 | 456 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 457 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
458 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
459 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
460 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
461 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
462 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
463 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
11654 | 464 |
11850 | 465 |
466 #if GTK_CHECK_VERSION(2,6,0) | |
467 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); | |
468 #endif | |
469 | |
11756 | 470 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
471 icon_size, "GtkGaimStatusBox"); | |
472 status_box->connecting_index = 0; | |
473 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT0, | |
474 icon_size, "GtkGaimStatusBox"); | |
475 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT1, | |
476 icon_size, "GtkGaimStatusBox"); | |
477 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT2, | |
478 icon_size, "GtkGaimStatusBox"); | |
479 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT3, | |
480 icon_size, "GtkGaimStatusBox"); | |
481 | |
482 status_box->typing_index = 0; | |
483 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING0, | |
484 icon_size, "GtkGaimStatusBox"); | |
485 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING1, | |
486 icon_size, "GtkGaimStatusBox"); | |
487 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING2, | |
488 icon_size, "GtkGaimStatusBox"); | |
489 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING3, | |
490 icon_size, "GtkGaimStatusBox"); | |
491 | |
11732 | 492 gtk_gaim_status_box_regenerate(status_box); |
10643 | 493 } |
494 | |
495 | |
496 static void | |
10861 | 497 gtk_gaim_status_box_size_request(GtkWidget *widget, |
498 GtkRequisition *requisition) | |
10643 | 499 { |
500 GtkRequisition box_req; | |
501 combo_box_size_request(widget, requisition); | |
10861 | 502 |
10643 | 503 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
504 if (box_req.height > 1) | |
505 requisition->height = requisition->height + box_req.height + 6; | |
10861 | 506 |
10643 | 507 requisition->width = 1; |
508 | |
509 } | |
510 | |
511 static void | |
10861 | 512 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
513 GtkAllocation *allocation) | |
10643 | 514 { |
515 GtkRequisition req = {0,0}; | |
11400 | 516 GtkAllocation parent_alc, box_alc; |
517 | |
518 parent_alc = *allocation; | |
519 box_alc = *allocation; | |
10643 | 520 combo_box_size_request(widget, &req); |
10861 | 521 |
10643 | 522 /* EVIL XXX */ |
10861 | 523 box_alc.height = 80; |
524 /* box_alc.height = MAX(1,box_alc.height - req.height - 6); */ | |
525 | |
10643 | 526 box_alc.y = box_alc.y + req.height + 6; |
527 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | |
10861 | 528 |
10643 | 529 parent_alc.height = MAX(1,req.height); |
530 combo_box_size_allocate(widget, &parent_alc); | |
531 widget->allocation = *allocation; | |
532 } | |
533 | |
534 | |
535 static gboolean | |
10861 | 536 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
537 GdkEventExpose *event) | |
10643 | 538 { |
10861 | 539 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
540 combo_box_expose_event(widget, event); | |
10643 | 541 |
10861 | 542 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
543 status_box->vbox, event); | |
544 return FALSE; | |
10643 | 545 } |
546 | |
547 static void | |
10861 | 548 gtk_gaim_status_box_forall(GtkContainer *container, |
549 gboolean include_internals, | |
550 GtkCallback callback, | |
551 gpointer callback_data) | |
10643 | 552 { |
10861 | 553 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 554 |
10861 | 555 if (include_internals) |
556 { | |
557 (* callback) (status_box->vbox, callback_data); | |
558 } | |
10643 | 559 |
10861 | 560 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 561 } |
562 | |
563 GtkWidget * | |
564 gtk_gaim_status_box_new() | |
565 { | |
566 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
567 } | |
568 | |
11499 | 569 GtkWidget * |
570 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
571 { | |
572 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
573 } | |
10643 | 574 |
575 void | |
11739 | 576 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *text, const char *sec_text) |
10643 | 577 { |
578 GtkTreeIter iter; | |
579 char *t; | |
10861 | 580 |
10643 | 581 if (sec_text) { |
582 char aa_color[8]; | |
583 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
584 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
585 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
586 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 587 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 588 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
589 } else { | |
590 t = g_strdup(text); | |
591 } | |
10861 | 592 |
10643 | 593 gtk_list_store_append(status_box->dropdown_store, &iter); |
594 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 595 TYPE_COLUMN, type, |
10643 | 596 ICON_COLUMN, pixbuf, |
10861 | 597 TEXT_COLUMN, t, |
10643 | 598 TITLE_COLUMN, text, |
10861 | 599 DESC_COLUMN, sec_text, |
11739 | 600 -1); |
11638 | 601 g_free(t); |
10643 | 602 } |
603 | |
604 void | |
11738 | 605 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
606 { | |
11756 | 607 /* Don't do anything unless GTK actually supports |
608 * gtk_combo_box_set_row_separator_func */ | |
609 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 610 GtkTreeIter iter; |
611 | |
612 gtk_list_store_append(status_box->dropdown_store, &iter); | |
613 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 614 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
615 -1); | |
11756 | 616 #endif |
11738 | 617 } |
618 | |
619 void | |
10643 | 620 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
621 { | |
11523 | 622 if (status_box->error) |
623 g_free(status_box->error); | |
10643 | 624 status_box->error = g_strdup(error); |
625 gtk_gaim_status_box_refresh(status_box); | |
626 } | |
627 | |
628 void | |
629 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
630 { | |
631 if (!status_box) | |
632 return; | |
633 status_box->connecting = connecting; | |
634 gtk_gaim_status_box_refresh(status_box); | |
635 } | |
636 | |
637 void | |
638 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
639 { | |
640 if (!status_box) | |
641 return; | |
642 if (status_box->connecting_index == 3) | |
643 status_box->connecting_index = 0; | |
10861 | 644 else |
10643 | 645 status_box->connecting_index++; |
646 gtk_gaim_status_box_refresh(status_box); | |
647 } | |
648 | |
649 void | |
650 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
651 { | |
652 if (status_box->typing_index == 3) | |
653 status_box->typing_index = 0; | |
10861 | 654 else |
10643 | 655 status_box->typing_index++; |
656 gtk_gaim_status_box_refresh(status_box); | |
657 } | |
658 | |
11654 | 659 static void |
660 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 661 { |
11739 | 662 GtkGaimStatusBoxItemType type; |
663 gchar *title; | |
10643 | 664 GtkTreeIter iter; |
11654 | 665 char *message; |
666 GaimSavedStatus *saved_status; | |
10643 | 667 |
11654 | 668 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
669 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, | |
11739 | 670 TYPE_COLUMN, &type, |
11638 | 671 TITLE_COLUMN, &title, -1); |
11654 | 672 message = gtk_gaim_status_box_get_message(status_box); |
11739 | 673 |
674 /* | |
675 * If the currently selected status is "Custom..." or | |
676 * "Saved..." then do nothing. | |
677 */ | |
678 if ((type < 0) || (type >= GAIM_STATUS_NUM_PRIMITIVES)) | |
679 return; | |
11654 | 680 |
681 /* TODO: Should save the previous status as a transient status? */ | |
682 | |
683 /* Save the newly selected status to prefs.xml and status.xml */ | |
684 saved_status = gaim_savedstatus_find(_("Default")); | |
685 if (saved_status == NULL) | |
11739 | 686 saved_status = gaim_savedstatus_new(_("Default"), type); |
687 gaim_savedstatus_set_type(saved_status, type); | |
11654 | 688 gaim_savedstatus_set_message(saved_status, message); |
689 gaim_prefs_set_string("/core/status/current", _("Default")); | |
690 | |
691 /* Set the status for each account */ | |
11806 | 692 gaim_savedstatus_activate(saved_status); |
11627 | 693 |
11638 | 694 g_free(title); |
11654 | 695 g_free(message); |
696 } | |
697 | |
698 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
699 { | |
700 activate_currently_selected_status(status_box); | |
701 | |
702 g_source_remove(status_box->typing); | |
703 status_box->typing = 0; | |
704 gtk_gaim_status_box_refresh(status_box); | |
10643 | 705 } |
706 | |
707 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
708 { | |
11400 | 709 GtkGaimStatusBox *status_box; |
10643 | 710 GtkTreeIter iter; |
11739 | 711 GtkGaimStatusBoxItemType type; |
10643 | 712 char *text, *sec_text; |
713 GdkPixbuf *pixbuf; | |
11755 | 714 GList *accounts, *node; |
10643 | 715 |
11400 | 716 status_box = GTK_GAIM_STATUS_BOX(box); |
717 | |
10643 | 718 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
11739 | 719 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
720 TYPE_COLUMN, &type, | |
721 TITLE_COLUMN, &text, | |
10861 | 722 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
11739 | 723 -1); |
10643 | 724 if (status_box->title) |
725 g_free(status_box->title); | |
11638 | 726 status_box->title = text; |
10643 | 727 if (status_box->desc && sec_text) |
11638 | 728 g_free(status_box->desc); |
729 status_box->desc = sec_text; | |
10643 | 730 if (status_box->pixbuf) |
731 g_object_unref(status_box->pixbuf); | |
732 status_box->pixbuf = pixbuf; | |
11638 | 733 if (status_box->typing) |
734 g_source_remove(status_box->typing); | |
735 status_box->typing = 0; | |
10861 | 736 |
11739 | 737 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
11729 | 738 { |
739 gaim_gtk_status_editor_show(NULL); | |
11870 | 740 update_to_reflect_current_status(status_box); |
11729 | 741 return; |
742 } | |
743 | |
11739 | 744 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
11729 | 745 { |
746 gaim_gtk_status_window_show(); | |
11870 | 747 update_to_reflect_current_status(status_box); |
11729 | 748 return; |
749 } | |
750 | |
11654 | 751 /* |
11755 | 752 * Show the message box whenever 'type' allows for a |
753 * message attribute on any protocol that is enabled. | |
11654 | 754 */ |
11755 | 755 accounts = gaim_accounts_get_all_active(); |
756 status_box->imhtml_visible = FALSE; | |
757 for (node = accounts; node != NULL; node = node->next) | |
758 { | |
759 GaimAccount *account; | |
760 GaimStatusType *status_type; | |
761 | |
762 account = node->data; | |
763 status_type = gaim_account_get_status_type_with_primitive(account, type); | |
764 if ((status_type != NULL) && | |
765 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
766 { | |
767 status_box->imhtml_visible = TRUE; | |
768 break; | |
769 } | |
770 } | |
771 g_list_free(accounts); | |
11654 | 772 |
773 if (status_box->imhtml_visible) | |
774 { | |
10643 | 775 gtk_widget_show_all(status_box->vbox); |
776 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
777 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
778 gtk_widget_grab_focus(status_box->imhtml); | |
11654 | 779 } |
780 else | |
781 { | |
10643 | 782 gtk_widget_hide_all(status_box->vbox); |
11654 | 783 activate_currently_selected_status(status_box); |
10643 | 784 } |
785 gtk_gaim_status_box_refresh(status_box); | |
786 } | |
787 | |
788 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
789 { | |
790 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
791 if (box->typing) { | |
792 gtk_gaim_status_box_pulse_typing(box); | |
793 g_source_remove(box->typing); | |
10861 | 794 } |
10643 | 795 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); |
796 gtk_gaim_status_box_refresh(box); | |
797 } | |
10649 | 798 |
11739 | 799 GtkGaimStatusBoxItemType gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
10649 | 800 { |
801 GtkTreeIter iter; | |
11739 | 802 GtkGaimStatusBoxItemType type; |
10649 | 803 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
10861 | 804 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 805 TYPE_COLUMN, &type, -1); |
806 return type; | |
807 } | |
808 | |
11638 | 809 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 810 { |
811 if (status_box->imhtml_visible) | |
812 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
813 else | |
814 return NULL; | |
815 } |