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