| 1541 if(*height > 100) |
1542 if(*height > 100) |
| 1542 *height = 100; |
1543 *height = 100; |
| 1543 } |
1544 } |
| 1544 |
1545 |
| 1545 GdkPixbuf * |
1546 GdkPixbuf * |
| 1546 gaim_gtk_create_prpl_icon(GaimAccount *account) |
1547 gaim_gtk_create_prpl_icon(GaimAccount *account, double scale_factor) |
| 1547 { |
1548 { |
| 1548 GaimPlugin *prpl; |
1549 GaimPlugin *prpl; |
| 1549 GaimPluginProtocolInfo *prpl_info = NULL; |
1550 GaimPluginProtocolInfo *prpl_info; |
| 1550 GdkPixbuf *status = NULL; |
|
| 1551 char *filename = NULL; |
|
| 1552 const char *protoname = NULL; |
1551 const char *protoname = NULL; |
| 1553 char buf[256]; /* TODO: We should use a define for max file length */ |
1552 char buf[256]; /* TODO: We should use a define for max file length */ |
| |
1553 char *filename = NULL; |
| |
1554 GdkPixbuf *pixbuf, *scaled; |
| 1554 |
1555 |
| 1555 g_return_val_if_fail(account != NULL, NULL); |
1556 g_return_val_if_fail(account != NULL, NULL); |
| 1556 |
1557 |
| 1557 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
1558 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
| 1558 |
1559 if (prpl == NULL) |
| 1559 if (prpl != NULL) { |
1560 return NULL; |
| 1560 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
1561 |
| 1561 |
1562 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
| 1562 if (prpl_info->list_icon != NULL) |
1563 if (prpl_info->list_icon == NULL) |
| 1563 protoname = prpl_info->list_icon(account, NULL); |
1564 return NULL; |
| 1564 } |
1565 |
| 1565 |
1566 protoname = prpl_info->list_icon(account, NULL); |
| 1566 if (protoname == NULL) |
1567 if (protoname == NULL) |
| 1567 return NULL; |
1568 return NULL; |
| 1568 |
1569 |
| 1569 /* |
1570 /* |
| 1570 * Status icons will be themeable too, and then it will look up |
1571 * Status icons will be themeable too, and then it will look up |
| 1572 */ |
1573 */ |
| 1573 g_snprintf(buf, sizeof(buf), "%s.png", protoname); |
1574 g_snprintf(buf, sizeof(buf), "%s.png", protoname); |
| 1574 |
1575 |
| 1575 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", |
1576 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", |
| 1576 "default", buf, NULL); |
1577 "default", buf, NULL); |
| 1577 status = gdk_pixbuf_new_from_file(filename, NULL); |
1578 pixbuf = gdk_pixbuf_new_from_file(filename, NULL); |
| 1578 g_free(filename); |
1579 g_free(filename); |
| 1579 |
1580 |
| 1580 return status; |
1581 scaled = gdk_pixbuf_scale_simple(pixbuf, 30*scale_factor, |
| 1581 } |
1582 30*scale_factor, GDK_INTERP_BILINEAR); |
| 1582 |
1583 g_object_unref(pixbuf); |
| 1583 GdkPixbuf * |
1584 |
| 1584 gaim_gtk_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type) |
1585 return scaled; |
| 1585 { |
1586 } |
| 1586 char basename2[256]; |
1587 |
| |
1588 static GdkPixbuf * |
| |
1589 overlay_status_onto_icon(GdkPixbuf *pixbuf, GaimStatusPrimitive primitive) |
| |
1590 { |
| |
1591 const char *type_name; |
| |
1592 char basename[256]; |
| 1587 char *filename; |
1593 char *filename; |
| 1588 const char *type_name; |
1594 GdkPixbuf *emblem; |
| 1589 GdkPixbuf *pixbuf, *scale = NULL, *emblem; |
1595 |
| 1590 |
1596 type_name = gaim_primitive_get_id_from_type(primitive); |
| 1591 pixbuf = gaim_gtk_create_prpl_icon(account); |
1597 |
| 1592 |
1598 g_snprintf(basename, sizeof(basename), "%s.png", type_name); |
| 1593 if (pixbuf != NULL) { |
1599 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", |
| 1594 scale = gdk_pixbuf_scale_simple(pixbuf, 32, 32, |
1600 "default", basename, NULL); |
| 1595 GDK_INTERP_BILINEAR); |
|
| 1596 g_object_unref(G_OBJECT(pixbuf)); |
|
| 1597 } else { |
|
| 1598 return NULL; |
|
| 1599 } |
|
| 1600 |
|
| 1601 /* TODO: let the prpl pick the emblem on a per status basis, and only |
|
| 1602 * use the primitive as a fallback */ |
|
| 1603 type_name = gaim_primitive_get_id_from_type(gaim_status_type_get_primitive(status_type)); |
|
| 1604 |
|
| 1605 g_snprintf(basename2, sizeof(basename2), "%s.png", |
|
| 1606 type_name); |
|
| 1607 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", |
|
| 1608 basename2, NULL); |
|
| 1609 emblem = gdk_pixbuf_new_from_file(filename, NULL); |
1601 emblem = gdk_pixbuf_new_from_file(filename, NULL); |
| 1610 g_free(filename); |
1602 g_free(filename); |
| 1611 |
1603 |
| 1612 if (emblem) { |
1604 if (emblem != NULL) { |
| 1613 gdk_pixbuf_composite(emblem, |
1605 int width, height, emblem_width, emblem_height, new_emblem_width, new_emblem_height; |
| 1614 scale, 32-15, 32-15, |
1606 width = gdk_pixbuf_get_width(pixbuf); |
| 1615 15, 15, |
1607 height = gdk_pixbuf_get_height(pixbuf); |
| 1616 32-15, 32-15, |
1608 emblem_width = gdk_pixbuf_get_width(emblem); |
| 1617 1, 1, |
1609 emblem_height = gdk_pixbuf_get_height(emblem); |
| 1618 GDK_INTERP_BILINEAR, |
1610 new_emblem_width = width / 2; |
| 1619 255); |
1611 new_emblem_height = height / 2; |
| 1620 |
1612 /* Overlay emblem onto the bottom right corner of pixbuf */ |
| |
1613 gdk_pixbuf_composite(emblem, pixbuf, |
| |
1614 width - new_emblem_width, height - new_emblem_height, |
| |
1615 new_emblem_width, new_emblem_height, |
| |
1616 width - new_emblem_width, height - new_emblem_height, |
| |
1617 (double)new_emblem_width / (double)emblem_width, |
| |
1618 (double)new_emblem_height / (double)emblem_height, |
| |
1619 GDK_INTERP_BILINEAR, |
| |
1620 255); |
| 1621 g_object_unref(emblem); |
1621 g_object_unref(emblem); |
| 1622 } |
1622 } |
| 1623 return scale; |
1623 |
| |
1624 return pixbuf; |
| |
1625 } |
| |
1626 |
| |
1627 GdkPixbuf * |
| |
1628 gaim_gtk_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type, double scale_factor) |
| |
1629 { |
| |
1630 GdkPixbuf *pixbuf; |
| |
1631 |
| |
1632 pixbuf = gaim_gtk_create_prpl_icon(account, scale_factor); |
| |
1633 if (pixbuf == NULL) |
| |
1634 return NULL; |
| |
1635 |
| |
1636 /* |
| |
1637 * TODO: Let the prpl pick the emblem on a per status basis, |
| |
1638 * and only use the primitive as a fallback? |
| |
1639 */ |
| |
1640 |
| |
1641 return overlay_status_onto_icon(pixbuf, |
| |
1642 gaim_status_type_get_primitive(status_type)); |
| |
1643 } |
| |
1644 |
| |
1645 GdkPixbuf * |
| |
1646 gaim_gtk_create_gaim_icon_with_status(GaimStatusPrimitive primitive, double scale_factor) |
| |
1647 { |
| |
1648 gchar *filename; |
| |
1649 GdkPixbuf *orig, *pixbuf; |
| |
1650 |
| |
1651 filename = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL); |
| |
1652 orig = gdk_pixbuf_new_from_file(filename, NULL); |
| |
1653 g_free(filename); |
| |
1654 if (orig == NULL) |
| |
1655 return NULL; |
| |
1656 |
| |
1657 pixbuf = gdk_pixbuf_scale_simple(orig, 30*scale_factor, |
| |
1658 30*scale_factor, GDK_INTERP_BILINEAR); |
| |
1659 g_object_unref(G_OBJECT(orig)); |
| |
1660 |
| |
1661 return overlay_status_onto_icon(pixbuf, primitive); |
| 1624 } |
1662 } |
| 1625 |
1663 |
| 1626 static void |
1664 static void |
| 1627 menu_action_cb(GtkMenuItem *item, gpointer object) |
1665 menu_action_cb(GtkMenuItem *item, gpointer object) |
| 1628 { |
1666 { |