Mercurial > pidgin
annotate src/gtkstatusbox.c @ 12139:8500930c005e
[gaim-migrate @ 14440]
ChangeLog the Buddy Pounce manager, cause it's really freakin' sweet.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 18 Nov 2005 22:49:50 +0000 |
parents | 3c1bac709234 |
children | 152748df85cf |
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 GaimSavedStatus *saved_status; | |
12125 | 310 GaimStatusPrimitive primitive; |
311 const char *message; | |
11870 | 312 |
11983 | 313 /* this function is inappropriate for ones with accounts */ |
314 if (status_box->account) | |
315 return; | |
316 | |
12125 | 317 saved_status = gaim_savedstatus_get_current(); |
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 | |
12125 | 325 primitive = gaim_savedstatus_get_type(saved_status); |
326 if (gaim_savedstatus_has_substatuses(saved_status) || | |
327 ((primitive != GAIM_STATUS_AVAILABLE) && | |
328 (primitive != GAIM_STATUS_OFFLINE) && | |
329 (primitive != GAIM_STATUS_AWAY) && | |
330 (primitive != GAIM_STATUS_HIDDEN))) | |
11870 | 331 { |
12125 | 332 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 5); |
11870 | 333 } |
334 else | |
335 { | |
12125 | 336 if (primitive == GAIM_STATUS_AVAILABLE) |
337 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
338 if (primitive == GAIM_STATUS_OFFLINE) | |
339 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3); | |
340 else if (primitive == GAIM_STATUS_AWAY) | |
341 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1); | |
342 else if (primitive == GAIM_STATUS_HIDDEN) | |
343 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2); | |
344 } | |
11870 | 345 |
12125 | 346 message = gaim_savedstatus_get_message(saved_status); |
347 if (!message || !*message) | |
348 { | |
349 status_box->imhtml_visible = FALSE; | |
350 gtk_widget_hide_all(status_box->vbox); | |
351 } | |
352 else | |
353 { | |
354 status_box->imhtml_visible = TRUE; | |
355 gtk_widget_show_all(status_box->vbox); | |
11870 | 356 |
12125 | 357 /* |
358 * Suppress the "changed" signal because the status | |
359 * was changed programmatically. | |
360 */ | |
361 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), FALSE); | |
11954 | 362 |
12125 | 363 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); |
364 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); | |
365 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), TRUE); | |
11870 | 366 } |
11951 | 367 |
368 /* Stop suppressing the "changed" signal. */ | |
369 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); | |
11870 | 370 } |
371 | |
11732 | 372 static void |
373 gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) | |
374 { | |
11739 | 375 GaimAccount *account; |
11732 | 376 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; |
377 GtkIconSize icon_size; | |
378 | |
379 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
380 | |
381 gtk_list_store_clear(status_box->dropdown_store); | |
382 | |
11739 | 383 account = GTK_GAIM_STATUS_BOX(status_box)->account; |
384 if (account == NULL) | |
385 { | |
11756 | 386 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_ONLINE, |
11732 | 387 icon_size, "GtkGaimStatusBox"); |
11756 | 388 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_AWAY, |
11732 | 389 icon_size, "GtkGaimStatusBox"); |
11756 | 390 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
11732 | 391 icon_size, "GtkGaimStatusBox"); |
11756 | 392 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_INVISIBLE, |
11732 | 393 icon_size, "GtkGaimStatusBox"); |
394 /* hacks */ | |
11739 | 395 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AVAILABLE, pixbuf, _("Available"), NULL); |
396 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AWAY, pixbuf2, _("Away"), NULL); | |
397 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_HIDDEN, pixbuf4, _("Invisible"), NULL); | |
398 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_OFFLINE, pixbuf3, _("Offline"), NULL); | |
11738 | 399 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box)); |
11739 | 400 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("Custom..."), NULL); |
401 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL); | |
11732 | 402 |
11870 | 403 update_to_reflect_current_status(status_box); |
11732 | 404 |
405 } else { | |
406 const GList *l; | |
11739 | 407 |
408 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
409 { | |
11732 | 410 GaimStatusType *status_type = (GaimStatusType *)l->data; |
411 | |
412 if (!gaim_status_type_is_user_settable(status_type)) | |
413 continue; | |
414 | |
11739 | 415 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), |
416 gaim_status_type_get_primitive(status_type), | |
12080 | 417 gaim_gtk_create_prpl_icon_with_status(account, status_type), |
11739 | 418 gaim_status_type_get_name(status_type), |
419 NULL); | |
11732 | 420 } |
11967 | 421 update_to_reflect_account_status(status_box, account, gaim_account_get_active_status(account)); |
11732 | 422 } |
423 | |
424 } | |
425 | |
12075
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
426 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
|
427 { |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
428 if (event->direction == GDK_SCROLL_UP) |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
429 gtk_imhtml_page_up(imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
430 else if (event->direction == GDK_SCROLL_DOWN) |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
431 gtk_imhtml_page_down(imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
432 return TRUE; |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
433 } |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
434 |
11753 | 435 #if GTK_CHECK_VERSION(2,6,0) |
11738 | 436 static gboolean |
437 dropdown_store_row_separator_func(GtkTreeModel *model, | |
438 GtkTreeIter *iter, gpointer data) | |
439 { | |
11739 | 440 GtkGaimStatusBoxItemType type; |
11738 | 441 |
11885 | 442 gtk_tree_model_get(model, iter, TYPE_COLUMN, &type, -1); |
11738 | 443 |
11739 | 444 if (type == GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR) |
11738 | 445 return TRUE; |
446 | |
447 return FALSE; | |
448 } | |
11753 | 449 #endif |
11738 | 450 |
10643 | 451 static void |
11954 | 452 current_status_pref_changed_cb(const char *name, GaimPrefType type, |
453 gpointer val, gpointer data) | |
454 { | |
455 update_to_reflect_current_status(data); | |
456 } | |
457 | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
458 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
|
459 { |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
460 if (box->imhtml_visible) |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
461 return; |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
462 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
|
463 } |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
464 |
11954 | 465 static void |
10643 | 466 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) |
467 { | |
11400 | 468 GtkCellRenderer *text_rend; |
469 GtkCellRenderer *icon_rend; | |
10643 | 470 GtkTextBuffer *buffer; |
11732 | 471 GtkTreePath *path; |
11400 | 472 GtkIconSize icon_size; |
473 | |
474 text_rend = gtk_cell_renderer_text_new(); | |
475 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
476 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
10643 | 477 |
478 status_box->imhtml_visible = FALSE; | |
479 status_box->connecting = FALSE; | |
480 status_box->typing = FALSE; | |
481 status_box->title = NULL; | |
10861 | 482 status_box->pixbuf = NULL; |
10643 | 483 status_box->cell_view = gtk_cell_view_new(); |
484 gtk_widget_show (status_box->cell_view); | |
10861 | 485 |
11739 | 486 status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
487 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 | 488 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
489 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
490 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
491 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
492 gtk_gaim_status_box_refresh(status_box); | |
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
493 path = gtk_tree_path_new_from_string("0"); |
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
494 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
|
495 gtk_tree_path_free(path); |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
496 |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
497 status_box->event = gtk_event_box_new(); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
498 gtk_widget_show(status_box->event); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
499 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
|
500 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
|
501 |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
502 gtk_container_add(GTK_CONTAINER(status_box), status_box->event); |
10861 | 503 |
10643 | 504 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
505 status_box->text_rend = gtk_cell_renderer_text_new(); | |
506 | |
507 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
10861 | 508 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 509 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
510 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
511 | |
512 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
11499 | 513 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 514 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
515 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
516 | |
517 status_box->vbox = gtk_vbox_new(0, FALSE); | |
518 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
519 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
520 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
11562 | 521 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 522 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
523 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
524 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
525 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
526 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
527 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
528 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
11654 | 529 |
12075
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
530 g_signal_connect(G_OBJECT(status_box->imhtml), "scroll_event", |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
531 G_CALLBACK(scroll_event_cb), status_box->imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
532 |
11850 | 533 |
534 #if GTK_CHECK_VERSION(2,6,0) | |
535 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); | |
536 #endif | |
537 | |
11756 | 538 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
539 icon_size, "GtkGaimStatusBox"); | |
540 status_box->connecting_index = 0; | |
541 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT0, | |
542 icon_size, "GtkGaimStatusBox"); | |
543 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT1, | |
544 icon_size, "GtkGaimStatusBox"); | |
545 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT2, | |
546 icon_size, "GtkGaimStatusBox"); | |
547 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT3, | |
548 icon_size, "GtkGaimStatusBox"); | |
549 | |
550 status_box->typing_index = 0; | |
551 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING0, | |
552 icon_size, "GtkGaimStatusBox"); | |
553 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING1, | |
554 icon_size, "GtkGaimStatusBox"); | |
555 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING2, | |
556 icon_size, "GtkGaimStatusBox"); | |
557 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING3, | |
558 icon_size, "GtkGaimStatusBox"); | |
559 | |
11732 | 560 gtk_gaim_status_box_regenerate(status_box); |
11954 | 561 |
12123 | 562 /* Monitor changes in the "/core/savedstatus/current" preference */ |
563 gaim_prefs_connect_callback(status_box, "/core/savedstatus/current", | |
11954 | 564 current_status_pref_changed_cb, status_box); |
565 | |
566 /* TODO: Need to override the destroy method for this object and put the following line in it */ | |
567 /* gaim_prefs_disconnect_by_handle(status_box); */ | |
10643 | 568 } |
569 | |
570 static void | |
10861 | 571 gtk_gaim_status_box_size_request(GtkWidget *widget, |
572 GtkRequisition *requisition) | |
10643 | 573 { |
574 GtkRequisition box_req; | |
575 combo_box_size_request(widget, requisition); | |
12103 | 576 requisition->height += 6; |
10861 | 577 |
10643 | 578 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
579 if (box_req.height > 1) | |
580 requisition->height = requisition->height + box_req.height + 6; | |
10861 | 581 |
10643 | 582 requisition->width = 1; |
583 | |
584 } | |
585 | |
586 static void | |
10861 | 587 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
588 GtkAllocation *allocation) | |
10643 | 589 { |
590 GtkRequisition req = {0,0}; | |
11400 | 591 GtkAllocation parent_alc, box_alc; |
592 | |
593 parent_alc = *allocation; | |
594 box_alc = *allocation; | |
10643 | 595 combo_box_size_request(widget, &req); |
10861 | 596 |
12100 | 597 box_alc.height = MAX(1, ((allocation->height) - (req.height) - (12))); |
598 box_alc.y = box_alc.y + req.height + 9; | |
10861 | 599 |
12102
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
600 box_alc.width -= 6; |
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
601 box_alc.x += 3; |
12100 | 602 |
603 | |
10643 | 604 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); |
10861 | 605 |
10643 | 606 parent_alc.height = MAX(1,req.height); |
12102
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
607 parent_alc.width -= 6; |
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
608 parent_alc.x += 3; |
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
609 parent_alc.y += 3; |
12100 | 610 |
10643 | 611 combo_box_size_allocate(widget, &parent_alc); |
612 widget->allocation = *allocation; | |
613 } | |
614 | |
615 | |
616 static gboolean | |
10861 | 617 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
618 GdkEventExpose *event) | |
10643 | 619 { |
10861 | 620 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
621 combo_box_expose_event(widget, event); | |
10643 | 622 |
10861 | 623 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
624 status_box->vbox, event); | |
625 return FALSE; | |
10643 | 626 } |
627 | |
628 static void | |
10861 | 629 gtk_gaim_status_box_forall(GtkContainer *container, |
630 gboolean include_internals, | |
631 GtkCallback callback, | |
632 gpointer callback_data) | |
10643 | 633 { |
10861 | 634 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 635 |
10861 | 636 if (include_internals) |
637 { | |
638 (* callback) (status_box->vbox, callback_data); | |
639 } | |
10643 | 640 |
10861 | 641 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 642 } |
643 | |
644 GtkWidget * | |
645 gtk_gaim_status_box_new() | |
646 { | |
647 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
648 } | |
649 | |
11499 | 650 GtkWidget * |
651 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
652 { | |
653 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
654 } | |
10643 | 655 |
656 void | |
11739 | 657 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *text, const char *sec_text) |
10643 | 658 { |
659 GtkTreeIter iter; | |
660 char *t; | |
10861 | 661 |
10643 | 662 if (sec_text) { |
663 char aa_color[8]; | |
664 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
665 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
666 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
667 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 668 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 669 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
670 } else { | |
671 t = g_strdup(text); | |
672 } | |
10861 | 673 |
10643 | 674 gtk_list_store_append(status_box->dropdown_store, &iter); |
675 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 676 TYPE_COLUMN, type, |
10643 | 677 ICON_COLUMN, pixbuf, |
10861 | 678 TEXT_COLUMN, t, |
10643 | 679 TITLE_COLUMN, text, |
10861 | 680 DESC_COLUMN, sec_text, |
11739 | 681 -1); |
11638 | 682 g_free(t); |
10643 | 683 } |
684 | |
685 void | |
11738 | 686 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
687 { | |
11756 | 688 /* Don't do anything unless GTK actually supports |
689 * gtk_combo_box_set_row_separator_func */ | |
690 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 691 GtkTreeIter iter; |
692 | |
693 gtk_list_store_append(status_box->dropdown_store, &iter); | |
694 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 695 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
696 -1); | |
11756 | 697 #endif |
11738 | 698 } |
699 | |
700 void | |
10643 | 701 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
702 { | |
11523 | 703 if (status_box->error) |
704 g_free(status_box->error); | |
11891 | 705 status_box->error = NULL; |
706 if (error != NULL) | |
707 status_box->error = g_strdup(error); | |
10643 | 708 gtk_gaim_status_box_refresh(status_box); |
709 } | |
710 | |
711 void | |
712 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
713 { | |
714 if (!status_box) | |
715 return; | |
716 status_box->connecting = connecting; | |
717 gtk_gaim_status_box_refresh(status_box); | |
718 } | |
719 | |
720 void | |
721 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
722 { | |
723 if (!status_box) | |
724 return; | |
725 if (status_box->connecting_index == 3) | |
726 status_box->connecting_index = 0; | |
10861 | 727 else |
10643 | 728 status_box->connecting_index++; |
729 gtk_gaim_status_box_refresh(status_box); | |
730 } | |
731 | |
732 void | |
733 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
734 { | |
735 if (status_box->typing_index == 3) | |
736 status_box->typing_index = 0; | |
10861 | 737 else |
10643 | 738 status_box->typing_index++; |
739 gtk_gaim_status_box_refresh(status_box); | |
740 } | |
741 | |
11993 | 742 static GaimStatusType |
743 *find_status_type_by_index(const GaimAccount *account, gint active) | |
744 { | |
745 const GList *l = gaim_account_get_status_types(account); | |
746 gint i; | |
747 | |
748 for (i = 0; l; l = l->next) { | |
749 GaimStatusType *status_type = l->data; | |
750 if (!gaim_status_type_is_user_settable(status_type)) | |
751 continue; | |
752 | |
753 if (active == i) | |
754 return status_type; | |
755 i++; | |
756 } | |
757 | |
758 return NULL; | |
759 } | |
760 | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
761 static gboolean |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
762 message_changed(const char *one, const char *two) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
763 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
764 if (one == NULL && two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
765 return FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
766 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
767 if (one == NULL || two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
768 return TRUE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
769 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
770 return (g_utf8_collate(one, two) != 0); |
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 |
11654 | 773 static void |
774 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 775 { |
11739 | 776 GtkGaimStatusBoxItemType type; |
777 gchar *title; | |
10643 | 778 GtkTreeIter iter; |
11654 | 779 char *message; |
780 GaimSavedStatus *saved_status; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
781 gboolean changed = TRUE; |
10643 | 782 |
11951 | 783 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) |
784 return; | |
11654 | 785 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
11739 | 786 TYPE_COLUMN, &type, |
11638 | 787 TITLE_COLUMN, &title, -1); |
11654 | 788 message = gtk_gaim_status_box_get_message(status_box); |
11739 | 789 |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
790 if (!message || !*message) |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
791 { |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
792 gtk_widget_hide_all(status_box->vbox); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
793 status_box->imhtml_visible = FALSE; |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
794 } |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
795 |
11739 | 796 /* |
797 * If the currently selected status is "Custom..." or | |
11954 | 798 * "Saved..." then do nothing. Custom statuses are |
799 * activated elsewhere, and we update the status_box | |
800 * accordingly by monitoring the preference | |
12123 | 801 * "/core/savedstatus/current" and then calling |
11954 | 802 * update_to_reflect_current_status() |
11739 | 803 */ |
804 if ((type < 0) || (type >= GAIM_STATUS_NUM_PRIMITIVES)) | |
805 return; | |
11654 | 806 |
11981 | 807 if (status_box->account) { |
808 gint active; | |
809 GaimStatusType *status_type; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
810 GaimStatus *status; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
811 const char *id = NULL; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
812 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
813 status = gaim_account_get_active_status(status_box->account); |
11981 | 814 |
815 g_object_get(G_OBJECT(status_box), "active", &active, NULL); | |
11654 | 816 |
11993 | 817 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
|
818 id = gaim_status_type_get_id(status_type); |
11981 | 819 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
820 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
|
821 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
822 /* Selected status and previous status is the same */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
823 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
|
824 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
825 } |
12123 | 826 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
827 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
828 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
829 if (message) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
830 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
831 TRUE, "message", message, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
832 else |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
833 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
834 TRUE, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
835 } |
11981 | 836 } else { |
837 /* Save the newly selected status to prefs.xml and status.xml */ | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
838 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
839 /* Has the status been really changed? */ |
12125 | 840 saved_status = gaim_savedstatus_get_current(); |
841 if (gaim_savedstatus_get_type(saved_status) == type) | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
842 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
843 if (!message_changed(gaim_savedstatus_get_message(saved_status), message)) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
844 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
845 } |
11981 | 846 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
847 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
848 { |
12125 | 849 /* Create a new transient saved status */ |
850 saved_status = gaim_savedstatus_new(NULL, type); | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
851 gaim_savedstatus_set_type(saved_status, type); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
852 gaim_savedstatus_set_message(saved_status, message); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
853 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
854 /* Set the status for each account */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
855 gaim_savedstatus_activate(saved_status); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
856 } |
11981 | 857 } |
11627 | 858 |
11638 | 859 g_free(title); |
11654 | 860 g_free(message); |
861 } | |
862 | |
863 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
864 { | |
865 activate_currently_selected_status(status_box); | |
866 | |
867 g_source_remove(status_box->typing); | |
868 status_box->typing = 0; | |
869 gtk_gaim_status_box_refresh(status_box); | |
10643 | 870 } |
871 | |
872 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
873 { | |
11400 | 874 GtkGaimStatusBox *status_box; |
10643 | 875 GtkTreeIter iter; |
11739 | 876 GtkGaimStatusBoxItemType type; |
10643 | 877 char *text, *sec_text; |
878 GdkPixbuf *pixbuf; | |
11960 | 879 GList *accounts = NULL, *node; |
10643 | 880 |
11400 | 881 status_box = GTK_GAIM_STATUS_BOX(box); |
882 | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
883 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
|
884 return; |
11739 | 885 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
886 TYPE_COLUMN, &type, | |
887 TITLE_COLUMN, &text, | |
10861 | 888 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
11739 | 889 -1); |
10643 | 890 if (status_box->title) |
891 g_free(status_box->title); | |
11638 | 892 status_box->title = text; |
10643 | 893 if (status_box->desc && sec_text) |
11638 | 894 g_free(status_box->desc); |
895 status_box->desc = sec_text; | |
10643 | 896 if (status_box->pixbuf) |
897 g_object_unref(status_box->pixbuf); | |
898 status_box->pixbuf = pixbuf; | |
11638 | 899 if (status_box->typing) |
900 g_source_remove(status_box->typing); | |
901 status_box->typing = 0; | |
10861 | 902 |
11951 | 903 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11729 | 904 { |
11951 | 905 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
906 { | |
907 gaim_gtk_status_editor_show(NULL); | |
908 update_to_reflect_current_status(status_box); | |
909 return; | |
910 } | |
11729 | 911 |
11951 | 912 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
913 { | |
914 gaim_gtk_status_window_show(); | |
915 update_to_reflect_current_status(status_box); | |
916 return; | |
917 } | |
11729 | 918 } |
919 | |
11654 | 920 /* |
11755 | 921 * Show the message box whenever 'type' allows for a |
11960 | 922 * message attribute on any protocol that is enabled, |
923 * or our protocol, if we have account set | |
11654 | 924 */ |
11960 | 925 if (status_box->account) |
926 accounts = g_list_prepend(accounts, status_box->account); | |
927 else | |
928 accounts = gaim_accounts_get_all_active(); | |
11755 | 929 status_box->imhtml_visible = FALSE; |
930 for (node = accounts; node != NULL; node = node->next) | |
931 { | |
932 GaimAccount *account; | |
933 GaimStatusType *status_type; | |
934 | |
935 account = node->data; | |
936 status_type = gaim_account_get_status_type_with_primitive(account, type); | |
937 if ((status_type != NULL) && | |
938 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
939 { | |
940 status_box->imhtml_visible = TRUE; | |
941 break; | |
942 } | |
943 } | |
944 g_list_free(accounts); | |
11654 | 945 |
946 if (status_box->imhtml_visible) | |
947 { | |
10643 | 948 gtk_widget_show_all(status_box->vbox); |
11951 | 949 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
950 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
10643 | 951 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); |
952 gtk_widget_grab_focus(status_box->imhtml); | |
11654 | 953 } |
954 else | |
955 { | |
10643 | 956 gtk_widget_hide_all(status_box->vbox); |
11951 | 957 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11981 | 958 activate_currently_selected_status(status_box); /* This is where we actually set the status */ |
10643 | 959 } |
960 gtk_gaim_status_box_refresh(status_box); | |
961 } | |
962 | |
963 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
964 { | |
965 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
11951 | 966 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(box))) |
967 { | |
968 if (box->typing) { | |
969 gtk_gaim_status_box_pulse_typing(box); | |
970 g_source_remove(box->typing); | |
971 } | |
972 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); | |
10861 | 973 } |
10643 | 974 gtk_gaim_status_box_refresh(box); |
975 } | |
10649 | 976 |
11739 | 977 GtkGaimStatusBoxItemType gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
10649 | 978 { |
979 GtkTreeIter iter; | |
11739 | 980 GtkGaimStatusBoxItemType type; |
10649 | 981 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
10861 | 982 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 983 TYPE_COLUMN, &type, -1); |
984 return type; | |
985 } | |
986 | |
11638 | 987 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 988 { |
989 if (status_box->imhtml_visible) | |
990 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
991 else | |
992 return NULL; | |
993 } |