Compare commits

...

26 Commits

Author SHA1 Message Date
Justin Zobel
ae155805e9 CI - Flatpak - Update Runtime/SDK to 6.7 2024-04-07 22:49:04 +00:00
snow flurry
70bff21632 Render custom emoji icons in the completion pane 2024-04-07 19:40:02 +00:00
James Graham
f58c390a47 Re-add requirement for having devtools active for the show message source action
Re-add requirement for having devtools active for the show message source action

BUG: 485140
2024-04-07 08:40:14 +00:00
l10n daemon script
089a9abcb4 GIT_SILENT Sync po/docbooks with svn 2024-04-07 01:23:56 +00:00
Joshua Goins
bf1c76d0a6 Force the choose room dialog's search dialog to be focused
This makes it possible to open the share dialog and start typing to find
the room immediately.
2024-04-06 15:40:03 -04:00
Joshua Goins
879da627b1 Fix the share dialog not showing up
Seems to be a leftover from the refactor to use modules.
2024-04-06 15:39:36 -04:00
James Graham
9b93eb44d5 Show a verified icon for verified devices rather than a verify option 2024-04-06 14:19:38 +00:00
l10n daemon script
b30220eca9 GIT_SILENT Sync po/docbooks with svn 2024-04-06 01:23:47 +00:00
l10n daemon script
d270d4e5e1 GIT_SILENT Sync po/docbooks with svn 2024-04-05 01:21:52 +00:00
l10n daemon script
21da6cb0f4 GIT_SILENT Sync po/docbooks with svn 2024-04-04 01:24:44 +00:00
l10n daemon script
6ac75df935 GIT_SILENT Sync po/docbooks with svn 2024-04-03 01:24:31 +00:00
l10n daemon script
f29781349c SVN_SILENT made messages (.desktop file) - always resolve ours
In case of conflict in i18n, keep the version of the branch "ours"
To resolve a particular conflict, "git checkout --ours path/to/file.desktop"
2024-04-03 01:14:45 +00:00
Tobias Fella
bb776d5c2b Only ask for URL opening confirmation for QR codes
BUG: 484870
2024-04-02 19:47:07 +02:00
James Graham
6cfab9e3ea Tree Model 2 Electric Boogaloo
This draws heavily on what @carlschwan did in network/neochat!1579 but I found it easier to start again and grab the bits as I needed them plus some other copying from what I did in the Space tree model.

From my current limited testing this seems to work nicely try and break it.
2024-04-02 14:44:20 +00:00
l10n daemon script
6373186c15 GIT_SILENT Sync po/docbooks with svn 2024-04-02 01:18:19 +00:00
Nate Graham
e342de3bc1 Make ConfirmUrlDialog HIG-compliant
* "URL" is an acronym; make it all caps
* Use descriptive context-appropriate buttons instead of "Yes" and "No"
* Use KUIT markup for styling the link
2024-04-01 11:32:27 -06:00
Tobias Fella
4cd7b69ea5 Fix QML warning 2024-04-01 15:48:42 +02:00
Tobias Fella
988e8529da Remove leftover signal handler 2024-04-01 15:43:31 +02:00
James Graham
6a32d1e961 Create component for showing a maximize version of a code snippet 2024-04-01 11:20:10 +00:00
James Graham
0552c798fb Create qml module for devtools 2024-04-01 10:58:29 +00:00
l10n daemon script
a53ad41879 GIT_SILENT Sync po/docbooks with svn 2024-04-01 01:17:50 +00:00
Tobias Fella
92351edcd0 Fix location delegates
- Mark OSMLocationPlugina as singleton in cmake
- Use this plugin for the LocationChooser
2024-03-31 20:57:58 +02:00
James Graham
878eb48cb0 Shut qt up about models passed to QML
Shutup qt about below

```
SortFilterRoomListModel is neither a QObject, nor default- and copy-constructible, nor uncreatable. You should not use it as a QML type.
SortFilterRoomTreeModel is neither a QObject, nor default- and copy-constructible, nor uncreatable. You should not use it as a QML type.
SortFilterSpaceListModel is neither a QObject, nor default- and copy-constructible, nor uncreatable. You should not use it as a QML type.
```
2024-03-31 17:49:35 +00:00
James Graham
053ca6bed8 Move the various room models into RoomManager
Move the various room models into RoomManager. This means the same room models are always used and is a base from which further logic can be moved from QML to cpp.
2024-03-31 12:56:27 +00:00
Tobias Fella
78ae14ab2f Stay in DM tab when selecting a DM 2024-03-31 14:31:22 +02:00
l10n daemon script
5fdc2ad765 GIT_SILENT Sync po/docbooks with svn 2024-03-31 01:30:45 +00:00
91 changed files with 12226 additions and 10785 deletions

View File

