mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
b38eac89e4
commit
ff96bcb0fc
2 changed files with 10 additions and 9 deletions
|
@ -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.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
||||||
connect(ui.download, SIGNAL(clicked(bool)), this, SLOT(startDownload()));
|
connect(ui.download, SIGNAL(clicked(bool)), this, SLOT(startDownload()));
|
||||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
|
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebServices::hidePassword()
|
void WebServices::hidePassword()
|
||||||
|
@ -37,6 +36,12 @@ void WebServices::hideUpload()
|
||||||
ui.upload->hide();
|
ui.upload->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QNetworkAccessManager *WebServices::manager()
|
||||||
|
{
|
||||||
|
static QNetworkAccessManager *manager = new QNetworkAccessManager(qApp);
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
// #
|
// #
|
||||||
// #
|
// #
|
||||||
// # Subsurface Web Service Implementation.
|
// # Subsurface Web Service Implementation.
|
||||||
|
@ -89,9 +94,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QDialogButtonBox::RejectRole:
|
case QDialogButtonBox::RejectRole:
|
||||||
// we may want to clean up after ourselves, but this
|
// we may want to clean up after ourselves
|
||||||
// makes Subsurface throw a SIGSEGV...
|
|
||||||
// manager->deleteLater();
|
|
||||||
// reply->deleteLater();
|
// reply->deleteLater();
|
||||||
ui.progressBar->setMaximum(1);
|
ui.progressBar->setMaximum(1);
|
||||||
break;
|
break;
|
||||||
|
@ -108,11 +111,10 @@ void SubsurfaceWebServices::startDownload()
|
||||||
QUrl url("http://api.hohndel.org/api/dive/get/");
|
QUrl url("http://api.hohndel.org/api/dive/get/");
|
||||||
url.addQueryItem("login", ui.userID->text().toUpper());
|
url.addQueryItem("login", ui.userID->text().toUpper());
|
||||||
|
|
||||||
manager = new QNetworkAccessManager(this);
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
request.setRawHeader("Accept", "text/xml");
|
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.status->setText(tr("Wait a bit until we have something..."));
|
||||||
ui.progressBar->setRange(0,0); // this makes the progressbar do an 'infinite spin'
|
ui.progressBar->setRange(0,0); // this makes the progressbar do an 'infinite spin'
|
||||||
ui.download->setEnabled(false);
|
ui.download->setEnabled(false);
|
||||||
|
@ -136,7 +138,6 @@ void SubsurfaceWebServices::downloadFinished()
|
||||||
if (resultCode == DD_STATUS_OK){
|
if (resultCode == DD_STATUS_OK){
|
||||||
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
|
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
|
||||||
}
|
}
|
||||||
manager->deleteLater();
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +146,6 @@ void SubsurfaceWebServices::downloadError(QNetworkReply::NetworkError)
|
||||||
ui.download->setEnabled(true);
|
ui.download->setEnabled(true);
|
||||||
ui.progressBar->setRange(0,1);
|
ui.progressBar->setRange(0,1);
|
||||||
ui.status->setText(QString::number((int)QNetworkRequest::HttpStatusCodeAttribute));
|
ui.status->setText(QString::number((int)QNetworkRequest::HttpStatusCodeAttribute));
|
||||||
manager->deleteLater();
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ public:
|
||||||
void hidePassword();
|
void hidePassword();
|
||||||
void hideUpload();
|
void hideUpload();
|
||||||
|
|
||||||
|
static QNetworkAccessManager *manager();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
virtual void startDownload() = 0;
|
virtual void startDownload() = 0;
|
||||||
virtual void startUpload() = 0;
|
virtual void startUpload() = 0;
|
||||||
|
@ -25,7 +27,6 @@ private slots:
|
||||||
protected:
|
protected:
|
||||||
Ui::WebServices ui;
|
Ui::WebServices ui;
|
||||||
QNetworkReply *reply;
|
QNetworkReply *reply;
|
||||||
QNetworkAccessManager *manager;
|
|
||||||
QByteArray downloadedData;
|
QByteArray downloadedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue