diff --git a/src/widgets/room/roomwidget.cpp b/src/widgets/room/roomwidget.cpp index 7b7ad581..fe01f03f 100644 --- a/src/widgets/room/roomwidget.cpp +++ b/src/widgets/room/roomwidget.cpp @@ -1,283 +1,285 @@ /* 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 "ruqola.h" #include "rocketchataccount.h" #include "roomwrapper.h" #include "readonlylineeditwidget.h" #include "messagetextedit.h" #include "ruqolawidgets_debug.h" #include #include #include #include #include #include #include RoomWidget::RoomWidget(QWidget *parent) : QWidget(parent) { auto *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, 1); mStackedWidget = new QStackedWidget(this); mStackedWidget->setObjectName(QStringLiteral("mStackedWidget")); mainLayout->addWidget(mStackedWidget); mMessageLineWidget = new MessageLineWidget(this); mMessageLineWidget->setObjectName(QStringLiteral("mMessageLineWidget")); mStackedWidget->addWidget(mMessageLineWidget); mReadOnlyLineEditWidget = new ReadOnlyLineEditWidget(this); mReadOnlyLineEditWidget->setObjectName(QStringLiteral("mReadOnlyLineEditWidget")); mStackedWidget->addWidget(mReadOnlyLineEditWidget); mStackedWidget->setCurrentWidget(mMessageLineWidget); connect(this, &RoomWidget::channelSelected, this, &RoomWidget::setChannelSelected); connect(mMessageLineWidget, &MessageLineWidget::sendMessage, this, &RoomWidget::slotSendMessage); connect(mMessageLineWidget, &MessageLineWidget::sendFile, this, &RoomWidget::slotSendFile); connect(mMessageLineWidget, &MessageLineWidget::textEditing, this, &RoomWidget::slotTextEditing); connect(mMessageLineWidget->messageTextEdit(), &MessageTextEdit::keyPressed, this, &RoomWidget::keyPressedInLineEdit); connect(mRoomHeaderWidget, &RoomHeaderWidget::favoriteChanged, this, &RoomWidget::slotChangeFavorite); connect(mRoomHeaderWidget, &RoomHeaderWidget::encryptedChanged, this, &RoomWidget::slotEncryptedChanged); connect(mRoomHeaderWidget, &RoomHeaderWidget::goBackToRoom, this, &RoomWidget::slotGoBackToRoom); connect(mMessageListView, &MessageListView::editMessageRequested, this, &RoomWidget::slotEditMessage); setAcceptDrops(true); } RoomWidget::~RoomWidget() { delete mRoomWrapper; } void RoomWidget::slotTextEditing(bool clearNotification) { mCurrentRocketChatAccount->textEditing(mRoomId, clearNotification); } void RoomWidget::slotSendFile(const UploadFileDialog::UploadFileInfo &uploadFileInfo) { mCurrentRocketChatAccount->uploadFile(mRoomId, uploadFileInfo.description, QString(), uploadFileInfo.fileUrl); } void RoomWidget::slotSendMessage(const QString &msg) { if (mMessageIdBeingEdited.isEmpty()) { mCurrentRocketChatAccount->sendMessage(mRoomId, msg); } else { mCurrentRocketChatAccount->updateMessage(mRoomId, mMessageIdBeingEdited, msg); mMessageIdBeingEdited.clear(); } mMessageLineWidget->setMode(MessageLineWidget::EditingMode::NewMessage); } void RoomWidget::slotEditMessage(const QString &messageId, const QString &text) { mMessageIdBeingEdited = messageId; mMessageLineWidget->setMode(MessageLineWidget::EditingMode::EditMessage); mMessageLineWidget->setText(text); mMessageLineWidget->setFocus(); } void RoomWidget::dragEnterEvent(QDragEnterEvent *event) { const QMimeData *mimeData = event->mimeData(); if (mimeData->hasUrls()) { event->accept(); } } void RoomWidget::dropEvent(QDropEvent *event) { const QMimeData *mimeData = event->mimeData(); if (mimeData->hasUrls()) { const QList urls = mimeData->urls(); for (const QUrl &url : urls) { if (url.isLocalFile()) { QPointer dlg = new UploadFileDialog(this); dlg->setFileUrl(url); if (dlg->exec()) { const UploadFileDialog::UploadFileInfo uploadFileInfo = dlg->fileInfo(); slotSendFile(uploadFileInfo); } } } } } void RoomWidget::setChannelSelected(const QModelIndex &index) { if (mMessageLineWidget->text().isEmpty()) { mPendingTypedTexts.remove(mRoomId); } else { PendingTypedInfo info; info.text = mMessageLineWidget->text(); info.messageIdBeingEdited = mMessageIdBeingEdited; mPendingTypedTexts[mRoomId] = info; } const QString roomId = index.data(RoomModel::RoomID).toString(); setRoomId(roomId); setRoomType(index.data(RoomModel::RoomType).toString()); const PendingTypedInfo currentPendingInfo = mPendingTypedTexts.value(roomId); mMessageLineWidget->setText(currentPendingInfo.text); mMessageIdBeingEdited = currentPendingInfo.messageIdBeingEdited; mMessageLineWidget->setMode(mMessageIdBeingEdited.isEmpty() ? MessageLineWidget::EditingMode::NewMessage : MessageLineWidget::EditingMode::EditMessage); mMessageLineWidget->setFocus(); } void RoomWidget::updateRoomHeader() { if (mRoomWrapper) { mRoomHeaderWidget->setRoomName(mRoomWrapper->displayRoomName()); mRoomHeaderWidget->setRoomAnnouncement(mRoomWrapper->announcement()); mRoomHeaderWidget->setRoomTopic(mRoomWrapper->topic()); mRoomHeaderWidget->setFavoriteStatus(mRoomWrapper->favorite()); mRoomHeaderWidget->setEncypted(mRoomWrapper->encrypted()); mRoomHeaderWidget->setIsDiscussion(mRoomWrapper->isDiscussionRoom()); //TODO Description ? if (mRoomWrapper->roomMessageInfo().isEmpty()) { mStackedWidget->setCurrentWidget(mMessageLineWidget); } else { mStackedWidget->setCurrentWidget(mReadOnlyLineEditWidget); mReadOnlyLineEditWidget->setMessage(mRoomWrapper->roomMessageInfo()); } } else { //Hide it } } QString RoomWidget::roomId() const { return mRoomId; } void RoomWidget::setRoomType(const QString &roomType) { mRoomType = roomType; } RoomWrapper *RoomWidget::roomWrapper() const { return mRoomWrapper; } void RoomWidget::setRoomId(const QString &roomId) { mRoomId = roomId; delete mRoomWrapper; mRoomWrapper = mCurrentRocketChatAccount->roomWrapper(mRoomId); connectRoomWrapper(); mMessageListView->setChannelSelected(roomId); } void RoomWidget::connectRoomWrapper() { 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()); }); connect(mRoomWrapper, &RoomWrapper::favoriteChanged, this, [this]() { mRoomHeaderWidget->setFavoriteStatus(mRoomWrapper->favorite()); }); connect(mRoomWrapper, &RoomWrapper::encryptedChanged, this, [this]() { mRoomHeaderWidget->setEncypted(mRoomWrapper->encrypted()); }); } updateRoomHeader(); } void RoomWidget::slotClearNotification() { mCurrentRocketChatAccount->clearUnreadMessages(mRoomId); } void RoomWidget::slotEncryptedChanged(bool b) { qCWarning(RUQOLAWIDGETS_LOG) << "change encrypted not supported yet"; //TODO mCurrentRocketChatAccount->slot } void RoomWidget::slotChangeFavorite(bool b) { mCurrentRocketChatAccount->changeFavorite(mRoomId, b); } void RoomWidget::keyPressedInLineEdit(QKeyEvent *ev) { if (ev->key() == Qt::Key_Escape) { if (!mMessageIdBeingEdited.isEmpty()) { mMessageIdBeingEdited.clear(); mMessageLineWidget->setText(QString()); } else { slotClearNotification(); } ev->accept(); } else { mMessageListView->handleKeyPressEvent(ev); } } QString RoomWidget::roomType() const { return mRoomType; } void RoomWidget::setCurrentRocketChatAccount(RocketChatAccount *account) { mCurrentRocketChatAccount = account; mMessageLineWidget->setCurrentRocketChatAccount(account); mRoomId.clear(); //Clear it otherwise if we switch between two account with same roomId (as "GENERAL") we will see incorrect room. } void RoomWidget::slotGoBackToRoom() { + Q_EMIT selectChannelRequested(mRoomWrapper->parentRid()); + //TODO setChannelSelected(); //TODO fix me ! qDebug() << " void RoomWidget::slotGoBackToRoom()" <parentRid(); mCurrentRocketChatAccount->switchingToRoom(mRoomWrapper->parentRid()); //FIX select channel ! } diff --git a/src/widgets/room/roomwidget.h b/src/widgets/room/roomwidget.h index 83eb2eb9..edc2c1db 100644 --- a/src/widgets/room/roomwidget.h +++ b/src/widgets/room/roomwidget.h @@ -1,92 +1,93 @@ /* 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 #include "dialogs/uploadfiledialog.h" #include "libruqolawidgets_private_export.h" class RoomHeaderWidget; class MessageListView; class MessageLineWidget; class RoomWrapper; class ReadOnlyLineEditWidget; class QStackedWidget; class RocketChatAccount; 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); void setCurrentRocketChatAccount(RocketChatAccount *account); Q_REQUIRED_RESULT QString roomType() const; RoomWrapper *roomWrapper() const; Q_SIGNALS: void channelSelected(const QModelIndex &index); + void selectChannelRequested(const QString &channelId); protected: void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override; private: void setChannelSelected(const QModelIndex &index); void slotSendMessage(const QString &msg); void slotEditMessage(const QString &messageId, const QString &text); void slotClearNotification(); void slotSendFile(const UploadFileDialog::UploadFileInfo &uploadFileInfo); void updateRoomHeader(); void connectRoomWrapper(); void slotChangeFavorite(bool b); void keyPressedInLineEdit(QKeyEvent *ev); void setRoomType(const QString &roomType); void slotEncryptedChanged(bool b); void slotTextEditing(bool clearNotification); void slotGoBackToRoom(); QString mRoomId; QString mRoomType; QString mMessageIdBeingEdited; struct PendingTypedInfo { QString text; QString messageIdBeingEdited; }; QMap mPendingTypedTexts; RoomHeaderWidget *mRoomHeaderWidget = nullptr; MessageListView *mMessageListView = nullptr; MessageLineWidget *mMessageLineWidget = nullptr; RoomWrapper *mRoomWrapper = nullptr; QStackedWidget *mStackedWidget = nullptr; ReadOnlyLineEditWidget *mReadOnlyLineEditWidget = nullptr; RocketChatAccount *mCurrentRocketChatAccount = nullptr; }; #endif // ROOMWIDGET_H diff --git a/src/widgets/ruqolamainwidget.cpp b/src/widgets/ruqolamainwidget.cpp index 51f019c7..007e76b4 100644 --- a/src/widgets/ruqolamainwidget.cpp +++ b/src/widgets/ruqolamainwidget.cpp @@ -1,106 +1,112 @@ /* 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); + connect(mRoomWidget, &RoomWidget::selectChannelRequested, this, &RuqolaMainWidget::slotSelectChannelRequested); 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); } + +void RuqolaMainWidget::slotSelectChannelRequested(const QString &channelId) +{ + //TODO find channelId +} diff --git a/src/widgets/ruqolamainwidget.h b/src/widgets/ruqolamainwidget.h index b163ba6b..c78d1edd 100644 --- a/src/widgets/ruqolamainwidget.h +++ b/src/widgets/ruqolamainwidget.h @@ -1,54 +1,55 @@ /* 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: + void slotSelectChannelRequested(const QString &channelId); ChannelListWidget *mChannelList = nullptr; RoomWidget *mRoomWidget = nullptr; QSplitter *mSplitter = nullptr; RocketChatAccount *mCurrentRocketChatAccount = nullptr; QStackedWidget *mStackedRoomWidget = nullptr; QWidget *mEmptyRoomWidget = nullptr; }; #endif // RUQOLAMAINWIDGET_H