diff --git a/src/core/autotests/ruqolatest.cpp b/src/core/autotests/ruqolatest.cpp index 1bfd29aa..af8d9231 100644 --- a/src/core/autotests/ruqolatest.cpp +++ b/src/core/autotests/ruqolatest.cpp @@ -1,36 +1,53 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "ruqolatest.h" #include "ruqola.h" #include +#include + QTEST_MAIN(RuqolaTest) RuqolaTest::RuqolaTest(QObject *parent) : QObject(parent) { } void RuqolaTest::shouldHaveDefaultValue() { Ruqola r(nullptr); QVERIFY(r.accountManager()); QVERIFY(r.applicationData()); } + +void RuqolaTest::shouldDestroy() +{ + // GIVEN + Ruqola *obj = Ruqola::self(); + QPointer pNotification(obj->notification()); + QVERIFY(!pNotification.isNull()); + + // WHEN + Ruqola::destroy(); + + // THEN + QVERIFY(pNotification.isNull()); + // otherwise the process won't exit... +} diff --git a/src/core/autotests/ruqolatest.h b/src/core/autotests/ruqolatest.h index 7beece16..3bc5b002 100644 --- a/src/core/autotests/ruqolatest.h +++ b/src/core/autotests/ruqolatest.h @@ -1,36 +1,38 @@ /* Copyright (c) 2018-2020 Laurent Montel 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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. */ #ifndef RUQOLATEST_H #define RUQOLATEST_H #include class RuqolaTest : public QObject { Q_OBJECT public: explicit RuqolaTest(QObject *parent = nullptr); ~RuqolaTest() = default; + private Q_SLOTS: void shouldHaveDefaultValue(); + void shouldDestroy(); }; #endif // RUQOLATEST_H diff --git a/src/core/ruqola.cpp b/src/core/ruqola.cpp index 6a2f12a4..d0e8d20f 100644 --- a/src/core/ruqola.cpp +++ b/src/core/ruqola.cpp @@ -1,104 +1,111 @@ /* * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "ruqola.h" #include "typingnotification.h" #include "ddpapi/ddpclient.h" #include "notification.h" #include "messagequeue.h" #include "ruqola_debug.h" #include "rocketchataccount.h" #include "accountmanager.h" #include "managerdatapaths.h" #include "aboutdata/qmlaboutdata.h" #include "restapirequest.h" #include +static Ruqola *s_self = nullptr; + Ruqola *Ruqola::self() { - static Ruqola *s_self = nullptr; if (!s_self) { s_self = new Ruqola; // Create systray to show notifications on Desktop #if !defined(Q_OS_ANDROID) || !defined(Q_OS_IOS) s_self->notification(); #endif } return s_self; } +void Ruqola::destroy() +{ + delete s_self; + s_self = nullptr; +} + Ruqola::Ruqola(QObject *parent) : QObject(parent) { //Initialize paths (void)ManagerDataPaths::self(); mAccountManager = new AccountManager(this); connect(mAccountManager, &AccountManager::notification, this, &Ruqola::sendNotification); connect(mAccountManager, &AccountManager::updateNotification, this, &Ruqola::updateNotification); connect(mAccountManager, &AccountManager::logoutAccountDone, this, &Ruqola::logout); mRuqolaAboutData = new QmlAboutData(this); } void Ruqola::setCurrentAccount(const QString &accountName) { mAccountManager->setCurrentAccount(accountName); } AccountManager *Ruqola::accountManager() const { return mAccountManager; } QmlAboutData *Ruqola::applicationData() const { return mRuqolaAboutData; } RocketChatAccount *Ruqola::rocketChatAccount() const { return mAccountManager->account(); } void Ruqola::sendNotification(const QString &title, const QString &message, const QPixmap &pixmap) { KNotification::event(KNotification::Notification, title, message, pixmap); } Notification *Ruqola::notification() { if (!mNotification) { - mNotification = new Notification(); + mNotification = new Notification(this); } return mNotification; } void Ruqola::updateNotification(bool hasAlert, int nbUnread, const QString &accountName) { notification()->updateNotification(hasAlert, nbUnread, accountName); } void Ruqola::logout(const QString &accountName) { notification()->clearNotification(accountName); } diff --git a/src/core/ruqola.h b/src/core/ruqola.h index 54e3aecb..a83b97fb 100644 --- a/src/core/ruqola.h +++ b/src/core/ruqola.h @@ -1,81 +1,83 @@ /* * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef RUQOLA_H #define RUQOLA_H #include #include "libruqolacore_export.h" #include #include #include "ddpapi/ddpclient.h" #include "model/roommodel.h" #include "model/messagemodel.h" #include "notification.h" class QmlAboutData; class RocketChatAccount; class AccountManager; class LIBRUQOLACORE_EXPORT Ruqola : public QObject { Q_OBJECT public: /** * @brief Singleton provider * * @return Returns the singleton object m_self */ static Ruqola *self(); + static void destroy(); + Notification *notification(); Q_INVOKABLE RocketChatAccount *rocketChatAccount() const; Q_INVOKABLE QmlAboutData *applicationData() const; Q_INVOKABLE AccountManager *accountManager() const; explicit Ruqola(QObject *parent = nullptr); void setCurrentAccount(const QString &accountName); private: Q_DISABLE_COPY(Ruqola) void sendNotification(const QString &title, const QString &message, const QPixmap &pixmap); void updateNotification(bool hasAlert, int nbUnread, const QString &accountName); void logout(const QString &accountName); Notification *mNotification = nullptr; QmlAboutData *mRuqolaAboutData = nullptr; AccountManager *mAccountManager = nullptr; }; inline static QObject *ruqola_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) Ruqola *userData = Ruqola::self(); return userData; } #endif // RUQOLA_H diff --git a/src/widgets/ruqolamainwindow.cpp b/src/widgets/ruqolamainwindow.cpp index 6546a09e..21dc0a9c 100644 --- a/src/widgets/ruqolamainwindow.cpp +++ b/src/widgets/ruqolamainwindow.cpp @@ -1,60 +1,63 @@ /* Copyright (c) 2020 Laurent Montel 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "ruqola.h" #include "ruqolamainwindow.h" #include "ruqolacentralwidget.h" #include #include namespace { static const char myConfigGroupName[] = "RuqolaMainWindow"; } RuqolaMainWindow::RuqolaMainWindow(QWidget *parent) : KXmlGuiWindow(parent) { mMainWidget = new RuqolaCentralWidget(this); setCentralWidget(mMainWidget); setupActions(); setupGUI(); readConfig(); } RuqolaMainWindow::~RuqolaMainWindow() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(myConfigGroupName); group.writeEntry("Size", size()); + + Ruqola::destroy(); } void RuqolaMainWindow::readConfig() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = KConfigGroup(config, myConfigGroupName); const QSize sizeDialog = group.readEntry("Size", QSize(800, 600)); if (sizeDialog.isValid()) { resize(sizeDialog); } } void RuqolaMainWindow::setupActions() { }