mirror of https://github.com/Nheko-Reborn/nheko
parent
d3c6bcd43c
commit
cf09a6aa2f
@ -0,0 +1,188 @@ |
||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors |
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors |
||||
// |
||||
// SPDX-License-Identifier: GPL-3.0-or-later |
||||
|
||||
import ".." |
||||
import QtQuick 2.15 |
||||
import QtQuick.Controls 2.3 |
||||
import QtQuick.Layouts 1.2 |
||||
import QtQuick.Window 2.13 |
||||
import im.nheko 1.0 |
||||
|
||||
ApplicationWindow { |
||||
id: spaceChildrenDialog |
||||
|
||||
property SpaceChildrenModel spaceChildren |
||||
property NonSpaceChildrenModel nonChildren |
||||
|
||||
minimumWidth: 340 |
||||
minimumHeight: 450 |
||||
width: 450 |
||||
height: 680 |
||||
palette: Nheko.colors |
||||
color: Nheko.colors.window |
||||
modality: Qt.NonModal |
||||
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint |
||||
title: qsTr("Space children") |
||||
|
||||
Shortcut { |
||||
sequence: StandardKey.Cancel |
||||
onActivated: spaceChildrenDialog.close() |
||||
} |
||||
|
||||
ScrollHelper { |
||||
flickable: flickable |
||||
anchors.fill: flickable |
||||
} |
||||
|
||||
ColumnLayout { |
||||
id: contentLayout |
||||
anchors.fill: parent |
||||
anchors.margins: Nheko.paddingMedium |
||||
spacing: Nheko.paddingMedium |
||||
|
||||
Label { |
||||
color: Nheko.colors.text |
||||
horizontalAlignment: Label.AlignHCenter |
||||
Layout.alignment: Qt.AlignHCenter |
||||
Layout.fillWidth: true |
||||
text: qsTr("Children of %1").arg(spaceChildren.space.roomName) |
||||
wrapMode: Text.Wrap |
||||
font.pointSize: fontMetrics.font.pointSize * 1.5 |
||||
} |
||||
|
||||
ListView { |
||||
id: childrenList |
||||
|
||||
Layout.fillWidth: true |
||||
Layout.fillHeight: true |
||||
model: spaceChildren |
||||
spacing: Nheko.paddingMedium |
||||
clip: true |
||||
|
||||
ScrollHelper { |
||||
flickable: parent |
||||
anchors.fill: parent |
||||
} |
||||
|
||||
delegate: RowLayout { |
||||
id: childDel |
||||
|
||||
required property string id |
||||
required property string roomName |
||||
required property string avatarUrl |
||||
required property string alias |
||||
|
||||
spacing: Nheko.paddingMedium |
||||
width: ListView.view.width |
||||
|
||||
Avatar { |
||||
Layout.alignment: Qt.AlignVCenter |
||||
Layout.rightMargin: Nheko.paddingMedium |
||||
width: Nheko.avatarSize |
||||
height: Nheko.avatarSize |
||||
url: childDel.avatarUrl.replace("mxc://", "image://MxcImage/") |
||||
roomid: childDel.id |
||||
displayName: childDel.roomName |
||||
} |
||||
|
||||
ColumnLayout { |
||||
spacing: Nheko.paddingMedium |
||||
|
||||
Label { |
||||
font.bold: true |
||||
text: childDel.roomName |
||||
} |
||||
|
||||
Label { |
||||
text: childDel.alias |
||||
visible: childDel.alias |
||||
color: Nheko.inactiveColors.text |
||||
} |
||||
} |
||||
|
||||
Item { Layout.fillWidth: true } |
||||
|
||||
ImageButton { |
||||
image: ":/icons/icons/ui/delete.svg" |
||||
onClicked: Nheko.removeRoomFromSpace(childDel.id, spaceChildren.space.roomId) |
||||
} |
||||
} |
||||
} |
||||
|
||||
Label { |
||||
color: Nheko.colors.text |
||||
horizontalAlignment: Label.AlignHCenter |
||||
Layout.alignment: Qt.AlignHCenter |
||||
Layout.fillWidth: true |
||||
text: qsTr("Add rooms to %1").arg(spaceChildren.space.roomName) |
||||
wrapMode: Text.Wrap |
||||
font.pointSize: fontMetrics.font.pointSize * 1.5 |
||||
} |
||||
|
||||
ListView { |
||||
id: nonChildrenList |
||||
|
||||
Layout.fillWidth: true |
||||
Layout.fillHeight: true |
||||
model: nonChildren |
||||
spacing: Nheko.paddingMedium |
||||
clip: true |
||||
|
||||
ScrollHelper { |
||||
flickable: parent |
||||
anchors.fill: parent |
||||
} |
||||
|
||||
delegate: RowLayout { |
||||
id: nonChildDel |
||||
|
||||
required property string id |
||||
required property string roomName |
||||
required property string avatarUrl |
||||
required property string alias |
||||
|
||||
spacing: Nheko.paddingMedium |
||||
width: ListView.view.width |
||||
|
||||
Avatar { |
||||
Layout.alignment: Qt.AlignVCenter |
||||
Layout.rightMargin: Nheko.paddingMedium |
||||
width: Nheko.avatarSize |
||||
height: Nheko.avatarSize |
||||
url: nonChildDel.avatarUrl.replace("mxc://", "image://MxcImage/") |
||||
roomid: nonChildDel.id |
||||
displayName: nonChildDel.roomName |
||||
} |
||||
|
||||
ColumnLayout { |
||||
spacing: Nheko.paddingMedium |
||||
|
||||
Label { |
||||
font.bold: true |
||||
text: nonChildDel.roomName |
||||
} |
||||
|
||||
Label { |
||||
text: nonChildDel.alias |
||||
visible: nonChildDel.alias |
||||
color: Nheko.inactiveColors.text |
||||
} |
||||
} |
||||
|
||||
Item { Layout.fillWidth: true } |
||||
|
||||
ImageButton { |
||||
image: ":/icons/icons/ui/add-square-button.svg" |
||||
onClicked: Nheko.addRoomToSpace(nonChildDel.id, spaceChildren.space.roomId) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
footer: DialogButtonBox { |
||||
standardButtons: DialogButtonBox.Ok |
||||
onAccepted: close() |
||||
} |
||||
} |
@ -0,0 +1,106 @@ |
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "SpaceChildrenModel.h" |
||||
|
||||
#include "Cache.h" |
||||
#include "Cache_p.h" |
||||
|
||||
SpaceChildrenModel::SpaceChildrenModel(QSharedPointer<TimelineModel> space, QObject *parent) |
||||
: QAbstractListModel{parent} |
||||
, m_space{space} |
||||
{ |
||||
auto joinedRooms = cache::joinedRooms(); |
||||
for (const auto &child : cache::client()->getChildRoomIds(m_space->roomId().toStdString())) { |
||||
m_childIds.push_back(QString::fromStdString(child)); |
||||
|
||||
if (std::find(std::begin(joinedRooms), std::end(joinedRooms), child) != |
||||
std::end(joinedRooms)) |
||||
m_childInfos.push_back(cache::singleRoomInfo(child)); |
||||
else // TODO: replace with code to fetch a non-joined room
|
||||
m_childInfos.push_back(cache::singleRoomInfo(child)); |
||||
} |
||||
} |
||||
|
||||
QHash<int, QByteArray> |
||||
SpaceChildrenModel::roleNames() const |
||||
{ |
||||
return {{Roles::Id, "id"}, |
||||
{Roles::RoomName, "roomName"}, |
||||
{Roles::AvatarUrl, "avatarUrl"}, |
||||
{Roles::Alias, "alias"}}; |
||||
} |
||||
|
||||
QVariant |
||||
SpaceChildrenModel::data(const QModelIndex &index, int role) const |
||||
{ |
||||
if (!index.isValid() || index.row() >= (int)m_childIds.size() || index.row() < 0) |
||||
return {}; |
||||
|
||||
switch (role) { |
||||
case Roles::Id: |
||||
return m_childIds[index.row()]; |
||||
case Roles::RoomName: |
||||
return QString::fromStdString(m_childInfos[index.row()].name); |
||||
case Roles::AvatarUrl: |
||||
return QString::fromStdString(m_childInfos[index.row()].avatar_url); |
||||
case Roles::Alias: { |
||||
auto aliases = cache::client()->getRoomAliases(m_childIds[index.row()].toStdString()); |
||||
if (aliases.has_value()) |
||||
return QString::fromStdString(aliases->alias); |
||||
else |
||||
return {}; |
||||
} |
||||
default: |
||||
return {}; |
||||
} |
||||
} |
||||
|
||||
NonSpaceChildrenModel::NonSpaceChildrenModel(QSharedPointer<TimelineModel> space, QObject *parent) |
||||
: QAbstractListModel{parent} |
||||
, m_space{space} |
||||
{ |
||||
auto children = cache::client()->getChildRoomIds(m_space->roomId().toStdString()); |
||||
for (const auto &room : cache::joinedRooms()) { |
||||
if (room == space->roomId().toStdString() || |
||||
std::find(std::begin(children), std::end(children), room) == std::end(children)) { |
||||
m_roomIds.push_back(QString::fromStdString(room)); |
||||
m_roomInfos.push_back(cache::singleRoomInfo(room)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
QHash<int, QByteArray> |
||||
NonSpaceChildrenModel::roleNames() const |
||||
{ |
||||
return {{Roles::Id, "id"}, |
||||
{Roles::RoomName, "roomName"}, |
||||
{Roles::AvatarUrl, "avatarUrl"}, |
||||
{Roles::Alias, "alias"}}; |
||||
} |
||||
|
||||
QVariant |
||||
NonSpaceChildrenModel::data(const QModelIndex &index, int role) const |
||||
{ |
||||
if (!index.isValid() || index.row() >= (int)m_roomIds.size() || index.row() < 0) |
||||
return {}; |
||||
|
||||
switch (role) { |
||||
case Roles::Id: |
||||
return m_roomIds[index.row()]; |
||||
case Roles::RoomName: |
||||
return QString::fromStdString(m_roomInfos[index.row()].name); |
||||
case Roles::AvatarUrl: |
||||
return QString::fromStdString(m_roomInfos[index.row()].avatar_url); |
||||
case Roles::Alias: { |
||||
auto aliases = cache::client()->getRoomAliases(m_roomIds[index.row()].toStdString()); |
||||
if (aliases.has_value()) |
||||
return QString::fromStdString(aliases->alias); |
||||
else |
||||
return {}; |
||||
} |
||||
default: |
||||
return {}; |
||||
} |
||||
} |
@ -0,0 +1,79 @@ |
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#ifndef SPACECHILDRENMODEL_H |
||||
#define SPACECHILDRENMODEL_H |
||||
|
||||
#include <QAbstractListModel> |
||||
#include <QSharedPointer> |
||||
|
||||
#include "timeline/TimelineModel.h" |
||||
|
||||
class SpaceChildrenModel : public QAbstractListModel |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
Q_PROPERTY(TimelineModel *space READ space CONSTANT) |
||||
|
||||
public: |
||||
enum Roles |
||||
{ |
||||
Id, |
||||
RoomName, |
||||
AvatarUrl, |
||||
Alias, |
||||
}; |
||||
|
||||
explicit SpaceChildrenModel(QSharedPointer<TimelineModel> space, QObject *parent = nullptr); |
||||
|
||||
TimelineModel *space() const { return m_space.data(); } |
||||
|
||||
int rowCount(const QModelIndex &parent) const override |
||||
{ |
||||
Q_UNUSED(parent); |
||||
return m_childIds.size(); |
||||
} |
||||
QHash<int, QByteArray> roleNames() const override; |
||||
QVariant data(const QModelIndex &index, int role) const override; |
||||
|
||||
private: |
||||
QSharedPointer<TimelineModel> m_space; |
||||
QStringList m_childIds; |
||||
QList<RoomInfo> m_childInfos; |
||||
}; |
||||
|
||||
class NonSpaceChildrenModel : public QAbstractListModel |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
Q_PROPERTY(TimelineModel *space READ space CONSTANT) |
||||
|
||||
public: |
||||
enum Roles |
||||
{ |
||||
Id, |
||||
RoomName, |
||||
AvatarUrl, |
||||
Alias, |
||||
}; |
||||
|
||||
explicit NonSpaceChildrenModel(QSharedPointer<TimelineModel> space, QObject *parent = nullptr); |
||||
|
||||
TimelineModel *space() const { return m_space.data(); } |
||||
|
||||
int rowCount(const QModelIndex &parent) const override |
||||
{ |
||||
Q_UNUSED(parent); |
||||
return m_roomIds.size(); |
||||
} |
||||
QHash<int, QByteArray> roleNames() const override; |
||||
QVariant data(const QModelIndex &index, int role) const override; |
||||
|
||||
private: |
||||
QSharedPointer<TimelineModel> m_space; |
||||
QStringList m_roomIds; |
||||
QList<RoomInfo> m_roomInfos; |
||||
}; |
||||
|
||||
#endif // SPACECHILDRENMODEL_H
|
Loading…
Reference in new issue