comparison src/gtkstatusbox.c @ 13124:a0cdde3b06cf

[gaim-migrate @ 15486] Ok, I believe everything is working really well now. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 05 Feb 2006 20:06:31 +0000
parents a9f6d9a68a04
children 488619ad7ed5
comparison
equal deleted inserted replaced
13123:a9f6d9a68a04 13124:a0cdde3b06cf
308 * should modify status_box->store 308 * should modify status_box->store
309 */ 309 */
310 static void 310 static void
311 gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box) 311 gtk_gaim_status_box_refresh(GtkGaimStatusBox *status_box)
312 { 312 {
313 gboolean show_buddy_icons;
314 GtkIconSize icon_size;
315 GtkStyle *style;
316 char aa_color[8];
317 GaimSavedStatus *saved_status;
313 char *primary, *secondary, *text; 318 char *primary, *secondary, *text;
314 char aa_color[8];
315 GdkPixbuf *pixbuf; 319 GdkPixbuf *pixbuf;
316 GtkTreePath *path; 320 GtkTreePath *path;
317 GtkStyle *style;
318 GaimSavedStatus *saved_status;
319 gboolean show_buddy_icons;
320 321
321 show_buddy_icons = gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"); 322 show_buddy_icons = gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons");
323 if (show_buddy_icons)
324 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS);
325 else
326 icon_size = gtk_icon_size_from_name(GAIM_ICON_SIZE_STATUS_SMALL);
327
322 style = gtk_widget_get_style(GTK_WIDGET(status_box)); 328 style = gtk_widget_get_style(GTK_WIDGET(status_box));
323 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x", 329 snprintf(aa_color, sizeof(aa_color), "#%02x%02x%02x",
324 style->text_aa[GTK_STATE_NORMAL].red >> 8, 330 style->text_aa[GTK_STATE_NORMAL].red >> 8,
325 style->text_aa[GTK_STATE_NORMAL].green >> 8, 331 style->text_aa[GTK_STATE_NORMAL].green >> 8,
326 style->text_aa[GTK_STATE_NORMAL].blue >> 8); 332 style->text_aa[GTK_STATE_NORMAL].blue >> 8);
327 333
328 saved_status = gaim_savedstatus_get_current(); 334 saved_status = gaim_savedstatus_get_current();
329 335
330 /* Determine the primary text, secondary text, and pixbuf to use */ 336 /* Primary */
331 if (status_box->typing != 0) 337 if (status_box->typing != 0)
332 { 338 {
333 GtkTreeIter iter; 339 GtkTreeIter iter;
334 GtkGaimStatusBoxItemType type; 340 GtkGaimStatusBoxItemType type;
335 gpointer data; 341 gpointer data;
339 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, 345 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter,
340 TYPE_COLUMN, &type, 346 TYPE_COLUMN, &type,
341 DATA_COLUMN, &data, 347 DATA_COLUMN, &data,
342 -1); 348 -1);
343 if (type == GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE) 349 if (type == GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE)
344 primary = g_strdup(gaim_primitive_get_name_from_type((GaimStatusPrimitive)GPOINTER_TO_INT(data))); 350 primary = g_strdup(gaim_primitive_get_name_from_type(GPOINTER_TO_INT(data)));
345 else if (gaim_savedstatus_is_transient(saved_status))
346 primary = g_strdup(gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)));
347 else 351 else
348 primary = g_markup_escape_text(gaim_savedstatus_get_title(saved_status), -1); 352 /* This should never happen, but just in case... */
349 353 primary = g_strdup("New status");
354 }
355 else if (gaim_savedstatus_is_transient(saved_status))
356 primary = g_strdup(gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)));
357 else
358 primary = g_markup_escape_text(gaim_savedstatus_get_title(saved_status), -1);
359
360 /* Secondary */
361 if (status_box->typing != 0)
350 secondary = g_strdup(_("Typing")); 362 secondary = g_strdup(_("Typing"));
363 else if (status_box->connecting)
364 secondary = g_strdup(_("Connecting"));
365 else if (gaim_savedstatus_is_transient(saved_status))
366 secondary = NULL;
367 else
368 {
369 const char *message;
370 char *tmp;
371 message = gaim_savedstatus_get_message(saved_status);
372 if (message != NULL)
373 {
374 tmp = gaim_markup_strip_html(message);
375 gaim_util_chrreplace(tmp, '\n', ' ');
376 secondary = g_markup_escape_text(tmp, -1);
377 g_free(tmp);
378 }
379 else
380 secondary = NULL;
381 }
382
383 /* Pixbuf */
384 if (status_box->typing != 0)
351 pixbuf = status_box->typing_pixbufs[status_box->typing_index]; 385 pixbuf = status_box->typing_pixbufs[status_box->typing_index];
352 }
353 else if (status_box->connecting) 386 else if (status_box->connecting)
354 {
355 /* Primary */
356 if (gaim_savedstatus_is_transient(saved_status))
357 primary = g_strdup(gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)));
358 else
359 primary = g_markup_escape_text(gaim_savedstatus_get_title(saved_status), -1);
360
361 secondary = g_strdup(_("Connecting"));
362 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index]; 387 pixbuf = status_box->connecting_pixbufs[status_box->connecting_index];
363 }
364 else 388 else
365 { 389 {
366 /* Primary and secondary */
367 if (gaim_savedstatus_is_transient(saved_status))
368 {
369 primary = g_strdup(gaim_primitive_get_name_from_type(gaim_savedstatus_get_type(saved_status)));
370 secondary = NULL;
371 }
372 else
373 {
374 const gchar *message;
375 primary = g_markup_escape_text(gaim_savedstatus_get_title(saved_status), -1);
376
377 message = gaim_savedstatus_get_message(saved_status);
378 if (message != NULL)
379 {
380 secondary = gaim_markup_strip_html(message);
381 gaim_util_chrreplace(secondary, '\n', ' ');
382 }
383 else
384 secondary = NULL;
385 }
386
387 /* Pixbuf */
388 pixbuf = gaim_gtk_create_gaim_icon_with_status( 390 pixbuf = gaim_gtk_create_gaim_icon_with_status(
389 gaim_savedstatus_get_type(saved_status), 391 gaim_savedstatus_get_type(saved_status),
390 show_buddy_icons ? 1.0 : 0.5); 392 show_buddy_icons ? 1.0 : 0.5);
393
394 if (!gaim_savedstatus_is_transient(saved_status))
395 {
396 GdkPixbuf *emblem;
397
398 /* Overlay a disk in the bottom left corner */
399 emblem = gtk_widget_render_icon(GTK_WIDGET(status_box->vbox),
400 GTK_STOCK_SAVE, icon_size, "GtkGaimStatusBox");
401 if (emblem != NULL)
402 {
403 int width, height;
404 width = gdk_pixbuf_get_width(pixbuf) / 2;
405 height = gdk_pixbuf_get_height(pixbuf) / 2;
406 gdk_pixbuf_composite(emblem, pixbuf, 0, height,
407 width, height, 0, height,
408 0.5, 0.5, GDK_INTERP_BILINEAR, 255);
409 g_object_unref(G_OBJECT(emblem));
410 }
411 }
391 } 412 }
392 413
393 if (status_box->account != NULL) { 414 if (status_box->account != NULL) {
394 text = g_strdup_printf("%s\n<span size=\"smaller\">%s</span>", 415 text = g_strdup_printf("%s\n<span size=\"smaller\">%s</span>",
395 gaim_account_get_username(status_box->account), 416 gaim_account_get_username(status_box->account),
411 */ 432 */
412 gtk_list_store_set(status_box->store, &(status_box->iter), 433 gtk_list_store_set(status_box->store, &(status_box->iter),
413 ICON_COLUMN, pixbuf, 434 ICON_COLUMN, pixbuf,
414 TEXT_COLUMN, text, 435 TEXT_COLUMN, text,
415 -1); 436 -1);
437 if ((status_box->typing == 0) && (!status_box->connecting))
438 g_object_unref(pixbuf);
416 g_free(text); 439 g_free(text);
417 440
418 /* Make sure to activate the only row in the tree view */ 441 /* Make sure to activate the only row in the tree view */
419 path = gtk_tree_path_new_from_string("0"); 442 path = gtk_tree_path_new_from_string("0");
420 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path); 443 gtk_cell_view_set_displayed_row(GTK_CELL_VIEW(status_box->cell_view), path);
432 * 455 *
433 * Maybe we could accomplish this by triggering off the mouse and 456 * Maybe we could accomplish this by triggering off the mouse and
434 * keyboard signals instead of the changed signal? 457 * keyboard signals instead of the changed signal?
435 */ 458 */
436 static void 459 static void
437 update_to_reflect_current_status(GtkGaimStatusBox *status_box) 460 status_menu_refresh_iter(GtkGaimStatusBox *status_box)
438 { 461 {
439 GaimSavedStatus *saved_status; 462 GaimSavedStatus *saved_status;
440 GaimStatusPrimitive primitive; 463 GaimStatusPrimitive primitive;
441 gint index; 464 gint index;
442 const char *message; 465 const char *message;
529 552
530 static void 553 static void
531 add_popular_statuses(GtkGaimStatusBox *statusbox) 554 add_popular_statuses(GtkGaimStatusBox *statusbox)
532 { 555 {
533 gboolean show_buddy_icons; 556 gboolean show_buddy_icons;
557 GtkIconSize icon_size;
534 GList *list, *cur; 558 GList *list, *cur;
535 GtkIconSize icon_size;
536 GdkPixbuf *pixbuf, *emblem; 559 GdkPixbuf *pixbuf, *emblem;
537 int width, height; 560 int width, height;
538 561
539 list = gaim_savedstatuses_get_popular(6); 562 list = gaim_savedstatuses_get_popular(6);
540 if (list == NULL) 563 if (list == NULL)
643 666
644 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box)); 667 gtk_gaim_status_box_add_separator(GTK_GAIM_STATUS_BOX(status_box));
645 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("New..."), NULL, NULL); 668 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_CUSTOM, pixbuf, _("New..."), NULL, NULL);
646 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL, NULL); 669 gtk_gaim_status_box_add(GTK_GAIM_STATUS_BOX(status_box), GTK_GAIM_STATUS_BOX_TYPE_SAVED, pixbuf, _("Saved..."), NULL, NULL);
647 670
648 update_to_reflect_current_status(status_box); 671 status_menu_refresh_iter(status_box);
649 672
650 } else { 673 } else {
651 /* Per-account */ 674 /* Per-account */
652 const GList *l; 675 const GList *l;
653 676
788 811
789 if (status_box->account != NULL) 812 if (status_box->account != NULL)
790 update_to_reflect_account_status(status_box, status_box->account, 813 update_to_reflect_account_status(status_box, status_box->account,
791 gaim_account_get_active_status(status_box->account)); 814 gaim_account_get_active_status(status_box->account));
792 else 815 else
793 update_to_reflect_current_status(status_box); 816 status_menu_refresh_iter(status_box);
794 817
795 gtk_gaim_status_box_refresh(status_box); 818 gtk_gaim_status_box_refresh(status_box);
796 } 819 }
797 820
798 static void 821 static void
1194 -1); 1217 -1);
1195 1218
1196 /* 1219 /*
1197 * If the currently selected status is "New..." or 1220 * If the currently selected status is "New..." or
1198 * "Saved..." or a popular status then do nothing. 1221 * "Saved..." or a popular status then do nothing.
1199 * Custom statuses are 1222 * Popular statuses are
1200 * activated elsewhere, and we update the status_box 1223 * activated elsewhere, and we update the status_box
1201 * accordingly by monitoring the preference 1224 * accordingly by monitoring the preference
1202 * "/core/savedstatus/current" and then calling 1225 * "/core/savedstatus/current" and then calling
1203 * update_to_reflect_current_status() 1226 * status_menu_refresh_iter()
1204 */ 1227 */
1205 if (type != GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE) 1228 if (type != GTK_GAIM_STATUS_BOX_TYPE_PRIMITIVE)
1206 return; 1229 return;
1207 1230
1208 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, 1231 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter,
1326 static void remove_typing_cb(GtkGaimStatusBox *status_box) 1349 static void remove_typing_cb(GtkGaimStatusBox *status_box)
1327 { 1350 {
1328 if (status_box->typing == 0) 1351 if (status_box->typing == 0)
1329 { 1352 {
1330 /* Nothing has changed, so we don't need to do anything */ 1353 /* Nothing has changed, so we don't need to do anything */
1331 update_to_reflect_current_status(status_box); 1354 status_menu_refresh_iter(status_box);
1332 return; 1355 return;
1333 } 1356 }
1334 1357
1335 activate_currently_selected_status(status_box); 1358 activate_currently_selected_status(status_box);
1336 1359
1376 } 1399 }
1377 1400
1378 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM) 1401 if (type == GTK_GAIM_STATUS_BOX_TYPE_CUSTOM)
1379 { 1402 {
1380 gaim_gtk_status_editor_show(NULL); 1403 gaim_gtk_status_editor_show(NULL);
1381 // TODO: This shouldn't be neccessary? 1404 status_menu_refresh_iter(status_box);
1382 update_to_reflect_current_status(status_box);
1383 return; 1405 return;
1384 } 1406 }
1385 1407
1386 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED) 1408 if (type == GTK_GAIM_STATUS_BOX_TYPE_SAVED)
1387 { 1409 {
1388 gaim_gtk_status_window_show(); 1410 gaim_gtk_status_window_show();
1389 // TODO: This shouldn't be neccessary? 1411 status_menu_refresh_iter(status_box);
1390 update_to_reflect_current_status(status_box);
1391 return; 1412 return;
1392 } 1413 }
1393 } 1414 }
1394 1415
1395 /* 1416 /*