Skip to content

Commit

Permalink
Port to libadwaita adaptive dialogs (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende authored Mar 23, 2024
1 parent d4226f9 commit c8187e4
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ See [DEVELOPMENT.md](DEVELOPMENT.md) for detailed instructions and developing Co
- `python3`
- `meson >= 0.40.0` as build system
- `gtk4 >= 4.10`
- `libadwaita >= 1.4.0`
- `libadwaita >= 1.5.0`
- `peewee >= 3.9.6` as object relation mapper
- `mutagen` for meta tag management
- `distro`
Expand Down
2 changes: 1 addition & 1 deletion com.github.geigi.cozy.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app-id": "com.github.geigi.cozy",
"runtime": "org.gnome.Platform",
"runtime-version": "45",
"runtime-version": "46",
"sdk": "org.gnome.Sdk",
"command": "com.github.geigi.cozy",
"finish-args": [
Expand Down
5 changes: 2 additions & 3 deletions cozy/ui/about_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class AboutWindow:
def __init__(self, version: str) -> None:
self._window = Adw.AboutWindow.new_from_appdata(
self._window = Adw.AboutDialog.new_from_appdata(
"/com/github/geigi/cozy/appdata/com.github.geigi.cozy.appdata.xml",
release_notes_version=version,
)
Expand Down Expand Up @@ -53,5 +53,4 @@ def set_extra_credits(self) -> None:
)

def present(self, parent: Adw.ApplicationWindow) -> None:
self._window.set_transient_for(parent)
self._window.present()
self._window.present(parent)
8 changes: 5 additions & 3 deletions cozy/ui/db_migration_failed_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
You can help resolve this problem by reporting an issue on GitHub.")


class DBMigrationFailedView(Adw.MessageDialog):
class DBMigrationFailedView(Adw.AlertDialog):
def __init__(self):
super().__init__(
heading=_("Failed to Update Database"),
body=EXPLANATION,
default_response="help",
close_response="close",
modal=True,
)

self.add_response("close", _("Close Cozy"))
Expand All @@ -25,7 +24,10 @@ def __init__(self):

self.connect("response", self.get_help)

def get_help(self, *_, response):
def get_help(self, _, response):
if response == "help":
webbrowser.open("https://github.com/geigi/cozy/issues", new=2)

def present(self) -> None:
super().present()

7 changes: 4 additions & 3 deletions cozy/ui/delete_book_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cozy.ui.widgets.book_row import BookRow


class DeleteBookView(Adw.MessageDialog):
class DeleteBookView(Adw.AlertDialog):
main_window = inject.attr("MainWindow")

def __init__(self, callback, book: Book):
Expand All @@ -14,8 +14,6 @@ def __init__(self, callback, book: Book):
body=_("The audiobook will be removed from your disk and from Cozy's library."),
default_response="cancel",
close_response="cancel",
transient_for=self.main_window.window,
modal=True,
)

self.add_response("cancel", _("Cancel"))
Expand All @@ -27,3 +25,6 @@ def __init__(self, callback, book: Book):
self.set_extra_child(list_box)

self.connect("response", callback, book)

def present(self) -> None:
super().present(self.main_window.window)
9 changes: 5 additions & 4 deletions cozy/ui/file_not_found_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cozy.model.chapter import Chapter


class FileNotFoundDialog(Adw.MessageDialog):
class FileNotFoundDialog(Adw.AlertDialog):
main_window = inject.attr("MainWindow")
_importer: Importer = inject.attr(Importer)

Expand All @@ -19,15 +19,13 @@ def __init__(self, chapter: Chapter):
body=_("This file could not be found. Do you want to locate it manually?"),
default_response="locate",
close_response="cancel",
transient_for=self.main_window.window,
modal=True,
)

self.add_response("cancel", _("Cancel"))
self.add_response("locate", _("Locate"))
self.set_response_appearance("locate", Adw.ResponseAppearance.SUGGESTED)

label = Gtk.Label(label=chapter.file, margin_top=12)
label = Gtk.Label(label=chapter.file, margin_top=12, wrap=True)
label.add_css_class("monospace")
self.set_extra_child(label)

Expand Down Expand Up @@ -62,3 +60,6 @@ def _file_dialog_open_callback(self, dialog, result):
self.missing_chapter.file = file.get_path()
self._importer.scan()

def present(self) -> None:
super().present(self.main_window.window)

7 changes: 4 additions & 3 deletions cozy/ui/import_failed_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
message = HEADER + POSSIBILITIES


class ImportFailedDialog(Adw.MessageDialog):
class ImportFailedDialog(Adw.AlertDialog):
"""
Dialog that displays failed files on import.
"""
Expand All @@ -28,8 +28,6 @@ def __init__(self, files: list[str]):
heading=_("Some files could not be imported"),
default_response="cancel",
close_response="cancel",
transient_for=self.main_window.window,
modal=True,
)

self.add_response("cancel", _("Ok"))
Expand Down Expand Up @@ -57,3 +55,6 @@ def __init__(self, files: list[str]):
box.append(scroller)
self.set_extra_child(box)

def present(self) -> None:
super().present(self.main_window.window)

5 changes: 2 additions & 3 deletions cozy/ui/preferences_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@Gtk.Template.from_resource("/com/github/geigi/cozy/ui/preferences.ui")
class PreferencesWindow(Adw.PreferencesWindow):
class PreferencesWindow(Adw.PreferencesDialog):
__gtype_name__ = "PreferencesWindow"

_glib_settings: Gio.Settings = inject.attr(Gio.Settings)
Expand Down Expand Up @@ -57,5 +57,4 @@ def _on_lock_ui_changed(self) -> None:
self.storage_locations_view.set_sensitive(not self._view_model.lock_ui)

def present(self, parent: Adw.ApplicationWindow) -> None:
self.set_transient_for(parent)
super().present()
super().present(parent)
2 changes: 1 addition & 1 deletion data/ui/preferences.blp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Adjustment rewind_duration_adjustment {
page-increment: 10;
}

template $PreferencesWindow: Adw.PreferencesWindow {
template $PreferencesWindow: Adw.PreferencesDialog {
Adw.PreferencesPage {
icon-name: 'settings-symbolic';
title: _('General');
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
endif

dependency('glib-2.0')
dependency('libadwaita-1', version: '>= 1.4.0')
dependency('libadwaita-1', version: '>= 1.5.0')

# from https://github.com/AsavarTzeth/pulseeffects/blob/master/meson.build
# Support Debian non-standard python paths
Expand Down

0 comments on commit c8187e4

Please sign in to comment.