diff --git a/qml/component/DownloadableContent.qml b/qml/component/DownloadableContent.qml index efe43f4..3f7ec36 100644 --- a/qml/component/DownloadableContent.qml +++ b/qml/component/DownloadableContent.qml @@ -1,6 +1,7 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 import QtQuick.Controls.Material 2.2 +import Qt.labs.platform 1.0 Item { property bool openOnFinished: false @@ -27,7 +28,7 @@ Item { else { openOnFinished = true - currentRoom.downloadFile(eventId) + currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_") + ".tmp") } } diff --git a/qml/form/RoomListForm.qml b/qml/form/RoomListForm.qml index f8b42bc..d2b3f24 100644 --- a/qml/form/RoomListForm.qml +++ b/qml/form/RoomListForm.qml @@ -89,15 +89,36 @@ Item { pattern: searchField.text caseSensitivity: Qt.CaseInsensitive } - proxyRoles: [ - ExpressionRole { name: "isFavorite"; expression: category === "Favorites" }, - ExpressionRole { name: "isDirectChat"; expression: category === "People" }, - ExpressionRole { name: "isLowPriority"; expression: category === "Low Priorities" } - ] + proxyRoles: ExpressionRole { + name: "display" + expression: { + switch (category) { + case 1: return "Invited" + case 2: return "Favorites" + case 3: return "Rooms" + case 4: return "People" + case 5: return "Low Priorities" + } + } + } + sorters: [ - RoleSorter { roleName: "isFavorite"; sortOrder: Qt.DescendingOrder }, - RoleSorter { roleName: "isLowPriority" }, - RoleSorter { roleName: "isDirectChat" }, + ExpressionSorter { + expression: { + var leftCategory = modelLeft.category + var rightCategory = modelRight.category + if (leftCategory === 1) return true + if (rightCategory === 1) return false + if (leftCategory === 2) return true + if (rightCategory === 2) return false + if (leftCategory === 5) return false + if (rightCategory === 5) return true + if (leftCategory === 4) return false + if (rightCategory === 4) return true + return true + } + }, + StringSorter { roleName: "name" } ] } @@ -126,7 +147,7 @@ Item { height: 80 onPressed: listView.currentIndex = index onPressAndHold: roomListMenu.popup() - onClicked: enterRoom() + onClicked: category === RoomType.Invited ? inviteDialog.open() : enterRoom() ToolTip.visible: mini && hovered ToolTip.text: name @@ -180,7 +201,7 @@ Item { } } - section.property: "category" + section.property: "display" section.criteria: ViewSection.FullString section.delegate: Label { width: parent.width @@ -192,11 +213,29 @@ Item { verticalAlignment: Text.AlignVCenter horizontalAlignment: mini ? Text.AlignHCenter : undefined background: Rectangle { - anchors.fill:parent + anchors.fill: parent color: Material.theme == Material.Light ? "#dbdbdb" : "#363636" } } + Dialog { + id: inviteDialog + parent: ApplicationWindow.overlay + + x: (window.width - width) / 2 + y: (window.height - height) / 2 + width: 360 + + title: "Action Required" + modal: true + standardButtons: Dialog.Ok | Dialog.Cancel + + contentItem: Label { text: "Accept this invitation?" } + + onAccepted: matriqueController.acceptRoom(currentRoom) + onRejected: matriqueController.rejectRoom(currentRoom) + } + Menu { id: roomListMenu diff --git a/src/controller.cpp b/src/controller.cpp index 5b6e9a6..f5c7a7c 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -145,3 +145,10 @@ void Controller::saveFileAs(Room* room, QString eventId) { if (!fileName.isEmpty()) room->downloadFile(eventId, QUrl::fromLocalFile(fileName)); } + +void Controller::acceptRoom(Room* room) { room->setJoinState(JoinState::Join); } + +void Controller::rejectRoom(Room* room) { + room->setJoinState(JoinState::Leave); + forgetRoom(room->id()); +} diff --git a/src/controller.h b/src/controller.h index 3ddd5d3..fc5e0f5 100644 --- a/src/controller.h +++ b/src/controller.h @@ -5,9 +5,9 @@ #include "roomlistmodel.h" #include "user.h" -#include #include #include +#include using namespace QMatrixClient; @@ -111,6 +111,8 @@ class Controller : public QObject { void createDirectChat(const QString& userID); void copyToClipboard(const QString& text); void saveFileAs(Room* room, QString eventId); + void acceptRoom(Room* room); + void rejectRoom(Room* room); }; #endif // CONTROLLER_H diff --git a/src/main.cpp b/src/main.cpp index 8fba679..0bd94e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,11 +4,11 @@ #include #include "controller.h" +#include "emojimodel.h" #include "imageprovider.h" #include "messageeventmodel.h" #include "room.h" #include "roomlistmodel.h" -#include "emojimodel.h" #include "csapi/joining.h" #include "csapi/leaving.h" @@ -30,7 +30,9 @@ int main(int argc, char *argv[]) { qmlRegisterType("Matrique", 0, 1, "RoomListModel"); qmlRegisterType("Matrique", 0, 1, "MessageEventModel"); qmlRegisterType("Matrique", 0, 1, "EmojiModel"); - qmlRegisterUncreatableType("Matrique", 0, 1, "RoomMessageEvent", "ENUM"); + qmlRegisterUncreatableType("Matrique", 0, 1, + "RoomMessageEvent", "ENUM"); + qmlRegisterUncreatableType("Matrique", 0, 1, "RoomType", "ENUM"); QQmlApplicationEngine engine; diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index e97289d..4536883 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -33,8 +33,6 @@ QHash MessageEventModel::roleNames() const { return roles; } -MessageEventModel::~MessageEventModel() {} - MessageEventModel::MessageEventModel(QObject* parent) : QAbstractListModel(parent), m_currentRoom(nullptr) { using namespace QMatrixClient; @@ -44,6 +42,8 @@ MessageEventModel::MessageEventModel(QObject* parent) "Matrique", 0, 1, "EventStatus", "EventStatus is not an creatable type"); } +MessageEventModel::~MessageEventModel() {} + void MessageEventModel::setRoom(QMatrixClient::Room* room) { if (room == m_currentRoom) return; @@ -587,8 +587,9 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const { } } if (evt.isRedacted()) - return Settings().value("UI/show_redacted").toBool() - ? EventStatus::Redacted : EventStatus::Hidden; + return Settings().value("UI/show_redacted").toBool() + ? EventStatus::Redacted + : EventStatus::Hidden; if (evt.isStateEvent() && static_cast(evt).repeatsState() && diff --git a/src/roomlistmodel.cpp b/src/roomlistmodel.cpp index bd19340..fe5abca 100644 --- a/src/roomlistmodel.cpp +++ b/src/roomlistmodel.cpp @@ -5,6 +5,7 @@ #include #include #include +#include RoomListModel::RoomListModel(QObject* parent) : QAbstractListModel(parent) {} @@ -136,33 +137,22 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const { return QVariant(); } Room* room = m_rooms.at(index.row()); - if (role == NameRole) { - return room->displayName(); - } + if (role == NameRole) return room->displayName(); if (role == AvatarRole) { if (room->avatarUrl().toString() != "") { return room->avatarUrl(); } return QVariant(); } - if (role == TopicRole) { - return room->topic(); - } + if (role == TopicRole) return room->topic(); if (role == CategoryRole) { - // if (!room->isDirectChat()) - // qDebug() << room->displayName() << "is not direct."; - if (room->isFavourite()) return "Favorites"; - if (room->isDirectChat()) return "People"; - if (room->isLowPriority()) return "Low Priorities"; - return "Rooms"; - } - if (role == HighlightRole) { - if (room->highlightCount() > 0) return QBrush(QColor("orange")); - return QVariant(); - } - if (role == UnreadCountRole) { - return room->unreadCount(); + if (room->joinState() == JoinState::Invite) return RoomType::Invited; + if (room->isFavourite()) return RoomType::Favorite; + if (room->isDirectChat()) return RoomType::Direct; + if (room->isLowPriority()) return RoomType::Deprioritized; + return RoomType::Normal; } + if (role == UnreadCountRole) return room->unreadCount(); return QVariant(); } @@ -192,7 +182,6 @@ QHash RoomListModel::roleNames() const { roles[AvatarRole] = "avatar"; roles[TopicRole] = "topic"; roles[CategoryRole] = "category"; - roles[HighlightRole] = "highlight"; roles[UnreadCountRole] = "unreadCount"; return roles; } diff --git a/src/roomlistmodel.h b/src/roomlistmodel.h index fb86e83..22f543b 100644 --- a/src/roomlistmodel.h +++ b/src/roomlistmodel.h @@ -7,6 +7,20 @@ using namespace QMatrixClient; +class RoomType : public QObject { + Q_OBJECT + + public: + enum Types { + Invited = 1, + Favorite, + Normal, + Direct, + Deprioritized, + }; + REGISTER_ENUM(Types) +}; + class RoomListModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(Connection* connection READ getConnection WRITE setConnection) @@ -17,8 +31,7 @@ class RoomListModel : public QAbstractListModel { AvatarRole, TopicRole, CategoryRole, - HighlightRole, - UnreadCountRole + UnreadCountRole, }; RoomListModel(QObject* parent = 0);