fix(settings): align settings pages with KDE HIG

This commit is contained in:
tri committed 2026-11-07 20:08:28 +07:00
1 parent de9e6484ee
commit 3d8f644d8d
10 files changed
+200 -186

No files matched your search

+44 -3
View File
@@ -2,6 +2,8 @@
#include <QCoroSignal>
#include <KLocalizedString>
#include <QPointer>
#include <qt6keychain/keychain.h>
@@ -48,9 +50,31 @@ QString ApiKeyStore::error() const
return m_error;
}
bool ApiKeyStore::busy() const
{
return m_busy;
}
void ApiKeyStore::setKey(const QString &key)
{
store(key.trimmed());
if (m_busy) {
return;
}
m_pendingKey = key.trimmed();
m_retryStore = true;
store(m_pendingKey);
}
void ApiKeyStore::retry()
{
if (m_busy) {
return;
}
if (m_retryStore) {
store(m_pendingKey);
} else {
refresh();
}
}
QCoro::Task<ApiKeyStore::ReadResult> ApiKeyStore::readKey()
@@ -63,13 +87,14 @@ QCoro::Task<ApiKeyStore::ReadResult> ApiKeyStore::readKey()
co_return ReadResult{};
}
if (job->error() != QKeychain::NoError) {
co_return ReadResult{{}, job->errorString()};
co_return ReadResult{{}, i18nc("@info", "Could not read the API key from the system wallet.\nMake sure KWallet or Secret Service is running, then retry.")};
}
co_return ReadResult{job->textData(), {}};
}
QCoro::Task<> ApiKeyStore::refresh()
{
setBusy(true);
QPointer<ApiKeyStore> self(this);
const ReadResult result = co_await readKey();
if (!self) {
@@ -77,10 +102,12 @@ QCoro::Task<> ApiKeyStore::refresh()
}
setHasKey(!result.key.isEmpty());
setError(result.error);
setBusy(false);
}
QCoro::Task<> ApiKeyStore::store(QString key)
{
setBusy(true);
QPointer<ApiKeyStore> self(this);
std::unique_ptr<QKeychain::Job, JobDeleter> job;
if (key.isEmpty()) {
@@ -97,11 +124,17 @@ QCoro::Task<> ApiKeyStore::store(QString key)
}
if (job->error() != QKeychain::NoError && job->error() != QKeychain::EntryNotFound) {
setError(job->errorString());
setError(key.isEmpty()
? i18nc("@info", "Could not remove the API key from the system wallet.\nMake sure KWallet or Secret Service is running, then retry.")
: i18nc("@info", "Could not store the API key in the system wallet.\nMake sure KWallet or Secret Service is running, then retry."));
setBusy(false);
co_return;
}
setError({});
setHasKey(!key.isEmpty());
m_retryStore = false;
m_pendingKey.clear();
setBusy(false);
}
void ApiKeyStore::setHasKey(bool hasKey)
@@ -119,3 +152,11 @@ void ApiKeyStore::setError(const QString &error)
Q_EMIT errorChanged();
}
}
void ApiKeyStore::setBusy(bool busy)
{
if (busy != m_busy) {
m_busy = busy;
Q_EMIT busyChanged();
}
}
+9
View File
@@ -15,6 +15,7 @@ class ApiKeyStore : public QObject
Q_PROPERTY(bool hasKey READ hasKey NOTIFY hasKeyChanged)
Q_PROPERTY(QString error READ error NOTIFY errorChanged)
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
public:
struct ReadResult {
@@ -26,9 +27,12 @@ public:
bool hasKey() const;
QString error() const;
bool busy() const;
// Stores \a key, or removes the stored key when it is empty.
Q_INVOKABLE void setKey(const QString &key);
// Repeats the failed read, write, or removal without asking for the key again.
Q_INVOKABLE void retry();
// An empty key without error means none is stored.
static QCoro::Task<ReadResult> readKey();
@@ -36,13 +40,18 @@ public:
Q_SIGNALS:
void hasKeyChanged();
void errorChanged();
void busyChanged();
private:
QCoro::Task<> refresh();
QCoro::Task<> store(QString key);
void setHasKey(bool hasKey);
void setError(const QString &error);
void setBusy(bool busy);
bool m_hasKey = false;
QString m_error;
bool m_busy = false;
bool m_retryStore = false;
QString m_pendingKey;
};