From f29c8e8b41726df9dbdaf9724880ef15c2c54acd Mon Sep 17 00:00:00 2001 From: marisa Date: Sat, 9 Dec 2023 13:51:39 -0300 Subject: [PATCH] Initial commit --- .gitignore | 1 + CMakeLists.txt | 28 ++++++++++ src/Gui/Splash.qml | 32 +++++++++++ src/Gui/Style/PStyle/PBackground.qml | 6 ++ src/Gui/Style/PStyle/PStyle.qml | 16 ++++++ src/Gui/Style/PStyle/PText.qml | 7 +++ src/Gui/Style/PStyle/qmldir | 1 + src/Gui/Style/resources.qrc | 8 +++ src/Gui/Util/Http.qml | 83 ++++++++++++++++++++++++++++ src/Gui/Util/qmldir | 1 + src/main.cpp | 43 ++++++++++++++ src/resources.qrc | 8 +++ 12 files changed, 234 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 src/Gui/Splash.qml create mode 100644 src/Gui/Style/PStyle/PBackground.qml create mode 100644 src/Gui/Style/PStyle/PStyle.qml create mode 100644 src/Gui/Style/PStyle/PText.qml create mode 100644 src/Gui/Style/PStyle/qmldir create mode 100644 src/Gui/Style/resources.qrc create mode 100644 src/Gui/Util/Http.qml create mode 100644 src/Gui/Util/qmldir create mode 100644 src/main.cpp create mode 100644 src/resources.qrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..89506e3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.19) + +set(PROJECT "QutePleroma") + +project(${PROJECT} VERSION 1.0.0 LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +find_package(Qt6 COMPONENTS Widgets Qml QuickControls2 REQUIRED) + +add_executable(${PROJECT} + src/main.cpp + src/resources.qrc + src/Gui/Style/resources.qrc) + +target_link_libraries(${PROJECT} + Qt::Widgets + Qt::Qml + Qt::QuickControls2) + +if(CMAKE_BUILD_TYPE STREQUAL "Release") + set_property(TARGET ${PROJECT} PROPERTY WIN32_EXECUTABLE true) +endif() \ No newline at end of file diff --git a/src/Gui/Splash.qml b/src/Gui/Splash.qml new file mode 100644 index 0000000..55c22b8 --- /dev/null +++ b/src/Gui/Splash.qml @@ -0,0 +1,32 @@ +import QtQuick +import QtQuick.Window +import QtQuick.Layouts + +import Util +import "PStyle" + +Window { + visible: true + width: 640 + height: 480 + title: qsTr("QutePleroma") + + PBackground { + anchors.fill: parent + + ColumnLayout { + anchors.centerIn: parent + + PText { + text: qsTr("QutePleroma") + font.pointSize: 36 + } + + TextInput { + Layout.preferredWidth: 350 + color: PStyle.foreColor + font: PStyle.font + } + } + } +} \ No newline at end of file diff --git a/src/Gui/Style/PStyle/PBackground.qml b/src/Gui/Style/PStyle/PBackground.qml new file mode 100644 index 0000000..b994bc8 --- /dev/null +++ b/src/Gui/Style/PStyle/PBackground.qml @@ -0,0 +1,6 @@ +import QtQuick +import "." + +Rectangle { + color: PStyle.backColor +} \ No newline at end of file diff --git a/src/Gui/Style/PStyle/PStyle.qml b/src/Gui/Style/PStyle/PStyle.qml new file mode 100644 index 0000000..f38a745 --- /dev/null +++ b/src/Gui/Style/PStyle/PStyle.qml @@ -0,0 +1,16 @@ +pragma Singleton + +import QtQuick + +QtObject { + property color foreColor: Qt.hsva(0, 0, 0.8, 1) + property color foreColorDim: Qt.darker(foreColor, 1.2) + + property color backColor: Qt.hsva(0, 0, 0.1, 1) + property color backColorDark: Qt.darker(backColor, 1.2) + + property font font: Qt.font({ + family: "Roboto", + pointSize: 12, + }) +} \ No newline at end of file diff --git a/src/Gui/Style/PStyle/PText.qml b/src/Gui/Style/PStyle/PText.qml new file mode 100644 index 0000000..e41b22f --- /dev/null +++ b/src/Gui/Style/PStyle/PText.qml @@ -0,0 +1,7 @@ +import QtQuick +import "." + +Text { + color: PStyle.foreColor + font: PStyle.font +} \ No newline at end of file diff --git a/src/Gui/Style/PStyle/qmldir b/src/Gui/Style/PStyle/qmldir new file mode 100644 index 0000000..317917e --- /dev/null +++ b/src/Gui/Style/PStyle/qmldir @@ -0,0 +1 @@ +singleton PStyle 1.0 PStyle.qml \ No newline at end of file diff --git a/src/Gui/Style/resources.qrc b/src/Gui/Style/resources.qrc new file mode 100644 index 0000000..31ad281 --- /dev/null +++ b/src/Gui/Style/resources.qrc @@ -0,0 +1,8 @@ + + + PStyle/qmldir + PStyle/PStyle.qml + PStyle/PText.qml + PStyle/PBackground.qml + + \ No newline at end of file diff --git a/src/Gui/Util/Http.qml b/src/Gui/Util/Http.qml new file mode 100644 index 0000000..38f4235 --- /dev/null +++ b/src/Gui/Util/Http.qml @@ -0,0 +1,83 @@ +pragma Singleton + +import QtQuick + +QtObject { + property int maxRetries: 3 + + // Generic GET request function with automatic retries and JSON conversion + function getRequest(url, onSuccess, onError) { + var xhr = new XMLHttpRequest(); + var retryCount = 0; + + function sendRequest() { + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + try { + onSuccess(xhr.responseText); + } catch (e) { + if (onError) + onError(e.toString()); + } + retryCount = 0; + } else { + if (retryCount < maxRetries) { + console.error("Failed to GET " + url + ". Retrying..."); + retryCount++; + sendRequest(); // Retry the request + } else { + console.error("Failed to GET " + url + ". Max retries reached!"); + + if (onError) + onError("Error: " + xhr.status + " " + xhr.statusText + ". Max retries reached!"); + } + } + } + } + + print("GET " + url) + + xhr.open("GET", url, true); + xhr.send(); + } + + sendRequest(); // Initial request + } + + function postRequest(url, data, onSuccess, onError) { + var xhr = new XMLHttpRequest(); + var retryCount = 0; + + function sendRequest() { + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + if (onSuccess) + onSuccess(xhr.responseText); + retryCount = 0; + } else { + if (retryCount < maxRetries) { + console.error("Failed to POST " + url + ". Retrying..."); + retryCount++; + sendRequest(); // Retry the request + } else { + console.error("Failed to POST " + url + ". Max retries reached!"); + + if (onError) + onError("Error: " + xhr.status + " " + xhr.statusText + ". Max retries reached!"); + } + } + } + } + + print(`POST ${url} ${JSON.stringify(data)}`) + + xhr.open("POST", url, true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(JSON.stringify(data)); + } + + sendRequest(); // Initial request + } +} \ No newline at end of file diff --git a/src/Gui/Util/qmldir b/src/Gui/Util/qmldir new file mode 100644 index 0000000..20379d2 --- /dev/null +++ b/src/Gui/Util/qmldir @@ -0,0 +1 @@ +singleton Http 1.0 Http.qml \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..9a309f4 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,43 @@ +#include + +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); + + // QApplication::setOrganizationName("MarisaSoft"); + QApplication::setApplicationName("QutePleroma"); + QApplication::setApplicationDisplayName("QutePleroma"); + QApplication::setApplicationVersion("0.1"); + QQuickStyle::setStyle("Fusion"); + QApplication app(argc, argv); + + QQmlEngine *engine = new QQmlEngine(); + + QObject::connect(engine, &QQmlEngine::quit, &QApplication::quit); + engine->addImportPath("qrc:/"); + + QQmlContext *ctx = new QQmlContext(engine->rootContext()); + QQmlComponent component(engine, QUrl("qrc:/Splash.qml")); + + if (component.isError()) { + for (QQmlError e : component.errors()) + qCritical("%s:%d:%d: %s", e.url().toString().toStdString().c_str(), + e.line(), e.column(), e.description().toStdString().c_str()); + qFatal("One or more errors have occurred, exiting"); + } + + component.create(ctx); + + int ret = app.exec(); + delete ctx; + delete engine; + return ret; +} \ No newline at end of file diff --git a/src/resources.qrc b/src/resources.qrc new file mode 100644 index 0000000..efa0967 --- /dev/null +++ b/src/resources.qrc @@ -0,0 +1,8 @@ + + + Gui/Splash.qml + + Gui/Util/Http.qml + Gui/Util/qmldir + + \ No newline at end of file