Fixed compilation issues with Android
This commit is contained in:
parent
0a7107c414
commit
9ecad33138
@ -18,7 +18,7 @@ OTHER_FILES += $$PWD/src/QSimpleUpdater
|
||||
|
||||
INCLUDEPATH += $$PWD/src
|
||||
|
||||
macx || linux{
|
||||
macx || linux:!android {
|
||||
LIBS += -lcrypto -lssl
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,7 @@
|
||||
|
||||
DownloadDialog::DownloadDialog (QWidget *parent) :
|
||||
QWidget (parent),
|
||||
ui (new Ui::DownloadDialog)
|
||||
{
|
||||
ui (new Ui::DownloadDialog) {
|
||||
// Setup the UI
|
||||
ui->setupUi (this);
|
||||
|
||||
@ -27,13 +26,11 @@ DownloadDialog::DownloadDialog (QWidget *parent) :
|
||||
this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
||||
}
|
||||
|
||||
DownloadDialog::~DownloadDialog()
|
||||
{
|
||||
DownloadDialog::~DownloadDialog() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DownloadDialog::beginDownload (const QUrl &url)
|
||||
{
|
||||
void DownloadDialog::beginDownload (const QUrl &url) {
|
||||
Q_ASSERT (!url.isEmpty());
|
||||
|
||||
// Reset the UI
|
||||
@ -57,10 +54,8 @@ void DownloadDialog::beginDownload (const QUrl &url)
|
||||
showNormal();
|
||||
}
|
||||
|
||||
void DownloadDialog::openDownload()
|
||||
{
|
||||
if (!m_path.isEmpty())
|
||||
{
|
||||
void DownloadDialog::openDownload() {
|
||||
if (!m_path.isEmpty()) {
|
||||
QString url = m_path;
|
||||
|
||||
if (url.startsWith ("/"))
|
||||
@ -76,18 +71,15 @@ void DownloadDialog::openDownload()
|
||||
qWarning() << "QSimpleUpdater: cannot open downloaded file!";
|
||||
}
|
||||
|
||||
void DownloadDialog::cancelDownload()
|
||||
{
|
||||
if (!m_reply->isFinished())
|
||||
{
|
||||
void DownloadDialog::cancelDownload() {
|
||||
if (!m_reply->isFinished()) {
|
||||
QMessageBox _message;
|
||||
_message.setWindowTitle (tr ("Updater"));
|
||||
_message.setIcon (QMessageBox::Question);
|
||||
_message.setStandardButtons (QMessageBox::Yes | QMessageBox::No);
|
||||
_message.setText (tr ("Are you sure you want to cancel the download?"));
|
||||
|
||||
if (_message.exec() == QMessageBox::Yes)
|
||||
{
|
||||
if (_message.exec() == QMessageBox::Yes) {
|
||||
hide();
|
||||
m_reply->abort();
|
||||
}
|
||||
@ -97,21 +89,18 @@ void DownloadDialog::cancelDownload()
|
||||
hide();
|
||||
}
|
||||
|
||||
void DownloadDialog::downloadFinished()
|
||||
{
|
||||
void DownloadDialog::downloadFinished() {
|
||||
ui->stopButton->setText (tr ("Close"));
|
||||
ui->downloadLabel->setText (tr ("Download complete!"));
|
||||
ui->timeLabel->setText (tr ("The installer will open in a separate window..."));
|
||||
|
||||
QByteArray data = m_reply->readAll();
|
||||
|
||||
if (!data.isEmpty())
|
||||
{
|
||||
if (!data.isEmpty()) {
|
||||
QStringList list = m_reply->url().toString().split ("/");
|
||||
QFile file (QDir::tempPath() + "/" + list.at (list.count() - 1));
|
||||
|
||||
if (file.open (QIODevice::WriteOnly))
|
||||
{
|
||||
if (file.open (QIODevice::WriteOnly)) {
|
||||
file.write (data);
|
||||
m_path = file.fileName();
|
||||
}
|
||||
@ -127,11 +116,9 @@ void DownloadDialog::downloadFinished()
|
||||
qWarning() << "QSimpleUpdater: invalid download data!";
|
||||
}
|
||||
|
||||
void DownloadDialog::updateProgress (qint64 received, qint64 total)
|
||||
{
|
||||
void DownloadDialog::updateProgress (qint64 received, qint64 total) {
|
||||
// We know the size of the download, so we can calculate the progress....
|
||||
if (total > 0 && received > 0)
|
||||
{
|
||||
if (total > 0 && received > 0) {
|
||||
ui->progressBar->setMinimum (0);
|
||||
ui->progressBar->setMaximum (100);
|
||||
|
||||
@ -147,14 +134,12 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total)
|
||||
if (_total < 1024)
|
||||
_total_string = tr ("%1 bytes").arg (_total);
|
||||
|
||||
else if (_total < 1024 * 1024)
|
||||
{
|
||||
else if (_total < 1024 * 1024) {
|
||||
_total = roundNumber (_total / 1024);
|
||||
_total_string = tr ("%1 KB").arg (_total);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
_total = roundNumber (_total / (1024 * 1024));
|
||||
_total_string = tr ("%1 MB").arg (_total);
|
||||
}
|
||||
@ -162,14 +147,12 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total)
|
||||
if (_received < 1024)
|
||||
_received_string = tr ("%1 bytes").arg (_received);
|
||||
|
||||
else if (received < 1024 * 1024)
|
||||
{
|
||||
else if (received < 1024 * 1024) {
|
||||
_received = roundNumber (_received / 1024);
|
||||
_received_string = tr ("%1 KB").arg (_received);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
_received = roundNumber (_received / (1024 * 1024));
|
||||
_received_string = tr ("%1 MB").arg (_received);
|
||||
}
|
||||
@ -180,19 +163,16 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total)
|
||||
|
||||
uint _diff = QDateTime::currentDateTime().toTime_t() - m_start_time;
|
||||
|
||||
if (_diff > 0)
|
||||
{
|
||||
if (_diff > 0) {
|
||||
QString _time_string;
|
||||
float _time_remaining = total / (received / _diff);
|
||||
|
||||
if (_time_remaining > 7200)
|
||||
{
|
||||
if (_time_remaining > 7200) {
|
||||
_time_remaining /= 3600;
|
||||
_time_string = tr ("About %1 hours").arg (int (_time_remaining + 0.5));
|
||||
}
|
||||
|
||||
else if (_time_remaining > 60)
|
||||
{
|
||||
else if (_time_remaining > 60) {
|
||||
_time_remaining /= 60;
|
||||
_time_string = tr ("About %1 minutes").arg (int (_time_remaining + 0.5));
|
||||
}
|
||||
@ -205,8 +185,7 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total)
|
||||
}
|
||||
|
||||
// We do not know the size of the download, so we improvise...
|
||||
else
|
||||
{
|
||||
else {
|
||||
ui->progressBar->setValue (-1);
|
||||
ui->progressBar->setMinimum (0);
|
||||
ui->progressBar->setMaximum (0);
|
||||
@ -215,12 +194,10 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total)
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadDialog::ignoreSslErrors (QNetworkReply *reply, const QList<QSslError> &error)
|
||||
{
|
||||
void DownloadDialog::ignoreSslErrors (QNetworkReply *reply, const QList<QSslError> &error) {
|
||||
reply->ignoreSslErrors (error);
|
||||
}
|
||||
|
||||
float DownloadDialog::roundNumber (const float &input)
|
||||
{
|
||||
float DownloadDialog::roundNumber (const float &input) {
|
||||
return roundf (input * 100) / 100;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ class DownloadDialog : public QWidget
|
||||
Ui::DownloadDialog *ui;
|
||||
|
||||
QString m_path;
|
||||
bool m_download_paused;
|
||||
|
||||
QNetworkReply *m_reply;
|
||||
QNetworkAccessManager *m_manager;
|
||||
|
@ -108,6 +108,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
@ -118,6 +131,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="timeLabel">
|
||||
<property name="text">
|
||||
|
@ -12,15 +12,12 @@ QSimpleUpdater::QSimpleUpdater (QObject *parent)
|
||||
: QObject (parent)
|
||||
, m_changelog_downloaded (false)
|
||||
, m_version_check_finished (false)
|
||||
, m_new_version_available (false)
|
||||
{
|
||||
, m_new_version_available (false) {
|
||||
m_downloadDialog = new DownloadDialog();
|
||||
}
|
||||
|
||||
QString QSimpleUpdater::changeLog() const
|
||||
{
|
||||
if (m_changelog.isEmpty())
|
||||
{
|
||||
QString QSimpleUpdater::changeLog() const {
|
||||
if (m_changelog.isEmpty()) {
|
||||
qDebug() << "QSimpleUpdater: change log is empty,"
|
||||
<< "did you call setChangelogUrl() and checkForUpdates()?";
|
||||
}
|
||||
@ -28,10 +25,8 @@ QString QSimpleUpdater::changeLog() const
|
||||
return m_changelog;
|
||||
}
|
||||
|
||||
void QSimpleUpdater::checkForUpdates()
|
||||
{
|
||||
if (!m_reference_url.isEmpty())
|
||||
{
|
||||
void QSimpleUpdater::checkForUpdates() {
|
||||
if (!m_reference_url.isEmpty()) {
|
||||
QNetworkAccessManager *_manager = new QNetworkAccessManager (this);
|
||||
|
||||
connect (_manager, SIGNAL (finished (QNetworkReply *)),
|
||||
@ -47,22 +42,18 @@ void QSimpleUpdater::checkForUpdates()
|
||||
qDebug() << "QSimpleUpdater: Invalid reference URL";
|
||||
}
|
||||
|
||||
void QSimpleUpdater::openDownloadLink()
|
||||
{
|
||||
void QSimpleUpdater::openDownloadLink() {
|
||||
if (!m_download_url.isEmpty())
|
||||
QDesktopServices::openUrl (m_download_url);
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
qDebug() << "QSimpleUpdater: cannot download latest version,"
|
||||
<< "did you call setDownloadUrl() and checkForUpdates()?";
|
||||
}
|
||||
}
|
||||
|
||||
QString QSimpleUpdater::latestVersion() const
|
||||
{
|
||||
if (m_latest_version.isEmpty())
|
||||
{
|
||||
QString QSimpleUpdater::latestVersion() const {
|
||||
if (m_latest_version.isEmpty()) {
|
||||
qDebug() << "QSimpleUpdater: latest version is empty,"
|
||||
<< "did you call checkForUpdates() and setReferenceUrl()?";
|
||||
}
|
||||
@ -70,10 +61,8 @@ QString QSimpleUpdater::latestVersion() const
|
||||
return m_latest_version;
|
||||
}
|
||||
|
||||
QString QSimpleUpdater::installedVersion() const
|
||||
{
|
||||
if (m_installed_version.isEmpty())
|
||||
{
|
||||
QString QSimpleUpdater::installedVersion() const {
|
||||
if (m_installed_version.isEmpty()) {
|
||||
qDebug() << "QSimpleUpdater: installed version is empty,"
|
||||
<< "did you call setApplicationVersion()?";
|
||||
}
|
||||
@ -81,25 +70,21 @@ QString QSimpleUpdater::installedVersion() const
|
||||
return m_installed_version;
|
||||
}
|
||||
|
||||
void QSimpleUpdater::downloadLatestVersion()
|
||||
{
|
||||
void QSimpleUpdater::downloadLatestVersion() {
|
||||
if (!m_download_url.isEmpty())
|
||||
m_downloadDialog->beginDownload (m_download_url);
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
qDebug() << "QSimpleUpdater: cannot download latest version,"
|
||||
<< "did you call setDownloadUrl() and checkForUpdates()?";
|
||||
}
|
||||
}
|
||||
|
||||
bool QSimpleUpdater::newerVersionAvailable() const
|
||||
{
|
||||
bool QSimpleUpdater::newerVersionAvailable() const {
|
||||
return m_new_version_available;
|
||||
}
|
||||
|
||||
void QSimpleUpdater::setDownloadUrl (const QString &url)
|
||||
{
|
||||
void QSimpleUpdater::setDownloadUrl (const QString &url) {
|
||||
Q_ASSERT (!url.isEmpty());
|
||||
|
||||
if (!url.isEmpty())
|
||||
@ -109,8 +94,7 @@ void QSimpleUpdater::setDownloadUrl (const QString &url)
|
||||
qDebug() << "QSimpleUpdater: input URL cannot be empty!";
|
||||
}
|
||||
|
||||
void QSimpleUpdater::setReferenceUrl (const QString &url)
|
||||
{
|
||||
void QSimpleUpdater::setReferenceUrl (const QString &url) {
|
||||
Q_ASSERT (!url.isEmpty());
|
||||
|
||||
if (!url.isEmpty())
|
||||
@ -120,8 +104,7 @@ void QSimpleUpdater::setReferenceUrl (const QString &url)
|
||||
qDebug() << "QSimpleUpdater: input URL cannot be empty!";
|
||||
}
|
||||
|
||||
void QSimpleUpdater::setChangelogUrl (const QString &url)
|
||||
{
|
||||
void QSimpleUpdater::setChangelogUrl (const QString &url) {
|
||||
Q_ASSERT (!url.isEmpty());
|
||||
|
||||
if (!url.isEmpty())
|
||||
@ -131,8 +114,7 @@ void QSimpleUpdater::setChangelogUrl (const QString &url)
|
||||
qDebug() << "QSimpleUpdater: input URL cannot be empty!";
|
||||
}
|
||||
|
||||
void QSimpleUpdater::setApplicationVersion (const QString &version)
|
||||
{
|
||||
void QSimpleUpdater::setApplicationVersion (const QString &version) {
|
||||
Q_ASSERT (!version.isEmpty());
|
||||
|
||||
if (!version.isEmpty())
|
||||
@ -142,41 +124,33 @@ void QSimpleUpdater::setApplicationVersion (const QString &version)
|
||||
qDebug() << "QSimpleUpdater: input string cannot be empty!";
|
||||
}
|
||||
|
||||
void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply)
|
||||
{
|
||||
void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply) {
|
||||
bool _new_update = false;
|
||||
|
||||
QString _reply = QString::fromUtf8 (reply->readAll());
|
||||
_reply.replace (" ", "");
|
||||
_reply.replace ("\n", "");
|
||||
|
||||
if (!_reply.isEmpty() && _reply.contains ("."))
|
||||
{
|
||||
if (!_reply.isEmpty() && _reply.contains (".")) {
|
||||
m_latest_version = _reply;
|
||||
|
||||
QStringList _download = m_latest_version.split (".");
|
||||
QStringList _installed = m_installed_version.split (".");
|
||||
|
||||
for (int i = 0; i <= _download.count() - 1; ++i)
|
||||
{
|
||||
if (_download.count() - 1 >= i && _installed.count() - 1 >= i)
|
||||
{
|
||||
if (_download.at (i) > _installed.at (i))
|
||||
{
|
||||
for (int i = 0; i <= _download.count() - 1; ++i) {
|
||||
if (_download.count() - 1 >= i && _installed.count() - 1 >= i) {
|
||||
if (_download.at (i) > _installed.at (i)) {
|
||||
_new_update = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (_installed.count() < _download.count())
|
||||
{
|
||||
else {
|
||||
if (_installed.count() < _download.count()) {
|
||||
if (_installed.at (i - 1) == _download.at (i - 1))
|
||||
break;
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
_new_update = true;
|
||||
break;
|
||||
}
|
||||
@ -188,8 +162,7 @@ void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply)
|
||||
m_new_version_available = _new_update;
|
||||
emit versionCheckFinished();
|
||||
|
||||
if (!m_changelog_url.isEmpty() && newerVersionAvailable())
|
||||
{
|
||||
if (!m_changelog_url.isEmpty() && newerVersionAvailable()) {
|
||||
QNetworkAccessManager *_manager = new QNetworkAccessManager (this);
|
||||
|
||||
connect (_manager, SIGNAL (finished (QNetworkReply *)),
|
||||
@ -205,12 +178,10 @@ void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply)
|
||||
emit checkingFinished();
|
||||
}
|
||||
|
||||
void QSimpleUpdater::processDownloadedChangelog (QNetworkReply *reply)
|
||||
{
|
||||
void QSimpleUpdater::processDownloadedChangelog (QNetworkReply *reply) {
|
||||
QString _reply = QString::fromUtf8 (reply->readAll());
|
||||
|
||||
if (!_reply.isEmpty())
|
||||
{
|
||||
if (!_reply.isEmpty()) {
|
||||
m_changelog = _reply;
|
||||
emit changelogDownloadFinished();
|
||||
}
|
||||
@ -221,7 +192,6 @@ void QSimpleUpdater::processDownloadedChangelog (QNetworkReply *reply)
|
||||
emit checkingFinished();
|
||||
}
|
||||
|
||||
void QSimpleUpdater::ignoreSslErrors (QNetworkReply *reply, const QList<QSslError> &error)
|
||||
{
|
||||
void QSimpleUpdater::ignoreSslErrors (QNetworkReply *reply, const QList<QSslError> &error) {
|
||||
reply->ignoreSslErrors (error);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user