Mercurial > pidgin.yaz
annotate src/gtkstatusbox.c @ 13077:64ca89ffc639
[gaim-migrate @ 15439]
This should make comparing log size structs a little faster.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 31 Jan 2006 03:43:04 +0000 |
parents | 0afb445a3433 |
children | 896d6c305429 |
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 | |
307 * the current status. | |
308 */ | |
10643 | 309 static void |
310 gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box) | |
311 { | |
12228 | 312 char *text = NULL, *title; |
10643 | 313 char aa_color[8]; |
314 GdkPixbuf *pixbuf; | |
10702 | 315 GtkTreePath *path; |
11870 | 316 GtkStyle *style; |
10643 | 317 |
11870 | 318 style = gtk_widget_get_style(GTK_WIDGET(status_box)); |
10643 | 319 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", |
320 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
321 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
322 style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
323 |
13044 | 324 if (status_box->title != NULL) |
325 title = g_markup_escape_text(status_box->title, -1); | |
326 else | |
327 title = g_strdup(""); | |
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
328 |
10643 | 329 if (status_box->error) { |
13044 | 330 gchar *tmp = g_markup_escape_text(status_box->error, -1); |
12228 | 331 text = g_strdup_printf("<span size=\"smaller\" weight=\"bold\" color=\"red\">%s</span>", |
13044 | 332 tmp); |
333 g_free(tmp); | |
10643 | 334 } else if (status_box->typing) { |
12228 | 335 text = g_strdup_printf("<span size=\"smaller\" color=\"%s\">%s</span>", |
336 aa_color, _("Typing")); | |
10643 | 337 } else if (status_box->connecting) { |
12228 | 338 text = g_strdup_printf("<span size=\"smaller\" color=\"%s\">%s</span>", |
339 aa_color, _("Connecting")); | |
10861 | 340 } else if (status_box->desc) { |
13044 | 341 gchar *tmp = g_markup_escape_text(status_box->desc, -1); |
12228 | 342 text = g_strdup_printf("<span size=\"smaller\" color=\"%s\">%s</span>", |
13044 | 343 aa_color, tmp); |
344 g_free(tmp); | |
10643 | 345 } |
10861 | 346 |
11960 | 347 if (status_box->account) { |
12228 | 348 char *text2 = g_strdup_printf("%s\n<span size=\"smaller\">%s</span>", |
349 gaim_account_get_username(status_box->account), | |
350 text ? text : title); | |
11960 | 351 g_free(text); |
352 text = text2; | |
12228 | 353 } else if (text) { |
354 char *text2 = g_strdup_printf("%s\n%s", title, text); | |
355 g_free(text); | |
356 text = text2; | |
357 } else { | |
358 text = g_strdup(title); | |
11960 | 359 } |
13044 | 360 g_free(title); |
11960 | 361 |
11523 | 362 if (status_box->connecting) |
363 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; | |
364 else if (status_box->error) | |
10643 | 365 pixbuf = status_box->error_pixbuf; |
366 else if (status_box->typing) | |
367 pixbuf = status_box->typing_pixbufs[status_box->typing_index]; | |
368 else | |
369 pixbuf = status_box->pixbuf; | |
370 | |
13044 | 371 /* |
372 * Only two columns are used in this list store (does it | |
373 * really need to be a list store?) | |
374 */ | |
10643 | 375 gtk_list_store_set(status_box->store, &(status_box->iter), |
376 ICON_COLUMN, pixbuf, | |
10861 | 377 TEXT_COLUMN, text, |
11739 | 378 -1); |
10702 | 379 path = gtk_tree_path_new_from_string("0"); |
380 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); | |
381 gtk_tree_path_free(path); | |
10643 | 382 |
383 g_free(text); | |
12597
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
384 update_size(status_box); |
10643 | 385 } |
386 | |
11870 | 387 /** |
388 * This updates the GtkTreeView so that it correctly shows the state | |
389 * we are currently using. It is used when the current state is | |
390 * updated from somewhere other than the GtkStatusBox (from a plugin, | |
391 * or when signing on with the "-n" option, for example). It is | |
13025 | 392 * also used when the user selects the "New..." option. |
11870 | 393 * |
394 * Maybe we could accomplish this by triggering off the mouse and | |
395 * keyboard signals instead of the changed signal? | |
396 */ | |
397 static void | |
398 update_to_reflect_current_status(GtkGaimStatusBox *status_box) | |
399 { | |
400 GaimSavedStatus *saved_status; | |
13050 | 401 GaimStatusPrimitive primitive; |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
402 gint index; |
12125 | 403 const char *message; |
11870 | 404 |
11983 | 405 /* this function is inappropriate for ones with accounts */ |
406 if (status_box->account) | |
407 return; | |
408 | |
12125 | 409 saved_status = gaim_savedstatus_get_current(); |
11951 | 410 |
411 /* | |
412 * Suppress the "changed" signal because the status | |
413 * was changed programmatically. | |
414 */ | |
415 gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE); | |
416 | |
13050 | 417 /* |
418 * If the saved_status is transient, is Available, Away, Invisible | |
419 * or Offline, and it does not have an substatuses, then select | |
420 * the primitive in the dropdown menu. Otherwise select the | |
421 * popular status in the dropdown menu. | |
422 */ | |
423 primitive = gaim_savedstatus_get_type(saved_status); | |
424 if (gaim_savedstatus_is_transient(saved_status) && | |
425 ((primitive == GAIM_STATUS_AVAILABLE) || (primitive == GAIM_STATUS_AWAY) || | |
426 (primitive == GAIM_STATUS_INVISIBLE) || (primitive == GAIM_STATUS_OFFLINE)) && | |
427 (!gaim_savedstatus_has_substatuses(saved_status))) | |
428 { | |
429 index = get_statusbox_index(status_box, saved_status); | |
13066 | 430 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), index); |
431 | |
13050 | 432 } |
11870 | 433 else |
434 { | |
13066 | 435 GtkTreeIter iter; |
436 gpointer data; | |
437 | |
438 /* Unset the active item */ | |
439 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), -1); | |
440 | |
441 /* If this saved status is in the list store, then set it as the active item */ | |
442 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(status_box->dropdown_store), &iter)) | |
443 { | |
444 do | |
445 { | |
446 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, | |
447 DATA_COLUMN, &data, | |
448 -1); | |
449 if (GPOINTER_TO_INT(data) == gaim_savedstatus_get_creation_time(saved_status)) | |
450 { | |
451 /* Found! */ | |
452 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(status_box), &iter); | |
453 break; | |
454 } | |
455 } | |
456 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(status_box->dropdown_store), &iter)); | |
457 } | |
12125 | 458 } |
13050 | 459 |
12125 | 460 message = gaim_savedstatus_get_message(saved_status); |
13050 | 461 if (!gaim_savedstatus_is_transient(saved_status) || !message || !*message) |
12125 | 462 { |
463 status_box->imhtml_visible = FALSE; | |
464 gtk_widget_hide_all(status_box->vbox); | |
465 } | |
466 else | |
467 { | |
468 status_box->imhtml_visible = TRUE; | |
469 gtk_widget_show_all(status_box->vbox); | |
11870 | 470 |
12125 | 471 /* |
472 * Suppress the "changed" signal because the status | |
473 * was changed programmatically. | |
474 */ | |
475 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), FALSE); | |
11954 | 476 |
12125 | 477 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); |
12274 | 478 gtk_imhtml_clear_formatting(GTK_IMHTML(status_box->imhtml)); |
12125 | 479 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); |
480 gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), TRUE); | |
11870 | 481 } |
11951 | 482 |
12634
8512c990967b
[gaim-migrate @ 14970]
Richard Laager <rlaager@wiktel.com>
parents:
12619
diff
changeset
|
483 update_size(status_box); |
8512c990967b
[gaim-migrate @ 14970]
Richard Laager <rlaager@wiktel.com>
parents:
12619
diff
changeset
|
484 |
11951 | 485 /* Stop suppressing the "changed" signal. */ |
486 gtk_widget_set_sensitive(GTK_WIDGET(status_box), TRUE); | |
11870 | 487 } |
488 | |
11732 | 489 static void |
12778 | 490 add_popular_statuses(GtkGaimStatusBox *statusbox) |
491 { | |
492 GList *list, *cur; | |
493 GtkIconSize icon_size; | |
13062 | 494 GdkPixbuf *pixbuf, *emblem; |
495 int width, height; | |
12778 | 496 |
497 list = gaim_savedstatuses_get_popular(6); | |
498 if (list == NULL) | |
499 /* Odd... oh well, nothing we can do about it. */ | |
500 return; | |
501 | |
502 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) | |
503 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
504 else | |
505 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_SMALL); | |
506 | |
13050 | 507 /* Create the icon to use for non-transient saved-statuses */ |
508 pixbuf = gtk_widget_render_icon(GTK_WIDGET(statusbox->vbox), | |
509 GAIM_STOCK_STATUS_ONLINE, icon_size, "GtkGaimStatusBox"); | |
510 | |
511 emblem = gtk_widget_render_icon(GTK_WIDGET(statusbox->vbox), | |
512 GTK_STOCK_SAVE, icon_size, "GtkGaimStatusBox"); | |
13062 | 513 width = gdk_pixbuf_get_width(pixbuf) / 2; |
514 height = gdk_pixbuf_get_height(pixbuf) / 2; | |
13050 | 515 |
13062 | 516 gdk_pixbuf_composite(emblem, pixbuf, width, height, |
517 width, height, width, height, | |
518 0.5, 0.5, GDK_INTERP_BILINEAR, 255); | |
13050 | 519 g_object_unref(G_OBJECT(emblem)); |
12778 | 520 |
12779 | 521 gtk_gaim_status_box_add_separator(statusbox); |
522 | |
12778 | 523 for (cur = list; cur != NULL; cur = cur->next) |
524 { | |
525 GaimSavedStatus *saved = cur->data; | |
13050 | 526 const gchar *message; |
527 gchar *stripped; | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
528 |
13050 | 529 /* TODO: For transient saved-statuses, make a new icon showing the primitive */ |
530 | |
531 if (gaim_savedstatus_is_transient(saved)) | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
532 { |
13050 | 533 /* |
534 * Transient statuses do not have a title, so the savedstatus | |
535 * API returns the message when gaim_savedstatus_get_title() is | |
536 * called, so we don't need to get the message a second time. | |
537 */ | |
538 stripped = NULL; | |
539 } | |
540 else | |
541 { | |
542 message = gaim_savedstatus_get_message(saved); | |
543 stripped = gaim_markup_strip_html(message); | |
544 gaim_util_chrreplace(stripped, '\n', ' '); | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
545 } |
12778 | 546 gtk_gaim_status_box_add(statusbox, GTK_GAIM_STATUS_BOX_TYPE_POPULAR, |
13050 | 547 pixbuf, gaim_savedstatus_get_title(saved), stripped, |
12778 | 548 GINT_TO_POINTER(gaim_savedstatus_get_creation_time(saved))); |
13050 | 549 g_free(stripped); |
12778 | 550 } |
551 | |
552 g_list_free(list); | |
553 } | |
554 | |
555 static void | |
11732 | 556 gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) |
557 { | |
11739 | 558 GaimAccount *account; |
11732 | 559 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; |
560 GtkIconSize icon_size; | |
561 | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
562 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
563 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
564 else |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
565 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_SMALL); |
11732 | 566 |
12256 | 567 /* Unset the model while clearing it */ |
568 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), NULL); | |
11732 | 569 gtk_list_store_clear(status_box->dropdown_store); |
12256 | 570 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
|
571 |
11739 | 572 account = GTK_GAIM_STATUS_BOX(status_box)->account; |
573 if (account == NULL) | |
574 { | |
12779 | 575 /* Global */ |
11756 | 576 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_ONLINE, |
11732 | 577 icon_size, "GtkGaimStatusBox"); |
11756 | 578 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_AWAY, |
11732 | 579 icon_size, "GtkGaimStatusBox"); |
11756 | 580 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
11732 | 581 icon_size, "GtkGaimStatusBox"); |
11756 | 582 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_INVISIBLE, |
11732 | 583 icon_size, "GtkGaimStatusBox"); |
12779 | 584 |
585 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)); | |
586 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)); | |
587 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)); | |
588 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)); | |
589 | |
590 add_popular_statuses(status_box); | |
591 | |
11738 | 592 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box)); |
13025 | 593 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("New..."), NULL, NULL); |
12778 | 594 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL, NULL); |
595 | |
11870 | 596 update_to_reflect_current_status(status_box); |
11732 | 597 |
598 } else { | |
12779 | 599 /* Per-account */ |
11732 | 600 const GList *l; |
11739 | 601 |
602 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
603 { | |
11732 | 604 GaimStatusType *status_type = (GaimStatusType *)l->data; |
605 | |
606 if (!gaim_status_type_is_user_settable(status_type)) | |
607 continue; | |
608 | |
11739 | 609 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), |
610 gaim_status_type_get_primitive(status_type), | |
12080 | 611 gaim_gtk_create_prpl_icon_with_status(account, status_type), |
11739 | 612 gaim_status_type_get_name(status_type), |
12778 | 613 NULL, NULL); |
11732 | 614 } |
12779 | 615 |
11967 | 616 update_to_reflect_account_status(status_box, account, gaim_account_get_active_status(account)); |
11732 | 617 } |
618 } | |
619 | |
12827
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
620 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
|
621 { |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
622 gtk_combo_box_popup(GTK_COMBO_BOX(w)); |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
623 return TRUE; |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
624 } |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
625 |
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
626 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
|
627 { |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
628 if (event->direction == GDK_SCROLL_UP) |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
629 gtk_imhtml_page_up(imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
630 else if (event->direction == GDK_SCROLL_DOWN) |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
631 gtk_imhtml_page_down(imhtml); |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
632 return TRUE; |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
633 } |
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
634 |
12274 | 635 static int imhtml_remove_focus(GtkWidget *w, GdkEventKey *event, GtkGaimStatusBox *box) |
636 { | |
637 if (event->keyval == GDK_Tab || event->keyval == GDK_KP_Tab) | |
638 { | |
639 /* If last inserted character is a tab, then remove the focus from here */ | |
640 GtkWidget *top = gtk_widget_get_toplevel(w); | |
641 g_signal_emit_by_name(G_OBJECT(top), "move_focus", | |
642 (event->state & GDK_SHIFT_MASK) ? | |
643 GTK_DIR_TAB_BACKWARD: GTK_DIR_TAB_FORWARD); | |
644 return TRUE; | |
645 } | |
646 if (!box->typing) | |
647 return FALSE; | |
648 gtk_gaim_status_box_pulse_typing(box); | |
649 g_source_remove(box->typing); | |
12309 | 650 box->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, box); |
12460
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
651 |
12274 | 652 return FALSE; |
653 } | |
654 | |
11753 | 655 #if GTK_CHECK_VERSION(2,6,0) |
11738 | 656 static gboolean |
657 dropdown_store_row_separator_func(GtkTreeModel *model, | |
658 GtkTreeIter *iter, gpointer data) | |
659 { | |
11739 | 660 GtkGaimStatusBoxItemType type; |
11738 | 661 |
11885 | 662 gtk_tree_model_get(model, iter, TYPE_COLUMN, &type, -1); |
11738 | 663 |
11739 | 664 if (type == GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR) |
11738 | 665 return TRUE; |
666 | |
667 return FALSE; | |
668 } | |
11753 | 669 #endif |
11738 | 670 |
10643 | 671 static void |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
672 cache_pixbufs(GtkGaimStatusBox *status_box) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
673 { |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
674 GtkIconSize icon_size; |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
675 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
676 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) |
13065 | 677 { |
678 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
|
679 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_TWO_LINE); |
13065 | 680 } else { |
681 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
|
682 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_SMALL_TWO_LINE); |
13065 | 683 } |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
684 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
685 if (status_box->error_pixbuf != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
686 gdk_pixbuf_unref(status_box->error_pixbuf); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
687 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
688 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box->vbox), GAIM_STOCK_STATUS_OFFLINE, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
689 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
690 if (status_box->connecting_pixbufs[0] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
691 gdk_pixbuf_unref(status_box->connecting_pixbufs[0]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
692 if (status_box->connecting_pixbufs[1] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
693 gdk_pixbuf_unref(status_box->connecting_pixbufs[1]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
694 if (status_box->connecting_pixbufs[2] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
695 gdk_pixbuf_unref(status_box->connecting_pixbufs[2]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
696 if (status_box->connecting_pixbufs[3] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
697 gdk_pixbuf_unref(status_box->connecting_pixbufs[3]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
698 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
699 status_box->connecting_index = 0; |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
700 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
|
701 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
702 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
|
703 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
704 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
|
705 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
706 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
|
707 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
708 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
709 if (status_box->typing_pixbufs[0] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
710 gdk_pixbuf_unref(status_box->typing_pixbufs[0]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
711 if (status_box->typing_pixbufs[1] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
712 gdk_pixbuf_unref(status_box->typing_pixbufs[1]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
713 if (status_box->typing_pixbufs[2] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
714 gdk_pixbuf_unref(status_box->typing_pixbufs[2]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
715 if (status_box->typing_pixbufs[3] != NULL) |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
716 gdk_pixbuf_unref(status_box->typing_pixbufs[3]); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
717 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
718 status_box->typing_index = 0; |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
719 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
|
720 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
721 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
|
722 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
723 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
|
724 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
725 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
|
726 icon_size, "GtkGaimStatusBox"); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
727 } |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
728 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
729 static void |
11954 | 730 current_status_pref_changed_cb(const char *name, GaimPrefType type, |
12816 | 731 gconstpointer val, gpointer data) |
11954 | 732 { |
12244 | 733 GtkGaimStatusBox *box = data; |
12778 | 734 |
735 /* Make sure our current status is added to the list of popular statuses */ | |
736 gtk_gaim_status_box_regenerate(box); | |
737 | |
12244 | 738 if (box->account) |
739 update_to_reflect_account_status(box, box->account, | |
740 gaim_account_get_active_status(box->account)); | |
741 else | |
742 update_to_reflect_current_status(box); | |
11954 | 743 } |
744 | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
745 static void |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
746 buddy_list_details_pref_changed_cb(const char *name, GaimPrefType type, |
12816 | 747 gconstpointer val, gpointer data) |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
748 { |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
749 GtkGaimStatusBox *status_box = (GtkGaimStatusBox *)data; |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
750 |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
751 cache_pixbufs(status_box); |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
752 gtk_gaim_status_box_regenerate(status_box); |
12606
51b0ce9d45d9
[gaim-migrate @ 14942]
Richard Laager <rlaager@wiktel.com>
parents:
12598
diff
changeset
|
753 update_size(status_box); |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
754 } |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
755 |
12651 | 756 static void |
757 spellcheck_prefs_cb(const char *name, GaimPrefType type, | |
12816 | 758 gconstpointer value, gpointer data) |
12651 | 759 { |
760 #ifdef USE_GTKSPELL | |
761 GtkGaimStatusBox *status_box = (GtkGaimStatusBox *)data; | |
762 | |
763 if (value) | |
764 gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(status_box->imhtml)); | |
765 else | |
766 { | |
767 GtkSpell *spell; | |
768 spell = gtkspell_get_from_text_view(GTK_TEXT_VIEW(status_box->imhtml)); | |
769 gtkspell_detach(spell); | |
770 } | |
771 #endif | |
772 } | |
773 | |
12294
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
774 #if 0 |
12262 | 775 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
|
776 { |
12286
255e6912607b
[gaim-migrate @ 14590]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12275
diff
changeset
|
777 |
12274 | 778 if (event->button != 1) |
779 return FALSE; | |
12262 | 780 gtk_combo_box_popdown(GTK_COMBO_BOX(box)); |
781 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box->toggle_button), FALSE); | |
782 if (!box->imhtml_visible) | |
783 g_signal_emit_by_name(G_OBJECT(box), "changed", NULL, NULL); | |
784 return TRUE; | |
785 } | |
786 | |
787 static gboolean button_pressed_cb(GtkWidget *widget, GdkEventButton *event, GtkGaimStatusBox *box) | |
788 { | |
12274 | 789 if (event->button != 1) |
790 return FALSE; | |
12262 | 791 gtk_combo_box_popup(GTK_COMBO_BOX(box)); |
12274 | 792 // Disabled until button_released_cb works |
793 // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box->toggle_button), TRUE); | |
12262 | 794 return TRUE; |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
795 } |
12294
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
796 #endif |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
797 |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
798 static void |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
799 toggled_cb(GtkWidget *widget, GtkGaimStatusBox *box) |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
800 { |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
801 gtk_combo_box_popup(GTK_COMBO_BOX(box)); |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
802 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
|
803 } |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
804 |
11954 | 805 static void |
10643 | 806 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) |
807 { | |
11400 | 808 GtkCellRenderer *text_rend; |
809 GtkCellRenderer *icon_rend; | |
10643 | 810 GtkTextBuffer *buffer; |
811 | |
812 status_box->imhtml_visible = FALSE; | |
813 status_box->connecting = FALSE; | |
814 status_box->typing = FALSE; | |
815 status_box->title = NULL; | |
10861 | 816 status_box->pixbuf = NULL; |
12262 | 817 status_box->toggle_button = gtk_toggle_button_new(); |
818 status_box->hbox = gtk_hbox_new(FALSE, 6); | |
10643 | 819 status_box->cell_view = gtk_cell_view_new(); |
12262 | 820 status_box->vsep = gtk_vseparator_new(); |
821 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
|
822 |
12778 | 823 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); |
824 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 | 825 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
826 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
827 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
828 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
829 gtk_gaim_status_box_refresh(status_box); | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
830 |
12262 | 831 gtk_container_add(GTK_CONTAINER(status_box->toggle_button), status_box->hbox); |
832 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->cell_view, TRUE, TRUE, 0); | |
12274 | 833 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->vsep, FALSE, FALSE, 0); |
834 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->arrow, FALSE, FALSE, 0); | |
12262 | 835 gtk_widget_show_all(status_box->toggle_button); |
836 #if GTK_CHECK_VERSION(2,4,0) | |
837 gtk_button_set_focus_on_click(GTK_BUTTON(status_box->toggle_button), FALSE); | |
838 #endif | |
10643 | 839 |
13044 | 840 text_rend = gtk_cell_renderer_text_new(); |
841 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
10643 | 842 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); |
10861 | 843 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
10643 | 844 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
845 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
13045 | 846 #if GTK_CHECK_VERSION(2, 6, 0) |
847 g_object_set(text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
848 #endif | |
10643 | 849 |
13044 | 850 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
851 status_box->text_rend = gtk_cell_renderer_text_new(); | |
10643 | 852 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); |
11499 | 853 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
10643 | 854 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
855 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
13045 | 856 #if GTK_CHECK_VERSION(2, 6, 0) |
857 g_object_set(status_box->text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | |
858 #endif | |
10643 | 859 |
860 status_box->vbox = gtk_vbox_new(0, FALSE); | |
12879
f8748df5c17a
[gaim-migrate @ 15231]
Gary Kramlich <grim@reaperworld.com>
parents:
12827
diff
changeset
|
861 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
|
862 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
12286
255e6912607b
[gaim-migrate @ 14590]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12275
diff
changeset
|
863 |
10643 | 864 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
|
865 #if 0 |
12274 | 866 g_signal_connect(G_OBJECT(status_box->toggle_button), "button-press-event", |
867 G_CALLBACK(button_pressed_cb), status_box); | |
868 g_signal_connect(G_OBJECT(status_box->toggle_button), "button-release-event", | |
869 G_CALLBACK(button_released_cb), status_box); | |
12294
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
870 #endif |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
871 g_signal_connect(G_OBJECT(status_box->toggle_button), "toggled", |
d6b5373948f9
[gaim-migrate @ 14598]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12286
diff
changeset
|
872 G_CALLBACK(toggled_cb), status_box); |
10643 | 873 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
|
874 g_signal_connect(G_OBJECT(status_box->imhtml), "format_function_toggle", |
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
875 G_CALLBACK(imhtml_format_changed_cb), status_box); |
12274 | 876 g_signal_connect(G_OBJECT(status_box->imhtml), "key_press_event", |
877 G_CALLBACK(imhtml_remove_focus), status_box); | |
11562 | 878 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
10643 | 879 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
12651 | 880 #ifdef USE_GTKSPELL |
881 if (gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck")) | |
882 gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(status_box->imhtml)); | |
883 #endif | |
10643 | 884 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); |
12262 | 885 gtk_widget_set_parent(status_box->toggle_button, GTK_WIDGET(status_box)); |
12275 | 886 GTK_BIN(status_box)->child = status_box->toggle_button; |
12269 | 887 |
10643 | 888 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); |
11654 | 889 |
12827
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
890 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
|
891 g_signal_connect(G_OBJECT(status_box->imhtml), "scroll_event", |
12827
0f40c44348f4
[gaim-migrate @ 15175]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
892 G_CALLBACK(imhtml_scroll_event_cb), status_box->imhtml); |
12075
f62022e07351
[gaim-migrate @ 14372]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12074
diff
changeset
|
893 |
11850 | 894 #if GTK_CHECK_VERSION(2,6,0) |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
895 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); |
11850 | 896 #endif |
897 | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
898 cache_pixbufs(status_box); |
11732 | 899 gtk_gaim_status_box_regenerate(status_box); |
11954 | 900 |
12123 | 901 gaim_prefs_connect_callback(status_box, "/core/savedstatus/current", |
11954 | 902 current_status_pref_changed_cb, status_box); |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12585
diff
changeset
|
903 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
|
904 buddy_list_details_pref_changed_cb, status_box); |
12651 | 905 gaim_prefs_connect_callback(status_box, "/gaim/gtk/conversations/spellcheck", |
906 spellcheck_prefs_cb, status_box); | |
10643 | 907 } |
908 | |
909 static void | |
10861 | 910 gtk_gaim_status_box_size_request(GtkWidget *widget, |
911 GtkRequisition *requisition) | |
10643 | 912 { |
913 GtkRequisition box_req; | |
914 combo_box_size_request(widget, requisition); | |
12596
037a673ba862
[gaim-migrate @ 14926]
Richard Laager <rlaager@wiktel.com>
parents:
12595
diff
changeset
|
915 requisition->height += 3; |
10861 | 916 |
13065 | 917 /* If the gtkimhtml is visible, then add some additional padding */ |
10643 | 918 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
919 if (box_req.height > 1) | |
13065 | 920 requisition->height += box_req.height + 3; |
12286
255e6912607b
[gaim-migrate @ 14590]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12275
diff
changeset
|
921 |
10643 | 922 requisition->width = 1; |
923 } | |
924 | |
925 static void | |
10861 | 926 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
927 GtkAllocation *allocation) | |
10643 | 928 { |
929 GtkRequisition req = {0,0}; | |
11400 | 930 GtkAllocation parent_alc, box_alc; |
931 | |
10643 | 932 combo_box_size_request(widget, &req); |
10861 | 933 |
13065 | 934 box_alc = *allocation; |
12596
037a673ba862
[gaim-migrate @ 14926]
Richard Laager <rlaager@wiktel.com>
parents:
12595
diff
changeset
|
935 box_alc.height = MAX(1, (allocation->height - req.height - 6)); |
13065 | 936 box_alc.y += req.height + 6; |
10643 | 937 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); |
10861 | 938 |
13065 | 939 parent_alc = *allocation; |
10643 | 940 parent_alc.height = MAX(1,req.height); |
12102
8df87db79bad
[gaim-migrate @ 14399]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12100
diff
changeset
|
941 parent_alc.y += 3; |
10643 | 942 combo_box_size_allocate(widget, &parent_alc); |
12262 | 943 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->toggle_button, &parent_alc); |
10643 | 944 widget->allocation = *allocation; |
945 } | |
946 | |
947 static gboolean | |
10861 | 948 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
12262 | 949 GdkEventExpose *event) |
10643 | 950 { |
10861 | 951 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
12262 | 952 gtk_container_propagate_expose(GTK_CONTAINER(widget), status_box->vbox, event); |
12275 | 953 gtk_container_propagate_expose(GTK_CONTAINER(widget), status_box->toggle_button, event); |
10861 | 954 return FALSE; |
10643 | 955 } |
956 | |
957 static void | |
10861 | 958 gtk_gaim_status_box_forall(GtkContainer *container, |
959 gboolean include_internals, | |
960 GtkCallback callback, | |
961 gpointer callback_data) | |
10643 | 962 { |
10861 | 963 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
10643 | 964 |
10861 | 965 if (include_internals) |
966 { | |
967 (* callback) (status_box->vbox, callback_data); | |
12275 | 968 (* callback) (status_box->toggle_button, callback_data); |
969 (* callback) (status_box->arrow, callback_data); | |
10861 | 970 } |
10643 | 971 |
10861 | 972 combo_box_forall(container, include_internals, callback, callback_data); |
10643 | 973 } |
974 | |
975 GtkWidget * | |
976 gtk_gaim_status_box_new() | |
977 { | |
978 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
979 } | |
980 | |
11499 | 981 GtkWidget * |
982 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
983 { | |
984 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
985 } | |
10643 | 986 |
13050 | 987 /** |
988 * Add a row to the dropdown menu. | |
989 * | |
990 * @param status_box The status box itself. | |
991 * @param type A GtkGaimStatusBoxItemType. | |
992 * @param pixbuf The icon to associate with this row in the menu. | |
993 * @param title The title of this item. For the primitive entries, | |
994 * this is something like "Available" or "Away." For | |
995 * the saved statuses, this is something like | |
996 * "My favorite away message!" This should be | |
997 * plaintext (non-markedup) (this function escapes it). | |
998 * @param desc The secondary text for this item. This will be | |
999 * placed on the row below the title, in a dimmer | |
1000 * font (generally gray). This text should be plaintext | |
1001 * (non-markedup) (this function escapes it). | |
1002 * @param data Data to be associated with this row in the dropdown | |
1003 * menu. For primitives this is the value of the | |
1004 * GaimStatusPrimitive. For saved statuses this is the | |
1005 * creation timestamp. | |
1006 */ | |
10643 | 1007 void |
13050 | 1008 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *title, const char *desc, gpointer data) |
10643 | 1009 { |
1010 GtkTreeIter iter; | |
13050 | 1011 char *text; |
10861 | 1012 |
13050 | 1013 if (desc == NULL) |
1014 { | |
1015 text = g_markup_escape_text(title, -1); | |
1016 } | |
1017 else | |
1018 { | |
10643 | 1019 char aa_color[8]; |
13050 | 1020 gchar *escaped_title, *escaped_desc; |
1021 GtkStyle *style; | |
1022 | |
1023 style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
10643 | 1024 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", |
1025 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
1026 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
10861 | 1027 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
13050 | 1028 |
1029 escaped_title = g_markup_escape_text(title, -1); | |
1030 escaped_desc = g_markup_escape_text(desc, -1); | |
1031 text = g_strdup_printf("%s\n<span color=\"%s\" size=\"smaller\">%s</span>", | |
1032 escaped_title, aa_color, escaped_desc); | |
1033 g_free(escaped_title); | |
1034 g_free(escaped_desc); | |
10643 | 1035 } |
10861 | 1036 |
10643 | 1037 gtk_list_store_append(status_box->dropdown_store, &iter); |
1038 gtk_list_store_set(status_box->dropdown_store, &iter, | |
13050 | 1039 TYPE_COLUMN, type, |
1040 ICON_COLUMN, pixbuf, | |
1041 TEXT_COLUMN, text, | |
1042 TITLE_COLUMN, title, | |
1043 DESC_COLUMN, desc, | |
1044 DATA_COLUMN, data, | |
1045 -1); | |
1046 g_free(text); | |
10643 | 1047 } |
1048 | |
1049 void | |
11738 | 1050 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
1051 { | |
11756 | 1052 /* Don't do anything unless GTK actually supports |
1053 * gtk_combo_box_set_row_separator_func */ | |
1054 #if GTK_CHECK_VERSION(2,6,0) | |
11738 | 1055 GtkTreeIter iter; |
1056 | |
1057 gtk_list_store_append(status_box->dropdown_store, &iter); | |
1058 gtk_list_store_set(status_box->dropdown_store, &iter, | |
11739 | 1059 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
1060 -1); | |
11756 | 1061 #endif |
11738 | 1062 } |
1063 | |
1064 void | |
10643 | 1065 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
1066 { | |
11523 | 1067 if (status_box->error) |
1068 g_free(status_box->error); | |
11891 | 1069 status_box->error = NULL; |
13023 | 1070 #if 0 |
11891 | 1071 if (error != NULL) |
1072 status_box->error = g_strdup(error); | |
13023 | 1073 #endif |
10643 | 1074 gtk_gaim_status_box_refresh(status_box); |
1075 } | |
1076 | |
1077 void | |
1078 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
1079 { | |
1080 if (!status_box) | |
1081 return; | |
1082 status_box->connecting = connecting; | |
1083 gtk_gaim_status_box_refresh(status_box); | |
1084 } | |
1085 | |
1086 void | |
1087 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
1088 { | |
1089 if (!status_box) | |
1090 return; | |
1091 if (status_box->connecting_index == 3) | |
1092 status_box->connecting_index = 0; | |
10861 | 1093 else |
10643 | 1094 status_box->connecting_index++; |
1095 gtk_gaim_status_box_refresh(status_box); | |
1096 } | |
1097 | |
12274 | 1098 static void |
10643 | 1099 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) |
1100 { | |
1101 if (status_box->typing_index == 3) | |
1102 status_box->typing_index = 0; | |
10861 | 1103 else |
10643 | 1104 status_box->typing_index++; |
1105 gtk_gaim_status_box_refresh(status_box); | |
1106 } | |
1107 | |
13050 | 1108 static GaimStatusType * |
1109 find_status_type_by_index(const GaimAccount *account, gint active) | |
11993 | 1110 { |
1111 const GList *l = gaim_account_get_status_types(account); | |
1112 gint i; | |
1113 | |
1114 for (i = 0; l; l = l->next) { | |
1115 GaimStatusType *status_type = l->data; | |
1116 if (!gaim_status_type_is_user_settable(status_type)) | |
1117 continue; | |
1118 | |
1119 if (active == i) | |
1120 return status_type; | |
1121 i++; | |
1122 } | |
1123 | |
1124 return NULL; | |
1125 } | |
1126 | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1127 static gboolean |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1128 message_changed(const char *one, const char *two) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1129 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1130 if (one == NULL && two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1131 return FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1132 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1133 if (one == NULL || two == NULL) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1134 return TRUE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1135 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1136 return (g_utf8_collate(one, two) != 0); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1137 } |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1138 |
11654 | 1139 static void |
1140 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
10643 | 1141 { |
11739 | 1142 GtkGaimStatusBoxItemType type; |
12779 | 1143 gpointer data; |
11739 | 1144 gchar *title; |
10643 | 1145 GtkTreeIter iter; |
11654 | 1146 char *message; |
1147 GaimSavedStatus *saved_status; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1148 gboolean changed = TRUE; |
10643 | 1149 |
11951 | 1150 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) |
1151 return; | |
12659 | 1152 |
11654 | 1153 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
12779 | 1154 TYPE_COLUMN, &type, |
1155 DATA_COLUMN, &data, | |
1156 -1); | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
1157 |
11739 | 1158 /* |
13025 | 1159 * If the currently selected status is "New..." or |
12779 | 1160 * "Saved..." or a popular status then do nothing. |
1161 * Custom statuses are | |
11954 | 1162 * activated elsewhere, and we update the status_box |
1163 * accordingly by monitoring the preference | |
12123 | 1164 * "/core/savedstatus/current" and then calling |
11954 | 1165 * update_to_reflect_current_status() |
11739 | 1166 */ |
12779 | 1167 if (type != GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE) |
11739 | 1168 return; |
11654 | 1169 |
12659 | 1170 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
1171 TITLE_COLUMN, &title, -1); | |
1172 | |
1173 message = gtk_gaim_status_box_get_message(status_box); | |
1174 if (!message || !*message) | |
1175 { | |
1176 gtk_widget_hide_all(status_box->vbox); | |
1177 status_box->imhtml_visible = FALSE; | |
1178 } | |
1179 | |
12779 | 1180 if (status_box->account == NULL) { |
1181 /* Global */ | |
1182 /* Save the newly selected status to prefs.xml and status.xml */ | |
1183 | |
1184 /* Has the status been really changed? */ | |
1185 saved_status = gaim_savedstatus_get_current(); | |
1186 if (gaim_savedstatus_get_type(saved_status) == GPOINTER_TO_INT(data)) | |
1187 { | |
1188 if (!message_changed(gaim_savedstatus_get_message(saved_status), message)) | |
1189 changed = FALSE; | |
1190 } | |
1191 | |
1192 if (changed) | |
1193 { | |
13012 | 1194 /* If we've used this type+message before, lookup the transient status */ |
1195 saved_status = gaim_savedstatus_find_by_type_and_message( | |
1196 GPOINTER_TO_INT(data), message); | |
1197 | |
1198 | |
1199 /* If this type+message is unique then create a new transient saved status */ | |
1200 if (saved_status == NULL) | |
1201 { | |
1202 saved_status = gaim_savedstatus_new(NULL, GPOINTER_TO_INT(data)); | |
1203 gaim_savedstatus_set_message(saved_status, message); | |
1204 } | |
12779 | 1205 |
1206 /* Set the status for each account */ | |
1207 gaim_savedstatus_activate(saved_status); | |
1208 } | |
1209 } else { | |
1210 /* Per-account */ | |
11981 | 1211 gint active; |
1212 GaimStatusType *status_type; | |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1213 GaimStatus *status; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1214 const char *id = NULL; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1215 |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1216 status = gaim_account_get_active_status(status_box->account); |
11981 | 1217 |
1218 g_object_get(G_OBJECT(status_box), "active", &active, NULL); | |
11654 | 1219 |
11993 | 1220 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
|
1221 id = gaim_status_type_get_id(status_type); |
11981 | 1222 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1223 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
|
1224 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1225 /* Selected status and previous status is the same */ |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1226 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
|
1227 changed = FALSE; |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1228 } |
12123 | 1229 |
12076
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1230 if (changed) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1231 { |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1232 if (message) |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1233 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1234 TRUE, "message", message, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1235 else |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1236 gaim_account_set_status(status_box->account, id, |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1237 TRUE, NULL); |
4fb1edd43f45
[gaim-migrate @ 14373]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12075
diff
changeset
|
1238 } |
11981 | 1239 } |
11627 | 1240 |
11638 | 1241 g_free(title); |
11654 | 1242 g_free(message); |
1243 } | |
1244 | |
12597
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1245 static void update_size(GtkGaimStatusBox *status_box) |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1246 { |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1247 GtkTextBuffer *buffer; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1248 GtkTextIter iter; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1249 int wrapped_lines; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1250 int lines; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1251 GdkRectangle oneline; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1252 int height; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1253 int pad_top, pad_inside, pad_bottom; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1254 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1255 if (!status_box->imhtml_visible) |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1256 { |
12598
1c122dbc8e9e
[gaim-migrate @ 14928]
Richard Laager <rlaager@wiktel.com>
parents:
12597
diff
changeset
|
1257 if (status_box->vbox != NULL) |
1c122dbc8e9e
[gaim-migrate @ 14928]
Richard Laager <rlaager@wiktel.com>
parents:
12597
diff
changeset
|
1258 gtk_widget_set_size_request(status_box->vbox, -1, -1); |
12597
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1259 return; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1260 } |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1261 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1262 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
|
1263 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1264 wrapped_lines = 1; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1265 gtk_text_buffer_get_start_iter(buffer, &iter); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1266 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
|
1267 wrapped_lines++; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1268 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1269 lines = gtk_text_buffer_get_line_count(buffer); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1270 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1271 /* Show a maximum of 4 lines */ |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1272 lines = MIN(lines, 4); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1273 wrapped_lines = MIN(wrapped_lines, 4); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1274 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1275 gtk_text_buffer_get_start_iter(buffer, &iter); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1276 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
|
1277 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1278 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
|
1279 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
|
1280 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
|
1281 |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1282 height = (oneline.height + pad_top + pad_bottom) * lines; |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1283 height += (oneline.height + pad_inside) * (wrapped_lines - lines); |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1284 |
12905
ee0c8c446eef
[gaim-migrate @ 15258]
Richard Laager <rlaager@wiktel.com>
parents:
12879
diff
changeset
|
1285 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
|
1286 } |
842b3b897cde
[gaim-migrate @ 14927]
Richard Laager <rlaager@wiktel.com>
parents:
12596
diff
changeset
|
1287 |
11654 | 1288 static void remove_typing_cb(GtkGaimStatusBox *status_box) |
1289 { | |
12782 | 1290 if (status_box->typing == 0) |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1291 { |
12782 | 1292 /* 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
|
1293 update_to_reflect_current_status(status_box); |
12782 | 1294 return; |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1295 } |
12782 | 1296 |
11654 | 1297 activate_currently_selected_status(status_box); |
1298 | |
1299 g_source_remove(status_box->typing); | |
1300 status_box->typing = 0; | |
1301 gtk_gaim_status_box_refresh(status_box); | |
10643 | 1302 } |
1303 | |
1304 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
1305 { | |
11400 | 1306 GtkGaimStatusBox *status_box; |
10643 | 1307 GtkTreeIter iter; |
11739 | 1308 GtkGaimStatusBoxItemType type; |
13050 | 1309 char *text, *desc; |
10643 | 1310 GdkPixbuf *pixbuf; |
12778 | 1311 gpointer data; |
11960 | 1312 GList *accounts = NULL, *node; |
10643 | 1313 |
11400 | 1314 status_box = GTK_GAIM_STATUS_BOX(box); |
1315 | |
12074
950acb2bc835
[gaim-migrate @ 14370]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12060
diff
changeset
|
1316 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
|
1317 return; |
11739 | 1318 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
1319 TYPE_COLUMN, &type, | |
1320 TITLE_COLUMN, &text, | |
13050 | 1321 DESC_COLUMN, &desc, |
12778 | 1322 ICON_COLUMN, &pixbuf, |
1323 DATA_COLUMN, &data, | |
11739 | 1324 -1); |
10643 | 1325 if (status_box->title) |
1326 g_free(status_box->title); | |
11638 | 1327 status_box->title = text; |
13050 | 1328 if (status_box->desc && desc) |
11638 | 1329 g_free(status_box->desc); |
13050 | 1330 status_box->desc = desc; |
10643 | 1331 if (status_box->pixbuf) |
1332 g_object_unref(status_box->pixbuf); | |
1333 status_box->pixbuf = pixbuf; | |
11638 | 1334 if (status_box->typing) |
1335 g_source_remove(status_box->typing); | |
1336 status_box->typing = 0; | |
10861 | 1337 |
11951 | 1338 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11729 | 1339 { |
12778 | 1340 if (type == GTK_GAIM_STATUS_BOX_TYPE_POPULAR) |
1341 { | |
1342 GaimSavedStatus *saved; | |
1343 saved = gaim_savedstatus_find_by_creation_time(GPOINTER_TO_INT(data)); | |
1344 g_return_if_fail(saved != NULL); | |
1345 gaim_savedstatus_activate(saved); | |
1346 return; | |
1347 } | |
1348 | |
11951 | 1349 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
1350 { | |
1351 gaim_gtk_status_editor_show(NULL); | |
1352 update_to_reflect_current_status(status_box); | |
1353 return; | |
1354 } | |
11729 | 1355 |
11951 | 1356 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
1357 { | |
1358 gaim_gtk_status_window_show(); | |
1359 update_to_reflect_current_status(status_box); | |
1360 return; | |
1361 } | |
11729 | 1362 } |
1363 | |
11654 | 1364 /* |
12779 | 1365 * Show the message box whenever the primitive allows for a |
11960 | 1366 * message attribute on any protocol that is enabled, |
1367 * or our protocol, if we have account set | |
11654 | 1368 */ |
11960 | 1369 if (status_box->account) |
1370 accounts = g_list_prepend(accounts, status_box->account); | |
1371 else | |
1372 accounts = gaim_accounts_get_all_active(); | |
11755 | 1373 status_box->imhtml_visible = FALSE; |
1374 for (node = accounts; node != NULL; node = node->next) | |
1375 { | |
1376 GaimAccount *account; | |
1377 GaimStatusType *status_type; | |
1378 | |
1379 account = node->data; | |
12779 | 1380 status_type = gaim_account_get_status_type_with_primitive(account, GPOINTER_TO_INT(data)); |
11755 | 1381 if ((status_type != NULL) && |
1382 (gaim_status_type_get_attr(status_type, "message") != NULL)) | |
1383 { | |
1384 status_box->imhtml_visible = TRUE; | |
1385 break; | |
1386 } | |
1387 } | |
1388 g_list_free(accounts); | |
11654 | 1389 |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1390 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
11654 | 1391 { |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1392 if (status_box->imhtml_visible) |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1393 { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1394 GtkTextBuffer *buf; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1395 GtkTextIter start, end; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1396 gtk_widget_show_all(status_box->vbox); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1397 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1398 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
|
1399 } |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1400 gtk_widget_grab_focus(status_box->imhtml); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1401 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
|
1402 gtk_text_buffer_get_start_iter(buf, &start); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1403 gtk_text_buffer_get_end_iter(buf, &end); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1404 gtk_text_buffer_move_mark_by_name(buf, "insert", &end); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1405 gtk_text_buffer_move_mark_by_name(buf, "selection_bound", &start); |
12274 | 1406 } |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1407 else |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1408 { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1409 gtk_widget_hide_all(status_box->vbox); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1410 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(status_box))) |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1411 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
|
1412 } |
10643 | 1413 } |
1414 gtk_gaim_status_box_refresh(status_box); | |
1415 } | |
1416 | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1417 static gint |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1418 get_statusbox_index(GtkGaimStatusBox *box, GaimSavedStatus *saved_status) |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1419 { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1420 gint index; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1421 |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1422 switch (gaim_savedstatus_get_type(saved_status)) |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1423 { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1424 case GAIM_STATUS_AVAILABLE: |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1425 index = 0; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1426 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1427 case GAIM_STATUS_AWAY: |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1428 index = 1; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1429 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1430 case GAIM_STATUS_INVISIBLE: |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1431 index = 2; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1432 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1433 case GAIM_STATUS_OFFLINE: |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1434 index = 3; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1435 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1436 default: |
13050 | 1437 /* |
1438 * TODO: This is very bad! I believe it's causing the infinite | |
1439 * windows bug. Need to do something better here. | |
1440 */ | |
1441 /* index = GTK_LIST_STORE(box->dropdown_store)->length - 2; */ | |
1442 index = 0; | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1443 break; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1444 } |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1445 |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1446 return index; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1447 } |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1448 |
10643 | 1449 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) |
1450 { | |
1451 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
11951 | 1452 if (GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(box))) |
1453 { | |
1454 if (box->typing) { | |
1455 gtk_gaim_status_box_pulse_typing(box); | |
1456 g_source_remove(box->typing); | |
12932
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1457 } else { |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1458 gint index; |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1459 GaimSavedStatus *saved = gaim_savedstatus_get_current(); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1460 |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1461 index = get_statusbox_index(box, saved); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1462 |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1463 gtk_widget_set_sensitive(GTK_WIDGET(box), FALSE); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1464 gtk_combo_box_set_active(GTK_COMBO_BOX(box), index); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1465 gtk_widget_set_sensitive(GTK_WIDGET(box), TRUE); |
d7b9fa3b7baf
[gaim-migrate @ 15285]
Luke Schierer <lschiere@pidgin.im>
parents:
12905
diff
changeset
|
1466 gtk_widget_grab_focus(box->imhtml); |
11951 | 1467 } |
12309 | 1468 box->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, box); |
10861 | 1469 } |
10643 | 1470 gtk_gaim_status_box_refresh(box); |
1471 } | |
10649 | 1472 |
12460
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
1473 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
|
1474 { |
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
1475 imhtml_changed_cb(NULL, data); |
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
1476 } |
3d999a4d4892
[gaim-migrate @ 14770]
Richard Laager <rlaager@wiktel.com>
parents:
12379
diff
changeset
|
1477 |
11638 | 1478 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
10649 | 1479 { |
1480 if (status_box->imhtml_visible) | |
1481 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
1482 else | |
1483 return NULL; | |
1484 } |