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

Search UI overhaul #807

Merged
merged 23 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ef311e5
Move search to main view instead of the popover
rdbende Dec 2, 2023
ad6c5c6
Simplify `split_strings_to_set` function
rdbende Dec 2, 2023
79427eb
Forgot to add these files
rdbende Dec 2, 2023
33944e4
Merge branch 'master' into search-page
rdbende Dec 3, 2023
3e70c78
Display result box only after it's been populated
rdbende Dec 3, 2023
4e9e56d
Remove row_type parameter from _populate_listbox method
rdbende Dec 4, 2023
1bc1027
Remove old code
rdbende Dec 9, 2023
969515a
invert ifs
rdbende Dec 9, 2023
eed3e55
Annotations
rdbende Dec 9, 2023
22852e7
Format files
rdbende Dec 9, 2023
86d27e8
Disable play pause action while searching
rdbende Dec 10, 2023
657e159
Add Ctrl+f as search action accelerator
rdbende Dec 10, 2023
0aec725
Use <primary> instead of <Control>
rdbende Dec 10, 2023
1c390be
nice try, but I obviously messed up everything I could
rdbende Dec 10, 2023
7f17801
Merge remote-tracking branch 'geigi/master' into search-page
rdbende Jan 4, 2024
f2062a2
Accindental empty newline whoopsie
rdbende Jan 4, 2024
f4bf991
Update cozy/ui/widgets/search_results.py
rdbende Jan 5, 2024
664b1ce
Update to new symbolic icon
rdbende Jan 6, 2024
93d695a
Refactor query of online books
rdbende Jan 6, 2024
fb1c7a2
Search thread doesn't need to be named
rdbende Jan 6, 2024
016bfea
Merge branch 'master' of github.com:geigi/cozy into search-page
rdbende Jan 6, 2024
5cd1ccf
We don't even need an event anymore
rdbende Jan 6, 2024
8b4c597
Don't return a new set when we're showing every books anyway
rdbende Jan 6, 2024
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
15 changes: 9 additions & 6 deletions cozy/app_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def __init__(self, gtk_app, main_window_builder, main_window):

self.whats_new_window: WhatsNewWindow = WhatsNewWindow()

self.library_view: LibraryView = LibraryView(main_window_builder)
self.app_view: AppView = AppView(main_window_builder)
self.search_view: SearchView = SearchView()
self.book_detail_view: BookDetailView = BookDetailView(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)

self.library_view_model = inject.instance(LibraryViewModel)
self.app_view_model = inject.instance(AppViewModel)
Expand All @@ -68,7 +68,7 @@ def __init__(self, gtk_app, main_window_builder, main_window):
self.settings_view_model = inject.instance(SettingsViewModel)
self.player = inject.instance(Player)

self._connect_popovers()
self._connect_search_button()

self.search_view_model.add_listener(self._on_open_view)
self.book_detail_view_model.add_listener(self._on_open_view)
Expand Down Expand Up @@ -125,8 +125,11 @@ def open_library(self):
self.library_view_model.open_library()
self.app_view_model.view = View.LIBRARY_FILTER

def _connect_popovers(self):
self.headerbar.search_button.set_popover(self.search_view.popover)
def _connect_search_button(self):
self.headerbar.search_button.connect(
"notify::active",
self.search_view.on_state_changed
)

def _on_open_view(self, event, data):
if event == OpenView.AUTHOR:
Expand Down
15 changes: 2 additions & 13 deletions cozy/extensions/set.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import re
from typing import Set


def split_strings_to_set(set_to_split: Set[str]):
finished = set()
for entry in set_to_split:
results = re.split(",|;|/|&", entry)
results = {
entry.strip()
for entry in results
}

finished.update(results)

return finished
def split_strings_to_set(set_to_split: set[str]) -> set[str]:
return {entry.strip() for item in set_to_split for entry in re.split(",|;|/|&", item)}
22 changes: 4 additions & 18 deletions cozy/ui/delete_book_view.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from gi.repository import Adw, Gtk

from cozy.ext import inject
from cozy.control.artwork_cache import ArtworkCache
from cozy.model.book import Book
from cozy.ui.widgets.book_row import BookRow


class DeleteBookView(Adw.MessageDialog):
main_window = inject.attr("MainWindow")
artwork_cache: ArtworkCache = inject.attr(ArtworkCache)

