Mercurial > pidgin
annotate src/gtkstatusbox.c @ 11661:8ebc2219fae3
[gaim-migrate @ 13946]
hopefully this will apease cruise control...
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Fri, 14 Oct 2005 05:28:50 +0000 |
parents | 527cf464140b |
children | 8004885fabbe |
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" |
11627 | 30 |
10643 | 31 #include "gtkgaim.h" |
32 #include "gtkstock.h" | |
33 #include "gtkstatusbox.h" | |
34 | |
35 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); | |
11562 | 36 static void remove_typing_cb(GtkGaimStatusBox *box); |
10643 | 37 |
38 static void gtk_gaim_status_box_changed(GtkComboBox *box); | |
39 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
40 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
41 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); | |
42 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
43 | |
44 static void (*combo_box_size_request)(GtkWidget *widget, GtkRequisition *requisition); | |
45 static void (*combo_box_size_allocate)(GtkWidget *widget, GtkAllocation *allocation); | |
46 static gboolean (*combo_box_expose_event)(GtkWidget *widget, GdkEventExpose *event); | |
47 static void (*combo_box_forall) (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
48 enum { | |
49 ICON_COLUMN, | |
50 TEXT_COLUMN, | |
51 TITLE_COLUMN, | |
52 DESC_COLUMN, | |
53 TYPE_COLUMN, | |
54 NUM_COLUMNS | |
55 }; | |
56 | |
11499 | 57 enum { |
58 PROP_0, | |
59 PROP_ACCOUNT | |
60 }; | |
61 | |
10643 | 62 static void gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass); |
63 static void gtk_gaim_status_box_init (GtkGaimStatusBox *status_box); | |
64 | |
65 GType | |
66 gtk_gaim_status_box_get_type (void) | |
67 { | |
10861 | 68 static GType status_box_type = 0; |
10643 | 69 |
10861 | 70 if (!status_box_type) |
71 { | |
72 static const GTypeInfo status_box_info = | |
73 { | |
74 sizeof (GtkGaimStatusBoxClass), | |
75 NULL, /* base_init */ | |
76 NULL, /* base_finalize */ | |
77 (GClassInitFunc) gtk_gaim_status_box_class_init, | |
78 NULL, /* class_finalize */ | |
79 NULL, /* class_data */ | |
80 sizeof (GtkGaimStatusBox), | |
81 0, | |
82 (GInstanceInitFunc) gtk_gaim_status_box_init | |
83 }; | |
10643 | 84 |
10861 | 85 status_box_type = g_type_register_static(GTK_TYPE_COMBO_BOX, |
86 "GtkGaimStatusBox", | |
87 &status_box_info, | |
88 0); | |
89 } | |
10643 | 90 |
10861 | 91 return status_box_type; |
10643 | 92 } |
93 | |
94 static void | |
11499 | 95 gtk_gaim_status_box_get_property(GObject *object, guint param_id, |
96 GValue *value, GParamSpec *psec) | |
97 { | |
98 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
99 | |
100 switch (param_id) { | |
101 case PROP_ACCOUNT: | |
102 g_value_set_pointer(value, statusbox->account); | |
103 break; | |
104 default: | |
105 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, psec); | |
106 break; | |
107 } | |
108 } | |
109 | |
110 static void | |
111 gtk_gaim_status_box_set_property(GObject *object, guint param_id, | |
112 const GValue *value, GParamSpec *pspec) | |
113 { | |
114 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
115 | |
116 switch (param_id) { | |
117 case PROP_ACCOUNT: | |
118 statusbox->account = g_value_get_pointer(value); | |
119 break; | |
120 default: | |
121 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | |
122 break; | |
123 } | |
124 } | |
125 | |
126 | |
127 static void | |
10643 | 128 gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass) |
129 { | |
10861 | 130 GObjectClass *object_class; |
131 GtkWidgetClass *widget_class; | |
132 GtkComboBoxClass *parent_class = (GtkComboBoxClass*)klass; | |
133 GtkContainerClass *container_class = (GtkContainerClass*)klass; | |
10643 | 134 |
10861 | 135 parent_class->changed = gtk_gaim_status_box_changed; |
136 widget_class = (GtkWidgetClass*)klass; | |
137 combo_box_size_request = widget_class->size_request; | |
138 widget_class->size_request = gtk_gaim_status_box_size_request; | |
139 combo_box_size_allocate = widget_class->size_allocate; | |
140 widget_class->size_allocate = gtk_gaim_status_box_size_allocate; | |
141 combo_box_expose_event = widget_class->expose_event; | |
142 widget_class->expose_event = gtk_gaim_status_box_expose_event; | |
10643 | 143 |
10861 | 144 combo_box_forall = container_class->forall; |
145 container_class->forall = gtk_gaim_status_box_forall; | |
146 | |
147 object_class = (GObjectClass *)klass; | |
11499 | 148 |
149 object_class->get_property = gtk_gaim_status_box_get_property; | |
150 object_class->set_property = gtk_gaim_status_box_set_property; | |
151 | |
152 g_object_class_install_property(object_class, | |
153 PROP_ACCOUNT, | |
154 g_param_spec_pointer("account", | |
155 "Account", | |
156 "The account, or NULL for all accounts", | |
157 G_PARAM_READWRITE | |
158 ) | |
159 ); | |
10643 | 160 } |
161 | |
162 static void | |
163 gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box) | |
164 { | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
165 char *text, *title; |
10643 | 166 char aa_color[8]; |
167 GdkPixbuf *pixbuf; | |
10702 | 168 GtkTreePath *path; |
10643 | 169 |
170 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
171 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
172 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
173 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
174 style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
175 |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
176 title = status_box->title; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
177 if (!title) |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
178 title = ""; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
179 |
10643 | 180 if (status_box->error) { |
11499 | 181 text = g_strdup_printf("%s\n<span size=\"smaller\" weight=\"bold\" color=\"red\">%s</span>", |
10861 | 182 title, status_box->error); |
10643 | 183 } else if (status_box->typing) { |
10861 | 184 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
185 title, aa_color, _("Typing")); | |
10643 | 186 } else if (status_box->connecting) { |
10861 | 187 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
188 title, aa_color, _("Connecting")); | |
189 } else if (status_box->desc) { | |
190 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", | |
191 title, aa_color, status_box->desc); | |
10643 | 192 } else { |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
193 text = g_strdup_printf("%s", title); |
10643 | 194 } |
10861 | 195 |
11523 | 196 if (status_box->connecting) |
197 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; | |
198 else if (status_box->error) | |
10643 | 199 pixbuf = status_box->error_pixbuf; |
200 else if (status_box->typing) | |
201 pixbuf = status_box->typing_pixbufs[status_box->typing_index]; | |
202 else | |
203 pixbuf = status_box->pixbuf; | |
204 | |
205 gtk_list_store_set(status_box->store, &(status_box->iter), | |
206 ICON_COLUMN, pixbuf, | |
10861 | 207 TEXT_COLUMN, text, |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
208 TITLE_COLUMN, title, |
10861 | 209 DESC_COLUMN, status_box->desc, |
10643 | 210 TYPE_COLUMN, NULL, -1); |
10702 | 211 path = gtk_tree_path_new_from_string("0"); |
212 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); | |
213 gtk_tree_path_free(path); | |
10643 | 214 |
215 g_free(text); | |
216 } | |
217 | |
218 static void | |
219 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) | |
220 { | |
11400 | 221 GtkCellRenderer *text_rend; |
222 GtkCellRenderer *icon_rend; | |
10643 | 223 GtkTextBuffer *buffer; |
224 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; | |
11400 | 225 GtkIconSize icon_size; |
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
226 GtkTreePath *path; |
11654 | 227 const char *current_savedstatus_name; |
228 GaimSavedStatus *saved_status; | |
11400 | 229 |
230 text_rend = gtk_cell_renderer_text_new(); | |
231 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
232 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
10643 | 233 |
234 status_box->imhtml_visible = FALSE; | |
235 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
236 icon_size, "GtkGaimStatusBox"); | |
237 status_box->connecting_index = 0; | |
10861 | 238 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT0, |
10643 | 239 icon_size, "GtkGaimStatusBox"); |
10861 | 240 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT1, |
10643 | 241 icon_size, "GtkGaimStatusBox"); |
10861 | 242 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT2, |
10643 | 243 icon_size, "GtkGaimStatusBox"); |
10861 | 244 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT3, |
10643 | 245 icon_size, "GtkGaimStatusBox"); |
246 | |
247 status_box->typing_index = 0; | |
248 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING0, | |
249 icon_size, "GtkGaimStatusBox"); | |
250 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING1, | |
251 icon_size, "GtkGaimStatusBox"); | |
252 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING2, | |
253 icon_size, "GtkGaimStatusBox"); | |
254 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING3, | |
255 icon_size, "GtkGaimStatusBox"); | |
256 status_box->connecting = FALSE; | |
257 status_box->typing = FALSE; | |
258 status_box->title = NULL; | |
10861 | 259 status_box->pixbuf = NULL; |
10643 | 260 status_box->cell_view = gtk_cell_view_new(); |
261 gtk_widget_show (status_box->cell_view); | |
10861 | 262 |
10643 | 263 status_box->store = gtk_list_store_new(NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
264 status_box->dropdown_store = gtk_list_store_new(NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); | |
265 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); | |
266 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
267 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
268 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
269 gtk_gaim_status_box_refresh(status_box); | |
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
270 path = gtk_tree_path_new_from_string("0"); |
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
271 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
|
272 gtk_tree_path_free(path); |
10643 | 273 gtk_container_add(GTK_CONTAINER(status_box), status_box->cell_view); |
10861 | 274 |
10643 | 275 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
276 status_box->text_rend = gtk_cell_renderer_text_new(); | |
277 | |
278 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
10861 | 279 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 280 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
281 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
282 | |
283 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
11499 | 284 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 285 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
286 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
287 | |
288 status_box->vbox = gtk_vbox_new(0, FALSE); | |
289 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
290 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
291 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
11562 | 292 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 293 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
294 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
295 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
296 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
297 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
298 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
299 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
300 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_ONLINE, | |
301 icon_size, "GtkGaimStatusBox"); | |
302 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_AWAY, | |
303 icon_size, "GtkGaimStatusBox"); | |
304 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
305 icon_size, "GtkGaimStatusBox"); | |
306 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_INVISIBLE, | |
307 icon_size, "GtkGaimStatusBox"); | |
308 /* hacks */ | |
309 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Available"), NULL, "available"); | |
310 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf2, _("Away"), NULL, "away"); | |
311 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf4, _("Invisible"), NULL, "invisible"); | |
312 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf3, _("Offline"), NULL, "offline"); | |
11654 | 313 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), pixbuf, _("Custom..."), NULL, "custom"); |
314 | |
315 current_savedstatus_name = gaim_prefs_get_string("/core/status/current"); | |
316 saved_status = gaim_savedstatus_find(current_savedstatus_name); | |
317 if (saved_status == NULL) | |
318 { | |
319 /* Default to "available" */ | |
320 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
321 } | |
322 else | |
323 { | |
324 GaimStatusPrimitive primitive; | |
325 const char *message; | |
10643 | 326 |
11654 | 327 primitive = gaim_savedstatus_get_type(saved_status); |
328 if (gaim_savedstatus_has_substatuses(saved_status) || | |
329 ((primitive != GAIM_STATUS_AVAILABLE) && | |
330 (primitive != GAIM_STATUS_OFFLINE) && | |
331 (primitive != GAIM_STATUS_AWAY) && | |
332 (primitive != GAIM_STATUS_HIDDEN))) | |
333 { | |
334 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 4); | |
335 } | |
336 else | |
337 { | |
338 if (primitive == GAIM_STATUS_AVAILABLE) | |
339 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
340 if (primitive == GAIM_STATUS_OFFLINE) | |
341 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3); | |
342 else if (primitive == GAIM_STATUS_AWAY) | |
343 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1); | |
344 else if (primitive == GAIM_STATUS_HIDDEN) | |
345 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2); | |
346 } | |
11627 | 347 |
11654 | 348 message = gaim_savedstatus_get_message(saved_status); |
349 if (message != NULL) | |
350 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); | |
11627 | 351 } |
10643 | 352 } |
353 | |
354 | |
355 static void | |
10861 | 356 gtk_gaim_status_box_size_request(GtkWidget *widget, |
357 GtkRequisition *requisition) | |
10643 | 358 { |
359 GtkRequisition box_req; | |
360 combo_box_size_request(widget, requisition); | |
10861 | 361 |
10643 | 362 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
363 if (box_req.height > 1) | |
364 requisition->height = requisition->height + box_req.height + 6; | |
10861 | 365 |
10643 | 366 requisition->width = 1; |
367 | |
368 } | |
369 | |
370 static void | |
10861 | 371 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
372 GtkAllocation *allocation) | |
10643 | 373 { |
374 GtkRequisition req = {0,0}; | |
11400 | 375 GtkAllocation parent_alc, box_alc; |
376 | |
377 parent_alc = *allocation; | |
378 box_alc = *allocation; | |
10643 | 379 combo_box_size_request(widget, &req); |
10861 | 380 |
10643 | 381 /* EVIL XXX */ |
10861 | 382 box_alc.height = 80; |
383 /* box_alc.height = MAX(1,box_alc.height - req.height - 6); */ | |
384 | |
10643 | 385 box_alc.y = box_alc.y + req.height + 6; |
386 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | |
10861 | 387 |
10643 | 388 parent_alc.height = MAX(1,req.height); |
389 combo_box_size_allocate(widget, &parent_alc); | |
390 widget->allocation = *allocation; | |
391 } | |
392 | |
393 | |
394 static gboolean | |
10861 | 395 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
396 GdkEventExpose *event) | |
10643 | 397 { |
10861 | 398 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
399 combo_box_expose_event(widget, event); | |
10643 | 400 |
10861 | 401 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
402 status_box->vbox, event); | |
403 return FALSE; | |
10643 | 404 } |
405 | |
406 static void | |
10861 | 407 gtk_gaim_status_box_forall(GtkContainer *container, |
408 gboolean include_internals, | |
409 GtkCallback callback, | |
410 gpointer callback_data) | |
10643 | 411 { |
10861 | 412 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 413 |
10861 | 414 if (include_internals) |
415 { | |
416 (* callback) (status_box->vbox, callback_data); | |
417 } | |
10643 | 418 |
10861 | 419 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 420 } |
421 | |
422 GtkWidget * | |
423 gtk_gaim_status_box_new() | |
424 { | |
425 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
426 } | |
427 | |
11499 | 428 GtkWidget * |
429 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
430 { | |
431 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
432 } | |
10643 | 433 |
434 void | |
435 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GdkPixbuf *pixbuf, const char *text, const char *sec_text, char *edit) | |
436 { | |
437 GtkTreeIter iter; | |
438 char *t; | |
10861 | 439 |
10643 | 440 if (sec_text) { |
441 char aa_color[8]; | |
442 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
443 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
444 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
445 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 446 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 447 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
448 } else { | |
449 t = g_strdup(text); | |
450 } | |
10861 | 451 |
10643 | 452 gtk_list_store_append(status_box->dropdown_store, &iter); |
453 gtk_list_store_set(status_box->dropdown_store, &iter, | |
454 ICON_COLUMN, pixbuf, | |
10861 | 455 TEXT_COLUMN, t, |
10643 | 456 TITLE_COLUMN, text, |
10861 | 457 DESC_COLUMN, sec_text, |
10643 | 458 TYPE_COLUMN, edit, -1); |
11638 | 459 g_free(t); |
10643 | 460 } |
461 | |
462 void | |
463 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) | |
464 { | |
11523 | 465 if (status_box->error) |
466 g_free(status_box->error); | |
10643 | 467 status_box->error = g_strdup(error); |
468 gtk_gaim_status_box_refresh(status_box); | |
469 } | |
470 | |
471 void | |
472 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
473 { | |
474 if (!status_box) | |
475 return; | |
476 status_box->connecting = connecting; | |
477 gtk_gaim_status_box_refresh(status_box); | |
478 } | |
479 | |
480 void | |
481 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
482 { | |
483 if (!status_box) | |
484 return; | |
485 if (status_box->connecting_index == 3) | |
486 status_box->connecting_index = 0; | |
10861 | 487 else |
10643 | 488 status_box->connecting_index++; |
489 gtk_gaim_status_box_refresh(status_box); | |
490 } | |
491 | |
492 void | |
493 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
494 { | |
495 if (status_box->typing_index == 3) | |
496 status_box->typing_index = 0; | |
10861 | 497 else |
10643 | 498 status_box->typing_index++; |
499 gtk_gaim_status_box_refresh(status_box); | |
500 } | |
501 | |
11654 | 502 static void |
503 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 504 { |
11638 | 505 gchar *status_type_id, *title; |
10643 | 506 GList *l; |
507 GtkTreeIter iter; | |
11654 | 508 GaimStatusPrimitive primitive; |
509 char *message; | |
510 GaimSavedStatus *saved_status; | |
11655 | 511 int active_row; |
10643 | 512 |
11654 | 513 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
514 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, | |
11638 | 515 TYPE_COLUMN, &status_type_id, |
516 TITLE_COLUMN, &title, -1); | |
11654 | 517 message = gtk_gaim_status_box_get_message(status_box); |
11655 | 518 active_row = gtk_combo_box_get_active(GTK_COMBO_BOX(status_box)); |
519 if (active_row == 0) | |
520 primitive = GAIM_STATUS_AVAILABLE; | |
521 else if (active_row == 1) | |
522 primitive = GAIM_STATUS_AWAY; | |
523 else if (active_row == 2) | |
524 primitive = GAIM_STATUS_HIDDEN; | |
525 else if (active_row == 3) | |
526 primitive = GAIM_STATUS_OFFLINE; | |
527 else | |
528 primitive = GAIM_STATUS_AVAILABLE; | |
11654 | 529 |
530 /* TODO: Should save the previous status as a transient status? */ | |
531 | |
532 /* Save the newly selected status to prefs.xml and status.xml */ | |
533 saved_status = gaim_savedstatus_find(_("Default")); | |
534 if (saved_status == NULL) | |
535 saved_status = gaim_savedstatus_new(_("Default"), primitive); | |
536 gaim_savedstatus_set_type(saved_status, primitive); | |
537 gaim_savedstatus_set_message(saved_status, message); | |
538 gaim_prefs_set_string("/core/status/current", _("Default")); | |
539 | |
540 /* Set the status for each account */ | |
541 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) | |
542 { | |
10643 | 543 GaimAccount *account = (GaimAccount*)l->data; |
544 GaimStatusType *status_type; | |
10861 | 545 |
10643 | 546 if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) |
547 continue; | |
548 | |
549 status_type = gaim_account_get_status_type(account, status_type_id); | |
550 | |
551 if (status_type == NULL) | |
552 continue; | |
11638 | 553 |
10861 | 554 gaim_account_set_status(account, status_type_id, TRUE, |
11654 | 555 "message", message, NULL); |
10643 | 556 } |
11627 | 557 |
11638 | 558 g_free(status_type_id); |
559 g_free(title); | |
11654 | 560 g_free(message); |
561 } | |
562 | |
563 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
564 { | |
565 activate_currently_selected_status(status_box); | |
566 | |
567 g_source_remove(status_box->typing); | |
568 status_box->typing = 0; | |
569 gtk_gaim_status_box_refresh(status_box); | |
10643 | 570 } |
571 | |
572 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
573 { | |
11400 | 574 GtkGaimStatusBox *status_box; |
10643 | 575 GtkTreeIter iter; |
576 char *text, *sec_text; | |
577 GdkPixbuf *pixbuf; | |
578 gchar *status_type_id; | |
579 | |
11400 | 580 status_box = GTK_GAIM_STATUS_BOX(box); |
581 | |
10643 | 582 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
583 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, TITLE_COLUMN, &text, | |
10861 | 584 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
10643 | 585 TYPE_COLUMN, &status_type_id, -1); |
586 if (status_box->title) | |
587 g_free(status_box->title); | |
11638 | 588 status_box->title = text; |
10643 | 589 if (status_box->desc && sec_text) |
11638 | 590 g_free(status_box->desc); |
591 status_box->desc = sec_text; | |
10643 | 592 if (status_box->pixbuf) |
593 g_object_unref(status_box->pixbuf); | |
594 status_box->pixbuf = pixbuf; | |
11638 | 595 if (status_box->typing) |
596 g_source_remove(status_box->typing); | |
597 status_box->typing = 0; | |
10861 | 598 |
11654 | 599 /* |
600 * TODO: Should show the message box whenever status_type_id allows | |
601 * for a message attribute on any protocol that is enabled. | |
602 */ | |
603 if (!strcmp(status_type_id, "away")) | |
604 status_box->imhtml_visible = TRUE; | |
605 else | |
606 status_box->imhtml_visible = FALSE; | |
607 | |
608 if (status_box->imhtml_visible) | |
609 { | |
10643 | 610 gtk_widget_show_all(status_box->vbox); |
611 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
612 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
613 gtk_widget_grab_focus(status_box->imhtml); | |
11654 | 614 } |
615 else | |
616 { | |
10643 | 617 gtk_widget_hide_all(status_box->vbox); |
11654 | 618 activate_currently_selected_status(status_box); |
10643 | 619 } |
11638 | 620 g_free(status_type_id); |
10643 | 621 gtk_gaim_status_box_refresh(status_box); |
622 } | |
623 | |
624 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
625 { | |
626 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
627 if (box->typing) { | |
628 gtk_gaim_status_box_pulse_typing(box); | |
629 g_source_remove(box->typing); | |
10861 | 630 } |
10643 | 631 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); |
632 gtk_gaim_status_box_refresh(box); | |
633 } | |
10649 | 634 |
11638 | 635 char *gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
10649 | 636 { |
637 GtkTreeIter iter; | |
638 char *type; | |
639 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); | |
10861 | 640 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 641 TYPE_COLUMN, &type, -1); |
642 return type; | |
643 } | |
644 | |
11638 | 645 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 646 { |
647 if (status_box->imhtml_visible) | |
648 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
649 else | |
650 return NULL; | |
651 } |