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