Skip to content

Commit df9e2d6

Browse files
Diego-Ivanlw64
authored andcommitted
library: Remove Gdk.Pixbuf-related APIs in HTTP Image Vala demo (#798)
1 parent c13cfa9 commit df9e2d6

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env -S vala workbench.vala --pkg libadwaita-1 --pkg gdk-pixbuf-2.0 --pkg libsoup-3.0
1+
#!/usr/bin/env -S vala workbench.vala --pkg libadwaita-1 --pkg libsoup-3.0
22

33
public errordomain MessageError {
44
FAILED;
@@ -9,21 +9,19 @@ private const string IMAGE_URL = "https://picsum.photos/800";
99

1010
public async void main () {
1111
try {
12-
var input_stream = yield get_input_stream (IMAGE_URL);
13-
var pixbuf = yield new Gdk.Pixbuf.from_stream_async (input_stream, null);
14-
var texture = Gdk.Texture.for_pixbuf(pixbuf);
1512
var picture = (Gtk.Picture) workbench.builder.get_object ("picture");
16-
picture.set_paintable (texture);
13+
Bytes image_bytes = yield get_image_bytes (IMAGE_URL);
14+
picture.paintable = Gdk.Texture.from_bytes (image_bytes);
1715
} catch (Error e) {
1816
critical (e.message);
1917
}
2018
}
2119

22-
private async InputStream? get_input_stream (string url) throws Error {
20+
private async Bytes? get_image_bytes (string url) throws Error {
2321
var session = new Soup.Session ();
2422
var message = new Soup.Message.from_uri ("GET", Uri.parse (url, NONE));
2523

26-
InputStream input_stream = yield session.send_async (message, Priority.DEFAULT, null);
24+
Bytes image_bytes = yield session.send_and_read_async (message, Priority.DEFAULT, null);
2725

2826
uint status_code = message.status_code;
2927
string reason = message.reason_phrase;
@@ -32,5 +30,5 @@ private async InputStream? get_input_stream (string url) throws Error {
3230
throw new MessageError.FAILED (@"Got $status_code: $reason");
3331
}
3432

35-
return input_stream;
33+
return image_bytes;
3634
}

0 commit comments

Comments
 (0)