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

Blueprintify #896

Merged
merged 10 commits into from
Mar 14, 2024
Merged
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ debian/debhelper-build-stamp
debian/files
peewee/
venv/
env/
blueprint-compiler/

.pytest_cache

Expand Down
12 changes: 12 additions & 0 deletions com.github.geigi.cozy.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@
}
]
},
{
"name": "blueprint-compiler",
"buildsystem": "meson",
"cleanup": [ "*" ],
"sources": [
{
"type": "git",
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler.git",
"tag": "v0.10.0"
}
]
},
{
"name": "cozy",
"buildsystem": "meson",
Expand Down
11 changes: 5 additions & 6 deletions cozy/application.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import os

Check failure on line 2 in cozy/application.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

cozy/application.py:2:8: F401 `os` imported but unused
import platform
import sys
import threading
Expand Down Expand Up @@ -42,7 +42,7 @@
log.info("Starting up cozy %s", __version__)
log.info("libadwaita version: %s", Adw._version)

self.ui = CozyUI(self.pkgdatadir, self, __version__)
self.ui = CozyUI(self, __version__)
Adw.Application.do_startup(self)
init_db()
self.ui.startup()
Expand All @@ -56,10 +56,9 @@
if Settings.get().first_start:
Settings.update(first_start=False).execute()

path = os.path.join(Path.home(), _("Audiobooks"))
Storage.create(path=path, default=True)

os.makedirs(path, exist_ok=True)
audiobooks_path = Path.home() / _("Audiobooks")
audiobooks_path.mkdir(exist_ok=True)
Storage.create(path=str(audiobooks_path), default=True)

self.add_window(self.ui.window)

Expand All @@ -82,7 +81,7 @@

def quit(self):
self.app_controller.quit()
super(Application, self).quit()
super().quit()

@staticmethod
def init_custom_widgets():
Expand Down
57 changes: 57 additions & 0 deletions cozy/ui/about_window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from collections import defaultdict

from gi.repository import Adw, Gio, Gtk


class AboutWindow:
def __init__(self, version: str) -> None:
self._window = Adw.AboutWindow.new_from_appdata(
"/com/github/geigi/cozy/appdata/com.github.geigi.cozy.appdata.xml",
release_notes_version=version,
)

contributors = self.get_contributors()
self._window.set_developers(sorted(contributors["code"]))
self._window.set_designers(sorted(contributors["design"]))
self._window.set_artists(sorted(contributors["icon"]))

self._window.set_license_type(Gtk.License.GPL_3_0)

# Translators: Replace "translator-credits" with your names, one name per line
self._window.set_translator_credits(_("translator-credits"))

self.set_extra_credits()

def get_contributors(self) -> list[str]:
authors_file = Gio.resources_lookup_data(
"/com/github/geigi/cozy/appdata/authors.list", Gio.ResourceLookupFlags.NONE
)

current_section = ""
result = defaultdict(list)
for line in authors_file.get_data().decode().splitlines():
if line.startswith("#"):
current_section = line[1:].strip().lower()
elif line.startswith("-"):
result[current_section].append(line[1:].strip())

return result

def set_extra_credits(self) -> None:
self._window.add_acknowledgement_section(
_("Patreon Supporters"),
["Fred Warren", "Gabriel", "Hu Mann", "Josiah", "Oleksii Kriukov"],
)
self._window.add_acknowledgement_section(_("m4b chapter support in mutagen"), ("mweinelt",))
self._window.add_acknowledgement_section(
_("Open Source Projects"),
("Lollypop music player https://gitlab.gnome.org/World/lollypop",),
)

self._window.add_legal_section(
"python-inject", "© 2010 Ivan Korobkov", Gtk.License.APACHE_2_0
)

def present(self, parent: Adw.ApplicationWindow) -> None:
self._window.set_transient_for(parent)
self._window.present()
2 changes: 1 addition & 1 deletion cozy/ui/book_detail_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ALBUM_ART_SIZE = 256


@Gtk.Template.from_resource('/com/github/geigi/cozy/book_detail.ui')
@Gtk.Template.from_resource('/com/github/geigi/cozy/ui/book_detail.ui')
class BookDetailView(Gtk.Box):
__gtype_name__ = 'BookDetail'

Expand Down
2 changes: 1 addition & 1 deletion cozy/ui/chapter_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from cozy.model.chapter import Chapter


@Gtk.Template.from_resource('/com/github/geigi/cozy/chapter_element.ui')
@Gtk.Template.from_resource('/com/github/geigi/cozy/ui/chapter_element.ui')
class ChapterElement(Gtk.Box):
__gtype_name__ = "ChapterElement"

Expand Down
2 changes: 1 addition & 1 deletion cozy/ui/headerbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
log = logging.getLogger("Headerbar")


@Gtk.Template.from_resource("/com/github/geigi/cozy/headerbar.ui")
@Gtk.Template.from_resource("/com/github/geigi/cozy/ui/headerbar.ui")
class Headerbar(Gtk.Box):
__gtype_name__ = "Headerbar"

Expand Down
124 changes: 25 additions & 99 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@
from cozy.view_model.storages_view_model import StoragesViewModel
from cozy.open_view import OpenView
from cozy.ui.library_view import LibraryView
from cozy.ui.preferences_view import PreferencesView
from cozy.ui.about_window import AboutWindow
from cozy.ui.preferences_window import PreferencesWindow
from cozy.ui.widgets.first_import_button import FirstImportButton


log = logging.getLogger("ui")


class CozyUI(EventSender, metaclass=Singleton):
"""
CozyUI is the main ui class.
"""
# Is currently an dialog open?
is_initialized = False
__inhibit_cookie = None
"""CozyUI is the main ui class"""

fs_monitor = inject.attr(fs_monitor.FilesystemMonitor)
application_settings = inject.attr(ApplicationSettings)
_importer: Importer = inject.attr(Importer)
Expand All @@ -43,14 +40,13 @@ class CozyUI(EventSender, metaclass=Singleton):
_player: Player = inject.attr(Player)
_storages_view_model: StoragesViewModel = inject.attr(StoragesViewModel)

def __init__(self, pkgdatadir, app, version):
_library_view: LibraryView

def __init__(self, app, version):
super().__init__()
self.pkgdir = pkgdatadir
self.app = app
self.version = version

self._library_view: LibraryView = None

def activate(self, library_view: LibraryView):
self.__init_window()
self.__init_actions()
Expand All @@ -61,24 +57,9 @@ def activate(self, library_view: LibraryView):
self.auto_import()
self.check_for_tracks()

self.is_initialized = True

def startup(self):
self.__init_resources()

def __init_resources(self):
"""
Initialize all resources like gresource and glade windows.
"""

self.appdata_resource = Gio.resource_load(
os.path.join(self.pkgdir, 'com.github.geigi.cozy.appdata.gresource'))
Gio.Resource._register(self.appdata_resource)

self.window_builder = Gtk.Builder.new_from_resource(
"/com/github/geigi/cozy/main_window.ui")

self.window: Gtk.Window = self.window_builder.get_object("app_window")
self.window_builder = Gtk.Builder.new_from_resource("/com/github/geigi/cozy/ui/main_window.ui")
self.window: Adw.ApplicationWindow = self.window_builder.get_object("app_window")

def __init_window(self):
"""
Expand Down Expand Up @@ -112,15 +93,9 @@ def __init_actions(self):
"""
Init all app actions.
"""

about_action = Gio.SimpleAction.new("about", None)
about_action.connect("activate", self.about)
self.app.add_action(about_action)
self.app.set_accels_for_action("app.about", ["F1"])

self.create_action("about", self.about)
self.create_action("about", self.show_about_window, ["F1"])
self.create_action("prefs", self.show_preferences_window, ["<primary>comma"])
self.create_action("quit", self.quit, ["<primary>q", "<primary>w"])
self.create_action("prefs", self.show_prefs, ["<primary>comma"])
self.scan_action = self.create_action("scan", self.scan)
self.play_pause_action = self.create_action("play_pause", self.play_pause, ["space"])

Expand All @@ -130,6 +105,16 @@ def __init_actions(self):
self.hide_offline_action.connect("change-state", self.__on_hide_offline)
self.app.add_action(self.hide_offline_action)

def __init_components(self):
path = self._settings.default_location.path if self._settings.storage_locations else None
self.import_button = FirstImportButton(self._set_audiobook_path, path)
self.get_object("welcome_status_page").set_child(self.import_button)

if not self._player.loaded_book:
self.block_ui_buttons(True)

self._importer.add_listener(self._on_importer_event)

def create_action(
self,
name: str,
Expand All @@ -145,16 +130,6 @@ def create_action(

return action

def __init_components(self):
path = self._settings.default_location.path if self._settings.storage_locations else None
self.import_button = FirstImportButton(self._set_audiobook_path, path)
self.get_object("welcome_status_page").set_child(self.import_button)

if not self._player.loaded_book:
self.block_ui_buttons(True)

self._importer.add_listener(self._on_importer_event)

def get_object(self, name):
return self.window_builder.get_object(name)

Expand All @@ -165,60 +140,11 @@ def quit(self, action, parameter):
self.on_close(None)
self.app.quit()

def _get_contributors(self):
authors_file = self.appdata_resource.lookup_data("/com/github/geigi/cozy/authors", Gio.ResourceLookupFlags.NONE)

current_section = ""
result = defaultdict(list)
for line in authors_file.get_data().decode().splitlines():
if line.startswith("#"):
current_section = line[1:].strip().lower()
elif line.startswith("-"):
result[current_section].append(line[1:].strip())

return result

def about(self, *junk):
"""
Show about window.
"""
about = Adw.AboutWindow.new_from_appdata(
"/com/github/geigi/cozy/com.github.geigi.cozy.appdata.xml",
release_notes_version=self.version,
)

contributors = self._get_contributors()
about.set_developers(sorted(contributors["code"]))
about.set_designers(sorted(contributors["design"]))
about.set_artists(sorted(contributors["icon"]))

about.set_license_type(Gtk.License.GPL_3_0)

about.add_acknowledgement_section(
_("Patreon Supporters"),
["Fred Warren", "Gabriel", "Hu Mann", "Josiah", "Oleksii Kriukov"]
)
about.add_acknowledgement_section(
_("m4b chapter support in mutagen"),
("mweinelt",),
)
about.add_acknowledgement_section(
_("Open Source Projects"),
("Lollypop music player https://gitlab.gnome.org/World/lollypop",),
)

# Translators: Replace "translator-credits" with your names, one name per line
about.set_translator_credits(_("translator-credits"))
about.add_legal_section("python-inject", "© 2010 Ivan Korobkov", Gtk.License.APACHE_2_0)
def show_about_window(self, *_):
AboutWindow(self.version).present(self.window)

about.set_transient_for(self.window)
about.present()

def show_prefs(self, *_):
"""
Show preferences window.
"""
PreferencesView().present()
def show_preferences_window(self, *_):
PreferencesWindow().present(self.window)

def play_pause(self, *_):
self._player.play_pause()
Expand Down
19 changes: 16 additions & 3 deletions cozy/ui/media_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
COVER_SIZE = 46


@Gtk.Template.from_resource('/com/github/geigi/cozy/media_controller.ui')
@Gtk.Template.from_resource("/com/github/geigi/cozy/ui/media_controller.ui")
class MediaController(Adw.BreakpointBin):
__gtype_name__ = "MediaController"

Expand Down Expand Up @@ -50,7 +50,18 @@ def __init__(self, main_window_builder: Gtk.Builder):
self.playback_speed_button.set_popover(PlaybackSpeedPopover())
self.timer_button.set_popover(self.sleep_timer)

self._playback_control_view_model: PlaybackControlViewModel = inject.instance(PlaybackControlViewModel)
self.volume_button.set_icons(
[
"audio-volume-muted-symbolic",
"audio-volume-high-symbolic",
"audio-volume-low-symbolic",
"audio-volume-medium-symbolic",
]
)

self._playback_control_view_model: PlaybackControlViewModel = inject.instance(
PlaybackControlViewModel
)
self._artwork_cache: ArtworkCache = inject.instance(ArtworkCache)
self._connect_view_model()
self._connect_widgets()
Expand Down Expand Up @@ -85,7 +96,9 @@ def _connect_widgets(self):
self.cover_img.set_cursor(Gdk.Cursor.new_from_name("pointer"))

def _set_cover_image(self, book: Book):
paintable = self._artwork_cache.get_cover_paintable(book, self.get_scale_factor(), COVER_SIZE)
paintable = self._artwork_cache.get_cover_paintable(
book, self.get_scale_factor(), COVER_SIZE
)
if paintable:
self.cover_img.set_from_paintable(paintable)
else:
Expand Down
Loading
Loading