File indexing completed on 2024-11-17 04:45:06
0001 /* 0002 SPDX-FileCopyrightText: 2007 Till Adam <adam@kde.org> 0003 SPDX-FileCopyrightText: 2008 Omat Holding B.V. <info@omat.nl> 0004 SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org> 0005 0006 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> 0007 SPDX-FileContributor: Kevin Ottens <kevin@kdab.com> 0008 0009 SPDX-License-Identifier: LGPL-2.0-or-later 0010 */ 0011 0012 #include "imapresource.h" 0013 0014 #include "sessionpool.h" 0015 #include "sessionuiproxy.h" 0016 #include "settings.h" 0017 #include "setupserver.h" 0018 #include <config-imap.h> 0019 0020 #ifdef WITH_GMAIL_XOAUTH2 0021 #include "passwordrequester.h" 0022 #else 0023 #include "settingspasswordrequester.h" 0024 #endif 0025 0026 #include <QIcon> 0027 0028 #include <KLocalizedString> 0029 #include <KWindowSystem> 0030 0031 ImapResource::ImapResource(const QString &id) 0032 : ImapResourceBase(id) 0033 { 0034 #ifdef WITH_GMAIL_XOAUTH2 0035 m_pool->setPasswordRequester(new PasswordRequester(this, m_pool)); 0036 #else 0037 m_pool->setPasswordRequester(new SettingsPasswordRequester(this, m_pool)); 0038 #endif 0039 m_pool->setSessionUiProxy(SessionUiProxy::Ptr(new SessionUiProxy)); 0040 m_pool->setClientId(clientId()); 0041 0042 settings(); // make sure the D-Bus settings interface is up 0043 } 0044 0045 ImapResource::~ImapResource() = default; 0046 0047 QString ImapResource::defaultName() const 0048 { 0049 return i18n("IMAP Account"); 0050 } 0051 0052 QByteArray ImapResource::clientId() const 0053 { 0054 return QByteArrayLiteral("Kontact IMAP Resource"); 0055 } 0056 0057 QDialog *ImapResource::createConfigureDialog(WId windowId) 0058 { 0059 auto dlg = new SetupServer(this, windowId); 0060 dlg->setAttribute(Qt::WA_NativeWindow, true); 0061 KWindowSystem::setMainWindow(dlg->windowHandle(), windowId); 0062 dlg->setWindowTitle(i18nc("@title:window", "IMAP Account Settings")); 0063 dlg->setWindowIcon(QIcon::fromTheme(QStringLiteral("network-server"))); 0064 connect(dlg, &SetupServer::finished, this, &ImapResource::onConfigurationDone); 0065 return dlg; 0066 } 0067 0068 void ImapResource::onConfigurationDone(int result) 0069 { 0070 auto dlg = qobject_cast<SetupServer *>(sender()); 0071 if (result) { 0072 if (dlg->shouldClearCache()) { 0073 clearCache(); 0074 } 0075 settings()->save(); 0076 } 0077 dlg->deleteLater(); 0078 } 0079 0080 #include "moc_imapresource.cpp"