Skip to content

Commit

Permalink
Merge branch 'master' into ich-hab-scheiße-gebaut
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende authored Feb 3, 2024
2 parents af9ec9f + c2a16ff commit 26fb5bb
Show file tree
Hide file tree
Showing 28 changed files with 669 additions and 619 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/build.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Checks

on:
push:
branches:
- "main"
pull_request:

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
args: --exit-zero
20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Tests

on:
push:
branches:
- "main"
- "master"
pull_request:

jobs:
test:
runs-on: ubuntu-latest
container:
image: ghcr.io/geigi/cozy-ci:main

steps:
- uses: actions/checkout@v4

- name: Run pytest
run: pytest
8 changes: 6 additions & 2 deletions cozy/app_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from cozy.view_model.search_view_model import SearchViewModel
from cozy.view_model.settings_view_model import SettingsViewModel
from cozy.view_model.sleep_timer_view_model import SleepTimerViewModel
from cozy.view_model.storages_view_model import StoragesViewModel


class AppController(metaclass=Singleton):
Expand Down Expand Up @@ -75,7 +76,7 @@ def __init__(self, gtk_app, main_window_builder, main_window):
self.library_view_model.add_listener(self._on_open_view)
self.library_view_model.add_listener(self._on_library_view_event)
self.playback_control_view_model.add_listener(self._on_open_view)
self.headerbar_view_model.add_listener(self._on_open_view)
self.headerbar_view_model.add_listener(self._on_working_event)
self.app_view_model.add_listener(self._on_app_view_event)

self.main_window.add_listener(self._on_main_window_event)
Expand Down Expand Up @@ -108,6 +109,7 @@ def configure_inject(self, binder):
binder.bind_to_constructor(ToastNotifier, lambda: ToastNotifier())
binder.bind_to_constructor(AppViewModel, lambda: AppViewModel())
binder.bind_to_constructor(SettingsViewModel, lambda: SettingsViewModel())
binder.bind_to_constructor(StoragesViewModel, lambda: StoragesViewModel())

def open_author(self, author: str):
self.library_view_model.library_view_mode = LibraryViewMode.AUTHOR
Expand Down Expand Up @@ -149,10 +151,12 @@ def _on_app_view_event(self, event: str, data):
if event == "view":
self.headerbar_view_model.set_view(data)

def _on_main_window_event(self, event: str, data):
def _on_working_event(self, event: str, data) -> None:
if event == "working":
self.book_detail_view_model.lock_ui = data
self.settings_view_model.lock_ui = data

def _on_main_window_event(self, event: str, data):
if event == "open_view":
self._on_open_view(data, None)

Expand Down
24 changes: 14 additions & 10 deletions cozy/model/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ def last_played_book(self) -> Book | None:
try:
return self._db_object.last_played_book
except peewee.DoesNotExist:
log.warning("last_played_book references an non existent object. Setting last_played_book to None.")
reporter.warning("settings_model",
"last_played_book references an non existent object. Setting last_played_book to None.")
log.warning(
"last_played_book references an non existent object. Setting last_played_book to None."
)
reporter.warning(
"settings_model",
"last_played_book references an non existent object. Setting last_played_book to None.",
)

self.last_played_book = None
return None

@last_played_book.setter
def last_played_book(self, new_value):
def last_played_book(self, new_value) -> None:
if new_value:
self._db_object.last_played_book = new_value._db_object
else:
Expand Down Expand Up @@ -67,21 +71,21 @@ def external_storage_locations(self) -> list[Storage]:

return [storage for storage in self._storages if storage.external]

def invalidate(self):
self._storages = []
def invalidate(self) -> None:
self._storages.clear()

def _load_all_storage_locations(self):
self._storages = []
def _load_all_storage_locations(self) -> None:
self.invalidate()

for storage_db_obj in StorageModel.select(StorageModel.id):
try:
self._storages.append(Storage(self._db, storage_db_obj.id))
except InvalidPath:
log.error("Invalid path found in database, skipping: %s", storage_db_obj.path)

self._ensure_default_storage_present()
self._ensure_default_storage_is_present()

def _ensure_default_storage_present(self):
def _ensure_default_storage_is_present(self):
default_storage_present = any(storage.default for storage in self._storages)

if not default_storage_present and self._storages:
Expand Down
14 changes: 7 additions & 7 deletions cozy/model/storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
from pathlib import Path

from peewee import SqliteDatabase

Expand All @@ -17,8 +17,8 @@ def __init__(self, db: SqliteDatabase, db_id: int):
self._get_db_object()

@staticmethod
def new(db: SqliteDatabase):
db_obj = StorageModel.create(path="")
def new(db: SqliteDatabase, path: str):
db_obj = StorageModel.create(path=path)
return Storage(db, db_obj.id)

def _get_db_object(self):
Expand All @@ -33,11 +33,11 @@ def path(self):
return self._db_object.path

@path.setter
def path(self, new_path: str):
if not os.path.isabs(new_path):
def path(self, path: str):
if not Path(path).is_absolute():
raise InvalidPath

self._db_object.path = new_path
self._db_object.path = path
self._db_object.save(only=self._db_object.dirty_fields)

@property
Expand Down Expand Up @@ -68,4 +68,4 @@ def external(self, new_external: bool):
self._db_object.save(only=self._db_object.dirty_fields)

def delete(self):
self._db_object.delete_instance(recursive=True, delete_nullable=False)
self._db_object.delete_instance(recursive=True, delete_nullable=False)
39 changes: 34 additions & 5 deletions cozy/ui/headerbar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import logging

