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

Remove "What's new" popups, and improve the welcome experience #832

Merged
merged 6 commits into from
Feb 16, 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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ See [DEVELOPMENT.md](DEVELOPMENT.md) for detailed instructions and developing Co
- `distro`
- `requests`
- `pytz`
- `packaging`
- `gi-cairo`
- `gst-1.0`
- `file`
Expand Down
19 changes: 0 additions & 19 deletions com.github.geigi.cozy.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,6 @@
}
]
},
{
"name": "python3-packaging",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"packaging\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/05/8e/8de486cbd03baba4deef4142bd643a3e7bbe954a784dc1bb17142572d127/packaging-21.3-py3-none-any.whl",
"sha256": "ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl",
"sha256": "5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"
}
]
},
{
"name": "python3-peewee",
"buildsystem": "simple",
Expand Down
5 changes: 1 addition & 4 deletions cozy/app_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from cozy.ui.main_view import CozyUI
from cozy.ui.media_controller import MediaController
from cozy.ui.search_view import SearchView
from cozy.ui.widgets.whats_new_window import WhatsNewWindow
from cozy.view import View
from cozy.view_model.app_view_model import AppViewModel
from cozy.view_model.book_detail_view_model import BookDetailViewModel
Expand All @@ -50,11 +49,9 @@ def __init__(self, gtk_app, main_window_builder, main_window):

reporter.info("main", "startup")

self.whats_new_window: WhatsNewWindow = WhatsNewWindow()

self.library_view: LibraryView = LibraryView(main_window_builder)
self.app_view: AppView = AppView(main_window_builder)
self.headerbar: Headerbar = Headerbar(main_window_builder)
self.library_view: LibraryView = LibraryView(main_window_builder)
self.book_detail_view: BookDetailView = BookDetailView(main_window_builder)
self.media_controller: MediaController = MediaController(main_window_builder)
self.search_view: SearchView = SearchView(main_window_builder, self.headerbar)
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 @@ -5,7 +5,7 @@
from cozy.view import View

LIBRARY = "main"
EMPTY_STATE = "no_media"
EMPTY_STATE = "welcome"
PREPARING_LIBRARY = "import"
BOOK_DETAIL = "book_overview"

Expand Down
4 changes: 2 additions & 2 deletions cozy/ui/library_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
AUTHOR_PAGE = "author"
RECENT_PAGE = "recent"
MAIN_BOOK_PAGE = "main"
NO_MEDIA_PAGE = "no_media"
WELCOME_PAGE = "welcome"

NO_RECENT_PAGE = "no_recent"
BOOKS_PAGE = "books"
Expand Down Expand Up @@ -112,7 +112,7 @@ def _on_library_view_mode_changed(self):
books_view_page = BOOKS_PAGE

if len(self._view_model.books) < 1:
main_view_page = NO_MEDIA_PAGE
main_view_page = WELCOME_PAGE
visible_child_name = RECENT_PAGE
elif view_mode == LibraryViewMode.CURRENT:
visible_child_name = RECENT_PAGE
Expand Down
38 changes: 14 additions & 24 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
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.settings_view_model import SettingsViewModel
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
from cozy.ui.widgets.first_import_button import FirstImportButton


log = logging.getLogger("ui")

Expand Down Expand Up @@ -104,9 +106,6 @@ def __init_window(self):
self.navigation_view: Adw.NavigationView = self.window_builder.get_object("navigation_view")
self.drop_revealer: Gtk.Revealer = self.window_builder.get_object("drop_revealer")

self.no_media_file_chooser = self.window_builder.get_object("no_media_file_chooser")
self.no_media_file_chooser.connect("clicked", self._open_audiobook_dir_selector)

self.window.present()

def __init_actions(self):
Expand Down Expand Up @@ -147,6 +146,10 @@ 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)

