Compare commits

..
Author SHA1 Message Date
Marco Martin 883d3871e6 Port away from DelegateRecycler
Component has been removed from Kirigami
2023-10-16 10:56:52 +02:00
Bart Ribbers 5cbcb85cf5 Allow building with KF6 2023-08-06 21:25:54 +02:00
6 changed files with 39 additions and 110 deletions

No files matched your search

+2 -4
View File
@@ -14,14 +14,12 @@ project(audiotube VERSION ${RELEASE_SERVICE_VERSION})
include(FeatureSummary)
if (QT_MAJOR_VERSION STREQUAL "6")
if (QT_MAJOR_VERSION_STREQUAL "6")
set(QT_MIN_VERSION "6.4.0")
set(KF_MIN_VERSION "5.240.0")
set(KF_MAJOR_VERSION "6")
else()
set(QT_MIN_VERSION "5.15")
set(KF_MIN_VERSION "5.81.0")
set(KF_MAJOR_VERSION "5")
endif()
set(CMAKE_CXX_STANDARD 20)
@@ -47,7 +45,7 @@ ecm_setup_version(${PROJECT_VERSION}
kde_enable_exceptions()
find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED COMPONENTS Core Gui Qml QuickControls2 Svg Sql Widgets Concurrent DBus)
find_package(KF${KF_MAJOR_VERSION} ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 I18n CoreAddons Crash WindowSystem)
find_package(KF5 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 I18n CoreAddons Crash WindowSystem)
find_package(pybind11 REQUIRED)
find_package(Ytdlp REQUIRED RUNTIME)
find_package(YTMusicAPI 1.0.2 REQUIRED RUNTIME)
+1 -4
View File
@@ -43,10 +43,7 @@ Kirigami.ScrollablePage {
filterRegularExpression: searchLoader.filterExpression
sourceModel: Library.playbackHistory
}
delegate: Kirigami.DelegateRecycler {
Layout.alignment: Qt.AlignTop
sourceComponent: searchAlbum
}
delegate: searchAlbum
}
}
}
+8 -5
View File
@@ -40,7 +40,6 @@ Item {
onTextEdited: {
filterText = text
Library.searches.filter = text
if(completionList.count === 0) {
//no matching search -> message should display
Library.temporarySearch = ""
@@ -317,10 +316,11 @@ Item {
visible: searchField.filterText && recentsRepeater.count > 0 //if changed, adjust playOpenHeight
model: LocalSearchModel {
searchQuery: searchField.text
model: SortFilterModel {
filterRole: PlaybackHistoryModel.Title
filterRegularExpression: searchField.filterExpression
sourceModel: Library.playbackHistory
}
delegate: searchAlbum
}
Kirigami.Separator {
@@ -355,7 +355,10 @@ Item {
property int empiricDelegateHeight: recentsRepeater.visible ? (mainScrollView.contentHeight - recentsRepeater.height) / count : (mainScrollView.contentHeight + mainScrollViewLayout.spacing) / (count)
id: completionList
model: Library.searches
model: SortFilterModel {
sourceModel: Library.searches
filterRegularExpression: searchField.filterExpression
}
function isSelectedDelegateVisible() {
if(!recentsRepeater.visible) {
+24 -71
View File
@@ -27,10 +27,25 @@ Library::Library(QObject *parent)
}()))
{
m_database->runMigrations(":/migrations/");
m_searches = new SearchHistoryModel(this);
m_searches = new SearchHistoryModel(m_database->getResults<SingleValue<QString>>("select distinct (search_query) from searches order by search_id desc"), this);
connect(this, &Library::changeFavourites, [this]() {
auto future = m_database->getResults<Song>("select * from favourites natural join songs order by favourites.rowid desc");
m_favourites= new FavouritesModel(std::move(future), this);
Q_EMIT favouritesChanged();
});
Q_EMIT changeFavourites();
refreshFavourites();
refreshPlaybackHistory();
connect(this, &Library::changePlaybackHistory, [this]() {
//playbackHistory
auto future = m_database->getResults<PlayedSong>("select * from played_songs natural join songs");
m_playbackHistory = new PlaybackHistoryModel(std::move(future), this);
//mostPlayed
auto future2 = m_database->getResults<PlayedSong>("select * from played_songs natural join songs order by plays desc limit 10");
m_mostPlayed = new PlaybackHistoryModel(std::move(future2), this);
Q_EMIT playbackHistoryChanged();
});
Q_EMIT changePlaybackHistory();
}
Library::~Library() = default;
@@ -49,15 +64,13 @@ FavouritesModel *Library::favourites()
void Library::addFavourite(const QString &videoId, const QString &title, const QString &artist, const QString &album)
{
QCoro::connect(addSong(videoId, title, artist, album), this, [=, this] {
QCoro::connect(m_database->execute("insert or ignore into favourites (video_id) values (?)", videoId),
this, &Library::refreshFavourites);
QCoro::connect(m_database->execute("insert or ignore into favourites (video_id) values (?)", videoId), this, &Library::changeFavourites);
});
}
void Library::removeFavourite(const QString &videoId)
{
QCoro::connect(m_database->execute("delete from favourites where video_id = ?", videoId),
this, &Library::refreshFavourites);
QCoro::connect(m_database->execute("delete from favourites where video_id = ?", videoId), this, &Library::changeFavourites);
}
FavouriteWatcher *Library::favouriteWatcher(const QString &videoId)
@@ -101,41 +114,17 @@ PlaybackHistoryModel *Library::playbackHistory()
return m_playbackHistory;
}
void Library::refreshPlaybackHistory()
{
// playbackHistory
auto future = m_database->getResults<PlayedSong>(
"select * from played_songs natural join songs");
m_playbackHistory = new PlaybackHistoryModel(std::move(future), this);
// mostPlayed
auto future2 = m_database->getResults<PlayedSong>(
"select * from played_songs natural join songs order by plays desc limit 10");
m_mostPlayed = new PlaybackHistoryModel(std::move(future2), this);
Q_EMIT playbackHistoryChanged();
}
void Library::refreshFavourites()
{
auto future = m_database->getResults<Song>(
"select * from favourites natural join songs order by favourites.rowid desc");
m_favourites = new FavouritesModel(std::move(future), this);
Q_EMIT favouritesChanged();
}
void Library::addPlaybackHistoryItem(const QString &videoId, const QString &title, const QString &artist, const QString &album)
{
QCoro::connect(addSong(videoId, title, artist, album), this, [=, this] {
QCoro::connect(m_database->execute("insert or ignore into played_songs (video_id, plays) values (?, ?)", videoId, 0), this, [=, this] {
QCoro::connect(m_database->execute("update played_songs set plays = plays + 1 where video_id = ? ", videoId),
this, &Library::refreshPlaybackHistory);
QCoro::connect(m_database->execute("update played_songs set plays = plays + 1 where video_id = ? ", videoId), this, &Library::changePlaybackHistory);
});
});
}
void Library::removePlaybackHistoryItem(const QString &videoId)
{
QCoro::connect(m_database->execute("delete from played_songs where video_id = ?", videoId),
this, &Library::refreshPlaybackHistory);
QCoro::connect(m_database->execute("delete from played_songs where video_id = ?", videoId), this, &Library::changePlaybackHistory);
}
WasPlayedWatcher *Library::wasPlayedWatcher(const QString& videoId)
@@ -175,11 +164,6 @@ PlaybackHistoryModel::PlaybackHistoryModel(QFuture<std::vector<PlayedSong>> &&so
});
}
PlaybackHistoryModel::PlaybackHistoryModel(QObject *parent)
: QAbstractListModel(parent)
{
}
QHash<int, QByteArray> PlaybackHistoryModel::roleNames() const {
return {
{Roles::VideoId, "videoId"},
@@ -288,25 +272,9 @@ bool FavouriteWatcher::isFavourite() const {
return m_isFavourite;
}
SearchHistoryModel::SearchHistoryModel(Library *library)
: QAbstractListModel(library)
SearchHistoryModel::SearchHistoryModel(QFuture<std::vector<SingleValue<QString>>> &&historyFuture, QObject *parent)
: QAbstractListModel(parent)
{
auto historyFuture = library->database()
.getResults<SingleValue<QString>>("select distinct (search_query) from searches order by search_id desc limit 20");
connect(this, &SearchHistoryModel::filterChanged, this, [library, this]() {
auto future = library->database()
.getResults<SingleValue<QString>>("select distinct (search_query) from searches "
"where search_query like '%" % m_filter % "%'"
"order by search_id desc limit 20");
QCoro::connect(std::move(future), this, [this](auto history) {
beginResetModel();
m_history = history;
endResetModel();
});
});
QCoro::connect(std::move(historyFuture), this, [this](const auto history) {
beginResetModel();
m_history = history;
@@ -423,18 +391,3 @@ void WasPlayedWatcher::update(std::optional<SingleValue<bool> > result)
Q_EMIT wasPlayedChanged();
}
}
LocalSearchModel::LocalSearchModel(QObject *parent) : PlaybackHistoryModel(parent)
{
connect(this, &LocalSearchModel::searchQueryChanged, this, [this]() {
auto resultFuture = Library::instance().database()
.getResults<PlayedSong>("select * from played_songs natural join songs "
"where title like '%" % m_searchQuery % "%' "
"order by plays desc limit 10");
QCoro::connect(std::move(resultFuture), this, [this](auto results) {
beginResetModel();
m_playedSongs = results;
endResetModel();
});
});
}
+4 -25
View File
@@ -84,39 +84,21 @@ public:
Q_ENUM(Roles);
PlaybackHistoryModel(QFuture<std::vector<PlayedSong>> &&songs, QObject *parent = nullptr);
PlaybackHistoryModel(QObject *parent = nullptr);
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
std::vector<PlayedSong> getPlayedSong() const;
protected:
private:
std::vector<PlayedSong> m_playedSongs;
};
class LocalSearchModel : public PlaybackHistoryModel {
Q_OBJECT
Q_PROPERTY(QString searchQuery MEMBER m_searchQuery NOTIFY searchQueryChanged)
Q_SIGNAL void searchQueryChanged();
public:
LocalSearchModel(QObject *parent = nullptr);
QString m_searchQuery;
};
class Library;
class SearchHistoryModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(QString filter MEMBER m_filter NOTIFY filterChanged)
public:
SearchHistoryModel(Library *library);
SearchHistoryModel(QFuture<std::vector<SingleValue<QString>>> &&historyFuture, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent) const override;
void removeSearch(const QString &search);
QVariant data(const QModelIndex &index, int role) const override;
@@ -124,13 +106,10 @@ public:
const QString & temporarySearch() const;
void setTemporarySearch(QString const& text);
Q_SIGNAL void filterChanged();
private:
size_t getRow(QString const &search) const;
std::vector<SingleValue<QString>> m_history;
QString m_temporarySearch;
QString m_filter;
};
class Library : public QObject
@@ -150,7 +129,7 @@ public:
FavouritesModel *favourites();
Q_SIGNAL void favouritesChanged();
void refreshFavourites();
Q_SIGNAL void changeFavourites();
Q_INVOKABLE void addFavourite(const QString &videoId, const QString &title, const QString &artist, const QString &album);
Q_INVOKABLE void removeFavourite(const QString &videoId);
Q_INVOKABLE FavouriteWatcher *favouriteWatcher(const QString &videoId);
@@ -165,7 +144,7 @@ public:
PlaybackHistoryModel *playbackHistory();
Q_SIGNAL void playbackHistoryChanged();
void refreshPlaybackHistory();
Q_SIGNAL void changePlaybackHistory();
Q_INVOKABLE void addPlaybackHistoryItem(const QString &videoId, const QString &title, const QString &artist, const QString &album);
Q_INVOKABLE void removePlaybackHistoryItem(const QString &videoId);
Q_INVOKABLE WasPlayedWatcher *wasPlayedWatcher(const QString &videoId);
-1
View File
@@ -91,7 +91,6 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
qmlRegisterUncreatableType<PlaybackHistoryModel>(URI, 1, 0, "PlaybackHistoryModel","");
qmlRegisterType<QSortFilterProxyModel>(URI, 1, 0, "SortFilterModel");
qmlRegisterType<Blur>(URI, 1, 0, "Blur");
qmlRegisterType<LocalSearchModel>(URI, 1, 0, "LocalSearchModel");
qmlRegisterType<LocalPlaylistModel>(URI, 1, 0, "LocalPlaylistModel");
qmlRegisterType<LocalPlaylistsModel>(URI, 1, 0, "LocalPlaylistsModel");
qmlRegisterType<PlaylistImporter>(URI, 1, 0, "PlaylistImporter");