Added Qt example HttpWindow for network access

Added import of well paths to File->Import
p4#: 21764
This commit is contained in:
Magne Sjaastad
2013-05-29 14:49:04 +02:00
parent ada9819870
commit 5e3bb1f6a9
10 changed files with 719 additions and 12 deletions

View File

@@ -98,6 +98,8 @@ RiuMainWindow::RiuMainWindow()
m_treeModelPdm = new RimUiTreeModelPdm(this);
m_ssihubInterface = NULL;
createActions();
createMenus();
createToolBars();
@@ -185,6 +187,7 @@ void RiuMainWindow::createActions()
m_openProjectAction = new QAction(style()->standardIcon(QStyle::SP_DirOpenIcon), "&Open Project", this);
m_openLastUsedProjectAction = new QAction("Open &Last Used Project", this);
m_openWellPathsAction = new QAction(style()->standardIcon(QStyle::SP_DirOpenIcon), "&Open Well Paths", this);
m_importWellPathsAction = new QAction(style()->standardIcon(QStyle::SP_DriveNetIcon),"Import Well Paths", this);
m_mockModelAction = new QAction("&Mock Model", this);
m_mockResultsModelAction = new QAction("Mock Model With &Results", this);
@@ -207,6 +210,7 @@ void RiuMainWindow::createActions()
connect(m_openProjectAction, SIGNAL(triggered()), SLOT(slotOpenProject()));
connect(m_openLastUsedProjectAction,SIGNAL(triggered()), SLOT(slotOpenLastUsedProject()));
connect(m_openWellPathsAction, SIGNAL(triggered()), SLOT(slotOpenWellPaths()));
connect(m_importWellPathsAction, SIGNAL(triggered()), SLOT(slotImportWellPaths()));
connect(m_mockModelAction, SIGNAL(triggered()), SLOT(slotMockModel()));
connect(m_mockResultsModelAction, SIGNAL(triggered()), SLOT(slotMockResultsModel()));
@@ -303,6 +307,7 @@ void RiuMainWindow::createMenus()
importMenu->addAction(m_openEclipseCaseAction);
importMenu->addAction(m_openInputEclipseFileAction);
importMenu->addAction(m_openMultipleEclipseCasesAction);
importMenu->addAction(m_importWellPathsAction);
QMenu* exportMenu = fileMenu->addMenu("&Export");
exportMenu->addAction(m_snapshotToFile);
@@ -1586,7 +1591,11 @@ void RiuMainWindow::slotImportWellPaths()
{
m_ssihubInterface = new ssihub::Interface;
}
// ssihub::Interface ssiInterface;
m_ssihubInterface->setWebServiceAddress(app->preferences()->ssihubAddress);
//m_ssihubInterface->setJsonDestinationFolder(dir);
//m_ssihubInterface->setRegion(int east, int west, int north, int south);

View File

@@ -125,6 +125,7 @@ private:
QAction* m_openProjectAction;
QAction* m_openLastUsedProjectAction;
QAction* m_openWellPathsAction;
QAction* m_importWellPathsAction;
QAction* m_saveProjectAction;
QAction* m_saveProjectAsAction;
QAction* m_closeProjectAction;

View File

@@ -4,17 +4,31 @@ project (ssihubInterface)
# These headers need to go through Qt's MOC compiler
set( QOBJECT_HEADERS
ssihubWebServiceInterface.h
ssihubDialog.h
httpWindow.h
)
set( QT_UI_FILES
authenticationdialog.ui
)
if ( (${CMAKE_VERSION} VERSION_LESS 2.8.6) OR (NOT CMAKE_AUTOMOC) )
qt4_wrap_cpp( MOC_FILES_CPP ${QOBJECT_HEADERS} )
qt4_wrap_ui( FORM_FILES_CPP ${QT_UI_FILES} )
endif()
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
add_library( ${PROJECT_NAME}
ssihubInterface.cpp
ssihubWebServiceInterface.cpp
ssihubDialog.cpp
httpWindow.cpp
${MOC_FILES_CPP}
${FORM_FILES_CPP}
)

View File

