diff --git a/src/widgets/dialogs/channelinfodialog.cpp b/src/widgets/dialogs/channelinfodialog.cpp index c0942079..506a4afa 100644 --- a/src/widgets/dialogs/channelinfodialog.cpp +++ b/src/widgets/dialogs/channelinfodialog.cpp @@ -1,45 +1,50 @@ /* 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 "channelinfodialog.h" #include "channelinfowidget.h" #include #include #include ChannelInfoDialog::ChannelInfoDialog(QWidget *parent) : QDialog(parent) { setWindowTitle(i18nc("@title:window", "Channel Info")); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mChannelInfoWidget = new ChannelInfoWidget(this); mChannelInfoWidget->setObjectName(QStringLiteral("mChannelInfoWidget")); mainLayout->addWidget(mChannelInfoWidget); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this); connect(buttonBox, &QDialogButtonBox::rejected, this, &ChannelInfoDialog::reject); mainLayout->addWidget(buttonBox); } ChannelInfoDialog::~ChannelInfoDialog() { } + +void ChannelInfoDialog::setCanBeModified(bool editable) +{ + mChannelInfoWidget->setCanBeModified(editable); +} diff --git a/src/widgets/dialogs/channelinfodialog.h b/src/widgets/dialogs/channelinfodialog.h index 8e229b19..7dbaee35 100644 --- a/src/widgets/dialogs/channelinfodialog.h +++ b/src/widgets/dialogs/channelinfodialog.h @@ -1,37 +1,38 @@ /* 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 CHANNELINFODIALOG_H #define CHANNELINFODIALOG_H #include #include "libruqolawidgets_private_export.h" class ChannelInfoWidget; class LIBRUQOLAWIDGETS_TESTS_EXPORT ChannelInfoDialog : public QDialog { Q_OBJECT public: explicit ChannelInfoDialog(QWidget *parent = nullptr); ~ChannelInfoDialog(); + void setCanBeModified(bool editable); private: ChannelInfoWidget *mChannelInfoWidget = nullptr; }; #endif // CHANNELINFODIALOG_H diff --git a/src/widgets/dialogs/channelinfowidget.cpp b/src/widgets/dialogs/channelinfowidget.cpp index 5f9708fc..dff1167b 100644 --- a/src/widgets/dialogs/channelinfowidget.cpp +++ b/src/widgets/dialogs/channelinfowidget.cpp @@ -1,84 +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. */ #include "channelinfowidget.h" #include #include #include #include #include #include ChannelInfoWidget::ChannelInfoWidget(QWidget *parent) : QWidget(parent) { QFormLayout *layout = new QFormLayout(this); layout->setObjectName(QStringLiteral("layout")); layout->setContentsMargins(0, 0, 0, 0); mName = new KLineEdit(this); mName->setObjectName(QStringLiteral("mName")); mName->setTrapReturnKey(true); mName->setClearButtonEnabled(true); layout->addRow(i18n("Name:"), mName); mComment = new KLineEdit(this); mComment->setObjectName(QStringLiteral("mComment")); mComment->setTrapReturnKey(true); mComment->setClearButtonEnabled(true); layout->addRow(i18n("Comment:"), mComment); mAnnouncement = new KLineEdit(this); mAnnouncement->setObjectName(QStringLiteral("mAnnouncement")); mAnnouncement->setTrapReturnKey(true); mAnnouncement->setClearButtonEnabled(true); layout->addRow(i18n("Annoucement:"), mAnnouncement); mDescription = new KLineEdit(this); mDescription->setObjectName(QStringLiteral("mDescription")); mDescription->setTrapReturnKey(true); mDescription->setClearButtonEnabled(true); layout->addRow(i18n("Description:"), mDescription); mPasswordLineEdit = new KPasswordLineEdit(this); mPasswordLineEdit->setObjectName(QStringLiteral("mPasswordLineEdit")); layout->addRow(i18n("Password:"), mPasswordLineEdit); mReadOnly = new QCheckBox(this); mReadOnly->setObjectName(QStringLiteral("mReadOnly")); layout->addRow(i18n("ReadOnly:"), mReadOnly); mArchive = new QCheckBox(this); mArchive->setObjectName(QStringLiteral("mArchive")); layout->addRow(i18n("Archive:"), mArchive); mPrivate = new QCheckBox(this); mPrivate->setObjectName(QStringLiteral("mPrivate")); layout->addRow(i18n("Private:"), mPrivate); mDeleteChannel = new QPushButton(i18n("Delete"), this); //TODO add icons! mDeleteChannel->setObjectName(QStringLiteral("mDeleteChannel")); layout->addRow(QStringLiteral(" "), mDeleteChannel); } ChannelInfoWidget::~ChannelInfoWidget() { } +//Set roomWrapper here directly +void ChannelInfoWidget::setCanBeModified(bool editable) +{ + //TODO + mName->setReadOnly(!editable); + mComment->setReadOnly(!editable); + mAnnouncement->setReadOnly(!editable); + mDescription->setReadOnly(!editable); +} diff --git a/src/widgets/dialogs/channelinfowidget.h b/src/widgets/dialogs/channelinfowidget.h index 3c160dbc..a3eee1bd 100644 --- a/src/widgets/dialogs/channelinfowidget.h +++ b/src/widgets/dialogs/channelinfowidget.h @@ -1,48 +1,49 @@ /* 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 CHANNELINFOWIDGET_H #define CHANNELINFOWIDGET_H #include #include "libruqolawidgets_export.h" class KLineEdit; class KPasswordLineEdit; class QCheckBox; class QPushButton; class LIBRUQOLAWIDGETS_EXPORT ChannelInfoWidget : public QWidget { Q_OBJECT public: explicit ChannelInfoWidget(QWidget *parent = nullptr); ~ChannelInfoWidget(); + void setCanBeModified(bool editable); private: KLineEdit *mName = nullptr; KLineEdit *mComment = nullptr; KLineEdit *mAnnouncement = nullptr; KLineEdit *mDescription = nullptr; KPasswordLineEdit *mPasswordLineEdit = nullptr; QCheckBox *mReadOnly = nullptr; QCheckBox *mArchive = nullptr; QCheckBox *mPrivate = nullptr; QPushButton *mDeleteChannel = nullptr; }; #endif // CHANNELINFOWIDGET_H diff --git a/src/widgets/room/roomwidget.cpp b/src/widgets/room/roomwidget.cpp index b239e2dc..56ca10e7 100644 --- a/src/widgets/room/roomwidget.cpp +++ b/src/widgets/room/roomwidget.cpp @@ -1,199 +1,204 @@ /* 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 #include #include #include #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); 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); mStackedWidget->setMaximumHeight(mMessageLineWidget->height()); 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); connect(mRoomHeaderWidget, &RoomHeaderWidget::favoriteChanged, this, &RoomWidget::slotChangeFavorite); connect(mMessageListView, &MessageListView::keyPressed, this, &RoomWidget::keyPressedInListView); connect(mMessageListView, &MessageListView::editMessageRequested, this, &RoomWidget::slotEditMessage); } RoomWidget::~RoomWidget() { delete mRoomWrapper; } 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(); } } void RoomWidget::slotEditMessage(const QString &messageId, const QString &text) { mMessageIdBeingEdited = messageId; mMessageLineWidget->setText(text); mMessageLineWidget->setFocus(); } void RoomWidget::setChannelSelected(const QModelIndex &index) { setRoomId(index.data(RoomModel::RoomID).toString()); setRoomType(index.data(RoomModel::RoomType).toString()); mMessageLineWidget->setFocus(); } void RoomWidget::updateRoomHeader() { if (mRoomWrapper) { mRoomHeaderWidget->setRoomName(mRoomWrapper->name()); mRoomHeaderWidget->setRoomAnnouncement(mRoomWrapper->announcement()); mRoomHeaderWidget->setRoomTopic(mRoomWrapper->topic()); mRoomHeaderWidget->setFavoriteStatus(mRoomWrapper->favorite()); //TODO Description ? if (mRoomWrapper->readOnly()) { mStackedWidget->setCurrentWidget(mReadOnlyLineEditWidget); } else { mStackedWidget->setCurrentWidget(mMessageLineWidget); } } 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) { if (mRoomId != roomId) { mRoomId = roomId; mMessageListView->setChannelSelected(roomId); delete mRoomWrapper; mRoomWrapper = mCurrentRocketChatAccount->roomWrapper(mRoomId); connectRoomWrapper(); } } 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()); }); updateRoomHeader(); } } void RoomWidget::slotClearNotification() { mCurrentRocketChatAccount->clearUnreadMessages(mRoomId); } void RoomWidget::slotChangeFavorite(bool b) { mCurrentRocketChatAccount->changeFavorite(mRoomId, b); } void RoomWidget::keyPressedInListView(QKeyEvent *ev) { if (ev->key() == Qt::Key_Escape) { slotClearNotification(); } else { mMessageLineWidget->setFocus(); qApp->sendEvent(mMessageLineWidget, ev); } } QString RoomWidget::roomType() const { return mRoomType; } void RoomWidget::setCurrentRocketChatAccount(RocketChatAccount *account) { mCurrentRocketChatAccount = account; mMessageLineWidget->setCurrentRocketChatAccount(account); } diff --git a/src/widgets/room/roomwidget.h b/src/widgets/room/roomwidget.h index d9e10eb9..b02bdc8b 100644 --- a/src/widgets/room/roomwidget.h +++ b/src/widgets/room/roomwidget.h @@ -1,76 +1,78 @@ /* 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 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); 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 keyPressedInListView(QKeyEvent *ev); void setRoomType(const QString &roomType); QString mRoomId; QString mRoomType; QString mMessageIdBeingEdited; 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/ruqolacentralwidget.cpp b/src/widgets/ruqolacentralwidget.cpp index 3d72ac5f..cc5b4b6c 100644 --- a/src/widgets/ruqolacentralwidget.cpp +++ b/src/widgets/ruqolacentralwidget.cpp @@ -1,93 +1,98 @@ /* 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 "ruqolacentralwidget.h" #include "ruqolaloginwidget.h" #include "ruqolamainwidget.h" #include "ruqola.h" #include "rocketchataccount.h" #include #include #include #include RuqolaCentralWidget::RuqolaCentralWidget(QWidget *parent) : QWidget(parent) { QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainlayout")); mStackedWidget = new QStackedWidget(this); mStackedWidget->setObjectName(QStringLiteral("mStackedWidget")); mainLayout->addWidget(mStackedWidget); mRuqolaMainWidget = new RuqolaMainWidget(this); mRuqolaMainWidget->setObjectName(QStringLiteral("mRuqolaMainWidget")); mStackedWidget->addWidget(mRuqolaMainWidget); mRuqolaLoginWidget = new RuqolaLoginWidget(this); mRuqolaLoginWidget->setObjectName(QStringLiteral("mRuqolaLoginWidget")); mStackedWidget->addWidget(mRuqolaLoginWidget); mStackedWidget->setCurrentWidget(mRuqolaLoginWidget); } RuqolaCentralWidget::~RuqolaCentralWidget() { } void RuqolaCentralWidget::slotJobFailedInfo(const QString &messageError) { //TODO fix i18n KMessageBox::error(this, messageError, i18n("Job Failed")); } +RoomWrapper *RuqolaCentralWidget::roomWrapper() const +{ + return mRuqolaMainWidget->roomWrapper(); +} + QString RuqolaCentralWidget::roomId() const { return mRuqolaMainWidget->roomId(); } QString RuqolaCentralWidget::roomType() const { return mRuqolaMainWidget->roomType(); } void RuqolaCentralWidget::setCurrentRocketChatAccount(RocketChatAccount *account) { if (mCurrentRocketChatAccount) { disconnect(mCurrentRocketChatAccount, nullptr, this, nullptr); } mCurrentRocketChatAccount = account; connect(mCurrentRocketChatAccount, &RocketChatAccount::loginStatusChanged, this, &RuqolaCentralWidget::slotLoginStatusChanged); connect(mCurrentRocketChatAccount, &RocketChatAccount::jobFailed, this, &RuqolaCentralWidget::slotJobFailedInfo); mRuqolaMainWidget->setCurrentRocketChatAccount(account); } void RuqolaCentralWidget::slotLoginStatusChanged() { const auto loginStatus = mCurrentRocketChatAccount->loginStatus(); mRuqolaLoginWidget->setLogginStatus(loginStatus); if (loginStatus == DDPClient::LoggedIn) { mStackedWidget->setCurrentWidget(mRuqolaMainWidget); } else { mStackedWidget->setCurrentWidget(mRuqolaLoginWidget); mRuqolaLoginWidget->initialize(); } } diff --git a/src/widgets/ruqolacentralwidget.h b/src/widgets/ruqolacentralwidget.h index 1dcb42da..20b78172 100644 --- a/src/widgets/ruqolacentralwidget.h +++ b/src/widgets/ruqolacentralwidget.h @@ -1,49 +1,51 @@ /* 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 RUQOLACENTRALWIDGET_H #define RUQOLACENTRALWIDGET_H #include #include "libruqolawidgets_private_export.h" class QStackedWidget; class RuqolaMainWidget; class RuqolaLoginWidget; class RocketChatAccount; +class RoomWrapper; class LIBRUQOLAWIDGETS_TESTS_EXPORT RuqolaCentralWidget : public QWidget { Q_OBJECT public: explicit RuqolaCentralWidget(QWidget *parent = nullptr); ~RuqolaCentralWidget(); Q_REQUIRED_RESULT QString roomId() const; void setCurrentRocketChatAccount(RocketChatAccount *account); Q_REQUIRED_RESULT QString roomType() const; + RoomWrapper *roomWrapper() const; private: void slotLoginStatusChanged(); void slotJobFailedInfo(const QString &messageError); QStackedWidget *mStackedWidget = nullptr; RuqolaMainWidget *mRuqolaMainWidget = nullptr; RuqolaLoginWidget *mRuqolaLoginWidget = nullptr; RocketChatAccount *mCurrentRocketChatAccount = nullptr; }; #endif // RUQOLACENTRALWIDGET_H diff --git a/src/widgets/ruqolamainwidget.cpp b/src/widgets/ruqolamainwidget.cpp index 6e315a69..a83f4f43 100644 --- a/src/widgets/ruqolamainwidget.cpp +++ b/src/widgets/ruqolamainwidget.cpp @@ -1,86 +1,91 @@ /* 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) { QHBoxLayout *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); mRoomWidget = new RoomWidget(this); mRoomWidget->setObjectName(QStringLiteral("mRoomWidget")); mSplitter->addWidget(mRoomWidget); connect(mChannelList, &ChannelListWidget::channelSelected, mRoomWidget, &RoomWidget::channelSelected); KConfigGroup group(KSharedConfig::openConfig(), myConfigGroupName); mSplitter->restoreState(group.readEntry("SplitterSizes", QByteArray())); mChannelList->setCurrentSelectedRoom(group.readEntry("SelectedGroup", QString())); } RuqolaMainWidget::~RuqolaMainWidget() { KConfigGroup group(KSharedConfig::openConfig(), myConfigGroupName); group.writeEntry("SplitterSizes", mSplitter->saveState()); const QString selectedRoom = mChannelList->currentSelectedRoom(); if (selectedRoom.isEmpty()) { group.deleteEntry("SelectedGroup"); } else { group.writeEntry("SelectedGroup", 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); } diff --git a/src/widgets/ruqolamainwidget.h b/src/widgets/ruqolamainwidget.h index 7ea3804b..80c7291b 100644 --- a/src/widgets/ruqolamainwidget.h +++ b/src/widgets/ruqolamainwidget.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 RUQOLAMAINWIDGET_H #define RUQOLAMAINWIDGET_H #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; private: ChannelListWidget *mChannelList = nullptr; RoomWidget *mRoomWidget = nullptr; QSplitter *mSplitter = nullptr; RocketChatAccount *mCurrentRocketChatAccount = nullptr; }; #endif // RUQOLAMAINWIDGET_H diff --git a/src/widgets/ruqolamainwindow.cpp b/src/widgets/ruqolamainwindow.cpp index 889fedd7..ce3c0a4f 100644 --- a/src/widgets/ruqolamainwindow.cpp +++ b/src/widgets/ruqolamainwindow.cpp @@ -1,374 +1,379 @@ /* 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 "rocketchataccount.h" #include "accountmanager.h" +#include "roomwrapper.h" #include "receivetypingnotificationmanager.h" #include "ruqolamainwindow.h" #include "ruqolacentralwidget.h" #include "misc/accountmenu.h" #include "dialogs/serverinfodialog.h" #include "dialogs/searchchanneldialog.h" #include "dialogs/createnewchanneldialog.h" #include "dialogs/createnewaccountdialog.h" #include "dialogs/showpinnedmessagesdialog.h" #include "dialogs/showstarredmessagesdialog.h" #include "dialogs/showmentionsmessagesdialog.h" #include "dialogs/showsnipperedmessagesdialog.h" #include "dialogs/searchmessagedialog.h" #include "dialogs/configurenotificationdialog.h" #include "dialogs/showattachmentdialog.h" #include "dialogs/showdiscussionsdialog.h" #include "dialogs/channelpassworddialog.h" #include "dialogs/channelinfodialog.h" #include "dialogs/directchannelinfodialog.h" #include "configuredialog/configuresettingsdialog.h" #include #include #include #include #include #include #include #include namespace { static const char myConfigGroupName[] = "RuqolaMainWindow"; } RuqolaMainWindow::RuqolaMainWindow(QWidget *parent) : KXmlGuiWindow(parent) { mMainWidget = new RuqolaCentralWidget(this); mMainWidget->setObjectName(QStringLiteral("mMainWidget")); setCentralWidget(mMainWidget); setupActions(); setupStatusBar(); setupGUI(KXmlGuiWindow::Default, QStringLiteral(":/kxmlgui5/ruqola/ruqolaui.rc")); readConfig(); connect(Ruqola::self()->accountManager(), &AccountManager::currentAccountChanged, this, &RuqolaMainWindow::slotAccountChanged); slotAccountChanged(); } RuqolaMainWindow::~RuqolaMainWindow() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(myConfigGroupName); group.writeEntry("Size", size()); Ruqola::destroy(); } void RuqolaMainWindow::setupStatusBar() { mStatusBarTypingMessage = new QLabel(this); mStatusBarTypingMessage->setTextFormat(Qt::RichText); mStatusBarTypingMessage->setObjectName(QStringLiteral("mStatusBarTypingMessage")); statusBar()->addPermanentWidget(mStatusBarTypingMessage); } void RuqolaMainWindow::slotAccountChanged() { if (mCurrentRocketChatAccount) { disconnect(mCurrentRocketChatAccount, nullptr, this, nullptr); } mCurrentRocketChatAccount = Ruqola::self()->rocketChatAccount(); connect(mCurrentRocketChatAccount->receiveTypingNotificationManager(), &ReceiveTypingNotificationManager::notificationChanged, this, &RuqolaMainWindow::slotTypingNotificationChanged); connect(mCurrentRocketChatAccount->receiveTypingNotificationManager(), &ReceiveTypingNotificationManager::clearNotification, this, &RuqolaMainWindow::slotClearNotification); connect(mCurrentRocketChatAccount, &RocketChatAccount::missingChannelPassword, this, &RuqolaMainWindow::slotMissingChannelPassword); mMainWidget->setCurrentRocketChatAccount(mCurrentRocketChatAccount); updateActions(); } void RuqolaMainWindow::updateActions() { mUnreadOnTop->setChecked(mCurrentRocketChatAccount->sortUnreadOnTop()); } 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::slotClearNotification() { mStatusBarTypingMessage->clear(); } void RuqolaMainWindow::slotTypingNotificationChanged(const QString &roomId, const QString ¬ificationStr) { if (mMainWidget->roomId() == roomId) { mStatusBarTypingMessage->setText(notificationStr); } } void RuqolaMainWindow::setupActions() { KActionCollection *ac = actionCollection(); KStandardAction::quit(this, &RuqolaMainWindow::close, ac); KStandardAction::preferences(this, &RuqolaMainWindow::slotConfigure, ac); QAction *act = new QAction(i18n("Add Account..."), this); connect(act, &QAction::triggered, this, &RuqolaMainWindow::slotAddAccount); ac->addAction(QStringLiteral("add_account"), act); //Move in specific server widget mServerInfo = new QAction(i18n("Server Info..."), this); connect(mServerInfo, &QAction::triggered, this, &RuqolaMainWindow::slotServerInfo); ac->addAction(QStringLiteral("server_info"), mServerInfo); mLogout = new QAction(i18n("Logout"), this); connect(mLogout, &QAction::triggered, this, &RuqolaMainWindow::slotLogout); ac->addAction(QStringLiteral("logout"), mLogout); mSearchChannel = new QAction(i18n("Search Channel..."), this); connect(mSearchChannel, &QAction::triggered, this, &RuqolaMainWindow::slotSearchChannel); ac->addAction(QStringLiteral("search_channel"), mSearchChannel); mCreateNewChannel = new QAction(i18n("Create New Channel..."), this); connect(mCreateNewChannel, &QAction::triggered, this, &RuqolaMainWindow::slotCreateNewChannel); ac->addAction(QStringLiteral("create_new_channel"), mCreateNewChannel); mShowMentions = new QAction(i18n("Show Mentions..."), this); connect(mShowMentions, &QAction::triggered, this, &RuqolaMainWindow::slotShowMentions); ac->addAction(QStringLiteral("show_mentions"), mShowMentions); mShowPinnedMessages = new QAction(i18n("Show Pinned Messages..."), this); connect(mShowPinnedMessages, &QAction::triggered, this, &RuqolaMainWindow::slotPinnedMessages); ac->addAction(QStringLiteral("show_pinned_messages"), mShowPinnedMessages); mShowStarredMessages = new QAction(i18n("Show Starred Messages..."), this); connect(mShowStarredMessages, &QAction::triggered, this, &RuqolaMainWindow::slotStarredMessages); ac->addAction(QStringLiteral("show_starred_messages"), mShowStarredMessages); mShowSnipperedMessages = new QAction(i18n("Show Snippered Messages..."), this); connect(mShowSnipperedMessages, &QAction::triggered, this, &RuqolaMainWindow::slotSnipperedMessages); ac->addAction(QStringLiteral("show_snippered_messages"), mShowSnipperedMessages); mSearchMessages = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("Search Messages..."), this); connect(mSearchMessages, &QAction::triggered, this, &RuqolaMainWindow::slotSearchMessages); ac->addAction(QStringLiteral("search_messages"), mSearchMessages); mConfigureNotification = new QAction(QIcon::fromTheme(QStringLiteral("preferences-desktop-notification")), i18n("Configure Notification..."), this); connect(mConfigureNotification, &QAction::triggered, this, &RuqolaMainWindow::slotConfigureNotification); ac->addAction(QStringLiteral("configure_notification"), mConfigureNotification); mLoadChannelHistory = new QAction(i18n("Load Recent History"), this); connect(mLoadChannelHistory, &QAction::triggered, this, &RuqolaMainWindow::slotLoadRecentHistory); ac->addAction(QStringLiteral("load_recent_history"), mLoadChannelHistory); mShowFileAttachments = new QAction(i18n("Show File Attachment..."), this); connect(mShowFileAttachments, &QAction::triggered, this, &RuqolaMainWindow::slotShowFileAttachments); ac->addAction(QStringLiteral("show_file_attachments"), mShowFileAttachments); mAccountMenu = new AccountMenu(this); ac->addAction(QStringLiteral("account_menu"), mAccountMenu); mShowDiscussions = new QAction(i18n("Show Discussions..."), this); connect(mShowDiscussions, &QAction::triggered, this, &RuqolaMainWindow::slotShowDiscussions); ac->addAction(QStringLiteral("show_discussions"), mShowDiscussions); mShowThreads = new QAction(i18n("Show Threads..."), this); connect(mShowThreads, &QAction::triggered, this, &RuqolaMainWindow::slotShowThreads); ac->addAction(QStringLiteral("show_threads"), mShowThreads); mUnreadOnTop = new QAction(i18n("Unread on Top"), this); mUnreadOnTop->setCheckable(true); connect(mUnreadOnTop, &QAction::triggered, this, &RuqolaMainWindow::slotUnreadOnTop); ac->addAction(QStringLiteral("unread_on_top"), mUnreadOnTop); mChannelInfo = new QAction(i18n("Channel Info..."), this); connect(mChannelInfo, &QAction::triggered, this, &RuqolaMainWindow::slotShowChannelInfo); ac->addAction(QStringLiteral("channel_info"), mChannelInfo); } void RuqolaMainWindow::slotShowThreads() { // QPointer dlg = new ShowDiscussionsDialog(this); // //TODO dlg->setModel(mCurrentRocketChatAccount->filesForRoomFilterProxyModel()); // dlg->exec(); // delete dlg; } void RuqolaMainWindow::slotShowDiscussions() { QPointer dlg = new ShowDiscussionsDialog(this); //TODO dlg->setModel(mCurrentRocketChatAccount->filesForRoomFilterProxyModel()); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotShowChannelInfo() { - const QString roomType = mMainWidget->roomType(); - if (roomType == QLatin1String("d")) { - QPointer dlg = new DirectChannelInfoDialog(this); - dlg->exec(); - delete dlg; - } else { - QPointer dlg = new ChannelInfoDialog(this); - dlg->exec(); - delete dlg; + RoomWrapper *roomWrapper = mMainWidget->roomWrapper(); + if (roomWrapper) { + const QString roomType = mMainWidget->roomType(); + if (roomType == QLatin1String("d")) { + QPointer dlg = new DirectChannelInfoDialog(this); + dlg->exec(); + delete dlg; + } else { + QPointer dlg = new ChannelInfoDialog(this); + dlg->setCanBeModified(roomWrapper->canBeModify()); + dlg->exec(); + delete dlg; + } } } void RuqolaMainWindow::slotShowFileAttachments() { QPointer dlg = new ShowAttachmentDialog(this); const QString roomId = mMainWidget->roomId(); const QString roomType = mMainWidget->roomType(); mCurrentRocketChatAccount->roomFiles(roomId, roomType); dlg->setModel(mCurrentRocketChatAccount->filesForRoomFilterProxyModel()); dlg->setRoomId(roomId); dlg->setRoomType(roomType); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotLoadRecentHistory() { mCurrentRocketChatAccount->loadHistory(mMainWidget->roomId()); } void RuqolaMainWindow::slotConfigureNotification() { QPointer dlg = new ConfigureNotificationDialog(this); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotSearchMessages() { QPointer dlg = new SearchMessageDialog(this); dlg->setRoomId(mMainWidget->roomId()); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotStarredMessages() { QPointer dlg = new ShowStarredMessagesDialog(this); dlg->setRoomId(mMainWidget->roomId()); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); mCurrentRocketChatAccount->getListMessages(mMainWidget->roomId(), ListMessagesModel::StarredMessages); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotPinnedMessages() { QPointer dlg = new ShowPinnedMessagesDialog(this); dlg->setRoomId(mMainWidget->roomId()); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); mCurrentRocketChatAccount->getListMessages(mMainWidget->roomId(), ListMessagesModel::PinnedMessages); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotShowMentions() { // QPointer dlg = new ShowMentionsMessagesDialog(this); // dlg->setModel(Ruqola::self()->rocketChatAccount()->listMessagesFilterProxyModel()); // Ruqola::self()->rocketChatAccount()->getListMessages(mMainWidget->roomId(), ListMessagesModel::); // dlg->exec(); // delete dlg; } void RuqolaMainWindow::slotSnipperedMessages() { QPointer dlg = new ShowSnipperedMessagesDialog(this); dlg->setRoomId(mMainWidget->roomId()); dlg->setModel(mCurrentRocketChatAccount->listMessagesFilterProxyModel()); mCurrentRocketChatAccount->getListMessages(mMainWidget->roomId(), ListMessagesModel::SnipperedMessages); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotCreateNewChannel() { QPointer dlg = new CreateNewChannelDialog(this); if (dlg->exec()) { const CreateNewChannelDialog::NewChannelInfo info = dlg->channelInfo(); mCurrentRocketChatAccount->createNewChannel(info.channelName, info.readOnly, info.privateChannel, info.usersName, info.encryptedRoom, info.password, info.broadCast); } delete dlg; } void RuqolaMainWindow::slotConfigure() { QPointer dlg = new ConfigureSettingsDialog(this); if (dlg->exec()) { //TODO } delete dlg; } void RuqolaMainWindow::slotAddAccount() { QPointer dlg = new CreateNewAccountDialog(this); if (dlg->exec()) { const CreateNewAccountDialog::AccountInfo info = dlg->accountInfo(); Ruqola::self()->accountManager()->addAccount(info.accountName, info.userName, info.serverName); } delete dlg; } void RuqolaMainWindow::slotServerInfo() { QPointer dlg = new ServerInfoDialog(this); dlg->setServerConfigInfo(mCurrentRocketChatAccount->serverConfigInfo()); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotLogout() { mCurrentRocketChatAccount->logOut(); } void RuqolaMainWindow::slotSearchChannel() { QPointer dlg = new SearchChannelDialog(this); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotUnreadOnTop(bool checked) { mCurrentRocketChatAccount->setSortUnreadOnTop(checked); } void RuqolaMainWindow::slotMissingChannelPassword(const QString &roomId) { //TODO move in room page ? QPointer dlg = new ChannelPasswordDialog(this); //TODO add channel name! if (dlg->exec()) { mCurrentRocketChatAccount->joinRoom(roomId, dlg->password()); } delete dlg; }