@@ -2,7 +2,7 @@
"id": "org.kde.neochat",
"branch": "master",
"runtime": "org.kde.Platform",
"runtime-version": "6.6",
"runtime-version": "6.7",
"sdk": "org.kde.Sdk",
"command": "neochat",
"tags": [

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -172,6 +172,12 @@ add_library(neochat STATIC
models/statekeysmodel.h
sharehandler.cpp
sharehandler.h
models/roomtreeitem.cpp
models/roomtreeitem.h
)
set_source_files_properties(qml/OsmLocationPlugin.qml PROPERTIES
QT_QML_SINGLETON_TYPE TRUE
)
qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN
@@ -206,8 +212,6 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN
qml/CompletionMenu.qml
qml/PieProgressBar.qml
qml/QuickFormatBar.qml
qml/RoomData.qml
qml/ServerData.qml
qml/EmojiPicker.qml
qml/LoginStep.qml
qml/Login.qml
@@ -241,7 +245,6 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN
qml/FileDelegateContextMenu.qml
qml/MessageSourceSheet.qml
qml/ReportSheet.qml
qml/DevtoolsPage.qml
qml/ConfirmEncryptionDialog.qml
qml/RemoveSheet.qml
qml/BanSheet.qml
@@ -281,15 +284,13 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN
qml/RoomTreeSection.qml
qml/DelegateContextMenu.qml
qml/ShareDialog.qml
qml/FeatureFlagPage.qml
qml/AccountData.qml
qml/StateKeys.qml
qml/UnlockSSSSDialog.qml
qml/QrScannerPage.qml
qml/JoinRoomDialog.qml
qml/ConfirmUrlDialog.qml
qml/AccountSwitchDialog.qml
qml/ConfirmLeaveDialog.qml
qml/CodeMaximizeComponent.qml
RESOURCES
qml/confetti.png
qml/glowdot.png
@@ -297,6 +298,7 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN
add_subdirectory(settings)
add_subdirectory(timeline)
add_subdirectory(devtools)
if(UNIX)
qt_target_qml_sources(neochat QML_FILES qml/ShareAction.qml)
@@ -388,7 +390,7 @@ if (NOT ANDROID AND NOT WIN32 AND NOT APPLE)
endif()
target_include_directories(neochat PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/models ${CMAKE_CURRENT_SOURCE_DIR}/enums)
target_link_libraries(neochat PRIVATE settingsplugin timelineplugin)
target_link_libraries(neochat PRIVATE settingsplugin timelineplugin devtoolsplugin)
target_link_libraries(neochat PUBLIC
Qt::Core
Qt::Quick

View File

@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
# SPDX-License-Identifier: BSD-2-Clause
qt_add_library(devtools STATIC)
qt_add_qml_module(devtools
URI org.kde.neochat.devtools
OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/src/org/kde/neochat/devtools
QML_FILES
DevtoolsPage.qml
AccountData.qml
FeatureFlagPage.qml
RoomData.qml
ServerData.qml
StateKeys.qml
)

View File

@@ -7,7 +7,6 @@ import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.neochat
import org.kde.neochat.config
FormCard.FormCardPage {

View File

@@ -25,14 +25,11 @@ ColumnLayout {
text: i18n("Room")
textRole: "escapedDisplayName"
valueRole: "roomId"
displayText: roomListModel.data(roomListModel.index(currentIndex, 0), RoomListModel.DisplayNameRole)
model: RoomListModel {
id: roomListModel
connection: root.connection
}
displayText: RoomManager.roomListModel.data(RoomManager.roomListModel.index(currentIndex, 0), RoomListModel.DisplayNameRole)
model: RoomManager.roomListModel
currentIndex: 0
Component.onCompleted: currentIndex = roomListModel.rowForRoom(root.room)
onCurrentValueChanged: root.room = roomListModel.roomByAliasOrId(roomComboBox.currentValue)
Component.onCompleted: currentIndex = RoomManager.roomListModel.rowForRoom(root.room)
onCurrentValueChanged: root.room = RoomManager.roomListModel.roomByAliasOrId(roomComboBox.currentValue)
}
FormCard.FormTextDelegate {
text: i18n("Room Id: %1", root.room.id)

View File

@@ -29,6 +29,7 @@ public:
Deprioritized, /**< The room is set as low priority. */
Space, /**< The room is a space. */
AddDirect, /**< So we can show the add friend delegate. */
TypesCount, /**< Number of different types (this should always be last). */
};
Q_ENUM(Types);

View File

@@ -230,6 +230,7 @@ int main(int argc, char *argv[])
Q_IMPORT_QML_PLUGIN(org_kde_neochat_settingsPlugin)
Q_IMPORT_QML_PLUGIN(org_kde_neochat_timelinePlugin)
Q_IMPORT_QML_PLUGIN(org_kde_neochat_devtoolsPlugin)
qml_register_types_org_kde_neochat();
qmlRegisterSingletonInstance("org.kde.neochat.config", 1, 0, "Config", NeoChatConfig::self());

View File

@@ -161,7 +161,7 @@ QVariant CustomEmojiModel::data(const QModelIndex &idx, int role) const
case Roles::ImageURL:
return QUrl(QStringLiteral("image://mxc/") + data.url.mid(6));
case Roles::MxcUrl:
return data.url.mid(6);
return m_connection->makeMediaUrl(QUrl(data.url));
default:
return {};
}

View File

@@ -19,6 +19,15 @@ using namespace Quotient;
DevicesModel::DevicesModel(QObject *parent)
: QAbstractListModel(parent)
{
connect(m_connection, &Connection::sessionVerified, this, [this](const QString &, const QString &deviceId) {
const auto it = std::find_if(m_devices.begin(), m_devices.end(), [deviceId](const Quotient::Device &device) {
return device.deviceId == deviceId;
});
if (it != m_devices.end()) {
const auto index = this->index(it - m_devices.begin());
Q_EMIT dataChanged(index, index, {Type});
}
});
}
void DevicesModel::fetchDevices()

100
src/models/roomtreeitem.cpp Normal file
View File

@@ -0,0 +1,100 @@
// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "roomtreeitem.h"
RoomTreeItem::RoomTreeItem(TreeData data, RoomTreeItem *parent)
: m_parentItem(parent)
, m_data(data)
{
}
bool RoomTreeItem::operator==(const RoomTreeItem &other) const
{
if (std::holds_alternative<NeoChatRoomType::Types>(m_data) && std::holds_alternative<NeoChatRoomType::Types>(other.data())) {
return std::get<NeoChatRoomType::Types>(m_data) == std::get<NeoChatRoomType::Types>(m_data);
}
if (std::holds_alternative<NeoChatRoom *>(m_data) && std::holds_alternative<NeoChatRoom *>(other.data())) {
return std::get<NeoChatRoom *>(m_data)->id() == std::get<NeoChatRoom *>(m_data)->id();
}
return false;
}
RoomTreeItem *RoomTreeItem::child(int row)
{
return row >= 0 && row < childCount() ? m_children.at(row).get() : nullptr;
}
int RoomTreeItem::childCount() const
{
return int(m_children.size());
}
bool RoomTreeItem::insertChild(std::unique_ptr<RoomTreeItem> newChild)
{
if (newChild == nullptr) {
return false;
}
for (auto it = m_children.begin(), end = m_children.end(); it != end; ++it) {
if (*it == newChild) {
*it = std::move(newChild);
return true;
}
}
m_children.push_back(std::move(newChild));
return true;
}
bool RoomTreeItem::removeChild(int row)
{
if (row < 0 || row >= childCount()) {
return false;
}
m_children.erase(m_children.begin() + row);
return true;
}
int RoomTreeItem::row() const
{
if (m_parentItem == nullptr) {
return 0;
}
const auto it = std::find_if(m_parentItem->m_children.cbegin(), m_parentItem->m_children.cend(), [this](const std::unique_ptr<RoomTreeItem> &treeItem) {
return treeItem.get() == this;
});
if (it != m_parentItem->m_children.cend()) {
return std::distance(m_parentItem->m_children.cbegin(), it);
}
Q_ASSERT(false); // should not happen
return -1;
}
RoomTreeItem *RoomTreeItem::parentItem() const
{
return m_parentItem;
}
RoomTreeItem::TreeData RoomTreeItem::data() const
{
return m_data;
}
std::optional<int> RoomTreeItem::rowForRoom(Quotient::Room *room) const
{
Q_ASSERT_X(std::holds_alternative<NeoChatRoomType::Types>(m_data), __FUNCTION__, "rowForRoom only works items for rooms not categories");
int i = 0;
for (const auto &child : m_children) {
if (std::get<NeoChatRoom *>(child->data()) == room) {
return i;
}
i++;
}
return std::nullopt;
}

78
src/models/roomtreeitem.h Normal file
View File

@@ -0,0 +1,78 @@
// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "enums/neochatroomtype.h"
class NeoChatRoom;
/**
* @class RoomTreeItem
*
* This class defines an item in the space tree hierarchy model.
*
* @note This is separate from Quotient::Room and NeoChatRoom because we don't have
* full room information for any room/space the user hasn't joined and we
* don't want to create one for ever possible child in a space as that would
* be expensive.
*
* @sa Quotient::Room, NeoChatRoom
*/
class RoomTreeItem
{
public:
using TreeData = std::variant<NeoChatRoom *, NeoChatRoomType::Types>;
explicit RoomTreeItem(TreeData data, RoomTreeItem *parent = nullptr);
bool operator==(const RoomTreeItem &other) const;
/**
* @brief Return the child at the given row number.
*
* Nullptr is returned if there is no child at the given row number.
*/
RoomTreeItem *child(int row);
/**
* @brief The number of children this item has.
*/
int childCount() const;
/**
* @brief Insert the given child.
*/
bool insertChild(std::unique_ptr<RoomTreeItem> newChild);
/**
* @brief Remove the child at the given row number.
*
* @return True if a child was removed, false if the given row isn't valid.
*/
bool removeChild(int row);
/**
* @brief Return this item's parent.
*/
RoomTreeItem *parentItem() const;
/**
* @brief Return the row number for this child relative to the parent.
*
* @return The row value if the child has a parent, 0 otherwise.
*/
int row() const;
/**
* @brief Return this item's data.
*/
TreeData data() const;
std::optional<int> rowForRoom(Quotient::Room *room) const;
private:
std::vector<std::unique_ptr<RoomTreeItem>> m_children;
RoomTreeItem *m_parentItem;
TreeData m_data;
};

View File

@@ -15,21 +15,47 @@ using namespace Quotient;
RoomTreeModel::RoomTreeModel(QObject *parent)
: QAbstractItemModel(parent)
, m_rootItem(new RoomTreeItem(nullptr))
{
initializeCategories();
}
void RoomTreeModel::initializeCategories()
RoomTreeItem *RoomTreeModel::getItem(const QModelIndex &index) const
{
for (const auto &key : m_rooms.keys()) {
for (const auto &room : m_rooms[key]) {
room->disconnect(this);
if (index.isValid()) {
RoomTreeItem *item = static_cast<RoomTreeItem *>(index.internalPointer());
if (item) {
return item;
}
}
m_rooms.clear();
for (int i = 0; i < 8; i++) {
m_rooms[NeoChatRoomType::Types(i)] = {};
return m_rootItem.get();
}
void RoomTreeModel::resetModel()
{
if (m_connection == nullptr) {
beginResetModel();
m_rootItem.reset();
endResetModel();
return;
}
beginResetModel();
m_rootItem.reset(new RoomTreeItem(nullptr));
for (int i = 0; i < NeoChatRoomType::TypesCount; i++) {
m_rootItem->insertChild(std::make_unique<RoomTreeItem>(NeoChatRoomType::Types(i), m_rootItem.get()));
}
for (const auto &r : m_connection->allRooms()) {
const auto room = dynamic_cast<NeoChatRoom *>(r);
const auto type = NeoChatRoomType::typeForRoom(room);
const auto categoryItem = m_rootItem->child(type);
if (categoryItem->insertChild(std::make_unique<RoomTreeItem>(room, categoryItem))) {
connectRoomSignals(room);
}
}
endResetModel();
}
void RoomTreeModel::setConnection(NeoChatConnection *connection)
@@ -41,16 +67,13 @@ void RoomTreeModel::setConnection(NeoChatConnection *connection)
disconnect(m_connection.get(), nullptr, this, nullptr);
}
m_connection = connection;
beginResetModel();
initializeCategories();
endResetModel();
resetModel();
connect(connection, &Connection::newRoom, this, &RoomTreeModel::newRoom);
connect(connection, &Connection::leftRoom, this, &RoomTreeModel::leftRoom);
connect(connection, &Connection::aboutToDeleteRoom, this, &RoomTreeModel::leftRoom);
for (const auto &room : m_connection->allRooms()) {
newRoom(dynamic_cast<NeoChatRoom *>(room));
}
Q_EMIT connectionChanged();
}
@@ -68,23 +91,28 @@ void RoomTreeModel::newRoom(Room *r)
return;
}
beginInsertRows(index(type, 0), m_rooms[type].size(), m_rooms[type].size());
m_rooms[type].append(room);
const auto parentItem = m_rootItem->child(type);
beginInsertRows(index(parentItem->row(), 0), parentItem->childCount(), parentItem->childCount());
parentItem->insertChild(std::make_unique<RoomTreeItem>(room, parentItem));
connectRoomSignals(room);
endInsertRows();
qWarning() << "adding room" << type << "new count" << parentItem->childCount();
}
void RoomTreeModel::leftRoom(Room *r)
{
const auto room = dynamic_cast<NeoChatRoom *>(r);
const auto type = NeoChatRoomType::typeForRoom(room);
auto row = m_rooms[type].indexOf(room);
if (row == -1) {
auto index = indexForRoom(room);
if (!index.isValid()) {
return;
}
beginRemoveRows(index(type, 0), row, row);
m_rooms[type][row]->disconnect(this);
m_rooms[type].removeAt(row);
const auto parentItem = getItem(index.parent());
Q_ASSERT(parentItem);
beginRemoveRows(index.parent(), index.row(), index.row());
parentItem->removeChild(index.row());
room->disconnect(this);
endRemoveRows();
}
@@ -94,30 +122,41 @@ void RoomTreeModel::moveRoom(Quotient::Room *room)
// NeoChatRoomType::typeForRoom doesn't match it's current location. So find the room.
NeoChatRoomType::Types oldType;
int oldRow = -1;
for (const auto &key : m_rooms.keys()) {
if (m_rooms[key].contains(room)) {
oldType = key;
oldRow = m_rooms[key].indexOf(room);
for (int i = 0; i < NeoChatRoomType::TypesCount; i++) {
const auto categoryItem = m_rootItem->child(i);
const auto row = categoryItem->rowForRoom(room);
if (row) {
oldType = static_cast<NeoChatRoomType::Types>(i);
oldRow = *row;
}
}
if (oldRow == -1) {
return;
}
const auto newType = NeoChatRoomType::typeForRoom(dynamic_cast<NeoChatRoom *>(room));
auto neochatRoom = dynamic_cast<NeoChatRoom *>(room);
const auto newType = NeoChatRoomType::typeForRoom(neochatRoom);
if (newType == oldType) {
return;
}
const auto oldParent = index(oldType, 0, {});
auto oldParentItem = getItem(oldParent);
Q_ASSERT(oldParentItem);
const auto newParent = index(newType, 0, {});
auto newParentItem = getItem(newParent);
Q_ASSERT(newParentItem);
// HACK: We're doing this as a remove then insert because moving doesn't work
// properly with DelegateChooser for whatever reason.
Q_ASSERT(checkIndex(index(oldRow, 0, oldParent), QAbstractItemModel::CheckIndexOption::IndexIsValid));
beginRemoveRows(oldParent, oldRow, oldRow);
m_rooms[oldType].removeAt(oldRow);
const bool success = oldParentItem->removeChild(oldRow);
Q_ASSERT(success);
endRemoveRows();
beginInsertRows(newParent, m_rooms[newType].size(), m_rooms[newType].size());
m_rooms[newType].append(dynamic_cast<NeoChatRoom *>(room));
beginInsertRows(newParent, newParentItem->childCount(), newParentItem->childCount());
newParentItem->insertChild(std::make_unique<RoomTreeItem>(neochatRoom, newParentItem));
endInsertRows();
}
@@ -151,15 +190,12 @@ void RoomTreeModel::connectRoomSignals(NeoChatRoom *room)
void RoomTreeModel::refreshRoomRoles(NeoChatRoom *room, const QList<int> &roles)
{
const auto roomType = NeoChatRoomType::typeForRoom(room);
const auto it = std::find(m_rooms[roomType].begin(), m_rooms[roomType].end(), room);
if (it == m_rooms[roomType].end()) {
const auto index = indexForRoom(room);
if (!index.isValid()) {
qCritical() << "Room" << room->id() << "not found in the room list";
return;
}
const auto parentIndex = index(roomType, 0, {});
const auto idx = index(it - m_rooms[roomType].begin(), 0, parentIndex);
Q_EMIT dataChanged(idx, idx, roles);
Q_EMIT dataChanged(index, index, roles);
}
NeoChatConnection *RoomTreeModel::connection() const
@@ -175,32 +211,55 @@ int RoomTreeModel::columnCount(const QModelIndex &parent) const
int RoomTreeModel::rowCount(const QModelIndex &parent) const
{
RoomTreeItem *parentItem;
if (parent.column() > 0) {
return 0;
}
if (!parent.isValid()) {
return m_rooms.keys().size();
parentItem = m_rootItem.get();
} else {
parentItem = static_cast<RoomTreeItem *>(parent.internalPointer());
}
if (!parent.parent().isValid()) {
return m_rooms.values()[parent.row()].size();
}
return 0;
return parentItem->childCount();
}
QModelIndex RoomTreeModel::parent(const QModelIndex &index) const
{
if (!index.internalPointer()) {
return {};
if (!index.isValid()) {
return QModelIndex();
}
return this->index(NeoChatRoomType::typeForRoom(static_cast<NeoChatRoom *>(index.internalPointer())), 0, QModelIndex());
RoomTreeItem *childItem = static_cast<RoomTreeItem *>(index.internalPointer());
if (!childItem) {
return QModelIndex();
}
RoomTreeItem *parentItem = childItem->parentItem();
if (parentItem == m_rootItem.get()) {
return QModelIndex();
}
return createIndex(parentItem->row(), 0, parentItem);
}
QModelIndex RoomTreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (!parent.isValid()) {
return createIndex(row, column, nullptr);
if (!hasIndex(row, column, parent)) {
return QModelIndex();
}
if (row >= rowCount(parent)) {
return {};
RoomTreeItem *parentItem = getItem(parent);
if (!parentItem) {
return QModelIndex();
}
return createIndex(row, column, m_rooms[NeoChatRoomType::Types(parent.row())][row]);
RoomTreeItem *childItem = parentItem->child(row);
if (childItem) {
return createIndex(row, column, childItem);
}
return QModelIndex();
}
QHash<int, QByteArray> RoomTreeModel::roleNames() const
@@ -235,7 +294,8 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const
return QVariant();
}
if (!index.parent().isValid()) {
RoomTreeItem *child = getItem(index);
if (std::holds_alternative<NeoChatRoomType::Types>(child->data())) {
if (role == DisplayNameRole) {
return NeoChatRoomType::typeName(index.row());
}
@@ -256,7 +316,8 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const
}
return {};
}
const auto room = m_rooms.values()[index.parent().row()][index.row()].get();
const auto room = std::get<NeoChatRoom *>(child->data());
Q_ASSERT(room);
if (role == DisplayNameRole) {
@@ -338,16 +399,20 @@ QModelIndex RoomTreeModel::indexForRoom(NeoChatRoom *room) const
// Try and find by checking type.
const auto type = NeoChatRoomType::typeForRoom(room);
auto row = m_rooms[type].indexOf(room);
if (row >= 0) {
return index(row, 0, index(type, 0));
const auto parentItem = m_rootItem->child(type);
const auto row = parentItem->rowForRoom(room);
if (row) {
return index(*row, 0, index(type, 0));
}
// Double check that the room isn't in the wrong category.
for (const auto &key : m_rooms.keys()) {
if (m_rooms[key].contains(room)) {
return index(m_rooms[key].indexOf(room), 0, index(key, 0));
for (int i = 0; i < NeoChatRoomType::TypesCount; i++) {
const auto parentItem = m_rootItem->child(i);
const auto row = parentItem->rowForRoom(room);
if (row) {
return index(*row, 0, index(i, 0));
}
}
return {};
}

View File

@@ -7,6 +7,7 @@
#include <QPointer>
#include "enums/neochatroomtype.h"
#include "roomtreeitem.h"
namespace Quotient
{
@@ -82,10 +83,12 @@ Q_SIGNALS:
void connectionChanged();
private:
QPointer<NeoChatConnection> m_connection = nullptr;
QMap<NeoChatRoomType::Types, QList<QPointer<NeoChatRoom>>> m_rooms;
QPointer<NeoChatConnection> m_connection;
std::unique_ptr<RoomTreeItem> m_rootItem;
void initializeCategories();
RoomTreeItem *getItem(const QModelIndex &index) const;
void resetModel();
void connectRoomSignals(NeoChatRoom *room);
void newRoom(Quotient::Room *room);

View File

@@ -5,17 +5,20 @@
#include "roomlistmodel.h"
SortFilterRoomListModel::SortFilterRoomListModel(QObject *parent)
SortFilterRoomListModel::SortFilterRoomListModel(RoomListModel *sourceModel, QObject *parent)
: QSortFilterProxyModel(parent)
{
Q_ASSERT(sourceModel);
setSourceModel(sourceModel);
sort(0);
invalidateFilter();
connect(this, &SortFilterRoomListModel::filterTextChanged, this, [this]() {
invalidateFilter();
});
connect(this, &SortFilterRoomListModel::sourceModelChanged, this, [this]() {
connect(sourceModel(), &QAbstractListModel::rowsInserted, this, &SortFilterRoomListModel::invalidateRowsFilter);
connect(sourceModel(), &QAbstractListModel::rowsRemoved, this, &SortFilterRoomListModel::invalidateRowsFilter);
connect(this->sourceModel(), &QAbstractListModel::rowsInserted, this, &SortFilterRoomListModel::invalidateRowsFilter);
connect(this->sourceModel(), &QAbstractListModel::rowsRemoved, this, &SortFilterRoomListModel::invalidateRowsFilter);
});
}

View File

@@ -6,6 +6,8 @@
#include <QQmlEngine>
#include <QSortFilterProxyModel>
#include "models/roomlistmodel.h"
/**
* @class SortFilterRoomListModel
*
@@ -29,6 +31,7 @@ class SortFilterRoomListModel : public QSortFilterProxyModel
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")
/**
* @brief The text to use to filter room names.
@@ -36,7 +39,7 @@ class SortFilterRoomListModel : public QSortFilterProxyModel
Q_PROPERTY(QString filterText READ filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged)
public:
explicit SortFilterRoomListModel(QObject *parent = nullptr);
explicit SortFilterRoomListModel(RoomListModel *sourceModel, QObject *parent = nullptr);
void setFilterText(const QString &text);
[[nodiscard]] QString filterText() const;

View File

@@ -10,9 +10,12 @@
#include "roomtreemodel.h"
#include "spacehierarchycache.h"
SortFilterRoomTreeModel::SortFilterRoomTreeModel(QObject *parent)
SortFilterRoomTreeModel::SortFilterRoomTreeModel(RoomTreeModel *sourceModel, QObject *parent)
: QSortFilterProxyModel(parent)
{
Q_ASSERT(sourceModel);
setSourceModel(sourceModel);
setRoomSortOrder(static_cast<RoomSortOrder>(NeoChatConfig::sortOrder()));
connect(NeoChatConfig::self(), &NeoChatConfig::SortOrderChanged, this, [this]() {
setRoomSortOrder(static_cast<RoomSortOrder>(NeoChatConfig::sortOrder()));
@@ -21,12 +24,11 @@ SortFilterRoomTreeModel::SortFilterRoomTreeModel(QObject *parent)
setRecursiveFilteringEnabled(true);
sort(0);
invalidateFilter();
connect(this, &SortFilterRoomTreeModel::filterTextChanged, this, &SortFilterRoomTreeModel::invalidateFilter);
connect(this, &SortFilterRoomTreeModel::sourceModelChanged, this, [this]() {
sourceModel()->disconnect(this);
connect(sourceModel(), &QAbstractItemModel::rowsInserted, this, &SortFilterRoomTreeModel::invalidateFilter);
connect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, &SortFilterRoomTreeModel::invalidateFilter);
this->sourceModel()->disconnect(this);
connect(this->sourceModel(), &QAbstractItemModel::rowsInserted, this, &SortFilterRoomTreeModel::invalidateFilter);
connect(this->sourceModel(), &QAbstractItemModel::rowsRemoved, this, &SortFilterRoomTreeModel::invalidateFilter);
});
connect(NeoChatConfig::self(), &NeoChatConfig::CollapsedChanged, this, &SortFilterRoomTreeModel::invalidateFilter);

View File

@@ -32,6 +32,7 @@ class SortFilterRoomTreeModel : public QSortFilterProxyModel
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")
/**
* @brief The text to use to filter room names.
@@ -62,7 +63,7 @@ public:
};
Q_ENUM(Mode)
explicit SortFilterRoomTreeModel(QObject *parent = nullptr);
explicit SortFilterRoomTreeModel(RoomTreeModel *sourceModel, QObject *parent = nullptr);
void setRoomSortOrder(RoomSortOrder sortOrder);

View File

@@ -5,22 +5,21 @@
#include "roomlistmodel.h"
SortFilterSpaceListModel::SortFilterSpaceListModel(QObject *parent)
SortFilterSpaceListModel::SortFilterSpaceListModel(RoomListModel *sourceModel, QObject *parent)
: QSortFilterProxyModel{parent}
{
setSortRole(RoomListModel::RoomIdRole);
sort(0);
invalidateFilter();
connect(this, &QAbstractProxyModel::sourceModelChanged, this, [this]() {
connect(sourceModel(), &QAbstractListModel::dataChanged, this, [this](const QModelIndex &, const QModelIndex &, QList<int> roles) {
if (roles.contains(RoomListModel::IsChildSpaceRole)) {
invalidate();
}
countChanged();
});
invalidate();
Q_ASSERT(sourceModel);
setSourceModel(sourceModel);
connect(this->sourceModel(), &QAbstractListModel::dataChanged, this, [this](const QModelIndex &, const QModelIndex &, QList<int> roles) {
if (roles.contains(RoomListModel::IsChildSpaceRole)) {
invalidate();
}
Q_EMIT countChanged();
});
setSortRole(RoomListModel::RoomIdRole);
sort(0);
}
bool SortFilterSpaceListModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const

View File

@@ -6,6 +6,8 @@
#include <QQmlEngine>
#include <QSortFilterProxyModel>
#include "models/roomlistmodel.h"
/**
* @class SortFilterSpaceListModel
*
@@ -18,6 +20,7 @@ class SortFilterSpaceListModel : public QSortFilterProxyModel
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")
/**
* @brief The number of spaces in the model.
@@ -25,7 +28,7 @@ class SortFilterSpaceListModel : public QSortFilterProxyModel
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public:
explicit SortFilterSpaceListModel(QObject *parent = nullptr);
explicit SortFilterSpaceListModel(RoomListModel *sourceModel, QObject *parent = nullptr);
Q_SIGNALS:
void countChanged();

View File

@@ -5,6 +5,7 @@
"Name": "Tobias Fella",
"Name[ca@valencia]": "Tobias Fella",
"Name[ca]": "Tobias Fella",
"Name[cs]": "Tobias Fella",
"Name[de]": "Tobias Fella",
"Name[es]": "Tobias Fella",
"Name[eu]": "Tobias Fella",
@@ -49,6 +50,7 @@
"Name[ast]": "NeoChat",
"Name[ca@valencia]": "NeoChat",
"Name[ca]": "NeoChat",
"Name[cs]": "NeoChat",
"Name[de]": "NeoChat",
"Name[es]": "NeoChat",
"Name[eu]": "NeoChat",

View File

@@ -9,6 +9,7 @@ import org.kde.kirigami as Kirigami
import org.kde.neochat
import org.kde.neochat.settings
import org.kde.neochat.devtools
import org.kde.neochat.config
QQC2.Menu {
@@ -55,7 +56,7 @@ QQC2.Menu {
text: i18n("Open developer tools")
icon.name: "tools"
visible: Config.developerTools
onTriggered: pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'DevtoolsPage.qml'), {
onTriggered: pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat.devtools', 'DevtoolsPage.qml'), {
connection: root.connection
}, {
title: i18nc("@title:window", "Developer Tools"),

View File

@@ -18,16 +18,11 @@ Kirigami.ScrollablePage {
required property NeoChatConnection connection
header: Kirigami.SearchField {
onTextChanged: sortModel.filterText = text
onTextChanged: RoomManager.sortFilterRoomListModel.filterText = text
}
ListView {
model: SortFilterRoomListModel {
id: sortModel
sourceModel: RoomListModel {
connection: root.connection
}
}
model: RoomManager.sortFilterRoomListModel
delegate: RoomDelegate {
id: roomDelegate
onClicked: {
@@ -36,4 +31,6 @@ Kirigami.ScrollablePage {
connection: root.connection
}
}
Component.onCompleted: Qt.callLater(() => header.forceActiveFocus())
}

View File

@@ -0,0 +1,169 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigamiaddons.labs.components as Components
import org.kde.kirigami as Kirigami
import org.kde.syntaxhighlighting
import org.kde.neochat
Components.AbstractMaximizeComponent {
id: root
/**
* @brief The message author.
*
* This should consist of the following:
* - id - The matrix ID of the author.
* - isLocalUser - Whether the author is the local user.
* - avatarSource - The mxc URL for the author's avatar in the current room.
* - avatarMediaId - The media ID of the author's avatar.
* - avatarUrl - The mxc URL for the author's avatar.
* - displayName - The display name of the author.
* - display - The name of the author.
* - color - The color for the author.
* - object - The Quotient::User object for the author.
*
* @sa Quotient::User
*/
property var author
/**
* @brief The timestamp of the message.
*/
property var time
/**
* @brief The code text to show.
*/
property string codeText
/**
* @brief The code language, if any.
*/
property string language
actions: [
Kirigami.Action {
text: i18nc("@action", "Copy to clipboard")
icon.name: "edit-copy"
onTriggered: Clipboard.saveText(root.codeText)
}
]
leading: RowLayout {
Components.Avatar {
id: userAvatar
implicitWidth: Kirigami.Units.iconSizes.medium
implicitHeight: Kirigami.Units.iconSizes.medium
name: root.author.name ?? root.author.displayName
source: root.author.avatarSource
color: root.author.color
}
ColumnLayout {
spacing: 0
QQC2.Label {
id: userLabel
text: root.author.name ?? root.author.displayName
color: root.author.color
font.weight: Font.Bold
elide: Text.ElideRight
}
QQC2.Label {
id: dateTimeLabel
text: root.time.toLocaleString(Qt.locale(), Locale.ShortFormat)
color: Kirigami.Theme.disabledTextColor
elide: Text.ElideRight
}
}
}
content: QQC2.ScrollView {
id: codeScrollView
contentWidth: root.width
// HACK: Hide unnecessary horizontal scrollbar (https://bugreports.qt.io/browse/QTBUG-83890)
QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff
QQC2.TextArea {
id: codeText
topPadding: Kirigami.Units.smallSpacing
bottomPadding: Kirigami.Units.smallSpacing
leftPadding: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing * 2
text: root.codeText
readOnly: true
textFormat: TextEdit.PlainText
wrapMode: TextEdit.Wrap
color: Kirigami.Theme.textColor
font.family: "monospace"
Kirigami.SpellCheck.enabled: false
onWidthChanged: lineModel.resetModel()
onHeightChanged: lineModel.resetModel()
SyntaxHighlighter {
property string definitionName: Repository.definitionForName(root.language).name
textEdit: definitionName == "None" ? null : codeText
definition: definitionName
}
ColumnLayout {
id: lineNumberColumn
anchors {
top: codeText.top
topMargin: codeText.topPadding + 1
left: codeText.left
leftMargin: Kirigami.Units.smallSpacing
}
spacing: 0
Repeater {
id: repeater
model: LineModel {
id: lineModel
document: codeText.textDocument
}
delegate: QQC2.Label {
id: label
required property int index
required property int docLineHeight
Layout.fillWidth: true
Layout.preferredHeight: docLineHeight
horizontalAlignment: Text.AlignRight
text: index + 1
color: Kirigami.Theme.disabledTextColor
font.family: "monospace"
}
}
}
Kirigami.Separator {
anchors {
top: parent.top
bottom: parent.bottom
left: parent.left
leftMargin: lineNumberColumn.width + lineNumberColumn.anchors.leftMargin + Kirigami.Units.smallSpacing
}
}
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: root.close()
}
background: null
}
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
color: Kirigami.Theme.backgroundColor
}
}
}

View File

@@ -25,13 +25,8 @@ QQC2.Popup {
root.open();
}
RoomListModel {
id: roomListModel
connection: root.connection
}
Component.onCompleted: {
chatDocumentHandler.completionModel.roomListModel = roomListModel;
chatDocumentHandler.completionModel.roomListModel = RoomManager.roomListModel;
}
function incrementIndex() {

View File

@@ -14,11 +14,11 @@ Kirigami.Dialog {
width: Kirigami.Units.gridUnit * 24
height: Kirigami.Units.gridUnit * 8
title: i18nc("@title", "Open Url")
standardButtons: Kirigami.Dialog.Yes | Kirigami.Dialog.No
title: i18nc("@title", "Open URL")
standardButtons: QQC2.DialogButtonBox.Open | QQC2.DialogButtonBox.Cancel
contentItem: QQC2.Label {
text: i18nc("Do you want to open <link>", "Do you want to open <b>%1</b>?", root.link)
text: xi18nc("@info", "Do you want to open <link>%1</link>?", root.link)
wrapMode: QQC2.Label.Wrap
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter

View File

@@ -84,6 +84,7 @@ Loader {
* Some common actions shared between menus
*/
component ViewSourceAction: Kirigami.Action {
visible: Config.developerTools
text: i18n("View Source")
icon.name: "code-context"
onTriggered: RoomManager.viewEventSource(root.eventId)

View File

@@ -47,10 +47,12 @@ ApplicationWindow {
isLive: true
heading: NaN
visible: !isNaN(root.latitude) && !isNaN(root.longitude)
Component.onCompleted: mapView.map.addMapItem(this)
}
MapItemView {
model: root.liveLocationModel
delegate: LocationMapItem {}
Component.onCompleted: mapView.map.addMapItemView(this)
}
Connections {

View File

@@ -35,52 +35,25 @@ Components.AbstractMaximizeComponent {
content: MapView {
id: mapView
map.plugin: Plugin {
name: "osm"
PluginParameter {
name: "osm.useragent"
value: Application.name + "/" + Application.version + " (kde-devel@kde.org)"
}
PluginParameter {
name: "osm.mapping.providersrepository.address"
value: "https://autoconfig.kde.org/qtlocation/"
}
}
map.plugin: OsmLocationPlugin.plugin
MouseArea {
anchors.fill: parent
onClicked: {
root.location = mapView.map.toCoordinate(Qt.point(mouseX, mouseY), false);
mapView.map.addMapItem(mapView.locationMapItem);
}
}
MapQuickItem {
id: point
visible: root.location
anchorPoint.x: sourceItem.width / 2
anchorPoint.y: sourceItem.height * 0.85
coordinate: root.location
autoFadeIn: false
sourceItem: Kirigami.Icon {
width: height
height: Kirigami.Units.iconSizes.huge
source: "gps"
isMask: true
color: Kirigami.Theme.highlightColor
Kirigami.Icon {
anchors.centerIn: parent
anchors.verticalCenterOffset: -parent.height / 8
width: height
height: parent.height / 3 + 1
source: "pin"
isMask: true
color: Kirigami.Theme.highlightColor
}
}
readonly property LocationMapItem locationMapItem: LocationMapItem {
latitude: root.location.latitude
longitude: root.location.longitude
isLive: false
heading: NaN
asset: ""
author: null
}
Connections {
target: mapView.map
function onCopyrightLinkActivated() {

View File

@@ -29,17 +29,22 @@ Kirigami.Page {
map.zoomLevel: LocationHelper.zoomToFit(LocationHelper.unite(locationsModel.boundingBox, liveLocationsModel.boundingBox), mapView.width, mapView.height)
MapItemView {
Component.onCompleted: mapView.map.addMapItemView(this)
anchors.fill: parent
model: LocationsModel {
id: locationsModel
room: root.room
}
delegate: LocationMapItem {
isLive: true
isLive: false
heading: NaN
}
}
MapItemView {
Component.onCompleted: mapView.map.addMapItemView(this)
anchors.fill: parent
model: LiveLocationsModel {
id: liveLocationsModel
room: root.room
@@ -49,7 +54,7 @@ Kirigami.Page {
Kirigami.PlaceholderMessage {
text: i18n("There are no locations shared in this room.")
visible: mapView.mapItems.length === 0
visible: mapView.map.mapItems.length === 0
anchors.centerIn: parent
}
Connections {

View File

@@ -7,11 +7,14 @@ import QtQuick
import QtLocation
QtObject {
id: root
property string userAgent: Application.name + "/" + Application.version + " (kde-devel@kde.org)"
property var plugin: Plugin {
name: "osm"
PluginParameter {
name: "osm.useragent"
value: Application.name + "/" + Application.version + " (kde-devel@kde.org)"
value: root.userAgent
}
PluginParameter {
name: "osm.mapping.providersrepository.address"

View File

@@ -38,7 +38,7 @@ Kirigami.Page {
formats: Prison.Format.QRCode | Prison.Format.Aztec
onResultChanged: {
if (result.text.length > 0 && result.text != scanner.previousText) {
RoomManager.resolveResource(result.text, "");
RoomManager.resolveResource(result.text, "qr");
scanner.previousText = result.text;
}
root.closeDialog();

View File

@@ -66,6 +66,7 @@ QQC2.Dialog {
root.close();
}
focusSequence: ""
onTextChanged: RoomManager.sortFilterRoomListModel.filterText = text
}
QQC2.ScrollView {
@@ -81,13 +82,7 @@ QQC2.Dialog {
highlightMoveDuration: 200
Keys.forwardTo: searchField
keyNavigationEnabled: true
model: SortFilterRoomListModel {
filterText: searchField.text
sourceModel: RoomListModel {
id: roomListModel
connection: root.connection
}
}
model: RoomManager.sortFilterRoomListModel
delegate: RoomDelegate {
connection: root.connection

View File

@@ -29,10 +29,6 @@ Kirigami.Page {
required property NeoChatConnection connection
readonly property RoomTreeModel roomTreeModel: RoomTreeModel {
connection: root.connection
}
readonly property bool collapsed: Config.collapsed
onCurrentWidthChanged: pageStack.defaultColumnWidth = root.currentWidth
@@ -41,7 +37,7 @@ Kirigami.Page {
onCollapsedChanged: {
if (collapsed) {
sortFilterRoomTreeModel.filterText = "";
RoomManager.sortFilterRoomTreeModel.filterText = "";
}
}
@@ -107,8 +103,6 @@ Kirigami.Page {
Layout.fillHeight: true
connection: root.connection
onSpacesUpdated: sortFilterRoomTreeModel.invalidate()
}
Kirigami.Separator {
@@ -136,15 +130,7 @@ Kirigami.Page {
clip: true
reuseItems: false
model: SortFilterRoomTreeModel {
id: sortFilterRoomTreeModel
sourceModel: root.roomTreeModel
activeSpaceId: RoomManager.currentSpace
mode: RoomManager.currentSpace === "DM" ? SortFilterRoomTreeModel.DirectChats : SortFilterRoomTreeModel.Rooms
onRowsInserted: (index, first, last) => treeView.expandTo(index)
onDataChanged: treeView.expandRecursively()
}
model: RoomManager.sortFilterRoomTreeModel
selectionModel: ItemSelectionModel {}
@@ -217,7 +203,7 @@ Kirigami.Page {
anchors.horizontalCenterOffset: (spaceDrawer.width + 1) / 2
width: scrollView.width - Kirigami.Units.largeSpacing * 4
visible: treeView.rows == 0
text: if (sortFilterRoomTreeModel.filterText.length > 0) {
text: if (RoomManager.sortFilterRoomTreeModel.filterText.length > 0) {
return spaceDrawer.showDirectChats ? i18n("No friends found") : i18n("No rooms found");
} else {
return spaceDrawer.showDirectChats ? i18n("You haven't added any of your friends yet, click below to search for them.") : i18n("Join some rooms to get started");
@@ -226,12 +212,12 @@ Kirigami.Page {
Kirigami.Action {
id: exploreRoomAction
icon.name: sortFilterRoomTreeModel.filterText.length > 0 ? "search" : "list-add"
text: sortFilterRoomTreeModel.filterText.length > 0 ? i18n("Search in room directory") : i18n("Explore rooms")
icon.name: RoomManager.sortFilterRoomTreeModel.filterText.length > 0 ? "search" : "list-add"
text: RoomManager.sortFilterRoomTreeModel.filterText.length > 0 ? i18n("Search in room directory") : i18n("Explore rooms")
onTriggered: {
let dialog = pageStack.layers.push(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage.qml'), {
connection: root.connection,
keyword: sortFilterRoomTreeModel.filterText
keyword: RoomManager.sortFilterRoomTreeModel.filterText
}, {
title: i18nc("@title", "Explore Rooms")
});
@@ -243,8 +229,8 @@ Kirigami.Page {
Kirigami.Action {
id: userSearchAction
icon.name: sortFilterRoomTreeModel.filterText.length > 0 ? "search" : "list-add"
text: sortFilterRoomTreeModel.filterText.length > 0 ? i18n("Search in friend directory") : i18n("Find your friends")
icon.name: RoomManager.sortFilterRoomTreeModel.filterText.length > 0 ? "search" : "list-add"
text: RoomManager.sortFilterRoomTreeModel.filterText.length > 0 ? i18n("Search in friend directory") : i18n("Find your friends")
onTriggered: pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'UserSearchPage.qml'), {
connection: root.connection
}, {
@@ -325,7 +311,7 @@ Kirigami.Page {
connection: root.connection
onTextChanged: newText => {
sortFilterRoomTreeModel.filterText = newText;
RoomManager.sortFilterRoomTreeModel.filterText = newText;
treeView.expandRecursively();
}
}
@@ -337,7 +323,7 @@ Kirigami.Page {
connection: root.connection
onTextChanged: newText => {
sortFilterRoomTreeModel.filterText = newText;
RoomManager.sortFilterRoomTreeModel.filterText = newText;
}
}
}

View File

@@ -298,6 +298,15 @@ Kirigami.Page {
});
popup.open();
}
function onShowMaximizedCode(author, time, codeText, language) {
let popup = Qt.createComponent('org.kde.neochat', 'CodeMaximizeComponent.qml').createObject(QQC2.Overlay.overlay, {
author: author,
time: time,
codeText: codeText,
language: language
}).open();
}
}
Component {

View File

@@ -21,8 +21,6 @@ QQC2.Control {
topPadding: 0
bottomPadding: 0
signal spacesUpdated
contentItem: Loader {
id: sidebarColumn
z: 0
@@ -169,12 +167,7 @@ QQC2.Control {
}
Repeater {
model: SortFilterSpaceListModel {
sourceModel: RoomListModel {
connection: root.connection
}
onLayoutChanged: root.spacesUpdated()
}
model: RoomManager.sortFilterSpaceListModel
delegate: AvatarTabButton {
id: spaceDelegate
@@ -194,7 +187,6 @@ QQC2.Control {
onSelected: {
RoomManager.resolveResource(spaceDelegate.roomId);
RoomManager.currentSpace = spaceDelegate.roomId;
root.selectionChanged();
}
checked: RoomManager.currentSpace === roomId
onContextMenuRequested: root.createContextMenu(currentRoom)

View File

@@ -119,17 +119,6 @@ Kirigami.ApplicationWindow {
root.showUserDetail(user);
}
function onReplaceSpaceHome(room) {
if (root.spaceHomePage) {
pageStack.currentIndex = pageStack.depth - 1;
} else {
pageStack.pop();
root.spaceHomePage = pageStack.push(Qt.createComponent('org.kde.neochat', 'SpaceHomePage.qml'));
root.roomPage = null;
}
root.spaceHomePage.forceActiveFocus();
}
function goToEvent(event) {
if (event.length > 0) {
roomItem.goToEvent(event);
@@ -424,7 +413,7 @@ Kirigami.ApplicationWindow {
}
}
function handleShare(): void {
const dialog = applicationWindow().pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ChooseRoomDialog.qml", {
const dialog = applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ChooseRoomDialog.qml'), {
connection: root.connection
}, {
title: i18nc("@title", "Share"),

View File

@@ -11,6 +11,7 @@
#include "neochatconnection.h"
#include "neochatroom.h"
#include "spacehierarchycache.h"
#include "urlhelper.h"
#include <KLocalizedString>
#include <QDesktopServices>
@@ -29,6 +30,11 @@
RoomManager::RoomManager(QObject *parent)
: QObject(parent)
, m_config(KSharedConfig::openStateConfig())
, m_roomListModel(new RoomListModel(this))
, m_sortFilterRoomListModel(new SortFilterRoomListModel(m_roomListModel, this))
, m_sortFilterSpaceListModel(new SortFilterSpaceListModel(m_roomListModel, this))
, m_roomTreeModel(new RoomTreeModel(this))
, m_sortFilterRoomTreeModel(new SortFilterRoomTreeModel(m_roomTreeModel, this))
, m_timelineModel(new TimelineModel(this))
, m_messageFilterModel(new MessageFilterModel(this, m_timelineModel))
, m_mediaMessageFilterModel(new MediaMessageFilterModel(this, m_messageFilterModel))
@@ -44,6 +50,11 @@ RoomManager::RoomManager(QObject *parent)
connect(&Controller::instance(), &Controller::activeConnectionChanged, this, [this](NeoChatConnection *connection) {
setConnection(connection);
});
connect(this, &RoomManager::connectionChanged, this, [this]() {
m_roomListModel->setConnection(m_connection);
m_roomTreeModel->setConnection(m_connection);
});
connect(m_sortFilterSpaceListModel, &SortFilterSpaceListModel::layoutChanged, m_sortFilterRoomTreeModel, &SortFilterRoomTreeModel::invalidate);
}
RoomManager::~RoomManager()
@@ -61,6 +72,31 @@ NeoChatRoom *RoomManager::currentRoom() const
return m_currentRoom;
}
RoomListModel *RoomManager::roomListModel() const
{
return m_roomListModel;
}
SortFilterRoomListModel *RoomManager::sortFilterRoomListModel() const
{
return m_sortFilterRoomListModel;
}
SortFilterSpaceListModel *RoomManager::sortFilterSpaceListModel() const
{
return m_sortFilterSpaceListModel;
}
RoomTreeModel *RoomManager::roomTreeModel() const
{
return m_roomTreeModel;
}
SortFilterRoomTreeModel *RoomManager::sortFilterRoomTreeModel() const
{
return m_sortFilterRoomTreeModel;
}
TimelineModel *RoomManager::timelineModel() const
{
return m_timelineModel;
@@ -89,6 +125,11 @@ void RoomManager::resolveResource(const QString &idOrUri, const QString &action)
return;
}
if (uri.type() == Uri::NonMatrix && action == "qr"_ls) {
Q_EMIT externalUrl(uri.toUrl());
return;
}
if (uri.type() != Uri::NonMatrix) {
if (!m_connection) {
return;
@@ -123,6 +164,14 @@ void RoomManager::maximizeMedia(int index)
Q_EMIT showMaximizedMedia(index);
}
void RoomManager::maximizeCode(const QVariantMap &author, const QDateTime &time, const QString &codeText, const QString &language)
{
if (codeText.isEmpty()) {
return;
}
Q_EMIT showMaximizedCode(author, time, codeText, language);
}
void RoomManager::requestFullScreenClose()
{
Q_EMIT closeFullScreen();
@@ -282,7 +331,7 @@ void RoomManager::knockRoom(Quotient::Connection *account, const QString &roomAl
bool RoomManager::visitNonMatrix(const QUrl &url)
{
Q_EMIT externalUrl(url);
UrlHelper().openUrl(url);
return true;
}
@@ -327,6 +376,11 @@ void RoomManager::setConnection(NeoChatConnection *connection)
void RoomManager::setCurrentSpace(const QString &spaceId, bool setRoom)
{
m_currentSpaceId = spaceId;
// This need to happen before the signal so TreeView.expandRecursively() can work nicely.
m_sortFilterRoomTreeModel->setActiveSpaceId(m_currentSpaceId);
m_sortFilterRoomTreeModel->setMode(m_currentSpaceId == QLatin1String("DM") ? SortFilterRoomTreeModel::DirectChats : SortFilterRoomTreeModel::Rooms);
Q_EMIT currentSpaceChanged();
m_lastSpaceConfig.writeEntry(m_connection->userId(), spaceId);
@@ -357,8 +411,10 @@ void RoomManager::setCurrentRoom(const QString &roomId)
if (m_currentRoom->isSpace()) {
return;
}
if (m_currentRoom->isDirectChat() && m_currentSpaceId != "DM"_ls) {
setCurrentSpace("DM"_ls, false);
if (m_currentRoom->isDirectChat()) {
if (m_currentSpaceId != "DM"_ls) {
setCurrentSpace("DM"_ls, false);
}
return;
}
const auto &parentSpaces = SpaceHierarchyCache::instance().parentSpaces(roomId);

View File

@@ -15,6 +15,11 @@
#include "eventhandler.h"
#include "models/mediamessagefiltermodel.h"
#include "models/messagefiltermodel.h"
#include "models/roomlistmodel.h"
#include "models/roomtreemodel.h"
#include "models/sortfilterroomlistmodel.h"
#include "models/sortfilterroomtreemodel.h"
#include "models/sortfilterspacelistmodel.h"
#include "models/timelinemodel.h"
class NeoChatRoom;
@@ -53,6 +58,39 @@ class RoomManager : public QObject, public UriResolverBase
*/
Q_PROPERTY(QString currentSpace READ currentSpace WRITE setCurrentSpace NOTIFY currentSpaceChanged)
/**
* @brief The RoomListModel that should be used for linear room visualisation.
*
* The connection the model uses to get the data will be updated by this class
* so there is no need to do this manually or replace the model when the connection
* changes.
*/
Q_PROPERTY(RoomListModel *roomListModel READ roomListModel CONSTANT)
/**
* @brief The SortFilterRoomListModel that should be used for room visualisation.
*/
Q_PROPERTY(SortFilterRoomListModel *sortFilterRoomListModel READ sortFilterRoomListModel CONSTANT)
/**
* @brief The SortFilterSpaceListModel that should be used for space visualisation.
*/
Q_PROPERTY(SortFilterSpaceListModel *sortFilterSpaceListModel READ sortFilterSpaceListModel CONSTANT)
/**
* @brief The RoomTreeModel that should be used for room visualisation.
*
* The connection the model uses to get the data will be updated by this class
* so there is no need to do this manually or replace the model when the connection
* changes.
*/
Q_PROPERTY(RoomTreeModel *roomTreeModel READ roomTreeModel CONSTANT)
/**
* @brief The SortFilterRoomTreeModel that should be used for room visualisation.
*/
Q_PROPERTY(SortFilterRoomTreeModel *sortFilterRoomTreeModel READ sortFilterRoomTreeModel CONSTANT)
/**
* @brief The TimelineModel that should be used for room message visualisation.
*
@@ -106,6 +144,12 @@ public:
NeoChatRoom *currentRoom() const;
RoomListModel *roomListModel() const;
SortFilterRoomListModel *sortFilterRoomListModel() const;
SortFilterSpaceListModel *sortFilterSpaceListModel() const;
RoomTreeModel *roomTreeModel() const;
SortFilterRoomTreeModel *sortFilterRoomTreeModel() const;
TimelineModel *timelineModel() const;
MessageFilterModel *messageFilterModel() const;
MediaMessageFilterModel *mediaMessageFilterModel() const;
@@ -159,6 +203,8 @@ public:
*/
Q_INVOKABLE void maximizeMedia(int index);
Q_INVOKABLE void maximizeCode(const QVariantMap &author, const QDateTime &time, const QString &codeText, const QString &language);
/**
* @brief Request that any full screen overlay currently open closes.
*/
@@ -220,6 +266,11 @@ Q_SIGNALS:
*/
void showMaximizedMedia(int index);
/**
* @brief Request a block of code is shown maximized.
*/
void showMaximizedCode(const QVariantMap &author, const QDateTime &time, const QString &codeText, const QString &language);
/**
* @brief Request that any full screen overlay closes.
*/
@@ -293,6 +344,12 @@ private:
KConfigGroup m_directChatsConfig;
QPointer<ChatDocumentHandler> m_chatDocumentHandler;
RoomListModel *m_roomListModel;
SortFilterRoomListModel *m_sortFilterRoomListModel;
SortFilterSpaceListModel *m_sortFilterSpaceListModel;
RoomTreeModel *m_roomTreeModel;
SortFilterRoomTreeModel *m_sortFilterRoomTreeModel;
TimelineModel *m_timelineModel;
MessageFilterModel *m_messageFilterModel;
MediaMessageFilterModel *m_mediaMessageFilterModel;

View File

@@ -9,6 +9,7 @@
#include "neochatroom.h"
#include "roomlistmodel.h"
#include "roommanager.h"
#include "sortfilterroomlistmodel.h"
#include "windowcontroller.h"
RemoteImage Runner::serializeImage(const QImage &image)
@@ -28,9 +29,9 @@ RemoteImage Runner::serializeImage(const QImage &image)
Runner::Runner()
: QObject()
, m_sourceModel(new RoomListModel(this))
, m_model(new SortFilterRoomListModel(m_sourceModel, this))
{
m_sourceModel = new RoomListModel(this);
m_model.setSourceModel(m_sourceModel);
connect(&Controller::instance(), &Controller::activeConnectionChanged, this, [this]() {
m_sourceModel->setConnection(Controller::instance().activeConnection());
});
@@ -44,13 +45,13 @@ Runner::Runner()
void Runner::setRoomListModel(RoomListModel *roomListModel)
{
m_model.setSourceModel(roomListModel);
m_model->setSourceModel(roomListModel);
Q_EMIT roomListModelChanged();
}
RoomListModel *Runner::roomListModel() const
{
return dynamic_cast<RoomListModel *>(m_model.sourceModel());
return dynamic_cast<RoomListModel *>(m_model->sourceModel());
}
RemoteActions Runner::Actions()
@@ -60,22 +61,22 @@ RemoteActions Runner::Actions()
RemoteMatches Runner::Match(const QString &searchTerm)
{
m_model.setFilterText(searchTerm);
m_model->setFilterText(searchTerm);
RemoteMatches matches;
for (int i = 0; i < m_model.rowCount(); ++i) {
for (int i = 0; i < m_model->rowCount(); ++i) {
RemoteMatch match;
const QString name = m_model.data(m_model.index(i, 0), RoomListModel::DisplayNameRole).toString();
const QString name = m_model->data(m_model->index(i, 0), RoomListModel::DisplayNameRole).toString();
match.iconName = QStringLiteral("org.kde.neochat");
match.id = m_model.data(m_model.index(i, 0), RoomListModel::RoomIdRole).toString();
match.id = m_model->data(m_model->index(i, 0), RoomListModel::RoomIdRole).toString();
match.text = name;
match.relevance = 1;
const RemoteImage remoteImage = serializeImage(m_model.data(m_model.index(i, 0), RoomListModel::AvatarImageRole).value<QImage>());
const RemoteImage remoteImage = serializeImage(m_model->data(m_model->index(i, 0), RoomListModel::AvatarImageRole).value<QImage>());
match.properties.insert(QStringLiteral("icon-data"), QVariant::fromValue(remoteImage));
match.properties.insert(QStringLiteral("subtext"), m_model.data(m_model.index(i, 0), RoomListModel::TopicRole).toString());
match.properties.insert(QStringLiteral("subtext"), m_model->data(m_model->index(i, 0), RoomListModel::TopicRole).toString());
if (name.compare(searchTerm, Qt::CaseInsensitive) == 0) {
match.type = ExactMatch;

View File

@@ -203,7 +203,7 @@ Q_SIGNALS:
private:
RemoteImage serializeImage(const QImage &image);
SortFilterRoomListModel m_model;
RoomListModel *m_sourceModel;
QPointer<RoomListModel> m_sourceModel;
QPointer<SortFilterRoomListModel> m_model;
Runner();
};

View File

@@ -17,6 +17,7 @@ FormCard.AbstractFormDelegate {
required property string id
required property string timestamp
required property string displayName
required property int type
property bool editDeviceName: false
property bool showVerifyButton
@@ -98,7 +99,7 @@ FormCard.AbstractFormDelegate {
}
QQC2.ToolButton {
display: QQC2.AbstractButton.IconOnly
visible: root.showVerifyButton
visible: root.showVerifyButton && root.type !== DevicesModel.Verified
action: Kirigami.Action {
id: verifyDeviceAction
text: i18n("Verify device")
@@ -112,6 +113,21 @@ FormCard.AbstractFormDelegate {
delay: Kirigami.Units.toolTipDelay
}
}
Kirigami.Icon {
visible: root.showVerifyButton && root.type === DevicesModel.Verified
implicitWidth: Kirigami.Units.iconSizes.smallMedium
implicitHeight: Kirigami.Units.iconSizes.smallMedium
source: "security-high"
HoverHandler {
id: verifyHover
}
QQC2.ToolTip {
text: i18nc("This device is verified", "Verified")
delay: Kirigami.Units.toolTipDelay
visible: verifyHover.hovered
}
}
QQC2.ToolButton {
display: QQC2.AbstractButton.IconOnly
action: Kirigami.Action {

View File

@@ -9,6 +9,7 @@ import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.neochat
import org.kde.neochat.devtools
import org.kde.neochat.config
FormCard.FormCardPage {
@@ -218,7 +219,7 @@ FormCard.FormCardPage {
FormCard.FormButtonDelegate {
visible: Config.developerTools
text: i18n("Open developer tools")
onClicked: applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'DevtoolsPage.qml'), {
onClicked: applicationWindow().pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat.devtools', 'DevtoolsPage.qml'), {
connection: root.connection
}, {
title: i18n("Developer Tools")

View File

@@ -154,6 +154,7 @@ QQC2.Control {
delegate: MessageComponentChooser {
room: root.room
index: root.index
time: root.time
actionsHandler: root.actionsHandler
timeline: root.timeline
maxContentWidth: root.maxContentWidth

View File

@@ -13,6 +13,29 @@ import org.kde.neochat
QQC2.Control {
id: root
/**
* @brief The message author.
*
* This should consist of the following:
* - id - The matrix ID of the author.
* - isLocalUser - Whether the author is the local user.
* - avatarSource - The mxc URL for the author's avatar in the current room.
* - avatarMediaId - The media ID of the author's avatar.
* - avatarUrl - The mxc URL for the author's avatar.
* - displayName - The display name of the author.
* - display - The name of the author.
* - color - The color for the author.
* - object - The Quotient::User object for the author.
*
* @sa Quotient::User
*/
required property var author
/**
* @brief The timestamp of the message.
*/
required property var time
/**
* @brief The display text of the message.
*/
@@ -113,6 +136,7 @@ QQC2.Control {
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: RoomManager.maximizeCode(root.author, root.time, root.display, root.componentAttributes.class)
onLongPressed: root.showMessageMenu()
}

View File

@@ -76,7 +76,7 @@ ColumnLayout {
map.plugin: OsmLocationPlugin.plugin
LocationMapItem {
readonly property LocationMapItem locationMapItem: LocationMapItem {
latitude: root.latitude
longitude: root.longitude
asset: root.asset
@@ -85,6 +85,8 @@ ColumnLayout {
heading: NaN
}
Component.onCompleted: map.addMapItem(locationMapItem)
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: {

View File

@@ -22,6 +22,11 @@ DelegateChooser {
*/
required property var index
/**
* @brief The timestamp of the message.
*/
required property var time
/**
* @brief The ActionsHandler object to use.
*
@@ -89,6 +94,7 @@ DelegateChooser {
DelegateChoice {
roleValue: MessageComponentType.Code
delegate: CodeComponent {
time: root.time
maxContentWidth: root.maxContentWidth
onSelectedTextChanged: selectedText => {
root.selectedTextChanged(selectedText);