mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Ran qmlformat and make license
This commit is contained in:
parent
f2560b7531
commit
9ab1296131
4 changed files with 244 additions and 225 deletions
|
@ -10,10 +10,10 @@ import im.nheko 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
id: roomDirectoryWindow
|
id: roomDirectoryWindow
|
||||||
|
|
||||||
|
property RoomDirectoryModel publicRooms
|
||||||
|
|
||||||
visible: true
|
visible: true
|
||||||
|
|
||||||
property RoomDirectoryModel publicRooms : RoomDirectoryModel {}
|
|
||||||
|
|
||||||
x: MainWindow.x + (MainWindow.width / 2) - (width / 2)
|
x: MainWindow.x + (MainWindow.width / 2) - (width / 2)
|
||||||
y: MainWindow.y + (MainWindow.height / 2) - (height / 2)
|
y: MainWindow.y + (MainWindow.height / 2) - (height / 2)
|
||||||
minimumWidth: 650
|
minimumWidth: 650
|
||||||
|
@ -29,38 +29,12 @@ ApplicationWindow {
|
||||||
onActivated: roomDirectoryWindow.close()
|
onActivated: roomDirectoryWindow.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
header: RowLayout {
|
|
||||||
id: searchBarLayout
|
|
||||||
spacing: Nheko.paddingMedium
|
|
||||||
width: parent.width
|
|
||||||
|
|
||||||
implicitHeight: roomSearch.height
|
|
||||||
|
|
||||||
MatrixTextField {
|
|
||||||
id: roomSearch
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
selectByMouse: true
|
|
||||||
|
|
||||||
font.pixelSize: fontMetrics.font.pixelSize
|
|
||||||
padding: Nheko.paddingMedium
|
|
||||||
color: Nheko.colors.text
|
|
||||||
placeholderText: qsTr("Search for public rooms")
|
|
||||||
onTextChanged: searchTimer.restart()
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: searchTimer
|
|
||||||
|
|
||||||
interval: 350
|
|
||||||
onTriggered: roomDirView.model.setSearchTerm(roomSearch.text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: roomDirView
|
id: roomDirView
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
model: publicRooms
|
model: publicRooms
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
id: roomDirDelegate
|
id: roomDirDelegate
|
||||||
|
|
||||||
|
@ -70,12 +44,10 @@ ApplicationWindow {
|
||||||
property int avatarSize: fontMetrics.lineSpacing * 4
|
property int avatarSize: fontMetrics.lineSpacing * 4
|
||||||
|
|
||||||
color: background
|
color: background
|
||||||
|
|
||||||
height: avatarSize + 2.5 * Nheko.paddingMedium
|
height: avatarSize + 2.5 * Nheko.paddingMedium
|
||||||
width: ListView.view.width
|
width: ListView.view.width
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
|
||||||
spacing: Nheko.paddingMedium
|
spacing: Nheko.paddingMedium
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: Nheko.paddingMedium
|
anchors.margins: Nheko.paddingMedium
|
||||||
|
@ -103,6 +75,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: roomNameRow
|
id: roomNameRow
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
|
@ -113,21 +86,24 @@ ApplicationWindow {
|
||||||
font.pixelSize: fontMetrics.font.pixelSize * 1.1
|
font.pixelSize: fontMetrics.font.pixelSize * 1.1
|
||||||
fullText: model.name
|
fullText: model.name
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: roomDescriptionRow
|
id: roomDescriptionRow
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredWidth: parent.width
|
Layout.preferredWidth: parent.width
|
||||||
spacing: Nheko.paddingSmall
|
spacing: Nheko.paddingSmall
|
||||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||||
Layout.preferredHeight: fontMetrics.lineSpacing * 4
|
Layout.preferredHeight: fontMetrics.lineSpacing * 4
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: roomTopic
|
id: roomTopic
|
||||||
|
|
||||||
color: roomDirDelegate.unimportantText
|
color: roomDirDelegate.unimportantText
|
||||||
font.weight: Font.Thin
|
font.weight: Font.Thin
|
||||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||||
font.pixelSize: fontMetrics.font.pixelSize
|
font.pixelSize: fontMetrics.font.pixelSize
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
maximumLineCount: 2
|
maximumLineCount: 2
|
||||||
|
@ -136,60 +112,105 @@ ApplicationWindow {
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
}
|
}
|
||||||
Item {
|
|
||||||
id: numMembersRectangle
|
|
||||||
Layout.fillWidth: false
|
|
||||||
Layout.margins: Nheko.paddingSmall
|
|
||||||
width: roomCount.width
|
|
||||||
|
|
||||||
Label {
|
Item {
|
||||||
id: roomCount
|
id: numMembersRectangle
|
||||||
color: roomDirDelegate.unimportantText
|
|
||||||
anchors.centerIn: parent
|
|
||||||
Layout.fillWidth: false
|
Layout.fillWidth: false
|
||||||
font.weight: Font.Thin
|
Layout.margins: Nheko.paddingSmall
|
||||||
font.pixelSize: fontMetrics.font.pixelSize
|
width: roomCount.width
|
||||||
text: model.numMembers.toString()
|
|
||||||
}
|
Label {
|
||||||
}
|
id: roomCount
|
||||||
|
|
||||||
|
color: roomDirDelegate.unimportantText
|
||||||
|
anchors.centerIn: parent
|
||||||
|
Layout.fillWidth: false
|
||||||
|
font.weight: Font.Thin
|
||||||
|
font.pixelSize: fontMetrics.font.pixelSize
|
||||||
|
text: model.numMembers.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: buttonRectangle
|
||||||
|
|
||||||
|
Layout.fillWidth: false
|
||||||
|
Layout.margins: Nheko.paddingSmall
|
||||||
|
width: joinRoomButton.width
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: joinRoomButton
|
||||||
|
|
||||||
|
visible: publicRooms.canJoinRoom(model.roomid)
|
||||||
|
anchors.centerIn: parent
|
||||||
|
width: Math.ceil(0.1 * roomDirectoryWindow.width)
|
||||||
|
text: "Join"
|
||||||
|
onClicked: publicRooms.joinRoom(model.index)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Item {
|
|
||||||
id: buttonRectangle
|
|
||||||
Layout.fillWidth: false
|
|
||||||
Layout.margins: Nheko.paddingSmall
|
|
||||||
width: joinRoomButton.width
|
|
||||||
Button {
|
|
||||||
id: joinRoomButton
|
|
||||||
visible: publicRooms.canJoinRoom(model.roomid)
|
|
||||||
anchors.centerIn: parent
|
|
||||||
width: Math.ceil(0.1 * roomDirectoryWindow.width)
|
|
||||||
text: "Join"
|
|
||||||
onClicked: publicRooms.joinRoom(model.index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
footer: Item {
|
footer: Item {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
width: parent.width
|
width: parent.width
|
||||||
visible: (publicRooms.reachedEndOfPagination == false) && publicRooms.loadingMoreRooms
|
visible: (publicRooms.reachedEndOfPagination == false) && publicRooms.loadingMoreRooms
|
||||||
// hacky but works
|
// hacky but works
|
||||||
height: loadingSpinner.height + 2 * Nheko.paddingLarge
|
height: loadingSpinner.height + 2 * Nheko.paddingLarge
|
||||||
anchors.margins: Nheko.paddingLarge
|
anchors.margins: Nheko.paddingLarge
|
||||||
|
|
||||||
Spinner {
|
Spinner {
|
||||||
id: loadingSpinner
|
id: loadingSpinner
|
||||||
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
anchors.margins: Nheko.paddingLarge
|
anchors.margins: Nheko.paddingLarge
|
||||||
running: visible
|
running: visible
|
||||||
foreground: Nheko.colors.mid
|
foreground: Nheko.colors.mid
|
||||||
z: 7
|
z: 7
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publicRooms: RoomDirectoryModel {
|
||||||
|
}
|
||||||
|
|
||||||
|
header: RowLayout {
|
||||||
|
id: searchBarLayout
|
||||||
|
|
||||||
|
spacing: Nheko.paddingMedium
|
||||||
|
width: parent.width
|
||||||
|
implicitHeight: roomSearch.height
|
||||||
|
|
||||||
|
MatrixTextField {
|
||||||
|
id: roomSearch
|
||||||
|
|
||||||
|
Layout.fillWidth: true
|
||||||
|
selectByMouse: true
|
||||||
|
font.pixelSize: fontMetrics.font.pixelSize
|
||||||
|
padding: Nheko.paddingMedium
|
||||||
|
color: Nheko.colors.text
|
||||||
|
placeholderText: qsTr("Search for public rooms")
|
||||||
|
onTextChanged: searchTimer.restart()
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: searchTimer
|
||||||
|
|
||||||
|
interval: 350
|
||||||
|
onTriggered: roomDirView.model.setSearchTerm(roomSearch.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,10 +82,10 @@ RoomDirectoryModel::getViasForRoom(const std::vector<std::string> &aliases)
|
||||||
|
|
||||||
vias.reserve(aliases.size());
|
vias.reserve(aliases.size());
|
||||||
|
|
||||||
std::transform(
|
std::transform(aliases.begin(),
|
||||||
aliases.begin(), aliases.end(), std::back_inserter(vias), [](const auto &alias) {
|
aliases.end(),
|
||||||
return alias.substr(alias.find(":") + 1);
|
std::back_inserter(vias),
|
||||||
});
|
[](const auto &alias) { return alias.substr(alias.find(":") + 1); });
|
||||||
|
|
||||||
return vias;
|
return vias;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,8 @@ RoomDirectoryModel::data(const QModelIndex &index, int role) const
|
||||||
void
|
void
|
||||||
RoomDirectoryModel::fetchMore(const QModelIndex &)
|
RoomDirectoryModel::fetchMore(const QModelIndex &)
|
||||||
{
|
{
|
||||||
if (!canFetchMore_) return;
|
if (!canFetchMore_)
|
||||||
|
return;
|
||||||
|
|
||||||
nhlog::net()->debug("Fetching more rooms from mtxclient...");
|
nhlog::net()->debug("Fetching more rooms from mtxclient...");
|
||||||
|
|
||||||
|
@ -137,18 +138,18 @@ RoomDirectoryModel::fetchMore(const QModelIndex &)
|
||||||
// req.third_party_instance_id = third_party_instance_id;
|
// req.third_party_instance_id = third_party_instance_id;
|
||||||
auto requested_server = server_;
|
auto requested_server = server_;
|
||||||
|
|
||||||
reachedEndOfPagination_ = false;
|
reachedEndOfPagination_ = false;
|
||||||
emit reachedEndOfPaginationChanged();
|
emit reachedEndOfPaginationChanged();
|
||||||
|
|
||||||
loadingMoreRooms_ = true;
|
loadingMoreRooms_ = true;
|
||||||
emit loadingMoreRoomsChanged();
|
emit loadingMoreRoomsChanged();
|
||||||
|
|
||||||
http::client()->post_public_rooms(
|
http::client()->post_public_rooms(
|
||||||
req,
|
req,
|
||||||
[requested_server, this, req](const mtx::responses::PublicRooms &res,
|
[requested_server, this, req](const mtx::responses::PublicRooms &res,
|
||||||
mtx::http::RequestErr err) {
|
mtx::http::RequestErr err) {
|
||||||
loadingMoreRooms_ = false;
|
loadingMoreRooms_ = false;
|
||||||
emit loadingMoreRoomsChanged();
|
emit loadingMoreRoomsChanged();
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
nhlog::net()->error(
|
nhlog::net()->error(
|
||||||
|
@ -184,12 +185,12 @@ RoomDirectoryModel::displayRooms(std::vector<mtx::responses::PublicRoomsChunk> f
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
if (next_batch.empty()) {
|
if (next_batch.empty()) {
|
||||||
canFetchMore_ = false;
|
canFetchMore_ = false;
|
||||||
reachedEndOfPagination_ = true;
|
reachedEndOfPagination_ = true;
|
||||||
emit reachedEndOfPaginationChanged();
|
emit reachedEndOfPaginationChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
prevBatch_ = next_batch;
|
prevBatch_ = next_batch;
|
||||||
|
|
||||||
nhlog::ui()->debug ("Finished loading rooms");
|
nhlog::ui()->debug("Finished loading rooms");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,9 @@ class RoomDirectoryModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY (bool loadingMoreRooms READ loadingMoreRooms NOTIFY loadingMoreRoomsChanged)
|
Q_PROPERTY(bool loadingMoreRooms READ loadingMoreRooms NOTIFY loadingMoreRoomsChanged)
|
||||||
Q_PROPERTY (bool reachedEndOfPagination READ reachedEndOfPagination NOTIFY reachedEndOfPaginationChanged)
|
Q_PROPERTY(bool reachedEndOfPagination READ reachedEndOfPagination NOTIFY
|
||||||
|
reachedEndOfPaginationChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RoomDirectoryModel(QObject *parent = nullptr, const std::string &s = "");
|
explicit RoomDirectoryModel(QObject *parent = nullptr, const std::string &s = "");
|
||||||
|
@ -52,14 +53,11 @@ public:
|
||||||
return static_cast<int>(publicRoomsData_.size());
|
return static_cast<int>(publicRoomsData_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool canFetchMore(const QModelIndex &) const override
|
bool canFetchMore(const QModelIndex &) const override { return canFetchMore_; }
|
||||||
{
|
|
||||||
return canFetchMore_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool loadingMoreRooms() const { return loadingMoreRooms_; }
|
bool loadingMoreRooms() const { return loadingMoreRooms_; }
|
||||||
|
|
||||||
bool reachedEndOfPagination() const { return reachedEndOfPagination_; }
|
bool reachedEndOfPagination() const { return reachedEndOfPagination_; }
|
||||||
|
|
||||||
void fetchMore(const QModelIndex &) override;
|
void fetchMore(const QModelIndex &) override;
|
||||||
|
|
||||||
|
@ -69,8 +67,8 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void fetchedRoomsBatch(std::vector<mtx::responses::PublicRoomsChunk> rooms,
|
void fetchedRoomsBatch(std::vector<mtx::responses::PublicRoomsChunk> rooms,
|
||||||
const std::string &next_batch);
|
const std::string &next_batch);
|
||||||
void loadingMoreRoomsChanged();
|
void loadingMoreRoomsChanged();
|
||||||
void reachedEndOfPaginationChanged();
|
void reachedEndOfPaginationChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void displayRooms(std::vector<mtx::responses::PublicRoomsChunk> rooms,
|
void displayRooms(std::vector<mtx::responses::PublicRoomsChunk> rooms,
|
||||||
|
@ -85,9 +83,9 @@ private:
|
||||||
std::string userSearchString_;
|
std::string userSearchString_;
|
||||||
std::string prevBatch_;
|
std::string prevBatch_;
|
||||||
std::string nextBatch_;
|
std::string nextBatch_;
|
||||||
bool canFetchMore_ {true};
|
bool canFetchMore_{true};
|
||||||
bool loadingMoreRooms_ {false};
|
bool loadingMoreRooms_{false};
|
||||||
bool reachedEndOfPagination_ {false};
|
bool reachedEndOfPagination_{false};
|
||||||
std::vector<mtx::responses::PublicRoomsChunk> publicRoomsData_;
|
std::vector<mtx::responses::PublicRoomsChunk> publicRoomsData_;
|
||||||
|
|
||||||
std::vector<std::string> getViasForRoom(const std::vector<std::string> &room);
|
std::vector<std::string> getViasForRoom(const std::vector<std::string> &room);
|
||||||
|
|
|
@ -286,8 +286,7 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
|
||||||
"EmojiCategory",
|
"EmojiCategory",
|
||||||
"Error: Only enums");
|
"Error: Only enums");
|
||||||
|
|
||||||
qmlRegisterType<RoomDirectoryModel>(
|
qmlRegisterType<RoomDirectoryModel>("im.nheko", 1, 0, "RoomDirectoryModel");
|
||||||
"im.nheko", 1, 0, "RoomDirectoryModel");
|
|
||||||
|
|
||||||
#ifdef USE_QUICK_VIEW
|
#ifdef USE_QUICK_VIEW
|
||||||
view = new QQuickView(parent);
|
view = new QQuickView(parent);
|
||||||
|
|
Loading…
Reference in a new issue