From d3107dc09611cd53ccea5fbf0a91af0a2295f81b Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Thu, 1 Apr 2021 22:23:07 +0200 Subject: [PATCH] And more work on queue --- src/database.cpp | 3 ++- src/qml/EntryPage.qml | 2 +- src/qml/MinimizedPlayerControls.qml | 6 ++++++ src/qml/QueuePage.qml | 24 +++++------------------- src/qml/main.qml | 14 +++++++++----- src/queuemodel.cpp | 25 +++++++++++-------------- src/queuemodel.h | 3 ++- 7 files changed, 36 insertions(+), 41 deletions(-) diff --git a/src/database.cpp b/src/database.cpp index 72b9c2b7..1d179174 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -49,7 +49,8 @@ bool Database::migrateTo1() TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Feeds (name TEXT, url TEXT, image TEXT, link TEXT, description TEXT, deleteAfterCount INTEGER, deleteAfterType INTEGER, subscribed INTEGER, lastUpdated INTEGER, notify BOOL);"))); TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Entries (feed TEXT, id TEXT UNIQUE, title TEXT, content TEXT, created INTEGER, updated INTEGER, link TEXT, read bool, hasEnclosure BOOL);"))); TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Authors (feed TEXT, id TEXT, name TEXT, uri TEXT, email TEXT);"))); - TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Enclosures (feed TEXT, id TEXT, duration INTEGER, size INTEGER, title TEXT, type STRING, url STRING);"))); + TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Enclosures (feed TEXT, id TEXT, duration INTEGER, size INTEGER, title TEXT, type TEXT, url TEXT);"))); //, playposition INTEGER, filename TEXT);"))); + TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Queue (listnr INTEGER, feed TEXT, id TEXT);"))); TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 1;"))); return true; } diff --git a/src/qml/EntryPage.qml b/src/qml/EntryPage.qml index b507a818..b2adcffb 100644 --- a/src/qml/EntryPage.qml +++ b/src/qml/EntryPage.qml @@ -37,7 +37,7 @@ Kirigami.ScrollablePage { Layout.fillWidth: true Layout.fillHeight: true onLinkActivated: Qt.openUrlExternally(link) - onWidthChanged: entry.adjustedContent(width, font.pixelSize) + //onWidthChanged: { text = entry.adjustedContent(width, font.pixelSize) } } //} actions.main: Kirigami.Action { diff --git a/src/qml/MinimizedPlayerControls.qml b/src/qml/MinimizedPlayerControls.qml index cd08e1ae..afdc3f07 100644 --- a/src/qml/MinimizedPlayerControls.qml +++ b/src/qml/MinimizedPlayerControls.qml @@ -20,6 +20,12 @@ Item { //margins.bottom: miniprogressbar.height visible: (audio.entry !== undefined) && !audio.playerOpen + // Set background + Rectangle { + anchors.fill: parent + color: Kirigami.Theme.backgroundColor + } + // progress bar for limited width (phones) Rectangle { id: miniprogressbar diff --git a/src/qml/QueuePage.qml b/src/qml/QueuePage.qml index 1044a40e..08da198f 100644 --- a/src/qml/QueuePage.qml +++ b/src/qml/QueuePage.qml @@ -23,7 +23,7 @@ Kirigami.ScrollablePage { Kirigami.ListItemDragHandle { listItem: listItem listView: mainList - onMoveRequested: queueModel.moveRows(oldIndex, newIndex, 1) + onMoveRequested: queueModel.move(oldIndex, newIndex) } Controls.Label { @@ -55,26 +55,12 @@ Kirigami.ScrollablePage { } } + QueueModel { id: queueModel } + ListView { id: mainList - Timer { - id: refreshRequestTimer - interval: 3000 - onTriggered: page.refreshing = false - } - /*model: ListModel { - id: listModel - Component.onCompleted: { - for (var i = 0; i < 200; ++i) { - listModel.append({"title": "Item " + i, - "actions": [{text: "Action 1", icon: "document-decrypt"}, - {text: "Action 2", icon: "mail-reply-sender"}] - }) - } - } - }*/ - model: QueueModel { id: queueModel } + model: queueModel moveDisplaced: Transition { YAnimator { @@ -83,7 +69,7 @@ Kirigami.ScrollablePage { } } delegate: Kirigami.DelegateRecycler { - width: parent ? parent.width : implicitWidth + width: mainList.width sourceComponent: delegateComponent } } diff --git a/src/qml/main.qml b/src/qml/main.qml index 8f45bea4..25d76c09 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -27,14 +27,18 @@ Kirigami.ApplicationWindow { Kirigami.Action { text: i18n("Feed List") iconName: "rss" - onTriggered: root.pageStack.clear(), root.pageStack.push(feedList) - enabled: pageStack.layers.currentItem.title !== i18n("Feed List") + onTriggered: { + pageStack.clear() + pageStack.push(feedList) + } }, Kirigami.Action { text: i18n("Podcast Queue") iconName: "source-playlist" - onTriggered: root.pageStack.clear(), root.pageStack.push(queuelist) - enabled: pageStack.layers.currentItem.title !== i18n("Podcast Queue") + onTriggered: { + pageStack.clear() + pageStack.push(queuelist) + } }, Kirigami.Action { text: i18n("Settings") @@ -97,7 +101,7 @@ Kirigami.ApplicationWindow { } */ - footer: MinimizedPlayerControls {} + footer: MinimizedPlayerControls { } /*Item { visible: (audio.entry !== undefined) height: footerLoader.minimizedSize diff --git a/src/queuemodel.cpp b/src/queuemodel.cpp index ddba1ddc..8394de16 100644 --- a/src/queuemodel.cpp +++ b/src/queuemodel.cpp @@ -32,8 +32,6 @@ QueueModel::QueueModel(QObject *parent) void QueueModel::updateQueue() { - qDebug() << "Begin create queuemodel object"; - QSqlQuery query; query.prepare(QStringLiteral("SELECT * FROM Enclosures")); Database::instance().execute(query); @@ -120,24 +118,23 @@ int QueueModel::rowCount(const QModelIndex &parent) const return m_entries.size(); } +bool QueueModel::move(int from, int to) +{ + return moveRows(QModelIndex(), from, 1, QModelIndex(), to); +} bool QueueModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) { - if (sourceParent != destinationParent) { + Q_ASSERT(count == 1); // Only implemented the case of moving one row at a time + Q_ASSERT(sourceParent == destinationParent); // No moving between lists + + int to = (sourceRow < destinationChild) ? destinationChild + 1 : destinationChild; + + if (!beginMoveRows(sourceParent, sourceRow, sourceRow, destinationParent, to)) { return false; } - if (!beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1, destinationParent, destinationChild)) { - return false; - } - - for (auto cptItem = 0; cptItem < count; ++cptItem) { - if (sourceRow < destinationChild) { - m_entries.move(sourceRow, destinationChild - 1); - } else { - m_entries.move(sourceRow, destinationChild); - } - } + m_entries.move(sourceRow, destinationChild); endMoveRows(); diff --git a/src/queuemodel.h b/src/queuemodel.h index 494b3a04..0bccbcdc 100644 --- a/src/queuemodel.h +++ b/src/queuemodel.h @@ -24,7 +24,8 @@ public: QHash roleNames() const override; int rowCount(const QModelIndex &parent) const override; - bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override; + Q_INVOKABLE bool move(int from, int to); + Q_INVOKABLE bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override; private: void updateQueue();