Ran qmlformat and make license

This commit is contained in:
kamathmanu 2021-08-12 10:45:42 -04:00
parent f2560b7531
commit 9ab1296131
4 changed files with 244 additions and 225 deletions

View File

@ -1,195 +1,216 @@
// SPDX-FileCopyrightText: 2021 Nheko Contributors // SPDX-FileCopyrightText: 2021 Nheko Contributors
// //
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
import "./ui" import "./ui"
import QtQuick 2.9 import QtQuick 2.9
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import im.nheko 1.0 import im.nheko 1.0
ApplicationWindow { ApplicationWindow {
id: roomDirectoryWindow id: roomDirectoryWindow
visible: true
property RoomDirectoryModel publicRooms
property RoomDirectoryModel publicRooms : RoomDirectoryModel {}
visible: true
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
minimumHeight: 420 minimumHeight: 420
palette: Nheko.colors palette: Nheko.colors
color: Nheko.colors.window color: Nheko.colors.window
modality: Qt.WindowModal modality: Qt.WindowModal
flags: Qt.Dialog | Qt.WindowCloseButtonHint flags: Qt.Dialog | Qt.WindowCloseButtonHint
title: qsTr("Explore Public Rooms") title: qsTr("Explore Public Rooms")
Shortcut { Shortcut {
sequence: StandardKey.Cancel sequence: StandardKey.Cancel
onActivated: roomDirectoryWindow.close() onActivated: roomDirectoryWindow.close()
} }
header: RowLayout { ListView {
id: searchBarLayout id: roomDirView
spacing: Nheko.paddingMedium
width: parent.width anchors.fill: parent
model: publicRooms
implicitHeight: roomSearch.height
delegate: Rectangle {
MatrixTextField { id: roomDirDelegate
id: roomSearch
property color background: Nheko.colors.window
Layout.fillWidth: true property color importantText: Nheko.colors.text
selectByMouse: true property color unimportantText: Nheko.colors.buttonText
property int avatarSize: fontMetrics.lineSpacing * 4
font.pixelSize: fontMetrics.font.pixelSize
padding: Nheko.paddingMedium color: background
color: Nheko.colors.text height: avatarSize + 2.5 * Nheko.paddingMedium
placeholderText: qsTr("Search for public rooms") width: ListView.view.width
onTextChanged: searchTimer.restart()
} RowLayout {
spacing: Nheko.paddingMedium
Timer { anchors.fill: parent
id: searchTimer anchors.margins: Nheko.paddingMedium
implicitHeight: textContent.height
interval: 350
onTriggered: roomDirView.model.setSearchTerm(roomSearch.text) Avatar {
} id: roomAvatar
}
Layout.alignment: Qt.AlignVCenter
ListView { width: avatarSize
id: roomDirView height: avatarSize
anchors.fill: parent url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
model: publicRooms displayName: model.name
delegate: Rectangle { }
id: roomDirDelegate
ColumnLayout {
property color background: Nheko.colors.window id: textContent
property color importantText: Nheko.colors.text
property color unimportantText: Nheko.colors.buttonText Layout.alignment: Qt.AlignLeft
property int avatarSize: fontMetrics.lineSpacing * 4 Layout.fillWidth: true
width: parent.width - avatar.width
color: background Layout.preferredWidth: parent.width - avatar.width
Layout.preferredHeight: roomNameRow.height + roomDescriptionRow.height
height: avatarSize + 2.5 * Nheko.paddingMedium spacing: Nheko.paddingSmall
width: ListView.view.width
RowLayout {
RowLayout { id: roomNameRow
spacing: Nheko.paddingMedium Layout.fillWidth: true
anchors.fill: parent spacing: 0
anchors.margins: Nheko.paddingMedium
implicitHeight: textContent.height ElidedLabel {
Layout.alignment: Qt.AlignBottom
Avatar { color: roomDirDelegate.importantText
id: roomAvatar elideWidth: textContent.width * 0.5 - Nheko.paddingMedium
font.pixelSize: fontMetrics.font.pixelSize * 1.1
Layout.alignment: Qt.AlignVCenter fullText: model.name
width: avatarSize }
height: avatarSize
url: model.avatarUrl.replace("mxc://", "image://MxcImage/") }
displayName: model.name
} RowLayout {
id: roomDescriptionRow
ColumnLayout {
id: textContent Layout.fillWidth: true
Layout.preferredWidth: parent.width
Layout.alignment: Qt.AlignLeft spacing: Nheko.paddingSmall
Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
width: parent.width - avatar.width Layout.preferredHeight: fontMetrics.lineSpacing * 4
Layout.preferredWidth: parent.width - avatar.width
Layout.preferredHeight: roomNameRow.height + roomDescriptionRow.height Label {
spacing: Nheko.paddingSmall id: roomTopic
RowLayout { color: roomDirDelegate.unimportantText
id: roomNameRow font.weight: Font.Thin
Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
spacing: 0 font.pixelSize: fontMetrics.font.pixelSize
elide: Text.ElideRight
ElidedLabel { maximumLineCount: 2
Layout.alignment: Qt.AlignBottom Layout.fillWidth: true
color: roomDirDelegate.importantText text: model.topic
elideWidth: textContent.width * 0.5 - Nheko.paddingMedium verticalAlignment: Text.AlignVCenter
font.pixelSize: fontMetrics.font.pixelSize * 1.1 wrapMode: Text.WordWrap
fullText: model.name }
}
} Item {
id: numMembersRectangle
RowLayout {
id: roomDescriptionRow Layout.fillWidth: false
Layout.fillWidth: true Layout.margins: Nheko.paddingSmall
Layout.preferredWidth: parent.width width: roomCount.width
spacing: Nheko.paddingSmall
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft Label {
Layout.preferredHeight: fontMetrics.lineSpacing * 4 id: roomCount
Label { color: roomDirDelegate.unimportantText
id: roomTopic anchors.centerIn: parent
color: roomDirDelegate.unimportantText Layout.fillWidth: false
font.weight: Font.Thin font.weight: Font.Thin
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft font.pixelSize: fontMetrics.font.pixelSize
font.pixelSize: fontMetrics.font.pixelSize text: model.numMembers.toString()
elide: Text.ElideRight }
maximumLineCount: 2
Layout.fillWidth: true }
text: model.topic
verticalAlignment: Text.AlignVCenter Item {
wrapMode: Text.WordWrap id: buttonRectangle
}
Item { Layout.fillWidth: false
id: numMembersRectangle Layout.margins: Nheko.paddingSmall
Layout.fillWidth: false width: joinRoomButton.width
Layout.margins: Nheko.paddingSmall
width: roomCount.width Button {
id: joinRoomButton
Label {
id: roomCount visible: publicRooms.canJoinRoom(model.roomid)
color: roomDirDelegate.unimportantText anchors.centerIn: parent
anchors.centerIn: parent width: Math.ceil(0.1 * roomDirectoryWindow.width)
Layout.fillWidth: false text: "Join"
font.weight: Font.Thin onClicked: publicRooms.joinRoom(model.index)
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) footer: Item {
anchors.centerIn: parent anchors.horizontalCenter: parent.horizontalCenter
width: Math.ceil(0.1 * roomDirectoryWindow.width) width: parent.width
text: "Join" visible: (publicRooms.reachedEndOfPagination == false) && publicRooms.loadingMoreRooms
onClicked: publicRooms.joinRoom(model.index) // hacky but works
} height: loadingSpinner.height + 2 * Nheko.paddingLarge
} anchors.margins: Nheko.paddingLarge
}
} Spinner {
} id: loadingSpinner
}
anchors.centerIn: parent
footer: Item { anchors.margins: Nheko.paddingLarge
anchors.horizontalCenter: parent.horizontalCenter running: visible
width: parent.width foreground: Nheko.colors.mid
visible: (publicRooms.reachedEndOfPagination == false) && publicRooms.loadingMoreRooms z: 7
// hacky but works }
height: loadingSpinner.height + 2 * Nheko.paddingLarge
anchors.margins: Nheko.paddingLarge }
Spinner { }
id: loadingSpinner
publicRooms: RoomDirectoryModel {
anchors.centerIn: parent }
anchors.margins: Nheko.paddingLarge
running: visible header: RowLayout {
foreground: Nheko.colors.mid id: searchBarLayout
z: 7
} 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)
}
}
}

View File

@ -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");
} }

View File

@ -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);

View File

@ -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);