Skip to content

Commit

Permalink
Hope I'm not doing anything stupid with the database
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Dec 3, 2024
1 parent daa9576 commit 59c7fd5
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 82 deletions.
10 changes: 0 additions & 10 deletions cozy/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from cozy.app_controller import AppController
from cozy.control.db import init_db
from cozy.control.mpris import MPRIS
from cozy.db.settings import Settings
from cozy.db.storage import Storage
from cozy.report import reporter
from cozy.ui.main_view import CozyUI
from cozy.ui.widgets.filter_list_box import FilterListBox
Expand Down Expand Up @@ -52,14 +50,6 @@ def do_activate(self):
self.app_controller = AppController(self, main_window_builder, self.ui)

self.ui.activate(self.app_controller.library_view)

if Settings.get().first_start:
Settings.update(first_start=False).execute()

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)

if platform.system().lower() == "linux":
Expand Down
14 changes: 8 additions & 6 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from cozy.ui.book_detail_view import BookDetailView
from cozy.ui.library_view import LibraryView
from cozy.ui.preferences_window import PreferencesWindow
from cozy.ui.widgets.first_import_button import FirstImportButton
from cozy.ui.widgets.welcome_dialog import WelcomeDialog
from cozy.view_model.playback_control_view_model import PlaybackControlViewModel
from cozy.view_model.playback_speed_view_model import PlaybackSpeedViewModel
from cozy.view_model.storages_view_model import StoragesViewModel
from cozy.ui.widgets.storages import ask_storage_location

log = logging.getLogger("ui")

Expand Down Expand Up @@ -124,15 +124,17 @@ def set_hotkeys_enabled(self, enabled: bool) -> None:
action.set_enabled(enabled)

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)
self.get_object("first_import_button").connect("clicked", self._on_choose_location_clicked)

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

self._importer.add_listener(self._on_importer_event)

def _on_choose_location_clicked(self, _):
initial_path = self._settings.default_location.path if self._settings.storage_locations else None
ask_storage_location(self._set_audiobook_path, initial_path)

def create_action(
self,
name: str,
Expand Down Expand Up @@ -273,8 +275,8 @@ def _set_audiobook_path(self, path: str | None) -> None:
if path is None:
return

self.import_button.disable()
self._storages_view_model.add_first_storage_location(path)
self.main_stack.set_visible_child_name("import")
self._storages_view_model.add_storage_location(path, default=True)
self.scan(None, None)
self.fs_monitor.init_offline_mode()

Expand Down
23 changes: 0 additions & 23 deletions cozy/ui/widgets/first_import_button.py

This file was deleted.

20 changes: 16 additions & 4 deletions cozy/ui/widgets/welcome_dialog.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pathlib import Path
import inject
from gi.repository import Adw, Gtk

from cozy.view_model.playback_speed_view_model import PlaybackSpeedViewModel
from cozy.ui.widgets.error_reporting import ErrorReporting
from cozy.settings import ApplicationSettings
from cozy.view_model.storages_view_model import StoragesViewModel

from cozy.ui.widgets.storages import ask_storage_location

Expand All @@ -13,15 +15,18 @@ class WelcomeDialog(Adw.Dialog):
__gtype_name__ = "WelcomeDialog"

app_settings: ApplicationSettings = inject.attr(ApplicationSettings)
_storages_view_model: StoragesViewModel = inject.attr(StoragesViewModel)

carousel: Adw.Carousel = Gtk.Template.Child()
welcome_page: Adw.StatusPage = Gtk.Template.Child()
reporting_page: Gtk.Box = Gtk.Template.Child()
locations_page: Adw.StatusPage = Gtk.Template.Child()
create_directory_switch: Adw.SwitchRow = Gtk.Template.Child()

def __init__(self):
super().__init__()
self.order = [self.welcome_page, self.reporting_page, self.locations_page]
self._path = None
self._order = [self.welcome_page, self.reporting_page, self.locations_page]

@Gtk.Template.Callback()
def deny_reporting(self, _):
Expand All @@ -33,12 +38,19 @@ def accept_reporting(self, _):
self.advance()

@Gtk.Template.Callback()
def done(self, _):
def done(self, obj):
self.close()

inject.instance("MainWindow")._set_audiobook_path(self._path)

if self.create_directory_switch.props.active:
audiobooks_dir = Path.home() / _("Audiobooks")
audiobooks_dir.mkdir(exist_ok=True)
self._storages_view_model.add_storage_location(str(audiobooks_dir))

@Gtk.Template.Callback()
def choose_directory(self, _):
ask_storage_location(inject.instance("MainWindow")._set_audiobook_path, None)
ask_storage_location(lambda path: setattr(self, "_path", path), None)

def advance(self):
self.carousel.scroll_to(self.order[int(self.carousel.get_position()) + 1], True)
self.carousel.scroll_to(self._order[int(self.carousel.get_position()) + 1], True)
12 changes: 2 additions & 10 deletions cozy/view_model/storages_view_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,19 @@ def _rebase_storage_location(self, model: Storage, old_path: str) -> None:
name="RebaseStorageLocationThread",
).start()