def __init__(self, callback, book):
def __init__(self, callback, book: Book):
super().__init__(
heading=_("Delete Audiobook?"),
body=_("The audiobook will be removed from your disk and from Cozy's library."),
Expand All @@ -22,22 +22,8 @@ def __init__(self, callback, book):
self.add_response("delete", _("Remove Audiobook"))
self.set_response_appearance("delete", Adw.ResponseAppearance.DESTRUCTIVE)

book_row = Adw.ActionRow(
title=book.name,
subtitle=book.author,
selectable=False,
use_markup=False,
)
album_art = Gtk.Picture(margin_top=6, margin_bottom=6)

paintable = self.artwork_cache.get_cover_paintable(book, 1, 48)
if paintable:
album_art.set_paintable(paintable)
book_row.add_prefix(album_art)

list_box = Gtk.ListBox(margin_top=12, css_classes=["boxed-list"])
list_box.append(book_row)
list_box.append(BookRow(book))
self.set_extra_child(list_box)

self.connect("response", callback, book)

23 changes: 14 additions & 9 deletions cozy/ui/headerbar.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import logging

import gi
from gi.repository import Adw, Gtk

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
from cozy.view_model.headerbar_view_model import HeaderBarState, HeaderbarViewModel

log = logging.getLogger("Headerbar")

COVER_SIZE = 45


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

headerbar: Adw.HeaderBar = Gtk.Template.Child()

search_bar: Gtk.SearchBar = Gtk.Template.Child()
search_entry: Gtk.SearchEntry = Gtk.Template.Child()

show_sidebar_button: Gtk.ToggleButton = Gtk.Template.Child()
search_button: Gtk.MenuButton = Gtk.Template.Child()
menu_button: Gtk.MenuButton = Gtk.Template.Child()
Expand All @@ -34,7 +33,9 @@ def __init__(self, main_window_builder: Gtk.Builder):
self.header_container: Adw.ToolbarView = main_window_builder.get_object("header_container")
self.header_container.add_top_bar(self)

self.mobile_view_switcher: Adw.ViewSwitcherBar = main_window_builder.get_object("mobile_view_switcher")
self.mobile_view_switcher: Adw.ViewSwitcherBar = main_window_builder.get_object(
"mobile_view_switcher"
)
self.split_view: Adw.OverlaySplitView = main_window_builder.get_object("split_view")

self.sort_stack: Adw.ViewStack = main_window_builder.get_object("sort_stack")
Expand All @@ -44,6 +45,9 @@ def __init__(self, main_window_builder: Gtk.Builder):
self.progress_popover = ProgressPopover()
self.progress_menu_button.set_popover(self.progress_popover)

self.search_bar.connect_entry(self.search_entry)
self.search_bar.set_key_capture_widget(self.header_container)

self._headerbar_view_model: HeaderbarViewModel = inject.instance(HeaderbarViewModel)
self._connect_view_model()
self._connect_widgets()
Expand All @@ -64,6 +68,7 @@ def _on_sort_stack_changed(self, widget, _):
page = widget.props.visible_child_name

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

def _on_mobile_view(self, widget, _):
if widget.props.reveal:
Expand Down
64 changes: 28 additions & 36 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging
import os
import webbrowser
from threading import Thread
from collections import defaultdict
from threading import Thread
from typing import Callable

from gi.repository import Adw, Gtk, Gio, Gdk, GLib, GObject
from gi.repository import Adw, Gdk, Gio, GLib, Gtk

import cozy.control.filesystem_monitor as fs_monitor
import cozy.ext.inject as inject
Expand All @@ -13,15 +13,13 @@
from cozy.architecture.event_sender import EventSender
from cozy.architecture.singleton import Singleton
from cozy.control.db import books, close_db
from cozy.db.storage import Storage
from cozy.media.files import Files
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.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

log = logging.getLogger("ui")

Expand Down Expand Up @@ -126,39 +124,33 @@ def __init_actions(self):
self.app.add_action(about_action)
self.app.set_accels_for_action("app.about", ["F1"])

quit_action = Gio.SimpleAction.new("quit", None)
quit_action.connect("activate", self.quit)
self.app.add_action(quit_action)
self.app.set_accels_for_action(
"app.quit", ["<Control>q", "<Control>w"])

pref_action = Gio.SimpleAction.new("prefs", None)
pref_action.connect("activate", self.show_prefs)
self.app.add_action(pref_action)
self.app.set_accels_for_action("app.prefs", ["<Control>comma"])

self.scan_action = Gio.SimpleAction.new("scan", None)
self.scan_action.connect("activate", self.scan)
self.app.add_action(self.scan_action)

self.play_pause_action = Gio.SimpleAction.new("play_pause", None)
self.play_pause_action.connect("activate", self.play_pause)
self.app.add_action(self.play_pause_action)
self.app.set_accels_for_action("app.play_pause", ["space"])

# NavigationView.pop-on-escape doesn't work in some cases, so this is a hack
back_action = Gio.SimpleAction.new("back", None)
back_action.connect("activate", lambda *_: self.navigation_view.pop())
self.app.add_action(back_action)
self.app.set_accels_for_action("app.back", ["Escape"])

self.hide_offline_action = Gio.SimpleAction.new_stateful("hide_offline",
None,
GLib.Variant.new_boolean(
self.application_settings.hide_offline))
self.create_action("about", self.about)
self.create_action("quit", self.quit, ["<primary>q", "<primary>w"])
self.create_action("prefs", self.show_prefs, ["<primary>comma"])
self.create_action("scan", self.scan)
self.play_pause_action = self.create_action("play_pause", self.play_pause, ["space"])

self.hide_offline_action = Gio.SimpleAction.new_stateful(
"hide_offline", None, GLib.Variant.new_boolean(self.application_settings.hide_offline)
)
self.hide_offline_action.connect("change-state", self.__on_hide_offline)
self.app.add_action(self.hide_offline_action)

def create_action(
self,
name: str,
callback: Callable[[Gio.SimpleAction, None], None],
shortcuts: list[str] | None = None,
) -> Gio.SimpleAction:
action = Gio.SimpleAction.new(name, None)
action.connect("activate", callback)
self.app.add_action(action)

if shortcuts:
self.app.set_accels_for_action(f"app.{name}", shortcuts)

return action

def __init_components(self):
if not self._player.loaded_book:
self.block_ui_buttons(True)
Expand Down
Loading