Initial commit

This commit is contained in:
2023-12-09 13:51:39 -03:00
commit f29c8e8b41
12 changed files with 234 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build

28
CMakeLists.txt Normal file
View File

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

32
src/Gui/Splash.qml Normal file
View File

@@ -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
}
}
}
}

View File

@@ -0,0 +1,6 @@
import QtQuick
import "."
Rectangle {
color: PStyle.backColor
}

View File

@@ -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,
})
}

View File

@@ -0,0 +1,7 @@
import QtQuick
import "."
Text {
color: PStyle.foreColor
font: PStyle.font
}

View File

@@ -0,0 +1 @@
singleton PStyle 1.0 PStyle.qml

View File

@@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/">
<file alias="PStyle/qmldir">PStyle/qmldir</file>
<file alias="PStyle/PStyle.qml">PStyle/PStyle.qml</file>
<file alias="PStyle/PText.qml">PStyle/PText.qml</file>
<file alias="PStyle/PBackground.qml">PStyle/PBackground.qml</file>
</qresource>
</RCC>

83
src/Gui/Util/Http.qml Normal file
View File

@@ -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
}
}

1
src/Gui/Util/qmldir Normal file
View File

@@ -0,0 +1 @@
singleton Http 1.0 Http.qml

43
src/main.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include <iostream>
#include <QApplication>
#include <QGuiApplication>
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickStyle>
#include <QQuickWindow>
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;
}

8
src/resources.qrc Normal file
View File

@@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/">
<file alias="Splash.qml">Gui/Splash.qml</file>
<file alias="Util/Http.qml">Gui/Util/Http.qml</file>
<file alias="Util/qmldir">Gui/Util/qmldir</file>
</qresource>
</RCC>