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