fix(settings): align settings pages with KDE HIG
This commit is contained in:
1 parent
de9e6484ee
commit
8c42ee5a72
10 files changed
+200
-186
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user