aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/util/helper.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2018-01-12 21:03:09 +0100
committerfiaxh <git@mx.ax.lt>2018-01-28 00:38:47 +0100
commit782ae4c049e2b6fab13d7453cbb0e74610e7d200 (patch)
tree1b4cd0a1689cee0c2e2cac2ae9a5fb8ebbe63621 /main/src/ui/util/helper.vala
parentd46d071e57e599e8cfb1780597cbecb36881c4d8 (diff)
downloaddino-782ae4c049e2b6fab13d7453cbb0e74610e7d200.tar.gz
dino-782ae4c049e2b6fab13d7453cbb0e74610e7d200.zip
Move Jid class to xmpp-vala, partially refactor namespace
Diffstat (limited to 'main/src/ui/util/helper.vala')
-rw-r--r--main/src/ui/util/helper.vala21
1 files changed, 18 insertions, 3 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala
index a4f800f8..6d9218e4 100644
--- a/main/src/ui/util/helper.vala
+++ b/main/src/ui/util/helper.vala
@@ -65,7 +65,7 @@ public static string get_display_name(StreamInteractor stream_interactor, Jid ji
}
return jid.resourcepart;
} else {
- if (jid.bare_jid.equals(account.bare_jid.bare_jid)) {
+ if (jid.equals_bare(account.bare_jid)) {
if (account.alias == null || account.alias == "") {
return account.bare_jid.to_string();
} else {
@@ -84,9 +84,24 @@ public static string get_message_display_name(StreamInteractor stream_interactor
return get_display_name(stream_interactor, message.from, account);
}
-public static void image_set_from_scaled_pixbuf(Image image, Gdk.Pixbuf pixbuf, int scale = 0) {
+public static void image_set_from_scaled_pixbuf(Image image, Gdk.Pixbuf pixbuf, int scale = 0, int width = 0, int height = 0) {
if (scale == 0) scale = image.scale_factor;
- image.set_from_surface(Gdk.cairo_surface_create_from_pixbuf(pixbuf, scale, image.get_window()));
+ Cairo.Surface surface = Gdk.cairo_surface_create_from_pixbuf(pixbuf, scale, image.get_window());
+ if (height == 0 && width != 0) {
+ height = (int) ((double) width / pixbuf.width * pixbuf.height);
+ } else if (height != 0 && width == 0) {
+ width = (int) ((double) height / pixbuf.height * pixbuf.width);
+ }
+ if (width != 0) {
+ Cairo.Surface surface_new = new Cairo.Surface.similar_image(surface, Cairo.Format.ARGB32, width, height);
+ Cairo.Context context = new Cairo.Context(surface_new);
+ context.scale((double) width * scale / pixbuf.width, (double) height * scale / pixbuf.height);
+ context.set_source_surface(surface, 0, 0);
+ context.get_source().set_filter(Cairo.Filter.BEST);
+ context.paint();
+ surface = surface_new;
+ }
+ image.set_from_surface(surface);
}
private const string force_background_css = "%s { background-color: %s; }";