feat: dashboard show on hover, media and weather tabs added
This commit is contained in:
@@ -18,6 +18,8 @@ qml_module(ZShell-services
|
||||
memory.hpp memory.cpp
|
||||
diskinfo.hpp diskinfo.cpp
|
||||
storage.hpp storage.cpp
|
||||
lyriccandidate.hpp lyriccandidate.cpp
|
||||
lyrics.hpp lyrics.cpp
|
||||
LIBRARIES
|
||||
Qt6::Core
|
||||
Qt6::Qml
|
||||
@@ -25,4 +27,7 @@ qml_module(ZShell-services
|
||||
PkgConfig::Aubio
|
||||
PkgConfig::Cava
|
||||
Sensors::Sensors
|
||||
)
|
||||
ZShell-config
|
||||
DEPENDENCIES
|
||||
ZShell.Config
|
||||
)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "lyriccandidate.hpp"
|
||||
|
||||
namespace ZShell::services {
|
||||
|
||||
LyricCandidate::LyricCandidate(
|
||||
LyricsBackend backend,
|
||||
QString id,
|
||||
QString title,
|
||||
QString artist,
|
||||
QString album,
|
||||
qreal duration)
|
||||
: m_backend(backend)
|
||||
, m_id(std::move(id))
|
||||
, m_title(std::move(title))
|
||||
, m_artist(std::move(artist))
|
||||
, m_album(std::move(album))
|
||||
, m_duration(duration) {}
|
||||
|
||||
LyricsBackend LyricCandidate::backend() const {
|
||||
return m_backend;
|
||||
}
|
||||
|
||||
QString LyricCandidate::id() const {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
QString LyricCandidate::title() const {
|
||||
return m_title;
|
||||
}
|
||||
|
||||
QString LyricCandidate::artist() const {
|
||||
return m_artist;
|
||||
}
|
||||
|
||||
QString LyricCandidate::album() const {
|
||||
return m_album;
|
||||
}
|
||||
|
||||
qreal LyricCandidate::duration() const {
|
||||
return m_duration;
|
||||
}
|
||||
|
||||
bool LyricCandidate::isValid() const {
|
||||
return !m_id.isEmpty();
|
||||
}
|
||||
|
||||
bool LyricCandidate::operator==(const LyricCandidate& o) const noexcept {
|
||||
return m_backend == o.m_backend && m_id == o.m_id;
|
||||
}
|
||||
|
||||
bool LyricCandidate::operator!=(const LyricCandidate& o) const noexcept {
|
||||
return !(*this == o);
|
||||
}
|
||||
|
||||
} // namespace ZShell::services
|
||||
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qqmlintegration.h>
|
||||
|
||||
#include "config/enums.hpp"
|
||||
|
||||
namespace ZShell::services {
|
||||
|
||||
using LyricsBackend = config::LyricsBackend::Enum;
|
||||
|
||||
class LyricCandidate {
|
||||
Q_GADGET
|
||||
QML_VALUE_TYPE(lyricCandidate)
|
||||
|
||||
Q_PROPERTY(ZShell::config::LyricsBackend::Enum backend READ backend)
|
||||
Q_PROPERTY(QString id READ id)
|
||||
Q_PROPERTY(QString title READ title)
|
||||
Q_PROPERTY(QString artist READ artist)
|
||||
Q_PROPERTY(QString album READ album)
|
||||
Q_PROPERTY(qreal duration READ duration)
|
||||
|
||||
public:
|
||||
LyricCandidate() = default;
|
||||
LyricCandidate(
|
||||
LyricsBackend backend,
|
||||
QString id,
|
||||
QString title,
|
||||
QString artist,
|
||||
QString album = {},
|
||||
qreal duration = 0.0);
|
||||
|
||||
[[nodiscard]] LyricsBackend backend() const;
|
||||
[[nodiscard]] QString id() const;
|
||||
[[nodiscard]] QString title() const;
|
||||
[[nodiscard]] QString artist() const;
|
||||
[[nodiscard]] QString album() const;
|
||||
[[nodiscard]] qreal duration() const;
|
||||
|
||||
[[nodiscard]] bool isValid() const;
|
||||
bool operator==(const LyricCandidate& o) const noexcept;
|
||||
bool operator!=(const LyricCandidate& o) const noexcept;
|
||||
|
||||
private:
|
||||
LyricsBackend m_backend = LyricsBackend::Auto;
|
||||
QString m_id;
|
||||
QString m_title;
|
||||
QString m_artist;
|
||||
QString m_album;
|
||||
qreal m_duration = 0.0;
|
||||
};
|
||||
|
||||
} // namespace ZShell::services
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,162 @@
|
||||
#pragma once
|
||||
|
||||
#include <qhash.h>
|
||||
#include <qjsonobject.h>
|
||||
#include <qnetworkaccessmanager.h>
|
||||
#include <qnetworkreply.h>
|
||||
#include <qtimer.h>
|
||||
|
||||
#include "lyriccandidate.hpp"
|
||||
|
||||
namespace ZShell::services {
|
||||
|
||||
struct LyricLine {
|
||||
qreal time = 0.0;
|
||||
QString text;
|
||||
};
|
||||
|
||||
class Lyrics : public QObject {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_SINGLETON
|
||||
|
||||
Q_PROPERTY(QStringList lyrics READ lyrics NOTIFY lyricsChanged)
|
||||
Q_PROPERTY(
|
||||
ZShell::config::LyricsBackend::Enum backend READ backend NOTIFY
|
||||
backendChanged)
|
||||
Q_PROPERTY(
|
||||
ZShell::config::LyricsBackend::Enum preferredBackend READ
|
||||
preferredBackend WRITE setPreferredBackend NOTIFY
|
||||
preferredBackendChanged)
|
||||
Q_PROPERTY(
|
||||
QList<ZShell::services::LyricCandidate> lyricCandidates READ
|
||||
lyricCandidates NOTIFY lyricCandidatesChanged)
|
||||
Q_PROPERTY(
|
||||
ZShell::services::LyricCandidate selectedCandidate READ selectedCandidate
|
||||
WRITE setSelectedCandidate NOTIFY selectedCandidateChanged)
|
||||
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
|
||||
Q_PROPERTY(bool hasLyrics READ hasLyrics NOTIFY hasLyricsChanged)
|
||||
Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged)
|
||||
Q_PROPERTY(QString trackArtist READ trackArtist NOTIFY trackChanged)
|
||||
Q_PROPERTY(QString trackTitle READ trackTitle NOTIFY trackChanged)
|
||||
|
||||
public:
|
||||
explicit Lyrics(QObject* parent = nullptr);
|
||||
|
||||
[[nodiscard]] QStringList lyrics() const;
|
||||
[[nodiscard]] LyricsBackend backend() const;
|
||||
[[nodiscard]] LyricsBackend preferredBackend() const;
|
||||
void setPreferredBackend(LyricsBackend value);
|
||||
[[nodiscard]] QList<LyricCandidate> lyricCandidates() const;
|
||||
[[nodiscard]] LyricCandidate selectedCandidate() const;
|
||||
void setSelectedCandidate(const LyricCandidate& value);
|
||||
[[nodiscard]] bool loading() const;
|
||||
[[nodiscard]] bool hasLyrics() const;
|
||||
[[nodiscard]] qreal offset() const;
|
||||
void setOffset(qreal value);
|
||||
[[nodiscard]] QString trackArtist() const;
|
||||
[[nodiscard]] QString trackTitle() const;
|
||||
|
||||
[[nodiscard]] Q_INVOKABLE int indexForTime(qreal time) const;
|
||||
[[nodiscard]] Q_INVOKABLE qreal timeForIndex(int index) const;
|
||||
Q_INVOKABLE void setTrack(
|
||||
const QString& artist,
|
||||
const QString& title,
|
||||
const QString& album = {},
|
||||
qreal duration = 0.0);
|
||||
Q_INVOKABLE void clearTrack();
|
||||
Q_INVOKABLE void refresh();
|
||||
|
||||
signals:
|
||||
void lyricsChanged();
|
||||
void backendChanged();
|
||||
void preferredBackendChanged();
|
||||
void lyricCandidatesChanged();
|
||||
void selectedCandidateChanged();
|
||||
void loadingChanged();
|
||||
void hasLyricsChanged();
|
||||
void offsetChanged();
|
||||
void trackChanged();
|
||||
|
||||
private:
|
||||
void setBackend(LyricsBackend value);
|
||||
void setLoading(bool value);
|
||||
void setLines(QVector<LyricLine> lines, LyricsBackend source);
|
||||
void clearLines();
|
||||
void appendCandidates(const QList<LyricCandidate>& add);
|
||||
void clearCandidates();
|
||||
|
||||
void scheduleLoad();
|
||||
void doLoad();
|
||||
void cancelInFlight();
|
||||
int newRequestId();
|
||||
|
||||
void tryLocal(int reqId);
|
||||
void tryLrclib(int reqId);
|
||||
void tryNetEase(int reqId);
|
||||
void chainNext(LyricsBackend justFailed, int reqId);
|
||||
|
||||
void searchLrclibCandidates(int reqId);
|
||||
void searchNetEaseCandidates(int reqId);
|
||||
|
||||
void fetchLrclibById(const QString& id, int reqId);
|
||||
void fetchNetEaseLyricsById(const QString& id, int reqId);
|
||||
|
||||
QNetworkReply* getJson(
|
||||
const QUrl& url, const QHash<QByteArray, QByteArray>& headers = {});
|
||||
void trackReply(int reqId, QNetworkReply* reply);
|
||||
|
||||
void onPreferredBackendConfigChanged();
|
||||
void onLyricsDirChanged();
|
||||
|
||||
void loadLyricsMap();
|
||||
void persistTrackPrefs();
|
||||
|
||||
[[nodiscard]] static QString lyricsDir();
|
||||
[[nodiscard]] static QString lyricsMapPath();
|
||||
[[nodiscard]] QString trackKey() const;
|
||||
[[nodiscard]] static QString backendKey(LyricsBackend value);
|
||||
[[nodiscard]] static LyricsBackend backendFromKey(const QString& key);
|
||||
|
||||
[[nodiscard]] static const QString& stateDir();
|
||||
[[nodiscard]] static const QString& cacheDir();
|
||||
[[nodiscard]] static QString cachePathFor(
|
||||
LyricsBackend backend, const QString& id);
|
||||
[[nodiscard]] static QString readCachedLrc(
|
||||
LyricsBackend backend, const QString& id);
|
||||
static void writeCachedLrc(
|
||||
LyricsBackend backend, const QString& id, const QString& text);
|
||||
|
||||
[[nodiscard]] static QVector<LyricLine> parseLrc(const QString& text);
|
||||
[[nodiscard]] static QString tryReadLocalLrc(
|
||||
const QString& dir, const QString& artist, const QString& title);
|
||||
[[nodiscard]] static QString findLocalLrcRecursive(
|
||||
const QString& dir, const QString& artist, const QString& title);
|
||||
|
||||
QNetworkAccessManager* m_nam;
|
||||
QTimer* m_loadDebounce;
|
||||
|
||||
QVector<LyricLine> m_lines;
|
||||
QStringList m_lyrics;
|
||||
LyricsBackend m_backend = LyricsBackend::Auto;
|
||||
LyricsBackend m_preferredBackend = LyricsBackend::Auto;
|
||||
QList<LyricCandidate> m_candidates;
|
||||
LyricCandidate m_selected;
|
||||
bool m_loading = false;
|
||||
bool m_hasLyrics = false;
|
||||
qreal m_offset = 0.0;
|
||||
|
||||
QString m_artist;
|
||||
QString m_title;
|
||||
QString m_album;
|
||||
qreal m_duration = 0.0;
|
||||
|
||||
int m_currentRequestId = 0;
|
||||
QHash<int, QList<QPointer<QNetworkReply>>> m_pendingReplies;
|
||||
|
||||
QJsonObject m_lyricsMap;
|
||||
bool m_lyricsMapLoaded = false;
|
||||
bool m_settingFromPrefs = false;
|
||||
};
|
||||
|
||||
} // namespace ZShell::services
|
||||
Reference in New Issue
Block a user