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