Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85712496
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
15 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 43048fe..7b8df0f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,67 +1,73 @@
set(KAZV_DATA_DIR ${KDE_INSTALL_DATADIR})
set(KAZV_L10N_DIR ${KAZV_DATA_DIR}/l10n)
configure_file(kazv-path-config.hpp.in kazv-path-config.hpp)
configure_file(kazv-version.cpp.in kazv-version.cpp)
set(kazvprivlib_SRCS
qt-job-handler.cpp
qt-job.cpp
${CMAKE_CURRENT_BINARY_DIR}/kazv-version.cpp
matrix-sdk.cpp
matrix-room.cpp
matrix-room-list.cpp
matrix-room-timeline.cpp
matrix-room-member.cpp
matrix-event.cpp
meta-types.cpp
l10n-provider.cpp
qt-rand-adapter.cpp
+ helper.cpp
+
+ device-mgmt/matrix-device.cpp
+ device-mgmt/matrix-device-list.cpp
kazv-config.cpp
kazv-io-manager.cpp
kazv-io-job.cpp
upload-job-model.cpp
shortcuts/shortcut-util.cpp
register-types.cpp
resources.qrc
)
ecm_qt_declare_logging_category(kazvprivlib_SRCS
HEADER kazv-log.hpp
IDENTIFIER kazvLog
CATEGORY_NAME moe.kazv.mxc.kazv
)
add_library(kazvprivlib STATIC ${kazvprivlib_SRCS})
target_link_libraries(kazvprivlib PUBLIC
libkazv::kazvall
Qt5::Core
Qt5::Network
Threads::Threads
Qt5::Gui Qt5::Qml Qt5::Quick Qt5::QuickControls2 Qt5::Svg Qt5::Concurrent Qt5::Widgets
KF5::ConfigCore KF5::KIOCore
)
+
target_include_directories(kazvprivlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
+target_include_directories(kazvprivlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/device-mgmt)
set(kazv_SRCS
main.cpp
)
add_executable(kazv ${kazv_SRCS})
target_link_libraries(kazv
PRIVATE
kazvprivlib
)
install(TARGETS kazv ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/l10n/
DESTINATION ${KAZV_L10N_DIR}
FILES_MATCHING PATTERN "*.ftl"
PATTERN "*.json"
)
add_subdirectory(tests)
diff --git a/src/device-mgmt/matrix-device-list.cpp b/src/device-mgmt/matrix-device-list.cpp
new file mode 100644
index 0000000..8c8652c
--- /dev/null
+++ b/src/device-mgmt/matrix-device-list.cpp
@@ -0,0 +1,50 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <libkazv-config.hpp>
+#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
+
+#include <lager/lenses/optional.hpp>
+
+#include "matrix-device.hpp"
+
+#include "matrix-device-list.hpp"
+
+using namespace Kazv;
+
+MatrixDeviceList::MatrixDeviceList(lager::reader<immer::flex_vector<DeviceKeyInfo>> devices, QObject *parent)
+ : QObject(parent)
+ , m_devices(devices)
+ , LAGER_QT(count)(m_devices.map([](const auto &vec) -> int { return vec.size(); }))
+{
+}
+
+MatrixDeviceList::~MatrixDeviceList() = default;
+
+MatrixDevice *MatrixDeviceList::at(int index) const
+{
+ return new MatrixDevice(m_devices.map([index](const auto &devices) {
+ if (index < static_cast<int>(devices.size())) {
+ return devices[index];
+ } else {
+ return DeviceKeyInfo{};
+ }
+ }));
+}
+
+MatrixDevice *MatrixDeviceList::deviceById(QString deviceId) const
+{
+ return new MatrixDevice(m_devices.map([deviceId=deviceId.toStdString()](const auto &devices) {
+ auto it = std::find_if(devices.begin(), devices.end(), [deviceId](const auto &dev) {
+ return dev.deviceId == deviceId;
+ });
+ if (it != devices.end()) {
+ return *it;
+ } else {
+ return DeviceKeyInfo{};
+ }
+ }));
+}
diff --git a/src/device-mgmt/matrix-device-list.hpp b/src/device-mgmt/matrix-device-list.hpp
new file mode 100644
index 0000000..e82816f
--- /dev/null
+++ b/src/device-mgmt/matrix-device-list.hpp
@@ -0,0 +1,37 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+#include <libkazv-config.hpp>
+#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
+
+#include <QObject>
+#include <QQmlEngine>
+#include <QUrl>
+
+#include <lager/extra/qt.hpp>
+
+#include <client.hpp>
+
+class MatrixDevice;
+
+class MatrixDeviceList : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_UNCREATABLE("")
+
+ lager::reader<immer::flex_vector<Kazv::DeviceKeyInfo>> m_devices;
+
+public:
+ explicit MatrixDeviceList(lager::reader<immer::flex_vector<Kazv::DeviceKeyInfo>> devices, QObject *parent = 0);
+ ~MatrixDeviceList() override;
+
+ LAGER_QT_READER(int, count);
+
+ Q_INVOKABLE MatrixDevice *at(int index) const;
+ Q_INVOKABLE MatrixDevice *deviceById(QString deviceId) const;
+};
diff --git a/src/device-mgmt/matrix-device.cpp b/src/device-mgmt/matrix-device.cpp
new file mode 100644
index 0000000..00fe75b
--- /dev/null
+++ b/src/device-mgmt/matrix-device.cpp
@@ -0,0 +1,29 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <libkazv-config.hpp>
+#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
+
+#include <lager/lenses/optional.hpp>
+
+#include "helper.hpp"
+
+#include "matrix-device.hpp"
+
+using namespace Kazv;
+
+MatrixDevice::MatrixDevice(lager::reader<DeviceKeyInfo> device, QObject *parent)
+ : QObject(parent)
+ , m_device(device)
+ , LAGER_QT(deviceId)(m_device[&DeviceKeyInfo::deviceId].xform(strToQt))
+ , LAGER_QT(ed25519Key)(m_device[&DeviceKeyInfo::ed25519Key].xform(strToQt))
+ , LAGER_QT(curve25519Key)(m_device[&DeviceKeyInfo::curve25519Key].xform(strToQt))
+ , LAGER_QT(displayName)(m_device[&DeviceKeyInfo::displayName][lager::lenses::or_default].xform(strToQt))
+ , LAGER_QT(trustLevel)(m_device[&DeviceKeyInfo::trustLevel].xform(trustLevelToQString))
+{
+}
+
+MatrixDevice::~MatrixDevice() = default;
diff --git a/src/device-mgmt/matrix-device.hpp b/src/device-mgmt/matrix-device.hpp
new file mode 100644
index 0000000..6fda25b
--- /dev/null
+++ b/src/device-mgmt/matrix-device.hpp
@@ -0,0 +1,36 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+#include <libkazv-config.hpp>
+#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
+
+#include <QObject>
+#include <QQmlEngine>
+#include <QString>
+
+#include <lager/extra/qt.hpp>
+
+#include <client.hpp>
+
+class MatrixDevice : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_UNCREATABLE("")
+
+ lager::reader<Kazv::DeviceKeyInfo> m_device;
+
+public:
+ explicit MatrixDevice(lager::reader<Kazv::DeviceKeyInfo> device, QObject *parent = 0);
+ ~MatrixDevice() override;
+
+ LAGER_QT_READER(QString, deviceId);
+ LAGER_QT_READER(QString, ed25519Key);
+ LAGER_QT_READER(QString, curve25519Key);
+ LAGER_QT_READER(QString, displayName);
+ LAGER_QT_READER(QString, trustLevel);
+};
diff --git a/src/helper.cpp b/src/helper.cpp
new file mode 100644
index 0000000..8cf20e3
--- /dev/null
+++ b/src/helper.cpp
@@ -0,0 +1,51 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2020 Tusooa Zhu <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <libkazv-config.hpp>
+#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
+
+#include "kazv-log.hpp"
+
+#include "helper.hpp"
+
+using namespace Kazv;
+
+QString trustLevelToQStringFunc(DeviceTrustLevel trustLevel)
+{
+ switch (trustLevel) {
+ case Blocked:
+ return QStringLiteral("blocked");
+
+ case Unseen:
+ return QStringLiteral("unseen");
+
+ case Seen:
+ return QStringLiteral("seen");
+
+ case Verified:
+ return QStringLiteral("verified");
+
+ default:
+ qCWarning(kazvLog) << "trustLevelToQStringFunc(): Unknown trust level:" << trustLevel;
+ return QStringLiteral();
+ }
+}
+
+DeviceTrustLevel qStringToTrustLevelFunc(QString trustLevel)
+{
+ if (trustLevel == QStringLiteral("blocked")) {
+ return Blocked;
+ } else if (trustLevel == QStringLiteral("unseen")) {
+ return Unseen;
+ } else if (trustLevel == QStringLiteral("seen")) {
+ return Seen;
+ } else if (trustLevel == QStringLiteral("verified")) {
+ return Verified;
+ } else {
+ qCWarning(kazvLog) << "QStringToTrustLevelFunc(): Unknown trust level:" << trustLevel;
+ return Blocked;
+ }
+}
diff --git a/src/helper.hpp b/src/helper.hpp
index bbbe2c8..696f866 100644
--- a/src/helper.hpp
+++ b/src/helper.hpp
@@ -1,64 +1,74 @@
/*
* This file is part of kazv.
- * SPDX-FileCopyrightText: 2020 Tusooa Zhu <tusooa@kazv.moe>
+ * SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <libkazv-config.hpp>
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include <immer/array.hpp>
#include <QString>
+#include <QStringList>
#include <zug/transducer/map.hpp>
#include <cursorutil.hpp>
+#include <device-list-tracker.hpp>
namespace Kazv
{
namespace detail
{
struct StrToQtT
{
template<class T>
auto operator()(T &&x) {
return QString::fromStdString(std::forward<T>(x));
}
};
struct QStringToStdT
{
template<class T>
auto operator()(T &&x) {
return std::forward<T>(x).toStdString();
}
};
struct ContainerSizeT
{
template<class T>
auto operator()(T &&x) -> int {
return std::forward<T>(x).size();
}
};
}
}
constexpr auto strToQt = zug::map(::Kazv::detail::StrToQtT{});
constexpr auto strListToQtF = [](auto container) {
return zug::into(QStringList{}, strToQt, std::move(container));
};
constexpr auto strListToQt = zug::map(strListToQtF);
constexpr auto qStringToStd = zug::map(::Kazv::detail::QStringToStdT{});
constexpr auto qStringListToStdF = [](auto container) {
return Kazv::intoImmer(immer::array<std::string>{}, qStringToStd, std::move(container));
};
constexpr auto containerSize = zug::map(::Kazv::detail::ContainerSizeT{});
+
+QString trustLevelToQStringFunc(Kazv::DeviceTrustLevel trustLevel);
+
+Kazv::DeviceTrustLevel qStringToTrustLevelFunc(QString trustLevel);
+
+constexpr auto trustLevelToQString = zug::map(trustLevelToQStringFunc);
+
+constexpr auto qStringToTrustLevel = zug::map(qStringToTrustLevelFunc);
diff --git a/src/register-types.cpp b/src/register-types.cpp
index 5e10ab1..53adbbe 100644
--- a/src/register-types.cpp
+++ b/src/register-types.cpp
@@ -1,37 +1,41 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2021-2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <libkazv-config.hpp>
#include <QtQml>
#include "matrix-sdk.hpp"
#include "matrix-room-list.hpp"
#include "matrix-room.hpp"
#include "matrix-room-timeline.hpp"
#include "matrix-room-member.hpp"
#include "matrix-event.hpp"
#include "l10n-provider.hpp"
#include "kazv-config.hpp"
#include "kazv-io-manager.hpp"
#include "shortcuts/shortcut-util.hpp"
#include "kazv-io-job.hpp"
+#include "device-mgmt/matrix-device-list.hpp"
+#include "device-mgmt/matrix-device.hpp"
void registerKazvQmlTypes()
{
qmlRegisterType<MatrixSdk>("moe.kazv.mxc.kazv", 0, 0, "MatrixSdk");
qmlRegisterType<L10nProvider>("moe.kazv.mxc.kazv", 0, 0, "L10nProvider");
qmlRegisterType<KazvConfig>("moe.kazv.mxc.kazv", 0, 0, "KazvConfig");
qmlRegisterType<KazvIOBaseJob>("moe.kazv.mxc.kazv", 0, 0, "KazvIOBaseJob");
qmlRegisterType<KazvIOManager>("moe.kazv.mxc.kazv", 0, 0, "KazvIOManager");
qmlRegisterType<UploadJobModel>("moe.kazv.mxc.kazv", 0, 0, "UploadJobModel");
qmlRegisterUncreatableType<MatrixRoomList>("moe.kazv.mxc.kazv", 0, 0, "MatrixRoomList", "");
qmlRegisterUncreatableType<MatrixRoom>("moe.kazv.mxc.kazv", 0, 0, "MatrixRoom", "");
qmlRegisterUncreatableType<MatrixRoomMember>("moe.kazv.mxc.kazv", 0, 0, "MatrixRoomMember", "");
qmlRegisterUncreatableType<MatrixRoomTimeline>("moe.kazv.mxc.kazv", 0, 0, "MatrixRoomTimeline", "");
qmlRegisterUncreatableType<MatrixEvent>("moe.kazv.mxc.kazv", 0, 0, "MatrixEvent", "");
+ qmlRegisterUncreatableType<MatrixDeviceList>("moe.kazv.mxc.kazv", 0, 0, "MatrixDeviceList", "");
+ qmlRegisterUncreatableType<MatrixDevice>("moe.kazv.mxc.kazv", 0, 0, "MatrixDevice", "");
qmlRegisterSingletonInstance<ShortcutUtil>("moe.kazv.mxc.kazvshortcuts", 0, 0, "ShortcutUtil", new ShortcutUtil());
}
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index a376614..4405be9 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -1,12 +1,13 @@
ecm_add_tests(
qt-job-handler-test.cpp
qt-promise-handler-test.cpp
+ device-mgmt-test.cpp
LINK_LIBRARIES Qt5::Test libkazv::kazvall kazvprivlib
)
ecm_add_test(
quick-test.cpp
TEST_NAME quicktest
LINK_LIBRARIES Qt5::QuickTest libkazv::kazvall kazvprivlib
)
set_tests_properties(quicktest PROPERTIES WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
diff --git a/src/tests/device-mgmt-test.cpp b/src/tests/device-mgmt-test.cpp
new file mode 100644
index 0000000..6325b38
--- /dev/null
+++ b/src/tests/device-mgmt-test.cpp
@@ -0,0 +1,69 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <libkazv-config.hpp>
+#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
+
+#include <memory>
+
+#include <lager/state.hpp>
+
+#include <device-list-tracker.hpp>
+
+#include <matrix-device-list.hpp>
+#include <matrix-device.hpp>
+
+#include "tests.hpp"
+
+#include "device-mgmt-test.hpp"
+
+using namespace Kazv;
+
+static const immer::flex_vector<DeviceKeyInfo> devices{
+ {"device1", "device1ed25519", "device1curve25519", "device1name", Unseen},
+ {"device2", "device2ed25519", "device2curve25519", "device2name", Seen},
+ {"device3", "device3ed25519", "device3curve25519", "device3name", Verified},
+ {"device4", "device4ed25519", "device4curve25519", "device4name", Blocked},
+};
+
+void DeviceMgmtTest::testDeviceList()
+{
+ auto state = lager::make_state(devices, lager::automatic_tag{});
+
+ auto deviceList = MatrixDeviceList(state);
+
+ QVERIFY(deviceList.count() == 4);
+
+ auto dev = std::unique_ptr<MatrixDevice>(deviceList.at(0));
+ QVERIFY(dev);
+
+ dev = std::unique_ptr<MatrixDevice>(deviceList.at(6));
+ QVERIFY(dev);
+}
+
+void DeviceMgmtTest::testDevice()
+{
+ auto state = lager::make_state(devices, lager::automatic_tag{});
+ auto deviceList = MatrixDeviceList(state);
+
+ auto dev = std::unique_ptr<MatrixDevice>(deviceList.at(0));
+ QVERIFY(dev->deviceId() == QStringLiteral("device1"));
+ QVERIFY(dev->ed25519Key() == QStringLiteral("device1ed25519"));
+ QVERIFY(dev->curve25519Key() == QStringLiteral("device1curve25519"));
+ QVERIFY(dev->displayName() == QStringLiteral("device1name"));
+ QVERIFY(dev->trustLevel() == QStringLiteral("unseen"));
+
+ dev = std::unique_ptr<MatrixDevice>(deviceList.at(1));
+ QVERIFY(dev->trustLevel() == QStringLiteral("seen"));
+
+ dev = std::unique_ptr<MatrixDevice>(deviceList.at(2));
+ QVERIFY(dev->trustLevel() == QStringLiteral("verified"));
+
+ dev = std::unique_ptr<MatrixDevice>(deviceList.at(3));
+ QVERIFY(dev->trustLevel() == QStringLiteral("blocked"));
+}
+
+QTEST_MAIN(DeviceMgmtTest)
diff --git a/src/tests/device-mgmt-test.hpp b/src/tests/device-mgmt-test.hpp
new file mode 100644
index 0000000..615433f
--- /dev/null
+++ b/src/tests/device-mgmt-test.hpp
@@ -0,0 +1,21 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <libkazv-config.hpp>
+#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
+
+#include <QtTest>
+
+#include <memory>
+
+class DeviceMgmtTest : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void testDeviceList();
+ void testDevice();
+};
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Sep 19, 11:26 AM (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1769385
Default Alt Text
(15 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment