diff --git a/src/autotests/ldaptest.cpp b/src/autotests/ldaptest.cpp index 03ce211..d0c4624 100644 --- a/src/autotests/ldaptest.cpp +++ b/src/autotests/ldaptest.cpp @@ -1,112 +1,112 @@ /* Copyright (c) 2014 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include -#include +#include #include #include #include #include #include "../ldap.h" class TLdap : public Ldap { Q_OBJECT public: explicit TLdap(QObject *parent = nullptr) : Ldap(parent) { mTempFile.open(); mTempFile.close(); mConfig = new KConfig(mTempFile.fileName(), KConfig::SimpleConfig); m_clientSearchConfig->askForWallet(false); } virtual ~TLdap() { mTempFile.close(); delete mConfig; } KConfig *config() const override { mConfig->reparseConfiguration(); return mConfig; } QTemporaryFile mTempFile; KConfig *mConfig = nullptr; }; class LdapTest : public QObject { Q_OBJECT private Q_SLOTS: void testDestroy() { TLdap l; QFile::remove(l.mTempFile.fileName()); QFile::copy(QStringLiteral(TEST_DATA_DIR) + QStringLiteral("/ldap.cfg"), l.mTempFile.fileName()); KLDAP::LdapClientSearchConfig csc; csc.askForWallet(false); KConfigGroup group = l.config()->group("LDAP"); int cSelHosts = group.readEntry("NumSelectedHosts", 0); int cHosts = group.readEntry("NumHosts", 0); QCOMPARE(cSelHosts, 3); QCOMPARE(cHosts, 1); QVector selHosts; selHosts.reserve(cSelHosts); for (int i = 0; i < cSelHosts; ++i) { KLDAP::LdapServer server; csc.readConfig(server, group, i, true); selHosts.append(server); } QVector hosts; hosts.reserve(cHosts); for (int i = 0; i < cHosts; ++i) { KLDAP::LdapServer server; csc.readConfig(server, group, i, false); hosts.append(server); } l.m_entry = 0; l.destroy(); group = l.config()->group("LDAP"); QCOMPARE(group.readEntry("NumSelectedHosts", 0), 2); QCOMPARE(group.readEntry("NumHosts", 0), 1); KLDAP::LdapServer server; csc.readConfig(server, group, 0, false); QCOMPARE(server.host(), hosts.at(0).host()); csc.readConfig(server, group, 0, true); QCOMPARE(server.host(), selHosts.at(1).host()); csc.readConfig(server, group, 1, true); QCOMPARE(server.host(), selHosts.at(2).host()); } }; QTEST_GUILESS_MAIN(LdapTest) #include "ldaptest.moc" diff --git a/src/dynamicpage.cpp b/src/dynamicpage.cpp index 3517f2f..30ca4e6 100644 --- a/src/dynamicpage.cpp +++ b/src/dynamicpage.cpp @@ -1,71 +1,71 @@ /* Copyright (c) 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dynamicpage.h" #include "accountwizard_debug.h" #include #include -#include -#include +#include +#include #include "global.h" #include #include DynamicPage::DynamicPage(const QString &uiFile, KAssistantDialog *parent) : Page(parent) , m_dynamicWidget(nullptr) { QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); QWidget *pageParent = this; QUiLoader loader; loader.setLanguageChangeEnabled(true); QFile file(uiFile); if (file.open(QFile::ReadOnly)) { qCDebug(ACCOUNTWIZARD_LOG) << uiFile; m_dynamicWidget = loader.load(&file, pageParent); file.close(); if (!Global::poFileName().isEmpty()) { KLocalizedTranslator *translator = new KLocalizedTranslator(this); QCoreApplication::instance()->installTranslator(translator); translator->setTranslationDomain(Global::poFileName()); translator->addContextToMonitor(m_dynamicWidget->objectName()); QEvent le(QEvent::LanguageChange); QCoreApplication::sendEvent(m_dynamicWidget, &le); } } else { qCDebug(ACCOUNTWIZARD_LOG) << "Unable to open: " << uiFile; } if (m_dynamicWidget) { layout->addWidget(m_dynamicWidget); } setValid(true); } QObject *DynamicPage::widget() const { return m_dynamicWidget; } diff --git a/src/global.cpp b/src/global.cpp index 3ba914a..41e6311 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -1,133 +1,133 @@ /* Copyright (c) 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "global.h" #include "accountwizard_debug.h" -#include +#include #include #include #include class GlobalPrivate { public: QStringList filter; QString assistant; QString poFileName; }; Q_GLOBAL_STATIC(GlobalPrivate, sInstance) QString Global::assistant() { return sInstance->assistant; } void Global::setAssistant(const QString &assistant) { const QFileInfo info(assistant); if (info.isAbsolute()) { sInstance->assistant = assistant; return; } QStringList list; const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("akonadi/accountwizard/"), QStandardPaths::LocateDirectory); for (const QString &dir : dirs) { const QStringList directories = QDir(dir).entryList(QDir::AllDirs); for (const QString &directory : directories) { const QString fullPath = dir + QLatin1Char('/') + directory; const QStringList fileNames = QDir(fullPath).entryList(QStringList() << QStringLiteral("*.desktop")); list.reserve(fileNames.count()); for (const QString &file : fileNames) { list.append(fullPath + QLatin1Char('/') + file); } } } for (const QString &entry : qAsConst(list)) { const QFileInfo info(entry); const QDir dir(info.absolutePath()); if (dir.dirName() == assistant) { sInstance->assistant = entry; return; } } sInstance->assistant.clear(); } QStringList Global::typeFilter() { return sInstance->filter; } void Global::setTypeFilter(const QStringList &filter) { sInstance->filter = filter; } QString Global::assistantBasePath() { const QFileInfo info(assistant()); if (info.isAbsolute()) { return info.absolutePath() + QDir::separator(); } return QString(); } QString Global::unpackAssistant(const QUrl &remotePackageUrl) { QString localPackageFile; if (remotePackageUrl.scheme() == QLatin1String("file")) { localPackageFile = remotePackageUrl.path(); } else { QString remoteFileName = QFileInfo(remotePackageUrl.path()).fileName(); localPackageFile = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/accountwizard/") + remoteFileName; KIO::Job *job = KIO::copy(remotePackageUrl, QUrl::fromLocalFile(localPackageFile), KIO::Overwrite | KIO::HideProgressInfo); qCDebug(ACCOUNTWIZARD_LOG) << "downloading remote URL" << remotePackageUrl << "to" << localPackageFile; if (!job->exec()) { return QString(); } } const QUrl file(QLatin1String("tar://") + localPackageFile); const QFileInfo fi(localPackageFile); const QString assistant = fi.baseName(); const QString dest = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QLatin1Char('/'); QDir().mkpath(dest + file.fileName()); KIO::Job *getJob = KIO::copy(file, QUrl::fromLocalFile(dest), KIO::Overwrite | KIO::HideProgressInfo); if (getJob->exec()) { qCDebug(ACCOUNTWIZARD_LOG) << "worked, unpacked in " << dest; return dest + file.fileName() + QLatin1Char('/') + assistant + QLatin1Char('/') + assistant + QLatin1String(".desktop"); } else { qCDebug(ACCOUNTWIZARD_LOG) << "failed" << getJob->errorString(); return QString(); } } void Global::setPoFileName(const QString &poFileName) { sInstance->poFileName = poFileName; } QString Global::poFileName() { return sInstance->poFileName; } diff --git a/src/ispdb/autotests/ispdbtest.cpp b/src/ispdb/autotests/ispdbtest.cpp index c40c995..06ce85c 100644 --- a/src/ispdb/autotests/ispdbtest.cpp +++ b/src/ispdb/autotests/ispdbtest.cpp @@ -1,130 +1,130 @@ /* Copyright (c) 2014 Sandro Knauß This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include -#include +#include #include "../ispdb.h" class TIspdb : public Ispdb { public: void start(const QUrl &url) { setServerType(Ispdb::IspWellKnow); startJob(url); } }; class IspdbTest : public QObject { Q_OBJECT public: Ispdb *execIspdb(const QString &file) { QDir dir(QStringLiteral(AUTOCONFIG_DATA_DIR)); QString furl = QStringLiteral("file://%1/%2"); QEventLoop loop; TIspdb *ispdb = new TIspdb(); loop.connect(ispdb, SIGNAL(finished(bool)), SLOT(quit())); QUrl url(furl.arg(dir.path()).arg(file)); ispdb->setEmail(QStringLiteral("john.doe@example.com")); ispdb->start(url); loop.exec(); return ispdb; } void testServer(const Server &test, const Server &expected) const { QVERIFY(test.isValid()); QCOMPARE(test.hostname, expected.hostname); QCOMPARE(test.port, expected.port); QCOMPARE(test.socketType, expected.socketType); QCOMPARE(test.username, expected.username); QCOMPARE(test.authentication, expected.authentication); } void testIdendity(const identity &test, const identity &expected) const { QVERIFY(test.isValid()); QCOMPARE(test.name, expected.name); QCOMPARE(test.email, expected.email); QCOMPARE(test.organization, expected.organization); QCOMPARE(test.signature, expected.signature); QCOMPARE(test.isDefault(), expected.isDefault()); } private Q_SLOTS: void testParsing() { Ispdb *ispdb = execIspdb(QStringLiteral("autoconfig.xml")); Server s; identity i; s.hostname = QStringLiteral("imap.example.com"); s.port = 993; s.socketType = Ispdb::SSL; s.authentication = Ispdb::CramMD5; s.username = QStringLiteral("john.doe@example.com"); QCOMPARE(ispdb->imapServers().count(), 1); testServer(ispdb->imapServers().first(), s); s.hostname = QStringLiteral("smtp.example.com"); s.port = 25; s.socketType = Ispdb::None; s.authentication = Ispdb::Plain; s.username = QStringLiteral("john.doe"); QCOMPARE(ispdb->smtpServers().count(), 1); testServer(ispdb->smtpServers().first(), s); s.hostname = QStringLiteral("pop.example.com"); s.port = 995; s.socketType = Ispdb::StartTLS; s.authentication = Ispdb::NTLM; s.username = QStringLiteral("example.com"); QCOMPARE(ispdb->pop3Servers().count(), 1); testServer(ispdb->pop3Servers().first(), s); i.mDefault = true; i.name = QStringLiteral("John Doe"); i.email = QStringLiteral("john.doe@example.com"); i.organization = QStringLiteral("Example AG"); i.signature = QStringLiteral("John Doe\n\ Head of World\n\ \n\ Example AG\n\ \n\ w: http://example.com"); QCOMPARE(ispdb->identities().count(), 1); testIdendity(ispdb->identities().first(), i); QCOMPARE(ispdb->defaultIdentity(), 0); } }; QTEST_MAIN(IspdbTest) #include "ispdbtest.moc" diff --git a/src/loadpage.cpp b/src/loadpage.cpp index ed43146..538e99a 100644 --- a/src/loadpage.cpp +++ b/src/loadpage.cpp @@ -1,89 +1,89 @@ /* Copyright (c) 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "loadpage.h" #include "global.h" #include #include #include #include -#include +#include #include LoadPage::LoadPage(KAssistantDialog *parent) : Page(parent) , m_action(nullptr) { ui.setupUi(this); setValid(false); } void LoadPage::enterPageNext() { setValid(false); // FIXME: deletion seems to delete the exported objects as well, killing the entire wizard... //delete m_action; m_action = nullptr; Q_EMIT aboutToStart(); const KConfig f(Global::assistant()); KConfigGroup grp(&f, "Wizard"); const QString scriptFile = grp.readEntry("Script", QString()); if (scriptFile.isEmpty()) { ui.statusLabel->setText(i18n("No script specified in '%1'.", Global::assistant())); return; } if (!QFile::exists(Global::assistantBasePath() + scriptFile)) { ui.statusLabel->setText(i18n("Unable to load assistant: File '%1' does not exist.", Global::assistantBasePath() + scriptFile)); return; } ui.statusLabel->setText(i18n("Loading script '%1'...", Global::assistantBasePath() + scriptFile)); m_action = new Kross::Action(this, QStringLiteral("AccountWizard")); typedef QPair ObjectStringPair; for (const ObjectStringPair &exportedObject : qAsConst(m_exportedObjects)) { m_action->addQObject(exportedObject.first, exportedObject.second); } if (!m_action->setFile(Global::assistantBasePath() + scriptFile)) { ui.statusLabel->setText(i18n("Failed to load script: '%1'.", m_action->errorMessage())); return; } KConfigGroup grpTranslate(&f, "Translate"); const QString poFileName = grpTranslate.readEntry("Filename"); if (!poFileName.isEmpty()) { Global::setPoFileName(poFileName); m_action->trigger(); } m_parent->next(); } void LoadPage::enterPageBack() { // TODO: if we are the first page, call enterPageNext(), hm, can we get here then at all? m_parent->back(); } void LoadPage::exportObject(QObject *object, const QString &name) { m_exportedObjects.push_back(qMakePair(object, name)); } diff --git a/src/main.cpp b/src/main.cpp index 34f031e..aaea806 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,88 +1,88 @@ /* Copyright (c) 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "dialog.h" #include "global.h" #include #include -#include +#include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); QApplication app(argc, argv); app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); KLocalizedString::setApplicationDomain("accountwizard"); KCrash::initialize(); KAboutData aboutData(QStringLiteral("accountwizard"), i18n("Account Assistant"), QStringLiteral("0.2"), i18n("Helps setting up PIM accounts"), KAboutLicense::LGPL, i18n("(c) 2009-2019 the Akonadi developers"), QStringLiteral("https://community.kde.org/KDE_PIM/Akonadi")); aboutData.addAuthor(i18n("Volker Krause"), i18n("Author"), QStringLiteral("vkrause@kde.org")); aboutData.addAuthor(i18n("Laurent Montel"), QString(), QStringLiteral("montel@kde.org")); app.setOrganizationDomain(QStringLiteral("kde.org")); app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kontact"))); QCommandLineParser parser; KAboutData::setApplicationData(aboutData); parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("type"), i18n("Only offer accounts that support the given type."), QStringLiteral("type"))); parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("assistant"), i18n("Run the specified assistant."), QStringLiteral("assistant"))); parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("package"), i18n("unpack fullpath on startup and launch that assistant"), QStringLiteral("fullpath"))); aboutData.setupCommandLine(&parser); parser.process(app); aboutData.processCommandLine(&parser); KDBusService service(KDBusService::Unique); Akonadi::ControlGui::start(nullptr); const QString packageArgument = parser.value(QStringLiteral("package")); if (!packageArgument.isEmpty()) { Global::setAssistant(Global::unpackAssistant(QUrl::fromLocalFile(packageArgument))); } else { Global::setAssistant(parser.value(QStringLiteral("assistant"))); } QString typeValue = parser.value(QStringLiteral("type")); if (!typeValue.isEmpty()) { Global::setTypeFilter(typeValue.split(QLatin1Char(','))); } Dialog dlg(nullptr); dlg.show(); // Unregister once the UI is closed, even if the app will continue running // and generating keys in the background. QObject::connect(&dlg, &Dialog::accepted, &service, &KDBusService::unregister); return app.exec(); } diff --git a/src/setuppage.cpp b/src/setuppage.cpp index 2aebe3f..d9ce4d7 100644 --- a/src/setuppage.cpp +++ b/src/setuppage.cpp @@ -1,70 +1,70 @@ /* Copyright (c) 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "setuppage.h" #include -#include +#include SetupPage::SetupPage(KAssistantDialog *parent) : Page(parent) , m_msgModel(new QStandardItemModel(this)) { ui.setupUi(this); ui.detailView->setModel(m_msgModel); connect(ui.detailsButton, &QPushButton::clicked, this, &SetupPage::detailsClicked); } void SetupPage::enterPageNext() { ui.stackWidget->setCurrentIndex(0); } void SetupPage::detailsClicked() { ui.stackWidget->setCurrentIndex(1); } void SetupPage::addMessage(SetupPage::MessageType type, const QString &msg) { QStandardItem *item = new QStandardItem; item->setText(msg); item->setEditable(false); switch (type) { case Success: item->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok"))); break; case Info: item->setIcon(QIcon::fromTheme(QStringLiteral("dialog-information"))); break; case Error: item->setIcon(QIcon::fromTheme(QStringLiteral("dialog-error"))); break; } m_msgModel->appendRow(item); } void SetupPage::setStatus(const QString &msg) { ui.progressLabel->setText(msg); } void SetupPage::setProgress(int percent) { ui.progressBar->setValue(percent); }