aboutsummaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-04-13 13:00:41 +0200
committerfiaxh <git@lightrise.org>2020-04-13 13:00:41 +0200
commitbcbd5f0807e495b50d9aef8d23dfafe83e068eba (patch)
tree5d372326857b9c1118e8f67a265f260754a17b1d /main/src
parent5b9199e7d40ff8a9031741dc5af6db41fcb2542f (diff)
downloaddino-bcbd5f0807e495b50d9aef8d23dfafe83e068eba.tar.gz
dino-bcbd5f0807e495b50d9aef8d23dfafe83e068eba.zip
Fix FileWidget sometimes showing two states
Diffstat (limited to 'main/src')
-rw-r--r--main/src/ui/conversation_content_view/file_widget.vala50
1 files changed, 24 insertions, 26 deletions
diff --git a/main/src/ui/conversation_content_view/file_widget.vala b/main/src/ui/conversation_content_view/file_widget.vala
index 85ac0d56..d92eedb5 100644
--- a/main/src/ui/conversation_content_view/file_widget.vala
+++ b/main/src/ui/conversation_content_view/file_widget.vala
@@ -37,51 +37,45 @@ public class FileWidget : Box {
private StreamInteractor stream_interactor;
private FileTransfer file_transfer;
- private State state;
+ private State? state = null;
private FileDefaultWidgetController default_widget_controller;
- private Widget content;
+ private Widget? content = null;
public FileWidget(StreamInteractor stream_interactor, FileTransfer file_transfer) {
this.stream_interactor = stream_interactor;
this.file_transfer = file_transfer;
- load_widget.begin();
+ update_widget.begin();
size_allocate.connect((allocation) => {
if (allocation.height > parent.get_allocated_height()) {
Idle.add(() => { parent.queue_resize(); return false; });
}
});
- file_transfer.notify["state"].connect(update_widget_type);
- file_transfer.notify["mime-type"].connect(update_widget_type);
+ file_transfer.notify["state"].connect(update_widget);
+ file_transfer.notify["mime-type"].connect(update_widget);
}
- private async void load_widget() {
- if (show_image()) {
- content = yield get_image_widget(file_transfer.get_file(), file_transfer.file_name);
- if (content != null) {
- this.state = State.IMAGE;
+ private async void update_widget() {
+ if (show_image() && state != State.IMAGE) {
+ var content_bak = content;
+ Widget? image_widget = yield get_image_widget(file_transfer.get_file(), file_transfer.file_name);
+
+ // If the widget changed in the meanwhile, stop
+ if (content != content_bak) return;
+
+ if (image_widget != null) {
+ if (content != null) this.remove(content);
+ content = image_widget;
+ state = State.IMAGE;
this.add(content);
return;
}
}
- FileDefaultWidget default_file_widget = new FileDefaultWidget() { visible=true };
- default_widget_controller = new FileDefaultWidgetController(default_file_widget, file_transfer, stream_interactor);
- content = default_file_widget;
- this.state = State.DEFAULT;
- this.add(content);
- }
- private async void update_widget_type() {
- if (file_transfer.state == FileTransfer.State.COMPLETE && show_image() && state != State.IMAGE) {
- this.remove(content);
- this.add(yield get_image_widget(file_transfer.get_file(), file_transfer.file_name));
- state = State.IMAGE;
- return;
- }
- if (file_transfer.state == FileTransfer.State.FAILED && state == State.IMAGE) {
- this.remove(content);
+ if (state != State.DEFAULT) {
+ if (content != null) this.remove(content);
FileDefaultWidget default_file_widget = new FileDefaultWidget() { visible=true };
default_widget_controller = new FileDefaultWidgetController(default_file_widget, file_transfer, stream_interactor);
content = default_file_widget;
@@ -161,7 +155,11 @@ public class FileWidget : Box {
}
private bool show_image() {
- if (file_transfer.mime_type == null || file_transfer.state != FileTransfer.State.COMPLETE) return false;
+ if (file_transfer.mime_type == null) return false;
+ if (file_transfer.state != FileTransfer.State.COMPLETE &&
+ !(file_transfer.direction == FileTransfer.DIRECTION_SENT && file_transfer.state == FileTransfer.State.IN_PROGRESS)) {
+ return false;
+ }
foreach (PixbufFormat pixbuf_format in Pixbuf.get_formats()) {
foreach (string mime_type in pixbuf_format.get_mime_types()) {