Skip to content

Commit

Permalink
Search by genres
Browse files Browse the repository at this point in the history
Closes #43
  • Loading branch information
aleiepure committed Feb 11, 2025
1 parent b593ac1 commit c5c19cc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
8 changes: 8 additions & 0 deletions data/me.iepure.Ticketbooth.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ SPDX-License-Identifier: GPL-3.0-or-later
<default>false</default>
<summary>Search bar visibility</summary>
</key>
<key name="search-mode" type="s">
<choices>
<choice value="title" />
<choice value="genre" />
</choices>
<default>"title"</default>
<summary>Search mode</summary>
</key>
<key name="search-query" type="s">
<default>''</default>
<summary>Search query</summary>
Expand Down
24 changes: 18 additions & 6 deletions src/ui/views/main_view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,24 @@ template $MainView: Adw.Bin {
SearchBar _search_bar {
search-mode-enabled: bind _show_search_btn.active;

child: SearchEntry _search_entry {
halign: center;
activates-default: true;
placeholder-text: _("Search Your Watchlist");
search-delay: 500;
search-changed => $_on_searchentry_search_changed();
child: Box {
orientation: horizontal;
spacing: 6;

DropDown _search_mode {
model: StringList {
strings: ["Title", "Genre"];
};
selected: 0;
}

SearchEntry _search_entry {
halign: center;
activates-default: true;
placeholder-text: _("Search Your Watchlist");
search-delay: 500;
search-changed => $_on_searchentry_search_changed();
}
};
}

Expand Down
33 changes: 20 additions & 13 deletions src/views/content_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ def _load_content(self, movie_view: bool) -> None:
self._unwatched_box.set_visible(False)
self._watched_box.set_visible(False)

# if shared.schema.get_boolean('search-enabled'):
# self._full_box.set_visible(True)
# return

if not shared.schema.get_boolean('search-enabled') and shared.schema.get_boolean('separate-watched'):
self._separated_box.set_visible(True)
if self._watched_flow_box.get_child_at_index(0) is not None:
Expand Down Expand Up @@ -282,13 +278,23 @@ def _set_filter_function(self) -> None:
"""

if shared.schema.get_boolean('search-enabled'):
self._flow_box.set_filter_func(
lambda child,
user_data: (
shared.schema.get_string(
'search-query').lower() in child.get_child().content.title.lower()
),
None)
if shared.schema.get_string('search-mode') == 'title':
self._flow_box.set_filter_func(
lambda child,
user_data: (
shared.schema.get_string(
'search-query').lower() in child.get_child().content.title.lower()
),
None)
else:
self._flow_box.set_filter_func(
lambda child, user_data: (
any(
shared.schema.get_string(
'search-query').title() in genre
for genre in child.get_child().content.genres)
),
None)
self._flow_box.invalidate_filter()
return

Expand All @@ -314,8 +320,9 @@ def _on_search_enabled_changed(self, pspec: GObject.ParamSpec, user_data: object
None
"""

self._title_lbl.set_label(_("Search results") if shared.schema.get_boolean('search-enabled') else _("Your Watchlist"))

self._title_lbl.set_label(_("Search results") if shared.schema.get_boolean(
'search-enabled') else _("Your Watchlist"))

self.refresh_view()

self._set_filter_function()
12 changes: 9 additions & 3 deletions src/views/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MainView(Adw.Bin):
_banner = Gtk.Template.Child()
_background_indicator = Gtk.Template.Child()
_search_bar = Gtk.Template.Child()
_search_mode = Gtk.Template.Child()
_search_entry = Gtk.Template.Child()

_needs_refresh = ''
Expand Down Expand Up @@ -71,11 +72,11 @@ def __init__(self, window):
'search-mode-enabled', Gio.SettingsBindFlags.DEFAULT)
shared.schema.bind('search-enabled', self._show_search_btn,
'active', Gio.SettingsBindFlags.DEFAULT)

self._search_mode.connect('notify::selected', self._on_search_mode_changed)

self._tab_stack.connect(
'notify::visible-child-name', self._check_needs_refresh)



# Theme switcher (Adapted from https://gitlab.gnome.org/tijder/blueprintgtk/)
self._menu_btn.get_popover().add_child(ThemeSwitcher(), 'themeswitcher')
Expand Down Expand Up @@ -450,4 +451,9 @@ def _on_searchentry_search_changed(self, user_data: GObject.GPointer | None) ->
def _on_search_btn_toggled(self, user_data: GObject.GPointer | None) -> None:
shared.schema.set_boolean('search-enabled', self._show_search_btn.get_active())
shared.schema.set_string('search-query', '')


def _on_search_mode_changed(self, pspec: GObject.ParamSpec, user_data: object | None) -> None:
if self._search_mode.get_selected() == 0:
shared.schema.set_string('search-mode', 'title')
else:
shared.schema.set_string('search-mode', 'genre')

0 comments on commit c5c19cc

Please sign in to comment.