Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MainWindow: FileChooserNative → Gtk.FileDialog #192

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
33 changes: 19 additions & 14 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -284,26 +284,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 () {
Expand Down