@@ -0,0 +1,129 @@
<ui version="4.0" >
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>389</width>
<height>243</height>
</rect>
</property>
<property name="windowTitle" >
<string>Http authentication required</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" colspan="2" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>You need to supply a Username and a Password to access this site</string>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Username:</string>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QLineEdit" name="userEdit" />
</item>
<item row="3" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Password:</string>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QLineEdit" name="passwordEdit" />
</item>
<item row="5" column="0" colspan="2" >
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_4" >
<property name="text" >
<string>Site:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLabel" name="siteDescription" >
<property name="font" >
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text" >
<string>%1 at %2</string>
</property>
<property name="wordWrap" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,298 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtGui>
#include <QtNetwork>
#include "httpwindow.h"
#include "ui_authenticationdialog.h"
HttpWindow::HttpWindow(QWidget *parent)
#ifdef Q_WS_MAEMO_5
: QWidget(parent)
#else
: QDialog(parent)
#endif
{
#ifndef QT_NO_OPENSSL
urlLineEdit = new QLineEdit("https://qt.nokia.com/");
#else
urlLineEdit = new QLineEdit("http://qt.nokia.com/");
#endif
urlLabel = new QLabel(tr("&URL:"));
urlLabel->setBuddy(urlLineEdit);
statusLabel = new QLabel(tr("Please enter the URL of a file you want to "
"download."));
statusLabel->setWordWrap(true);
downloadButton = new QPushButton(tr("Download"));
downloadButton->setDefault(true);
quitButton = new QPushButton(tr("Quit"));
quitButton->setAutoDefault(false);
buttonBox = new QDialogButtonBox;
buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
#ifndef Q_WS_MAEMO_5
progressDialog = new QProgressDialog(this);
#endif
connect(urlLineEdit, SIGNAL(textChanged(QString)),
this, SLOT(enableDownloadButton()));
connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*)));
#ifndef QT_NO_OPENSSL
connect(&qnam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
#endif
#ifndef Q_WS_MAEMO_5
connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
#endif
connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(urlLabel);
topLayout->addWidget(urlLineEdit);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
mainLayout->addWidget(statusLabel);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("HTTP"));
urlLineEdit->setFocus();
}
void HttpWindow::startRequest(QUrl url)
{
reply = qnam.get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()),
this, SLOT(httpFinished()));
connect(reply, SIGNAL(readyRead()),
this, SLOT(httpReadyRead()));
connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(updateDataReadProgress(qint64,qint64)));
}
void HttpWindow::downloadFile()
{
url = urlLineEdit->text();
QFileInfo fileInfo(url.path());
QString fileName = fileInfo.fileName();
if (fileName.isEmpty())
fileName = "index.html";
if (QFile::exists(fileName)) {
if (QMessageBox::question(this, tr("HTTP"),
tr("There already exists a file called %1 in "
"the current directory. Overwrite?").arg(fileName),
QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
== QMessageBox::No)
return;
QFile::remove(fileName);
}
file = new QFile(fileName);
if (!file->open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("HTTP"),
tr("Unable to save the file %1: %2.")
.arg(fileName).arg(file->errorString()));
delete file;
file = 0;
return;
}
#ifndef Q_WS_MAEMO_5
progressDialog->setWindowTitle(tr("HTTP"));
progressDialog->setLabelText(tr("Downloading %1.").arg(fileName));
#endif
downloadButton->setEnabled(false);
// schedule the request
httpRequestAborted = false;
startRequest(url);
}
void HttpWindow::cancelDownload()
{
statusLabel->setText(tr("Download canceled."));
httpRequestAborted = true;
reply->abort();
downloadButton->setEnabled(true);
}
void HttpWindow::httpFinished()
{
if (httpRequestAborted) {
if (file) {
file->close();
file->remove();
delete file;
file = 0;
}
reply->deleteLater();
#ifndef Q_WS_MAEMO_5
progressDialog->hide();
#endif
return;
}
#ifndef Q_WS_MAEMO_5
progressDialog->hide();
#endif
file->flush();
file->close();
QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (reply->error()) {
file->remove();
QMessageBox::information(this, tr("HTTP"),
tr("Download failed: %1.")
.arg(reply->errorString()));
downloadButton->setEnabled(true);
} else if (!redirectionTarget.isNull()) {
QUrl newUrl = url.resolved(redirectionTarget.toUrl());
if (QMessageBox::question(this, tr("HTTP"),
tr("Redirect to %1 ?").arg(newUrl.toString()),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
url = newUrl;
reply->deleteLater();
file->open(QIODevice::WriteOnly);
file->resize(0);
startRequest(url);
return;
}
} else {
QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName();
statusLabel->setText(tr("Downloaded %1 to %2.").arg(fileName).arg(QDir::currentPath()));
downloadButton->setEnabled(true);
}
reply->deleteLater();
reply = 0;
delete file;
file = 0;
}
void HttpWindow::httpReadyRead()
{
// this slot gets called every time the QNetworkReply has new data.
// We read all of its new data and write it into the file.
// That way we use less RAM than when reading it at the finished()
// signal of the QNetworkReply
if (file)
file->write(reply->readAll());
}
void HttpWindow::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes)
{
if (httpRequestAborted)
return;
#ifndef Q_WS_MAEMO_5
progressDialog->setMaximum(totalBytes);
progressDialog->setValue(bytesRead);
#else
Q_UNUSED(bytesRead);
Q_UNUSED(totalBytes);
#endif
}
void HttpWindow::enableDownloadButton()
{
downloadButton->setEnabled(!urlLineEdit->text().isEmpty());
}
void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator)
{
QDialog dlg;
Ui::Dialog ui;
ui.setupUi(&dlg);
dlg.adjustSize();
ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host()));
// Did the URL have information? Fill the UI
// This is only relevant if the URL-supplied credentials were wrong
ui.userEdit->setText(url.userName());
ui.passwordEdit->setText(url.password());
if (dlg.exec() == QDialog::Accepted) {
authenticator->setUser(ui.userEdit->text());
authenticator->setPassword(ui.passwordEdit->text());
}
}
#ifndef QT_NO_OPENSSL
void HttpWindow::sslErrors(QNetworkReply*,const QList<QSslError> &errors)
{
QString errorString;
foreach (const QSslError &error, errors) {
if (!errorString.isEmpty())
errorString += ", ";
errorString += error.errorString();
}
if (QMessageBox::warning(this, tr("HTTP"),
tr("One or more SSL errors has occurred: %1").arg(errorString),
QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) {
reply->ignoreSslErrors();
}
}
#endif
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void HttpWindow::setUrl(const QString& httpAddress)
{
urlLineEdit->setText(httpAddress);
}

View File

@@ -0,0 +1,112 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef HTTPWINDOW_H
#define HTTPWINDOW_H
#ifdef Q_WS_MAEMO_5
#include <QWidget>
#else
#include <QDialog>
#endif
#include <QNetworkAccessManager>
#include <QUrl>
QT_BEGIN_NAMESPACE
class QDialogButtonBox;
class QFile;
class QLabel;
class QLineEdit;
class QProgressDialog;
class QPushButton;
class QSslError;
class QAuthenticator;
class QNetworkReply;
QT_END_NAMESPACE
#ifdef Q_WS_MAEMO_5
class HttpWindow : public QWidget
#else
class HttpWindow : public QDialog
#endif
{
Q_OBJECT
public:
HttpWindow(QWidget *parent = 0);
void setUrl(const QString& httpAddress);
void startRequest(QUrl url);
private slots:
void downloadFile();
void cancelDownload();
void httpFinished();
void httpReadyRead();
void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
void enableDownloadButton();
void slotAuthenticationRequired(QNetworkReply*,QAuthenticator *);
#ifndef QT_NO_OPENSSL
void sslErrors(QNetworkReply*,const QList<QSslError> &errors);
#endif
private:
QLabel *statusLabel;
QLabel *urlLabel;
QLineEdit *urlLineEdit;
#ifndef Q_WS_MAEMO_5
QProgressDialog *progressDialog;
#endif
QPushButton *downloadButton;
QPushButton *quitButton;
QDialogButtonBox *buttonBox;
QUrl url;
QNetworkAccessManager qnam;
QNetworkReply *reply;
QFile *file;
int httpGetId;
bool httpRequestAborted;
};
#endif

View File

@@ -17,6 +17,8 @@
/////////////////////////////////////////////////////////////////////////////////
#include "ssihubInterface.h"
#include "ssihubDialog.h"
#include "ssihubWebServiceInterface.h"
namespace ssihub {
@@ -27,22 +29,21 @@ namespace ssihub {
//--------------------------------------------------------------------------------------------------
Interface::Interface()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Interface::setWebServiceAdress(const QString& wsAdress)
void Interface::setWebServiceAddress(const QString wsAdress)
{
m_webServiceAdress = wsAdress;
m_webServiceAddress = wsAdress;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void Interface::setJsonDestinationFolder(const QString& folder)
void Interface::setJsonDestinationFolder(const QString folder)
{
m_jsonDestinationFolder = folder;
}
@@ -63,6 +64,17 @@ void Interface::setRegion(int east, int west, int north, int south)
//--------------------------------------------------------------------------------------------------
QStringList Interface::jsonWellPaths()
{
ssihub::WebServiceInterface ws;
ws.setUrl(m_webServiceAddress);
QMap<QString, QVariant> params;
ws.fetchData("", params);
// BasicAboutDialog dialog(NULL);
// dialog.exec();
return m_importedWellPathFiles;
}

View File

@@ -28,14 +28,14 @@ class Interface
public:
Interface();
void setWebServiceAdress(const QString& wsAdress);
void setJsonDestinationFolder(const QString& folder);
void setWebServiceAddress(const QString wsAdress);
void setJsonDestinationFolder(const QString folder);
void setRegion(int east, int west, int north, int south);
QStringList jsonWellPaths();
private:
QString m_webServiceAdress;
QString m_webServiceAddress;
QString m_jsonDestinationFolder;
int m_east;

View File

@@ -16,4 +16,113 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "ssihubWebServiceInterface.h"
#include "ssihubWebServiceInterface.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QStringList>
#include "httpwindow.h"
//#include <QObject>
namespace ssihub {
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
WebServiceInterface::WebServiceInterface(QObject *parent /*= 0*/)
: QObject(parent)
{
m_networkManager = new QNetworkAccessManager(this);
//connect(m_openProjectAction, SIGNAL(triggered()), SLOT(slotOpenProject()));
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onResult(QNetworkReply*)));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
WebServiceInterface::~WebServiceInterface()
{
//if (m_networkManager) delete m_networkManager;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void WebServiceInterface::setUrl(const QString& url)
{
m_httpAddress = url;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList WebServiceInterface::fetchData(const QString& method, const QMap<QString, QVariant>& arguments)
{
HttpWindow httpWin;
httpWin.setUrl(m_httpAddress);
httpWin.exec();
/*
QNetworkReply* reply = m_networkManager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));
while (!reply->isFinished())
{
}
QString data = (QString) reply->readAll();
/*
QUrl url(m_httpAddress);
// url.setPath(QString("%1%2").arg(url.path()).arg(method));
//
// foreach(QString param, arguments.keys()) {
// url.addQueryItem(param, arguments[param].toString());
// }
QNetworkRequest request;
request.setUrl(url);
QNetworkReply* reply = m_networkManager->get(request);
QString data = (QString) reply->readAll();
QStringList fileContent;
fileContent.push_back(data);
return fileContent;
*/
QStringList strings;
return strings;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void WebServiceInterface::onResult(QNetworkReply* reply)
{
if (reply->error() != QNetworkReply::NoError)
return; // ...only in a blog post
QString data = (QString) reply->readAll();
}
}; // namespace ssihub

View File

@@ -18,15 +18,38 @@
#pragma once
#include <QString>
#include <QVariant>
#include <QMap>
class QNetworkReply;
class QNetworkAccessManager;
namespace ssihub {
class WebServiceInterface
class WebServiceInterface : public QObject
{
public:
WebServiceInterface();
Q_OBJECT
public:
WebServiceInterface(QObject *parent = 0);
~WebServiceInterface();
void setUrl(const QString& url);
QStringList fetchData(const QString& method, const QMap<QString, QVariant>& arguments);
private slots:
void onResult(QNetworkReply* reply);
private:
QString m_httpAddress;
QNetworkAccessManager* m_networkManager;
};
}