Retry failed file receipts & extra checks

Allows the user to click on a failed file receipt and retry the file download. There are also now checks for if a file marked as complete doesn't exist.
This commit is contained in:
Alphastaire 2024-08-13 01:35:00 -07:00 committed by Max Logaev
parent c28d3865bc
commit 80af06709f

View file

@ -90,7 +90,8 @@ public class FileWidget : SizeRequestBox {
private async void update_widget() { private async void update_widget() {
if (show_image() && state != State.IMAGE if (show_image() && state != State.IMAGE
&& file_transfer.state == FileTransfer.State.COMPLETE) { && file_transfer.state == FileTransfer.State.COMPLETE
&& file_transfer.get_file().query_exists()) {
var content_bak = content; var content_bak = content;
FileImageWidget file_image_widget = null; FileImageWidget file_image_widget = null;
@ -109,7 +110,8 @@ public class FileWidget : SizeRequestBox {
} catch (Error e) { } } catch (Error e) { }
} }
if (state != State.DEFAULT) { if (state != State.DEFAULT ||
(file_transfer.state == FileTransfer.State.COMPLETE && !file_transfer.get_file().query_exists())) {
if (content != null) this.remove(content); if (content != null) this.remove(content);
FileDefaultWidget default_file_widget = new FileDefaultWidget(); FileDefaultWidget default_file_widget = new FileDefaultWidget();
default_widget_controller = new FileDefaultWidgetController(default_file_widget); default_widget_controller = new FileDefaultWidgetController(default_file_widget);
@ -176,11 +178,17 @@ public class FileWidgetController : Object {
} }
private void open_file() { private void open_file() {
if (file_transfer.get_file().query_exists()) {
try { try {
Dino.Util.launch_default_for_uri(file_transfer.get_file().get_uri()); Dino.Util.launch_default_for_uri(file_transfer.get_file().get_uri());
} catch (Error err) { } catch (Error err) {
warning("Failed to open %s - %s", file_transfer.get_file().get_uri(), err.message); warning("Failed to open %s - %s", file_transfer.get_file().get_uri(), err.message);
} }
} else {
warning("File %s does not exist", file_transfer.get_file().get_uri());
file_transfer.state = FileTransfer.State.NOT_STARTED;
widget.activate_action("file.download", null);
}
} }
private void save_file() { private void save_file() {
@ -244,8 +252,12 @@ public class FileDefaultWidgetController : Object {
private void update_file_info() { private void update_file_info() {
state = file_transfer.state; state = file_transfer.state;
if (state == FileTransfer.State.COMPLETE && !file_transfer.get_file().query_exists()) {
state = FileTransfer.State.NOT_STARTED;
file_transfer.state = FileTransfer.State.NOT_STARTED;
}
widget.update_file_info(file_transfer.mime_type, file_transfer.transferred_bytes, widget.update_file_info(file_transfer.mime_type, file_transfer.transferred_bytes,
file_transfer.direction, file_transfer.state, file_transfer.size); file_transfer.direction, state, file_transfer.size);
} }
private void on_clicked() { private void on_clicked() {
@ -254,10 +266,11 @@ public class FileDefaultWidgetController : Object {
widget.activate_action("file.open", null); widget.activate_action("file.open", null);
break; break;
case FileTransfer.State.NOT_STARTED: case FileTransfer.State.NOT_STARTED:
case FileTransfer.State.FAILED:
widget.activate_action("file.download", null); widget.activate_action("file.download", null);
break; break;
default: default:
// Clicking doesn't do anything in FAILED and IN_PROGRESS states // Clicking doesn't do anything in IN_PROGRESS state
break; break;
} }
} }