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