Mercurial > pidgin.yaz
annotate src/gtkstatusbox.c @ 12250:5e2a365af01b
[gaim-migrate @ 14552]
Change some *_unref() reference count guards into g_return_if_fail()/g_return_val_if_fail(). That way we'll get a debug message if they fail, not that they ever should, of course.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 28 Nov 2005 11:47:50 +0000 |
parents | 65477e67a712 |
children | 0eed625872f7 |
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 { | |
12244 | 460 GtkGaimStatusBox *box = data; |
461 if (box->account) | |
462 update_to_reflect_account_status(box, box->account, | |
463 gaim_account_get_active_status(box->account)); | |
464 else | |
465 update_to_reflect_current_status(box); | |
11954 | 466 } |
467 | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
468 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
|
469 { |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
470 if (box->imhtml_visible) |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
471 return; |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
472 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
|
473 } |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
474 |
11954 | 475 static void |
10643 | 476 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) |
477 { | |
11400 | 478 GtkCellRenderer *text_rend; |
479 GtkCellRenderer *icon_rend; | |
10643 | 480 GtkTextBuffer *buffer; |
11732 | 481 GtkTreePath *path; |
11400 | 482 GtkIconSize icon_size; |
483 | |
484 text_rend = gtk_cell_renderer_text_new(); | |
485 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
486 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
10643 | 487 |
488 status_box->imhtml_visible = FALSE; | |
489 status_box->connecting = FALSE; | |
490 status_box->typing = FALSE; | |
491 status_box->title = NULL; | |
10861 | 492 status_box->pixbuf = NULL; |
10643 | 493 status_box->cell_view = gtk_cell_view_new(); |
494 gtk_widget_show (status_box->cell_view); | |
10861 | 495 |
11739 | 496 status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
497 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 | 498 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
499 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
500 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
501 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
502 gtk_gaim_status_box_refresh(status_box); | |
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
503 path = gtk_tree_path_new_from_string("0"); |
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
504 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
|
505 gtk_tree_path_free(path); |
12074
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 status_box->event = gtk_event_box_new(); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
508 gtk_widget_show(status_box->event); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
509 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
|
510 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
|
511 |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
512 gtk_container_add(GTK_CONTAINER(status_box), status_box->event); |
10861 | 513 |
10643 | 514 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
515 status_box->text_rend = gtk_cell_renderer_text_new(); | |
516 | |
517 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
10861 | 518 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 519 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
520 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
521 | |
522 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
11499 | 523 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 524 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
525 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
526 | |
527 status_box->vbox = gtk_vbox_new(0, FALSE); | |
528 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
529 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
530 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
11562 | 531 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 532 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
533 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
534 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
535 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
536 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
537 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
538 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
11654 | 539 |
12075
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
540 g_signal_connect(G_OBJECT(status_box->imhtml), "scroll_event", |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
541 G_CALLBACK(scroll_event_cb), status_box->imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
542 |
11850 | 543 |
544 #if GTK_CHECK_VERSION(2,6,0) | |
545 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); | |
546 #endif | |
547 | |
11756 | 548 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
549 icon_size, "GtkGaimStatusBox"); | |
550 status_box->connecting_index = 0; | |
551 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT0, | |
552 icon_size, "GtkGaimStatusBox"); | |
553 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT1, | |
554 icon_size, "GtkGaimStatusBox"); | |
555 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT2, | |
556 icon_size, "GtkGaimStatusBox"); | |
557 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT3, | |
558 icon_size, "GtkGaimStatusBox"); | |
559 | |
560 status_box->typing_index = 0; | |
561 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING0, | |
562 icon_size, "GtkGaimStatusBox"); | |
563 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING1, | |
564 icon_size, "GtkGaimStatusBox"); | |
565 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING2, | |
566 icon_size, "GtkGaimStatusBox"); | |
567 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING3, | |
568 icon_size, "GtkGaimStatusBox"); | |
569 | |
11732 | 570 gtk_gaim_status_box_regenerate(status_box); |
11954 | 571 |
12123 | 572 /* Monitor changes in the "/core/savedstatus/current" preference */ |
573 gaim_prefs_connect_callback(status_box, "/core/savedstatus/current", | |
11954 | 574 current_status_pref_changed_cb, status_box); |
575 | |
576 /* TODO: Need to override the destroy method for this object and put the following line in it */ | |
577 /* gaim_prefs_disconnect_by_handle(status_box); */ | |
10643 | 578 } |
579 | |
580 static void | |
10861 | 581 gtk_gaim_status_box_size_request(GtkWidget *widget, |
582 GtkRequisition *requisition) | |
10643 | 583 { |
584 GtkRequisition box_req; | |
585 combo_box_size_request(widget, requisition); | |
12103 | 586 requisition->height += 6; |
10861 | 587 |
10643 | 588 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
589 if (box_req.height > 1) | |
590 requisition->height = requisition->height + box_req.height + 6; | |
10861 | 591 |
10643 | 592 requisition->width = 1; |
593 | |
594 } | |
595 | |
596 static void | |
10861 | 597 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
598 GtkAllocation *allocation) | |
10643 | 599 { |
600 GtkRequisition req = {0,0}; | |
11400 | 601 GtkAllocation parent_alc, box_alc; |
602 | |
603 parent_alc = *allocation; | |
604 box_alc = *allocation; | |
10643 | 605 combo_box_size_request(widget, &req); |
10861 | 606 |
12100 | 607 box_alc.height = MAX(1, ((allocation->height) - (req.height) - (12))); |
608 box_alc.y = box_alc.y + req.height + 9; | |
10861 | 609 |
12102
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
610 box_alc.width -= 6; |
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
611 box_alc.x += 3; |
12100 | 612 |
613 | |
10643 | 614 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); |
10861 | 615 |
10643 | 616 parent_alc.height = MAX(1,req.height); |
12102
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
617 parent_alc.width -= 6; |
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
618 parent_alc.x += 3; |
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
619 parent_alc.y += 3; |
12100 | 620 |
10643 | 621 combo_box_size_allocate(widget, &parent_alc); |
622 widget->allocation = *allocation; | |
623 } | |
624 | |
625 | |
626 static gboolean | |
10861 | 627 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
628 GdkEventExpose *event) | |
10643 | 629 { |
10861 | 630 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
631 combo_box_expose_event(widget, event); | |
10643 | 632 |
10861 | 633 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
634 status_box->vbox, event); | |
635 return FALSE; | |
10643 | 636 } |
637 | |
638 static void | |
10861 | 639 gtk_gaim_status_box_forall(GtkContainer *container, |
640 gboolean include_internals, | |
641 GtkCallback callback, | |
642 gpointer callback_data) | |
10643 | 643 { |
10861 | 644 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 645 |
10861 | 646 if (include_internals) |
647 { | |
648 (* callback) (status_box->vbox, callback_data); | |
649 } | |
10643 | 650 |
10861 | 651 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 652 } |
653 | |
654 GtkWidget * | |
655 gtk_gaim_status_box_new() | |
656 { | |
657 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
658 } | |
659 | |
11499 | 660 GtkWidget * |
661 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
662 { | |
663 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
664 } | |
10643 | 665 |
666 void | |
11739 | 667 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *text, const char *sec_text) |
10643 | 668 { |
669 GtkTreeIter iter; | |
670 char *t; | |
10861 | 671 |
10643 | 672 if (sec_text) { |
673 char aa_color[8]; | |
674 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
675 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
676 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
677 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 678 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 679 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
680 } else { | |
681 t = g_strdup(text); | |
682 } | |
10861 | 683 |
10643 | 684 gtk_list_store_append(status_box->dropdown_store, &iter); |
685 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 686 TYPE_COLUMN, type, |
10643 | 687 ICON_COLUMN, pixbuf, |
10861 | 688 TEXT_COLUMN, t, |
10643 | 689 TITLE_COLUMN, text, |
10861 | 690 DESC_COLUMN, sec_text, |
11739 | 691 -1); |
11638 | 692 g_free(t); |
10643 | 693 } |
694 | |
695 void | |
11738 | 696 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
697 { | |
11756 | 698 /* Don't do anything unless GTK actually supports |
699 * gtk_combo_box_set_row_separator_func */ | |
700 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 701 GtkTreeIter iter; |
702 | |
703 gtk_list_store_append(status_box->dropdown_store, &iter); | |
704 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 705 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
706 -1); | |
11756 | 707 #endif |
11738 | 708 } |
709 | |
710 void | |
10643 | 711 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
712 { | |
11523 | 713 if (status_box->error) |
714 g_free(status_box->error); | |
11891 | 715 status_box->error = NULL; |
716 if (error != NULL) | |
717 status_box->error = g_strdup(error); | |
10643 | 718 gtk_gaim_status_box_refresh(status_box); |
719 } | |
720 | |
721 void | |
722 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
723 { | |
724 if (!status_box) | |
725 return; | |
726 status_box->connecting = connecting; | |
727 gtk_gaim_status_box_refresh(status_box); | |
728 } | |
729 | |
730 void | |
731 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
732 { | |
733 if (!status_box) | |
734 return; | |
735 if (status_box->connecting_index == 3) | |
736 status_box->connecting_index = 0; | |
10861 | 737 else |
10643 | 738 status_box->connecting_index++; |
739 gtk_gaim_status_box_refresh(status_box); | |
740 } | |
741 | |
742 void | |
743 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
744 { | |
745 if (status_box->typing_index == 3) | |
746 status_box->typing_index = 0; | |
10861 | 747 else |
10643 | 748 status_box->typing_index++; |
749 gtk_gaim_status_box_refresh(status_box); | |
750 } | |
751 | |
11993 | 752 static GaimStatusType |
753 *find_status_type_by_index(const GaimAccount *account, gint active) | |
754 { | |
755 const GList *l = gaim_account_get_status_types(account); | |
756 gint i; | |
757 | |
758 for (i = 0; l; l = l->next) { | |
759 GaimStatusType *status_type = l->data; | |
760 if (!gaim_status_type_is_user_settable(status_type)) | |
761 continue; | |
762 | |
763 if (active == i) | |
764 return status_type; | |
765 i++; | |
766 } | |
767 | |
768 return NULL; | |
769 } | |
770 | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
771 static gboolean |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
772 message_changed(const char *one, const char *two) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
773 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
774 if (one == NULL && two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
775 return FALSE; |
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 if (one == NULL || two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
778 return TRUE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
779 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
780 return (g_utf8_collate(one, two) != 0); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
781 } |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
782 |
11654 | 783 static void |
784 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 785 { |
11739 | 786 GtkGaimStatusBoxItemType type; |
787 gchar *title; | |
10643 | 788 GtkTreeIter iter; |
11654 | 789 char *message; |
790 GaimSavedStatus *saved_status; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
791 gboolean changed = TRUE; |
10643 | 792 |
11951 | 793 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) |
794 return; | |
11654 | 795 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
11739 | 796 TYPE_COLUMN, &type, |
11638 | 797 TITLE_COLUMN, &title, -1); |
11654 | 798 message = gtk_gaim_status_box_get_message(status_box); |
11739 | 799 |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
800 if (!message || !*message) |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
801 { |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
802 gtk_widget_hide_all(status_box->vbox); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
803 status_box->imhtml_visible = FALSE; |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
804 } |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
805 |
11739 | 806 /* |
807 * If the currently selected status is "Custom..." or | |
11954 | 808 * "Saved..." then do nothing. Custom statuses are |
809 * activated elsewhere, and we update the status_box | |
810 * accordingly by monitoring the preference | |
12123 | 811 * "/core/savedstatus/current" and then calling |
11954 | 812 * update_to_reflect_current_status() |
11739 | 813 */ |
12221
152748df85cf
[gaim-migrate @ 14523]
Richard Laager <rlaager@wiktel.com>
parents:
12125
diff
changeset
|
814 if (type >= GAIM_STATUS_NUM_PRIMITIVES) |
11739 | 815 return; |
11654 | 816 |
11981 | 817 if (status_box->account) { |
818 gint active; | |
819 GaimStatusType *status_type; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
820 GaimStatus *status; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
821 const char *id = NULL; |
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 status = gaim_account_get_active_status(status_box->account); |
11981 | 824 |
825 g_object_get(G_OBJECT(status_box), "active", &active, NULL); | |
11654 | 826 |
11993 | 827 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
|
828 id = gaim_status_type_get_id(status_type); |
11981 | 829 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
830 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
|
831 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
832 /* Selected status and previous status is the same */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
833 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
|
834 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
835 } |
12123 | 836 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
837 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
838 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
839 if (message) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
840 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
841 TRUE, "message", message, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
842 else |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
843 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
844 TRUE, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
845 } |
11981 | 846 } else { |
847 /* 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
|
848 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
849 /* Has the status been really changed? */ |
12125 | 850 saved_status = gaim_savedstatus_get_current(); |
851 if (gaim_savedstatus_get_type(saved_status) == type) | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
852 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
853 if (!message_changed(gaim_savedstatus_get_message(saved_status), message)) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
854 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
855 } |
11981 | 856 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
857 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
858 { |
12125 | 859 /* Create a new transient saved status */ |
860 saved_status = gaim_savedstatus_new(NULL, type); | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
861 gaim_savedstatus_set_type(saved_status, type); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
862 gaim_savedstatus_set_message(saved_status, message); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
863 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
864 /* Set the status for each account */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
865 gaim_savedstatus_activate(saved_status); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
866 } |
11981 | 867 } |
11627 | 868 |
11638 | 869 g_free(title); |
11654 | 870 g_free(message); |
871 } | |
872 | |
873 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
874 { | |
875 activate_currently_selected_status(status_box); | |
876 | |
877 g_source_remove(status_box->typing); | |
878 status_box->typing = 0; | |
879 gtk_gaim_status_box_refresh(status_box); | |
10643 | 880 } |
881 | |
882 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
883 { | |
11400 | 884 GtkGaimStatusBox *status_box; |
10643 | 885 GtkTreeIter iter; |
11739 | 886 GtkGaimStatusBoxItemType type; |
10643 | 887 char *text, *sec_text; |
888 GdkPixbuf *pixbuf; | |
11960 | 889 GList *accounts = NULL, *node; |
10643 | 890 |
11400 | 891 status_box = GTK_GAIM_STATUS_BOX(box); |
892 | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
893 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
|
894 return; |
11739 | 895 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
896 TYPE_COLUMN, &type, | |
897 TITLE_COLUMN, &text, | |
10861 | 898 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
11739 | 899 -1); |
10643 | 900 if (status_box->title) |
901 g_free(status_box->title); | |
11638 | 902 status_box->title = text; |
10643 | 903 if (status_box->desc && sec_text) |
11638 | 904 g_free(status_box->desc); |
905 status_box->desc = sec_text; | |
10643 | 906 if (status_box->pixbuf) |
907 g_object_unref(status_box->pixbuf); | |
908 status_box->pixbuf = pixbuf; | |
11638 | 909 if (status_box->typing) |
910 g_source_remove(status_box->typing); | |
911 status_box->typing = 0; | |
10861 | 912 |
11951 | 913 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11729 | 914 { |
11951 | 915 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
916 { | |
917 gaim_gtk_status_editor_show(NULL); | |
918 update_to_reflect_current_status(status_box); | |
919 return; | |
920 } | |
11729 | 921 |
11951 | 922 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
923 { | |
924 gaim_gtk_status_window_show(); | |
925 update_to_reflect_current_status(status_box); | |
926 return; | |
927 } | |
11729 | 928 } |
929 | |
11654 | 930 /* |
11755 | 931 * Show the message box whenever 'type' allows for a |
11960 | 932 * message attribute on any protocol that is enabled, |
933 * or our protocol, if we have account set | |
11654 | 934 */ |
11960 | 935 if (status_box->account) |
936 accounts = g_list_prepend(accounts, status_box->account); | |
937 else | |
938 accounts = gaim_accounts_get_all_active(); | |
11755 | 939 status_box->imhtml_visible = FALSE; |
940 for (node = accounts; node != NULL; node = node->next) | |
941 { | |
942 GaimAccount *account; | |
943 GaimStatusType *status_type; | |
944 | |
945 account = node->data; | |
946 status_type = gaim_account_get_status_type_with_primitive(account, type); | |
947 if ((status_type != NULL) && | |
948 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
949 { | |
950 status_box->imhtml_visible = TRUE; | |
951 break; | |
952 } | |
953 } | |
954 g_list_free(accounts); | |
11654 | 955 |
956 if (status_box->imhtml_visible) | |
957 { | |
10643 | 958 gtk_widget_show_all(status_box->vbox); |
11951 | 959 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
960 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
10643 | 961 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); |
962 gtk_widget_grab_focus(status_box->imhtml); | |
11654 | 963 } |
964 else | |
965 { | |
10643 | 966 gtk_widget_hide_all(status_box->vbox); |
11951 | 967 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11981 | 968 activate_currently_selected_status(status_box); /* This is where we actually set the status */ |
10643 | 969 } |
970 gtk_gaim_status_box_refresh(status_box); | |
971 } | |
972 | |
973 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
974 { | |
975 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
11951 | 976 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(box))) |
977 { | |
978 if (box->typing) { | |
979 gtk_gaim_status_box_pulse_typing(box); | |
980 g_source_remove(box->typing); | |
981 } | |
982 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); | |
10861 | 983 } |
10643 | 984 gtk_gaim_status_box_refresh(box); |
985 } | |
10649 | 986 |
11739 | 987 GtkGaimStatusBoxItemType gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
10649 | 988 { |
989 GtkTreeIter iter; | |
11739 | 990 GtkGaimStatusBoxItemType type; |
10649 | 991 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
10861 | 992 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 993 TYPE_COLUMN, &type, -1); |
994 return type; | |
995 } | |
996 | |
11638 | 997 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 998 { |
999 if (status_box->imhtml_visible) | |
1000 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
1001 else | |
1002 return NULL; | |
1003 } |