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