diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -3,7 +3,6 @@ ruqolamainwindow.cpp ruqolacentralwidget.cpp ruqolaloginwidget.cpp - ruqolamainwidget.cpp ) set(Ruqola_widgets_dialog_SRCS diff --git a/src/widgets/autotests/CMakeLists.txt b/src/widgets/autotests/CMakeLists.txt --- a/src/widgets/autotests/CMakeLists.txt +++ b/src/widgets/autotests/CMakeLists.txt @@ -9,5 +9,4 @@ add_ruqolawidget_test(ruqolacentralwidgettest.cpp) add_ruqolawidget_test(ruqolaloginwidgettest.cpp) -add_ruqolawidget_test(ruqolamainwidgettest.cpp) add_ruqolawidget_test(ruqolamainwindowtest.cpp) diff --git a/src/widgets/autotests/ruqolamainwidgettest.cpp b/src/widgets/autotests/ruqolamainwidgettest.cpp deleted file mode 100644 --- a/src/widgets/autotests/ruqolamainwidgettest.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - 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 "ruqolamainwidgettest.h" -#include "ruqolamainwidget.h" -#include "channellist/channellistwidget.h" -#include "room/roomwidget.h" - -#include -#include -#include - -QTEST_MAIN(RuqolaMainWidgetTest) - -RuqolaMainWidgetTest::RuqolaMainWidgetTest(QObject *parent) - : QObject(parent) -{ -} - -void RuqolaMainWidgetTest::shouldHaveDefaultValues() -{ - RuqolaMainWidget w; - auto *mainLayout = w.findChild(QStringLiteral("mainlayout")); - QVERIFY(mainLayout); - - auto *mSplitter = w.findChild(QStringLiteral("mSplitter")); - QVERIFY(mSplitter); - QVERIFY(!mSplitter->childrenCollapsible()); - - auto *mChannelList = w.findChild(QStringLiteral("mChannelList")); - QVERIFY(mChannelList); - - auto *mStackedRoomWidget = w.findChild(QStringLiteral("mStackedRoomWidget")); - QVERIFY(mStackedRoomWidget); - - auto *mRoomWidget = w.findChild(QStringLiteral("mRoomWidget")); - QVERIFY(mRoomWidget); - QVERIFY(mSplitter->indexOf(mChannelList) >= 0); - QVERIFY(mSplitter->indexOf(mStackedRoomWidget) >= 0); - - auto *mEmptyRoomWidget = w.findChild(QStringLiteral("mEmptyRoomWidget")); - QVERIFY(mEmptyRoomWidget); - QCOMPARE(mStackedRoomWidget->currentWidget(), mEmptyRoomWidget); -} diff --git a/src/widgets/misc/accountsoverviewwidget.cpp b/src/widgets/misc/accountsoverviewwidget.cpp --- a/src/widgets/misc/accountsoverviewwidget.cpp +++ b/src/widgets/misc/accountsoverviewwidget.cpp @@ -200,8 +200,11 @@ AccountsOverviewWidget::AccountsOverviewWidget(QWidget *parent) : QWidget(parent) { - setLayout(new QHBoxLayout); + setLayout(new QVBoxLayout); const auto model = Ruqola::self()->accountManager()->rocketChatAccountModel(); + connect(model, &RocketChatAccountModel::rowsInserted, this, &AccountsOverviewWidget::updateButtons); + connect(model, &RocketChatAccountModel::rowsRemoved, this, &AccountsOverviewWidget::updateButtons); + connect(model, &RocketChatAccountModel::modelReset, this, &AccountsOverviewWidget::updateButtons); connect(model, &RocketChatAccountModel::accountNumberChanged, this, &AccountsOverviewWidget::updateButtons); updateButtons(); } diff --git a/src/widgets/ruqolacentralwidget.h b/src/widgets/ruqolacentralwidget.h --- a/src/widgets/ruqolacentralwidget.h +++ b/src/widgets/ruqolacentralwidget.h @@ -24,11 +24,14 @@ #include #include #include "libruqolawidgets_private_export.h" + +class ChannelListWidget; class QStackedWidget; class RuqolaMainWidget; class RuqolaLoginWidget; class RocketChatAccount; class RoomWrapper; +class RoomWidget; class LIBRUQOLAWIDGETS_TESTS_EXPORT RuqolaCentralWidget : public QWidget { @@ -48,8 +51,9 @@ void slotJobFailedInfo(const QString &messageError); void slotSocketError(QAbstractSocket::SocketError error, const QString &errorString); + RoomWidget *mRoomWidget = nullptr; QStackedWidget *mStackedWidget = nullptr; - RuqolaMainWidget *mRuqolaMainWidget = nullptr; + ChannelListWidget *mChannelListWidget = nullptr; RuqolaLoginWidget *mRuqolaLoginWidget = nullptr; RocketChatAccount *mCurrentRocketChatAccount = nullptr; }; diff --git a/src/widgets/ruqolacentralwidget.cpp b/src/widgets/ruqolacentralwidget.cpp --- a/src/widgets/ruqolacentralwidget.cpp +++ b/src/widgets/ruqolacentralwidget.cpp @@ -20,11 +20,15 @@ #include "ruqolacentralwidget.h" #include "ruqolaloginwidget.h" -#include "ruqolamainwidget.h" #include "ruqola.h" #include "rocketchataccount.h" +#include "channellist/channellistwidget.h" +#include "room/roomwidget.h" +#include "misc/accountsoverviewwidget.h" + #include #include +#include #include #include @@ -34,20 +38,36 @@ auto *mainLayout = new QHBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainlayout")); + auto hSplitter = new QSplitter(this); + mainLayout->addWidget(hSplitter); + + auto vSplitter = new QSplitter(this); + vSplitter->setOrientation(Qt::Vertical); + hSplitter->addWidget(vSplitter); + + vSplitter->addWidget(new AccountsOverviewWidget(this)); + + mChannelListWidget = new ChannelListWidget(this); + vSplitter->addWidget(mChannelListWidget); + vSplitter->setStretchFactor(1, 1); + mStackedWidget = new QStackedWidget(this); - mStackedWidget->setObjectName(QStringLiteral("mStackedWidget")); - mainLayout->addWidget(mStackedWidget); + hSplitter->addWidget(mStackedWidget); + hSplitter->setStretchFactor(1, 1); - mRuqolaMainWidget = new RuqolaMainWidget(this); - mRuqolaMainWidget->setObjectName(QStringLiteral("mRuqolaMainWidget")); - mStackedWidget->addWidget(mRuqolaMainWidget); + mRoomWidget = new RoomWidget(this); + mStackedWidget->addWidget(mRoomWidget); mRuqolaLoginWidget = new RuqolaLoginWidget(this); mRuqolaLoginWidget->setObjectName(QStringLiteral("mRuqolaLoginWidget")); mStackedWidget->addWidget(mRuqolaLoginWidget); + connect(mChannelListWidget, &ChannelListWidget::channelSelected, this, [this](const QModelIndex &index) { + Q_EMIT mRoomWidget->channelSelected(index); + Q_EMIT channelSelected(); + }); + mStackedWidget->setCurrentWidget(mRuqolaLoginWidget); - connect(mRuqolaMainWidget, &RuqolaMainWidget::channelSelected, this, &RuqolaCentralWidget::channelSelected); } RuqolaCentralWidget::~RuqolaCentralWidget() @@ -70,17 +90,17 @@ RoomWrapper *RuqolaCentralWidget::roomWrapper() const { - return mRuqolaMainWidget->roomWrapper(); + return mRoomWidget->roomWrapper(); } QString RuqolaCentralWidget::roomId() const { - return mRuqolaMainWidget->roomId(); + return mRoomWidget->roomId(); } QString RuqolaCentralWidget::roomType() const { - return mRuqolaMainWidget->roomType(); + return mRoomWidget->roomType(); } void RuqolaCentralWidget::setCurrentRocketChatAccount(RocketChatAccount *account) @@ -93,7 +113,8 @@ connect(mCurrentRocketChatAccount, &RocketChatAccount::loginStatusChanged, this, &RuqolaCentralWidget::slotLoginStatusChanged); connect(mCurrentRocketChatAccount, &RocketChatAccount::socketError, this, &RuqolaCentralWidget::slotSocketError); connect(mCurrentRocketChatAccount, &RocketChatAccount::jobFailed, this, &RuqolaCentralWidget::slotJobFailedInfo); - mRuqolaMainWidget->setCurrentRocketChatAccount(account); + mChannelListWidget->setCurrentRocketChatAccount(account); + mRoomWidget->setCurrentRocketChatAccount(account); //Check if account is connected or not. slotLoginStatusChanged(); } @@ -103,7 +124,7 @@ const auto loginStatus = mCurrentRocketChatAccount->loginStatus(); mRuqolaLoginWidget->setLoginStatus(loginStatus); if (loginStatus == DDPClient::LoggedIn) { - mStackedWidget->setCurrentWidget(mRuqolaMainWidget); + mStackedWidget->setCurrentWidget(mRoomWidget); } else { mStackedWidget->setCurrentWidget(mRuqolaLoginWidget); mRuqolaLoginWidget->initialize(); diff --git a/src/widgets/ruqolamainwidget.h b/src/widgets/ruqolamainwidget.h deleted file mode 100644 --- a/src/widgets/ruqolamainwidget.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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. -*/ - -#ifndef RUQOLAMAINWIDGET_H -#define RUQOLAMAINWIDGET_H - -#include -#include -#include "libruqolawidgets_private_export.h" -class ChannelListWidget; -class RoomWidget; -class QSplitter; -class RocketChatAccount; -class RoomWrapper; -class LIBRUQOLAWIDGETS_TESTS_EXPORT RuqolaMainWidget : public QWidget -{ - Q_OBJECT -public: - explicit RuqolaMainWidget(QWidget *parent = nullptr); - ~RuqolaMainWidget(); - Q_REQUIRED_RESULT QString roomId() const; - void setCurrentRocketChatAccount(RocketChatAccount *account); - Q_REQUIRED_RESULT QString roomType() const; - RoomWrapper *roomWrapper() const; - -Q_SIGNALS: - void channelSelected(); -private: - ChannelListWidget *mChannelList = nullptr; - RoomWidget *mRoomWidget = nullptr; - QSplitter *mSplitter = nullptr; - RocketChatAccount *mCurrentRocketChatAccount = nullptr; - QStackedWidget *mStackedRoomWidget = nullptr; - QWidget *mEmptyRoomWidget = nullptr; -}; - -#endif // RUQOLAMAINWIDGET_H diff --git a/src/widgets/ruqolamainwidget.cpp b/src/widgets/ruqolamainwidget.cpp deleted file mode 100644 --- a/src/widgets/ruqolamainwidget.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - 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 "ruqolamainwidget.h" -#include "channellist/channellistwidget.h" -#include "room/roomwidget.h" - -#include -#include -#include -#include - -namespace { -static const char myConfigGroupName[] = "RuqolaMainWidget"; -} - -RuqolaMainWidget::RuqolaMainWidget(QWidget *parent) - : QWidget(parent) -{ - auto *mainLayout = new QHBoxLayout(this); - mainLayout->setObjectName(QStringLiteral("mainlayout")); - - mSplitter = new QSplitter(this); - mSplitter->setObjectName(QStringLiteral("mSplitter")); - mSplitter->setChildrenCollapsible(false); - mainLayout->addWidget(mSplitter); - - mChannelList = new ChannelListWidget(this); - mChannelList->setObjectName(QStringLiteral("mChannelList")); - mSplitter->addWidget(mChannelList); - - mStackedRoomWidget = new QStackedWidget(this); - mStackedRoomWidget->setObjectName(QStringLiteral("mStackedRoomWidget")); - mSplitter->addWidget(mStackedRoomWidget); - - mRoomWidget = new RoomWidget(this); - mRoomWidget->setObjectName(QStringLiteral("mRoomWidget")); - mStackedRoomWidget->addWidget(mRoomWidget); - - mEmptyRoomWidget = new QWidget(this); - mEmptyRoomWidget->setObjectName(QStringLiteral("mEmptyRoomWidget")); - mStackedRoomWidget->addWidget(mEmptyRoomWidget); - - mStackedRoomWidget->setCurrentWidget(mEmptyRoomWidget); - - connect(mChannelList, &ChannelListWidget::channelSelected, this, [this](const QModelIndex &index) { - Q_EMIT mRoomWidget->channelSelected(index); - mStackedRoomWidget->setCurrentWidget(mRoomWidget); - Q_EMIT channelSelected(); - }); - - KConfigGroup group(KSharedConfig::openConfig(), myConfigGroupName); - mSplitter->restoreState(group.readEntry("SplitterSizes", QByteArray())); - mChannelList->setCurrentSelectedRoom(group.readEntry("SelectedRoom", QString())); -} - -RuqolaMainWidget::~RuqolaMainWidget() -{ - KConfigGroup group(KSharedConfig::openConfig(), myConfigGroupName); - group.writeEntry("SplitterSizes", mSplitter->saveState()); - const QString selectedRoom = mChannelList->currentSelectedRoom(); - if (selectedRoom.isEmpty()) { - group.deleteEntry("SelectedRoom"); - } else { - group.writeEntry("SelectedRoom", selectedRoom); - } -} - -RoomWrapper *RuqolaMainWidget::roomWrapper() const -{ - return mRoomWidget->roomWrapper(); -} - -QString RuqolaMainWidget::roomId() const -{ - return mRoomWidget->roomId(); -} - -QString RuqolaMainWidget::roomType() const -{ - return mRoomWidget->roomType(); -} - -void RuqolaMainWidget::setCurrentRocketChatAccount(RocketChatAccount *account) -{ - mChannelList->setCurrentRocketChatAccount(account); - mRoomWidget->setCurrentRocketChatAccount(account); - mStackedRoomWidget->setCurrentWidget(mEmptyRoomWidget); -} diff --git a/src/widgets/ruqolamainwindow.h b/src/widgets/ruqolamainwindow.h --- a/src/widgets/ruqolamainwindow.h +++ b/src/widgets/ruqolamainwindow.h @@ -88,7 +88,6 @@ AccountMenu *mAccountMenu = nullptr; RocketChatAccount *mCurrentRocketChatAccount = nullptr; QLabel *mStatusBarTypingMessage = nullptr; - AccountsOverviewWidget *mAccountOverviewWidget = nullptr; }; #endif // RUQOLAMAINWINDOW_H diff --git a/src/widgets/ruqolamainwindow.cpp b/src/widgets/ruqolamainwindow.cpp --- a/src/widgets/ruqolamainwindow.cpp +++ b/src/widgets/ruqolamainwindow.cpp @@ -26,7 +26,6 @@ #include "ruqolamainwindow.h" #include "ruqolacentralwidget.h" #include "misc/accountmenu.h" -#include "misc/accountsoverviewwidget.h" #include "dialogs/serverinfodialog.h" #include "dialogs/searchchanneldialog.h" #include "dialogs/createnewchanneldialog.h" @@ -90,8 +89,6 @@ mStatusBarTypingMessage->setTextFormat(Qt::RichText); mStatusBarTypingMessage->setObjectName(QStringLiteral("mStatusBarTypingMessage")); statusBar()->addPermanentWidget(mStatusBarTypingMessage); - mAccountOverviewWidget = new AccountsOverviewWidget(this); - statusBar()->addPermanentWidget(mAccountOverviewWidget); } void RuqolaMainWindow::slotAccountChanged() @@ -389,11 +386,8 @@ void RuqolaMainWindow::slotConfigure() { - QPointer dlg = new ConfigureSettingsDialog(this); - if (dlg->exec()) { - mAccountOverviewWidget->updateButtons(); - } - delete dlg; + QScopedPointer dlg(new ConfigureSettingsDialog(this)); + dlg->exec(); } void RuqolaMainWindow::slotAddAccount()