File indexing completed on 2024-12-22 03:46:51

0001 /*
0002   This file is part of the KTextTemplate library
0003 
0004   SPDX-FileCopyrightText: 2011 Stephen Kelly <steveire@gmail.com>
0005 
0006   SPDX-License-Identifier: LGPL-2.1-or-later
0007 
0008 */
0009 
0010 #define QT_DISABLE_DEPRECATED_BEFORE 0
0011 
0012 #include "localrequestmanager.h"
0013 
0014 #include <QDebug>
0015 #include <QFile>
0016 
0017 #include "templatereply.h"
0018 
0019 LocalRequestManager::LocalRequestManager(KTextTemplate::Engine *engine, QObject *parent)
0020     : QNetworkAccessManager(parent)
0021     , m_engine(engine)
0022 {
0023 }
0024 
0025 QNetworkReply *LocalRequestManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
0026 {
0027     QUrl requestUrl = request.url();
0028     if (requestUrl.scheme() != "template") {
0029         return QNetworkAccessManager::createRequest(op, request, outgoingData);
0030     }
0031 
0032     KTextTemplate::Template t = m_engine->loadByName(requestUrl.path());
0033 
0034     if (t->error()) {
0035         qDebug() << t->errorString();
0036     }
0037 
0038     QList<std::pair<QString, QString>> query = requestUrl.queryItems();
0039     if (outgoingData) {
0040         QUrl postData;
0041         postData.setEncodedQuery(outgoingData->readAll());
0042     }
0043 
0044     KTextTemplate::Context c;
0045 
0046     TemplateReply *reply = new TemplateReply(request, op, t, c);
0047 
0048     if (t->error()) {
0049         qDebug() << t->errorString();
0050     }
0051     reply->open(QIODevice::ReadOnly);
0052 
0053     return reply;
0054 }
0055 
0056 #include "moc_localrequestmanager.cpp"