UpdateCenterImpl::UpdateCenterImpl(Updates *updates, bool autoDownloadAndInstall, QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f) { setupUi(this); // resize for macosx #ifndef Q_OS_WIN32 resize(630, 366); #endif closedByButton = false; // version lblxVSTVersion->setText(QString(lblxVSTVersion->text()).arg(PROGRAM_VERSION)); // set update class this->updates = updates; // configure updates list QStringList headers; headers << tr(" File ") << tr(" Version ") << tr(" Size ") << tr(" Progress "); // add the headers lsvUpdates->setHeaderLabels(headers); // change headers sizes QFontMetrics fm = fontMetrics(); QHeaderView *header = lsvUpdates->header(); // resize header->resizeSection(1, fm.width(headers.at(0) + "9.99.999 alpha")); header->resizeSection(2, fm.width(headers.at(1) + " 1024,99Mb ")); // configure resize mode header->setHighlightSections(false); header->setStretchLastSection(false); header->setSectionResizeMode(0, QHeaderView::Stretch); // set header text aligment QTreeWidgetItem * headerItem = lsvUpdates->headerItem(); headerItem->setTextAlignment(1, Qt::AlignHCenter | Qt::AlignVCenter); headerItem->setTextAlignment(2, Qt::AlignRight | Qt::AlignVCenter); headerItem->setTextAlignment(3, Qt::AlignHCenter | Qt::AlignVCenter); // fill data fillUpdates(); // signals connect(lsvUpdates, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*, int))); connect(btnCancel, SIGNAL(clicked()), this, SLOT(btnCancelClicked())); connect(btnUpdate, SIGNAL(clicked()), this, SLOT(btnUpdateClicked())); // updater connect(updates, SIGNAL(downloadingUpdate(int, int, int)), this, SLOT(downloadingUpdate(int, int, int))); connect(updates, SIGNAL(downloadUpdateFinished(int)), this, SLOT(downloadUpdateFinished(int))); connect(updates, SIGNAL(downloadUpdateError(int)), this, SLOT(downloadUpdateError(int))); connect(updates, SIGNAL(downloadsFinished()), this, SLOT(downloadsFinished())); connect(updates, SIGNAL(readyToInstallUpdates()), this, SLOT(readyToInstallUpdates())); connect(updates, SIGNAL(failedToInstallUpdates()), this, SLOT(failedToInstallUpdates())); // if auto download & install updates, then... if (autoDownloadAndInstall) { // disable update button lsvUpdates->setEnabled(false); btnUpdate->setEnabled(false); // start automatically to download updates (in 500ms) QTimer::singleShot(500, this, SLOT(btnUpdateClicked())); } }
void ProgressDialog::networkReplyFinished(QNetworkReply *networkReply) { QVariant possibleRedirectUrl = networkReply->attribute(QNetworkRequest::RedirectionTargetAttribute); QString redirectUrl = possibleRedirectUrl.toUrl().toString(); if (!redirectUrl.isEmpty()) { doUrlDownload(redirectUrl); return; } this->m_downloadRequestTimeout->stop(); disconnect(this->m_networkRequest, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(networkReplyDownloadProgress(qint64,qint64))); QString filename = QDir::tempPath() + "/flashTool." + QUuid::createUuid().toString(); QFile *file = new QFile(filename); if (file->open(QIODevice::ReadWrite)) { file->write(networkReply->readAll()); } file->close(); this->m_downloads[this->m_downloadsIndex].tmpFile = filename; this->m_downloads[this->m_downloadsIndex].success = (networkReply->error() == QNetworkReply::NoError); this->m_downloadsIndex++; if (this->m_downloads.count() > this->m_downloadsIndex) { doUrlDownload(this->m_downloads[this->m_downloadsIndex].uri); } else { emit downloadsFinished(this->m_downloads); } }
void Updater::run() { connect(ai, SIGNAL(startUpdate(QList<FileUpdate>)), this, SLOT(startUpdate(QList<FileUpdate>))); connect(dm, SIGNAL(downloadsFinished(QList<FileUpdate>)), this, SLOT(downloadFinished(QList<FileUpdate>))); connect(ai, SIGNAL(applicationClosed(bool)), this, SLOT(startExchange(bool))); connect(ai, SIGNAL(executableChanged(QString)), this, SLOT(setExecutable(QString))); connect(fh, SIGNAL(exchangingFinished(bool)), this, SLOT(exchangeFinished(bool))); connect(dm, SIGNAL(error(QString)), ai, SLOT(sendError(QString))); connect(fh, SIGNAL(error(QString)), ai, SLOT(sendError(QString))); connect(ai, SIGNAL(close()), this, SLOT(closeRequested())); }