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