summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Thiago Macieira <thiago@macieira.org>2013-11-14 14:55:49 -0800
committerGravatar Thiago Macieira <thiago@macieira.org>2013-12-03 13:53:00 -0800
commitff96bcb0fc9ef47c94fee8e675431882d20ba9dc (patch)
treeeccfda959b137e31b36e240e11395b3f30e8eca7
parentb38eac89e4903c91821c949d9d196bb1b8f652e3 (diff)
downloadsubsurface-ff96bcb0fc9ef47c94fee8e675431882d20ba9dc.tar.gz
Make the QNetworkAccessManager a singleton available to all
One of the rules of using QNetworkAccessManager is to share it among all users, since sockets and other state can be shared. Looks like Marble doesn't allow us to set it, though, and it creates multiple instances. I'll prepare an upstream patch to fix that sometime. Signed-off-by: Thiago Macieira <thiago@macieira.org>
-rw-r--r--qt-ui/subsurfacewebservices.cpp16
-rw-r--r--qt-ui/subsurfacewebservices.h3
2 files changed, 10 insertions, 9 deletions
diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
index 5edc5cb02..4713ef2af 100644
--- a/qt-ui/subsurfacewebservices.cpp
+++ b/qt-ui/subsurfacewebservices.cpp
@@ -23,7 +23,6 @@ WebServices::WebServices(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f)
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
connect(ui.download, SIGNAL(clicked(bool)), this, SLOT(startDownload()));
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
-
}
void WebServices::hidePassword()
@@ -37,6 +36,12 @@ void WebServices::hideUpload()
ui.upload->hide();
}
+QNetworkAccessManager *WebServices::manager()
+{
+ static QNetworkAccessManager *manager = new QNetworkAccessManager(qApp);
+ return manager;
+}
+
// #
// #
// # Subsurface Web Service Implementation.
@@ -89,9 +94,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
}
break;
case QDialogButtonBox::RejectRole:
- // we may want to clean up after ourselves, but this
- // makes Subsurface throw a SIGSEGV...
- // manager->deleteLater();
+ // we may want to clean up after ourselves
// reply->deleteLater();
ui.progressBar->setMaximum(1);
break;
@@ -108,11 +111,10 @@ void SubsurfaceWebServices::startDownload()
QUrl url("http://api.hohndel.org/api/dive/get/");
url.addQueryItem("login", ui.userID->text().toUpper());
- manager = new QNetworkAccessManager(this);
QNetworkRequest request;
request.setUrl(url);
request.setRawHeader("Accept", "text/xml");
- reply = manager->get(request);
+ reply = manager()->get(request);
ui.status->setText(tr("Wait a bit until we have something..."));
ui.progressBar->setRange(0,0); // this makes the progressbar do an 'infinite spin'
ui.download->setEnabled(false);
@@ -136,7 +138,6 @@ void SubsurfaceWebServices::downloadFinished()
if (resultCode == DD_STATUS_OK){
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
}
- manager->deleteLater();
reply->deleteLater();
}
@@ -145,7 +146,6 @@ void SubsurfaceWebServices::downloadError(QNetworkReply::NetworkError)
ui.download->setEnabled(true);
ui.progressBar->setRange(0,1);
ui.status->setText(QString::number((int)QNetworkRequest::HttpStatusCodeAttribute));
- manager->deleteLater();
reply->deleteLater();
}
diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h
index 83aba372b..0400fd503 100644
--- a/qt-ui/subsurfacewebservices.h
+++ b/qt-ui/subsurfacewebservices.h
@@ -17,6 +17,8 @@ public:
void hidePassword();
void hideUpload();
+ static QNetworkAccessManager *manager();
+
private slots:
virtual void startDownload() = 0;
virtual void startUpload() = 0;
@@ -25,7 +27,6 @@ private slots:
protected:
Ui::WebServices ui;
QNetworkReply *reply;
- QNetworkAccessManager *manager;
QByteArray downloadedData;
};