Work on issue #6
This commit is contained in:
parent
401f79cdfc
commit
e0c7e41212
@ -1,2 +1,2 @@
|
|||||||
# Style and format recursively
|
# Style and format recursively
|
||||||
astyle --style=linux --indent=spaces --align-pointer=type --indent-preproc-block --indent-preproc-define --indent-col1-comments --pad-first-paren-out --pad-oper --attach-namespaces --remove-brackets --convert-tabs --close-templates --max-code-length=100 --max-instatement-indent=50 --lineend=windows --suffix=none --recursive ../../*.h ../../*.c ../../*.cpp ../../*.cc
|
astyle --style=linux --indent=spaces --align-pointer=type --indent-preproc-block --indent-preproc-define --indent-col1-comments --pad-first-paren-out --pad-oper --attach-namespaces --remove-brackets --convert-tabs --close-templates --max-code-length=100 --max-instatement-indent=50 --lineend=windows --suffix=none --recursive ../../*.h ../../*.cpp ../../*.cc
|
||||||
|
@ -89,6 +89,7 @@ public:
|
|||||||
QString getPlatformKey (const QString& url) const;
|
QString getPlatformKey (const QString& url) const;
|
||||||
QString getLatestVersion (const QString& url) const;
|
QString getLatestVersion (const QString& url) const;
|
||||||
QString getModuleVersion (const QString& url) const;
|
QString getModuleVersion (const QString& url) const;
|
||||||
|
QString getUserAgentString (const QString& url) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void checkForUpdates (const QString& url);
|
void checkForUpdates (const QString& url);
|
||||||
@ -98,6 +99,7 @@ public slots:
|
|||||||
void setPlatformKey (const QString& url, const QString& platform);
|
void setPlatformKey (const QString& url, const QString& platform);
|
||||||
void setModuleVersion (const QString& url, const QString& version);
|
void setModuleVersion (const QString& url, const QString& version);
|
||||||
void setDownloaderEnabled (const QString& url, const bool enabled);
|
void setDownloaderEnabled (const QString& url, const bool enabled);
|
||||||
|
void setUserAgentString (const QString& url, const QString& agent);
|
||||||
void setUseCustomAppcast (const QString& url, const bool customAppcast);
|
void setUseCustomAppcast (const QString& url, const bool customAppcast);
|
||||||
void setUseCustomInstallProcedures (const QString& url, const bool custom);
|
void setUseCustomInstallProcedures (const QString& url, const bool custom);
|
||||||
|
|
||||||
|
@ -112,9 +112,14 @@ void Downloader::startDownload (const QUrl& url)
|
|||||||
m_ui->downloadLabel->setText (tr ("Downloading updates"));
|
m_ui->downloadLabel->setText (tr ("Downloading updates"));
|
||||||
m_ui->timeLabel->setText (tr ("Time remaining") + ": " + tr ("unknown"));
|
m_ui->timeLabel->setText (tr ("Time remaining") + ": " + tr ("unknown"));
|
||||||
|
|
||||||
|
/* Configure the network request */
|
||||||
|
QNetworkRequest request (url);
|
||||||
|
if (!m_userAgentString.isEmpty())
|
||||||
|
request.setRawHeader ("User-Agent", m_userAgentString.toUtf8());
|
||||||
|
|
||||||
/* Start download */
|
/* Start download */
|
||||||
m_startTime = QDateTime::currentDateTime().toTime_t();
|
m_startTime = QDateTime::currentDateTime().toTime_t();
|
||||||
m_reply = m_manager->get (QNetworkRequest (url));
|
m_reply = m_manager->get (request);
|
||||||
|
|
||||||
/* Ensure that downloads directory exists */
|
/* Ensure that downloads directory exists */
|
||||||
if (!DOWNLOAD_DIR.exists())
|
if (!DOWNLOAD_DIR.exists())
|
||||||
@ -384,6 +389,14 @@ qreal Downloader::round (const qreal& input)
|
|||||||
return roundf (input * 100) / 100;
|
return roundf (input * 100) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the user-agent string used to communicate with the remote HTTP server
|
||||||
|
*/
|
||||||
|
void Downloader::setUserAgentString (const QString& agent)
|
||||||
|
{
|
||||||
|
m_userAgentString = agent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the \a custom parameter is set to \c true, then the \c Downloader will not
|
* If the \a custom parameter is set to \c true, then the \c Downloader will not
|
||||||
* attempt to open the downloaded file.
|
* attempt to open the downloaded file.
|
||||||
|
@ -60,6 +60,7 @@ public slots:
|
|||||||
void setUrlId (const QString& url);
|
void setUrlId (const QString& url);
|
||||||
void startDownload (const QUrl& url);
|
void startDownload (const QUrl& url);
|
||||||
void setFileName (const QString& file);
|
void setFileName (const QString& file);
|
||||||
|
void setUserAgentString (const QString& agent);
|
||||||
void setUseCustomInstallProcedures (const bool custom);
|
void setUseCustomInstallProcedures (const bool custom);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -80,6 +81,7 @@ private:
|
|||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
Ui::Downloader* m_ui;
|
Ui::Downloader* m_ui;
|
||||||
QNetworkReply* m_reply;
|
QNetworkReply* m_reply;
|
||||||
|
QString m_userAgentString;
|
||||||
bool m_useCustomProcedures;
|
bool m_useCustomProcedures;
|
||||||
QNetworkAccessManager* m_manager;
|
QNetworkAccessManager* m_manager;
|
||||||
};
|
};
|
||||||
|
@ -229,6 +229,18 @@ QString QSimpleUpdater::getModuleVersion (const QString& url) const
|
|||||||
return getUpdater (url)->moduleVersion();
|
return getUpdater (url)->moduleVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user-agent string used by the updater to communicate with
|
||||||
|
* the remote HTTP(S) server.
|
||||||
|
*
|
||||||
|
* \note If an \c Updater instance registered with the given \a url is not
|
||||||
|
* found, that \c Updater instance will be initialized automatically
|
||||||
|
*/
|
||||||
|
QString QSimpleUpdater::getUserAgentString (const QString& url) const
|
||||||
|
{
|
||||||
|
return getUpdater (url)->userAgentString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instructs the \c Updater instance with the registered \c url to download and
|
* Instructs the \c Updater instance with the registered \c url to download and
|
||||||
* interpret the update definitions file.
|
* interpret the update definitions file.
|
||||||
@ -330,6 +342,19 @@ void QSimpleUpdater::setDownloaderEnabled (const QString& url,
|
|||||||
getUpdater (url)->setDownloaderEnabled (enabled);
|
getUpdater (url)->setDownloaderEnabled (enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the user-agent string used by the updater to communicate
|
||||||
|
* with the remote server
|
||||||
|
*
|
||||||
|
* \note If an \c Updater instance registered with the given \a url is not
|
||||||
|
* found, that \c Updater instance will be initialized automatically
|
||||||
|
*/
|
||||||
|
void QSimpleUpdater::setUserAgentString (const QString& url,
|
||||||
|
const QString& agent)
|
||||||
|
{
|
||||||
|
getUpdater (url)->setUserAgentString (agent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the \a customAppcast parameter is set to \c true, then the \c Updater
|
* If the \a customAppcast parameter is set to \c true, then the \c Updater
|
||||||
* will not try to read the network reply from the server, instead, it will
|
* will not try to read the network reply from the server, instead, it will
|
||||||
|
@ -67,6 +67,9 @@ Updater::Updater()
|
|||||||
m_platform = "ios";
|
m_platform = "ios";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
setUserAgentString (QString ("%1/%2 (Qt; QSimpleUpdater)").arg (qApp->applicationName(),
|
||||||
|
qApp->applicationVersion()));
|
||||||
|
|
||||||
connect (m_downloader, SIGNAL (downloadFinished (QString, QString)),
|
connect (m_downloader, SIGNAL (downloadFinished (QString, QString)),
|
||||||
this, SIGNAL (downloadFinished (QString, QString)));
|
this, SIGNAL (downloadFinished (QString, QString)));
|
||||||
connect (m_manager, SIGNAL (finished (QNetworkReply*)),
|
connect (m_manager, SIGNAL (finished (QNetworkReply*)),
|
||||||
@ -147,6 +150,15 @@ QString Updater::latestVersion() const
|
|||||||
return m_latestVersion;
|
return m_latestVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user-agent header used by the client when communicating
|
||||||
|
* with the server through HTTP
|
||||||
|
*/
|
||||||
|
QString Updater::userAgentString() const
|
||||||
|
{
|
||||||
|
return m_userAgentString;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the "local" version of the installed module
|
* Returns the "local" version of the installed module
|
||||||
*/
|
*/
|
||||||
@ -221,7 +233,11 @@ bool Updater::useCustomInstallProcedures() const
|
|||||||
*/
|
*/
|
||||||
void Updater::checkForUpdates()
|
void Updater::checkForUpdates()
|
||||||
{
|
{
|
||||||
m_manager->get (QNetworkRequest (url()));
|
QNetworkRequest request (url());
|
||||||
|
if (!userAgentString().isEmpty())
|
||||||
|
request.setRawHeader ("User-Agent", userAgentString().toUtf8());
|
||||||
|
|
||||||
|
m_manager->get (request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -261,6 +277,18 @@ void Updater::setNotifyOnFinish (const bool notify)
|
|||||||
m_notifyOnFinish = notify;
|
m_notifyOnFinish = notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the user agent string used to identify the client application
|
||||||
|
* from the server in a HTTP session.
|
||||||
|
*
|
||||||
|
* By default, the user agent will co
|
||||||
|
*/
|
||||||
|
void Updater::setUserAgentString (const QString& agent)
|
||||||
|
{
|
||||||
|
m_userAgentString = agent;
|
||||||
|
m_downloader->setUserAgentString (agent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the module \a version
|
* Changes the module \a version
|
||||||
* \note The module version is used to compare the local and remote versions.
|
* \note The module version is used to compare the local and remote versions.
|
||||||
@ -331,8 +359,7 @@ void Updater::onReply (QNetworkReply* reply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* There was a network error */
|
/* There was a network error */
|
||||||
if (reply->error() != QNetworkReply::NoError)
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
{
|
|
||||||
setUpdateAvailable (false);
|
setUpdateAvailable (false);
|
||||||
emit checkingFinished (url());
|
emit checkingFinished (url());
|
||||||
return;
|
return;
|
||||||
@ -349,8 +376,7 @@ void Updater::onReply (QNetworkReply* reply)
|
|||||||
QJsonDocument document = QJsonDocument::fromJson (reply->readAll());
|
QJsonDocument document = QJsonDocument::fromJson (reply->readAll());
|
||||||
|
|
||||||
/* JSON is invalid */
|
/* JSON is invalid */
|
||||||
if (document.isNull())
|
if (document.isNull()) {
|
||||||
{
|
|
||||||
setUpdateAvailable (false);
|
setUpdateAvailable (false);
|
||||||
emit checkingFinished (url());
|
emit checkingFinished (url());
|
||||||
return;
|
return;
|
||||||
|
@ -63,6 +63,7 @@ public:
|
|||||||
QString platformKey() const;
|
QString platformKey() const;
|
||||||
QString moduleVersion() const;
|
QString moduleVersion() const;
|
||||||
QString latestVersion() const;
|
QString latestVersion() const;
|
||||||
|
QString userAgentString() const;
|
||||||
|
|
||||||
bool customAppcast() const;
|
bool customAppcast() const;
|
||||||
bool notifyOnUpdate() const;
|
bool notifyOnUpdate() const;
|
||||||
@ -77,6 +78,7 @@ public slots:
|
|||||||
void setModuleName (const QString& name);
|
void setModuleName (const QString& name);
|
||||||
void setNotifyOnUpdate (const bool notify);
|
void setNotifyOnUpdate (const bool notify);
|
||||||
void setNotifyOnFinish (const bool notify);
|
void setNotifyOnFinish (const bool notify);
|
||||||
|
void setUserAgentString (const QString& agent);
|
||||||
void setModuleVersion (const QString& version);
|
void setModuleVersion (const QString& version);
|
||||||
void setDownloaderEnabled (const bool enabled);
|
void setDownloaderEnabled (const bool enabled);
|
||||||
void setPlatformKey (const QString& platformKey);
|
void setPlatformKey (const QString& platformKey);
|
||||||
@ -92,6 +94,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_url;
|
QString m_url;
|
||||||
|
QString m_userAgentString;
|
||||||
|
|
||||||
bool m_customAppcast;
|
bool m_customAppcast;
|
||||||
bool m_notifyOnUpdate;
|
bool m_notifyOnUpdate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user