Mercurial > pidgin.yaz
annotate src/gtkstatusbox.c @ 12088:980c877bd238
[gaim-migrate @ 14385]
sf patch #1356873, from Will Thompson (resiak)
"gaim_find_buddys_group is a stupid name.
gaim_buddy_get_group is not a stupid name."
Way to think outside the box!
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 14 Nov 2005 22:41:52 +0000 |
parents | 3b52d94437f3 |
children | 383226e075f2 |
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" | |
12080 | 36 #include "gtkutils.h" |
10643 | 37 |
38 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); | |
11562 | 39 static void remove_typing_cb(GtkGaimStatusBox *box); |
10643 | 40 |
11967 | 41 static void gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box); |
11732 | 42 static void gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box); |
10643 | 43 static void gtk_gaim_status_box_changed(GtkComboBox *box); |
44 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
45 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
46 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); | |
47 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
48 | |
49 static void (*combo_box_size_request)(GtkWidget *widget, GtkRequisition *requisition); | |
50 static void (*combo_box_size_allocate)(GtkWidget *widget, GtkAllocation *allocation); | |
51 static gboolean (*combo_box_expose_event)(GtkWidget *widget, GdkEventExpose *event); | |
52 static void (*combo_box_forall) (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
11739 | 53 |
10643 | 54 enum { |
11739 | 55 TYPE_COLUMN, /* A GtkGaimStatusBoxItemType */ |
11738 | 56 ICON_COLUMN, /* This is a GdkPixbuf (the other columns are strings) */ |
57 TEXT_COLUMN, /* A string */ | |
58 TITLE_COLUMN, /* The plain-English title of this item */ | |
59 DESC_COLUMN, /* A plain-English description of this item */ | |
10643 | 60 NUM_COLUMNS |
61 }; | |
62 | |
11499 | 63 enum { |
64 PROP_0, | |
65 PROP_ACCOUNT | |
66 }; | |
67 | |
10643 | 68 static void gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass); |
69 static void gtk_gaim_status_box_init (GtkGaimStatusBox *status_box); | |
70 | |
71 GType | |
72 gtk_gaim_status_box_get_type (void) | |
73 { | |
10861 | 74 static GType status_box_type = 0; |
10643 | 75 |
10861 | 76 if (!status_box_type) |
77 { | |
78 static const GTypeInfo status_box_info = | |
79 { | |
80 sizeof (GtkGaimStatusBoxClass), | |
81 NULL, /* base_init */ | |
82 NULL, /* base_finalize */ | |
83 (GClassInitFunc) gtk_gaim_status_box_class_init, | |
84 NULL, /* class_finalize */ | |
85 NULL, /* class_data */ | |
86 sizeof (GtkGaimStatusBox), | |
87 0, | |
88 (GInstanceInitFunc) gtk_gaim_status_box_init | |
89 }; | |
10643 | 90 |
10861 | 91 status_box_type = g_type_register_static(GTK_TYPE_COMBO_BOX, |
92 "GtkGaimStatusBox", | |
93 &status_box_info, | |
94 0); | |
95 } | |
10643 | 96 |
10861 | 97 return status_box_type; |
10643 | 98 } |
99 | |
100 static void | |
11499 | 101 gtk_gaim_status_box_get_property(GObject *object, guint param_id, |
102 GValue *value, GParamSpec *psec) | |
103 { | |
104 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
105 | |
106 switch (param_id) { | |
107 case PROP_ACCOUNT: | |
108 g_value_set_pointer(value, statusbox->account); | |
109 break; | |
110 default: | |
111 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, psec); | |
112 break; | |
113 } | |
114 } | |
115 | |
116 static void | |
11967 | 117 update_to_reflect_account_status(GtkGaimStatusBox *status_box, GaimAccount *account, GaimStatus *newstatus) |
11960 | 118 { |
11967 | 119 const GList *l; |
120 int status_no = -1; | |
121 const GaimStatusType *statustype = NULL; | |
12060 | 122 const char *message; |
11967 | 123 |
124 statustype = gaim_status_type_find_with_id((GList *)gaim_account_get_status_types(account), | |
125 (char *)gaim_status_type_get_id(gaim_status_get_type(newstatus))); | |
126 | |
127 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) { | |
128 GaimStatusType *status_type = (GaimStatusType *)l->data; | |
129 | |
130 if (!gaim_status_type_is_user_settable(status_type)) | |
131 continue; | |
132 status_no++; | |
133 if (statustype == status_type) | |
134 break; | |
135 } | |
136 | |
137 if (status_no != -1) { | |
138 gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE); | |
139 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), status_no); | |
140 gtk_gaim_status_box_refresh(status_box); | |
12060 | 141 |
142 message = gaim_status_get_attr_string(newstatus, "message"); | |
143 | |
144 if (!message || !*message) | |
145 { | |
146 gtk_widget_hide_all(status_box->vbox); | |
147 status_box->imhtml_visible = FALSE; | |
148 } | |
149 else | |
150 { | |
151 gtk_widget_show_all(status_box->vbox); | |
152 status_box->imhtml_visible = TRUE; | |
153 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
154 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); | |
155 } | |
11967 | 156 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); |
157 } | |
158 } | |
159 | |
160 static void | |
161 account_status_changed_cb(GaimAccount *account, GaimStatus *oldstatus, GaimStatus *newstatus, GtkGaimStatusBox *status_box) | |
162 { | |
163 if (status_box->account == account) | |
164 update_to_reflect_account_status(status_box, account, newstatus); | |
11960 | 165 } |
166 | |
167 static void | |
11499 | 168 gtk_gaim_status_box_set_property(GObject *object, guint param_id, |
169 const GValue *value, GParamSpec *pspec) | |
170 { | |
171 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
172 | |
173 switch (param_id) { | |
174 case PROP_ACCOUNT: | |
175 statusbox->account = g_value_get_pointer(value); | |
11960 | 176 |
177 /* FIXME: call this in the destroy function too, if we had one */ | |
11967 | 178 if (statusbox->status_changed_signal) { |
179 gaim_signal_disconnect(gaim_accounts_get_handle(), "account-status-changed", | |
180 statusbox, GAIM_CALLBACK(account_status_changed_cb)); | |
181 statusbox->status_changed_signal = 0; | |
182 } | |
11960 | 183 if (statusbox->account) |
11967 | 184 statusbox->status_changed_signal = gaim_signal_connect(gaim_accounts_get_handle(), "account-status-changed", |
11960 | 185 statusbox, GAIM_CALLBACK(account_status_changed_cb), |
186 statusbox); | |
11732 | 187 gtk_gaim_status_box_regenerate(statusbox); |
11499 | 188 break; |
189 default: | |
190 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | |
191 break; | |
192 } | |
193 } | |
194 | |
195 static void | |
10643 | 196 gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass) |
197 { | |
10861 | 198 GObjectClass *object_class; |
199 GtkWidgetClass *widget_class; | |
200 GtkComboBoxClass *parent_class = (GtkComboBoxClass*)klass; | |
201 GtkContainerClass *container_class = (GtkContainerClass*)klass; | |
10643 | 202 |
10861 | 203 parent_class->changed = gtk_gaim_status_box_changed; |
204 widget_class = (GtkWidgetClass*)klass; | |
205 combo_box_size_request = widget_class->size_request; | |
206 widget_class->size_request = gtk_gaim_status_box_size_request; | |
207 combo_box_size_allocate = widget_class->size_allocate; | |
208 widget_class->size_allocate = gtk_gaim_status_box_size_allocate; | |
209 combo_box_expose_event = widget_class->expose_event; | |
210 widget_class->expose_event = gtk_gaim_status_box_expose_event; | |
10643 | 211 |
10861 | 212 combo_box_forall = container_class->forall; |
213 container_class->forall = gtk_gaim_status_box_forall; | |
214 | |
215 object_class = (GObjectClass *)klass; | |
11499 | 216 |
217 object_class->get_property = gtk_gaim_status_box_get_property; | |
218 object_class->set_property = gtk_gaim_status_box_set_property; | |
219 | |
220 g_object_class_install_property(object_class, | |
221 PROP_ACCOUNT, | |
222 g_param_spec_pointer("account", | |
223 "Account", | |
224 "The account, or NULL for all accounts", | |
225 G_PARAM_READWRITE | |
226 ) | |
227 ); | |
10643 | 228 } |
229 | |
230 static void | |
231 gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box) | |
232 { | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
233 char *text, *title; |
10643 | 234 char aa_color[8]; |
235 GdkPixbuf *pixbuf; | |
10702 | 236 GtkTreePath *path; |
11870 | 237 GtkStyle *style; |
10643 | 238 |
11870 | 239 style = gtk_widget_get_style(GTK_WIDGET(status_box)); |
10643 | 240 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", |
241 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
242 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
243 style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
244 |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
245 title = status_box->title; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
246 if (!title) |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
247 title = ""; |
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
248 |
11960 | 249 |
10643 | 250 if (status_box->error) { |
11499 | 251 text = g_strdup_printf("%s\n<span size=\"smaller\" weight=\"bold\" color=\"red\">%s</span>", |
10861 | 252 title, status_box->error); |
10643 | 253 } else if (status_box->typing) { |
10861 | 254 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
255 title, aa_color, _("Typing")); | |
10643 | 256 } else if (status_box->connecting) { |
10861 | 257 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
258 title, aa_color, _("Connecting")); | |
259 } else if (status_box->desc) { | |
260 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", | |
261 title, aa_color, status_box->desc); | |
10643 | 262 } else { |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
263 text = g_strdup_printf("%s", title); |
10643 | 264 } |
10861 | 265 |
11960 | 266 if (status_box->account) { |
267 char *text2 = g_strdup_printf("%s\n<span size=\"smaller\">%s</span>", gaim_account_get_username(status_box->account), text); | |
268 g_free(text); | |
269 text = text2; | |
270 } | |
271 | |
272 | |
11523 | 273 if (status_box->connecting) |
274 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; | |
275 else if (status_box->error) | |
10643 | 276 pixbuf = status_box->error_pixbuf; |
277 else if (status_box->typing) | |
278 pixbuf = status_box->typing_pixbufs[status_box->typing_index]; | |
279 else | |
280 pixbuf = status_box->pixbuf; | |
281 | |
282 gtk_list_store_set(status_box->store, &(status_box->iter), | |
11755 | 283 TYPE_COLUMN, -1, /* This field is not used in this list store */ |
10643 | 284 ICON_COLUMN, pixbuf, |
10861 | 285 TEXT_COLUMN, text, |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
286 TITLE_COLUMN, title, |
10861 | 287 DESC_COLUMN, status_box->desc, |
11739 | 288 -1); |
10702 | 289 path = gtk_tree_path_new_from_string("0"); |
290 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); | |
291 gtk_tree_path_free(path); | |
10643 | 292 |
293 g_free(text); | |
294 } | |
295 | |
11870 | 296 /** |
297 * This updates the GtkTreeView so that it correctly shows the state | |
298 * we are currently using. It is used when the current state is | |
299 * updated from somewhere other than the GtkStatusBox (from a plugin, | |
300 * or when signing on with the "-n" option, for example). It is | |
301 * also used when the user selects the "Custom..." option. | |
302 * | |
303 * Maybe we could accomplish this by triggering off the mouse and | |
304 * keyboard signals instead of the changed signal? | |
305 */ | |
306 static void | |
307 update_to_reflect_current_status(GtkGaimStatusBox *status_box) | |
308 { | |
309 const char *current_savedstatus_name; | |
310 GaimSavedStatus *saved_status; | |
311 | |
11983 | 312 /* this function is inappropriate for ones with accounts */ |
313 if (status_box->account) | |
314 return; | |
315 | |
11870 | 316 current_savedstatus_name = gaim_prefs_get_string("/core/status/current"); |
317 saved_status = gaim_savedstatus_find(current_savedstatus_name); | |
11951 | 318 |
319 /* | |
320 * Suppress the "changed" signal because the status | |
321 * was changed programmatically. | |
322 */ | |
323 gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE); | |
324 | |
11870 | 325 if (saved_status == NULL) |
326 { | |
327 /* Default to "available" */ | |
328 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
329 } | |
330 else | |
331 { | |
332 GaimStatusPrimitive primitive; | |
333 const char *message; | |
334 | |
335 primitive = gaim_savedstatus_get_type(saved_status); | |
336 if (gaim_savedstatus_has_substatuses(saved_status) || | |
337 ((primitive != GAIM_STATUS_AVAILABLE) && | |
338 (primitive != GAIM_STATUS_OFFLINE) && | |
339 (primitive != GAIM_STATUS_AWAY) && | |
340 (primitive != GAIM_STATUS_HIDDEN))) | |
341 { | |
12080 | 342 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 5); |
11870 | 343 } |
344 else | |
345 { | |
346 if (primitive == GAIM_STATUS_AVAILABLE) | |
347 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
348 if (primitive == GAIM_STATUS_OFFLINE) | |
349 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3); | |
350 else if (primitive == GAIM_STATUS_AWAY) | |
351 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1); | |
352 else if (primitive == GAIM_STATUS_HIDDEN) | |
353 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2); | |
354 } | |
355 | |
356 message = gaim_savedstatus_get_message(saved_status); | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
357 if (!message || !*message) |
11951 | 358 { |
11954 | 359 status_box->imhtml_visible = FALSE; |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
360 gtk_widget_hide_all(status_box->vbox); |
11954 | 361 } |
362 else | |
363 { | |
364 status_box->imhtml_visible = TRUE; | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
365 gtk_widget_show_all(status_box->vbox); |
11954 | 366 |
11951 | 367 /* |
368 * Suppress the "changed" signal because the status | |
369 * was changed programmatically. | |
370 */ | |
371 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), FALSE); | |
11954 | 372 |
373 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
11870 | 374 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); |
11951 | 375 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), TRUE); |
376 } | |
11870 | 377 } |
11951 | 378 |
379 /* Stop suppressing the "changed" signal. */ | |
380 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); | |
11870 | 381 } |
382 | |
11732 | 383 static void |
384 gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) | |
385 { | |
11739 | 386 GaimAccount *account; |
11732 | 387 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; |
388 GtkIconSize icon_size; | |
389 | |
390 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
391 | |
392 gtk_list_store_clear(status_box->dropdown_store); | |
393 | |
11739 | 394 account = GTK_GAIM_STATUS_BOX(status_box)->account; |
395 if (account == NULL) | |
396 { | |
11756 | 397 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_ONLINE, |
11732 | 398 icon_size, "GtkGaimStatusBox"); |
11756 | 399 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_AWAY, |
11732 | 400 icon_size, "GtkGaimStatusBox"); |
11756 | 401 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
11732 | 402 icon_size, "GtkGaimStatusBox"); |
11756 | 403 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_INVISIBLE, |
11732 | 404 icon_size, "GtkGaimStatusBox"); |
405 /* hacks */ | |
11739 | 406 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AVAILABLE, pixbuf, _("Available"), NULL); |
407 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AWAY, pixbuf2, _("Away"), NULL); | |
408 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_HIDDEN, pixbuf4, _("Invisible"), NULL); | |
409 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_OFFLINE, pixbuf3, _("Offline"), NULL); | |
11738 | 410 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box)); |
11739 | 411 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("Custom..."), NULL); |
412 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL); | |
11732 | 413 |
11870 | 414 update_to_reflect_current_status(status_box); |
11732 | 415 |
416 } else { | |
417 const GList *l; | |
11739 | 418 |
419 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
420 { | |
11732 | 421 GaimStatusType *status_type = (GaimStatusType *)l->data; |
422 | |
423 if (!gaim_status_type_is_user_settable(status_type)) | |
424 continue; | |
425 | |
11739 | 426 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), |
427 gaim_status_type_get_primitive(status_type), | |
12080 | 428 gaim_gtk_create_prpl_icon_with_status(account, status_type), |
11739 | 429 gaim_status_type_get_name(status_type), |
430 NULL); | |
11732 | 431 } |
11967 | 432 update_to_reflect_account_status(status_box, account, gaim_account_get_active_status(account)); |
11732 | 433 } |
434 | |
435 } | |
436 | |
12075
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
437 static gboolean scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkIMHtml *imhtml) |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
438 { |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
439 if (event->direction == GDK_SCROLL_UP) |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
440 gtk_imhtml_page_up(imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
441 else if (event->direction == GDK_SCROLL_DOWN) |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
442 gtk_imhtml_page_down(imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
443 return TRUE; |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
444 } |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
445 |
11753 | 446 #if GTK_CHECK_VERSION(2,6,0) |
11738 | 447 static gboolean |
448 dropdown_store_row_separator_func(GtkTreeModel *model, | |
449 GtkTreeIter *iter, gpointer data) | |
450 { | |
11739 | 451 GtkGaimStatusBoxItemType type; |
11738 | 452 |
11885 | 453 gtk_tree_model_get(model, iter, TYPE_COLUMN, &type, -1); |
11738 | 454 |
11739 | 455 if (type == GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR) |
11738 | 456 return TRUE; |
457 | |
458 return FALSE; | |
459 } | |
11753 | 460 #endif |
11738 | 461 |
10643 | 462 static void |
11954 | 463 current_status_pref_changed_cb(const char *name, GaimPrefType type, |
464 gpointer val, gpointer data) | |
465 { | |
466 update_to_reflect_current_status(data); | |
467 } | |
468 | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
469 static void status_box_clicked_cb(GtkWidget *w, GdkEventButton *event, GtkGaimStatusBox *box) |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
470 { |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
471 if (box->imhtml_visible) |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
472 return; |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
473 g_signal_emit_by_name(G_OBJECT(box), "changed", NULL, NULL); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
474 } |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
475 |
11954 | 476 static void |
10643 | 477 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) |
478 { | |
11400 | 479 GtkCellRenderer *text_rend; |
480 GtkCellRenderer *icon_rend; | |
10643 | 481 GtkTextBuffer *buffer; |
11732 | 482 GtkTreePath *path; |
11400 | 483 GtkIconSize icon_size; |
484 | |
485 text_rend = gtk_cell_renderer_text_new(); | |
486 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
487 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
10643 | 488 |
489 status_box->imhtml_visible = FALSE; | |
490 status_box->connecting = FALSE; | |
491 status_box->typing = FALSE; | |
492 status_box->title = NULL; | |
10861 | 493 status_box->pixbuf = NULL; |
10643 | 494 status_box->cell_view = gtk_cell_view_new(); |
495 gtk_widget_show (status_box->cell_view); | |
10861 | 496 |
11739 | 497 status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
498 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 | 499 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
500 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
501 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
502 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
503 gtk_gaim_status_box_refresh(status_box); | |
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
504 path = gtk_tree_path_new_from_string("0"); |
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
505 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
|
506 gtk_tree_path_free(path); |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
507 |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
508 status_box->event = gtk_event_box_new(); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
509 gtk_widget_show(status_box->event); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
510 g_signal_connect(G_OBJECT(status_box->event), "button_press_event", G_CALLBACK(status_box_clicked_cb), status_box); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
511 gtk_container_add(GTK_CONTAINER(status_box->event), status_box->cell_view); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
512 |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
513 gtk_container_add(GTK_CONTAINER(status_box), status_box->event); |
10861 | 514 |
10643 | 515 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
516 status_box->text_rend = gtk_cell_renderer_text_new(); | |
517 | |
518 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
10861 | 519 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 520 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
521 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
522 | |
523 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
11499 | 524 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 525 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
526 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
527 | |
528 status_box->vbox = gtk_vbox_new(0, FALSE); | |
529 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
530 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
531 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
11562 | 532 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 533 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
534 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
535 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
536 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
537 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
538 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
539 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
11654 | 540 |
12075
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
541 g_signal_connect(G_OBJECT(status_box->imhtml), "scroll_event", |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
542 G_CALLBACK(scroll_event_cb), status_box->imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
543 |
11850 | 544 |
545 #if GTK_CHECK_VERSION(2,6,0) | |
546 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); | |
547 #endif | |
548 | |
11756 | 549 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
550 icon_size, "GtkGaimStatusBox"); | |
551 status_box->connecting_index = 0; | |
552 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT0, | |
553 icon_size, "GtkGaimStatusBox"); | |
554 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT1, | |
555 icon_size, "GtkGaimStatusBox"); | |
556 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT2, | |
557 icon_size, "GtkGaimStatusBox"); | |
558 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT3, | |
559 icon_size, "GtkGaimStatusBox"); | |
560 | |
561 status_box->typing_index = 0; | |
562 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING0, | |
563 icon_size, "GtkGaimStatusBox"); | |
564 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING1, | |
565 icon_size, "GtkGaimStatusBox"); | |
566 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING2, | |
567 icon_size, "GtkGaimStatusBox"); | |
568 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING3, | |
569 icon_size, "GtkGaimStatusBox"); | |
570 | |
11732 | 571 gtk_gaim_status_box_regenerate(status_box); |
11954 | 572 |
573 /* Monitor changes in the "/core/status/current" preference */ | |
574 gaim_prefs_connect_callback(status_box, "/core/status/current", | |
575 current_status_pref_changed_cb, status_box); | |
576 | |
577 /* TODO: Need to override the destroy method for this object and put the following line in it */ | |
578 /* gaim_prefs_disconnect_by_handle(status_box); */ | |
10643 | 579 } |
580 | |
581 static void | |
10861 | 582 gtk_gaim_status_box_size_request(GtkWidget *widget, |
583 GtkRequisition *requisition) | |
10643 | 584 { |
585 GtkRequisition box_req; | |
586 combo_box_size_request(widget, requisition); | |
10861 | 587 |
10643 | 588 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
589 if (box_req.height > 1) | |
590 requisition->height = requisition->height + box_req.height + 6; | |
10861 | 591 |
10643 | 592 requisition->width = 1; |
593 | |
594 } | |
595 | |
596 static void | |
10861 | 597 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
598 GtkAllocation *allocation) | |
10643 | 599 { |
600 GtkRequisition req = {0,0}; | |
11400 | 601 GtkAllocation parent_alc, box_alc; |
602 | |
603 parent_alc = *allocation; | |
604 box_alc = *allocation; | |
10643 | 605 combo_box_size_request(widget, &req); |
10861 | 606 |
11998 | 607 box_alc.height = MAX(1, ((allocation->height) - (req.height) - (6))); |
10861 | 608 |
10643 | 609 box_alc.y = box_alc.y + req.height + 6; |
610 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | |
10861 | 611 |
10643 | 612 parent_alc.height = MAX(1,req.height); |
613 combo_box_size_allocate(widget, &parent_alc); | |
614 widget->allocation = *allocation; | |
615 } | |
616 | |
617 | |
618 static gboolean | |
10861 | 619 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
620 GdkEventExpose *event) | |
10643 | 621 { |
10861 | 622 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
623 combo_box_expose_event(widget, event); | |
10643 | 624 |
10861 | 625 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
626 status_box->vbox, event); | |
627 return FALSE; | |
10643 | 628 } |
629 | |
630 static void | |
10861 | 631 gtk_gaim_status_box_forall(GtkContainer *container, |
632 gboolean include_internals, | |
633 GtkCallback callback, | |
634 gpointer callback_data) | |
10643 | 635 { |
10861 | 636 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 637 |
10861 | 638 if (include_internals) |
639 { | |
640 (* callback) (status_box->vbox, callback_data); | |
641 } | |
10643 | 642 |
10861 | 643 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 644 } |
645 | |
646 GtkWidget * | |
647 gtk_gaim_status_box_new() | |
648 { | |
649 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
650 } | |
651 | |
11499 | 652 GtkWidget * |
653 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
654 { | |
655 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
656 } | |
10643 | 657 |
658 void | |
11739 | 659 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *text, const char *sec_text) |
10643 | 660 { |
661 GtkTreeIter iter; | |
662 char *t; | |
10861 | 663 |
10643 | 664 if (sec_text) { |
665 char aa_color[8]; | |
666 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
667 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
668 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
669 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 670 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 671 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
672 } else { | |
673 t = g_strdup(text); | |
674 } | |
10861 | 675 |
10643 | 676 gtk_list_store_append(status_box->dropdown_store, &iter); |
677 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 678 TYPE_COLUMN, type, |
10643 | 679 ICON_COLUMN, pixbuf, |
10861 | 680 TEXT_COLUMN, t, |
10643 | 681 TITLE_COLUMN, text, |
10861 | 682 DESC_COLUMN, sec_text, |
11739 | 683 -1); |
11638 | 684 g_free(t); |
10643 | 685 } |
686 | |
687 void | |
11738 | 688 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
689 { | |
11756 | 690 /* Don't do anything unless GTK actually supports |
691 * gtk_combo_box_set_row_separator_func */ | |
692 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 693 GtkTreeIter iter; |
694 | |
695 gtk_list_store_append(status_box->dropdown_store, &iter); | |
696 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 697 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
698 -1); | |
11756 | 699 #endif |
11738 | 700 } |
701 | |
702 void | |
10643 | 703 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
704 { | |
11523 | 705 if (status_box->error) |
706 g_free(status_box->error); | |
11891 | 707 status_box->error = NULL; |
708 if (error != NULL) | |
709 status_box->error = g_strdup(error); | |
10643 | 710 gtk_gaim_status_box_refresh(status_box); |
711 } | |
712 | |
713 void | |
714 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
715 { | |
716 if (!status_box) | |
717 return; | |
718 status_box->connecting = connecting; | |
719 gtk_gaim_status_box_refresh(status_box); | |
720 } | |
721 | |
722 void | |
723 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
724 { | |
725 if (!status_box) | |
726 return; | |
727 if (status_box->connecting_index == 3) | |
728 status_box->connecting_index = 0; | |
10861 | 729 else |
10643 | 730 status_box->connecting_index++; |
731 gtk_gaim_status_box_refresh(status_box); | |
732 } | |
733 | |
734 void | |
735 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
736 { | |
737 if (status_box->typing_index == 3) | |
738 status_box->typing_index = 0; | |
10861 | 739 else |
10643 | 740 status_box->typing_index++; |
741 gtk_gaim_status_box_refresh(status_box); | |
742 } | |
743 | |
11993 | 744 static GaimStatusType |
745 *find_status_type_by_index(const GaimAccount *account, gint active) | |
746 { | |
747 const GList *l = gaim_account_get_status_types(account); | |
748 gint i; | |
749 | |
750 for (i = 0; l; l = l->next) { | |
751 GaimStatusType *status_type = l->data; | |
752 if (!gaim_status_type_is_user_settable(status_type)) | |
753 continue; | |
754 | |
755 if (active == i) | |
756 return status_type; | |
757 i++; | |
758 } | |
759 | |
760 return NULL; | |
761 } | |
762 | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
763 static gboolean |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
764 message_changed(const char *one, const char *two) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
765 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
766 if (one == NULL && two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
767 return FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
768 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
769 if (one == NULL || two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
770 return TRUE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
771 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
772 return (g_utf8_collate(one, two) != 0); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
773 } |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
774 |
11654 | 775 static void |
776 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 777 { |
11739 | 778 GtkGaimStatusBoxItemType type; |
779 gchar *title; | |
10643 | 780 GtkTreeIter iter; |
11654 | 781 char *message; |
782 GaimSavedStatus *saved_status; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
783 gboolean changed = TRUE; |
10643 | 784 |
11951 | 785 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) |
786 return; | |
11654 | 787 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
11739 | 788 TYPE_COLUMN, &type, |
11638 | 789 TITLE_COLUMN, &title, -1); |
11654 | 790 message = gtk_gaim_status_box_get_message(status_box); |
11739 | 791 |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
792 if (!message || !*message) |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
793 { |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
794 gtk_widget_hide_all(status_box->vbox); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
795 status_box->imhtml_visible = FALSE; |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
796 } |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
797 |
11739 | 798 /* |
799 * If the currently selected status is "Custom..." or | |
11954 | 800 * "Saved..." then do nothing. Custom statuses are |
801 * activated elsewhere, and we update the status_box | |
802 * accordingly by monitoring the preference | |
803 * "/core/status/current" and then calling | |
804 * update_to_reflect_current_status() | |
11739 | 805 */ |
806 if ((type < 0) || (type >= GAIM_STATUS_NUM_PRIMITIVES)) | |
807 return; | |
11654 | 808 |
809 /* TODO: Should save the previous status as a transient status? */ | |
810 | |
11981 | 811 if (status_box->account) { |
812 gint active; | |
813 GaimStatusType *status_type; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
814 GaimStatus *status; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
815 const char *id = NULL; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
816 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
817 status = gaim_account_get_active_status(status_box->account); |
11981 | 818 |
819 g_object_get(G_OBJECT(status_box), "active", &active, NULL); | |
11654 | 820 |
11993 | 821 status_type = find_status_type_by_index(status_box->account, active); |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
822 id = gaim_status_type_get_id(status_type); |
11981 | 823 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
824 if (strncmp(id, gaim_status_get_id(status), strlen(id)) == 0) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
825 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
826 /* Selected status and previous status is the same */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
827 if (!message_changed(message, gaim_status_get_attr_string(status, "message"))) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
828 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
829 } |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
830 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
831 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
832 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
833 if (message) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
834 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
835 TRUE, "message", message, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
836 else |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
837 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
838 TRUE, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
839 } |
11981 | 840 } else { |
841 /* Save the newly selected status to prefs.xml and status.xml */ | |
842 /* TODO: This should be saved as transient. */ | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
843 const char *current = NULL; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
844 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
845 /* Has the status been really changed? */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
846 current = gaim_prefs_get_string("/core/status/current"); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
847 saved_status = gaim_savedstatus_find(current); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
848 if (saved_status && gaim_savedstatus_get_type(saved_status) == type) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
849 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
850 if (!message_changed(gaim_savedstatus_get_message(saved_status), message)) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
851 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
852 } |
11981 | 853 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
854 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
855 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
856 saved_status = gaim_savedstatus_find(_("Default")); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
857 if (saved_status == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
858 saved_status = gaim_savedstatus_new(_("Default"), type); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
859 gaim_savedstatus_set_type(saved_status, type); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
860 gaim_savedstatus_set_message(saved_status, message); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
861 gaim_prefs_set_string("/core/status/current", _("Default")); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
862 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
863 /* Set the status for each account */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
864 gaim_savedstatus_activate(saved_status); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
865 } |
11981 | 866 } |
11627 | 867 |
11638 | 868 g_free(title); |
11654 | 869 g_free(message); |
870 } | |
871 | |
872 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
873 { | |
874 activate_currently_selected_status(status_box); | |
875 | |
876 g_source_remove(status_box->typing); | |
877 status_box->typing = 0; | |
878 gtk_gaim_status_box_refresh(status_box); | |
10643 | 879 } |
880 | |
881 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
882 { | |
11400 | 883 GtkGaimStatusBox *status_box; |
10643 | 884 GtkTreeIter iter; |
11739 | 885 GtkGaimStatusBoxItemType type; |
10643 | 886 char *text, *sec_text; |
887 GdkPixbuf *pixbuf; | |
11960 | 888 GList *accounts = NULL, *node; |
10643 | 889 |
11400 | 890 status_box = GTK_GAIM_STATUS_BOX(box); |
891 | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
892 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
893 return; |
11739 | 894 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
895 TYPE_COLUMN, &type, | |
896 TITLE_COLUMN, &text, | |
10861 | 897 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
11739 | 898 -1); |
10643 | 899 if (status_box->title) |
900 g_free(status_box->title); | |
11638 | 901 status_box->title = text; |
10643 | 902 if (status_box->desc && sec_text) |
11638 | 903 g_free(status_box->desc); |
904 status_box->desc = sec_text; | |
10643 | 905 if (status_box->pixbuf) |
906 g_object_unref(status_box->pixbuf); | |
907 status_box->pixbuf = pixbuf; | |
11638 | 908 if (status_box->typing) |
909 g_source_remove(status_box->typing); | |
910 status_box->typing = 0; | |
10861 | 911 |
11951 | 912 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11729 | 913 { |
11951 | 914 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
915 { | |
916 gaim_gtk_status_editor_show(NULL); | |
917 update_to_reflect_current_status(status_box); | |
918 return; | |
919 } | |
11729 | 920 |
11951 | 921 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
922 { | |
923 gaim_gtk_status_window_show(); | |
924 update_to_reflect_current_status(status_box); | |
925 return; | |
926 } | |
11729 | 927 } |
928 | |
11654 | 929 /* |
11755 | 930 * Show the message box whenever 'type' allows for a |
11960 | 931 * message attribute on any protocol that is enabled, |
932 * or our protocol, if we have account set | |
11654 | 933 */ |
11960 | 934 if (status_box->account) |
935 accounts = g_list_prepend(accounts, status_box->account); | |
936 else | |
937 accounts = gaim_accounts_get_all_active(); | |
11755 | 938 status_box->imhtml_visible = FALSE; |
939 for (node = accounts; node != NULL; node = node->next) | |
940 { | |
941 GaimAccount *account; | |
942 GaimStatusType *status_type; | |
943 | |
944 account = node->data; | |
945 status_type = gaim_account_get_status_type_with_primitive(account, type); | |
946 if ((status_type != NULL) && | |
947 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
948 { | |
949 status_box->imhtml_visible = TRUE; | |
950 break; | |
951 } | |
952 } | |
953 g_list_free(accounts); | |
11654 | 954 |
955 if (status_box->imhtml_visible) | |
956 { | |
10643 | 957 gtk_widget_show_all(status_box->vbox); |
11951 | 958 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
959 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
10643 | 960 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); |
961 gtk_widget_grab_focus(status_box->imhtml); | |
11654 | 962 } |
963 else | |
964 { | |
10643 | 965 gtk_widget_hide_all(status_box->vbox); |
11951 | 966 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11981 | 967 activate_currently_selected_status(status_box); /* This is where we actually set the status */ |
10643 | 968 } |
969 gtk_gaim_status_box_refresh(status_box); | |
970 } | |
971 | |
972 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
973 { | |
974 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
11951 | 975 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(box))) |
976 { | |
977 if (box->typing) { | |
978 gtk_gaim_status_box_pulse_typing(box); | |
979 g_source_remove(box->typing); | |
980 } | |
981 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); | |
10861 | 982 } |
10643 | 983 gtk_gaim_status_box_refresh(box); |
984 } | |
10649 | 985 |
11739 | 986 GtkGaimStatusBoxItemType gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
10649 | 987 { |
988 GtkTreeIter iter; | |
11739 | 989 GtkGaimStatusBoxItemType type; |
10649 | 990 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
10861 | 991 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 992 TYPE_COLUMN, &type, -1); |
993 return type; | |
994 } | |
995 | |
11638 | 996 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 997 { |
998 if (status_box->imhtml_visible) | |
999 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
1000 else | |
1001 return NULL; | |
1002 } |