diff --git a/src/widgets/room/messagelinewidget.cpp b/src/widgets/room/messagelinewidget.cpp index f72ad9e0..efc59b4e 100644 --- a/src/widgets/room/messagelinewidget.cpp +++ b/src/widgets/room/messagelinewidget.cpp @@ -1,62 +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 "messagelineedit.h" #include "messagelinewidget.h" #include "dialogs/uploadfiledialog.h" #include #include #include MessageLineWidget::MessageLineWidget(QWidget *parent) : QWidget(parent) { QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); mSendFile = new QToolButton(this); mSendFile->setObjectName(QStringLiteral("mSendFile")); mainLayout->addWidget(mSendFile); mSendFile->setIcon(QIcon::fromTheme(QStringLiteral("document-send-symbolic"))); connect(mSendFile, &QToolButton::clicked, this, &MessageLineWidget::slotSendFile); mMessageLineEdit = new MessageLineEdit(this); mMessageLineEdit->setObjectName(QStringLiteral("mMessageLineEdit")); mainLayout->addWidget(mMessageLineEdit); connect(mMessageLineEdit, &MessageLineEdit::sendMessage, this, &MessageLineWidget::sendMessage); connect(mMessageLineEdit, &MessageLineEdit::clearNotification, this, &MessageLineWidget::clearNotification); } MessageLineWidget::~MessageLineWidget() { } void MessageLineWidget::slotSendFile() { QPointer dlg = new UploadFileDialog(this); if (dlg->exec()) { const UploadFileDialog::UploadFileInfo result = dlg->fileInfo(); + Q_EMIT sendFile(result); //TODO } delete dlg; } diff --git a/src/widgets/room/messagelinewidget.h b/src/widgets/room/messagelinewidget.h index db77da7a..552269f4 100644 --- a/src/widgets/room/messagelinewidget.h +++ b/src/widgets/room/messagelinewidget.h @@ -1,46 +1,48 @@ /* 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 MESSAGELINEWIDGET_H #define MESSAGELINEWIDGET_H #include +#include "dialogs/uploadfiledialog.h" #include "libruqolawidgets_private_export.h" class MessageLineEdit; class QToolButton; class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageLineWidget : public QWidget { Q_OBJECT public: explicit MessageLineWidget(QWidget *parent = nullptr); ~MessageLineWidget(); Q_SIGNALS: void sendMessage(const QString &str); void clearNotification(); + void sendFile(const UploadFileDialog::UploadFileInfo &result); private: void slotSendFile(); MessageLineEdit *mMessageLineEdit = nullptr; QToolButton *mSendFile = nullptr; }; #endif // MESSAGELINEWIDGET_H diff --git a/src/widgets/room/roomwidget.cpp b/src/widgets/room/roomwidget.cpp index 2499eaee..07cc0234 100644 --- a/src/widgets/room/roomwidget.cpp +++ b/src/widgets/room/roomwidget.cpp @@ -1,88 +1,94 @@ /* 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" 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() { } +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()); //Description ??? } QString RoomWidget::roomId() const { return mRoomId; } void RoomWidget::setRoomId(const QString &roomId) { if (mRoomId != roomId) { mRoomId = roomId; mMessageListView->setChannelSelected(roomId); } } void RoomWidget::slotClearNotification() { Ruqola::self()->rocketChatAccount()->clearUnreadMessages(mRoomId); } diff --git a/src/widgets/room/roomwidget.h b/src/widgets/room/roomwidget.h index 97eedd20..c5fa770f 100644 --- a/src/widgets/room/roomwidget.h +++ b/src/widgets/room/roomwidget.h @@ -1,52 +1,54 @@ /* 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 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(); QString mRoomId; RoomHeaderWidget *mRoomHeaderWidget = nullptr; MessageListView *mMessageListView = nullptr; MessageLineWidget *mMessageLineWidget = nullptr; + void slotSendFile(const UploadFileDialog::UploadFileInfo &uploadFileInfo); }; #endif // ROOMWIDGET_H