Skip to content

Commit

Permalink
Stability fixes
Browse files Browse the repository at this point in the history
Changed `appstream-util` to `appstreamcli`, fixes #13
Fixes #9 (hopefully)
  • Loading branch information
aleiepure committed Sep 26, 2023
1 parent 234d7ac commit f631e02
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
6 changes: 3 additions & 3 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ appstream_file = i18n.merge_file(
install_dir: join_paths(get_option('datadir'), 'metainfo')
)

appstream_util = find_program('appstream-util', required: false)
if appstream_util.found()
test('Validate appstream file', appstream_util, args: ['validate', appstream_file])
appstreamcli = find_program('appstreamcli', required: false)
if appstreamcli.found()
test('Validate appstream file', appstreamcli, args: ['validate', appstream_file])
endif

install_data(
Expand Down
1 change: 0 additions & 1 deletion src/ui/views/main_view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ template $MainView: Adw.Bin {
menu-model: _add_menu;
}


[end]
MenuButton _menu_btn {
icon-name: "open-menu";
Expand Down
19 changes: 11 additions & 8 deletions src/views/content_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, movie_view: bool):

self._stack.set_visible_child_name('loading')

GLib.Thread.new(None, self._load_content, movie_view)
self._load_content(self.movie_view)

self._set_sorting_function()
shared.schema.connect('changed::view-sorting', self._on_sort_changed)
Expand Down Expand Up @@ -110,10 +110,9 @@ def refresh_view(self) -> None:

self._stack.set_visible_child_name('loading')

while self._flow_box.get_child_at_index(0):
self._flow_box.remove(self._flow_box.get_child_at_index(0))
self._flow_box.remove_all()

GLib.Thread.new(None, self._load_content, self.movie_view)
self._load_content(self.movie_view)

def _on_clicked(self, source: Gtk.Widget, content: MovieModel | SeriesModel) -> None:
"""
Expand Down Expand Up @@ -157,21 +156,25 @@ def _set_sorting_function(self) -> None:
case 'added-date-new':
self._flow_box.set_sort_func(lambda child1, child2, user_data: (
(child1.get_child().content.add_date < child2.get_child().content.add_date) -
(child1.get_child().content.add_date > child2.get_child().content.add_date)
(child1.get_child().content.add_date >
child2.get_child().content.add_date)
), None)
case 'added-date-old':
self._flow_box.set_sort_func(lambda child1, child2, user_data: (
(child1.get_child().content.add_date > child2.get_child().content.add_date) -
(child1.get_child().content.add_date < child2.get_child().content.add_date)
(child1.get_child().content.add_date <
child2.get_child().content.add_date)
), None)
case 'released-date-new':
self._flow_box.set_sort_func(lambda child1, child2, user_data: (
(child1.get_child().content.release_date < child2.get_child().content.release_date) -
(child1.get_child().content.release_date > child2.get_child().content.release_date)
(child1.get_child().content.release_date >
child2.get_child().content.release_date)
), None)
case 'released-date-old':
self._flow_box.set_sort_func(lambda child1, child2, user_data: (
(child1.get_child().content.release_date > child2.get_child().content.release_date) -
(child1.get_child().content.release_date < child2.get_child().content.release_date)
(child1.get_child().content.release_date <
child2.get_child().content.release_date)
), None)
self._flow_box.invalidate_sort()
27 changes: 26 additions & 1 deletion src/views/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from gettext import gettext as _
from gettext import pgettext as C_

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

from .. import shared # type: ignore
from ..background_queue import (ActivityType, BackgroundActivity,
Expand Down Expand Up @@ -40,6 +40,8 @@ class MainView(Adw.Bin):
_banner = Gtk.Template.Child()
_background_indicator = Gtk.Template.Child()

_needs_refresh = ''

def __init__(self):
super().__init__()

Expand All @@ -60,9 +62,30 @@ def __init__(self):
shared.schema.bind('offline-mode', self._banner,
'revealed', Gio.SettingsBindFlags.GET)

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')

def _check_needs_refresh(self, pspec: GObject.ParamSpec, user_data: object | None) -> None:
"""
Checks if the tab switched to is pending a refresh and does it if needed.
Args:
pspec (GObject.ParamSpec): pspec of the changed property
user_data (object or None): additional data passed to the callback
Returns:
None
"""
if self._tab_stack.get_visible_child_name() == 'movies' and self._needs_refresh == 'movies':
self._tab_stack.get_child_by_name('movies').refresh_view()
self._needs_refresh = ''
elif self._tab_stack.get_visible_child_name() == 'series' and self._needs_refresh == 'series':
self._tab_stack.get_child_by_name('series').refresh_view()
self._needs_refresh = ''

@Gtk.Template.Callback('_on_map')
def _on_map(self, user_data: object | None) -> None:
"""
Expand Down Expand Up @@ -156,5 +179,7 @@ def refresh(self) -> None:

if self._tab_stack.get_visible_child_name() == 'movies':
self._tab_stack.get_child_by_name('movies').refresh_view()
self._needs_refresh = 'series'
else:
self._tab_stack.get_child_by_name('series').refresh_view()
self._needs_refresh = 'movies'
11 changes: 7 additions & 4 deletions src/widgets/search_result_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _check_in_db_thread(self, thread_data: object | None) -> None:
"""

if local.get_movie_by_id(self.tmdb_id) or local.get_series_by_id(self.tmdb_id):
self._add_btn.set_label(_('Already in your whatchlist'))
self._add_btn.set_label(_('Already in your watchlist'))
self._add_btn.set_icon_name('check-plain')
self._add_btn.set_sensitive(False)

Expand All @@ -112,7 +112,8 @@ def _get_poster_file(self) -> None | Gio.File:
None or a Gio.File containing an image
"""
if self.poster_path:
Gio.Task.new(self, None, self._on_get_poster_done, None).run_in_thread(self._get_poster_thread)
Gio.Task.new(self, None, self._on_get_poster_done,
None).run_in_thread(self._get_poster_thread)
else:
self._poster_spinner.set_visible(False)
return Gio.File.new_for_uri(f'resource://{shared.PREFIX}/blank_poster.jpg')
Expand Down Expand Up @@ -169,7 +170,8 @@ def _add_content_to_db(self, activity: BackgroundActivity) -> None:
self._add_btn.set_label(_('Already in your whatchlist'))
self._add_btn.set_icon_name('check-plain')
self._add_spinner.set_visible(False)
self.get_ancestor(Adw.Window).get_transient_for().activate_action('win.refresh', None)
self.get_ancestor(Adw.Window).get_transient_for(
).activate_action('win.refresh', None)
activity.end()

def _get_poster_thread(self, task: Gio.Task, source_object: GObject.Object, task_data: object | None,
Expand Down Expand Up @@ -203,7 +205,8 @@ def _get_poster(self) -> Gio.File:
Gio.File containing the poster
"""

files = glob.glob(f'{self.poster_path[1:-4]}.jpg', root_dir=shared.cache_dir)
files = glob.glob(
f'{self.poster_path[1:-4]}.jpg', root_dir=shared.cache_dir)
if files:
return Gio.File.new_for_path(f'{shared.cache_dir}/{files[0]}')
else:
Expand Down

0 comments on commit f631e02

Please sign in to comment.