Page MenuHomePhorge

No OneTemporary

Size
12 KB
Referenced Files
None
Subscribers
None
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e8353bb..517ff60 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,53 +1,53 @@
cmake_minimum_required(VERSION 3.13)
project(kazv)
include(FeatureSummary)
set(kazv_VERSION_MAJOR 0)
set(kazv_VERSION_MINOR 0)
set(kazv_VERSION_PATCH 1)
set(kazv_VERSION_STRING ${kazv_VERSION_MAJOR}.${kazv_VERSION_MINOR}.${kazv_VERSION_PATCH})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 17)
set(QT5_MIN_VERSION 5.15)
set(KF5_MIN_VERSION 5.78)
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH})
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMSetupVersion)
include(ECMGenerateHeaders)
include(ECMPoQmTools)
include(ECMAddTests)
include(ECMQtDeclareLoggingCategory)
find_package(Qt5 ${QT5_MIN_VERSION} REQUIRED COMPONENTS
Core Gui Qml QuickControls2 Svg Concurrent Widgets
- Multimedia Test Network
+ Multimedia Test Network QuickTest
)
# Sql Quick QuickControls2 Network DBus Xml)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 Config KIO)
# Notifications Config Service KIO)
#find_package(MauiKit REQUIRED)
find_package(Threads REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(libkazv REQUIRED)
kde_enable_exceptions()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -foperator-names -DQT_NO_EMIT")
add_subdirectory(src)
install(PROGRAMS moe.kazv.mxc.kazv.desktop DESTINATION ${KDE_INSTALL_APPDIR})
install(FILES moe.kazv.mxc.kazv.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR})
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cabb34b..43048fe 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,65 +1,67 @@
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
-)
-
-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
-)
-target_include_directories(kazvprivlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
-
-set(kazv_SRCS
${CMAKE_CURRENT_BINARY_DIR}/kazv-version.cpp
- main.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
kazv-config.cpp
kazv-io-manager.cpp
kazv-io-job.cpp
upload-job-model.cpp
shortcuts/shortcut-util.cpp
+ register-types.cpp
+
resources.qrc
- )
+)
-add_executable(kazv ${kazv_SRCS})
+ecm_qt_declare_logging_category(kazvprivlib_SRCS
+ HEADER kazv-log.hpp
+ IDENTIFIER kazvLog
+ CATEGORY_NAME moe.kazv.mxc.kazv
+)
-target_link_libraries(kazv
- PRIVATE
+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})
+
+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/main.cpp b/src/main.cpp
index f96411f..54ad1a0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,60 +1,36 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2021-2023 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 <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include <QUrl>
-#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 "register-types.hpp"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QCoreApplication::setOrganizationName("project-kazv");
QCoreApplication::setOrganizationDomain("mxc.kazv.moe");
QCoreApplication::setApplicationName("kazv");
QQmlApplicationEngine engine;
- 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", "");
- qmlRegisterSingletonInstance<ShortcutUtil>("moe.kazv.mxc.kazvshortcuts", 0, 0, "ShortcutUtil", new ShortcutUtil());
+ registerKazvQmlTypes();
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
if (engine.rootObjects().isEmpty()) {
return -1;
}
return app.exec();
}
diff --git a/src/main.cpp b/src/register-types.cpp
similarity index 68%
copy from src/main.cpp
copy to src/register-types.cpp
index f96411f..5e10ab1 100644
--- a/src/main.cpp
+++ b/src/register-types.cpp
@@ -1,60 +1,37 @@
/*
* This file is part of kazv.
- * SPDX-FileCopyrightText: 2021-2023 Tusooa Zhu <tusooa@kazv.moe>
+ * SPDX-FileCopyrightText: 2021-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 <libkazv-config.hpp>
-#include <QApplication>
-#include <QQmlApplicationEngine>
#include <QtQml>
-#include <QUrl>
#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"
-Q_DECL_EXPORT int main(int argc, char *argv[])
+void registerKazvQmlTypes()
{
- QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QApplication app(argc, argv);
- QCoreApplication::setOrganizationName("project-kazv");
- QCoreApplication::setOrganizationDomain("mxc.kazv.moe");
- QCoreApplication::setApplicationName("kazv");
-
- QQmlApplicationEngine engine;
-
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", "");
qmlRegisterSingletonInstance<ShortcutUtil>("moe.kazv.mxc.kazvshortcuts", 0, 0, "ShortcutUtil", new ShortcutUtil());
-
- engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
-
- if (engine.rootObjects().isEmpty()) {
- return -1;
- }
-
- return app.exec();
}
diff --git a/src/register-types.hpp b/src/register-types.hpp
new file mode 100644
index 0000000..b4e7be0
--- /dev/null
+++ b/src/register-types.hpp
@@ -0,0 +1,10 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2021-2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+#include <libkazv-config.hpp>
+
+void registerKazvQmlTypes();
diff --git a/src/tests/qt-promise-handler-test.cpp b/src/tests/qt-promise-handler-test.cpp
index 35a37bd..e2ceafd 100644
--- a/src/tests/qt-promise-handler-test.cpp
+++ b/src/tests/qt-promise-handler-test.cpp
@@ -1,147 +1,138 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-2021 Tusooa Zhu <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <libkazv-config.hpp>
#include <memory>
#include <vector>
#include <QTimer>
#include "qt-promise-handler-test.hpp"
#include "qt-promise-handler.hpp"
namespace
{
struct MockDataStruct
{
int i{};
};
}
void QtPromiseHandlerTest::testPromise()
{
QEventLoop loop;
QObject *obj = new QObject(&loop);
auto ph = QtPromiseHandler(std::ref(*obj));
std::vector<int> v;
auto p1 = ph.create<int>([&v](auto resolve) {
qDebug() << "p1";
v.push_back(1);
resolve(2);
});
auto p2 = p1.then([&v, &ph](int val) {
qDebug() << "p2";
v.push_back(val);
return ph.createResolved(3);
});
auto p3 = p2.then([&v, &ph](int val) {
qDebug() << "p3";
v.push_back(val);
return ph.createResolved(-1);
});
auto p4 = p3.then([](int val) {
qDebug() << "p4" << val;
[=] { QVERIFY(val == -1); }();
return 5;
});
auto p5 = p4.then([](int val) {
qDebug() << "p5" << val;
[=] { QVERIFY(val == 5); }();
return MockDataStruct{6};
});
auto p6 = p5.then([obj, &loop](MockDataStruct m) {
qDebug() << "p6" << m.i;
[=] { QVERIFY(m.i == 6); }();
obj->deleteLater();
loop.quit();
return 0;
});
- QObject::connect(obj, &QObject::destroyed,
- this, [&v] {
- qDebug() << "QObject::destroyed()";
- QVERIFY((v == std::vector<int>{ 1, 2, 3 }));
- });
-
loop.exec();
+
+ QVERIFY((v == std::vector<int>{ 1, 2, 3 }));
}
void QtPromiseHandlerTest::testTimer()
{
QEventLoop loop;
QObject *obj = new QObject(&loop);
auto ph = QtPromiseHandler(std::ref(*obj));
auto pTimer = ph.create<int>([](auto resolve) {
QTimer::singleShot(300, [resolve]() { resolve(20); });
});
int i;
auto pTimer2 = pTimer.then([&i, &loop, obj](int val) -> int {
i = val;
obj->deleteLater();
loop.quit();
return 0;
});
- QObject::connect(obj, &QObject::destroyed,
- this, [&i] {
- qDebug() << "QObject::destroyed()";
- QVERIFY(i == 20);
- });
-
loop.exec();
+ QVERIFY(i == 20);
}
void QtPromiseHandlerTest::testStop()
{
QEventLoop loop;
QObject *obj = new QObject(&loop);
auto ph = QtPromiseHandler(std::ref(*obj));
auto pTimer = ph.create<int>([](auto resolve) {
QTimer::singleShot(500, [resolve]() { resolve(20); });
});
int i = 0;
auto pTimer2 = pTimer.then([&i, &loop, obj](int val) -> int {
qDebug() << "then-continuation";
i = val;
obj->deleteLater();
loop.quit();
return 0;
});
QTimer::singleShot(300, this, [obj]() {
qDebug() << "delete obj";
obj->deleteLater();
});
QObject::connect(obj, &QObject::destroyed,
this, [&i] {
qDebug() << "QObject::destroyed()";
});
QTimer::singleShot(2000, this, [&loop]() {
qDebug() << "stop loop";
loop.quit();
});
loop.exec();
}
QTEST_MAIN(QtPromiseHandlerTest)

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 3:24 PM (19 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55268
Default Alt Text
(12 KB)

Event Timeline