47 #include "optionsWidget.hh" 50 #include <QMessageBox> 55 QFileInfo urlInfo(_url);
58 QFileInfo fileInfo( QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
59 ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + urlInfo.fileName() );
61 QString fileName = fileInfo.filePath();
63 if (QFile::exists(fileName)) {
64 QFile::remove(fileName);
67 file =
new QFile(fileName);
68 if (!file->open(QIODevice::WriteOnly)) {
69 std::cerr <<
"Unable to Open local file " + fileName.toStdString() +
" for writing" << std::endl;
72 checkUpdateButton->setEnabled(
true);
77 httpRequestAborted =
false;
78 QByteArray path = QUrl::toPercentEncoding(url.path(),
"!$&'()*+,;=:@/");
82 statusLabel->setText(tr(
"Getting Versions file from Server"));
84 if ( ! progressDialog_ ) {
85 progressDialog_ =
new QProgressDialog(
this);
86 connect(progressDialog_, SIGNAL(canceled()),
this, SLOT(cancelDownload()));
88 progressDialog_->setWindowTitle(tr(
"HTTP"));
89 progressDialog_->setLabelText(tr(
"Downloading %1.").arg(fileName));
90 progressDialog_->show();
92 downloadRep_ = networkMan_->get(req);
94 connect(downloadRep_, SIGNAL(error(QNetworkReply::NetworkError)),
95 this, SLOT(
showError(QNetworkReply::NetworkError)));
96 connect(downloadRep_,SIGNAL(downloadProgress(qint64 , qint64 )),
97 this,SLOT(updateDataReadProgress(qint64 , qint64 )));
99 checkUpdateButton->setEnabled(
false);
106 if ( ! updateUser->text().isEmpty() )
107 _authenticator->setUser(updateUser->text());
109 if ( ! updatePass->text().isEmpty() )
110 _authenticator->setPassword(updatePass->text());
113 void OptionsWidget::httpRequestFinished(QNetworkReply* _qnr)
115 if (_qnr != downloadRep_)
118 QNetworkReply::NetworkError error = _qnr->error();
120 if (httpRequestAborted) {
128 progressDialog_->hide();
129 checkUpdateButton->setEnabled(
true);
133 progressDialog_->hide();
136 delete(progressDialog_);
139 if (error != QNetworkReply::NoError) {
142 QString fileName = QFileInfo(QUrl(updateURL->text()).path()).fileName();
143 statusLabel->setText(tr(
"Downloaded %1").arg(file->fileName() ));
146 checkUpdateButton->setEnabled(
true);
150 if ( error == QNetworkReply::NoError ) {
151 if ( downloadType == VERSIONS_FILE )
153 if ( downloadType == PLUGIN )
158 void OptionsWidget::cancelDownload()
160 statusLabel->setText(tr(
"download canceled."));
161 httpRequestAborted =
true;
163 downloadRep_->abort();
164 checkUpdateButton->setEnabled(
true);
167 void OptionsWidget::updateDataReadProgress(qint64 _bytesReceived, qint64 _bytesTotal)
169 if (httpRequestAborted)
172 if (progressDialog_) {
173 progressDialog_->setMaximum(_bytesTotal);
174 progressDialog_->setValue(_bytesReceived);
180 if (_error == QNetworkReply::NoError)
182 statusLabel->setText(tr(
"Download failed: %1.").arg(downloadRep_->errorString()));
183 QMessageBox::information(
this, tr(
"HTTP Error"),
184 tr(
"Download failed: %1.")
185 .arg(downloadRep_->errorString()) + file->fileName() );
void authentication(QNetworkReply *_reply, QAuthenticator *_authenticator)
authentication
void compareVersions()
Compares the versions from the downloaded Versions file with the current versions.
void showError(QNetworkReply::NetworkError _error)
error occured while downloading
void startDownload(QString _url)
Starts the download of the given file.