Skip to content

Commit

Permalink
Merge pull request #151 from thigg/episodelistmodel
Browse files Browse the repository at this point in the history
AllEpisodes Page updates
4 years overdue, I'm very embarrassed.
Thank you!

Your other PRs will be reviewed in coming releases.
  • Loading branch information
Keeper-of-the-Keys authored Mar 20, 2024
2 parents df5c2fd + c4c84be commit 01d42de
Show file tree
Hide file tree
Showing 18 changed files with 250 additions and 189 deletions.
2 changes: 2 additions & 0 deletions common/GPodderCore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Python {
signal updatedEpisode(var episode)
signal updateStats()
signal configChanged(string key, var value)
signal initialized()

Component.onCompleted: {
setHandler('hello', function (coreversion, uiversion, parserversion) {
Expand Down Expand Up @@ -73,6 +74,7 @@ Python {
importModule('main', function() {
py.call('main.initialize', [py.progname], function() {
py.ready = true;
initialized();
});
});
}
Expand Down
69 changes: 32 additions & 37 deletions common/GPodderEpisodeListModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import 'util.js' as Util
import 'constants.js' as Constants

ListModel {
id: episodeListModel

property int podcast_id: -1
property var myself: this


property var queries: ({
All: '',
Expand All @@ -40,41 +40,33 @@ ListModel {
})

property var filters: ([
{ label: qsTr("All"), query: episodeListModel.queries.All },
{ label: qsTr("Fresh"), query: episodeListModel.queries.Fresh },
{ label: qsTr("Downloaded"), query: episodeListModel.queries.Downloaded },
{ label: qsTr("Unplayed downloads"), query: episodeListModel.queries.UnplayedDownloads },
{ label: qsTr("Finished downloads"), query: episodeListModel.queries.FinishedDownloads },
{ label: qsTr("Hide deleted"), query: episodeListModel.queries.HideDeleted },
{ label: qsTr("Deleted episodes"), query: episodeListModel.queries.Deleted },
{ label: qsTr("Short downloads (< 10 min)"), query: episodeListModel.queries.ShortDownloads },
{ label: qsTr("All"), query: queries.All },
{ label: qsTr("Fresh"), query: queries.Fresh },
{ label: qsTr("Downloaded"), query: queries.Downloaded },
{ label: qsTr("Unplayed downloads"), query: queries.UnplayedDownloads },
{ label: qsTr("Finished downloads"), query: queries.FinishedDownloads },
{ label: qsTr("Hide deleted"), query: queries.HideDeleted },
{ label: qsTr("Deleted episodes"), query: queries.Deleted },
{ label: qsTr("Short downloads (< 10 min)"), query: queries.ShortDownloads },
])

property bool ready: false
property int currentFilterIndex: -1
property string currentCustomQuery: queries.All

Component.onCompleted: {
// Request filter, then load episodes
py.call('main.get_config_value', ['ui.qml.episode_list.filter_eql'], function (result) {
setQueryFromUpdate(result);
reload();
});
}

function forEachEpisode(callback) {
// Go from bottom up (= chronological order)
for (var i=count-1; i>=0; i--) {
callback(get(i));
}
}

function setQueryIndex(index) {
currentFilterIndex = index;
py.call('main.set_config_value', ['ui.qml.episode_list.filter_eql', filters[currentFilterIndex].query]);
function setQueryFromIndex(index) {
console.debug("Setting filter index ", index)
setQueryEx(filters[index].query, true);
}

function setQueryFromUpdate(query) {
function setQueryFromConfigUpdate(query) {
setQueryEx(query, false);
}

Expand All @@ -85,29 +77,32 @@ ListModel {
function setQueryEx(query, update) {
for (var i=0; i<filters.length; i++) {
if (filters[i].query === query) {
if (update) {
py.call('main.set_config_value', ['ui.qml.episode_list.filter_eql', query]);
}
currentCustomQuery = query;
currentFilterIndex = i;
console.debug("found index ", i, " for query '", query, "'");
if (update && podcast_id === -1) {
updateQueryFilterConfig();
}
reload();
return;
}
}
console.warn("Could not find a predefined query for: '",query,"' Resetting to the all-query");
setQueryFromIndex(0);
}

currentFilterIndex = -1;
currentCustomQuery = query;

if (update) {
py.call('main.set_config_value', ['ui.qml.episode_list.filter_eql', query]);
}
function updateQueryFilterConfig(){
console.info("saving selected filter: ", currentFilterIndex, "='", currentCustomQuery, "'.")
py.call('main.set_config_value', ['ui.qml.episode_list.filter_eql', currentCustomQuery])
}

function loadAllEpisodes(callback) {
episodeListModel.podcast_id = -1;
podcast_id = -1;
reload(callback);
}

function loadEpisodes(podcast_id, callback) {
episodeListModel.podcast_id = podcast_id;
function loadEpisodes(podcast, callback) {
podcast_id = podcast;
reload(callback);
}

Expand All @@ -120,10 +115,10 @@ ListModel {
query = currentCustomQuery;
}

ready = false;
myself.ready = false;
py.call('main.load_episodes', [podcast_id, query], function (episodes) {
Util.updateModelFrom(episodeListModel, episodes);
episodeListModel.ready = true;
Util.updateModelFrom( myself, episodes);
myself.ready = true;
if (callback !== undefined) {
callback();
}
Expand Down
22 changes: 13 additions & 9 deletions common/GPodderEpisodeListModelConnections.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,37 @@ import 'util.js' as Util

Connections {
target: py
property var model

onDownloadProgress: {
Util.updateModelWith(episodeListModel, 'id', episode_id,
Util.updateModelWith(model, 'id', episode_id,
{'progress': progress});
}
onPlaybackProgress: {
Util.updateModelWith(episodeListModel, 'id', episode_id,
Util.updateModelWith(model, 'id', episode_id,
{'playbackProgress': progress});
}
onUpdatedEpisode: {
for (var i=0; i<episodeListModel.count; i++) {
if (episodeListModel.get(i).id === episode.id) {
episodeListModel.set(i, episode);
for (var i=0; i < model.count; i++) {
if (model.get(i).id === episode.id) {
model.set(i, episode);
break;
}
}
}
onEpisodeListChanged: {
if (episodeListModel.podcast_id === podcast_id) {
episodeListModel.reload();
if (model.podcast_id === podcast_id) {
model.reload();
}
}

onConfigChanged: {
if (key === 'ui.qml.episode_list.filter_eql') {
episodeListModel.setQueryFromUpdate(value);
episodeListModel.reload();
model.setQueryFromConfigUpdate(value);
}
}

onReadyChanged: {
model.reload();
}
}
6 changes: 3 additions & 3 deletions common/GPodderPodcastListModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import 'util.js' as Util

ListModel {
id: podcastListModel
property bool firstRun: false
property bool initialized: false

function reload() {
py.call('main.load_podcasts', [], function (podcasts) {
Util.updateModelFrom(podcastListModel, podcasts);
if(!firstRun) {
firstRun = true;
if(!initialized) {
initialized = true;
}
});
}
Expand Down
14 changes: 4 additions & 10 deletions qml/AllEpisodesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ Page {

onStatusChanged: pgst.handlePageStatusChange(status)

Component.onCompleted: {
episodeListModel.setQuery(episodeListModel.queries.Downloaded);
episodeListModel.reload();
}

BusyIndicator {
visible: !episodeListModel.ready
visible: !allPodcastsEpisodesModel.ready
running: visible
anchors.centerIn: parent
}
Expand All @@ -46,7 +41,7 @@ Page {
anchors.fill: parent

PullDownMenu {
EpisodeListFilterItem { id: filterItem; model: episodeListModel }
EpisodeListFilterItem { id: filterItem; model: allPodcastsEpisodesModel }
}

VerticalScrollDecorator { flickable: filteredEpisodesList }
Expand All @@ -55,8 +50,7 @@ Page {
title: filterItem.currentFilter + ": " + filteredEpisodesList.count
}

model: GPodderEpisodeListModel { id: episodeListModel }
GPodderEpisodeListModelConnections {}
model: allPodcastsEpisodesModel

section.property: 'section'
section.delegate: SectionHeader {
Expand All @@ -67,7 +61,7 @@ Page {
delegate: EpisodeItem {}

ViewPlaceholder {
enabled: filteredEpisodesList.count == 0 && episodeListModel.ready
enabled: filteredEpisodesList.count == 0 && allPodcastsEpisodesModel.ready
text: qsTr("No episodes found")
}
}
Expand Down
3 changes: 1 addition & 2 deletions qml/EpisodeFilterDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ Page {
highlighted: down || (index == filterSelector.selectedIndex)

onClicked: {
filterSelector.model.currentFilterIndex = index;
filterSelector.model.reload();
filterSelector.model.setQueryFromIndex(index);
pageStack.pop();
}

Expand Down
19 changes: 10 additions & 9 deletions qml/EpisodesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ Page {
RemorsePopup { id: remorse }

Component.onCompleted: {
episodeListModel.podcast_id = podcast_id;
episodeListModel.setQuery(episodeListModel.queries.All);
episodeListModel.reload();
singlePodcastEpisodesModel.podcast_id = podcast_id;
singlePodcastEpisodesModel.setQuery(singlePodcastEpisodesModel.queries.All);
}

BusyIndicator {
visible: !episodeListModel.ready
visible: !singlePodcastEpisodesModel.ready
running: visible
anchors.centerIn: parent
}
Expand All @@ -69,8 +68,10 @@ Page {
}
}

model: GPodderEpisodeListModel { id: episodeListModel }
GPodderEpisodeListModelConnections {}
model: GPodderEpisodeListModel { id: singlePodcastEpisodesModel }
GPodderEpisodeListModelConnections {
model: singlePodcastEpisodesModel
}

PullDownMenu {
MenuItem {
Expand Down Expand Up @@ -101,19 +102,19 @@ Page {
}
});

episodeListModel.forEachEpisode(function (episode) {
singlePodcastEpisodesModel.forEachEpisode(function (episode) {
player.enqueueEpisode(episode.id, startPlayback);
});
}
}

EpisodeListFilterItem { model: episodeListModel }
EpisodeListFilterItem { model: singlePodcastEpisodesModel }
}

delegate: EpisodeItem {}

ViewPlaceholder {
enabled: episodeList.count == 0 && episodeListModel.ready
enabled: episodeList.count == 0 && singlePodcastEpisodesModel.ready
text: qsTr("No episodes found")
}
}
Expand Down
14 changes: 14 additions & 0 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ PodcastsPage {
GPodderCore {
id: py
progname: 'harbour-org.gpodder.sailfish'

onInitialized: {
py.getConfig( 'ui.qml.episode_list.filter_eql', function (result) {
console.debug("got query from storage: '",result,"'")
allPodcastsEpisodesModel.setQueryFromConfigUpdate(result);
});
}
}

GPodderPlayback {
Expand All @@ -75,6 +82,13 @@ PodcastsPage {
GPodderPodcastListModel { id: podcastListModel }
GPodderPodcastListModelConnections {}

GPodderEpisodeListModel {
id: allPodcastsEpisodesModel
}
GPodderEpisodeListModelConnections {
model: allPodcastsEpisodesModel
}

function loadPage(filename, properties, replace) {
var component = Qt.createComponent(filename);
if (component.status !== Component.Ready) {
Expand Down
9 changes: 8 additions & 1 deletion qml/PodcastsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,19 @@ Page {

model: podcastListModel

BusyIndicator {
size: BusyIndicatorSize.Large
anchors.centerIn: parent
visible: !podcastListModel.initialized
running: visible
}

delegate: PodcastItem {
onClicked: pgst.loadPage('EpisodesPage.qml', {'podcast_id': id, 'title': title});
}

ViewPlaceholder {
enabled: podcastListModel.count === 0 && podcastListModel.firstRun
enabled: podcastListModel.count === 0 && podcastListModel.initialized
text: qsTr("No subscriptions")
}
}
Expand Down
Loading

0 comments on commit 01d42de

Please sign in to comment.