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