c99afc75.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. From c99afc75a503fff6ca83df2f47a5d5d951579524 Mon Sep 17 00:00:00 2001
  2. From: Carl Schwan <carl@carlschwan.eu>
  3. Date: Tue, 19 Sep 2023 18:58:54 +0200
  4. Subject: [PATCH] Actually start job to read secret key
  5. BUG: 470820
  6. (cherry picked from commit 8393e92d56ecb31b2dd65d15d046f8e02565f5e3)
  7. ---
  8. resources/google-groupware/googleconfig.cpp | 8 +++++++-
  9. resources/google-groupware/googlesettings.cpp | 15 +++++++++------
  10. .../google-groupware/googlesettingswidget.cpp | 3 +--
  11. 3 files changed, 17 insertions(+), 9 deletions(-)
  12. diff --git a/resources/google-groupware/googleconfig.cpp b/resources/google-groupware/googleconfig.cpp
  13. index 2eb6ab2efa..1af177c81f 100644
  14. --- a/resources/google-groupware/googleconfig.cpp
  15. +++ b/resources/google-groupware/googleconfig.cpp
  16. @@ -6,6 +6,7 @@
  17. #include <Akonadi/AgentConfigurationBase>
  18. +#include "googleresource_debug.h"
  19. #include "googlesettings.h"
  20. #include "googlesettingswidget.h"
  21. @@ -25,7 +26,12 @@ public:
  22. void load() override
  23. {
  24. Akonadi::AgentConfigurationBase::load();
  25. - mWidget.loadSettings();
  26. + mSettings.init();
  27. + connect(&mSettings, &GoogleSettings::accountReady, this, [this](bool ready) {
  28. + if (ready) {
  29. + mWidget.loadSettings();
  30. + }
  31. + });
  32. }
  33. Q_REQUIRED_RESULT bool save() const override
  34. diff --git a/resources/google-groupware/googlesettings.cpp b/resources/google-groupware/googlesettings.cpp
  35. index aa94cad1ab..23a9979895 100644
  36. --- a/resources/google-groupware/googlesettings.cpp
  37. +++ b/resources/google-groupware/googlesettings.cpp
  38. @@ -32,7 +32,6 @@ static const QString googleWalletFolder = QStringLiteral("Akonadi Google");
  39. GoogleSettings::GoogleSettings(const KSharedConfigPtr &config, Options options)
  40. : SettingsBase(config)
  41. {
  42. - qDebug() << config;
  43. if (options & Option::ExportToDBus) {
  44. new SettingsAdaptor(this);
  45. QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"),
  46. @@ -44,9 +43,11 @@ GoogleSettings::GoogleSettings(const KSharedConfigPtr &config, Options options)
  47. void GoogleSettings::init()
  48. {
  49. // First read from QtKeyChain
  50. - auto job = new QKeychain::ReadPasswordJob(googleWalletFolder);
  51. + auto job = new QKeychain::ReadPasswordJob(googleWalletFolder, this);
  52. + job->setKey(account());
  53. connect(job, &QKeychain::Job::finished, this, [this, job]() {
  54. if (job->error() != QKeychain::Error::NoError) {
  55. + qCWarning(GOOGLE_LOG) << "Unable to read password" << job->error();
  56. Q_EMIT accountReady(false);
  57. return;
  58. }
  59. @@ -54,18 +55,19 @@ void GoogleSettings::init()
  60. // Found something with QtKeyChain
  61. if (!account().isEmpty()) {
  62. m_account = fetchAccountFromKeychain(account(), job);
  63. + m_isReady = true;
  64. + Q_EMIT accountReady(true);
  65. }
  66. - m_isReady = true;
  67. - Q_EMIT accountReady(true);
  68. });
  69. + job->start();
  70. }
  71. KGAPI2::AccountPtr GoogleSettings::fetchAccountFromKeychain(const QString &accountName, QKeychain::ReadPasswordJob *job)
  72. {
  73. QMap<QString, QString> map;
  74. auto value = job->binaryData();
  75. - if (!value.isEmpty()) {
  76. - qCDebug(GOOGLE_LOG) << "Account" << accountName << "not found in kwallet";
  77. + if (value.isEmpty()) {
  78. + qCWarning(GOOGLE_LOG) << "Account" << accountName << "not found in kwallet";
  79. return {};
  80. }
  81. @@ -116,6 +118,7 @@ WritePasswordJob *GoogleSettings::storeAccount(AccountPtr account)
  82. connect(writeJob, &WritePasswordJob::finished, this, [this, writeJob]() {
  83. if (writeJob->error()) {
  84. + qCWarning(GOOGLE_LOG) << "Unable to write password" << writeJob->error();
  85. return;
  86. }
  87. SettingsBase::setAccount(m_account->accountName());
  88. diff --git a/resources/google-groupware/googlesettingswidget.cpp b/resources/google-groupware/googlesettingswidget.cpp
  89. index 2543c4c6b8..8e84cfbabd 100644
  90. --- a/resources/google-groupware/googlesettingswidget.cpp
  91. +++ b/resources/google-groupware/googlesettingswidget.cpp
  92. @@ -36,7 +36,6 @@ GoogleSettingsWidget::GoogleSettingsWidget(GoogleSettings &settings, const QStri
  93. , m_settings(settings)
  94. , m_identifier(identifier)
  95. {
  96. - qDebug() << m_settings.account();
  97. auto mainLayout = new QVBoxLayout(this);
  98. auto mainWidget = new QWidget(this);
  99. @@ -83,7 +82,7 @@ bool GoogleSettingsWidget::handleError(KGAPI2::Job *job)
  100. }
  101. if (job->error() == KGAPI2::Unauthorized) {
  102. - qCDebug(GOOGLE_LOG) << job << job->errorString();
  103. + qWarning() << job << job->errorString();
  104. const QList<QUrl> resourceScopes = googleScopes();
  105. for (const QUrl &scope : resourceScopes) {
  106. if (!m_account->scopes().contains(scope)) {
  107. --
  108. GitLab