Mercurial > pidgin.yaz
annotate src/gtkstatusbox.c @ 12275:0d6aeb831975
[gaim-migrate @ 14579]
Fixes the "overlap" thing and the "have to hold down the mouse button" thing
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Wed, 30 Nov 2005 21:28:53 +0000 |
parents | 3d9ef8a98074 |
children | 255e6912607b |
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); | |
12274 | 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 } | |
12256 | 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)); |
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 { |
12274 | 501 |
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); | |
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(); | |
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 |
12075
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
610 g_signal_connect(G_OBJECT(status_box->imhtml), "scroll_event", |
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 |
614 #if GTK_CHECK_VERSION(2,6,0) | |
615 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); | |
616 #endif | |
617 | |
11756 | 618 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
619 icon_size, "GtkGaimStatusBox"); | |
620 status_box->connecting_index = 0; | |
621 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT0, | |
622 icon_size, "GtkGaimStatusBox"); | |
623 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT1, | |
624 icon_size, "GtkGaimStatusBox"); | |
625 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT2, | |
626 icon_size, "GtkGaimStatusBox"); | |
627 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT3, | |
628 icon_size, "GtkGaimStatusBox"); | |
629 | |
630 status_box->typing_index = 0; | |
631 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING0, | |
632 icon_size, "GtkGaimStatusBox"); | |
633 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING1, | |
634 icon_size, "GtkGaimStatusBox"); | |
635 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING2, | |
636 icon_size, "GtkGaimStatusBox"); | |
637 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING3, | |
638 icon_size, "GtkGaimStatusBox"); | |
639 | |
11732 | 640 gtk_gaim_status_box_regenerate(status_box); |
11954 | 641 |
12123 | 642 /* Monitor changes in the "/core/savedstatus/current" preference */ |
643 gaim_prefs_connect_callback(status_box, "/core/savedstatus/current", | |
11954 | 644 current_status_pref_changed_cb, status_box); |
645 | |
646 /* TODO: Need to override the destroy method for this object and put the following line in it */ | |
647 /* gaim_prefs_disconnect_by_handle(status_box); */ | |
10643 | 648 } |
649 | |
650 static void | |
10861 | 651 gtk_gaim_status_box_size_request(GtkWidget *widget, |
652 GtkRequisition *requisition) | |
10643 | 653 { |
654 GtkRequisition box_req; | |
655 combo_box_size_request(widget, requisition); | |
12103 | 656 requisition->height += 6; |
10861 | 657 |
10643 | 658 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
659 if (box_req.height > 1) | |
660 requisition->height = requisition->height + box_req.height + 6; | |
12269 | 661 |
662 if (GTK_GAIM_STATUS_BOX(widget)->typing) { | |
663 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->toolbar, &box_req); | |
664 requisition->height = requisition->height + box_req.height; | |
665 } | |
666 | |
10643 | 667 requisition->width = 1; |
668 | |
669 } | |
670 | |
671 static void | |
10861 | 672 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
673 GtkAllocation *allocation) | |
10643 | 674 { |
675 GtkRequisition req = {0,0}; | |
11400 | 676 GtkAllocation parent_alc, box_alc; |
677 | |
678 parent_alc = *allocation; | |
679 box_alc = *allocation; | |
10643 | 680 combo_box_size_request(widget, &req); |
10861 | 681 |
12100 | 682 box_alc.height = MAX(1, ((allocation->height) - (req.height) - (12))); |
683 box_alc.y = box_alc.y + req.height + 9; | |
10861 | 684 |
12102
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
685 box_alc.width -= 6; |
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
686 box_alc.x += 3; |
12100 | 687 |
688 | |
10643 | 689 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); |
10861 | 690 |
10643 | 691 parent_alc.height = MAX(1,req.height); |
12102
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
692 parent_alc.width -= 6; |
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
693 parent_alc.x += 3; |
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
694 parent_alc.y += 3; |
12100 | 695 |
10643 | 696 combo_box_size_allocate(widget, &parent_alc); |
12262 | 697 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->toggle_button, &parent_alc); |
10643 | 698 widget->allocation = *allocation; |
699 } | |
700 | |
701 | |
702 static gboolean | |
10861 | 703 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
12262 | 704 GdkEventExpose *event) |
10643 | 705 { |
10861 | 706 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
12262 | 707 gtk_container_propagate_expose(GTK_CONTAINER(widget), status_box->vbox, event); |
12275 | 708 gtk_container_propagate_expose(GTK_CONTAINER(widget), status_box->toggle_button, event); |
10861 | 709 return FALSE; |
10643 | 710 } |
711 | |
712 static void | |
10861 | 713 gtk_gaim_status_box_forall(GtkContainer *container, |
714 gboolean include_internals, | |
715 GtkCallback callback, | |
716 gpointer callback_data) | |
10643 | 717 { |
10861 | 718 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 719 |
10861 | 720 if (include_internals) |
721 { | |
722 (* callback) (status_box->vbox, callback_data); | |
12275 | 723 (* callback) (status_box->toggle_button, callback_data); |
724 (* callback) (status_box->arrow, callback_data); | |
10861 | 725 } |
10643 | 726 |
10861 | 727 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 728 } |
729 | |
730 GtkWidget * | |
731 gtk_gaim_status_box_new() | |
732 { | |
733 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
734 } | |
735 | |
11499 | 736 GtkWidget * |
737 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
738 { | |
739 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
740 } | |
10643 | 741 |
742 void | |
11739 | 743 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *text, const char *sec_text) |
10643 | 744 { |
745 GtkTreeIter iter; | |
746 char *t; | |
10861 | 747 |
10643 | 748 if (sec_text) { |
749 char aa_color[8]; | |
750 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
751 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
752 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
753 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 754 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
10643 | 755 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
756 } else { | |
757 t = g_strdup(text); | |
758 } | |
10861 | 759 |
10643 | 760 gtk_list_store_append(status_box->dropdown_store, &iter); |
761 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 762 TYPE_COLUMN, type, |
10643 | 763 ICON_COLUMN, pixbuf, |
10861 | 764 TEXT_COLUMN, t, |
10643 | 765 TITLE_COLUMN, text, |
10861 | 766 DESC_COLUMN, sec_text, |
11739 | 767 -1); |
11638 | 768 g_free(t); |
10643 | 769 } |
770 | |
771 void | |
11738 | 772 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
773 { | |
11756 | 774 /* Don't do anything unless GTK actually supports |
775 * gtk_combo_box_set_row_separator_func */ | |
776 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 777 GtkTreeIter iter; |
778 | |
779 gtk_list_store_append(status_box->dropdown_store, &iter); | |
780 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 781 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
782 -1); | |
11756 | 783 #endif |
11738 | 784 } |
785 | |
786 void | |
10643 | 787 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
788 { | |
11523 | 789 if (status_box->error) |
790 g_free(status_box->error); | |
11891 | 791 status_box->error = NULL; |
792 if (error != NULL) | |
793 status_box->error = g_strdup(error); | |
10643 | 794 gtk_gaim_status_box_refresh(status_box); |
795 } | |
796 | |
797 void | |
798 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
799 { | |
800 if (!status_box) | |
801 return; | |
802 status_box->connecting = connecting; | |
803 gtk_gaim_status_box_refresh(status_box); | |
804 } | |
805 | |
806 void | |
807 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
808 { | |
809 if (!status_box) | |
810 return; | |
811 if (status_box->connecting_index == 3) | |
812 status_box->connecting_index = 0; | |
10861 | 813 else |
10643 | 814 status_box->connecting_index++; |
815 gtk_gaim_status_box_refresh(status_box); | |
816 } | |
817 | |
12274 | 818 static void |
10643 | 819 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) |
820 { | |
821 if (status_box->typing_index == 3) | |
822 status_box->typing_index = 0; | |
10861 | 823 else |
10643 | 824 status_box->typing_index++; |
825 gtk_gaim_status_box_refresh(status_box); | |
826 } | |
827 | |
11993 | 828 static GaimStatusType |
829 *find_status_type_by_index(const GaimAccount *account, gint active) | |
830 { | |
831 const GList *l = gaim_account_get_status_types(account); | |
832 gint i; | |
833 | |
834 for (i = 0; l; l = l->next) { | |
835 GaimStatusType *status_type = l->data; | |
836 if (!gaim_status_type_is_user_settable(status_type)) | |
837 continue; | |
838 | |
839 if (active == i) | |
840 return status_type; | |
841 i++; | |
842 } | |
843 | |
844 return NULL; | |
845 } | |
846 | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
847 static gboolean |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
848 message_changed(const char *one, const char *two) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
849 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
850 if (one == NULL && two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
851 return FALSE; |
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 (one == NULL || two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
854 return TRUE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
855 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
856 return (g_utf8_collate(one, two) != 0); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
857 } |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
858 |
11654 | 859 static void |
860 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 861 { |
11739 | 862 GtkGaimStatusBoxItemType type; |
863 gchar *title; | |
10643 | 864 GtkTreeIter iter; |
11654 | 865 char *message; |
866 GaimSavedStatus *saved_status; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
867 gboolean changed = TRUE; |
10643 | 868 |
11951 | 869 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) |
870 return; | |
11654 | 871 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
11739 | 872 TYPE_COLUMN, &type, |
11638 | 873 TITLE_COLUMN, &title, -1); |
11654 | 874 message = gtk_gaim_status_box_get_message(status_box); |
11739 | 875 |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
876 if (!message || !*message) |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
877 { |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
878 gtk_widget_hide_all(status_box->vbox); |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
879 status_box->imhtml_visible = FALSE; |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
880 } |
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
881 |
11739 | 882 /* |
883 * If the currently selected status is "Custom..." or | |
11954 | 884 * "Saved..." then do nothing. Custom statuses are |
885 * activated elsewhere, and we update the status_box | |
886 * accordingly by monitoring the preference | |
12123 | 887 * "/core/savedstatus/current" and then calling |
11954 | 888 * update_to_reflect_current_status() |
11739 | 889 */ |
12221
152748df85cf
[gaim-migrate @ 14523]
Richard Laager <rlaager@wiktel.com>
parents:
12125
diff
changeset
|
890 if (type >= GAIM_STATUS_NUM_PRIMITIVES) |
11739 | 891 return; |
11654 | 892 |
11981 | 893 if (status_box->account) { |
894 gint active; | |
895 GaimStatusType *status_type; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
896 GaimStatus *status; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
897 const char *id = NULL; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
898 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
899 status = gaim_account_get_active_status(status_box->account); |
11981 | 900 |
901 g_object_get(G_OBJECT(status_box), "active", &active, NULL); | |
11654 | 902 |
11993 | 903 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
|
904 id = gaim_status_type_get_id(status_type); |
11981 | 905 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
906 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
|
907 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
908 /* Selected status and previous status is the same */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
909 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
|
910 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
911 } |
12123 | 912 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
913 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
914 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
915 if (message) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
916 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
917 TRUE, "message", message, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
918 else |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
919 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
920 TRUE, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
921 } |
11981 | 922 } else { |
923 /* 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
|
924 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
925 /* Has the status been really changed? */ |
12125 | 926 saved_status = gaim_savedstatus_get_current(); |
927 if (gaim_savedstatus_get_type(saved_status) == type) | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
928 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
929 if (!message_changed(gaim_savedstatus_get_message(saved_status), message)) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
930 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
931 } |
11981 | 932 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
933 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
934 { |
12125 | 935 /* Create a new transient saved status */ |
936 saved_status = gaim_savedstatus_new(NULL, type); | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
937 gaim_savedstatus_set_type(saved_status, type); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
938 gaim_savedstatus_set_message(saved_status, message); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
939 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
940 /* Set the status for each account */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
941 gaim_savedstatus_activate(saved_status); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
942 } |
11981 | 943 } |
11627 | 944 |
11638 | 945 g_free(title); |
11654 | 946 g_free(message); |
947 } | |
948 | |
949 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
950 { | |
951 activate_currently_selected_status(status_box); | |
952 | |
953 g_source_remove(status_box->typing); | |
954 status_box->typing = 0; | |
955 gtk_gaim_status_box_refresh(status_box); | |
10643 | 956 } |
957 | |
958 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
959 { | |
11400 | 960 GtkGaimStatusBox *status_box; |
10643 | 961 GtkTreeIter iter; |
11739 | 962 GtkGaimStatusBoxItemType type; |
10643 | 963 char *text, *sec_text; |
964 GdkPixbuf *pixbuf; | |
11960 | 965 GList *accounts = NULL, *node; |
10643 | 966 |
11400 | 967 status_box = GTK_GAIM_STATUS_BOX(box); |
968 | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
969 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
|
970 return; |
11739 | 971 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
972 TYPE_COLUMN, &type, | |
973 TITLE_COLUMN, &text, | |
10861 | 974 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
11739 | 975 -1); |
10643 | 976 if (status_box->title) |
977 g_free(status_box->title); | |
11638 | 978 status_box->title = text; |
10643 | 979 if (status_box->desc && sec_text) |
11638 | 980 g_free(status_box->desc); |
981 status_box->desc = sec_text; | |
10643 | 982 if (status_box->pixbuf) |
983 g_object_unref(status_box->pixbuf); | |
984 status_box->pixbuf = pixbuf; | |
11638 | 985 if (status_box->typing) |
986 g_source_remove(status_box->typing); | |
987 status_box->typing = 0; | |
12269 | 988 gtk_widget_hide(status_box->hsep); |
989 gtk_widget_hide(status_box->toolbar); | |
10861 | 990 |
11951 | 991 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11729 | 992 { |
11951 | 993 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
994 { | |
995 gaim_gtk_status_editor_show(NULL); | |
996 update_to_reflect_current_status(status_box); | |
997 return; | |
998 } | |
11729 | 999 |
11951 | 1000 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
1001 { | |
1002 gaim_gtk_status_window_show(); | |
1003 update_to_reflect_current_status(status_box); | |
1004 return; | |
1005 } | |
11729 | 1006 } |
1007 | |
11654 | 1008 /* |
11755 | 1009 * Show the message box whenever 'type' allows for a |
11960 | 1010 * message attribute on any protocol that is enabled, |
1011 * or our protocol, if we have account set | |
11654 | 1012 */ |
11960 | 1013 if (status_box->account) |
1014 accounts = g_list_prepend(accounts, status_box->account); | |
1015 else | |
1016 accounts = gaim_accounts_get_all_active(); | |
11755 | 1017 status_box->imhtml_visible = FALSE; |
1018 for (node = accounts; node != NULL; node = node->next) | |
1019 { | |
1020 GaimAccount *account; | |
1021 GaimStatusType *status_type; | |
1022 | |
1023 account = node->data; | |
1024 status_type = gaim_account_get_status_type_with_primitive(account, type); | |
1025 if ((status_type != NULL) && | |
1026 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
1027 { | |
1028 status_box->imhtml_visible = TRUE; | |
1029 break; | |
1030 } | |
1031 } | |
1032 g_list_free(accounts); | |
11654 | 1033 |
1034 if (status_box->imhtml_visible) | |
1035 { | |
10643 | 1036 gtk_widget_show_all(status_box->vbox); |
12274 | 1037 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) { |
11951 | 1038 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); |
12274 | 1039 } else { |
1040 gtk_widget_hide(status_box->toolbar); | |
1041 gtk_widget_hide(status_box->hsep); | |
1042 } | |
10643 | 1043 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); |
12274 | 1044 gtk_imhtml_clear_formatting(GTK_IMHTML(status_box->imhtml)); |
10643 | 1045 gtk_widget_grab_focus(status_box->imhtml); |
11654 | 1046 } |
1047 else | |
1048 { | |
10643 | 1049 gtk_widget_hide_all(status_box->vbox); |
11951 | 1050 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11981 | 1051 activate_currently_selected_status(status_box); /* This is where we actually set the status */ |
10643 | 1052 } |
1053 gtk_gaim_status_box_refresh(status_box); | |
1054 } | |
1055 | |
1056 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
1057 { | |
1058 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
11951 | 1059 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(box))) |
1060 { | |
1061 if (box->typing) { | |
1062 gtk_gaim_status_box_pulse_typing(box); | |
1063 g_source_remove(box->typing); | |
1064 } | |
1065 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); | |
12269 | 1066 gtk_widget_show(box->hsep); |
1067 gtk_widget_show(box->toolbar); | |
10861 | 1068 } |
10643 | 1069 gtk_gaim_status_box_refresh(box); |
1070 } | |
10649 | 1071 |
11739 | 1072 GtkGaimStatusBoxItemType gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
10649 | 1073 { |
1074 GtkTreeIter iter; | |
11739 | 1075 GtkGaimStatusBoxItemType type; |
10649 | 1076 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
10861 | 1077 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
10649 | 1078 TYPE_COLUMN, &type, -1); |
1079 return type; | |
1080 } | |
1081 | |
11638 | 1082 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 1083 { |
1084 if (status_box->imhtml_visible) | |
1085 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
1086 else | |
1087 return NULL; | |
1088 } |