diff --git a/com.github.lachhebo.Gabtag.Devel.json b/com.github.lachhebo.Gabtag.Devel.json index 5b76998..db3feeb 100644 --- a/com.github.lachhebo.Gabtag.Devel.json +++ b/com.github.lachhebo.Gabtag.Devel.json @@ -5,7 +5,6 @@ "sdk": "org.gnome.Sdk", "command": "gabtag", "finish-args": [ - "--filesystem=home", "--device=dri", "--share=network", "--share=ipc", diff --git a/src/event_machine.py b/src/event_machine.py index e71d82b..e0c2f37 100644 --- a/src/event_machine.py +++ b/src/event_machine.py @@ -4,8 +4,9 @@ from .controller import Controller from .tools import add_filters, get_filenames_from_selection -from gi.repository import Gio, Gtk +from gi.repository import Gio, GLib, Gtk +import logging import gi import gettext @@ -43,31 +44,25 @@ def on_reset_all_clicked(self, widget, action: Gio.Action): def on_about_clicked(self, widget, action: Gio.Action): if self.window is not None: - self.window.id_about_window.show() + self.window.id_about_window.set_visible(True) def on_open_clicked(self, widget): self.is_real_selection = 0 - dialog = Gtk.FileChooserDialog( - title=_("Select a Folder"), - transient_for=self.window, - action=Gtk.FileChooserAction.SELECT_FOLDER, - ) - dialog.add_buttons(_("_Open"), Gtk.ResponseType.OK) - dialog.add_buttons(_("_Cancel"), Gtk.ResponseType.CANCEL) - dialog.set_default_response(Gtk.ResponseType.OK) + dialog = Gtk.FileDialog.new() + dialog.set_title(_("Select a Folder")) dialog.set_modal(True) - dialog.connect("response", self.on_open_folder_chooser) - - dialog.show() + dialog.select_folder(self.window, None, self.on_open_folder_chooser) self.is_real_selection = 1 - def on_open_folder_chooser(self, dialog, response): - dialog.destroy() - - if response == Gtk.ResponseType.OK: - Controller.change_directory(dialog.get_file().get_path()) + def on_open_folder_chooser(self, dialog, result): + try: + gfile = dialog.select_folder_finish(result) + except GLib.Error as err: + logging.debug("Could not open folder: %s", err.message) + else: + Controller.change_directory(gfile.get_path()) def on_menu_but_toggled(self, widget): pass @@ -112,32 +107,24 @@ def on_load_cover_clicked(self, widget): if self.is_real_selection == 1: self.is_real_selection = 0 - dialog = Gtk.FileChooserDialog( - title=_("Open a File"), - transient_for=self.window, - action=Gtk.FileChooserAction.OPEN, - ) - dialog.add_buttons(_("_Open"), Gtk.ResponseType.OK) - dialog.add_buttons(_("_Cancel"), Gtk.ResponseType.CANCEL) - dialog.set_default_response(Gtk.ResponseType.OK) + dialog = Gtk.FileDialog.new() + dialog.set_title(_("Open a File")) dialog.set_modal(True) add_filters(dialog) - dialog.connect("response", self.on_open_image_chooser) - - dialog.show() + dialog.open(self.window, None, self.on_open_image_chooser) self.is_real_selection = 1 - def on_open_image_chooser(self, dialog, response): - dialog.destroy() - - if response == Gtk.ResponseType.OK: - file_cover = dialog.get_file().get_path() - + def on_open_image_chooser(self, dialog, result): + try: + gfile = dialog.open_finish(result) + except GLib.Error as err: + logging.debug("Could not open file: %s", err.message) + else: name_files = get_filenames_from_selection(SELECTION.selection) - MODEL.update_modifications(name_files, "cover", file_cover) + MODEL.update_modifications(name_files, "cover", gfile.get_path()) Controller.update_view(name_files) def on_selected_changed(self, selection): diff --git a/src/tools.py b/src/tools.py index 2da733c..a8fd1e9 100644 --- a/src/tools.py +++ b/src/tools.py @@ -11,7 +11,7 @@ gi.require_version("Gtk", "4.0") -from gi.repository import Gtk # noqa: E402 +from gi.repository import Gio, Gtk # noqa: E402 _ = gettext.gettext @@ -105,21 +105,25 @@ def music_length_to_string(length): def add_filters(dialog): + store = Gio.ListStore.new(Gtk.FileFilter) + filter_all = Gtk.FileFilter() filter_all.set_name(_("All Supported Images")) filter_all.add_mime_type("image/png") filter_all.add_mime_type("image/jpeg") - dialog.add_filter(filter_all) + store.append(filter_all) filter_png = Gtk.FileFilter() filter_png.set_name(_("PNG Images")) filter_png.add_mime_type("image/png") - dialog.add_filter(filter_png) + store.append(filter_png) filter_jpeg = Gtk.FileFilter() filter_jpeg.set_name(_("JPEG Images")) filter_jpeg.add_mime_type("image/jpeg") - dialog.add_filter(filter_jpeg) + store.append(filter_jpeg) + + dialog.set_filters(store) def set_label(view_label, multiple_rows, value):