Commit 78ca73d6 authored by Milan Crha's avatar Milan Crha

M!13 - Improve icons in previews with hiDPI monitors

Closes GNOME/evolution!13
parent f2c79880
......@@ -29,7 +29,12 @@
#include "e-stock-request.h"
struct _EStockRequestPrivate {
gint dummy;
gint scale_factor;
};
enum {
PROP_0,
PROP_SCALE_FACTOR
};
static void e_stock_request_content_request_init (EContentRequestInterface *iface);
......@@ -72,7 +77,6 @@ process_stock_request_idle_cb (gpointer user_data)
GtkWidgetPath *path;
GtkIconSet *icon_set;
gssize size = GTK_ICON_SIZE_BUTTON;
gchar *a_size;
gchar *buffer = NULL, *mime_type = NULL;
gsize buff_len = 0;
GError *local_error = NULL;
......@@ -96,9 +100,12 @@ process_stock_request_idle_cb (gpointer user_data)
query = soup_form_decode (suri->query);
if (query != NULL) {
a_size = g_hash_table_lookup (query, "size");
if (a_size != NULL)
size = atoi (a_size);
const gchar *value;
value = g_hash_table_lookup (query, "size");
if (value)
size = atoi (value);
g_hash_table_destroy (query);
}
......@@ -126,14 +133,19 @@ process_stock_request_idle_cb (gpointer user_data)
GtkIconTheme *icon_theme;
GtkIconInfo *icon_info;
const gchar *filename;
gint icon_width, icon_height;
gint icon_width, icon_height, scale_factor;
scale_factor = e_stock_request_get_scale_factor (E_STOCK_REQUEST (sid->request));
if (scale_factor < 1)
scale_factor = 1;
if (!gtk_icon_size_lookup (size, &icon_width, &icon_height)) {
icon_width = size;
icon_height = size;
}
size = MAX (icon_width, icon_height);
size = MAX (icon_width, icon_height) * scale_factor;
icon_theme = gtk_icon_theme_get_default ();
......@@ -278,6 +290,41 @@ e_stock_request_process_sync (EContentRequest *request,
return sid.success;
}
static void
e_stock_request_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SCALE_FACTOR:
e_stock_request_set_scale_factor (
E_STOCK_REQUEST (object),
g_value_get_int (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
e_stock_request_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SCALE_FACTOR:
g_value_set_int (
value,
e_stock_request_get_scale_factor (
E_STOCK_REQUEST (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
e_stock_request_content_request_init (EContentRequestInterface *iface)
{
......@@ -288,13 +335,31 @@ e_stock_request_content_request_init (EContentRequestInterface *iface)
static void
e_stock_request_class_init (EStockRequestClass *class)
{
GObjectClass *object_class;
g_type_class_add_private (class, sizeof (EStockRequestPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = e_stock_request_set_property;
object_class->get_property = e_stock_request_get_property;
g_object_class_install_property (
object_class,
PROP_SCALE_FACTOR,
g_param_spec_int (
"scale-factor",
"Scale Factor",
NULL,
G_MININT, G_MAXINT, 0,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
static void
e_stock_request_init (EStockRequest *request)
{
request->priv = G_TYPE_INSTANCE_GET_PRIVATE (request, E_TYPE_STOCK_REQUEST, EStockRequestPrivate);
request->priv->scale_factor = 0;
}
EContentRequest *
......@@ -302,3 +367,25 @@ e_stock_request_new (void)
{
return g_object_new (E_TYPE_STOCK_REQUEST, NULL);
}
gint
e_stock_request_get_scale_factor (EStockRequest *stock_request)
{
g_return_val_if_fail (E_IS_STOCK_REQUEST (stock_request), 0);
return stock_request->priv->scale_factor;
}
void
e_stock_request_set_scale_factor (EStockRequest *stock_request,
gint scale_factor)
{
g_return_if_fail (E_IS_STOCK_REQUEST (stock_request));
if (stock_request->priv->scale_factor == scale_factor)
return;
stock_request->priv->scale_factor = scale_factor;
g_object_notify (G_OBJECT (stock_request), "scale-factor");
}
......@@ -61,6 +61,9 @@ struct _EStockRequestClass {
GType e_stock_request_get_type (void) G_GNUC_CONST;
EContentRequest *
e_stock_request_new (void);
gint e_stock_request_get_scale_factor(EStockRequest *stock_request);
void e_stock_request_set_scale_factor(EStockRequest *stock_request,
gint scale_factor);
G_END_DECLS
......
......@@ -1267,6 +1267,9 @@ web_view_initialize (WebKitWebView *web_view)
g_object_unref (content_request);
content_request = e_stock_request_new ();
e_binding_bind_property (web_view, "scale-factor",
content_request, "scale-factor",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
e_web_view_register_content_request_for_scheme (E_WEB_VIEW (web_view), "gtk-stock", content_request);
g_object_unref (content_request);
......
......@@ -543,16 +543,24 @@ emfe_headers_format (EMailFormatterExtension *extension,
e_mail_part_get_id (part),
direction);
if (is_collapsable)
if (is_collapsable) {
gint icon_width, icon_height;
if (!gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, &icon_width, &icon_height)) {
icon_width = 16;
icon_height = 16;
}
g_string_append_printf (
buffer,
"<td valign=\"top\" width=\"18\" style=\"padding-left: 0px\">"
"<button type=\"button\" class=\"header-collapse\" id=\"__evo-collapse-headers-img\">"
"<img src=\"gtk-stock://%s\" />"
"<img src=\"gtk-stock://%s?size=%d\" width=\"%dpx\" height=\"%dpx\"/>"
"</button>"
"</td>",
is_collapsed ? "pan-end-symbolic" : "pan-down-symbolic"
);
is_collapsed ? "pan-end-symbolic" : "pan-down-symbolic",
GTK_ICON_SIZE_BUTTON, icon_width, icon_height);
}
g_string_append (buffer, "<td>");
......
......@@ -206,15 +206,23 @@ e_mail_formatter_format_address (EMailFormatter *formatter,
if (strcmp (field, _("To")) == 0 ||
strcmp (field, _("Cc")) == 0 ||
strcmp (field, _("Bcc")) == 0) {
gint icon_width, icon_height;
if (!gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, &icon_width, &icon_height)) {
icon_width = 16;
icon_height = 16;
}
g_string_append (
out,
"<span id=\"__evo-moreaddr\" "
"style=\"display: none;\">");
str = g_strdup_printf (
"<button type=\"button\" id=\"__evo-moreaddr-button\" class=\"header-collapse\" style=\"display: inline-block;\">"
"<img src=\"gtk-stock://pan-end-symbolic\" />"
"</button>");
"<img src=\"gtk-stock://pan-end-symbolic?size=%d\" width=\"%dpx\" height=\"%dpx\"/>"
"</button>",
GTK_ICON_SIZE_BUTTON, icon_width, icon_height);
}
}
}
......
......@@ -1579,6 +1579,9 @@ mail_display_constructed (GObject *object)
g_object_unref (content_request);
content_request = e_mail_request_new ();
e_binding_bind_property (display, "scale-factor",
content_request, "scale-factor",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
e_web_view_register_content_request_for_scheme (web_view, "mail", content_request);
g_object_unref (content_request);
......
......@@ -37,7 +37,12 @@
#define d(x)
struct _EMailRequestPrivate {
gint dummy;
gint scale_factor;
};
enum {
PROP_0,
PROP_SCALE_FACTOR
};
static void e_mail_request_content_request_init (EContentRequestInterface *iface);
......@@ -198,10 +203,17 @@ mail_request_process_mail_sync (EContentRequest *request,
if (icon) {
const gchar *size = g_hash_table_lookup (uri_query, "size");
gint scale_factor;
if (!size)
size = "16";
save_gicon_to_stream (icon, atoi (size), output_stream, &use_mime_type);
scale_factor = e_mail_request_get_scale_factor (E_MAIL_REQUEST (request));
if (scale_factor < 1)
scale_factor = 1;
save_gicon_to_stream (icon, atoi (size) * scale_factor, output_stream, &use_mime_type);
}
}
......@@ -486,6 +498,41 @@ e_mail_request_process_sync (EContentRequest *request,
return success;
}
static void
e_mail_request_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SCALE_FACTOR:
e_mail_request_set_scale_factor (
E_MAIL_REQUEST (object),
g_value_get_int (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
e_mail_request_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SCALE_FACTOR:
g_value_set_int (
value,
e_mail_request_get_scale_factor (
E_MAIL_REQUEST (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
e_mail_request_content_request_init (EContentRequestInterface *iface)
{
......@@ -496,13 +543,31 @@ e_mail_request_content_request_init (EContentRequestInterface *iface)
static void
e_mail_request_class_init (EMailRequestClass *class)
{
GObjectClass *object_class;
g_type_class_add_private (class, sizeof (EMailRequestPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = e_mail_request_set_property;
object_class->get_property = e_mail_request_get_property;
g_object_class_install_property (
object_class,
PROP_SCALE_FACTOR,
g_param_spec_int (
"scale-factor",
"Scale Factor",
NULL,
G_MININT, G_MAXINT, 0,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
static void
e_mail_request_init (EMailRequest *request)
{
request->priv = G_TYPE_INSTANCE_GET_PRIVATE (request, E_TYPE_MAIL_REQUEST, EMailRequestPrivate);
request->priv->scale_factor = 0;
}
EContentRequest *
......@@ -510,3 +575,25 @@ e_mail_request_new (void)
{
return g_object_new (E_TYPE_MAIL_REQUEST, NULL);
}
gint
e_mail_request_get_scale_factor (EMailRequest *mail_request)
{
g_return_val_if_fail (E_IS_MAIL_REQUEST (mail_request), 0);
return mail_request->priv->scale_factor;
}
void
e_mail_request_set_scale_factor (EMailRequest *mail_request,
gint scale_factor)
{
g_return_if_fail (E_IS_MAIL_REQUEST (mail_request));
if (mail_request->priv->scale_factor == scale_factor)
return;
mail_request->priv->scale_factor = scale_factor;
g_object_notify (G_OBJECT (mail_request), "scale-factor");
}
......@@ -57,6 +57,9 @@ struct _EMailRequestClass {
GType e_mail_request_get_type (void) G_GNUC_CONST;
EContentRequest *
e_mail_request_new (void);
gint e_mail_request_get_scale_factor (EMailRequest *mail_request);
void e_mail_request_set_scale_factor (EMailRequest *mail_request,
gint scale_factor);
G_END_DECLS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment