diff --git a/src/widgets/room/roomwidget.cpp b/src/widgets/room/roomwidget.cpp index 07cc0234..9530120a 100644 --- a/src/widgets/room/roomwidget.cpp +++ b/src/widgets/room/roomwidget.cpp @@ -1,94 +1,117 @@ /* 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 "roomwidget.h" #include "roomheaderwidget.h" #include "messagelistview.h" #include "messagelinewidget.h" #include #include #include "ruqola.h" #include "rocketchataccount.h" +#include RoomWidget::RoomWidget(QWidget *parent) : QWidget(parent) { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mRoomHeaderWidget = new RoomHeaderWidget(this); mRoomHeaderWidget->setObjectName(QStringLiteral("mRoomHeaderWidget")); mainLayout->addWidget(mRoomHeaderWidget); mMessageListView = new MessageListView(this); mMessageListView->setObjectName(QStringLiteral("mMessageListView")); mainLayout->addWidget(mMessageListView); mMessageLineWidget = new MessageLineWidget(this); mMessageLineWidget->setObjectName(QStringLiteral("mMessageLineWidget")); mainLayout->addWidget(mMessageLineWidget); connect(this, &RoomWidget::channelSelected, this, &RoomWidget::setChannelSelected); connect(mMessageLineWidget, &MessageLineWidget::sendMessage, this, &RoomWidget::slotSendMessage); connect(mMessageLineWidget, &MessageLineWidget::clearNotification, this, &RoomWidget::slotClearNotification); connect(mMessageLineWidget, &MessageLineWidget::sendFile, this, &RoomWidget::slotSendFile); } RoomWidget::~RoomWidget() { + delete mRoomWrapper; } void RoomWidget::slotSendFile(const UploadFileDialog::UploadFileInfo &uploadFileInfo) { Ruqola::self()->rocketChatAccount()->uploadFile(mRoomId, uploadFileInfo.description, uploadFileInfo.message, uploadFileInfo.fileUrl); } void RoomWidget::slotSendMessage(const QString &msg) { Ruqola::self()->rocketChatAccount()->sendMessage(mRoomId, msg); } void RoomWidget::setChannelSelected(const QModelIndex &index) { setRoomId(index.data(RoomModel::RoomID).toString()); - mRoomHeaderWidget->setRoomName(index.data(RoomModel::RoomFName).toString()); - mRoomHeaderWidget->setRoomAnnouncement(index.data(RoomModel::RoomAnnouncement).toString()); - mRoomHeaderWidget->setRoomTopic(index.data(RoomModel::RoomTopic).toString()); + //Use roomwrapper here! //Description ??? } +void RoomWidget::updateRoomHeader() +{ + if (mRoomWrapper) { + mRoomHeaderWidget->setRoomName(mRoomWrapper->name()); + mRoomHeaderWidget->setRoomAnnouncement(mRoomWrapper->announcement()); + mRoomHeaderWidget->setRoomTopic(mRoomWrapper->topic()); + } +} + QString RoomWidget::roomId() const { return mRoomId; } void RoomWidget::setRoomId(const QString &roomId) { if (mRoomId != roomId) { mRoomId = roomId; mMessageListView->setChannelSelected(roomId); + delete mRoomWrapper; + mRoomWrapper = Ruqola::self()->rocketChatAccount()->roomWrapper(mRoomId); + if (mRoomWrapper) { + connect(mRoomWrapper, &RoomWrapper::announcementChanged, this, [this]() { + mRoomHeaderWidget->setRoomAnnouncement(mRoomWrapper->announcement()); + }); + connect(mRoomWrapper, &RoomWrapper::topicChanged, this, [this]() { + mRoomHeaderWidget->setRoomTopic(mRoomWrapper->topic()); + }); + connect(mRoomWrapper, &RoomWrapper::nameChanged, this, [this]() { + mRoomHeaderWidget->setRoomName(mRoomWrapper->name()); + }); + updateRoomHeader(); + } } } void RoomWidget::slotClearNotification() { Ruqola::self()->rocketChatAccount()->clearUnreadMessages(mRoomId); } diff --git a/src/widgets/room/roomwidget.h b/src/widgets/room/roomwidget.h index c5fa770f..af7a3798 100644 --- a/src/widgets/room/roomwidget.h +++ b/src/widgets/room/roomwidget.h @@ -1,54 +1,57 @@ /* 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 ROOMWIDGET_H #define ROOMWIDGET_H #include #include "dialogs/uploadfiledialog.h" #include "libruqolawidgets_private_export.h" class RoomHeaderWidget; class MessageListView; class MessageLineWidget; +class RoomWrapper; class LIBRUQOLAWIDGETS_TESTS_EXPORT RoomWidget : public QWidget { Q_OBJECT public: explicit RoomWidget(QWidget *parent = nullptr); ~RoomWidget(); Q_REQUIRED_RESULT QString roomId() const; void setRoomId(const QString &roomId); Q_SIGNALS: void channelSelected(const QModelIndex &index); private: void setChannelSelected(const QModelIndex &index); void slotSendMessage(const QString &msg); void slotClearNotification(); + void slotSendFile(const UploadFileDialog::UploadFileInfo &uploadFileInfo); + void updateRoomHeader(); QString mRoomId; RoomHeaderWidget *mRoomHeaderWidget = nullptr; MessageListView *mMessageListView = nullptr; MessageLineWidget *mMessageLineWidget = nullptr; - void slotSendFile(const UploadFileDialog::UploadFileInfo &uploadFileInfo); + RoomWrapper *mRoomWrapper = nullptr; }; #endif // ROOMWIDGET_H