diff options
6 files changed, 44 insertions, 14 deletions
diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index 927b108d..0c98a8f3 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -106,9 +106,12 @@ public class AvatarManager : StreamInteractionModule, Object { return get_avatar_hash(account, jid) != null; } - public void publish(Account account, string file) { + public void publish(Account account, File file) { + debug("Publish avatar from %s", file.get_uri()); + FileInputStream file_stream = null; try { - Pixbuf pixbuf = new Pixbuf.from_file(file); + file_stream = file.read(); + Pixbuf pixbuf = new Pixbuf.from_stream(file_stream); if (pixbuf.width >= pixbuf.height && pixbuf.width > MAX_PIXEL) { int dest_height = (int) ((float) MAX_PIXEL / pixbuf.width * pixbuf.height); pixbuf = pixbuf.scale_simple(MAX_PIXEL, dest_height, InterpType.BILINEAR); @@ -121,9 +124,18 @@ public class AvatarManager : StreamInteractionModule, Object { XmppStream stream = stream_interactor.get_stream(account); if (stream != null) { Xmpp.Xep.UserAvatars.publish_png(stream, buffer, pixbuf.width, pixbuf.height); + debug("Publishing %u png bytes via user-avatars.", buffer.length); + } else { + warning("No stream when trying to publish."); } } catch (Error e) { warning(e.message); + } finally { + try { + if (file_stream != null) file_stream.close(); + } catch (Error e) { + // Ignore + } } } @@ -257,6 +269,7 @@ public class AvatarManager : StreamInteractionModule, Object { DataOutputStream fos = new DataOutputStream(file.create(FileCreateFlags.REPLACE_DESTINATION)); yield fos.write_bytes_async(data); } catch (Error e) { + warning("Error writing avatar file: %s", e.message); // Ignore: we failed in storing, so we refuse to display later... } } diff --git a/main/src/ui/conversation_content_view/file_image_widget.vala b/main/src/ui/conversation_content_view/file_image_widget.vala index 6efe2d58..f39dd30a 100644 --- a/main/src/ui/conversation_content_view/file_image_widget.vala +++ b/main/src/ui/conversation_content_view/file_image_widget.vala @@ -154,10 +154,20 @@ public class FileImageWidget : Widget { public async void load_from_file(File file, string file_name) throws GLib.Error { FixedRatioPicture image = new FixedRatioPicture() { min_width=100, min_height=100, max_width=600, max_height=300 }; - // Work-around because Gtk.Picture does not apply the orientation itself - Gdk.Pixbuf? pixbuf = new Pixbuf.from_file(file.get_path()); - pixbuf = pixbuf.apply_embedded_orientation(); - image.paintable = Texture.for_pixbuf(pixbuf); + FileInputStream file_stream = null; + try { + file_stream = file.read(); + // Work-around because Gtk.Picture does not apply the orientation itself + Gdk.Pixbuf? pixbuf = new Pixbuf.from_stream(file_stream); + pixbuf = pixbuf.apply_embedded_orientation(); + image.paintable = Texture.for_pixbuf(pixbuf); + } finally { + try { + if (file_stream != null) file_stream.close(); + } catch (Error e) { + // Ignore + } + } stack.add_child(image); stack.set_visible_child(image); diff --git a/main/src/ui/conversation_content_view/file_widget.vala b/main/src/ui/conversation_content_view/file_widget.vala index f031db21..0e3cee03 100644 --- a/main/src/ui/conversation_content_view/file_widget.vala +++ b/main/src/ui/conversation_content_view/file_widget.vala @@ -169,8 +169,13 @@ public class FileWidgetController : Object { save_dialog.set_current_name(file_transfer.file_name); save_dialog.response.connect(() => { - try{ - GLib.File.new_for_uri(file_transfer.get_file().get_uri()).copy(save_dialog.get_file(), GLib.FileCopyFlags.OVERWRITE, null); + File? target_file = save_dialog.get_file(); + if (target_file == null) { + warning("No file returned from save dialog."); + return; + } + try { + file_transfer.get_file().copy(save_dialog.get_file(), GLib.FileCopyFlags.OVERWRITE, null); } catch (Error err) { warning("Failed copy file %s - %s", file_transfer.get_file().get_uri(), err.message); } diff --git a/main/src/ui/conversation_view_controller.vala b/main/src/ui/conversation_view_controller.vala index 1662ae56..2e11e1e9 100644 --- a/main/src/ui/conversation_view_controller.vala +++ b/main/src/ui/conversation_view_controller.vala @@ -203,7 +203,7 @@ public class ConversationViewController : Object { FileChooserNative chooser = new FileChooserNative(_("Select file"), view.get_root() as Gtk.Window, FileChooserAction.OPEN, _("Select"), _("Cancel")); chooser.response.connect((response) => { if (response == ResponseType.ACCEPT) { - open_send_file_overlay(File.new_for_path(chooser.get_file().get_path())); + open_send_file_overlay(chooser.get_file()); } }); chooser.show(); @@ -213,7 +213,10 @@ public class ConversationViewController : Object { FileInfo file_info; try { file_info = file.query_info("*", FileQueryInfoFlags.NONE); - } catch (Error e) { return; } + } catch (Error e) { + warning("Failed querying info for file %s", file.get_path()); + return; + } FileSendOverlay overlay = new FileSendOverlay(file, file_info); overlay.send_file.connect(() => send_file(file)); diff --git a/main/src/view_model/preferences_dialog.vala b/main/src/view_model/preferences_dialog.vala index c09c650a..af00494d 100644 --- a/main/src/view_model/preferences_dialog.vala +++ b/main/src/view_model/preferences_dialog.vala @@ -66,8 +66,8 @@ public class Dino.Ui.ViewModel.PreferencesDialog : Object { update(); } - public void set_avatar_uri(Account account, string uri) { - stream_interactor.get_module(AvatarManager.IDENTITY).publish(account, uri); + public void set_avatar_file(Account account, File file) { + stream_interactor.get_module(AvatarManager.IDENTITY).publish(account, file); } public void remove_avatar(Account account) { diff --git a/main/src/windows/preferences_window/account_preferences_subpage.vala b/main/src/windows/preferences_window/account_preferences_subpage.vala index 7a17fbda..660a9aeb 100644 --- a/main/src/windows/preferences_window/account_preferences_subpage.vala +++ b/main/src/windows/preferences_window/account_preferences_subpage.vala @@ -144,8 +144,7 @@ public class Dino.Ui.AccountPreferencesSubpage : Adw.NavigationPage { chooser.add_filter(filter); chooser.response.connect(() => { - string uri = chooser.get_file().get_path(); - model.set_avatar_uri(account, uri); + model.set_avatar_file(account, chooser.get_file()); }); chooser.show(); |
