added supprot GET requests

This commit is contained in:
Andrei Yankovich 2020-09-28 23:43:49 +03:00
parent 2318a08054
commit adc41cc058
8 changed files with 136 additions and 13 deletions

View File

@ -12,6 +12,8 @@ set(BUILD_SHARED_LIBS ON)
include(Site/QuasarAppLib/CMake/ccache.cmake)
include(Site/QuasarAppLib/CMake/crossplatform/crossplatform.cmake)
project(DocsSite)
# Add sub directories
add_subdirectory(Site)

View File

@ -9,6 +9,7 @@
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <correnthostimageprovider.h>
bool BaseFront::init(QQmlApplicationEngine *engine) {
if (!engine)
@ -18,6 +19,9 @@ bool BaseFront::init(QQmlApplicationEngine *engine) {
auto root = engine->rootContext();
if (!root)
return false;
engine->addImageProvider(QLatin1String("curhost"), new CorrentHostImageProvider);
engine->addImportPath(":/");
return true;

View File

@ -0,0 +1,75 @@
#include "correnthostimageprovider.h"
#include <string>
#include <functional>
#ifdef WASM32_BUILD
#include <emscripten/fetch.h>
#endif
namespace BaseFront {
CorrentHostImageProvider::CorrentHostImageProvider() {
}
CorrentHostImageProvider::~CorrentHostImageProvider() {
}
QQuickImageResponse *CorrentHostImageProvider::requestImageResponse(
const QString &id, const QSize &requestedSize) {
AsyncImageResponse *response = new AsyncImageResponse(id, requestedSize);
response->run();
return response;
}
AsyncImageResponse::AsyncImageResponse(const QString &id, const QSize &requestedSize)
: m_id(id), m_requestedSize(requestedSize) {
setAutoDelete(false);
}
QQuickTextureFactory *AsyncImageResponse::textureFactory() const {
return QQuickTextureFactory::textureFactoryForImage(m_image);
}
#ifdef WASM32_BUILD
static void * tmpPTR = nullptr;
#endif
void AsyncImageResponse::run() {
#ifdef WASM32_BUILD
tmpPTR = this;
auto downloadSucceeded = [](emscripten_fetch_t *fetch){
auto resp = reinterpret_cast<AsyncImageResponse*>(tmpPTR);
resp->m_image = QImage::fromData(reinterpret_cast<const unsigned char *>(fetch->data), fetch->numBytes);
if (resp->m_requestedSize.isValid())
resp->m_image = resp->m_image.scaled(resp->m_requestedSize);
emit resp->finished();
emscripten_fetch_close(fetch); // Free data associated with the fetch.
};
auto downloadFailed = [](emscripten_fetch_t *fetch){
emscripten_fetch_close(fetch); // Also free data on failure.
};
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
attr.onsuccess = downloadSucceeded;
attr.onerror = downloadFailed;
auto stdString = m_id.toStdString();
emscripten_fetch(&attr, stdString.c_str());
#else
cancel();
#endif
}
}

View File

@ -0,0 +1,35 @@
#ifndef CORRENTHOSTIMAGEPROVIDER_H
#define CORRENTHOSTIMAGEPROVIDER_H
#include <QQuickAsyncImageProvider>
#include <QRunnable>
#include "BaseFront_global.h"
namespace BaseFront {
class BASEFRONT_LIBRARYSHARED_EXPORT AsyncImageResponse : public QQuickImageResponse, public QRunnable
{
public:
AsyncImageResponse(const QString &id, const QSize &requestedSize);
QQuickTextureFactory *textureFactory() const;
void run();
QString m_id;
QSize m_requestedSize;
QImage m_image;
};
class BASEFRONT_LIBRARYSHARED_EXPORT CorrentHostImageProvider: public QQuickAsyncImageProvider
{
public:
CorrentHostImageProvider();
~CorrentHostImageProvider();
QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
};
}
#endif // CORRENTHOSTIMAGEPROVIDER_H

@ -1 +1 @@
Subproject commit f84faab0ddfda32f165633a9c18df4898434f0c4
Subproject commit f873269780d00e9dfe2f56a7d6a9702f49d35508

View File

@ -18,5 +18,5 @@ QObject * AbstractPage::makeBlok() const {
}
QString AbstractPage::resourcesPath() const {
return QuasarAppUtils::Params::getCurrentExecutableDir() + "/plugins/images";
return "image://curhost/plugins/images";
}

View File

@ -13,6 +13,8 @@
int main(int argc, char *argv[])
{
QuasarAppUtils::Params::parseParams(argc, argv);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);

View File

@ -57,24 +57,29 @@
<translation type="vanished">Поддерживаемые платформы</translation>
</message>
<message>
<location filename="../Models/mainmodel.cpp" line="109"/>
<source>At the moment, we can offer support for our solutions for the following platforms:&lt;br&gt;&lt;br&gt;</source>
<translation>На данный момент мы можем предложить поддержку наших решений для следующих платформ: &lt;br&gt; &lt;br&gt;</translation>
<translation type="vanished">На данный момент мы можем предложить поддержку наших решений для следующих платформ: &lt;br&gt; &lt;br&gt;</translation>
</message>
<message>
<location filename="../Models/mainmodel.cpp" line="111"/>
<source>- &lt;i&gt; Linux &lt;/i&gt;&lt;br&gt;- &lt;i&gt; Windows &lt;/i&gt;&lt;br&gt;- &lt;i&gt; Android &lt;/i&gt;&lt;br&gt;- &lt;i&gt; Web &lt;/i&gt;</source>
<translation></translation>
</message>
<message>
<location filename="../Models/mainmodel.cpp" line="122"/>
<source>Order a project.</source>
<translation>Заказать проект.</translation>
<translation type="vanished">Заказать проект.</translation>
</message>
<message>
<location filename="../Models/mainmodel.cpp" line="124"/>
<source>We are always happy to help you realize your best and most fantastic ideas.&lt;br&gt;&lt;br&gt;If you have an idea for the application, then you can leave a request to create a project with us on GitHub. All that is required of you is a detailed description of what needs to be done. Further, our specialists will decide when work will begin on the project and how much resources will be allocated to the project.&lt;br&gt;&lt;br&gt;That how many resources will be allocated for the development depends on how much this project will collect cash donations.&lt;br&gt;&lt;br&gt;You can also request a private project exclusively for you, but such a project can no longer be free.</source>
<translation>Мы всегда рады помочь вам реализовать ваши лучшие и самые фантастические идеи. &lt;br&gt; &lt;br&gt; Если у вас есть идея для приложения, вы можете оставить заявку на создание проекта у нас на GitHub. Все, что от вас требуется, - это подробное описание того, что нужно сделать. Далее наши специалисты решат, когда начнется работа над проектом и сколько ресурсов будет выделено для проекта. &lt;br&gt; &lt;br&gt; То, сколько ресурсов будет выделено на разработку, зависит от того, сколько этот проект собирет денежными пожертвованиями. . &lt;br&gt; &lt;br&gt; Вы также можете запросить частный проект исключительно для вас, но такой проект больше не может быть бесплатным.</translation>
<translation type="vanished">Мы всегда рады помочь вам реализовать ваши лучшие и самые фантастические идеи. &lt;br&gt; &lt;br&gt; Если у вас есть идея для приложения, вы можете оставить заявку на создание проекта у нас на GitHub. Все, что от вас требуется, - это подробное описание того, что нужно сделать. Далее наши специалисты решат, когда начнется работа над проектом и сколько ресурсов будет выделено для проекта. &lt;br&gt; &lt;br&gt; То, сколько ресурсов будет выделено на разработку, зависит от того, сколько этот проект собирет денежными пожертвованиями. . &lt;br&gt; &lt;br&gt; Вы также можете запросить частный проект исключительно для вас, но такой проект больше не может быть бесплатным.</translation>
</message>
</context>
<context>
<name>QasarAppOrder</name>
<message>
<location filename="../Models/qasarapporder.cpp" line="9"/>
<source>We are always happy to help you realize your best and most fantastic ideas.&lt;br&gt;&lt;br&gt;If you have an idea for the application, then you can leave a request to create a project with us on GitHub. All that is required of you is a detailed description of what needs to be done. Further, our specialists will decide when work will begin on the project and how much resources will be allocated to the project.&lt;br&gt;&lt;br&gt;That how many resources will be allocated for the development depends on how much this project will collect cash donations.&lt;br&gt;&lt;br&gt;You can also request a private project exclusively for you, but such a project can no longer be free.</source>
<translation type="unfinished">Мы всегда рады помочь вам реализовать ваши лучшие и самые фантастические идеи. &lt;br&gt; &lt;br&gt; Если у вас есть идея для приложения, вы можете оставить заявку на создание проекта у нас на GitHub. Все, что от вас требуется, - это подробное описание того, что нужно сделать. Далее наши специалисты решат, когда начнется работа над проектом и сколько ресурсов будет выделено для проекта. &lt;br&gt; &lt;br&gt; То, сколько ресурсов будет выделено на разработку, зависит от того, сколько этот проект собирет денежными пожертвованиями. . &lt;br&gt; &lt;br&gt; Вы также можете запросить частный проект исключительно для вас, но такой проект больше не может быть бесплатным.</translation>
</message>
<message>
<location filename="../Models/qasarapporder.cpp" line="23"/>
<source>Order a project.</source>
<translation type="unfinished">Заказать проект.</translation>
</message>
</context>
<context>