Skip to content

Commit

Permalink
Merge branch 'master' into devel-update
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Dec 3, 2023
2 parents 6baaf18 + e6f0e9f commit 5c9e4d2
Show file tree
Hide file tree
Showing 47 changed files with 2,737 additions and 607 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,3 @@ jobs:
- name: Test with pytest
run: |
pytest
- name: Install Cozy
run: |
meson --prefix=/usr ./build
ninja -C build install
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ To nedrichards for the Flatpak.
## Help me translate cozy!
Cozy is on <a href="https://www.transifex.com/geigi/cozy/">Transifex</a>, where anyone can contribute and translate. Can't find your language in the list? Let me know!

If you like this project, consider supporting me on <a href="https://www.patreon.com/bePatron?u=8147127">Patreon</a> :)
If you like this project, consider supporting me on <a href="https://www.patreon.com/geigi">Patreon</a> :)

----
[![Maintainability](https://api.codeclimate.com/v1/badges/fde8cbdff23033adaca2/maintainability)](https://codeclimate.com/github/geigi/cozy/maintainability)
4 changes: 2 additions & 2 deletions cozy/app_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from cozy.ui.app_view import AppView
from cozy.ui.book_detail_view import BookDetailView
from cozy.ui.headerbar import Headerbar
from cozy.ui.info_banner import InfoBanner
from cozy.ui.toaster import ToastNotifier
from cozy.ui.library_view import LibraryView
from cozy.ui.main_view import CozyUI
from cozy.ui.media_controller import MediaController
Expand Down Expand Up @@ -105,7 +105,7 @@ def configure_inject(self, binder):
binder.bind_to_constructor(SleepTimerViewModel, lambda: SleepTimerViewModel())
binder.bind_to_constructor(GstPlayer, lambda: GstPlayer())
binder.bind_to_constructor(PowerManager, lambda: PowerManager())
binder.bind_to_constructor(InfoBanner, lambda: InfoBanner())
binder.bind_to_constructor(ToastNotifier, lambda: ToastNotifier())
binder.bind_to_constructor(AppViewModel, lambda: AppViewModel())
binder.bind_to_constructor(SettingsViewModel, lambda: SettingsViewModel())

Expand Down
22 changes: 13 additions & 9 deletions cozy/application.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import gettext
import locale
import logging
import os
Expand All @@ -15,8 +16,6 @@
from cozy.ui.widgets.filter_list_box import FilterListBox
from cozy.ui.widgets.seek_bar import SeekBar

gi.require_version('Adw', '1')

from gi.repository import Gtk, GLib, Adw

from cozy.app_controller import AppController
Expand Down Expand Up @@ -57,15 +56,15 @@ def run_with_except_hook(*args2, **kwargs2):
threading.Thread.__init__ = init


class Application(Gtk.Application):
class Application(Adw.Application):
ui: CozyUI
app_controller: AppController

def __init__(self, localedir: str, pkgdatadir: str):
self.localedir = localedir
self.pkgdatadir = pkgdatadir

Gtk.Application.__init__(self, application_id='com.github.geigi.cozy')
super().__init__(application_id='com.github.geigi.cozy')
self.init_custom_widgets()

GLib.setenv("PULSE_PROP_media.role", "music", True)
Expand All @@ -75,19 +74,24 @@ def __init__(self, localedir: str, pkgdatadir: str):
sys.excepthook = self.handle_exception
setup_thread_excepthook()

import gettext
# We need to call `locale.*textdomain` to get the strings in UI files translated
locale.bindtextdomain('com.github.geigi.cozy', localedir)
locale.textdomain('com.github.geigi.cozy')

# But also `gettext.*textdomain`, to make `_("foo")` in Python work as well
gettext.bindtextdomain('com.github.geigi.cozy', localedir)
gettext.textdomain('com.github.geigi.cozy')

gettext.install('com.github.geigi.cozy', localedir)

def do_startup(self):
log.info(distro.linux_distribution(full_distribution_name=False))
log.info("Starting up cozy " + __version__)
log.info(f"Starting up cozy {__version__}")
log.info(f"libadwaita version: {Adw._version}")

self.ui = CozyUI(self.pkgdatadir, self, __version__)
Adw.Application.do_startup(self)
init_db()
Gtk.Application.do_startup(self)
Adw.init()
log.info("libadwaita version: {}".format(Adw._version))
self.ui.startup()

def do_activate(self):
Expand Down
15 changes: 6 additions & 9 deletions cozy/control/filesystem_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def init_offline_mode(self):
# go through all audiobook locations and test if they can be found in the mounts list

for storage in self._settings.external_storage_locations:
online = False
if any(mount.get_root().get_path() in storage.path for mount in mounts):
online = True
online = any(
mount.get_root().get_path() and mount.get_root().get_path() in storage.path
for mount in mounts
)
self.external_storage.append(ExternalStorage(storage=storage, online=online))

def close(self):
Expand All @@ -62,18 +63,14 @@ def close(self):

def get_book_online(self, book: Book):
try:
result = next(
return next(
(storage.online for storage in self.external_storage if storage.storage.path in book.chapters[0].file),
True)
return result
except IndexError:
return True

def is_track_online(self, track):
"""
"""
result = next((storage.online for storage in self.external_storage if storage.storage.path in track.file), True)
return (result)
return next((storage.online for storage in self.external_storage if storage.storage.path in track.file), True)

def get_offline_storages(self):
return [i.storage.path for i in self.external_storage if not i.online]
Expand Down
10 changes: 8 additions & 2 deletions cozy/control/mpris.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
log = logging.getLogger("offline_cache")


class UnsupportedProperty(Exception):
pass


class Server:
def __init__(self, con, path):
method_outargs = {}
Expand Down Expand Up @@ -84,13 +88,15 @@ def on_method_call(self,
invocation.return_value(variant)
else:
invocation.return_value(None)
except UnsupportedProperty:
invocation.return_dbus_error("{}.Error.NotSupported".format(interface_name), "Unsupported property")
except Exception as e:
log.error(e)
reporter.exception("mpris", e)
reporter.error("mpris", "MPRIS method call failed with method name: {}".format(method_name))
if out_args:
reporter.error("mpris", "MPRIS method call failed with out_args: {}".format(out_args))
invocation.return_value(None)
invocation.return_dbus_error("{}.Error.Failed".format(interface_name), "Internal exception occurred")


class MPRIS(Server):
Expand Down Expand Up @@ -270,7 +276,7 @@ def Get(self, interface, property_name):
return GLib.Variant("d", self._player.volume)
else:
reporter.warning("mpris", "MPRIS required an unknown information: {}".format(property_name))
return None
raise UnsupportedProperty

def GetAll(self, interface):
ret = {}
Expand Down
30 changes: 13 additions & 17 deletions cozy/media/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
from cozy.media.importer import Importer
from cozy.model.settings import Settings
from cozy.report import reporter
from cozy.ui.info_banner import InfoBanner
from cozy.ui.toaster import ToastNotifier

log = logging.getLogger("files")


class Files(EventSender):
_settings = inject.attr(Settings)
_importer = inject.attr(Importer)
_info_bar: InfoBanner = inject.attr(InfoBanner)
_toast: ToastNotifier = inject.attr(ToastNotifier)

_file_count = 0
_file_progess = 0
Expand All @@ -29,23 +29,21 @@ def __init__(self):
def copy(self, selection):
log.info("Start of copying files")
self.emit_event_main_thread("start-copy", None)
uris = selection.get_uris()

paths = [f.get_path() for f in selection]
storage_location = self._settings.default_location.path

self._file_count = 0
self._file_progess = 0

self._count_all_files(uris)
self._copy_all(uris, storage_location)
self._count_all_files(paths)
self._copy_all(paths, storage_location)

log.info("Copying of files finished")
self._importer.scan()

def _copy_all(self, sources, destination: str):
for uri in sources:
parsed_path = urllib.parse.urlparse(uri)
path = urllib.parse.unquote(parsed_path.path)

for path in sources:
if os.path.isdir(path):
self._copy_directory(path, destination)
else:
Expand All @@ -66,11 +64,11 @@ def _copy_file(self, source_path: str, dest_path: str):
if e.code == Gio.IOErrorEnum.CANCELLED:
pass
elif e.code == Gio.IOErrorEnum.READ_ONLY:
self._info_bar.show(_("Cannot copy: Audiobook directory is read only"))
self._toast.show(_("Cannot copy: Audiobook directory is read only"))
elif e.code == Gio.IOErrorEnum.NO_SPACE:
self._info_bar.show(_("Cannot copy: Disk is full"))
self._toast.show(_("Cannot copy: Disk is full"))
elif e.code == Gio.IOErrorEnum.PERMISSION_DENIED:
self._info_bar.show(_("Cannot copy: Permission denied"))
self._toast.show(_("Cannot copy: Permission denied"))
else:
reporter.exception("files", e)

Expand All @@ -86,18 +84,16 @@ def _copy_directory(self, path, destination):
Path(destination_dir).mkdir(parents=True, exist_ok=True)
except PermissionError as e:
log.error(e)
self._info_bar.show(_("Cannot copy: Permission denied"))
self._toast.show(_("Cannot copy: Permission denied"))
return

for file in filenames:
source = os.path.join(dirpath, file)
file_copy_destination = os.path.join(destination, dirname, file)
self._copy_file(source, file_copy_destination)

def _count_all_files(self, uris):
for uri in uris:
parsed_path = urllib.parse.urlparse(uri)
path = urllib.parse.unquote(parsed_path.path)
def _count_all_files(self, paths: list[str]) -> None:
for path in paths:
if os.path.isdir(path):
self._file_count += self._count_files_in_folder(path)
else:
Expand Down
3 changes: 0 additions & 3 deletions cozy/media/gst_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
from enum import Enum, auto
from typing import Optional

import gi

from cozy.architecture.event_sender import EventSender
from cozy.report import reporter

gi.require_version('Gst', '1.0')
from gi.repository import Gst

log = logging.getLogger("gst_player")
Expand Down
6 changes: 3 additions & 3 deletions cozy/media/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from cozy.model.library import Library
from cozy.model.settings import Settings
from cozy.report import reporter
from cozy.ui.info_banner import InfoBanner
from cozy.ui.toaster import ToastNotifier

log = logging.getLogger("importer")

Expand Down Expand Up @@ -56,7 +56,7 @@ class Importer(EventSender):
_settings = inject.attr(Settings)
_library = inject.attr(Library)
_database_importer = inject.attr(DatabaseImporter)
_info_bar: InfoBanner = inject.attr(InfoBanner)
_toast: ToastNotifier = inject.attr(ToastNotifier)

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -118,7 +118,7 @@ def _execute_import(self, files_to_scan: List[str]) -> (Set[str], Set[str]):
log.error("Error while inserting new tracks to the database")
reporter.exception("importer", e)
log.error(traceback.format_exc())
self._info_bar.show("{}: {}".format(_("Error while importing new files"), str(e.__class__)))
self._toast.show("{}: {}".format(_("Error while importing new files"), str(e.__class__)))

if self._progress >= self._files_count:
break
Expand Down
4 changes: 0 additions & 4 deletions cozy/media/media_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@

from cozy.architecture.event_sender import EventSender

import gi

from cozy.media.media_file import MediaFile
from cozy.media.tag_reader import TagReader

gi.require_version('Gst', '1.0')
gi.require_version('GstPbutils', '1.0')
from gi.repository import Gst, GstPbutils

log = logging.getLogger("media_detector")
Expand Down
7 changes: 4 additions & 3 deletions cozy/media/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from cozy.report import reporter
from cozy.tools import IntervalTimer
from cozy.ui.file_not_found_dialog import FileNotFoundDialog
from cozy.ui.info_banner import InfoBanner
from cozy.ui.toaster import ToastNotifier

log = logging.getLogger("mediaplayer")

Expand All @@ -30,7 +30,7 @@ class Player(EventSender):
_library: Library = inject.attr(Library)
_app_settings: ApplicationSettings = inject.attr(ApplicationSettings)
_offline_cache: OfflineCache = inject.attr(OfflineCache)
_info_bar: InfoBanner = inject.attr(InfoBanner)
_toast: ToastNotifier = inject.attr(ToastNotifier)
_importer: Importer = inject.attr(Importer)

_gst_player: GstPlayer = inject.attr(GstPlayer)
Expand Down Expand Up @@ -285,6 +285,7 @@ def _next_chapter(self):
if not self._book:
log.error("Cannot play next chapter because no book reference is stored.")
reporter.error("player", "Cannot play next chapter because no book reference is stored.")
return

index_current_chapter = self._book.chapters.index(self._book.current_chapter)

Expand Down Expand Up @@ -327,7 +328,7 @@ def _on_gst_player_event(self, event: str, message):

def _handle_gst_error(self, error: GLib.Error):
if error.code != Gst.ResourceError.BUSY:
self._info_bar.show(error.message)
self._toast.show(error.message)

if error.code == Gst.ResourceError.OPEN_READ or Gst.ResourceError.READ:
self._stop_playback()
Expand Down
3 changes: 0 additions & 3 deletions cozy/media/tag_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
from typing import List
from urllib.parse import unquote, urlparse

import gi
import mutagen
from mutagen.mp4 import MP4

gi.require_version('Gst', '1.0')
gi.require_version('GstPbutils', '1.0')
from gi.repository import GstPbutils, Gst, GLib

from cozy.media.chapter import Chapter
Expand Down
4 changes: 0 additions & 4 deletions cozy/report/report_to_loki.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
from peewee import __version__ as PeeweeVersion
from mutagen import version_string as MutagenVersion

import gi

gi.require_version('Gtk', '4.0')

from gi.repository import Gtk

URL = 'https://errors.cozy.sh:3100/api/prom/push'
Expand Down
2 changes: 1 addition & 1 deletion cozy/ui/app_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, builder: Gtk.Builder):

def _get_ui_elements(self):
self._main_stack: Gtk.Stack = self._builder.get_object("main_stack")
self._navigation_view: Adw.Leaflet = self._builder.get_object("navigation_view")
self._navigation_view: Adw.NavigationView = self._builder.get_object("navigation_view")

def _connect_ui_elements(self):
self._main_stack.connect("notify::visible-child", self._update_view_model_view)
Expand Down
Loading

0 comments on commit 5c9e4d2

Please sign in to comment.