Load images in conversation summary in different thread
This commit is contained in:
parent
43720d3d2f
commit
a96c80149f
|
@ -37,22 +37,28 @@ public class FileWidget : Box {
|
||||||
this.stream_interactor = stream_interactor;
|
this.stream_interactor = stream_interactor;
|
||||||
this.file_transfer = file_transfer;
|
this.file_transfer = file_transfer;
|
||||||
|
|
||||||
|
load_widget.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void load_widget() {
|
||||||
if (show_image()) {
|
if (show_image()) {
|
||||||
content = getImageWidget(file_transfer);
|
content = yield get_image_widget(file_transfer);
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
this.state = State.IMAGE;
|
this.state = State.IMAGE;
|
||||||
this.add(content);
|
this.add(content);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
content = get_default_widget(file_transfer);
|
||||||
content = getDefaultWidget(file_transfer);
|
|
||||||
this.state = State.DEFAULT;
|
this.state = State.DEFAULT;
|
||||||
this.add(content);
|
this.add(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Widget? getImageWidget(FileTransfer file_transfer) {
|
private async Widget? get_image_widget(FileTransfer file_transfer) {
|
||||||
Image image = new Image() { halign=Align.START, visible = true };
|
Image image = new Image() { halign=Align.START, visible = true };
|
||||||
|
|
||||||
|
// Load, scale and set the image
|
||||||
|
new Thread<void*> (null, () => {
|
||||||
Gdk.Pixbuf pixbuf;
|
Gdk.Pixbuf pixbuf;
|
||||||
try {
|
try {
|
||||||
pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_file().get_path());
|
pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_file().get_path());
|
||||||
|
@ -73,6 +79,12 @@ public class FileWidget : Box {
|
||||||
}
|
}
|
||||||
pixbuf = crop_corners(pixbuf, 3 * image.get_scale_factor());
|
pixbuf = crop_corners(pixbuf, 3 * image.get_scale_factor());
|
||||||
Util.image_set_from_scaled_pixbuf(image, pixbuf);
|
Util.image_set_from_scaled_pixbuf(image, pixbuf);
|
||||||
|
|
||||||
|
Idle.add(get_image_widget.callback);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
yield;
|
||||||
|
|
||||||
Util.force_css(image, "* { box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.1); margin: 2px; border-radius: 3px; }");
|
Util.force_css(image, "* { box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.1); margin: 2px; border-radius: 3px; }");
|
||||||
|
|
||||||
Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_summary/image_toolbar.ui");
|
Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_summary/image_toolbar.ui");
|
||||||
|
@ -133,7 +145,7 @@ public class FileWidget : Box {
|
||||||
return Gdk.pixbuf_get_from_surface(ctx.get_target(), 0, 0, pixbuf.width, pixbuf.height);
|
return Gdk.pixbuf_get_from_surface(ctx.get_target(), 0, 0, pixbuf.width, pixbuf.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Widget getDefaultWidget(FileTransfer file_transfer) {
|
private Widget get_default_widget(FileTransfer file_transfer) {
|
||||||
string icon_name = get_file_icon_name(file_transfer.mime_type);
|
string icon_name = get_file_icon_name(file_transfer.mime_type);
|
||||||
|
|
||||||
main_box = new Box(Orientation.HORIZONTAL, 10) { halign=Align.FILL, hexpand=true, visible=true };
|
main_box = new Box(Orientation.HORIZONTAL, 10) { halign=Align.FILL, hexpand=true, visible=true };
|
||||||
|
@ -235,15 +247,15 @@ public class FileWidget : Box {
|
||||||
file_transfer.notify["path"].connect(update_file_info);
|
file_transfer.notify["path"].connect(update_file_info);
|
||||||
file_transfer.notify["state"].connect(update_file_info);
|
file_transfer.notify["state"].connect(update_file_info);
|
||||||
file_transfer.notify["mime-type"].connect(update_file_info);
|
file_transfer.notify["mime-type"].connect(update_file_info);
|
||||||
update_file_info();
|
update_file_info.begin();
|
||||||
|
|
||||||
return event_box;
|
return event_box;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update_file_info() {
|
private async void update_file_info() {
|
||||||
if (file_transfer.state == FileTransfer.State.COMPLETE && show_image() && state != State.IMAGE) {
|
if (file_transfer.state == FileTransfer.State.COMPLETE && show_image() && state != State.IMAGE) {
|
||||||
this.remove(content);
|
this.remove(content);
|
||||||
this.add(getImageWidget(file_transfer));
|
this.add(yield get_image_widget(file_transfer));
|
||||||
state = State.IMAGE;
|
state = State.IMAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue