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