def add_storage_location(self, path: str | None) -> None:
def add_storage_location(self, path: str | None, default: bool = False) -> None:
if path is None:
return

model = Storage.new(self._db, path)
model.default = default
model.external = self._fs_monitor.is_external(path)

self._model.invalidate()
self._notify("storage_locations")

self._scan_new_storage(model)

def add_first_storage_location(self, path: str) -> None:
storage = self.storages[0]
storage.path = path
storage.external = self._fs_monitor.is_external(path)
assert storage.default

self._model.invalidate()
self._notify("storage_locations")

def change_storage_location(self, model: Storage, new_path: str) -> None:
old_path = model.path
model.path = new_path
Expand Down
1 change: 0 additions & 1 deletion data/gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<file preprocess="xml-stripblanks">ui/book_detail.ui</file>
<file preprocess="xml-stripblanks">ui/chapter_element.ui</file>
<file preprocess="xml-stripblanks">ui/error_reporting.ui</file>
<file preprocess="xml-stripblanks">ui/first_import_button.ui</file>
<file preprocess="xml-stripblanks">ui/headerbar.ui</file>
<file preprocess="xml-stripblanks">ui/main_window.ui</file>
<file preprocess="xml-stripblanks">ui/media_controller.ui</file>
Expand Down
23 changes: 0 additions & 23 deletions data/ui/first_import_button.blp

This file was deleted.

16 changes: 14 additions & 2 deletions data/ui/main_window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ Adw.ApplicationWindow app_window {
show-title: false;
}

content: Adw.StatusPage {
icon-name: 'com.github.geigi.cozy';
content: Adw.StatusPage import_status_page {
paintable: Adw.SpinnerPaintable {
widget: import_status_page;
};
title: _("Importing");
description: _("Stay tuned while Cozy is preparing your library…");
};
Expand All @@ -237,6 +239,16 @@ Adw.ApplicationWindow app_window {
icon-name: 'com.github.geigi.cozy';
title: _("Let's Get Cozy");
description: _("Select a folder, or drop audiobooks here to add them to your library");
child: Button first_import_button {
halign: center;
styles ["pill", "suggested-action"]

Adw.ButtonContent content {
halign: center;
label: _("Select Folder");
icon-name: 'folder-open-symbolic';
}
};
};
};
}
Expand Down
1 change: 0 additions & 1 deletion data/ui/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ blueprints = custom_target('blueprints',
'book_detail.blp',
'chapter_element.blp',
'error_reporting.blp',
'first_import_button.blp',
'headerbar.blp',
'main_window.blp',
'media_controller.blp',
Expand Down
5 changes: 3 additions & 2 deletions data/ui/welcome_dialog.blp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ template $WelcomeDialog: Adw.Dialog {
spacing: 18;

Adw.PreferencesGroup {
Adw.SwitchRow {
Adw.SwitchRow create_directory_switch {
title: _("Create Default Audiobooks Directory");
subtitle: _("This will create a dedicated directory for audiobooks in your home directory");
active: true;
}

Adw.ActionRow {
Expand All @@ -79,8 +80,8 @@ template $WelcomeDialog: Adw.Dialog {
}

Button {
label: _("Done");
halign: center;
label: _("Done");

styles ["pill", "suggested-action"]

Expand Down

0 comments on commit 59c7fd5

Please sign in to comment.