From a053da2487103ddd5e146ffc9bfb4dbffb9436d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sun, 5 Feb 2023 09:10:08 -0800 Subject: [PATCH] =?UTF-8?q?MainWindow:=20FileChooserNative=20=E2=86=92=20G?= =?UTF-8?q?tk.FileDialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- meson.build | 2 +- src/MainWindow.vala | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/meson.build b/meson.build index fbd60c5..cd49eba 100644 --- a/meson.build +++ b/meson.build @@ -12,7 +12,7 @@ vapi_dir = join_paths(meson.current_source_dir(), 'vapi') add_project_arguments(['--vapidir', vapi_dir], language: 'vala') dependencies = [ - dependency('gtk4'), + dependency('gtk4', version: '>=4.10'), dependency('gee-0.8'), dependency('granite-7'), dependency('threads'), diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 106260b..0036bd1 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -336,26 +336,31 @@ public class Torrential.MainWindow : Gtk.ApplicationWindow { } private void on_open (SimpleAction action) { - var all_files_filter = new Gtk.FileFilter (); - all_files_filter.set_filter_name (_("All files")); + var all_files_filter = new Gtk.FileFilter () { + name = _("All files") + }; all_files_filter.add_pattern ("*"); - var torrent_files_filter = new Gtk.FileFilter (); - torrent_files_filter.set_filter_name (_("Torrent files")); + var torrent_files_filter = new Gtk.FileFilter () { + name = _("Torrent files") + }; torrent_files_filter.add_mime_type ("application/x-bittorrent"); - var filech = new Gtk.FileChooserNative (_("Open some torrents"), this, Gtk.FileChooserAction.OPEN, _("Open"), _("Cancel")); - filech.set_select_multiple (true); - filech.add_filter (torrent_files_filter); - filech.add_filter (all_files_filter); + var filters = new ListStore (typeof (Gtk.FileFilter)); + filters.append (all_files_filter); + filters.append (torrent_files_filter); - filech.show (); + var file_dialog = new Gtk.FileDialog () { + filters = filters, + title = _("Open some torrents") + }; - filech.response.connect ((response) => { - if (response == Gtk.ResponseType.ACCEPT) { - add_files (filech.get_files ()); - } - }); + try { + var file_listmodel = file_dialog.open_multiple (this, null); + add_files (file_listmodel); + } catch (Error e) { + critical (e.message); + } } private void on_open_magnet () {