Mercurial > pidgin.yaz
annotate src/gtkstatusbox.c @ 13123:a9f6d9a68a04
[gaim-migrate @ 15485]
Fix a bug I introduced yesterday. Selecting available and away where
it waits for you to enter the message into the imhtml, the status box
would show your current status instead of "available" or "away"
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 05 Feb 2006 18:14:43 +0000 |
parents | d33a225fcb80 |
children | a0cdde3b06cf |
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 | |
13044 | 26 /* |
27 * The status box is made up of two main pieces: | |
28 * - The box that displays the current status, which is made | |
29 * of a GtkListStore ("status_box->store") and GtkCellView | |
30 * ("status_box->cell_view"). There is always exactly 1 row | |
31 * in this list store. Only the TYPE_ICON and TYPE_TEXT | |
32 * columns are used in this list store. | |
33 * - The dropdown menu that lets users select a status, which | |
34 * is made of a GtkComboBox ("status_box") and GtkListStore | |
35 * ("status_box->dropdown_store"). This dropdown is shown | |
36 * when the user clicks on the box that displays the current | |
37 * status. This list store contains one row for Available, | |
38 * one row for Away, etc., a few rows for popular statuses, | |
39 * and the "New..." and "Saved..." options. | |
40 */ | |
41 | |
12274 | 42 #include <gdk/gdkkeysyms.h> |
43 | |
11627 | 44 #include "account.h" |
10643 | 45 #include "internal.h" |
11627 | 46 #include "savedstatuses.h" |
10643 | 47 #include "status.h" |
11732 | 48 #include "debug.h" |
11627 | 49 |
10643 | 50 #include "gtkgaim.h" |
11729 | 51 #include "gtksavedstatuses.h" |
10643 | 52 #include "gtkstock.h" |
53 #include "gtkstatusbox.h" | |
12080 | 54 #include "gtkutils.h" |
10643 | 55 |
12651 | 56 #ifdef USE_GTKSPELL |
57 # include <gtkspell/gtkspell.h> | |
58 # ifdef _WIN32 | |
59 # include "wspell.h" | |
60 # endif | |
61 #endif | |
62 | |
12309 | 63 #define TYPING_TIMEOUT 4000 |
64 | |
10643 | 65 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); |
12460
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
66 static void imhtml_format_changed_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, void *data); |
11562 | 67 static void remove_typing_cb(GtkGaimStatusBox *box); |
12597
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
68 static void update_size (GtkGaimStatusBox *box); |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
69 static gint get_statusbox_index(GtkGaimStatusBox *box, GaimSavedStatus *saved_status); |
10643 | 70 |
12274 | 71 static void gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box); |
11967 | 72 static void gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box); |
11732 | 73 static void gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box); |
10643 | 74 static void gtk_gaim_status_box_changed(GtkComboBox *box); |
75 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
76 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
77 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); | |
78 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
79 | |
80 static void (*combo_box_size_request)(GtkWidget *widget, GtkRequisition *requisition); | |
81 static void (*combo_box_size_allocate)(GtkWidget *widget, GtkAllocation *allocation); | |
82 static void (*combo_box_forall) (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
11739 | 83 |
10643 | 84 enum { |
13044 | 85 /** A GtkGaimStatusBoxItemType */ |
86 TYPE_COLUMN, | |
87 | |
88 /** | |
89 * This is a GdkPixbuf (the other columns are strings). | |
90 * This column is visible. | |
91 */ | |
92 ICON_COLUMN, | |
93 | |
94 /** The text displayed on the status box. This column is visible. */ | |
95 TEXT_COLUMN, | |
96 | |
97 /** The plain-English title of this item */ | |
98 TITLE_COLUMN, | |
99 | |
100 /** A plain-English description of this item */ | |
101 DESC_COLUMN, | |
102 | |
103 /* | |
104 * This value depends on TYPE_COLUMN. For POPULAR types, | |
105 * this is the creation time. For PRIMITIVE types, | |
106 * this is the GaimStatusPrimitive. | |
107 */ | |
108 DATA_COLUMN, | |
109 | |
10643 | 110 NUM_COLUMNS |
111 }; | |
112 | |
11499 | 113 enum { |
114 PROP_0, | |
115 PROP_ACCOUNT | |
116 }; | |
117 | |
12379
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
118 GtkComboBoxClass *parent_class = NULL; |
12651 | 119 |
10643 | 120 static void gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass); |
121 static void gtk_gaim_status_box_init (GtkGaimStatusBox *status_box); | |
122 | |
123 GType | |
124 gtk_gaim_status_box_get_type (void) | |
125 { | |
10861 | 126 static GType status_box_type = 0; |
10643 | 127 |
10861 | 128 if (!status_box_type) |
129 { | |
130 static const GTypeInfo status_box_info = | |
131 { | |
132 sizeof (GtkGaimStatusBoxClass), | |
133 NULL, /* base_init */ | |
134 NULL, /* base_finalize */ | |
135 (GClassInitFunc) gtk_gaim_status_box_class_init, | |
136 NULL, /* class_finalize */ | |
137 NULL, /* class_data */ | |
138 sizeof (GtkGaimStatusBox), | |
139 0, | |
12221
152748df85cf
[gaim-migrate @ 14523]
Richard Laager <rlaager@wiktel.com>
parents:
12125
diff
changeset
|
140 (GInstanceInitFunc) gtk_gaim_status_box_init, |
152748df85cf
[gaim-migrate @ 14523]
Richard Laager <rlaager@wiktel.com>
parents:
12125
diff
changeset
|
141 NULL /* value_table */ |
10861 | 142 }; |
10643 | 143 |
10861 | 144 status_box_type = g_type_register_static(GTK_TYPE_COMBO_BOX, |
145 "GtkGaimStatusBox", | |
146 &status_box_info, | |
147 0); | |
148 } | |
10643 | 149 |
10861 | 150 return status_box_type; |
10643 | 151 } |
152 | |
153 static void | |
11499 | 154 gtk_gaim_status_box_get_property(GObject *object, guint param_id, |
155 GValue *value, GParamSpec *psec) | |
156 { | |
157 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
158 | |
159 switch (param_id) { | |
160 case PROP_ACCOUNT: | |
161 g_value_set_pointer(value, statusbox->account); | |
162 break; | |
163 default: | |
164 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, psec); | |
165 break; | |
166 } | |
167 } | |
168 | |
169 static void | |
11967 | 170 update_to_reflect_account_status(GtkGaimStatusBox *status_box, GaimAccount *account, GaimStatus *newstatus) |
11960 | 171 { |
11967 | 172 const GList *l; |
173 int status_no = -1; | |
174 const GaimStatusType *statustype = NULL; | |
12060 | 175 const char *message; |
11967 | 176 |
177 statustype = gaim_status_type_find_with_id((GList *)gaim_account_get_status_types(account), | |
178 (char *)gaim_status_type_get_id(gaim_status_get_type(newstatus))); | |
179 | |
180 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) { | |
181 GaimStatusType *status_type = (GaimStatusType *)l->data; | |
182 | |
183 if (!gaim_status_type_is_user_settable(status_type)) | |
184 continue; | |
185 status_no++; | |
186 if (statustype == status_type) | |
187 break; | |
188 } | |
189 | |
190 if (status_no != -1) { | |
191 gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE); | |
192 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
|
193 |
12060 | 194 message = gaim_status_get_attr_string(newstatus, "message"); |
195 | |
196 if (!message || !*message) | |
197 { | |
198 gtk_widget_hide_all(status_box->vbox); | |
199 status_box->imhtml_visible = FALSE; | |
200 } | |
201 else | |
202 { | |
203 gtk_widget_show_all(status_box->vbox); | |
204 status_box->imhtml_visible = TRUE; | |
205 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
12274 | 206 gtk_imhtml_clear_formatting(GTK_IMHTML(status_box->imhtml)); |
12060 | 207 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); |
208 } | |
11967 | 209 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); |
12274 | 210 gtk_gaim_status_box_refresh(status_box); |
11967 | 211 } |
212 } | |
213 | |
214 static void | |
215 account_status_changed_cb(GaimAccount *account, GaimStatus *oldstatus, GaimStatus *newstatus, GtkGaimStatusBox *status_box) | |
216 { | |
217 if (status_box->account == account) | |
218 update_to_reflect_account_status(status_box, account, newstatus); | |
11960 | 219 } |
220 | |
221 static void | |
11499 | 222 gtk_gaim_status_box_set_property(GObject *object, guint param_id, |
223 const GValue *value, GParamSpec *pspec) | |
224 { | |
225 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
226 | |
227 switch (param_id) { | |
228 case PROP_ACCOUNT: | |
229 statusbox->account = g_value_get_pointer(value); | |
11960 | 230 |
11967 | 231 if (statusbox->status_changed_signal) { |
232 gaim_signal_disconnect(gaim_accounts_get_handle(), "account-status-changed", | |
233 statusbox, GAIM_CALLBACK(account_status_changed_cb)); | |
234 statusbox->status_changed_signal = 0; | |
235 } | |
12286
255e6912607b
[gaim-migrate @ 14590]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12275
diff
changeset
|
236 |
11960 | 237 if (statusbox->account) |
11967 | 238 statusbox->status_changed_signal = gaim_signal_connect(gaim_accounts_get_handle(), "account-status-changed", |
11960 | 239 statusbox, GAIM_CALLBACK(account_status_changed_cb), |
240 statusbox); | |
11732 | 241 gtk_gaim_status_box_regenerate(statusbox); |
12256 | 242 |
11499 | 243 break; |
244 default: | |
245 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | |
246 break; | |
247 } | |
248 } | |
249 | |
250 static void | |
12379
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
251 gtk_gaim_status_box_finalize(GObject *obj) |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
252 { |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
253 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(obj); |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
254 |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
255 if (statusbox->status_changed_signal) { |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
256 gaim_signal_disconnect(gaim_accounts_get_handle(), "account-status-changed", |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
257 statusbox, GAIM_CALLBACK(account_status_changed_cb)); |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
258 statusbox->status_changed_signal = 0; |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
259 } |
12651 | 260 gaim_prefs_disconnect_by_handle(statusbox); |
12379
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
261 |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
262 G_OBJECT_CLASS(parent_class)->finalize(obj); |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
263 } |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
264 |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
265 static void |
10643 | 266 gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass) |
267 { | |
10861 | 268 GObjectClass *object_class; |
12379
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
269 GtkComboBoxClass *combo_class; |
10861 | 270 GtkWidgetClass *widget_class; |
271 GtkContainerClass *container_class = (GtkContainerClass*)klass; | |
10643 | 272 |
12379
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
273 parent_class = g_type_class_peek_parent(klass); |
12651 | 274 |
12379
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
275 combo_class = (GtkComboBoxClass*)klass; |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
276 combo_class->changed = gtk_gaim_status_box_changed; |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
277 |
10861 | 278 widget_class = (GtkWidgetClass*)klass; |
279 combo_box_size_request = widget_class->size_request; | |
280 widget_class->size_request = gtk_gaim_status_box_size_request; | |
281 combo_box_size_allocate = widget_class->size_allocate; | |
282 widget_class->size_allocate = gtk_gaim_status_box_size_allocate; | |
283 widget_class->expose_event = gtk_gaim_status_box_expose_event; | |
10643 | 284 |
10861 | 285 combo_box_forall = container_class->forall; |
286 container_class->forall = gtk_gaim_status_box_forall; | |
287 | |
288 object_class = (GObjectClass *)klass; | |
11499 | 289 |
12379
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
290 object_class->finalize = gtk_gaim_status_box_finalize; |
24c5fbfca306
[gaim-migrate @ 14683]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12320
diff
changeset
|
291 |
11499 | 292 object_class->get_property = gtk_gaim_status_box_get_property; |
293 object_class->set_property = gtk_gaim_status_box_set_property; | |
294 | |
295 g_object_class_install_property(object_class, | |
296 PROP_ACCOUNT, | |
297 g_param_spec_pointer("account", | |
298 "Account", | |
299 "The account, or NULL for all accounts", | |
300 G_PARAM_READWRITE | |
301 ) | |
302 ); | |
10643 | 303 } |
304 | |
13044 | 305 /** |
306 * This updates the text displayed on the status box so that it shows | |
13123 | 307 * the current status. This is the only function in this file that |
308 * should modify status_box->store | |
13044 | 309 */ |
10643 | 310 static void |
311 gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box) | |
312 { | |
13123 | 313 char *primary, *secondary, *text; |
10643 | 314 char aa_color[8]; |
315 GdkPixbuf *pixbuf; | |
10702 | 316 GtkTreePath *path; |
11870 | 317 GtkStyle *style; |
13121 | 318 GaimSavedStatus *saved_status; |
319 gboolean show_buddy_icons; | |
10643 | 320 |
13121 | 321 show_buddy_icons = gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"); |
11870 | 322 style = gtk_widget_get_style(GTK_WIDGET(status_box)); |
10643 | 323 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", |
324 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
325 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
326 style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
327 |
13121 | 328 saved_status = gaim_savedstatus_get_current(); |
329 | |
13123 | 330 /* Determine the primary text, secondary text, and pixbuf to use */ |
331 if (status_box->typing != 0) | |
332 { | |
333 GtkTreeIter iter; | |
334 GtkGaimStatusBoxItemType type; | |
335 gpointer data; | |
336 | |
337 /* Primary (get the status selected in the dropdown) */ | |
338 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); | |
339 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, | |
340 TYPE_COLUMN, &type, | |
341 DATA_COLUMN, &data, | |
342 -1); | |
343 if (type == GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE) | |
344 primary = g_strdup(gaim_primitive_get_name_from_type((GaimStatusPrimitive)GPOINTER_TO_INT(data))); | |
345 else if (gaim_savedstatus_is_transient(saved_status)) | |
346 primary = g_strdup(gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status))); | |
347 else | |
348 primary = g_markup_escape_text(gaim_savedstatus_get_title(saved_status), -1); | |
349 | |
350 secondary = g_strdup(_("Typing")); | |
351 pixbuf = status_box->typing_pixbufs[status_box->typing_index]; | |
352 } | |
353 else if (status_box->connecting) | |
354 { | |
355 /* Primary */ | |
356 if (gaim_savedstatus_is_transient(saved_status)) | |
357 primary = g_strdup(gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status))); | |
358 else | |
359 primary = g_markup_escape_text(gaim_savedstatus_get_title(saved_status), -1); | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
360 |
13123 | 361 secondary = g_strdup(_("Connecting")); |
362 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; | |
363 } | |
364 else | |
365 { | |
366 /* Primary and secondary */ | |
367 if (gaim_savedstatus_is_transient(saved_status)) | |
368 { | |
369 primary = g_strdup(gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status))); | |
370 secondary = NULL; | |
371 } | |
372 else | |
13121 | 373 { |
13123 | 374 const gchar *message; |
375 primary = g_markup_escape_text(gaim_savedstatus_get_title(saved_status), -1); | |
376 | |
377 message = gaim_savedstatus_get_message(saved_status); | |
378 if (message != NULL) | |
379 { | |
380 secondary = gaim_markup_strip_html(message); | |
381 gaim_util_chrreplace(secondary, '\n', ' '); | |
382 } | |
383 else | |
384 secondary = NULL; | |
13121 | 385 } |
13123 | 386 |
387 /* Pixbuf */ | |
388 pixbuf = gaim_gtk_create_gaim_icon_with_status( | |
389 gaim_savedstatus_get_type(saved_status), | |
390 show_buddy_icons ? 1.0 : 0.5); | |
10643 | 391 } |
10861 | 392 |
13121 | 393 if (status_box->account != NULL) { |
13123 | 394 text = g_strdup_printf("%s\n<span size=\"smaller\">%s</span>", |
12228 | 395 gaim_account_get_username(status_box->account), |
13123 | 396 secondary ? secondary : primary); |
397 } else if (secondary != NULL) { | |
13121 | 398 char *separator; |
399 separator = show_buddy_icons ? "\n" : " - "; | |
13123 | 400 text = g_strdup_printf("%s<span size=\"smaller\" color=\"%s\">%s%s</span>", |
401 primary, aa_color, separator, secondary); | |
12228 | 402 } else { |
13123 | 403 text = g_strdup(primary); |
11960 | 404 } |
13123 | 405 g_free(primary); |
406 g_free(secondary); | |
10643 | 407 |
13044 | 408 /* |
409 * Only two columns are used in this list store (does it | |
410 * really need to be a list store?) | |
411 */ | |
10643 | 412 gtk_list_store_set(status_box->store, &(status_box->iter), |
413 ICON_COLUMN, pixbuf, | |
10861 | 414 TEXT_COLUMN, text, |
11739 | 415 -1); |
13123 | 416 g_free(text); |
417 | |
418 /* Make sure to activate the only row in the tree view */ | |
10702 | 419 path = gtk_tree_path_new_from_string("0"); |
420 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); | |
421 gtk_tree_path_free(path); | |
10643 | 422 |
12597
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
423 update_size(status_box); |
10643 | 424 } |
425 | |
11870 | 426 /** |
427 * This updates the GtkTreeView so that it correctly shows the state | |
428 * we are currently using. It is used when the current state is | |
429 * updated from somewhere other than the GtkStatusBox (from a plugin, | |
430 * or when signing on with the "-n" option, for example). It is | |
13025 | 431 * also used when the user selects the "New..." option. |
11870 | 432 * |
433 * Maybe we could accomplish this by triggering off the mouse and | |
434 * keyboard signals instead of the changed signal? | |
435 */ | |
436 static void | |
437 update_to_reflect_current_status(GtkGaimStatusBox *status_box) | |
438 { | |
439 GaimSavedStatus *saved_status; | |
13050 | 440 GaimStatusPrimitive primitive; |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
441 gint index; |
12125 | 442 const char *message; |
11870 | 443 |
11983 | 444 /* this function is inappropriate for ones with accounts */ |
445 if (status_box->account) | |
446 return; | |
447 | |
12125 | 448 saved_status = gaim_savedstatus_get_current(); |
11951 | 449 |
450 /* | |
451 * Suppress the "changed" signal because the status | |
452 * was changed programmatically. | |
453 */ | |
454 gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE); | |
455 | |
13050 | 456 /* |
457 * If the saved_status is transient, is Available, Away, Invisible | |
458 * or Offline, and it does not have an substatuses, then select | |
459 * the primitive in the dropdown menu. Otherwise select the | |
460 * popular status in the dropdown menu. | |
461 */ | |
462 primitive = gaim_savedstatus_get_type(saved_status); | |
463 if (gaim_savedstatus_is_transient(saved_status) && | |
464 ((primitive == GAIM_STATUS_AVAILABLE) || (primitive == GAIM_STATUS_AWAY) || | |
465 (primitive == GAIM_STATUS_INVISIBLE) || (primitive == GAIM_STATUS_OFFLINE)) && | |
466 (!gaim_savedstatus_has_substatuses(saved_status))) | |
467 { | |
468 index = get_statusbox_index(status_box, saved_status); | |
13066 | 469 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), index); |
13050 | 470 } |
11870 | 471 else |
472 { | |
13066 | 473 GtkTreeIter iter; |
13111 | 474 GtkGaimStatusBoxItemType type; |
475 gpointer data; | |
13066 | 476 |
477 /* Unset the active item */ | |
478 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), -1); | |
479 | |
480 /* If this saved status is in the list store, then set it as the active item */ | |
481 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(status_box->dropdown_store), &iter)) | |
482 { | |
483 do | |
484 { | |
485 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, | |
13111 | 486 TYPE_COLUMN, &type, |
13066 | 487 DATA_COLUMN, &data, |
488 -1); | |
13111 | 489 if ((type == GTK_GAIM_STATUS_BOX_TYPE_POPULAR) && |
490 (GPOINTER_TO_INT(data) == gaim_savedstatus_get_creation_time(saved_status))) | |
13066 | 491 { |
492 /* Found! */ | |
493 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(status_box), &iter); | |
494 break; | |
495 } | |
496 } | |
497 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(status_box->dropdown_store), &iter)); | |
498 } | |
12125 | 499 } |
13050 | 500 |
12125 | 501 message = gaim_savedstatus_get_message(saved_status); |
13050 | 502 if (!gaim_savedstatus_is_transient(saved_status) || !message || !*message) |
12125 | 503 { |
504 status_box->imhtml_visible = FALSE; | |
505 gtk_widget_hide_all(status_box->vbox); | |
506 } | |
507 else | |
508 { | |
509 status_box->imhtml_visible = TRUE; | |
510 gtk_widget_show_all(status_box->vbox); | |
11870 | 511 |
12125 | 512 /* |
513 * Suppress the "changed" signal because the status | |
514 * was changed programmatically. | |
515 */ | |
516 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), FALSE); | |
11954 | 517 |
12125 | 518 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); |
12274 | 519 gtk_imhtml_clear_formatting(GTK_IMHTML(status_box->imhtml)); |
12125 | 520 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); |
521 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), TRUE); | |
11870 | 522 } |
11951 | 523 |
12634
8512c990967b
[gaim-migrate @ 14970]
Richard Laager <rlaager@wiktel.com>
parents:
12619
diff
changeset
|
524 update_size(status_box); |
8512c990967b
[gaim-migrate @ 14970]
Richard Laager <rlaager@wiktel.com>
parents:
12619
diff
changeset
|
525 |
11951 | 526 /* Stop suppressing the "changed" signal. */ |
527 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); | |
11870 | 528 } |
529 | |
11732 | 530 static void |
12778 | 531 add_popular_statuses(GtkGaimStatusBox *statusbox) |
532 { | |
13090 | 533 gboolean show_buddy_icons; |
12778 | 534 GList *list, *cur; |
535 GtkIconSize icon_size; | |
13062 | 536 GdkPixbuf *pixbuf, *emblem; |
537 int width, height; | |
12778 | 538 |
539 list = gaim_savedstatuses_get_popular(6); | |
540 if (list == NULL) | |
541 /* Odd... oh well, nothing we can do about it. */ | |
542 return; | |
543 | |
13090 | 544 show_buddy_icons = gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"); |
545 if (show_buddy_icons) | |
12778 | 546 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); |
547 else | |
548 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_SMALL); | |
549 | |
12779 | 550 gtk_gaim_status_box_add_separator(statusbox); |
551 | |
12778 | 552 for (cur = list; cur != NULL; cur = cur->next) |
553 { | |
554 GaimSavedStatus *saved = cur->data; | |
13050 | 555 const gchar *message; |
13098
44a4bd35cc97
[gaim-migrate @ 15460]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
556 gchar *stripped = NULL; |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
557 |
13090 | 558 /* Get an appropriate status icon */ |
13121 | 559 pixbuf = gaim_gtk_create_gaim_icon_with_status( |
560 gaim_savedstatus_get_type(saved), | |
13090 | 561 show_buddy_icons ? 1.0 : 0.5); |
13050 | 562 |
563 if (gaim_savedstatus_is_transient(saved)) | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
564 { |
13050 | 565 /* |
566 * Transient statuses do not have a title, so the savedstatus | |
567 * API returns the message when gaim_savedstatus_get_title() is | |
568 * called, so we don't need to get the message a second time. | |
569 */ | |
570 } | |
571 else | |
572 { | |
573 message = gaim_savedstatus_get_message(saved); | |
13098
44a4bd35cc97
[gaim-migrate @ 15460]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
574 if (message != NULL) |
44a4bd35cc97
[gaim-migrate @ 15460]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
575 { |
44a4bd35cc97
[gaim-migrate @ 15460]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
576 stripped = gaim_markup_strip_html(message); |
44a4bd35cc97
[gaim-migrate @ 15460]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
577 gaim_util_chrreplace(stripped, '\n', ' '); |
44a4bd35cc97
[gaim-migrate @ 15460]
Richard Laager <rlaager@wiktel.com>
parents:
13090
diff
changeset
|
578 } |
13090 | 579 |
580 /* Overlay a disk in the bottom left corner */ | |
581 emblem = gtk_widget_render_icon(GTK_WIDGET(statusbox->vbox), | |
582 GTK_STOCK_SAVE, icon_size, "GtkGaimStatusBox"); | |
583 if (emblem != NULL) | |
584 { | |
585 width = gdk_pixbuf_get_width(pixbuf) / 2; | |
586 height = gdk_pixbuf_get_height(pixbuf) / 2; | |
587 gdk_pixbuf_composite(emblem, pixbuf, 0, height, | |
588 width, height, 0, height, | |
589 0.5, 0.5, GDK_INTERP_BILINEAR, 255); | |
590 g_object_unref(G_OBJECT(emblem)); | |
591 } | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
592 } |
13090 | 593 |
12778 | 594 gtk_gaim_status_box_add(statusbox, GTK_GAIM_STATUS_BOX_TYPE_POPULAR, |
13079 | 595 pixbuf, gaim_savedstatus_get_title(saved), stripped, |
12778 | 596 GINT_TO_POINTER(gaim_savedstatus_get_creation_time(saved))); |
13050 | 597 g_free(stripped); |
13090 | 598 if (pixbuf != NULL) |
599 g_object_unref(G_OBJECT(pixbuf)); | |
12778 | 600 } |
601 | |
602 g_list_free(list); | |
603 } | |
604 | |
605 static void | |
11732 | 606 gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) |
607 { | |
13090 | 608 gboolean show_buddy_icons; |
11739 | 609 GaimAccount *account; |
13090 | 610 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4, *tmp; |
11732 | 611 GtkIconSize icon_size; |
612 | |
13090 | 613 show_buddy_icons = gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"); |
614 if (show_buddy_icons) | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
615 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
616 else |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
617 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_SMALL); |
11732 | 618 |
12256 | 619 /* Unset the model while clearing it */ |
620 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), NULL); | |
11732 | 621 gtk_list_store_clear(status_box->dropdown_store); |
12256 | 622 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
|
623 |
11739 | 624 account = GTK_GAIM_STATUS_BOX(status_box)->account; |
625 if (account == NULL) | |
626 { | |
12779 | 627 /* Global */ |
11756 | 628 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_ONLINE, |
11732 | 629 icon_size, "GtkGaimStatusBox"); |
11756 | 630 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_AWAY, |
11732 | 631 icon_size, "GtkGaimStatusBox"); |
11756 | 632 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
11732 | 633 icon_size, "GtkGaimStatusBox"); |
11756 | 634 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_INVISIBLE, |
11732 | 635 icon_size, "GtkGaimStatusBox"); |
12779 | 636 |
637 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE, pixbuf, _("Available"), NULL, GINT_TO_POINTER(GAIM_STATUS_AVAILABLE)); | |
638 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE, pixbuf2, _("Away"), NULL, GINT_TO_POINTER(GAIM_STATUS_AWAY)); | |
639 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE, pixbuf4, _("Invisible"), NULL, GINT_TO_POINTER(GAIM_STATUS_INVISIBLE)); | |
640 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE, pixbuf3, _("Offline"), NULL, GINT_TO_POINTER(GAIM_STATUS_OFFLINE)); | |
641 | |
642 add_popular_statuses(status_box); | |
643 | |
11738 | 644 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box)); |
13025 | 645 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("New..."), NULL, NULL); |
12778 | 646 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL, NULL); |
647 | |
11870 | 648 update_to_reflect_current_status(status_box); |
11732 | 649 |
650 } else { | |
12779 | 651 /* Per-account */ |
11732 | 652 const GList *l; |
11739 | 653 |
654 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
655 { | |
11732 | 656 GaimStatusType *status_type = (GaimStatusType *)l->data; |
657 | |
658 if (!gaim_status_type_is_user_settable(status_type)) | |
659 continue; | |
660 | |
13090 | 661 tmp = gaim_gtk_create_prpl_icon_with_status(account, status_type, |
662 show_buddy_icons ? 1.0 : 0.5); | |
11739 | 663 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), |
664 gaim_status_type_get_primitive(status_type), | |
13090 | 665 tmp, |
11739 | 666 gaim_status_type_get_name(status_type), |
12778 | 667 NULL, NULL); |
13090 | 668 if (tmp != NULL) |
669 g_object_unref(tmp); | |
11732 | 670 } |
12779 | 671 |
11967 | 672 update_to_reflect_account_status(status_box, account, gaim_account_get_active_status(account)); |
11732 | 673 } |
674 } | |
675 | |
12827
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
676 static gboolean combo_box_scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkIMHtml *imhtml) |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
677 { |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
678 gtk_combo_box_popup(GTK_COMBO_BOX(w)); |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
679 return TRUE; |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
680 } |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
681 |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
682 static gboolean imhtml_scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkIMHtml *imhtml) |
12075
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
683 { |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
684 if (event->direction == GDK_SCROLL_UP) |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
685 gtk_imhtml_page_up(imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
686 else if (event->direction == GDK_SCROLL_DOWN) |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
687 gtk_imhtml_page_down(imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
688 return TRUE; |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
689 } |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
690 |
13123 | 691 static int imhtml_remove_focus(GtkWidget *w, GdkEventKey *event, GtkGaimStatusBox *status_box) |
12274 | 692 { |
693 if (event->keyval == GDK_Tab || event->keyval == GDK_KP_Tab) | |
694 { | |
695 /* If last inserted character is a tab, then remove the focus from here */ | |
696 GtkWidget *top = gtk_widget_get_toplevel(w); | |
697 g_signal_emit_by_name(G_OBJECT(top), "move_focus", | |
698 (event->state & GDK_SHIFT_MASK) ? | |
699 GTK_DIR_TAB_BACKWARD: GTK_DIR_TAB_FORWARD); | |
700 return TRUE; | |
701 } | |
13123 | 702 if (!status_box->typing != 0) |
12274 | 703 return FALSE; |
13123 | 704 gtk_gaim_status_box_pulse_typing(status_box); |
705 g_source_remove(status_box->typing); | |
706 status_box->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box); | |
12460
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
707 |
12274 | 708 return FALSE; |
709 } | |
710 | |
11753 | 711 #if GTK_CHECK_VERSION(2,6,0) |
11738 | 712 static gboolean |
713 dropdown_store_row_separator_func(GtkTreeModel *model, | |
714 GtkTreeIter *iter, gpointer data) | |
715 { | |
11739 | 716 GtkGaimStatusBoxItemType type; |
11738 | 717 |
11885 | 718 gtk_tree_model_get(model, iter, TYPE_COLUMN, &type, -1); |
11738 | 719 |
11739 | 720 if (type == GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR) |
11738 | 721 return TRUE; |
722 | |
723 return FALSE; | |
724 } | |
11753 | 725 #endif |
11738 | 726 |
10643 | 727 static void |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
728 cache_pixbufs(GtkGaimStatusBox *status_box) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
729 { |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
730 GtkIconSize icon_size; |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
731 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
732 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) |
13065 | 733 { |
734 g_object_set(G_OBJECT(status_box->icon_rend), "xpad", 6, NULL); | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
735 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_TWO_LINE); |
13065 | 736 } else { |
737 g_object_set(G_OBJECT(status_box->icon_rend), "xpad", 3, NULL); | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
738 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_SMALL_TWO_LINE); |
13065 | 739 } |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
740 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
741 if (status_box->connecting_pixbufs[0] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
742 gdk_pixbuf_unref(status_box->connecting_pixbufs[0]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
743 if (status_box->connecting_pixbufs[1] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
744 gdk_pixbuf_unref(status_box->connecting_pixbufs[1]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
745 if (status_box->connecting_pixbufs[2] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
746 gdk_pixbuf_unref(status_box->connecting_pixbufs[2]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
747 if (status_box->connecting_pixbufs[3] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
748 gdk_pixbuf_unref(status_box->connecting_pixbufs[3]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
749 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
750 status_box->connecting_index = 0; |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
751 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT0, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
752 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
753 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT1, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
754 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
755 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT2, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
756 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
757 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_CONNECT3, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
758 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
759 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
760 if (status_box->typing_pixbufs[0] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
761 gdk_pixbuf_unref(status_box->typing_pixbufs[0]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
762 if (status_box->typing_pixbufs[1] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
763 gdk_pixbuf_unref(status_box->typing_pixbufs[1]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
764 if (status_box->typing_pixbufs[2] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
765 gdk_pixbuf_unref(status_box->typing_pixbufs[2]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
766 if (status_box->typing_pixbufs[3] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
767 gdk_pixbuf_unref(status_box->typing_pixbufs[3]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
768 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
769 status_box->typing_index = 0; |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
770 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING0, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
771 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
772 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING1, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
773 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
774 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING2, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
775 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
776 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_TYPING3, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
777 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
778 } |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
779 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
780 static void |
11954 | 781 current_status_pref_changed_cb(const char *name, GaimPrefType type, |
12816 | 782 gconstpointer val, gpointer data) |
11954 | 783 { |
13121 | 784 GtkGaimStatusBox *status_box = data; |
12778 | 785 |
786 /* Make sure our current status is added to the list of popular statuses */ | |
13121 | 787 gtk_gaim_status_box_regenerate(status_box); |
12778 | 788 |
13121 | 789 if (status_box->account != NULL) |
790 update_to_reflect_account_status(status_box, status_box->account, | |
791 gaim_account_get_active_status(status_box->account)); | |
12244 | 792 else |
13121 | 793 update_to_reflect_current_status(status_box); |
794 | |
795 gtk_gaim_status_box_refresh(status_box); | |
11954 | 796 } |
797 | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
798 static void |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
799 buddy_list_details_pref_changed_cb(const char *name, GaimPrefType type, |
12816 | 800 gconstpointer val, gpointer data) |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
801 { |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
802 GtkGaimStatusBox *status_box = (GtkGaimStatusBox *)data; |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
803 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
804 cache_pixbufs(status_box); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
805 gtk_gaim_status_box_regenerate(status_box); |
13121 | 806 gtk_gaim_status_box_refresh(status_box); |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
807 } |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
808 |
12651 | 809 static void |
810 spellcheck_prefs_cb(const char *name, GaimPrefType type, | |
12816 | 811 gconstpointer value, gpointer data) |
12651 | 812 { |
813 #ifdef USE_GTKSPELL | |
814 GtkGaimStatusBox *status_box = (GtkGaimStatusBox *)data; | |
815 | |
816 if (value) | |
817 gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(status_box->imhtml)); | |
818 else | |
819 { | |
820 GtkSpell *spell; | |
821 spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(status_box->imhtml)); | |
822 gtkspell_detach(spell); | |
823 } | |
824 #endif | |
825 } | |
826 | |
12294
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
827 #if 0 |
12262 | 828 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
|
829 { |
12286
255e6912607b
[gaim-migrate @ 14590]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12275
diff
changeset
|
830 |
12274 | 831 if (event->button != 1) |
832 return FALSE; | |
12262 | 833 gtk_combo_box_popdown(GTK_COMBO_BOX(box)); |
834 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box->toggle_button), FALSE); | |
835 if (!box->imhtml_visible) | |
836 g_signal_emit_by_name(G_OBJECT(box), "changed", NULL, NULL); | |
837 return TRUE; | |
838 } | |
839 | |
840 static gboolean button_pressed_cb(GtkWidget *widget, GdkEventButton *event, GtkGaimStatusBox *box) | |
841 { | |
12274 | 842 if (event->button != 1) |
843 return FALSE; | |
12262 | 844 gtk_combo_box_popup(GTK_COMBO_BOX(box)); |
12274 | 845 // Disabled until button_released_cb works |
846 // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box->toggle_button), TRUE); | |
12262 | 847 return TRUE; |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
848 } |
12294
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
849 #endif |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
850 |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
851 static void |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
852 toggled_cb(GtkWidget *widget, GtkGaimStatusBox *box) |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
853 { |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
854 gtk_combo_box_popup(GTK_COMBO_BOX(box)); |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
855 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
|
856 } |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
857 |
11954 | 858 static void |
10643 | 859 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) |
860 { | |
11400 | 861 GtkCellRenderer *text_rend; |
862 GtkCellRenderer *icon_rend; | |
10643 | 863 GtkTextBuffer *buffer; |
864 | |
865 status_box->imhtml_visible = FALSE; | |
866 status_box->connecting = FALSE; | |
13123 | 867 status_box->typing = 0; |
12262 | 868 status_box->toggle_button = gtk_toggle_button_new(); |
869 status_box->hbox = gtk_hbox_new(FALSE, 6); | |
10643 | 870 status_box->cell_view = gtk_cell_view_new(); |
12262 | 871 status_box->vsep = gtk_vseparator_new(); |
872 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
|
873 |
12778 | 874 status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); |
875 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, G_TYPE_POINTER); | |
10643 | 876 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
877 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
878 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
879 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
880 gtk_gaim_status_box_refresh(status_box); | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
881 |
12262 | 882 gtk_container_add(GTK_CONTAINER(status_box->toggle_button), status_box->hbox); |
883 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->cell_view, TRUE, TRUE, 0); | |
12274 | 884 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->vsep, FALSE, FALSE, 0); |
885 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->arrow, FALSE, FALSE, 0); | |
12262 | 886 gtk_widget_show_all(status_box->toggle_button); |
887 #if GTK_CHECK_VERSION(2,4,0) | |
888 gtk_button_set_focus_on_click(GTK_BUTTON(status_box->toggle_button), FALSE); | |
889 #endif | |
10643 | 890 |
13044 | 891 text_rend = gtk_cell_renderer_text_new(); |
892 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
10643 | 893 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); |
10861 | 894 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 895 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
896 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
13045 | 897 #if GTK_CHECK_VERSION(2, 6, 0) |
898 g_object_set(text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
899 #endif | |
10643 | 900 |
13044 | 901 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
902 status_box->text_rend = gtk_cell_renderer_text_new(); | |
10643 | 903 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); |
11499 | 904 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 905 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
906 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
13045 | 907 #if GTK_CHECK_VERSION(2, 6, 0) |
908 g_object_set(status_box->text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
909 #endif | |
10643 | 910 |
911 status_box->vbox = gtk_vbox_new(0, FALSE); | |
12879
f8748df5c17a
[gaim-migrate @ 15231]
Gary Kramlich <grim@reaperworld.com>
parents:
12827
diff
changeset
|
912 status_box->sw = gaim_gtk_create_imhtml(FALSE, &status_box->imhtml, NULL); |
f8748df5c17a
[gaim-migrate @ 15231]
Gary Kramlich <grim@reaperworld.com>
parents:
12827
diff
changeset
|
913 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
12286
255e6912607b
[gaim-migrate @ 14590]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12275
diff
changeset
|
914 |
10643 | 915 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
|
916 #if 0 |
12274 | 917 g_signal_connect(G_OBJECT(status_box->toggle_button), "button-press-event", |
918 G_CALLBACK(button_pressed_cb), status_box); | |
919 g_signal_connect(G_OBJECT(status_box->toggle_button), "button-release-event", | |
920 G_CALLBACK(button_released_cb), status_box); | |
12294
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
921 #endif |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
922 g_signal_connect(G_OBJECT(status_box->toggle_button), "toggled", |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
923 G_CALLBACK(toggled_cb), status_box); |
10643 | 924 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
|
925 g_signal_connect(G_OBJECT(status_box->imhtml), "format_function_toggle", |
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
926 G_CALLBACK(imhtml_format_changed_cb), status_box); |
12274 | 927 g_signal_connect(G_OBJECT(status_box->imhtml), "key_press_event", |
928 G_CALLBACK(imhtml_remove_focus), status_box); | |
11562 | 929 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 930 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
12651 | 931 #ifdef USE_GTKSPELL |
932 if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck")) | |
933 gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(status_box->imhtml)); | |
934 #endif | |
10643 | 935 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); |
12262 | 936 gtk_widget_set_parent(status_box->toggle_button, GTK_WIDGET(status_box)); |
12275 | 937 GTK_BIN(status_box)->child = status_box->toggle_button; |
12269 | 938 |
10643 | 939 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); |
11654 | 940 |
12827
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
941 g_signal_connect(G_OBJECT(status_box), "scroll_event", G_CALLBACK(combo_box_scroll_event_cb), NULL); |
12286
255e6912607b
[gaim-migrate @ 14590]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12275
diff
changeset
|
942 g_signal_connect(G_OBJECT(status_box->imhtml), "scroll_event", |
12827
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
943 G_CALLBACK(imhtml_scroll_event_cb), status_box->imhtml); |
12075
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
944 |
11850 | 945 #if GTK_CHECK_VERSION(2,6,0) |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
946 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); |
11850 | 947 #endif |
948 | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
949 cache_pixbufs(status_box); |
11732 | 950 gtk_gaim_status_box_regenerate(status_box); |
11954 | 951 |
12123 | 952 gaim_prefs_connect_callback(status_box, "/core/savedstatus/current", |
11954 | 953 current_status_pref_changed_cb, status_box); |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
954 gaim_prefs_connect_callback(status_box, "/gaim/gtk/blist/show_buddy_icons", |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
955 buddy_list_details_pref_changed_cb, status_box); |
12651 | 956 gaim_prefs_connect_callback(status_box, "/gaim/gtk/conversations/spellcheck", |
957 spellcheck_prefs_cb, status_box); | |
10643 | 958 } |
959 | |
960 static void | |
10861 | 961 gtk_gaim_status_box_size_request(GtkWidget *widget, |
962 GtkRequisition *requisition) | |
10643 | 963 { |
964 GtkRequisition box_req; | |
965 combo_box_size_request(widget, requisition); | |
12596
037a673ba862
[gaim-migrate @ 14926]
Richard Laager <rlaager@wiktel.com>
parents:
12595
diff
changeset
|
966 requisition->height += 3; |
10861 | 967 |
13065 | 968 /* If the gtkimhtml is visible, then add some additional padding */ |
10643 | 969 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
970 if (box_req.height > 1) | |
13065 | 971 requisition->height += box_req.height + 3; |
12286
255e6912607b
[gaim-migrate @ 14590]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12275
diff
changeset
|
972 |
10643 | 973 requisition->width = 1; |
974 } | |
975 | |
976 static void | |
10861 | 977 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
978 GtkAllocation *allocation) | |
10643 | 979 { |
980 GtkRequisition req = {0,0}; | |
11400 | 981 GtkAllocation parent_alc, box_alc; |
982 | |
10643 | 983 combo_box_size_request(widget, &req); |
10861 | 984 |
13065 | 985 box_alc = *allocation; |
12596
037a673ba862
[gaim-migrate @ 14926]
Richard Laager <rlaager@wiktel.com>
parents:
12595
diff
changeset
|
986 box_alc.height = MAX(1, (allocation->height - req.height - 6)); |
13065 | 987 box_alc.y += req.height + 6; |
10643 | 988 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); |
10861 | 989 |
13065 | 990 parent_alc = *allocation; |
10643 | 991 parent_alc.height = MAX(1,req.height); |
12102
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
992 parent_alc.y += 3; |
10643 | 993 combo_box_size_allocate(widget, &parent_alc); |
12262 | 994 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->toggle_button, &parent_alc); |
10643 | 995 widget->allocation = *allocation; |
996 } | |
997 | |
998 static gboolean | |
10861 | 999 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
12262 | 1000 GdkEventExpose *event) |
10643 | 1001 { |
10861 | 1002 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
12262 | 1003 gtk_container_propagate_expose(GTK_CONTAINER(widget), status_box->vbox, event); |
12275 | 1004 gtk_container_propagate_expose(GTK_CONTAINER(widget), status_box->toggle_button, event); |
10861 | 1005 return FALSE; |
10643 | 1006 } |
1007 | |
1008 static void | |
10861 | 1009 gtk_gaim_status_box_forall(GtkContainer *container, |
1010 gboolean include_internals, | |
1011 GtkCallback callback, | |
1012 gpointer callback_data) | |
10643 | 1013 { |
10861 | 1014 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 1015 |
10861 | 1016 if (include_internals) |
1017 { | |
1018 (* callback) (status_box->vbox, callback_data); | |
12275 | 1019 (* callback) (status_box->toggle_button, callback_data); |
1020 (* callback) (status_box->arrow, callback_data); | |
10861 | 1021 } |
10643 | 1022 |
10861 | 1023 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 1024 } |
1025 | |
1026 GtkWidget * | |
1027 gtk_gaim_status_box_new() | |
1028 { | |
1029 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
1030 } | |
1031 | |
11499 | 1032 GtkWidget * |
1033 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
1034 { | |
1035 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
1036 } | |
10643 | 1037 |
13050 | 1038 /** |
1039 * Add a row to the dropdown menu. | |
1040 * | |
1041 * @param status_box The status box itself. | |
1042 * @param type A GtkGaimStatusBoxItemType. | |
1043 * @param pixbuf The icon to associate with this row in the menu. | |
1044 * @param title The title of this item. For the primitive entries, | |
1045 * this is something like "Available" or "Away." For | |
1046 * the saved statuses, this is something like | |
1047 * "My favorite away message!" This should be | |
1048 * plaintext (non-markedup) (this function escapes it). | |
1049 * @param desc The secondary text for this item. This will be | |
1050 * placed on the row below the title, in a dimmer | |
1051 * font (generally gray). This text should be plaintext | |
1052 * (non-markedup) (this function escapes it). | |
1053 * @param data Data to be associated with this row in the dropdown | |
1054 * menu. For primitives this is the value of the | |
1055 * GaimStatusPrimitive. For saved statuses this is the | |
1056 * creation timestamp. | |
1057 */ | |
10643 | 1058 void |
13050 | 1059 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *title, const char *desc, gpointer data) |
10643 | 1060 { |
1061 GtkTreeIter iter; | |
13050 | 1062 char *text; |
10861 | 1063 |
13050 | 1064 if (desc == NULL) |
1065 { | |
1066 text = g_markup_escape_text(title, -1); | |
1067 } | |
1068 else | |
1069 { | |
10643 | 1070 char aa_color[8]; |
13050 | 1071 gchar *escaped_title, *escaped_desc; |
1072 GtkStyle *style; | |
1073 | |
1074 style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
10643 | 1075 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", |
1076 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
1077 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 1078 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
13050 | 1079 |
1080 escaped_title = g_markup_escape_text(title, -1); | |
1081 escaped_desc = g_markup_escape_text(desc, -1); | |
1082 text = g_strdup_printf("%s\n<span color=\"%s\" size=\"smaller\">%s</span>", | |
1083 escaped_title, aa_color, escaped_desc); | |
1084 g_free(escaped_title); | |
1085 g_free(escaped_desc); | |
10643 | 1086 } |
10861 | 1087 |
10643 | 1088 gtk_list_store_append(status_box->dropdown_store, &iter); |
1089 gtk_list_store_set(status_box->dropdown_store, &iter, | |
13050 | 1090 TYPE_COLUMN, type, |
1091 ICON_COLUMN, pixbuf, | |
1092 TEXT_COLUMN, text, | |
1093 TITLE_COLUMN, title, | |
1094 DESC_COLUMN, desc, | |
1095 DATA_COLUMN, data, | |
1096 -1); | |
1097 g_free(text); | |
10643 | 1098 } |
1099 | |
1100 void | |
11738 | 1101 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
1102 { | |
11756 | 1103 /* Don't do anything unless GTK actually supports |
1104 * gtk_combo_box_set_row_separator_func */ | |
1105 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 1106 GtkTreeIter iter; |
1107 | |
1108 gtk_list_store_append(status_box->dropdown_store, &iter); | |
1109 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 1110 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
1111 -1); | |
11756 | 1112 #endif |
11738 | 1113 } |
1114 | |
1115 void | |
10643 | 1116 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) |
1117 { | |
1118 if (!status_box) | |
1119 return; | |
1120 status_box->connecting = connecting; | |
1121 gtk_gaim_status_box_refresh(status_box); | |
1122 } | |
1123 | |
1124 void | |
1125 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
1126 { | |
1127 if (!status_box) | |
1128 return; | |
1129 if (status_box->connecting_index == 3) | |
1130 status_box->connecting_index = 0; | |
10861 | 1131 else |
10643 | 1132 status_box->connecting_index++; |
1133 gtk_gaim_status_box_refresh(status_box); | |
1134 } | |
1135 | |
12274 | 1136 static void |
10643 | 1137 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) |
1138 { | |
1139 if (status_box->typing_index == 3) | |
1140 status_box->typing_index = 0; | |
10861 | 1141 else |
10643 | 1142 status_box->typing_index++; |
1143 gtk_gaim_status_box_refresh(status_box); | |
1144 } | |
1145 | |
13050 | 1146 static GaimStatusType * |
1147 find_status_type_by_index(const GaimAccount *account, gint active) | |
11993 | 1148 { |
1149 const GList *l = gaim_account_get_status_types(account); | |
1150 gint i; | |
1151 | |
1152 for (i = 0; l; l = l->next) { | |
1153 GaimStatusType *status_type = l->data; | |
1154 if (!gaim_status_type_is_user_settable(status_type)) | |
1155 continue; | |
1156 | |
1157 if (active == i) | |
1158 return status_type; | |
1159 i++; | |
1160 } | |
1161 | |
1162 return NULL; | |
1163 } | |
1164 | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1165 static gboolean |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1166 message_changed(const char *one, const char *two) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1167 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1168 if (one == NULL && two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1169 return FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1170 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1171 if (one == NULL || two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1172 return TRUE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1173 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1174 return (g_utf8_collate(one, two) != 0); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1175 } |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1176 |
11654 | 1177 static void |
1178 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 1179 { |
11739 | 1180 GtkGaimStatusBoxItemType type; |
12779 | 1181 gpointer data; |
11739 | 1182 gchar *title; |
10643 | 1183 GtkTreeIter iter; |
11654 | 1184 char *message; |
1185 GaimSavedStatus *saved_status; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1186 gboolean changed = TRUE; |
10643 | 1187 |
11951 | 1188 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) |
1189 return; | |
12659 | 1190 |
11654 | 1191 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
12779 | 1192 TYPE_COLUMN, &type, |
1193 DATA_COLUMN, &data, | |
1194 -1); | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
1195 |
11739 | 1196 /* |
13025 | 1197 * If the currently selected status is "New..." or |
12779 | 1198 * "Saved..." or a popular status then do nothing. |
1199 * Custom statuses are | |
11954 | 1200 * activated elsewhere, and we update the status_box |
1201 * accordingly by monitoring the preference | |
12123 | 1202 * "/core/savedstatus/current" and then calling |
11954 | 1203 * update_to_reflect_current_status() |
11739 | 1204 */ |
12779 | 1205 if (type != GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE) |
11739 | 1206 return; |
11654 | 1207 |
12659 | 1208 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
1209 TITLE_COLUMN, &title, -1); | |
1210 | |
1211 message = gtk_gaim_status_box_get_message(status_box); | |
1212 if (!message || !*message) | |
1213 { | |
1214 gtk_widget_hide_all(status_box->vbox); | |
1215 status_box->imhtml_visible = FALSE; | |
1216 } | |
1217 | |
12779 | 1218 if (status_box->account == NULL) { |
1219 /* Global */ | |
1220 /* Save the newly selected status to prefs.xml and status.xml */ | |
1221 | |
13111 | 1222 /* Has the status really been changed? */ |
12779 | 1223 saved_status = gaim_savedstatus_get_current(); |
1224 if (gaim_savedstatus_get_type(saved_status) == GPOINTER_TO_INT(data)) | |
1225 { | |
1226 if (!message_changed(gaim_savedstatus_get_message(saved_status), message)) | |
1227 changed = FALSE; | |
1228 } | |
1229 | |
1230 if (changed) | |
1231 { | |
13012 | 1232 /* If we've used this type+message before, lookup the transient status */ |
1233 saved_status = gaim_savedstatus_find_by_type_and_message( | |
1234 GPOINTER_TO_INT(data), message); | |
1235 | |
1236 | |
1237 /* If this type+message is unique then create a new transient saved status */ | |
1238 if (saved_status == NULL) | |
1239 { | |
1240 saved_status = gaim_savedstatus_new(NULL, GPOINTER_TO_INT(data)); | |
1241 gaim_savedstatus_set_message(saved_status, message); | |
1242 } | |
12779 | 1243 |
1244 /* Set the status for each account */ | |
1245 gaim_savedstatus_activate(saved_status); | |
1246 } | |
1247 } else { | |
1248 /* Per-account */ | |
11981 | 1249 gint active; |
1250 GaimStatusType *status_type; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1251 GaimStatus *status; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1252 const char *id = NULL; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1253 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1254 status = gaim_account_get_active_status(status_box->account); |
11981 | 1255 |
1256 g_object_get(G_OBJECT(status_box), "active", &active, NULL); | |
11654 | 1257 |
11993 | 1258 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
|
1259 id = gaim_status_type_get_id(status_type); |
11981 | 1260 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1261 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
|
1262 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1263 /* Selected status and previous status is the same */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1264 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
|
1265 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1266 } |
12123 | 1267 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1268 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1269 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1270 if (message) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1271 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1272 TRUE, "message", message, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1273 else |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1274 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1275 TRUE, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1276 } |
11981 | 1277 } |
11627 | 1278 |
11638 | 1279 g_free(title); |
11654 | 1280 g_free(message); |
1281 } | |
1282 | |
12597
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1283 static void update_size(GtkGaimStatusBox *status_box) |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1284 { |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1285 GtkTextBuffer *buffer; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1286 GtkTextIter iter; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1287 int wrapped_lines; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1288 int lines; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1289 GdkRectangle oneline; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1290 int height; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1291 int pad_top, pad_inside, pad_bottom; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1292 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1293 if (!status_box->imhtml_visible) |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1294 { |
12598
1c122dbc8e9e
[gaim-migrate @ 14928]
Richard Laager <rlaager@wiktel.com>
parents:
12597
diff
changeset
|
1295 if (status_box->vbox != NULL) |
1c122dbc8e9e
[gaim-migrate @ 14928]
Richard Laager <rlaager@wiktel.com>
parents:
12597
diff
changeset
|
1296 gtk_widget_set_size_request(status_box->vbox, -1, -1); |
12597
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1297 return; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1298 } |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1299 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1300 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1301 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1302 wrapped_lines = 1; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1303 gtk_text_buffer_get_start_iter(buffer, &iter); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1304 while (gtk_text_view_forward_display_line(GTK_TEXT_VIEW(status_box->imhtml), &iter)) |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1305 wrapped_lines++; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1306 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1307 lines = gtk_text_buffer_get_line_count(buffer); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1308 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1309 /* Show a maximum of 4 lines */ |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1310 lines = MIN(lines, 4); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1311 wrapped_lines = MIN(wrapped_lines, 4); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1312 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1313 gtk_text_buffer_get_start_iter(buffer, &iter); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1314 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(status_box->imhtml), &iter, &oneline); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1315 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1316 pad_top = gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(status_box->imhtml)); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1317 pad_bottom = gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(status_box->imhtml)); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1318 pad_inside = gtk_text_view_get_pixels_inside_wrap(GTK_TEXT_VIEW(status_box->imhtml)); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1319 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1320 height = (oneline.height + pad_top + pad_bottom) * lines; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1321 height += (oneline.height + pad_inside) * (wrapped_lines - lines); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1322 |
12905
ee0c8c446eef
[gaim-migrate @ 15258]
Richard Laager <rlaager@wiktel.com>
parents:
12879
diff
changeset
|
1323 gtk_widget_set_size_request(status_box->vbox, -1, height + GAIM_HIG_BOX_SPACE); |
12597
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1324 } |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1325 |
11654 | 1326 static void remove_typing_cb(GtkGaimStatusBox *status_box) |
1327 { | |
12782 | 1328 if (status_box->typing == 0) |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1329 { |
12782 | 1330 /* Nothing has changed, so we don't need to do anything */ |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1331 update_to_reflect_current_status(status_box); |
12782 | 1332 return; |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1333 } |
12782 | 1334 |
11654 | 1335 activate_currently_selected_status(status_box); |
1336 | |
1337 g_source_remove(status_box->typing); | |
1338 status_box->typing = 0; | |
1339 gtk_gaim_status_box_refresh(status_box); | |
10643 | 1340 } |
1341 | |
1342 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
1343 { | |
11400 | 1344 GtkGaimStatusBox *status_box; |
10643 | 1345 GtkTreeIter iter; |
11739 | 1346 GtkGaimStatusBoxItemType type; |
13050 | 1347 char *text, *desc; |
10643 | 1348 GdkPixbuf *pixbuf; |
12778 | 1349 gpointer data; |
11960 | 1350 GList *accounts = NULL, *node; |
10643 | 1351 |
11400 | 1352 status_box = GTK_GAIM_STATUS_BOX(box); |
1353 | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
1354 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
|
1355 return; |
11739 | 1356 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
1357 TYPE_COLUMN, &type, | |
1358 TITLE_COLUMN, &text, | |
13050 | 1359 DESC_COLUMN, &desc, |
12778 | 1360 ICON_COLUMN, &pixbuf, |
1361 DATA_COLUMN, &data, | |
11739 | 1362 -1); |
13123 | 1363 if (status_box->typing != 0) |
11638 | 1364 g_source_remove(status_box->typing); |
1365 status_box->typing = 0; | |
10861 | 1366 |
11951 | 1367 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11729 | 1368 { |
12778 | 1369 if (type == GTK_GAIM_STATUS_BOX_TYPE_POPULAR) |
1370 { | |
1371 GaimSavedStatus *saved; | |
1372 saved = gaim_savedstatus_find_by_creation_time(GPOINTER_TO_INT(data)); | |
1373 g_return_if_fail(saved != NULL); | |
1374 gaim_savedstatus_activate(saved); | |
1375 return; | |
1376 } | |
1377 | |
11951 | 1378 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
1379 { | |
1380 gaim_gtk_status_editor_show(NULL); | |
13121 | 1381 // TODO: This shouldn't be neccessary? |
11951 | 1382 update_to_reflect_current_status(status_box); |
1383 return; | |
1384 } | |
11729 | 1385 |
11951 | 1386 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
1387 { | |
1388 gaim_gtk_status_window_show(); | |
13121 | 1389 // TODO: This shouldn't be neccessary? |
11951 | 1390 update_to_reflect_current_status(status_box); |
1391 return; | |
1392 } | |
11729 | 1393 } |
1394 | |
11654 | 1395 /* |
12779 | 1396 * Show the message box whenever the primitive allows for a |
11960 | 1397 * message attribute on any protocol that is enabled, |
1398 * or our protocol, if we have account set | |
11654 | 1399 */ |
11960 | 1400 if (status_box->account) |
1401 accounts = g_list_prepend(accounts, status_box->account); | |
1402 else | |
1403 accounts = gaim_accounts_get_all_active(); | |
11755 | 1404 status_box->imhtml_visible = FALSE; |
1405 for (node = accounts; node != NULL; node = node->next) | |
1406 { | |
1407 GaimAccount *account; | |
1408 GaimStatusType *status_type; | |
1409 | |
1410 account = node->data; | |
12779 | 1411 status_type = gaim_account_get_status_type_with_primitive(account, GPOINTER_TO_INT(data)); |
11755 | 1412 if ((status_type != NULL) && |
1413 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
1414 { | |
1415 status_box->imhtml_visible = TRUE; | |
1416 break; | |
1417 } | |
1418 } | |
1419 g_list_free(accounts); | |
11654 | 1420 |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1421 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11654 | 1422 { |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1423 if (status_box->imhtml_visible) |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1424 { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1425 GtkTextBuffer *buf; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1426 GtkTextIter start, end; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1427 gtk_widget_show_all(status_box->vbox); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1428 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1429 status_box->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1430 } |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1431 gtk_widget_grab_focus(status_box->imhtml); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1432 buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1433 gtk_text_buffer_get_start_iter(buf, &start); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1434 gtk_text_buffer_get_end_iter(buf, &end); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1435 gtk_text_buffer_move_mark_by_name(buf, "insert", &end); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1436 gtk_text_buffer_move_mark_by_name(buf, "selection_bound", &start); |
12274 | 1437 } |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1438 else |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1439 { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1440 gtk_widget_hide_all(status_box->vbox); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1441 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1442 activate_currently_selected_status(status_box); /* This is where we actually set the status */ |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1443 } |
10643 | 1444 } |
1445 gtk_gaim_status_box_refresh(status_box); | |
1446 } | |
1447 | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1448 static gint |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1449 get_statusbox_index(GtkGaimStatusBox *box, GaimSavedStatus *saved_status) |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1450 { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1451 gint index; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1452 |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1453 switch (gaim_savedstatus_get_type(saved_status)) |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1454 { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1455 case GAIM_STATUS_AVAILABLE: |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1456 index = 0; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1457 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1458 case GAIM_STATUS_AWAY: |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1459 index = 1; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1460 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1461 case GAIM_STATUS_INVISIBLE: |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1462 index = 2; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1463 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1464 case GAIM_STATUS_OFFLINE: |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1465 index = 3; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1466 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1467 default: |
13079 | 1468 index = -1; |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1469 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1470 } |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1471 |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1472 return index; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1473 } |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1474 |
10643 | 1475 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) |
1476 { | |
13123 | 1477 GtkGaimStatusBox *status_box = (GtkGaimStatusBox*)data; |
1478 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) | |
11951 | 1479 { |
13123 | 1480 if (status_box->typing != 0) { |
1481 gtk_gaim_status_box_pulse_typing(status_box); | |
1482 g_source_remove(status_box->typing); | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1483 } else { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1484 gint index; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1485 GaimSavedStatus *saved = gaim_savedstatus_get_current(); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1486 |
13123 | 1487 index = get_statusbox_index(status_box, saved); |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1488 |
13123 | 1489 gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE); |
1490 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), index); | |
1491 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); | |
1492 gtk_widget_grab_focus(status_box->imhtml); | |
11951 | 1493 } |
13123 | 1494 status_box->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box); |
10861 | 1495 } |
13123 | 1496 gtk_gaim_status_box_refresh(status_box); |
10643 | 1497 } |
10649 | 1498 |
12460
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
1499 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
|
1500 { |
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
1501 imhtml_changed_cb(NULL, data); |
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
1502 } |
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
1503 |
11638 | 1504 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 1505 { |
1506 if (status_box->imhtml_visible) | |
1507 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
1508 else | |
1509 return NULL; | |
1510 } |