diff --git a/src/core/model/roommodel.cpp b/src/core/model/roommodel.cpp index c27b7fb8..348395eb 100644 --- a/src/core/model/roommodel.cpp +++ b/src/core/model/roommodel.cpp @@ -1,569 +1,569 @@ /* * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "roommodel.h" #include "ruqola_debug.h" #include "rocketchataccount.h" #include "usersforroommodel.h" #include "threadsmodel.h" #include "roomwrapper.h" #include #include #include #include #include RoomModel::RoomModel(RocketChatAccount *account, QObject *parent) : QAbstractListModel(parent) , mRocketChatAccount(account) { } RoomModel::~RoomModel() { #if 0 if (mRocketChatAccount && mRocketChatAccount->settings()) { const QString cachePath = mRocketChatAccount->settings()->cacheBasePath(); if (cachePath.isEmpty()) { qCWarning(RUQOLA_LOG) << " Cache Path is not defined"; return; } QDir cacheDir(cachePath); if (!cacheDir.exists(cacheDir.path())) { cacheDir.mkpath(cacheDir.path()); } QFile f(cacheDir.absoluteFilePath(QStringLiteral("rooms"))); if (f.open(QIODevice::WriteOnly)) { QDataStream out(&f); for (Room *m : qAsConst(mRoomsList)) { qCDebug(RUQOLA_LOG) << " save cache for room " << m->name(); const QByteArray ms = Room::serialize(m); out.writeBytes(ms.constData(), ms.size()); } } } #endif qDeleteAll(mRoomsList); } void RoomModel::clear() { if (!mRoomsList.isEmpty()) { beginRemoveRows(QModelIndex(), 0, rowCount() - 1); qDeleteAll(mRoomsList); mRoomsList.clear(); endRemoveRows(); } } Room *RoomModel::findRoom(const QString &roomID) const { for (Room *r : qAsConst(mRoomsList)) { if (r->roomId() == roomID) { return r; } } return nullptr; } RoomWrapper *RoomModel::findRoomWrapper(const QString &roomID) const { for (Room *r : qAsConst(mRoomsList)) { if (r->roomId() == roomID) { auto *wrapper = new RoomWrapper(r); return wrapper; } } return nullptr; } // Clear data and refill it with data in the cache, if there is void RoomModel::reset() { clear(); if (!mRocketChatAccount) { return; } if (mRocketChatAccount->settings()->cacheBasePath().isEmpty()) { return; } //Laurent disable cache for the moment /* QDir cacheDir(Ruqola::self()->cacheBasePath()); // load cache if (cacheDir.exists(cacheDir.path())) { QFile f(cacheDir.absoluteFilePath(QStringLiteral("rooms"))); if (f.open(QIODevice::ReadOnly)) { QDataStream in(&f); while (!f.atEnd()) { char *byteArray; quint32 length; in.readBytes(byteArray, length); QByteArray arr = QByteArray::fromRawData(byteArray, length); Room m = Room::fromJSon(QJsonDocument::fromBinaryData(arr).object()); qDebug() <<" Load from cache room name: " << m.name; addRoom(m.id, m.name, m.selected); } } qCDebug(RUQOLA_LOG) << "Cache Loaded"; } */ } QHash RoomModel::roleNames() const { QHash roles; roles[RoomName] = QByteArrayLiteral("name"); roles[RoomFName] = QByteArrayLiteral("fname"); roles[RoomID] = QByteArrayLiteral("room_id"); roles[RoomSelected] = QByteArrayLiteral("selected"); roles[RoomUnread] = QByteArrayLiteral("unread"); roles[RoomType] = QByteArrayLiteral("type"); roles[RoomOwnerUserName] = QByteArrayLiteral("username"); roles[RoomOwnerUserID] = QByteArrayLiteral("userID"); roles[RoomTopic] = QByteArrayLiteral("topic"); roles[RoomMutedUsers] = QByteArrayLiteral("mutedUsers"); roles[RoomJitsiTimeout] = QByteArrayLiteral("jitsiTimeout"); roles[RoomRo] = QByteArrayLiteral("readOnly"); roles[RoomAnnouncement] = QByteArrayLiteral("announcement"); roles[RoomOpen] = QByteArrayLiteral("open"); roles[RoomAlert] = QByteArrayLiteral("alert"); roles[RoomOrder] = QByteArrayLiteral("roomorder"); roles[RoomFavorite] = QByteArrayLiteral("favorite"); roles[RoomSection] = QByteArrayLiteral("sectionname"); roles[RoomIcon] = QByteArrayLiteral("channelicon"); roles[RoomUserMentions] = QByteArrayLiteral("userMentions"); roles[RoomAutotranslateLanguage] = QByteArrayLiteral("autotranslateLanguage"); roles[RoomAutotranslate] = QByteArrayLiteral("autotranslate"); return roles; } int RoomModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return mRoomsList.size(); } QVariant RoomModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= mRoomsList.count()) { return QVariant(); } Room *r = mRoomsList.at(index.row()); if (role == Qt::DisplayRole) { return r->displayFName(); } switch (role) { case RoomModel::RoomName: return r->name(); case RoomModel::RoomFName: return r->displayFName(); case RoomModel::RoomID: return r->roomId(); case RoomModel::RoomSelected: return r->selected(); case RoomModel::RoomType: return r->channelType(); case RoomModel::RoomOwnerUserID: return r->roomCreatorUserId(); case RoomModel::RoomOwnerUserName: return r->roomOwnerUserName(); case RoomModel::RoomTopic: return r->topic(); case RoomModel::RoomMutedUsers: return r->mutedUsers(); case RoomModel::RoomJitsiTimeout: return r->jitsiTimeout(); case RoomModel::RoomRo: return r->readOnly(); case RoomModel::RoomAnnouncement: return r->announcement(); case RoomModel::RoomUnread: return r->unread(); case RoomModel::RoomOpen: return r->open(); case RoomModel::RoomAlert: return r->alert(); case RoomModel::RoomFavorite: return r->favorite(); case RoomModel::RoomSection: return sectionName(r); case RoomModel::RoomOrder: return order(r); case RoomModel::RoomIcon: case Qt::DecorationRole: return icon(r); case RoomModel::RoomOtr: //TODO implement it. return {}; case RoomModel::RoomUserMentions: return r->userMentions(); case RoomModel::RoomIgnoredUsers: return r->ignoredUsers(); case RoomModel::RoomAutotranslateLanguage: return r->autoTranslateLanguage(); } return {}; } void RoomModel::addRoom(const QString &roomID, const QString &roomName, bool selected) { if (roomID.isEmpty() || roomName.isEmpty()) { qCDebug(RUQOLA_LOG) << " Impossible to add a room"; return; } qCDebug(RUQOLA_LOG) << "Adding room : roomId: " << roomID << " room Name " << roomName << " isSelected : " << selected; Room *r = createNewRoom(); r->setRoomId(roomID); r->setName(roomName); r->setSelected(selected); addRoom(r); } Room *RoomModel::createNewRoom() { Room *r = new Room(mRocketChatAccount); connect(r, &Room::alertChanged, this, &RoomModel::needToUpdateNotification); connect(r, &Room::unreadChanged, this, &RoomModel::needToUpdateNotification); return r; } void RoomModel::getUnreadAlertFromAccount(bool &hasAlert, int &nbUnread) { for (int i = 0; i < mRoomsList.count(); ++i) { if (mRoomsList.at(i)->open()) { if (mRoomsList.at(i)->alert()) { hasAlert = true; } nbUnread += mRoomsList.at(i)->unread(); } } } void RoomModel::updateSubscriptionRoom(const QJsonObject &roomData) { //TODO fix me! //Use "_id" QString rId = roomData.value(QLatin1String("rid")).toString(); if (rId.isEmpty()) { rId = roomData.value(QLatin1String("_id")).toString(); } if (!rId.isEmpty()) { const int roomCount = mRoomsList.size(); for (int i = 0; i < roomCount; ++i) { if (mRoomsList.at(i)->roomId() == rId) { qCDebug(RUQOLA_LOG) << " void RoomModel::updateSubscriptionRoom(const QJsonArray &array) room found"; Room *room = mRoomsList.at(i); room->updateSubscriptionRoom(roomData); Q_EMIT dataChanged(createIndex(i, 0), createIndex(i, 0)); break; } } } else { qCWarning(RUQOLA_LOG) << "RoomModel::updateRoom incorrect jsonobject "<< roomData; //qWarning() << "RoomModel::updateSubscriptionRoom incorrect jsonobject "<< roomData; } } QString RoomModel::insertRoom(const QJsonObject &room) { Room *r = createNewRoom(); r->parseInsertRoom(room); qCDebug(RUQOLA_LOG) << "Inserting room" << r->name() << r->roomId() << r->topic(); addRoom(r); return r->roomId(); } Room *RoomModel::addRoom(const QJsonObject &room) { Room *r = createNewRoom(); r->parseSubscriptionRoom(room); qCDebug(RUQOLA_LOG) << "Adding room subscription" << r->name() << r->roomId() << r->topic(); addRoom(r); return r; } void RoomModel::addRoom(Room *room) { qCDebug(RUQOLA_LOG) << " void RoomModel::addRoom(const Room &room)"<name(); int roomCount = mRoomsList.count(); for (int i = 0; i < roomCount; ++i) { if (mRoomsList.at(i)->roomId() == room->roomId()) { delete mRoomsList.takeAt(i); break; } } roomCount = mRoomsList.count(); beginInsertRows(QModelIndex(), roomCount, roomCount); qCDebug(RUQOLA_LOG) << "Inserting room at position" <roomId() == id) { beginRemoveRows(QModelIndex(), i, i); mRoomsList.remove(i); endRemoveRows(); break; } } } else if (actionName == QLatin1String("inserted")) { qCDebug(RUQOLA_LOG) << "INSERT ROOM name " << roomData.value(QLatin1String("name")) << " rid " << roomData.value(QLatin1String("rid")); //TODO fix me! addRoom(roomData); //addRoom(roomData.value(QLatin1String("rid")).toString(), roomData.value(QLatin1String("name")).toString(), false); } else if (actionName == QLatin1String("updated")) { qCDebug(RUQOLA_LOG) << "UPDATE ROOM name " << roomData.value(QLatin1String("name")).toString() << " rid " << roomData.value(QLatin1String("rid")) << " roomData " << roomData; updateSubscriptionRoom(roomData); } else if (actionName == QLatin1String("changed")) { //qDebug() << "CHANGED ROOM name " << roomData.value(QLatin1String("name")).toString() << " rid " << roomData.value(QLatin1String("rid")) << " roomData " << roomData; qCDebug(RUQOLA_LOG) << "CHANGED ROOM name " << roomData.value(QLatin1String("name")).toString() << " rid " << roomData.value(QLatin1String("rid")) << " roomData " << roomData; qCDebug(RUQOLA_LOG) << "RoomModel::updateSubscription Not implementer changed room yet" << array; updateRoom(roomData); } else { qCDebug(RUQOLA_LOG) << "RoomModel::updateSubscription Undefined type" << actionName; } } void RoomModel::updateRoom(const QJsonObject &roomData) { qCDebug(RUQOLA_LOG) << " void RoomModel::updateRoom(const QJsonObject &roomData)"; //TODO fix me! //Use "_id" QString rId = roomData.value(QLatin1String("rid")).toString(); if (rId.isEmpty()) { rId = roomData.value(QLatin1String("_id")).toString(); } if (!rId.isEmpty()) { const int roomCount = mRoomsList.size(); for (int i = 0; i < roomCount; ++i) { if (mRoomsList.at(i)->roomId() == rId) { qCDebug(RUQOLA_LOG) << " void RoomModel::updateRoom(const QJsonArray &array) room found"; Room *room = mRoomsList.at(i); room->parseUpdateRoom(roomData); Q_EMIT dataChanged(createIndex(i, 0), createIndex(i, 0)); break; } } } else { qCWarning(RUQOLA_LOG) << "RoomModel::updateRoom incorrect jsonobject "<< roomData; //qWarning() << "RoomModel::updateRoom incorrect jsonobject "<< roomData; } } void RoomModel::userStatusChanged(const User &user) { const int roomCount = mRoomsList.count(); for (int i = 0; i < roomCount; ++i) { Room *room = mRoomsList.at(i); if (room->name() == user.userName()) { const QModelIndex idx = createIndex(i, 0); Q_EMIT dataChanged(idx, idx); } - room->usersModelForRoom()->userStatusChanged(user); + room->usersModelForRoom()->setUserStatusChanged(user); } } UsersForRoomModel *RoomModel::usersModelForRoom(const QString &roomId) const { const int roomCount = mRoomsList.count(); for (int i = 0; i < roomCount; ++i) { Room *room = mRoomsList.at(i); if (room->roomId() == roomId) { return room->usersModelForRoom(); } } qCWarning(RUQOLA_LOG) << " Users model for room undefined !"; return nullptr; } UsersForRoomFilterProxyModel *RoomModel::usersForRoomFilterProxyModel(const QString &roomId) const { const int roomCount = mRoomsList.count(); for (int i = 0; i < roomCount; ++i) { Room *room = mRoomsList.at(i); if (room->roomId() == roomId) { return room->usersModelForRoomProxyModel(); } } return {}; } MessageModel *RoomModel::messageModel(const QString &roomId) const { const int roomCount = mRoomsList.count(); for (int i = 0; i < roomCount; ++i) { Room *room = mRoomsList.at(i); if (room->roomId() == roomId) { return room->messageModel(); } } return {}; } QString RoomModel::inputMessage(const QString &roomId) const { const int roomCount = mRoomsList.count(); for (int i = 0; i < roomCount; ++i) { Room *room = mRoomsList.at(i); if (room->roomId() == roomId) { return room->inputMessage(); } } return {}; } void RoomModel::setInputMessage(const QString &roomId, const QString &inputMessage) { const int roomCount = mRoomsList.count(); for (int i = 0; i < roomCount; ++i) { Room *room = mRoomsList.at(i); if (room->roomId() == roomId) { room->setInputMessage(inputMessage); return; } } } QString RoomModel::sectionName(Room *r) const { QString str; if (r->favorite()) { str = i18n("Favorites"); } else { const QString channelTypeStr = r->channelType(); if (mRocketChatAccount && mRocketChatAccount->sortUnreadOnTop() && (r->unread() > 0 || r->alert())) { if (channelTypeStr == QLatin1Char('p')) { if (r->parentRid().isEmpty()) { str = i18n("Unread Rooms"); } else { str = i18n("Unread Discussions"); } } else if (channelTypeStr == QLatin1Char('c')) { str = i18n("Unread Rooms"); } else if (channelTypeStr == QLatin1Char('d')) { str = i18n("Unread Private Messages"); } } else { if (channelTypeStr == QLatin1Char('p')) { if (r->parentRid().isEmpty()) { str = i18n("Rooms"); } else { str = i18n("Discussions"); } } else if (channelTypeStr == QLatin1Char('c')) { str = i18n("Rooms"); } else if (channelTypeStr == QLatin1Char('d')) { str = i18n("Private Messages"); } } } return str; } int RoomModel::order(Room *r) const { int order = 0; // Unread on top: push down everything that isn't unread if (mRocketChatAccount && mRocketChatAccount->sortUnreadOnTop() && r->unread() == 0 && !r->alert()) { order += 20; } // Then we have favorites channels, push down everything else if (!r->favorite()) { order += 10; } const QString channelTypeStr = r->channelType(); if (channelTypeStr == QLatin1Char('c')) { order += 1; } else if (channelTypeStr == QLatin1Char('d')) { order += 2; } else if (channelTypeStr == QLatin1Char('p')) { if (r->parentRid().isEmpty()) { order += 1; } else { order += 4; } } else { qCDebug(RUQOLA_LOG) << r->name() << "has unhandled channel type" << channelTypeStr; order += 5; } return order; } QIcon RoomModel::icon(Room *r) const { if (r->channelType() == QLatin1Char('c')) { if (r->unread() > 0 || r->alert()) { return QIcon::fromTheme(QStringLiteral("irc-channel-active")); } else { return QIcon::fromTheme(QStringLiteral("irc-channel-inactive")); } } else if (r->channelType() == QLatin1Char('d')) { const QString userStatusIconFileName = mRocketChatAccount ? mRocketChatAccount->userStatusIconFileName(r->name()) : QString(); if (userStatusIconFileName.isEmpty()) { return QIcon::fromTheme(QStringLiteral("user-available")); } else { return QIcon::fromTheme(userStatusIconFileName); } } else if (r->channelType() == QLatin1Char('p')) { return QIcon::fromTheme(QStringLiteral("lock")); } return {}; } QModelIndex RoomModel::indexForRoomName(const QString &roomName) const { for (int row = 0; row < rowCount(); ++row) { const QModelIndex modelIndex = index(row, 0); if (modelIndex.data(RoomModel::RoomName) == roomName) { return modelIndex; } } return {}; } diff --git a/src/core/model/usersforroommodel.cpp b/src/core/model/usersforroommodel.cpp index d11a7a65..787c39b1 100644 --- a/src/core/model/usersforroommodel.cpp +++ b/src/core/model/usersforroommodel.cpp @@ -1,251 +1,243 @@ /* Copyright (c) 2017-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 "usersforroommodel.h" #include "usersmodel.h" #include "ruqola_debug.h" #include #include UsersForRoomModel::UsersForRoomModel(QObject *parent) : QAbstractListModel(parent) { } UsersForRoomModel::~UsersForRoomModel() { } -void UsersForRoomModel::removeUser(const QString &userId) -{ - //TODO verify if it -} - -void UsersForRoomModel::addUser(const User &users) -{ - //TODO verify if it -} - void UsersForRoomModel::setUsers(const QVector &users) { if (mUsers.isEmpty()) { if (rowCount() != 0) { beginRemoveRows(QModelIndex(), 0, mUsers.count() - 1); mUsers.clear(); endRemoveRows(); } if (!users.isEmpty()) { beginInsertRows(QModelIndex(), 0, users.count() - 1); mUsers = users; endInsertRows(); } } else { const int numberOfElement = mUsers.count(); mUsers << users; beginInsertRows(QModelIndex(), numberOfElement, mUsers.count() - 1); endInsertRows(); } checkFullList(); } void UsersForRoomModel::clear() { if (!mUsers.isEmpty()) { beginRemoveRows(QModelIndex(), 0, mUsers.count() - 1); mUsers.clear(); endRemoveRows(); } } int UsersForRoomModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return mUsers.count(); } QVariant UsersForRoomModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= mUsers.count()) { return QVariant(); } const User &user = mUsers.at(index.row()); switch (role) { case DisplayName: return generateDisplayName(user); case UserName: return user.userName(); case IconStatus: return user.iconFromStatus(); case UserId: return user.userId(); case Name: return user.name(); } return {}; } QString UsersForRoomModel::generateDisplayName(const User &user) const { const QString displayName = QStringLiteral("%1").arg(user.userName().isEmpty() ? user.name() : user.userName()); return displayName; } void UsersForRoomModel::checkFullList() { setHasFullList(mUsers.count() == mTotal); } bool UsersForRoomModel::hasFullList() const { return mHasFullList; } void UsersForRoomModel::setHasFullList(bool hasFullList) { if (mHasFullList != hasFullList) { mHasFullList = hasFullList; Q_EMIT hasFullListChanged(); } } int UsersForRoomModel::usersCount() const { return mUsers.count(); } int UsersForRoomModel::offset() const { return mOffset; } void UsersForRoomModel::setOffset(int offset) { mOffset = offset; } int UsersForRoomModel::total() const { return mTotal; } void UsersForRoomModel::setTotal(int total) { mTotal = total; } QHash UsersForRoomModel::roleNames() const { QHash roles; roles[UserName] = QByteArrayLiteral("username"); roles[Name] = QByteArrayLiteral("name"); roles[UserId] = QByteArrayLiteral("userid"); roles[IconStatus] = QByteArrayLiteral("iconstatus"); roles[DisplayName] = QByteArrayLiteral("displayname"); return roles; } void UsersForRoomModel::parseUsersForRooms(const QJsonObject &root, UsersModel *model, bool restapi) { if (restapi) { mTotal = root[QLatin1String("total")].toInt(); mOffset = root[QLatin1String("offset")].toInt(); const QJsonArray members = root[QStringLiteral("members")].toArray(); QVector users; users.reserve(members.count()); for (const QJsonValue ¤t : members) { if (current.type() == QJsonValue::Object) { const QJsonObject userObject = current.toObject(); const QString userName = userObject[QStringLiteral("username")].toString(); const QString name = userObject[QStringLiteral("name")].toString(); const QString id = userObject[QStringLiteral("_id")].toString(); const double utcOffset = userObject[QStringLiteral("utcOffset")].toDouble(); const QString status = userObject[QStringLiteral("status")].toString(); User user; user.setName(name); user.setUserName(userName); user.setUserId(id); user.setUtcOffset(utcOffset); user.setStatus(status); if (user.isValid()) { users.append(user); } else { qCWarning(RUQOLA_LOG) << "Invalid user" << user; mTotal--; } } else { qCWarning(RUQOLA_LOG) << "Parse records: Error in users for rooms json" << root; } } setUsers(users); } else { const QJsonObject result = root[QLatin1String("result")].toObject(); if (!result.isEmpty()) { const QJsonArray records = result[QStringLiteral("records")].toArray(); mTotal = result[QLatin1String("total")].toInt(); mOffset = root[QLatin1String("offset")].toInt(); //TODO verify if a day we use no rest api QVector users; users.reserve(records.count()); for (const QJsonValue ¤t : records) { if (current.type() == QJsonValue::Object) { const QJsonObject userObject = current.toObject(); const QString userName = userObject[QStringLiteral("username")].toString(); const QString name = userObject[QStringLiteral("name")].toString(); const QString id = userObject[QStringLiteral("_id")].toString(); User user; user.setName(name); user.setUserName(userName); user.setUserId(id); if (model) { user.setStatus(model->status(id)); } //Add status! if (user.isValid()) { users.append(user); } else { qCWarning(RUQOLA_LOG) << "Invalid user" << user; mTotal--; } } else { qCWarning(RUQOLA_LOG) << "Parse records: Error in users for rooms json" << root; } } setUsers(users); } else { qCWarning(RUQOLA_LOG) << "Error in users for rooms json" << root; } } } -void UsersForRoomModel::userStatusChanged(const User &newuser) +void UsersForRoomModel::setUserStatusChanged(const User &newuser) { const int roomCount = mUsers.count(); for (int i = 0; i < roomCount; ++i) { User &user = mUsers[i]; if (newuser.userId() == user.userId()) { user.setStatus(newuser.status()); const QModelIndex idx = createIndex(i, 0); Q_EMIT dataChanged(idx, idx); + Q_EMIT userStatusChanged(user.userId()); + break; } } } diff --git a/src/core/model/usersforroommodel.h b/src/core/model/usersforroommodel.h index cb94442a..da1cfc71 100644 --- a/src/core/model/usersforroommodel.h +++ b/src/core/model/usersforroommodel.h @@ -1,81 +1,80 @@ /* Copyright (c) 2017-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 USERSFORROOMMODEL_H #define USERSFORROOMMODEL_H #include "libruqolacore_export.h" #include "user.h" #include #include class UsersModel; class LIBRUQOLACORE_EXPORT UsersForRoomModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(bool hasFullList READ hasFullList WRITE setHasFullList NOTIFY hasFullListChanged) public: enum UsersForRoomRoles { UserName = Qt::UserRole + 1, UserId, Name, IconStatus, DisplayName }; Q_ENUM(UsersForRoomRoles) explicit UsersForRoomModel(QObject *parent = nullptr); ~UsersForRoomModel() override; void setUsers(const QVector &users); void clear(); Q_INVOKABLE int rowCount(const QModelIndex &parent = {}) const override; Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role) const override; void parseUsersForRooms(const QJsonObject &root, UsersModel *model, bool restapi); - void userStatusChanged(const User &newuser); - void removeUser(const QString &userId); - void addUser(const User &users); + void setUserStatusChanged(const User &newuser); Q_REQUIRED_RESULT QHash roleNames() const override; Q_REQUIRED_RESULT int total() const; void setTotal(int total); Q_REQUIRED_RESULT int offset() const; void setOffset(int offset); Q_REQUIRED_RESULT bool hasFullList() const; void setHasFullList(bool hasFullList); Q_REQUIRED_RESULT int usersCount() const; Q_SIGNALS: void hasFullListChanged(); + void userStatusChanged(const QString &userId); private: QString generateDisplayName(const User &user) const; void checkFullList(); QVector mUsers; int mTotal = 0; int mOffset = 0; bool mHasFullList = false; }; #endif // USERSFORROOMMODEL_H diff --git a/src/widgets/dialogs/addusersinroomwidget.cpp b/src/widgets/dialogs/addusersinroomwidget.cpp index c3708f77..376cd70a 100644 --- a/src/widgets/dialogs/addusersinroomwidget.cpp +++ b/src/widgets/dialogs/addusersinroomwidget.cpp @@ -1,50 +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. */ #include "adduserscompletionlineedit.h" #include "addusersinroomwidget.h" #include "misc/adduserswidget.h" #include #include AddUsersInRoomWidget::AddUsersInRoomWidget(QWidget *parent) : QWidget(parent) { auto *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mAddUsersWidget = new AddUsersWidget(this); mAddUsersWidget->setObjectName(QStringLiteral("mAddUsersWidget")); + mAddUsersWidget->setPlaceholderText(i18n("Search Users...")); connect(mAddUsersWidget, &AddUsersWidget::userListChanged, this, &AddUsersInRoomWidget::updateOkButton); mainLayout->addWidget(mAddUsersWidget); mainLayout->addStretch(1); } AddUsersInRoomWidget::~AddUsersInRoomWidget() { } QStringList AddUsersInRoomWidget::users() const { return mAddUsersWidget->users(); } diff --git a/src/widgets/dialogs/createnewchanneldialog.h b/src/widgets/dialogs/createnewchanneldialog.h index 64f92590..8f5d34d3 100644 --- a/src/widgets/dialogs/createnewchanneldialog.h +++ b/src/widgets/dialogs/createnewchanneldialog.h @@ -1,52 +1,52 @@ /* 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 CREATENEWCHANNELDIALOG_H #define CREATENEWCHANNELDIALOG_H #include #include "libruqolawidgets_private_export.h" class CreateNewChannelWidget; class QPushButton; class LIBRUQOLAWIDGETS_TESTS_EXPORT CreateNewChannelDialog : public QDialog { Q_OBJECT public: explicit CreateNewChannelDialog(QWidget *parent = nullptr); ~CreateNewChannelDialog() override; struct NewChannelInfo { - QString usersName; + QStringList usersName; QString channelName; QString password; bool readOnly = false; bool broadCast = false; bool privateChannel = false; bool encryptedRoom = false; }; Q_REQUIRED_RESULT NewChannelInfo channelInfo() const; private: void writeConfig(); void readConfig(); CreateNewChannelWidget *mCreateNewChannelWidget = nullptr; QPushButton *mOkButton = nullptr; }; #endif // CREATENEWCHANNELDIALOG_H diff --git a/src/widgets/dialogs/createnewchannelwidget.cpp b/src/widgets/dialogs/createnewchannelwidget.cpp index 734b7cc7..029c1873 100644 --- a/src/widgets/dialogs/createnewchannelwidget.cpp +++ b/src/widgets/dialogs/createnewchannelwidget.cpp @@ -1,114 +1,114 @@ /* 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 "createnewchannelwidget.h" - +#include "misc/adduserswidget.h" #include -#include +#include #include #include #include CreateNewChannelWidget::CreateNewChannelWidget(QWidget *parent) : QWidget(parent) { auto *mainLayout = new QFormLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); - mChannelName = new QLineEdit(this); + mChannelName = new KLineEdit(this); mChannelName->setObjectName(QStringLiteral("mChannelName")); mainLayout->addRow(i18n("Name:"), mChannelName); - mUsers = new QLineEdit(this); + mUsers = new AddUsersWidget(this); mUsers->setObjectName(QStringLiteral("mUsers")); - mUsers->setPlaceholderText(i18nc("List of users separated by ','", "User separate with ','")); + mUsers->setPlaceholderText(i18n("Invite Users...")); mainLayout->addRow(i18n("Users:"), mUsers); mReadOnly = new QCheckBox(this); mReadOnly->setObjectName(QStringLiteral("mReadOnly")); mReadOnly->setChecked(false); mainLayout->addRow(i18n("Read-Only:"), mReadOnly); mBroadcast = new QCheckBox(this); mBroadcast->setObjectName(QStringLiteral("mBroadcast")); mBroadcast->setChecked(false); mainLayout->addRow(i18n("Broadcast:"), mBroadcast); mPrivate = new QCheckBox(this); mPrivate->setObjectName(QStringLiteral("mPrivate")); mPrivate->setChecked(false); mainLayout->addRow(i18n("Private Room:"), mPrivate); mEncryptedRoom = new QCheckBox(this); mEncryptedRoom->setObjectName(QStringLiteral("mEncryptedRoom")); mEncryptedRoom->setChecked(false); mainLayout->addRow(i18n("Encrypted Room:"), mEncryptedRoom); mPasswordLineEdit = new KPasswordLineEdit(this); mPasswordLineEdit->setObjectName(QStringLiteral("mPasswordLineEdit")); mainLayout->addRow(i18n("Password:"), mPasswordLineEdit); - connect(mChannelName, &QLineEdit::textChanged, this, &CreateNewChannelWidget::slotChangeOkButtonEnabled); + connect(mChannelName, &KLineEdit::textChanged, this, &CreateNewChannelWidget::slotChangeOkButtonEnabled); } CreateNewChannelWidget::~CreateNewChannelWidget() { } void CreateNewChannelWidget::slotChangeOkButtonEnabled() { Q_EMIT updateOkButton(!mChannelName->text().trimmed().isEmpty()); } QString CreateNewChannelWidget::channelName() const { return mChannelName->text(); } -QString CreateNewChannelWidget::users() const +QStringList CreateNewChannelWidget::users() const { - return mUsers->text(); + return mUsers->users(); } bool CreateNewChannelWidget::readOnly() const { return mReadOnly->isChecked(); } bool CreateNewChannelWidget::broadCast() const { return mBroadcast->isChecked(); } bool CreateNewChannelWidget::privateChannel() const { return mPrivate->isChecked(); } bool CreateNewChannelWidget::encryptedRoom() const { return mEncryptedRoom->isChecked(); } QString CreateNewChannelWidget::password() const { return mPasswordLineEdit->password(); } diff --git a/src/widgets/dialogs/createnewchannelwidget.h b/src/widgets/dialogs/createnewchannelwidget.h index eedb6260..302790b7 100644 --- a/src/widgets/dialogs/createnewchannelwidget.h +++ b/src/widgets/dialogs/createnewchannelwidget.h @@ -1,59 +1,60 @@ /* 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 CREATENEWCHANNELWIDGET_H #define CREATENEWCHANNELWIDGET_H #include #include "libruqolawidgets_private_export.h" -class QLineEdit; +class KLineEdit; class QCheckBox; class KPasswordLineEdit; +class AddUsersWidget; class LIBRUQOLAWIDGETS_TESTS_EXPORT CreateNewChannelWidget : public QWidget { Q_OBJECT public: explicit CreateNewChannelWidget(QWidget *parent = nullptr); ~CreateNewChannelWidget() override; Q_REQUIRED_RESULT QString channelName() const; - Q_REQUIRED_RESULT QString users() const; + Q_REQUIRED_RESULT QStringList users() const; Q_REQUIRED_RESULT bool encryptedRoom() const; Q_REQUIRED_RESULT bool privateChannel() const; Q_REQUIRED_RESULT bool broadCast() const; Q_REQUIRED_RESULT bool readOnly() const; Q_REQUIRED_RESULT QString password() const; Q_SIGNALS: void updateOkButton(bool state); private: void slotChangeOkButtonEnabled(); - QLineEdit *mChannelName = nullptr; - QLineEdit *mUsers = nullptr; + KLineEdit *mChannelName = nullptr; + AddUsersWidget *mUsers = nullptr; QCheckBox *mReadOnly = nullptr; QCheckBox *mBroadcast = nullptr; QCheckBox *mPrivate = nullptr; QCheckBox *mEncryptedRoom = nullptr; KPasswordLineEdit *mPasswordLineEdit = nullptr; }; #endif // CREATENEWCHANNELWIDGET_H diff --git a/src/widgets/misc/adduserswidget.cpp b/src/widgets/misc/adduserswidget.cpp index 337247b3..cc35f97f 100644 --- a/src/widgets/misc/adduserswidget.cpp +++ b/src/widgets/misc/adduserswidget.cpp @@ -1,87 +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 "adduserswidget.h" #include "dialogs/adduserscompletionlineedit.h" #include "common/flowlayout.h" #include "misc/clickableuserwidget.h" #include #include #include AddUsersWidget::AddUsersWidget(QWidget *parent) : QWidget(parent) { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mSearchUserLineEdit = new AddUsersCompletionLineEdit(this); mSearchUserLineEdit->setObjectName(QStringLiteral("mSearchUserLineEdit")); - mSearchUserLineEdit->setPlaceholderText(i18n("Search Users...")); connect(mSearchUserLineEdit, &AddUsersCompletionLineEdit::newUserName, this, &AddUsersWidget::slotAddNewName); mainLayout->addWidget(mSearchUserLineEdit); mFlowLayout = new FlowLayout; mFlowLayout->setObjectName(QStringLiteral("mFlowLayout")); mainLayout->addLayout(mFlowLayout); } AddUsersWidget::~AddUsersWidget() { - + delete mFlowLayout; } void AddUsersWidget::slotAddNewName(const QString &str) { if (mMap.contains(str)) { return; } ClickableUserWidget *clickableUserWidget = new ClickableUserWidget(str, this); connect(clickableUserWidget, &ClickableUserWidget::removeUser, this, &AddUsersWidget::slotRemoveUser); mFlowLayout->addWidget(clickableUserWidget); mMap.insert(str, clickableUserWidget); Q_EMIT userListChanged(!mMap.isEmpty()); } void AddUsersWidget::slotRemoveUser(const QString &username) { ClickableUserWidget *userWidget = mMap.value(username); if (userWidget) { const int index = mFlowLayout->indexOf(userWidget); if (index != -1) { delete mFlowLayout->takeAt(index); mMap.remove(username); delete userWidget; } } Q_EMIT userListChanged(!mMap.isEmpty()); } QStringList AddUsersWidget::users() const { QStringList addUsers; QMapIterator i(mMap); while (i.hasNext()) { i.next(); addUsers << i.value()->userName(); } return addUsers; } + +void AddUsersWidget::setPlaceholderText(const QString &str) +{ + mSearchUserLineEdit->setPlaceholderText(str); +} diff --git a/src/widgets/misc/adduserswidget.h b/src/widgets/misc/adduserswidget.h index b2aa2586..acfe3c04 100644 --- a/src/widgets/misc/adduserswidget.h +++ b/src/widgets/misc/adduserswidget.h @@ -1,51 +1,53 @@ /* 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 ADDUSERSWIDGET_H #define ADDUSERSWIDGET_H #include #include #include "libruqolawidgets_private_export.h" class AddUsersCompletionLineEdit; class FlowLayout; class ClickableUserWidget; class LIBRUQOLAWIDGETS_TESTS_EXPORT AddUsersWidget : public QWidget { Q_OBJECT public: explicit AddUsersWidget(QWidget *parent = nullptr); ~AddUsersWidget(); Q_REQUIRED_RESULT QStringList users() const; + void setPlaceholderText(const QString &str); + Q_SIGNALS: void textChanged(const QString &str); void userListChanged(bool isNotEmpty); private: void slotRemoveUser(const QString &username); void slotAddNewName(const QString &str); AddUsersCompletionLineEdit *mSearchUserLineEdit = nullptr; FlowLayout *mFlowLayout = nullptr; QMap mMap; }; #endif // ADDUSERSWIDGET_H diff --git a/src/widgets/misc/autotests/adduserswidgettest.cpp b/src/widgets/misc/autotests/adduserswidgettest.cpp index 6cbed2dd..009da518 100644 --- a/src/widgets/misc/autotests/adduserswidgettest.cpp +++ b/src/widgets/misc/autotests/adduserswidgettest.cpp @@ -1,50 +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 "adduserswidgettest.h" #include "misc/adduserswidget.h" #include "common/flowlayout.h" #include "dialogs/adduserscompletionlineedit.h" #include #include QTEST_MAIN(AddUsersWidgetTest) AddUsersWidgetTest::AddUsersWidgetTest(QObject *parent) : QObject(parent) { } void AddUsersWidgetTest::shouldHaveDefaultValues() { AddUsersWidget w; QVBoxLayout *mainLayout = w.findChild(QStringLiteral("mainLayout")); QVERIFY(mainLayout); QCOMPARE(mainLayout->contentsMargins(), QMargins(0, 0, 0, 0)); AddUsersCompletionLineEdit *mSearchUserLineEdit = w.findChild(QStringLiteral("mSearchUserLineEdit")); QVERIFY(mSearchUserLineEdit); - QVERIFY(!mSearchUserLineEdit->placeholderText().isEmpty()); + QVERIFY(mSearchUserLineEdit->placeholderText().isEmpty()); FlowLayout *mFlowLayout = w.findChild(QStringLiteral("mFlowLayout")); QVERIFY(mFlowLayout); QVERIFY(w.users().isEmpty()); } diff --git a/src/widgets/misc/clickableuserwidget.cpp b/src/widgets/misc/clickableuserwidget.cpp index 9c2dcf9f..44d56026 100644 --- a/src/widgets/misc/clickableuserwidget.cpp +++ b/src/widgets/misc/clickableuserwidget.cpp @@ -1,81 +1,81 @@ /* 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 "clickableuserwidget.h" #include #include #include ClickableUserWidget::ClickableUserWidget(const QString &userName, QWidget *parent) : QWidget(parent) , mUserName(userName) { QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mUserLabel = new QLabel(mUserName, this); mUserLabel->setObjectName(QStringLiteral("mUserLabel")); mainLayout->addWidget(mUserLabel); mClickableLabel = new ClickableLabel(this); mClickableLabel->setObjectName(QStringLiteral("mClickableLabel")); mainLayout->addWidget(mClickableLabel); connect(mClickableLabel, &ClickableLabel::clicked, this, &ClickableUserWidget::slotRemoveUser); } ClickableUserWidget::~ClickableUserWidget() { } void ClickableUserWidget::slotRemoveUser() { Q_EMIT removeUser(mUserName); } QString ClickableUserWidget::userName() const { return mUserName; } void ClickableUserWidget::setUserName(const QString &userName) { mUserName = userName; } ClickableLabel::ClickableLabel(QWidget *parent) : QLabel(parent) { - setPixmap(QIcon::fromTheme(QStringLiteral("edit-delete-shred")).pixmap(22, 22)); + setPixmap(QIcon::fromTheme(QStringLiteral("edit-delete-shred")).pixmap(18, 18)); } ClickableLabel::~ClickableLabel() { } void ClickableLabel::mousePressEvent(QMouseEvent *event) { Q_EMIT clicked(); QLabel::mousePressEvent(event); } diff --git a/src/widgets/room/usersinroomflowwidget.cpp b/src/widgets/room/usersinroomflowwidget.cpp index 41c9b8ee..834a6ab1 100644 --- a/src/widgets/room/usersinroomflowwidget.cpp +++ b/src/widgets/room/usersinroomflowwidget.cpp @@ -1,70 +1,92 @@ /* 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 "usersinroomflowwidget.h" #include "usersinroomlabel.h" #include "ruqola.h" #include "rocketchataccount.h" #include "common/flowlayout.h" #include "model/usersforroommodel.h" #include "model/usersforroomfilterproxymodel.h" #include #include UsersInRoomFlowWidget::UsersInRoomFlowWidget(QWidget *parent) : QWidget(parent) { mFlowLayout = new FlowLayout(this); mFlowLayout->setObjectName(QStringLiteral("mFlowLayout")); mFlowLayout->setSpacing(0); mFlowLayout->setContentsMargins(0, 0, 0, 0); } UsersInRoomFlowWidget::~UsersInRoomFlowWidget() { } void UsersInRoomFlowWidget::setRoomId(const QString &roomId) { if (mRoomId != roomId) { mRoomId = roomId; + const auto model = Ruqola::self()->rocketChatAccount()->usersForRoomFilterProxyModel(mRoomId); + connect(model, &UsersForRoomFilterProxyModel::rowsInserted, this, &UsersInRoomFlowWidget::updateList); + connect(model, &UsersForRoomFilterProxyModel::rowsRemoved, this, &UsersInRoomFlowWidget::updateList); + connect(model, &UsersForRoomFilterProxyModel::dataChanged, this, &UsersInRoomFlowWidget::updateList); + connect(model, &UsersForRoomFilterProxyModel::modelReset, this, &UsersInRoomFlowWidget::updateList); updateList(); } } +void UsersInRoomFlowWidget::showEvent(QShowEvent *event) +{ + updateList(); + QWidget::showEvent(event); +} + void UsersInRoomFlowWidget::updateList() { - if (/*isVisible()*/1) { + if (isVisible()) { const auto model = Ruqola::self()->rocketChatAccount()->usersForRoomFilterProxyModel(mRoomId); const auto count = model->rowCount(); mFlowLayout->clearAndDeleteWidgets(); for (int i = 0; i < count; ++i) { const auto roomModelIndex = model->index(i, 0); - const auto userName = roomModelIndex.data(UsersForRoomModel::UsersForRoomRoles::UserName).toString(); + const QString userName = roomModelIndex.data(UsersForRoomModel::UsersForRoomRoles::DisplayName).toString(); + const QString iconStatus = roomModelIndex.data(UsersForRoomModel::UsersForRoomRoles::IconStatus).toString(); UsersInRoomLabel *userLabel = new UsersInRoomLabel(this); userLabel->setUserName(userName); + userLabel->setIconStatus(iconStatus); mFlowLayout->addWidget(userLabel); } if (!model->hasFullList()) { - mFlowLayout->addWidget(new QLabel(i18n("(load More elements)"))); + QLabel *loadingMoreLabel = new QLabel(QStringLiteral("%1").arg(i18n("(Click here for Loading more...)")), this); + loadingMoreLabel->setTextFormat(Qt::RichText); + connect(loadingMoreLabel, &QLabel::linkActivated, this, &UsersInRoomFlowWidget::loadMoreUsersAttachment); + mFlowLayout->addWidget(loadingMoreLabel); } } } + +void UsersInRoomFlowWidget::loadMoreUsersAttachment() +{ + //FIXME + Ruqola::self()->rocketChatAccount()->loadMoreUsersInRoom(mRoomId, QStringLiteral("c")); +} diff --git a/src/widgets/room/usersinroomflowwidget.h b/src/widgets/room/usersinroomflowwidget.h index eecdeecf..eecc2fe9 100644 --- a/src/widgets/room/usersinroomflowwidget.h +++ b/src/widgets/room/usersinroomflowwidget.h @@ -1,40 +1,46 @@ /* 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 USERSINROOMFLOWWIDGET_H #define USERSINROOMFLOWWIDGET_H #include #include "libruqolawidgets_private_export.h" class FlowLayout; class LIBRUQOLAWIDGETS_TESTS_EXPORT UsersInRoomFlowWidget : public QWidget { Q_OBJECT public: explicit UsersInRoomFlowWidget(QWidget *parent = nullptr); ~UsersInRoomFlowWidget(); void setRoomId(const QString &roomId); + +protected: + void showEvent(QShowEvent *event) override; + private: + void loadMoreUsersAttachment(); void updateList(); QString mRoomId; FlowLayout *mFlowLayout = nullptr; + }; #endif // USERSINROOMFLOWWIDGET_H diff --git a/src/widgets/room/usersinroomlabel.cpp b/src/widgets/room/usersinroomlabel.cpp index 1f98f297..b740394b 100644 --- a/src/widgets/room/usersinroomlabel.cpp +++ b/src/widgets/room/usersinroomlabel.cpp @@ -1,50 +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. */ #include "usersinroomlabel.h" #include +#include #include UsersInRoomLabel::UsersInRoomLabel(QWidget *parent) : QWidget(parent) { QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); mIconLabel = new QLabel(this); mIconLabel->setObjectName(QStringLiteral("mIconLabel")); mainLayout->addWidget(mIconLabel); mUserNameLabel = new QLabel(this); mUserNameLabel->setObjectName(QStringLiteral("mUserNameLabel")); + mUserNameLabel->setTextFormat(Qt::RichText); mainLayout->addWidget(mUserNameLabel); } UsersInRoomLabel::~UsersInRoomLabel() { } void UsersInRoomLabel::setUserName(const QString &userName) { mUserNameLabel->setText(userName); } + +void UsersInRoomLabel::setIconStatus(const QString &iconStatus) +{ + mIconLabel->setPixmap(QIcon::fromTheme(iconStatus).pixmap(18, 18)); +} diff --git a/src/widgets/room/usersinroomlabel.h b/src/widgets/room/usersinroomlabel.h index eadfe6db..1ffada7a 100644 --- a/src/widgets/room/usersinroomlabel.h +++ b/src/widgets/room/usersinroomlabel.h @@ -1,42 +1,42 @@ /* 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 USERSINROOMLABEL_H #define USERSINROOMLABEL_H #include #include "libruqolawidgets_private_export.h" class QLabel; class LIBRUQOLAWIDGETS_TESTS_EXPORT UsersInRoomLabel : public QWidget { Q_OBJECT public: explicit UsersInRoomLabel(QWidget *parent = nullptr); ~UsersInRoomLabel(); void setUserName(const QString &userName); - + void setIconStatus(const QString &iconStatus); private: QLabel *mIconLabel = nullptr; QLabel *mUserNameLabel = nullptr; }; #endif // USERSINROOMLABEL_H diff --git a/src/widgets/ruqolamainwindow.cpp b/src/widgets/ruqolamainwindow.cpp index 764cbaad..8a2bdaae 100644 --- a/src/widgets/ruqolamainwindow.cpp +++ b/src/widgets/ruqolamainwindow.cpp @@ -1,481 +1,482 @@ /* 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 "ruqolamainwindow.h" #include "config-ruqola.h" #include "ruqola.h" #include "rocketchataccount.h" #include "accountmanager.h" #include "roomwrapper.h" #include "receivetypingnotificationmanager.h" #include "ruqolacentralwidget.h" #include "misc/accountmenu.h" #include "misc/accountsoverviewwidget.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/showthreadsdialog.h" #include "dialogs/channelpassworddialog.h" #include "dialogs/channelinfodialog.h" #include "dialogs/directchannelinfodialog.h" #include "dialogs/addusersinroomdialog.h" #include "configuredialog/configuresettingsdialog.h" #include #include #include #include #include #include #include #include #if HAVE_KUSERFEEDBACK #include "userfeedback/userfeedbackmanager.h" #include #include #endif namespace { static const char myConfigGroupName[] = "RuqolaMainWindow"; } RuqolaMainWindow::RuqolaMainWindow(QWidget *parent) : KXmlGuiWindow(parent) { mMainWidget = new RuqolaCentralWidget(this); mMainWidget->setObjectName(QStringLiteral("mMainWidget")); connect(mMainWidget, &RuqolaCentralWidget::channelSelected, this, [this]() { changeActionStatus(true); }); setCentralWidget(mMainWidget); setupActions(); setupStatusBar(); setupGUI(/*QStringLiteral(":/kxmlgui5/ruqola/ruqolaui.rc")*/); readConfig(); connect(Ruqola::self()->accountManager(), &AccountManager::currentAccountChanged, this, &RuqolaMainWindow::slotAccountChanged); slotAccountChanged(); #if HAVE_KUSERFEEDBACK KUserFeedback::NotificationPopup *userFeedBackNotificationPopup = new KUserFeedback::NotificationPopup(this); userFeedBackNotificationPopup->setFeedbackProvider(UserFeedBackManager::self()->userFeedbackProvider()); #endif } 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); mAccountOverviewWidget = new AccountsOverviewWidget(this); statusBar()->addPermanentWidget(mAccountOverviewWidget); } 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); connect(mCurrentRocketChatAccount, &RocketChatAccount::publicSettingChanged, this, &RuqolaMainWindow::updateActions); connect(mCurrentRocketChatAccount, &RocketChatAccount::serverVersionChanged, this, &RuqolaMainWindow::updateActions); updateActions(); changeActionStatus(false); //Disable actions when switching. slotClearNotification(); //Clear notification when we switch too. mMainWidget->setCurrentRocketChatAccount(mCurrentRocketChatAccount); } void RuqolaMainWindow::changeActionStatus(bool enabled) { mShowMentions->setEnabled(enabled); mShowPinnedMessages->setEnabled(enabled); mShowStarredMessages->setEnabled(enabled); mShowSnipperedMessages->setEnabled(enabled); mSearchMessages->setEnabled(enabled); mConfigureNotification->setEnabled(enabled); mLoadChannelHistory->setEnabled(enabled); mShowFileAttachments->setEnabled(enabled); mShowDiscussions->setEnabled(enabled); mShowThreads->setEnabled(enabled); mChannelInfo->setEnabled(enabled); mListOfUsers->setEnabled(enabled); mStartVideoChat->setEnabled(enabled); RoomWrapper *roomWrapper = mMainWidget->roomWrapper(); mAddUserInRooms->setEnabled(enabled && roomWrapper && roomWrapper->canBeModify()); } void RuqolaMainWindow::updateActions() { mUnreadOnTop->setChecked(mCurrentRocketChatAccount->sortUnreadOnTop()); mShowPinnedMessages->setVisible(mCurrentRocketChatAccount->hasPinnedMessagesSupport() && mCurrentRocketChatAccount->allowMessagePinningEnabled()); mShowStarredMessages->setVisible(mCurrentRocketChatAccount->hasStarredMessagesSupport() && mCurrentRocketChatAccount->allowMessageStarringEnabled()); mShowSnipperedMessages->setVisible(mCurrentRocketChatAccount->hasSnippetedMessagesSupport() && mCurrentRocketChatAccount->allowMessageSnippetingEnabled()); mStartVideoChat->setVisible(mCurrentRocketChatAccount->jitsiEnabled()); } 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); ac->setDefaultShortcuts(mSearchMessages, KStandardShortcut::find()); 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); mAddUserInRooms = new QAction(i18n("Add Users in Channel..."), this); connect(mAddUserInRooms, &QAction::triggered, this, &RuqolaMainWindow::slotAddUsersInRoom); ac->addAction(QStringLiteral("add_user_in_room"), mAddUserInRooms); auto clearAlerts = new QAction(i18n("Mark all channels read"), this); ac->setDefaultShortcut(clearAlerts, Qt::SHIFT + Qt::Key_Escape); connect(clearAlerts, &QAction::triggered, this, &RuqolaMainWindow::slotClearAccountAlerts); ac->addAction(QStringLiteral("mark_all_channels_read"), clearAlerts); mListOfUsers = new QAction(QIcon::fromTheme(QStringLiteral("system-users")), i18n("List of Users"), this); mListOfUsers->setCheckable(true); mListOfUsers->setChecked(false); connect(mListOfUsers, &QAction::triggered, this, &RuqolaMainWindow::slotListOfUsersInRoom); ac->addAction(QStringLiteral("list_of_users_in_room"), mListOfUsers); mStartVideoChat = new QAction(QIcon::fromTheme(QStringLiteral("camera-video")), i18n("Video Chat"), this); connect(mStartVideoChat, &QAction::triggered, this, &RuqolaMainWindow::slotStartVideoChat); ac->addAction(QStringLiteral("video_chat"), mStartVideoChat); } void RuqolaMainWindow::slotAddUsersInRoom() { QPointer dlg = new AddUsersInRoomDialog(this); if (dlg->exec()) { qWarning() << " Not implement yet"; } delete dlg; } void RuqolaMainWindow::slotClearAccountAlerts() { if (auto acct = Ruqola::self()->accountManager()->account()) { acct->clearAllUnreadMessages(); } } void RuqolaMainWindow::slotShowThreads() { QPointer dlg = new ShowThreadsDialog(this); dlg->setModel(mCurrentRocketChatAccount->threadsFilterProxyModel()); const QString roomId = mMainWidget->roomId(); mCurrentRocketChatAccount->threadsInRoom(roomId); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotShowDiscussions() { QPointer dlg = new ShowDiscussionsDialog(this); dlg->setModel(mCurrentRocketChatAccount->discussionsFilterProxyModel()); const QString roomId = mMainWidget->roomId(); mCurrentRocketChatAccount->discussionsInRoom(roomId); dlg->exec(); delete dlg; } void RuqolaMainWindow::slotShowChannelInfo() { 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->setRoomWrapper(roomWrapper); 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->setRoomWrapper(mMainWidget->roomWrapper()); if (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->setRoomId(mMainWidget->roomId()); dlg->setModel(Ruqola::self()->rocketChatAccount()->listMessagesFilterProxyModel()); Ruqola::self()->rocketChatAccount()->getListMessages(mMainWidget->roomId(), ListMessagesModel::MentionsMessages); 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); + //TODO adapt createNewChannel api for using QStringList + mCurrentRocketChatAccount->createNewChannel(info.channelName, info.readOnly, info.privateChannel, info.usersName.join(QLatin1Char(',')), info.encryptedRoom, info.password, info.broadCast); } delete dlg; } void RuqolaMainWindow::slotConfigure() { QPointer dlg = new ConfigureSettingsDialog(this); if (dlg->exec()) { mAccountOverviewWidget->updateButtons(); } 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 RocketChatRestApi::ChannelBaseJob::ChannelInfo &channelInfo) { //TODO move in room page ? QPointer dlg = new ChannelPasswordDialog(this); //TODO add channel name! if (dlg->exec()) { //FIXME channelinfo mCurrentRocketChatAccount->joinRoom(channelInfo.channelInfoIdentifier, dlg->password()); } delete dlg; } void RuqolaMainWindow::slotListOfUsersInRoom(bool checked) { mMainWidget->showListOfUsersInRoom(checked); } void RuqolaMainWindow::slotStartVideoChat() { mCurrentRocketChatAccount->createJitsiConfCall(mMainWidget->roomId()); }