53 #include "optionsWidget.hh"
60 QFileInfo urlInfo(_url);
63 QFileInfo fileInfo( QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
64 ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + urlInfo.fileName() );
66 QString fileName = fileInfo.filePath();
68 if (QFile::exists(fileName)) {
69 QFile::remove(fileName);
72 file =
new QFile(fileName);
73 if (!file->open(QIODevice::WriteOnly)) {
74 std::cerr <<
"Unable to Open local file " + fileName.toStdString() +
" for writing" << std::endl;
77 checkUpdateButton->setEnabled(
true);
82 httpRequestAborted =
false;
83 QByteArray path = QUrl::toPercentEncoding(url.path(),
"!$&'()*+,;=:@/");
87 statusLabel->setText(tr(
"Getting Versions file from Server"));
89 if ( ! progressDialog_ ) {
90 progressDialog_ =
new QProgressDialog(
this);
91 connect(progressDialog_, SIGNAL(canceled()),
this, SLOT(cancelDownload()));
93 progressDialog_->setWindowTitle(tr(
"HTTP"));
94 progressDialog_->setLabelText(tr(
"Downloading %1.").arg(fileName));
95 progressDialog_->show();
97 downloadRep_ = networkMan_->get(req);
99 connect(downloadRep_, SIGNAL(error(QNetworkReply::NetworkError)),
100 this, SLOT(
showError(QNetworkReply::NetworkError)));
101 connect(downloadRep_,SIGNAL(downloadProgress(qint64 , qint64 )),
102 this,SLOT(updateDataReadProgress(qint64 , qint64 )));
104 checkUpdateButton->setEnabled(
false);
111 if ( ! updateUser->text().isEmpty() )
112 _authenticator->setUser(updateUser->text());
114 if ( ! updatePass->text().isEmpty() )
115 _authenticator->setPassword(updatePass->text());
118 void OptionsWidget::httpRequestFinished(QNetworkReply* _qnr)
120 if (_qnr != downloadRep_)
123 QNetworkReply::NetworkError error = _qnr->error();
125 if (httpRequestAborted) {
133 progressDialog_->hide();
134 checkUpdateButton->setEnabled(
true);
138 progressDialog_->hide();
141 delete(progressDialog_);
144 if (error != QNetworkReply::NoError) {
147 QString fileName = QFileInfo(QUrl(updateURL->text()).path()).fileName();
148 statusLabel->setText(tr(
"Downloaded %1").arg(file->fileName() ));
151 checkUpdateButton->setEnabled(
true);
155 if ( error == QNetworkReply::NoError ) {
156 if ( downloadType == VERSIONS_FILE )
158 if ( downloadType == PLUGIN )
163 void OptionsWidget::cancelDownload()
165 statusLabel->setText(tr(
"download canceled."));
166 httpRequestAborted =
true;
168 downloadRep_->abort();
169 checkUpdateButton->setEnabled(
true);
172 void OptionsWidget::updateDataReadProgress(qint64 _bytesReceived, qint64 _bytesTotal)
174 if (httpRequestAborted)
177 if (progressDialog_) {
178 progressDialog_->setMaximum(_bytesTotal);
179 progressDialog_->setValue(_bytesReceived);
185 if (_error == QNetworkReply::NoError)
187 statusLabel->setText(tr(
"Download failed: %1.").arg(downloadRep_->errorString()));
188 QMessageBox::information(
this, tr(
"HTTP Error"),
189 tr(
"Download failed: %1.")
190 .arg(downloadRep_->errorString()) + file->fileName() );
void showError(QNetworkReply::NetworkError _error)
error occured while downloading
void startDownload(QString _url)
Starts the download of the given file.
void authentication(QNetworkReply *_reply, QAuthenticator *_authenticator)
authentication
void compareVersions()
Compares the versions from the downloaded Versions file with the current versions.