fix: don't prefix lyrics backend strings with qualifier
Also store the lyrics map in the state dir instead of lyrics dir
This commit is contained in:
parent
deb40a6536
commit
b80b9475ac
2 changed files with 21 additions and 15 deletions
|
|
@ -788,7 +788,6 @@ void Lyrics::onPreferredBackendConfigChanged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lyrics::onLyricsDirChanged() {
|
void Lyrics::onLyricsDirChanged() {
|
||||||
loadLyricsMap();
|
|
||||||
scheduleLoad();
|
scheduleLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -828,11 +827,7 @@ void Lyrics::persistTrackPrefs() {
|
||||||
}
|
}
|
||||||
m_lyricsMap.insert(key, entry);
|
m_lyricsMap.insert(key, entry);
|
||||||
|
|
||||||
const QString dir = lyricsDir();
|
QDir().mkpath(stateDir());
|
||||||
if (dir.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QDir().mkpath(dir);
|
|
||||||
|
|
||||||
QSaveFile out(lyricsMapPath());
|
QSaveFile out(lyricsMapPath());
|
||||||
if (!out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
if (!out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||||
|
|
@ -867,8 +862,7 @@ QString Lyrics::lyricsDir() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Lyrics::lyricsMapPath() const {
|
QString Lyrics::lyricsMapPath() const {
|
||||||
const QString dir = lyricsDir();
|
return stateDir() + u"/lyrics_map.json"_s;
|
||||||
return dir.isEmpty() ? QString() : dir + u"/lyrics_map.json"_s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Lyrics::trackKey() const {
|
QString Lyrics::trackKey() const {
|
||||||
|
|
@ -881,30 +875,41 @@ QString Lyrics::trackKey() const {
|
||||||
QString Lyrics::backendKey(LyricsBackend::Backend value) {
|
QString Lyrics::backendKey(LyricsBackend::Backend value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case LyricsBackend::Local:
|
case LyricsBackend::Local:
|
||||||
return u"LyricsBackend::Local"_s;
|
return u"Local"_s;
|
||||||
case LyricsBackend::LRCLIB:
|
case LyricsBackend::LRCLIB:
|
||||||
return u"LyricsBackend::LRCLIB"_s;
|
return u"LRCLIB"_s;
|
||||||
case LyricsBackend::NetEase:
|
case LyricsBackend::NetEase:
|
||||||
return u"LyricsBackend::NetEase"_s;
|
return u"NetEase"_s;
|
||||||
case LyricsBackend::Auto:
|
case LyricsBackend::Auto:
|
||||||
default:
|
default:
|
||||||
return u"LyricsBackend::Auto"_s;
|
return u"Auto"_s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LyricsBackend::Backend Lyrics::backendFromKey(const QString& key) {
|
LyricsBackend::Backend Lyrics::backendFromKey(const QString& key) {
|
||||||
if (key.compare(u"LyricsBackend::Local"_s, Qt::CaseInsensitive) == 0) {
|
if (key.compare(u"Local"_s, Qt::CaseInsensitive) == 0) {
|
||||||
return LyricsBackend::Local;
|
return LyricsBackend::Local;
|
||||||
}
|
}
|
||||||
if (key.compare(u"LyricsBackend::LRCLIB"_s, Qt::CaseInsensitive) == 0) {
|
if (key.compare(u"LRCLIB"_s, Qt::CaseInsensitive) == 0) {
|
||||||
return LyricsBackend::LRCLIB;
|
return LyricsBackend::LRCLIB;
|
||||||
}
|
}
|
||||||
if (key.compare(u"LyricsBackend::NetEase"_s, Qt::CaseInsensitive) == 0) {
|
if (key.compare(u"NetEase"_s, Qt::CaseInsensitive) == 0) {
|
||||||
return LyricsBackend::NetEase;
|
return LyricsBackend::NetEase;
|
||||||
}
|
}
|
||||||
return LyricsBackend::Auto;
|
return LyricsBackend::Auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString& Lyrics::stateDir() {
|
||||||
|
static const QString s_dir = [] {
|
||||||
|
QString state = qEnvironmentVariable("XDG_STATE_HOME");
|
||||||
|
if (state.isEmpty()) {
|
||||||
|
state = QDir::homePath() + u"/.local/state"_s;
|
||||||
|
}
|
||||||
|
return state + u"/caelestia/lyrics"_s;
|
||||||
|
}();
|
||||||
|
return s_dir;
|
||||||
|
}
|
||||||
|
|
||||||
const QString& Lyrics::cacheDir() {
|
const QString& Lyrics::cacheDir() {
|
||||||
static const QString s_dir = [] {
|
static const QString s_dir = [] {
|
||||||
QString cache = qEnvironmentVariable("XDG_CACHE_HOME");
|
QString cache = qEnvironmentVariable("XDG_CACHE_HOME");
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@ private:
|
||||||
[[nodiscard]] static QString backendKey(LyricsBackend::Backend value);
|
[[nodiscard]] static QString backendKey(LyricsBackend::Backend value);
|
||||||
[[nodiscard]] static LyricsBackend::Backend backendFromKey(const QString& key);
|
[[nodiscard]] static LyricsBackend::Backend backendFromKey(const QString& key);
|
||||||
|
|
||||||
|
[[nodiscard]] static const QString& stateDir();
|
||||||
[[nodiscard]] static const QString& cacheDir();
|
[[nodiscard]] static const QString& cacheDir();
|
||||||
[[nodiscard]] static QString cachePathFor(LyricsBackend::Backend backend, const QString& id);
|
[[nodiscard]] static QString cachePathFor(LyricsBackend::Backend backend, const QString& id);
|
||||||
[[nodiscard]] static QString readCachedLrc(LyricsBackend::Backend backend, const QString& id);
|
[[nodiscard]] static QString readCachedLrc(LyricsBackend::Backend backend, const QString& id);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue