Skip to content

Commit

Permalink
Revert "AllEpisodes Page updates"
Browse files Browse the repository at this point in the history
  • Loading branch information
Keeper-of-the-Keys authored Mar 31, 2024
1 parent 01d42de commit bd43749
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 250 deletions.
2 changes: 0 additions & 2 deletions common/GPodderCore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ 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 @@ -74,7 +73,6 @@ Python {
importModule('main', function() {
py.call('main.initialize', [py.progname], function() {
py.ready = true;
initialized();
});
});
}
Expand Down
69 changes: 37 additions & 32 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 {
property int podcast_id: -1
property var myself: this
id: episodeListModel

property int podcast_id: -1

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

property var filters: ([
{ 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 },
{ 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 },
])

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

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

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

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

if (update) {
py.call('main.set_config_value', ['ui.qml.episode_list.filter_eql', query]);
}
}

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

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

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

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

Connections {
target: py
property var model

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

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

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 initialized: false
property bool firstRun: false

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

onStatusChanged: pgst.handlePageStatusChange(status)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

delegate: EpisodeItem {}

ViewPlaceholder {
enabled: episodeList.count == 0 && singlePodcastEpisodesModel.ready
enabled: episodeList.count == 0 && episodeListModel.ready
text: qsTr("No episodes found")
}
}
Expand Down
14 changes: 0 additions & 14 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ 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 @@ -82,13 +75,6 @@ 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: 1 addition & 8 deletions qml/PodcastsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,12 @@ 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.initialized
enabled: podcastListModel.count === 0 && podcastListModel.firstRun
text: qsTr("No subscriptions")
}
}
Expand Down
Loading

0 comments on commit bd43749

Please sign in to comment.