Mercurial > pidgin
annotate src/gtkstatusbox.c @ 11739:a25be0e70a67
[gaim-migrate @ 14030]
I changed the GtkStatusBox list stores to use an enum instead of a string
to identify the items in the GtkStatusBox. This feels a lot cleaner to me
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sun, 23 Oct 2005 06:46:07 +0000 |
| parents | 992d49cf2b92 |
| children | 59ae71ae0b7c |
| 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" | |
| 36 | |
| 37 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); | |
| 11562 | 38 static void remove_typing_cb(GtkGaimStatusBox *box); |
| 10643 | 39 |
| 11732 | 40 static void gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box); |
| 10643 | 41 static void gtk_gaim_status_box_changed(GtkComboBox *box); |
| 42 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
| 43 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
| 44 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); | |
| 45 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
| 46 | |
| 47 static void (*combo_box_size_request)(GtkWidget *widget, GtkRequisition *requisition); | |
| 48 static void (*combo_box_size_allocate)(GtkWidget *widget, GtkAllocation *allocation); | |
| 49 static gboolean (*combo_box_expose_event)(GtkWidget *widget, GdkEventExpose *event); | |
| 50 static void (*combo_box_forall) (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | |
| 11739 | 51 |
| 10643 | 52 enum { |
| 11739 | 53 TYPE_COLUMN, /* A GtkGaimStatusBoxItemType */ |
| 11738 | 54 ICON_COLUMN, /* This is a GdkPixbuf (the other columns are strings) */ |
| 55 TEXT_COLUMN, /* A string */ | |
| 56 TITLE_COLUMN, /* The plain-English title of this item */ | |
| 57 DESC_COLUMN, /* A plain-English description of this item */ | |
| 10643 | 58 NUM_COLUMNS |
| 59 }; | |
| 60 | |
| 11499 | 61 enum { |
| 62 PROP_0, | |
| 63 PROP_ACCOUNT | |
| 64 }; | |
| 65 | |
| 10643 | 66 static void gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass); |
| 67 static void gtk_gaim_status_box_init (GtkGaimStatusBox *status_box); | |
| 68 | |
| 69 GType | |
| 70 gtk_gaim_status_box_get_type (void) | |
| 71 { | |
| 10861 | 72 static GType status_box_type = 0; |
| 10643 | 73 |
| 10861 | 74 if (!status_box_type) |
| 75 { | |
| 76 static const GTypeInfo status_box_info = | |
| 77 { | |
| 78 sizeof (GtkGaimStatusBoxClass), | |
| 79 NULL, /* base_init */ | |
| 80 NULL, /* base_finalize */ | |
| 81 (GClassInitFunc) gtk_gaim_status_box_class_init, | |
| 82 NULL, /* class_finalize */ | |
| 83 NULL, /* class_data */ | |
| 84 sizeof (GtkGaimStatusBox), | |
| 85 0, | |
| 86 (GInstanceInitFunc) gtk_gaim_status_box_init | |
| 87 }; | |
| 10643 | 88 |
| 10861 | 89 status_box_type = g_type_register_static(GTK_TYPE_COMBO_BOX, |
| 90 "GtkGaimStatusBox", | |
| 91 &status_box_info, | |
| 92 0); | |
| 93 } | |
| 10643 | 94 |
| 10861 | 95 return status_box_type; |
| 10643 | 96 } |
| 97 | |
| 98 static void | |
| 11499 | 99 gtk_gaim_status_box_get_property(GObject *object, guint param_id, |
| 100 GValue *value, GParamSpec *psec) | |
| 101 { | |
| 102 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
| 103 | |
| 104 switch (param_id) { | |
| 105 case PROP_ACCOUNT: | |
| 106 g_value_set_pointer(value, statusbox->account); | |
| 107 break; | |
| 108 default: | |
| 109 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, psec); | |
| 110 break; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 static void | |
| 115 gtk_gaim_status_box_set_property(GObject *object, guint param_id, | |
| 116 const GValue *value, GParamSpec *pspec) | |
| 117 { | |
| 118 GtkGaimStatusBox *statusbox = GTK_GAIM_STATUS_BOX(object); | |
| 119 | |
| 120 switch (param_id) { | |
| 121 case PROP_ACCOUNT: | |
| 122 statusbox->account = g_value_get_pointer(value); | |
| 11732 | 123 gtk_gaim_status_box_regenerate(statusbox); |
| 11499 | 124 break; |
| 125 default: | |
| 126 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | |
| 127 break; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 | |
| 132 static void | |
| 10643 | 133 gtk_gaim_status_box_class_init (GtkGaimStatusBoxClass *klass) |
| 134 { | |
| 10861 | 135 GObjectClass *object_class; |
| 136 GtkWidgetClass *widget_class; | |
| 137 GtkComboBoxClass *parent_class = (GtkComboBoxClass*)klass; | |
| 138 GtkContainerClass *container_class = (GtkContainerClass*)klass; | |
| 10643 | 139 |
| 10861 | 140 parent_class->changed = gtk_gaim_status_box_changed; |
| 141 widget_class = (GtkWidgetClass*)klass; | |
| 142 combo_box_size_request = widget_class->size_request; | |
| 143 widget_class->size_request = gtk_gaim_status_box_size_request; | |
| 144 combo_box_size_allocate = widget_class->size_allocate; | |
| 145 widget_class->size_allocate = gtk_gaim_status_box_size_allocate; | |
| 146 combo_box_expose_event = widget_class->expose_event; | |
| 147 widget_class->expose_event = gtk_gaim_status_box_expose_event; | |
| 10643 | 148 |
| 10861 | 149 combo_box_forall = container_class->forall; |
| 150 container_class->forall = gtk_gaim_status_box_forall; | |
| 151 | |
| 152 object_class = (GObjectClass *)klass; | |
| 11499 | 153 |
| 154 object_class->get_property = gtk_gaim_status_box_get_property; | |
| 155 object_class->set_property = gtk_gaim_status_box_set_property; | |
| 156 | |
| 157 g_object_class_install_property(object_class, | |
| 158 PROP_ACCOUNT, | |
| 159 g_param_spec_pointer("account", | |
| 160 "Account", | |
| 161 "The account, or NULL for all accounts", | |
| 162 G_PARAM_READWRITE | |
| 163 ) | |
| 164 ); | |
| 10643 | 165 } |
| 166 | |
| 167 static void | |
| 168 gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box) | |
| 169 { | |
|
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
170 char *text, *title; |
| 10643 | 171 char aa_color[8]; |
| 172 GdkPixbuf *pixbuf; | |
| 10702 | 173 GtkTreePath *path; |
| 10643 | 174 |
| 175 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
| 176 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
| 177 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
| 178 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
| 179 style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
|
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
180 |
|
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
181 title = status_box->title; |
|
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
182 if (!title) |
|
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
183 title = ""; |
|
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
184 |
| 10643 | 185 if (status_box->error) { |
| 11499 | 186 text = g_strdup_printf("%s\n<span size=\"smaller\" weight=\"bold\" color=\"red\">%s</span>", |
| 10861 | 187 title, status_box->error); |
| 10643 | 188 } else if (status_box->typing) { |
| 10861 | 189 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
| 190 title, aa_color, _("Typing")); | |
| 10643 | 191 } else if (status_box->connecting) { |
| 10861 | 192 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", |
| 193 title, aa_color, _("Connecting")); | |
| 194 } else if (status_box->desc) { | |
| 195 text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"%s\">%s</span>", | |
| 196 title, aa_color, status_box->desc); | |
| 10643 | 197 } else { |
|
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
198 text = g_strdup_printf("%s", title); |
| 10643 | 199 } |
| 10861 | 200 |
| 11523 | 201 if (status_box->connecting) |
| 202 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; | |
| 203 else if (status_box->error) | |
| 10643 | 204 pixbuf = status_box->error_pixbuf; |
| 205 else if (status_box->typing) | |
| 206 pixbuf = status_box->typing_pixbufs[status_box->typing_index]; | |
| 207 else | |
| 208 pixbuf = status_box->pixbuf; | |
| 209 | |
| 210 gtk_list_store_set(status_box->store, &(status_box->iter), | |
| 11739 | 211 TYPE_COLUMN, -1, /* TODO: Should use something real here? */ |
| 10643 | 212 ICON_COLUMN, pixbuf, |
| 10861 | 213 TEXT_COLUMN, text, |
|
10672
0925c898b73c
[gaim-migrate @ 12212]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10661
diff
changeset
|
214 TITLE_COLUMN, title, |
| 10861 | 215 DESC_COLUMN, status_box->desc, |
| 11739 | 216 -1); |
| 10702 | 217 path = gtk_tree_path_new_from_string("0"); |
| 218 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); | |
| 219 gtk_tree_path_free(path); | |
| 10643 | 220 |
| 221 g_free(text); | |
| 222 } | |
| 223 | |
| 11732 | 224 static GdkPixbuf * |
| 225 load_icon(const char *basename) | |
| 226 { | |
| 227 char basename2[BUFSIZ]; | |
| 228 char *filename; | |
| 229 GdkPixbuf *pixbuf, *scale = NULL; | |
| 230 | |
| 231 if (!strcmp(basename, "available")) | |
| 232 basename = "online"; | |
| 233 else if (!strcmp(basename, "hidden")) | |
| 234 basename = "invisible"; | |
| 235 | |
| 236 /* | |
| 237 * TODO: Find a way to fallback to the GaimStatusPrimitive | |
| 238 * if an icon for this id does not exist. | |
| 239 */ | |
| 240 g_snprintf(basename2, sizeof(basename2), "%s.png", | |
| 241 basename); | |
| 242 | |
| 243 | |
| 244 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", | |
| 245 basename2, NULL); | |
| 246 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
| 247 g_free(filename); | |
| 248 | |
| 249 if (pixbuf != NULL) { | |
| 250 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
| 251 GDK_INTERP_BILINEAR); | |
| 252 | |
| 253 g_object_unref(G_OBJECT(pixbuf)); | |
| 254 } else { | |
| 255 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
| 256 "default", basename, NULL); | |
| 257 scale = gdk_pixbuf_new_from_file(filename, NULL); | |
| 258 g_free(filename); | |
| 259 } | |
| 260 | |
| 261 return scale; | |
| 262 } | |
| 263 | |
| 264 static void | |
| 265 gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box) | |
| 266 { | |
| 11739 | 267 GaimAccount *account; |
| 11732 | 268 GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3, *pixbuf4; |
| 269 GtkIconSize icon_size; | |
| 270 const char *current_savedstatus_name; | |
| 271 GaimSavedStatus *saved_status; | |
| 272 | |
| 273 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
| 274 | |
| 275 gtk_list_store_clear(status_box->dropdown_store); | |
| 276 | |
| 11739 | 277 account = GTK_GAIM_STATUS_BOX(status_box)->account; |
| 278 if (account == NULL) | |
| 279 { | |
| 11732 | 280 pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_ONLINE, |
| 281 icon_size, "GtkGaimStatusBox"); | |
| 282 pixbuf2 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_AWAY, | |
| 283 icon_size, "GtkGaimStatusBox"); | |
| 284 pixbuf3 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
| 285 icon_size, "GtkGaimStatusBox"); | |
| 286 pixbuf4 = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_INVISIBLE, | |
| 287 icon_size, "GtkGaimStatusBox"); | |
| 288 /* hacks */ | |
| 11739 | 289 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AVAILABLE, pixbuf, _("Available"), NULL); |
| 290 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_AWAY, pixbuf2, _("Away"), NULL); | |
| 291 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_HIDDEN, pixbuf4, _("Invisible"), NULL); | |
| 292 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GAIM_STATUS_OFFLINE, pixbuf3, _("Offline"), NULL); | |
| 11738 | 293 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box)); |
| 11739 | 294 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("Custom..."), NULL); |
| 295 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL); | |
| 11732 | 296 |
| 297 current_savedstatus_name = gaim_prefs_get_string("/core/status/current"); | |
| 298 saved_status = gaim_savedstatus_find(current_savedstatus_name); | |
| 299 if (saved_status == NULL) | |
| 300 { | |
| 301 /* Default to "available" */ | |
| 302 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
| 303 } | |
| 304 else | |
| 305 { | |
| 306 GaimStatusPrimitive primitive; | |
| 307 const char *message; | |
| 308 | |
| 309 primitive = gaim_savedstatus_get_type(saved_status); | |
| 310 if (gaim_savedstatus_has_substatuses(saved_status) || | |
| 311 ((primitive != GAIM_STATUS_AVAILABLE) && | |
| 312 (primitive != GAIM_STATUS_OFFLINE) && | |
| 313 (primitive != GAIM_STATUS_AWAY) && | |
| 314 (primitive != GAIM_STATUS_HIDDEN))) | |
| 315 { | |
| 316 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 4); | |
| 317 } | |
| 318 else | |
| 319 { | |
| 320 if (primitive == GAIM_STATUS_AVAILABLE) | |
| 321 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0); | |
| 322 if (primitive == GAIM_STATUS_OFFLINE) | |
| 323 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3); | |
| 324 else if (primitive == GAIM_STATUS_AWAY) | |
| 325 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1); | |
| 326 else if (primitive == GAIM_STATUS_HIDDEN) | |
| 327 gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2); | |
| 328 } | |
| 329 | |
| 330 message = gaim_savedstatus_get_message(saved_status); | |
| 331 if (message != NULL) | |
| 332 gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0); | |
| 333 } | |
| 334 | |
| 335 | |
| 336 } else { | |
| 337 const GList *l; | |
| 11739 | 338 |
| 339 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
| 340 { | |
| 11732 | 341 GaimStatusType *status_type = (GaimStatusType *)l->data; |
| 342 | |
| 343 if (!gaim_status_type_is_user_settable(status_type)) | |
| 344 continue; | |
| 345 | |
| 11739 | 346 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), |
| 347 gaim_status_type_get_primitive(status_type), | |
| 348 load_icon(gaim_status_type_get_id(status_type)), | |
| 349 gaim_status_type_get_name(status_type), | |
| 350 NULL); | |
| 11732 | 351 } |
| 352 } | |
| 353 | |
| 354 } | |
| 355 | |
| 11738 | 356 static gboolean |
| 357 dropdown_store_row_separator_func(GtkTreeModel *model, | |
| 358 GtkTreeIter *iter, gpointer data) | |
| 359 { | |
| 11739 | 360 GtkGaimStatusBoxItemType type; |
| 11738 | 361 GdkPixbuf *pixbuf; |
| 11739 | 362 gchar *text, *title, *description; |
| 11738 | 363 |
| 364 gtk_tree_model_get(model, iter, | |
| 11739 | 365 TYPE_COLUMN, &type, |
| 11738 | 366 ICON_COLUMN, &pixbuf, |
| 367 TEXT_COLUMN, &text, | |
| 368 TITLE_COLUMN, &title, | |
| 369 DESC_COLUMN, &description, | |
| 370 -1); | |
| 371 | |
| 11739 | 372 if (type == GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR) |
| 11738 | 373 return TRUE; |
| 374 | |
| 375 return FALSE; | |
| 376 } | |
| 377 | |
| 10643 | 378 static void |
| 379 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) | |
| 380 { | |
| 11400 | 381 GtkCellRenderer *text_rend; |
| 382 GtkCellRenderer *icon_rend; | |
| 10643 | 383 GtkTextBuffer *buffer; |
| 11732 | 384 GtkTreePath *path; |
| 11400 | 385 GtkIconSize icon_size; |
| 386 | |
| 387 text_rend = gtk_cell_renderer_text_new(); | |
| 388 icon_rend = gtk_cell_renderer_pixbuf_new(); | |
| 389 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS); | |
| 10643 | 390 |
| 391 status_box->imhtml_visible = FALSE; | |
| 392 status_box->error_pixbuf = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_OFFLINE, | |
| 393 icon_size, "GtkGaimStatusBox"); | |
| 394 status_box->connecting_index = 0; | |
| 10861 | 395 status_box->connecting_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT0, |
| 10643 | 396 icon_size, "GtkGaimStatusBox"); |
| 10861 | 397 status_box->connecting_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT1, |
| 10643 | 398 icon_size, "GtkGaimStatusBox"); |
| 10861 | 399 status_box->connecting_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT2, |
| 10643 | 400 icon_size, "GtkGaimStatusBox"); |
| 10861 | 401 status_box->connecting_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_CONNECT3, |
| 10643 | 402 icon_size, "GtkGaimStatusBox"); |
| 403 | |
| 404 status_box->typing_index = 0; | |
| 405 status_box->typing_pixbufs[0] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING0, | |
| 406 icon_size, "GtkGaimStatusBox"); | |
| 407 status_box->typing_pixbufs[1] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING1, | |
| 408 icon_size, "GtkGaimStatusBox"); | |
| 409 status_box->typing_pixbufs[2] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING2, | |
| 410 icon_size, "GtkGaimStatusBox"); | |
| 411 status_box->typing_pixbufs[3] = gtk_widget_render_icon (GTK_WIDGET(status_box), GAIM_STOCK_STATUS_TYPING3, | |
| 412 icon_size, "GtkGaimStatusBox"); | |
| 413 status_box->connecting = FALSE; | |
| 414 status_box->typing = FALSE; | |
| 415 status_box->title = NULL; | |
| 10861 | 416 status_box->pixbuf = NULL; |
| 10643 | 417 status_box->cell_view = gtk_cell_view_new(); |
| 418 gtk_widget_show (status_box->cell_view); | |
| 10861 | 419 |
| 11739 | 420 status_box->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
| 421 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); | |
| 11738 | 422 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box), dropdown_store_row_separator_func, NULL, NULL); |
| 10643 | 423 gtk_combo_box_set_model(GTK_COMBO_BOX(status_box), GTK_TREE_MODEL(status_box->dropdown_store)); |
| 424 gtk_cell_view_set_model(GTK_CELL_VIEW(status_box->cell_view), GTK_TREE_MODEL(status_box->store)); | |
| 425 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(status_box), 0); | |
| 426 gtk_list_store_append(status_box->store, &(status_box->iter)); | |
| 427 gtk_gaim_status_box_refresh(status_box); | |
|
11593
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
428 path = gtk_tree_path_new_from_string("0"); |
|
4b7fb30b8926
[gaim-migrate @ 13863]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11562
diff
changeset
|
429 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
|
430 gtk_tree_path_free(path); |
| 10643 | 431 gtk_container_add(GTK_CONTAINER(status_box), status_box->cell_view); |
| 10861 | 432 |
| 10643 | 433 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); |
| 434 status_box->text_rend = gtk_cell_renderer_text_new(); | |
| 435 | |
| 436 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), icon_rend, FALSE); | |
| 10861 | 437 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box), text_rend, TRUE); |
| 10643 | 438 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), icon_rend, "pixbuf", ICON_COLUMN, NULL); |
| 439 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box), text_rend, "markup", TEXT_COLUMN, NULL); | |
| 440 | |
| 441 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); | |
| 11499 | 442 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); |
| 10643 | 443 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "pixbuf", ICON_COLUMN, NULL); |
| 444 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); | |
| 445 | |
| 446 status_box->vbox = gtk_vbox_new(0, FALSE); | |
| 447 status_box->imhtml = gtk_imhtml_new(NULL, NULL); | |
| 448 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(status_box->imhtml)); | |
| 449 g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(imhtml_changed_cb), status_box); | |
| 11562 | 450 g_signal_connect_swapped(G_OBJECT(status_box->imhtml), "message_send", G_CALLBACK(remove_typing_cb), status_box); |
| 10643 | 451 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); |
| 452 gtk_widget_set_parent(status_box->vbox, GTK_WIDGET(status_box)); | |
| 453 status_box->sw = gtk_scrolled_window_new(NULL, NULL); | |
| 454 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(status_box->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
| 455 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(status_box->sw), GTK_SHADOW_IN); | |
| 456 gtk_container_add(GTK_CONTAINER(status_box->sw), status_box->imhtml); | |
| 457 gtk_box_pack_start(GTK_BOX(status_box->vbox), status_box->sw, TRUE, TRUE, 0); | |
| 11654 | 458 |
| 11732 | 459 gtk_gaim_status_box_regenerate(status_box); |
| 10643 | 460 } |
| 461 | |
| 462 | |
| 463 static void | |
| 10861 | 464 gtk_gaim_status_box_size_request(GtkWidget *widget, |
| 465 GtkRequisition *requisition) | |
| 10643 | 466 { |
| 467 GtkRequisition box_req; | |
| 468 combo_box_size_request(widget, requisition); | |
| 10861 | 469 |
| 10643 | 470 gtk_widget_size_request(GTK_GAIM_STATUS_BOX(widget)->vbox, &box_req); |
| 471 if (box_req.height > 1) | |
| 472 requisition->height = requisition->height + box_req.height + 6; | |
| 10861 | 473 |
| 10643 | 474 requisition->width = 1; |
| 475 | |
| 476 } | |
| 477 | |
| 478 static void | |
| 10861 | 479 gtk_gaim_status_box_size_allocate(GtkWidget *widget, |
| 480 GtkAllocation *allocation) | |
| 10643 | 481 { |
| 482 GtkRequisition req = {0,0}; | |
| 11400 | 483 GtkAllocation parent_alc, box_alc; |
| 484 | |
| 485 parent_alc = *allocation; | |
| 486 box_alc = *allocation; | |
| 10643 | 487 combo_box_size_request(widget, &req); |
| 10861 | 488 |
| 10643 | 489 /* EVIL XXX */ |
| 10861 | 490 box_alc.height = 80; |
| 491 /* box_alc.height = MAX(1,box_alc.height - req.height - 6); */ | |
| 492 | |
| 10643 | 493 box_alc.y = box_alc.y + req.height + 6; |
| 494 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | |
| 10861 | 495 |
| 10643 | 496 parent_alc.height = MAX(1,req.height); |
| 497 combo_box_size_allocate(widget, &parent_alc); | |
| 498 widget->allocation = *allocation; | |
| 499 } | |
| 500 | |
| 501 | |
| 502 static gboolean | |
| 10861 | 503 gtk_gaim_status_box_expose_event(GtkWidget *widget, |
| 504 GdkEventExpose *event) | |
| 10643 | 505 { |
| 10861 | 506 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
| 507 combo_box_expose_event(widget, event); | |
| 10643 | 508 |
| 10861 | 509 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
| 510 status_box->vbox, event); | |
| 511 return FALSE; | |
| 10643 | 512 } |
| 513 | |
| 514 static void | |
| 10861 | 515 gtk_gaim_status_box_forall(GtkContainer *container, |
| 516 gboolean include_internals, | |
| 517 GtkCallback callback, | |
| 518 gpointer callback_data) | |
| 10643 | 519 { |
| 10861 | 520 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX (container); |
| 10643 | 521 |
| 10861 | 522 if (include_internals) |
| 523 { | |
| 524 (* callback) (status_box->vbox, callback_data); | |
| 525 } | |
| 10643 | 526 |
| 10861 | 527 combo_box_forall(container, include_internals, callback, callback_data); |
| 10643 | 528 } |
| 529 | |
| 530 GtkWidget * | |
| 531 gtk_gaim_status_box_new() | |
| 532 { | |
| 533 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, NULL); | |
| 534 } | |
| 535 | |
| 11499 | 536 GtkWidget * |
| 537 gtk_gaim_status_box_new_with_account(GaimAccount *account) | |
| 538 { | |
| 539 return g_object_new(GTK_GAIM_TYPE_STATUS_BOX, "account", account, NULL); | |
| 540 } | |
| 10643 | 541 |
| 542 void | |
| 11739 | 543 gtk_gaim_status_box_add(GtkGaimStatusBox *status_box, GtkGaimStatusBoxItemType type, GdkPixbuf *pixbuf, const char *text, const char *sec_text) |
| 10643 | 544 { |
| 545 GtkTreeIter iter; | |
| 546 char *t; | |
| 10861 | 547 |
| 10643 | 548 if (sec_text) { |
| 549 char aa_color[8]; | |
| 550 GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(status_box)); | |
| 551 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", | |
| 552 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
| 553 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
| 10861 | 554 style->text_aa[GTK_STATE_NORMAL].blue >> 8); |
| 10643 | 555 t = g_strdup_printf("%s\n<span color=\"%s\">%s</span>", text, aa_color, sec_text); |
| 556 } else { | |
| 557 t = g_strdup(text); | |
| 558 } | |
| 10861 | 559 |
| 10643 | 560 gtk_list_store_append(status_box->dropdown_store, &iter); |
| 561 gtk_list_store_set(status_box->dropdown_store, &iter, | |
| 11739 | 562 TYPE_COLUMN, type, |
| 10643 | 563 ICON_COLUMN, pixbuf, |
| 10861 | 564 TEXT_COLUMN, t, |
| 10643 | 565 TITLE_COLUMN, text, |
| 10861 | 566 DESC_COLUMN, sec_text, |
| 11739 | 567 -1); |
| 11638 | 568 g_free(t); |
| 10643 | 569 } |
| 570 | |
| 571 void | |
| 11738 | 572 gtk_gaim_status_box_add_separator(GtkGaimStatusBox *status_box) |
| 573 { | |
| 574 GtkTreeIter iter; | |
| 575 | |
| 576 gtk_list_store_append(status_box->dropdown_store, &iter); | |
| 577 gtk_list_store_set(status_box->dropdown_store, &iter, | |
| 11739 | 578 TYPE_COLUMN, GTK_GAIM_STATUS_BOX_TYPE_SEPARATOR, |
| 579 -1); | |
| 11738 | 580 } |
| 581 | |
| 582 void | |
| 10643 | 583 gtk_gaim_status_box_set_error(GtkGaimStatusBox *status_box, const gchar *error) |
| 584 { | |
| 11523 | 585 if (status_box->error) |
| 586 g_free(status_box->error); | |
| 10643 | 587 status_box->error = g_strdup(error); |
| 588 gtk_gaim_status_box_refresh(status_box); | |
| 589 } | |
| 590 | |
| 591 void | |
| 592 gtk_gaim_status_box_set_connecting(GtkGaimStatusBox *status_box, gboolean connecting) | |
| 593 { | |
| 594 if (!status_box) | |
| 595 return; | |
| 596 status_box->connecting = connecting; | |
| 597 gtk_gaim_status_box_refresh(status_box); | |
| 598 } | |
| 599 | |
| 600 void | |
| 601 gtk_gaim_status_box_pulse_connecting(GtkGaimStatusBox *status_box) | |
| 602 { | |
| 603 if (!status_box) | |
| 604 return; | |
| 605 if (status_box->connecting_index == 3) | |
| 606 status_box->connecting_index = 0; | |
| 10861 | 607 else |
| 10643 | 608 status_box->connecting_index++; |
| 609 gtk_gaim_status_box_refresh(status_box); | |
| 610 } | |
| 611 | |
| 612 void | |
| 613 gtk_gaim_status_box_pulse_typing(GtkGaimStatusBox *status_box) | |
| 614 { | |
| 615 if (status_box->typing_index == 3) | |
| 616 status_box->typing_index = 0; | |
| 10861 | 617 else |
| 10643 | 618 status_box->typing_index++; |
| 619 gtk_gaim_status_box_refresh(status_box); | |
| 620 } | |
| 621 | |
| 11654 | 622 static void |
| 623 activate_currently_selected_status(GtkGaimStatusBox *status_box) | |
| 10643 | 624 { |
| 11739 | 625 GtkGaimStatusBoxItemType type; |
| 626 gchar *title; | |
| 10643 | 627 GList *l; |
| 628 GtkTreeIter iter; | |
| 11654 | 629 char *message; |
| 630 GaimSavedStatus *saved_status; | |
| 10643 | 631 |
| 11654 | 632 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
| 633 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, | |
| 11739 | 634 TYPE_COLUMN, &type, |
| 11638 | 635 TITLE_COLUMN, &title, -1); |
| 11654 | 636 message = gtk_gaim_status_box_get_message(status_box); |
| 11739 | 637 |
| 638 /* | |
| 639 * If the currently selected status is "Custom..." or | |
| 640 * "Saved..." then do nothing. | |
| 641 */ | |
| 642 if ((type < 0) || (type >= GAIM_STATUS_NUM_PRIMITIVES)) | |
| 643 return; | |
| 11654 | 644 |
| 645 /* TODO: Should save the previous status as a transient status? */ | |
| 646 | |
| 647 /* Save the newly selected status to prefs.xml and status.xml */ | |
| 648 saved_status = gaim_savedstatus_find(_("Default")); | |
| 649 if (saved_status == NULL) | |
| 11739 | 650 saved_status = gaim_savedstatus_new(_("Default"), type); |
| 651 gaim_savedstatus_set_type(saved_status, type); | |
| 11654 | 652 gaim_savedstatus_set_message(saved_status, message); |
| 653 gaim_prefs_set_string("/core/status/current", _("Default")); | |
| 654 | |
| 655 /* Set the status for each account */ | |
| 656 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) | |
| 657 { | |
| 10643 | 658 GaimAccount *account = (GaimAccount*)l->data; |
| 659 GaimStatusType *status_type; | |
| 10861 | 660 |
| 10643 | 661 if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) |
| 662 continue; | |
| 663 | |
| 11739 | 664 status_type = gaim_account_get_status_type_with_primitive(account, type); |
| 10643 | 665 |
| 666 if (status_type == NULL) | |
| 667 continue; | |
| 11638 | 668 |
| 11739 | 669 gaim_account_set_status(account, |
| 670 gaim_status_type_get_id(status_type), | |
| 671 TRUE, "message", message, NULL); | |
| 10643 | 672 } |
| 11627 | 673 |
| 11638 | 674 g_free(title); |
| 11654 | 675 g_free(message); |
| 676 } | |
| 677 | |
| 678 static void remove_typing_cb(GtkGaimStatusBox *status_box) | |
| 679 { | |
| 680 activate_currently_selected_status(status_box); | |
| 681 | |
| 682 g_source_remove(status_box->typing); | |
| 683 status_box->typing = 0; | |
| 684 gtk_gaim_status_box_refresh(status_box); | |
| 10643 | 685 } |
| 686 | |
| 687 static void gtk_gaim_status_box_changed(GtkComboBox *box) | |
| 688 { | |
| 11400 | 689 GtkGaimStatusBox *status_box; |
| 10643 | 690 GtkTreeIter iter; |
| 11739 | 691 GtkGaimStatusBoxItemType type; |
| 10643 | 692 char *text, *sec_text; |
| 693 GdkPixbuf *pixbuf; | |
| 694 | |
| 11400 | 695 status_box = GTK_GAIM_STATUS_BOX(box); |
| 696 | |
| 10643 | 697 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
| 11739 | 698 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
| 699 TYPE_COLUMN, &type, | |
| 700 TITLE_COLUMN, &text, | |
| 10861 | 701 DESC_COLUMN, &sec_text, ICON_COLUMN, &pixbuf, |
| 11739 | 702 -1); |
| 10643 | 703 if (status_box->title) |
| 704 g_free(status_box->title); | |
| 11638 | 705 status_box->title = text; |
| 10643 | 706 if (status_box->desc && sec_text) |
| 11638 | 707 g_free(status_box->desc); |
| 708 status_box->desc = sec_text; | |
| 10643 | 709 if (status_box->pixbuf) |
| 710 g_object_unref(status_box->pixbuf); | |
| 711 status_box->pixbuf = pixbuf; | |
| 11638 | 712 if (status_box->typing) |
| 713 g_source_remove(status_box->typing); | |
| 714 status_box->typing = 0; | |
| 10861 | 715 |
| 11739 | 716 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) |
| 11729 | 717 { |
| 718 gaim_gtk_status_editor_show(NULL); | |
| 719 return; | |
| 720 } | |
| 721 | |
| 11739 | 722 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) |
| 11729 | 723 { |
| 724 gaim_gtk_status_window_show(); | |
| 725 return; | |
| 726 } | |
| 727 | |
| 11654 | 728 /* |
| 11739 | 729 * TODO: Should show the message box whenever 'type' allows |
| 11654 | 730 * for a message attribute on any protocol that is enabled. |
| 731 */ | |
| 11739 | 732 if (type == GAIM_STATUS_AWAY) |
| 11654 | 733 status_box->imhtml_visible = TRUE; |
| 734 else | |
| 735 status_box->imhtml_visible = FALSE; | |
| 736 | |
| 737 if (status_box->imhtml_visible) | |
| 738 { | |
| 10643 | 739 gtk_widget_show_all(status_box->vbox); |
| 740 status_box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, status_box); | |
| 741 gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml)); | |
| 742 gtk_widget_grab_focus(status_box->imhtml); | |
| 11654 | 743 } |
| 744 else | |
| 745 { | |
| 10643 | 746 gtk_widget_hide_all(status_box->vbox); |
| 11654 | 747 activate_currently_selected_status(status_box); |
| 10643 | 748 } |
| 749 gtk_gaim_status_box_refresh(status_box); | |
| 750 } | |
| 751 | |
| 752 static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) | |
| 753 { | |
| 754 GtkGaimStatusBox *box = (GtkGaimStatusBox*)data; | |
| 755 if (box->typing) { | |
| 756 gtk_gaim_status_box_pulse_typing(box); | |
| 757 g_source_remove(box->typing); | |
| 10861 | 758 } |
| 10643 | 759 box->typing = g_timeout_add(3000, (GSourceFunc)remove_typing_cb, box); |
| 760 gtk_gaim_status_box_refresh(box); | |
| 761 } | |
| 10649 | 762 |
| 11739 | 763 GtkGaimStatusBoxItemType gtk_gaim_status_box_get_active_type(GtkGaimStatusBox *status_box) |
| 10649 | 764 { |
| 765 GtkTreeIter iter; | |
| 11739 | 766 GtkGaimStatusBoxItemType type; |
| 10649 | 767 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter); |
| 10861 | 768 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, |
| 10649 | 769 TYPE_COLUMN, &type, -1); |
| 770 return type; | |
| 771 } | |
| 772 | |
| 11638 | 773 char *gtk_gaim_status_box_get_message(GtkGaimStatusBox *status_box) |
| 10649 | 774 { |
| 775 if (status_box->imhtml_visible) | |
| 776 return gtk_imhtml_get_markup(GTK_IMHTML(status_box->imhtml)); | |
| 777 else | |
| 778 return NULL; | |
| 779 } |
