Initial commit
This commit is contained in:
32
src/Gui/Splash.qml
Normal file
32
src/Gui/Splash.qml
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
6
src/Gui/Style/PStyle/PBackground.qml
Normal file
6
src/Gui/Style/PStyle/PBackground.qml
Normal file
@@ -0,0 +1,6 @@
|
||||
import QtQuick
|
||||
import "."
|
||||
|
||||
Rectangle {
|
||||
color: PStyle.backColor
|
||||
}
|
||||
16
src/Gui/Style/PStyle/PStyle.qml
Normal file
16
src/Gui/Style/PStyle/PStyle.qml
Normal 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,
|
||||
})
|
||||
}
|
||||
7
src/Gui/Style/PStyle/PText.qml
Normal file
7
src/Gui/Style/PStyle/PText.qml
Normal file
@@ -0,0 +1,7 @@
|
||||
import QtQuick
|
||||
import "."
|
||||
|
||||
Text {
|
||||
color: PStyle.foreColor
|
||||
font: PStyle.font
|
||||
}
|
||||
1
src/Gui/Style/PStyle/qmldir
Normal file
1
src/Gui/Style/PStyle/qmldir
Normal file
@@ -0,0 +1 @@
|
||||
singleton PStyle 1.0 PStyle.qml
|
||||
8
src/Gui/Style/resources.qrc
Normal file
8
src/Gui/Style/resources.qrc
Normal 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
83
src/Gui/Util/Http.qml
Normal 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
1
src/Gui/Util/qmldir
Normal file
@@ -0,0 +1 @@
|
||||
singleton Http 1.0 Http.qml
|
||||
43
src/main.cpp
Normal file
43
src/main.cpp
Normal 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
8
src/resources.qrc
Normal 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>
|
||||
Reference in New Issue
Block a user