from gi.repository import Adw, Gtk
import gi

from cozy.ext import inject
from cozy.ui.widgets.progress_popover import ProgressPopover
from cozy.view_model.headerbar_view_model import HeaderbarViewModel, HeaderBarState

from gi.repository import Adw, Gtk, GObject

from cozy.ext import inject
from cozy.ui.widgets.progress_popover import ProgressPopover
Expand Down Expand Up @@ -52,6 +58,8 @@ def __init__(self, main_window_builder: Gtk.Builder):
self._connect_view_model()
self._connect_widgets()

self._set_show_sidebar_button_visible()

def _connect_view_model(self):
self._headerbar_view_model.bind_to("state", self._on_state_changed)
self._headerbar_view_model.bind_to("work_progress", self._on_work_progress_changed)
Expand All @@ -62,20 +70,41 @@ def _connect_widgets(self):
self.split_view.connect("notify::show-sidebar", self._on_sidebar_toggle)
self.show_sidebar_button.connect("notify::active", self._on_sidebar_toggle)
self.mobile_view_switcher.connect("notify::reveal", self._on_mobile_view)
self.sort_stack.connect("notify::visible-child", self._on_sort_stack_changed)
self.sort_stack.connect("notify::visible-child", self._set_show_sidebar_button_visible)

self.mobile_view_switcher.bind_property(
"reveal", self.split_view, "collapsed", GObject.BindingFlags.SYNC_CREATE
)

def _on_sort_stack_changed(self, widget, _):
page = widget.props.visible_child_name
def _on_mobile(self) -> bool:
return self.mobile_view_switcher.props.reveal

def _set_show_sidebar_button_visible(self, *_):
page = self.sort_stack.props.visible_child_name

if not self._on_mobile():
self.show_sidebar_button.set_visible(False)
self.split_view.set_collapsed(False)
self.split_view.set_show_sidebar(page != "recent")
return

if self.mobile_view_switcher.props.reveal:
self.show_sidebar_button.set_visible(page != "recent")
else:
self.show_sidebar_button.set_visible(False)

self.show_sidebar_button.set_visible(page != "recent")
self.search_button.set_active(False)

def _on_mobile_view(self, widget, _):
page = self.sort_stack.props.visible_child_name

if widget.props.reveal:
self.headerbar.set_title_widget(Adw.WindowTitle(title="Cozy"))
else:
self.headerbar.set_title_widget(self.view_switcher)

self._set_show_sidebar_button_visible()

def _on_sidebar_toggle(self, widget, param):
show_sidebar = widget.get_property(param.name)

Expand Down
8 changes: 5 additions & 3 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from cozy.media.importer import Importer, ScanStatus
from cozy.media.player import Player
from cozy.model.settings import Settings as SettingsModel
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.view_model.settings_view_model import SettingsViewModel
Expand All @@ -37,7 +39,7 @@ class CozyUI(EventSender, metaclass=Singleton):
_settings: SettingsModel = inject.attr(SettingsModel)
_files: Files = inject.attr(Files)
_player: Player = inject.attr(Player)
_settings_view_model: SettingsViewModel = inject.attr(SettingsViewModel)
_storages_view_model: StoragesViewModel = inject.attr(StoragesViewModel)

def __init__(self, pkgdatadir, app, version):
super().__init__()
Expand Down Expand Up @@ -243,9 +245,9 @@ def switch_to_playing(self):
self.block_ui_buttons(False, True)
else:
# we want to only block the player controls
# TODO: rework. this is messy
self.block_ui_buttons(False, True)
self.block_ui_buttons(True, False)
self.emit_event_main_thread("working", False)

def check_for_tracks(self):
"""
Expand Down Expand Up @@ -303,7 +305,7 @@ def _on_drag_data_received(self, widget, value, *_):
return True

def _set_audiobook_path(self, path):
self._settings_view_model.add_first_storage_location(path)
self._storages_view_model.add_first_storage_location(path)
self.main_stack.props.visible_child_name = "import"
self.scan(None, None)
self.fs_monitor.init_offline_mode()
Expand Down
12 changes: 3 additions & 9 deletions cozy/ui/media_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class MediaController(Adw.BreakpointBin):
def __init__(self, main_window_builder: Gtk.Builder):
super().__init__()

media_control_box: Gtk.Box = main_window_builder.get_object("media_control_box")
media_control_box.append(self)
self.container_bar: Gtk.Revealer = main_window_builder.get_object("media_control_box")
self.container_bar.set_child(self)

self.seek_bar = SeekBar()
self.seek_bar_container.append(self.seek_bar)
Expand Down Expand Up @@ -127,13 +127,7 @@ def _on_length_changed(self):

def _on_lock_ui_changed(self):
sensitive = not self._playback_control_view_model.lock_ui
self.seek_bar.sensitive = sensitive
self.prev_button.set_sensitive(sensitive)
self.next_button.set_sensitive(sensitive)
self.play_button.set_sensitive(sensitive)
self.volume_button.set_sensitive(sensitive)
self.playback_speed_button.set_sensitive(sensitive)
self.timer_button.set_sensitive(sensitive)
self.container_bar.set_reveal_child(sensitive)

def _on_volume_changed(self):
self.volume_button.set_value(self._playback_control_view_model.volume)
Expand Down
Loading

0 comments on commit 26fb5bb

Please sign in to comment.