mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
New button: Download default icons and mapping (#4703)
Basing the URL of icons.zip on VERSION_CONFIG_PREFIX
Additional: Pointing VERSION_CONFIG_PREFIX to 3.8,
paired to cb76b795dc
This commit is contained in:
committed by
GitHub
parent
8ab29217e5
commit
3fc373110f
@@ -134,7 +134,7 @@
|
||||
//#define GC_VERSION VERSION_STRING // To force version string on non-tagged ci builds
|
||||
|
||||
// default config for this release cycle
|
||||
#define VERSION_CONFIG_PREFIX "http://www.goldencheetah.org/defaults/3.7"
|
||||
#define VERSION_CONFIG_PREFIX "http://www.goldencheetah.org/defaults/3.8"
|
||||
|
||||
class GcUpgradeLogDialog : public QDialog
|
||||
{
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "IconManager.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "../qzip/zipwriter.h"
|
||||
#include "../qzip/zipreader.h"
|
||||
@@ -205,11 +207,28 @@ IconManager::importBundle
|
||||
(const QString &filename)
|
||||
{
|
||||
QFile zipFile(filename);
|
||||
if (! zipFile.open(QIODevice::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
zipFile.close();
|
||||
ZipReader reader(zipFile.fileName());
|
||||
return importBundle(&zipFile);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
IconManager::importBundle
|
||||
(const QUrl &url)
|
||||
{
|
||||
QByteArray zipData = downloadUrl(url);
|
||||
QBuffer buffer;
|
||||
buffer.setData(zipData);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
|
||||
return importBundle(&buffer);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
IconManager::importBundle
|
||||
(QIODevice *device)
|
||||
{
|
||||
ZipReader reader(device);
|
||||
for (ZipReader::FileInfo info : reader.fileInfoList()) {
|
||||
if (info.isFile) {
|
||||
QByteArray data = reader.fileData(info.filePath);
|
||||
@@ -313,3 +332,37 @@ IconManager::readGroup
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
QByteArray
|
||||
IconManager::downloadUrl
|
||||
(const QUrl &url, int timeoutMs)
|
||||
{
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkRequest request(url);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
#endif
|
||||
QNetworkReply *reply = manager.get(request);
|
||||
|
||||
QTimer timeoutTimer;
|
||||
timeoutTimer.setSingleShot(true);
|
||||
QEventLoop loop;
|
||||
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
QObject::connect(&timeoutTimer, &QTimer::timeout, [&]() {
|
||||
reply->abort();
|
||||
loop.quit();
|
||||
});
|
||||
timeoutTimer.start(timeoutMs);
|
||||
loop.exec();
|
||||
timeoutTimer.stop();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
delete reply;
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray data = reply->readAll();
|
||||
delete reply;
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
|
||||
bool exportBundle(const QString &filepath);
|
||||
bool importBundle(const QString &filepath);
|
||||
bool importBundle(const QUrl &url);
|
||||
bool importBundle(QIODevice *device);
|
||||
|
||||
bool saveConfig() const;
|
||||
|
||||
@@ -68,6 +70,7 @@ private:
|
||||
bool loadMapping();
|
||||
void writeGroup(QJsonObject &rootObj, const QString &field, const QHash<QString, QString> &data) const;
|
||||
QHash<QString, QString> readGroup(const QJsonObject &rootObj, const QString &field);
|
||||
QByteArray downloadUrl(const QUrl &url, int timeoutMs = 15000);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2463,6 +2463,7 @@ IconsPage::IconsPage
|
||||
trash->setAcceptDrops(true);
|
||||
trash->setPixmap(trashIcon.pixmap(ICONSPAGE_L, QIcon::Normal));
|
||||
trash->installEventFilter(this);
|
||||
QPushButton *downloadButton = new QPushButton(tr("Download Default"));
|
||||
QPushButton *importButton = new QPushButton(tr("Import"));
|
||||
QPushButton *exportButton = new QPushButton(tr("Export"));
|
||||
|
||||
@@ -2473,6 +2474,7 @@ IconsPage::IconsPage
|
||||
QHBoxLayout *actionLayout = new QHBoxLayout();
|
||||
actionLayout->addWidget(trash);
|
||||
actionLayout->addStretch();
|
||||
actionLayout->addWidget(downloadButton);
|
||||
actionLayout->addWidget(importButton);
|
||||
actionLayout->addWidget(exportButton);
|
||||
|
||||
@@ -2480,19 +2482,28 @@ IconsPage::IconsPage
|
||||
mainLayout->addLayout(contentLayout);
|
||||
mainLayout->addLayout(actionLayout);
|
||||
|
||||
connect(importButton, &QPushButton::clicked, [=]() {
|
||||
QString zipFile = QFileDialog::getOpenFileName(this, tr("Import Icons"), "", tr("Zip Files (*.zip)"));
|
||||
if (zipFile.isEmpty() || ! IconManager::instance().importBundle(zipFile)) {
|
||||
QMessageBox::warning(nullptr, tr("Icons Bundle"), tr("Bundle file %1 cannot be imported.").arg(zipFile));
|
||||
} else {
|
||||
connect(downloadButton, &QPushButton::clicked, [=]() {
|
||||
QUrl url(QString("%1/icons.zip").arg(VERSION_CONFIG_PREFIX));
|
||||
if (IconManager::instance().importBundle(url)) {
|
||||
initSportTree();
|
||||
updateIconList();
|
||||
} else {
|
||||
QMessageBox::warning(nullptr, tr("Icon Bundle"), tr("Bundle file %1 cannot be imported.").arg(url.toString()));
|
||||
}
|
||||
});
|
||||
connect(importButton, &QPushButton::clicked, [=]() {
|
||||
QString zipFile = QFileDialog::getOpenFileName(this, tr("Import Icons"), "", tr("Zip Files (*.zip)"));
|
||||
if (! zipFile.isEmpty() && IconManager::instance().importBundle(zipFile)) {
|
||||
initSportTree();
|
||||
updateIconList();
|
||||
} else {
|
||||
QMessageBox::warning(nullptr, tr("Icon Bundle"), tr("Bundle file %1 cannot be imported.").arg(zipFile));
|
||||
}
|
||||
});
|
||||
connect(exportButton, &QPushButton::clicked, [=]() {
|
||||
QString zipFile = QFileDialog::getSaveFileName(this, tr("Export Icons"), "", tr("Zip Files (*.zip)"));
|
||||
if (zipFile.isEmpty() || ! IconManager::instance().exportBundle(zipFile)) {
|
||||
QMessageBox::warning(nullptr, tr("Icons Bundle"), tr("Bundle file %1 cannot be created.").arg(zipFile));
|
||||
QMessageBox::warning(nullptr, tr("Icon Bundle"), tr("Bundle file %1 cannot be created.").arg(zipFile));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -2894,6 +2905,9 @@ IconsPage::initSportTree
|
||||
}
|
||||
}
|
||||
}
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
sportTree->viewport()->update();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user