Expand Down Expand Up @@ -239,8 +242,9 @@ def switch_to_playing(self):
Switch the UI state back to playing.
This enables all UI functionality for the user.
"""
if self.navigation_view.props.visible_page != "book_overview" and self.main_stack.props.visible_child_name != "no_media":
if self.navigation_view.props.visible_page != "book_overview" and self.main_stack.props.visible_child_name != "welcome":
self.navigation_view.pop_to_tag("main")

if self._player.loaded_book:
self.block_ui_buttons(False, True)
else:
Expand All @@ -257,23 +261,6 @@ def check_for_tracks(self):
if books().count() < 1:
self.block_ui_buttons(True)

def _open_audiobook_dir_selector(self, __):
path = ""
if len(self._settings.storage_locations) > 0:
path = self._settings.default_location.path

location_chooser = Gtk.FileDialog(title=_("Set Audiobooks Directory"))
location_chooser.select_folder(self.window, None, self._location_chooser_open_callback)

def _location_chooser_open_callback(self, dialog, result):
try:
file = dialog.select_folder_finish(result)
except GLib.GError:
pass
else:
if file is not None:
self._set_audiobook_path(file.get_path())

def scan(self, _, __):
thread = Thread(target=self._importer.scan, name="ScanMediaThread")
thread.start()
Expand Down Expand Up @@ -304,9 +291,12 @@ def _on_drag_data_received(self, widget, value, *_):
thread.start()
return True

def _set_audiobook_path(self, path):
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.props.visible_child_name = "import"
self.scan(None, None)
self.fs_monitor.init_offline_mode()

Expand Down
24 changes: 24 additions & 0 deletions cozy/ui/widgets/first_import_button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from gi.repository import Adw, Gtk, GObject

from .storages import ask_storage_location

from typing import Callable


@Gtk.Template.from_resource('/com/github/geigi/cozy/first_import_button.ui')
class FirstImportButton(Gtk.Button):
__gtype_name__ = "FirstImportButton"

stack: Gtk.Stack = Gtk.Template.Child()
label: Adw.ButtonContent = Gtk.Template.Child()
spinner: Gtk.Spinner = Gtk.Template.Child()

def __init__(self, callback: Callable[[str], None], initial_folder: str) -> None:
super().__init__()

self.connect("clicked", lambda *_: ask_storage_location(callback, initial_folder))

def disable(self) -> None:
self.set_sensitive(False)
self.spinner.set_spinning(True)
self.stack.set_visible_child(self.spinner)
10 changes: 5 additions & 5 deletions cozy/ui/widgets/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cozy.view_model.storages_view_model import StoragesViewModel


def ask_storage_location(callback: Callable[[str], None], initial_folder: str | None = None):
def ask_storage_location(callback: Callable[[str | None], None], initial_folder: str | None = None):
location_chooser = Gtk.FileDialog(title=_("Set Audiobooks Directory"))

if initial_folder:
Expand All @@ -20,8 +20,7 @@ def finish_callback(dialog, result):
except GLib.GError:
pass
else:
if file is not None:
callback(file.get_path())
callback(None if file is None else file.get_path())

location_chooser.select_folder(inject.instance("MainWindow").window, None, finish_callback)

Expand Down Expand Up @@ -53,8 +52,9 @@ def model(self) -> Storage:
def ask_for_new_location(self, *_) -> None:
ask_storage_location(self._on_folder_changed, initial_folder=self._model.path)

def _on_folder_changed(self, new_path: str) -> None:
self.emit("location-changed", new_path)
def _on_folder_changed(self, new_path: str | None) -> None:
if new_path is not None:
self.emit("location-changed", new_path)

def _on_menu_opened(self, *_) -> None:
self.emit("menu-opened")
Expand Down
11 changes: 0 additions & 11 deletions cozy/ui/widgets/welcome.py

This file was deleted.

9 changes: 0 additions & 9 deletions cozy/ui/widgets/whats_new_importer.py

This file was deleted.

11 changes: 0 additions & 11 deletions cozy/ui/widgets/whats_new_library.py

This file was deleted.

12 changes: 0 additions & 12 deletions cozy/ui/widgets/whats_new_m4b.py

This file was deleted.

12 changes: 0 additions & 12 deletions cozy/ui/widgets/whats_new_m4b_chapter.py

This file was deleted.

93 changes: 0 additions & 93 deletions cozy/ui/widgets/whats_new_window.py

This file was deleted.

5 changes: 4 additions & 1 deletion cozy/view_model/storages_view_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def _rebase_storage_location(self, model: Storage, old_path: str) -> None:
name="RebaseStorageLocationThread",
).start()

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

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

Expand Down
Loading
Loading