Refactor firmware and companion updates plus add extra supporting components

This commit is contained in:
elecpower
2022-09-06 09:29:41 +10:00
committed by Peter Feerick
parent b4e1ceb4f8
commit bbfaf86bc8
70 changed files with 5526 additions and 1310 deletions
+39
View File
@@ -0,0 +1,39 @@
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
set(updates_NAMES
updates
updatesdialog
updateoptionsdialog
repomodels
updateinterface
updatefirmware
updatecompanion
updatesdcard
updatesounds
updatethemes
updatemultiprotocol
)
foreach(name ${updates_NAMES})
set(updates_SRCS ${updates_SRCS} ${name}.cpp)
set(updates_HDRS ${updates_HDRS} ${name}.h)
endforeach()
set(updates_UIS
updatesdialog.ui
updateoptionsdialog.ui
)
set(updates_QTS
updates.h
updatesdialog.h
updateoptionsdialog.h
repomodels.h
updateinterface.h
)
qt5_wrap_ui(updates_SRCS ${updates_UIS})
qt5_wrap_cpp(updates_SRCS ${updates_QTS})
add_library(updates ${updates_SRCS} ${updates_HDRS})
target_link_libraries(updates PRIVATE ${CPN_COMMON_LIB})
+129
View File
@@ -0,0 +1,129 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "downloaddialog.h"
#include "ui_downloaddialog.h"
#include "constants.h"
#include "helpers.h"
#include <QTime>
DownloadDialog::DownloadDialog(QWidget *parent, QString src, QString tgt, QString contentType, QString title):
QDialog(parent),
ui(new Ui::DownloadDialog),
reply(nullptr),
file(nullptr),
aborted(false)
{
ui->setupUi(this);
setWindowIcon(CompanionIcon("download.png"));
ui->progressBar->setValue(0);
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(100);
if (tgt.isEmpty()) {
setWindowTitle(src);
return; // just show wait dialog.
}
setWindowTitle(windowTitle() % title);
file = new QFile(tgt);
if (!file->open(QIODevice::WriteOnly)) {
QMessageBox::critical(this, CPN_STR_APP_NAME, tr("Unable to open the download file %1 for writing.\nError: %2").arg(tgt).arg(file->errorString()));
QTimer::singleShot(0, this, SLOT(fileError()));
}
else {
url.setUrl(src);
qDebug() << "url:" << url.url();
request.setUrl(url);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork);
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
request.setRawHeader(QByteArray("Accept"), contentType.toUtf8());
reply = qnam.get(request);
connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));
connect(reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateDataReadProgress(qint64, qint64)));
}
}
DownloadDialog::~DownloadDialog()
{
delete ui;
delete file;
}
void DownloadDialog::reject()
{
if (reply && reply->isRunning()) {
aborted = true;
reply->abort(); // this will call QNetworkReply::finished()
return;
}
QDialog::reject();
}
void DownloadDialog::httpFinished()
{
file->flush();
file->close();
const bool ok = !(reply->error() || aborted);
if (!ok) {
file->remove();
if (!aborted)
QMessageBox::information(this, CPN_STR_APP_NAME, tr("Download failed: %1.").arg(reply->errorString()));
}
reply->deleteLater();
reply = nullptr;
file->deleteLater();
file = nullptr;
if (ok)
accept();
else
reject();
}
void DownloadDialog::httpReadyRead()
{
if (file) {
file->write(reply->readAll());
}
}
void DownloadDialog::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes)
{
ui->progressBar->setMaximum(totalBytes);
ui->progressBar->setValue(bytesRead);
}
void DownloadDialog::fileError()
{
delete file;
file = nullptr;
reject();
}
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <QtWidgets>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QFile>
namespace Ui {
class DownloadDialog;
}
class DownloadDialog : public QDialog
{
Q_OBJECT
public:
explicit DownloadDialog(QWidget *parent = 0, QString src = "", QString tgt = "", QString contentType = "", QString title = "");
~DownloadDialog();
public slots:
virtual void reject() override;
private slots:
void fileError();
void httpFinished();
void httpReadyRead();
void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
private:
Ui::DownloadDialog *ui;
QNetworkAccessManager qnam;
QNetworkReply *reply;
QFile *file;
bool aborted;
QNetworkRequest request;
QUrl url;
};
+86
View File
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DownloadDialog</class>
<widget class="QDialog" name="DownloadDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>562</width>
<height>82</height>
</rect>
</property>
<property name="windowTitle">
<string>Downloading: </string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</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>
</layout>
</widget>
<resources>
<include location="companion.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DownloadDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DownloadDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+456
View File
@@ -0,0 +1,456 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "repomodels.h"
#include "appdata.h"
#include <QStandardItem>
#include <QJsonDocument>
QString metaDataTypeToString(MetaDataType val)
{
switch ((int)val) {
case MDT_Release:
return "Release";
case MDT_Releases:
return "Releases";
case MDT_Asset:
return "Asset";
case MDT_ReleaseAssets:
return "Release Assets";
default:
return CPN_STR_UNKNOWN_ITEM;
}
}
/*
ReleasesItemModel
*/
ReleasesItemModel::ReleasesItemModel() :
UpdatesItemModel("Releases"),
m_settingsIdx(-1),
m_nightlyName(""),
m_releaseChannel(-1)
{
setSortRole(UpdatesItemModel::IMDR_Date);
}
bool ReleasesItemModel::releaseChannelChanged()
{
if (m_settingsIdx > -1 && m_releaseChannel != (int)g.component[m_settingsIdx].releaseChannel())
return true;
else
return false;
}
void ReleasesItemModel::parseMetaData(const int mdt, QJsonDocument * jsonDoc)
{
json = jsonDoc;
if (m_settingsIdx > -1)
m_releaseChannel = g.component[m_settingsIdx].releaseChannel();
switch (mdt) {
case MDT_Release:
parseRelease();
break;
case MDT_Releases:
parseReleases();
break;
}
}
void ReleasesItemModel::parseRelease()
{
clear();
if (json->isObject()) {
const QJsonObject &obj = json->object();
parseJsonObject(obj);
}
}
void ReleasesItemModel::parseReleases()
{
clear();
if (json->isArray()) {
const QJsonArray &array = json->array();
foreach (const QJsonValue &v, array)
{
if (v.isObject()) {
const QJsonObject &obj = v.toObject();
parseJsonObject(obj);
}
}
}
sort(0, Qt::DescendingOrder);
}
void ReleasesItemModel::parseJsonObject(const QJsonObject & obj)
{
QStandardItem * item = new QStandardItem();
QString tag = QString();
bool prerelease = false;
if (!obj.value("name").isUndefined()) {
item->setText(obj.value("name").toString());
}
if (!obj.value("id").isUndefined()) {
item->setData(obj.value("id").toInt(), UpdatesItemModel::IMDR_Id);
}
if (!obj.value("tag_name").isUndefined()) {
tag = obj.value("tag_name").toString();
item->setData(tag, UpdatesItemModel::IMDR_Tag);
}
if (!obj.value("prerelease").isUndefined()) {
prerelease = obj.value("prerelease").toBool();
item->setData(prerelease, UpdatesItemModel::IMDR_Prerelease);
}
if (!obj.value("created_at").isUndefined()) {
item->setData(QDateTime::fromString(obj.value("created_at").toString(), Qt::ISODate), UpdatesItemModel::IMDR_Date);
}
item->setData(isReleaseAvailable(tag, prerelease), UpdatesItemModel::IMDR_Available);
appendRow(item);
}
bool ReleasesItemModel::isReleaseAvailable(const QString tagname, const bool prerelease)
{
if (prerelease) {
if (m_releaseChannel == ComponentData::RELEASE_CHANNEL_STABLE) {
//qDebug() << "Release channel stable" << tagname << "is pre-release" ;
return false;
}
else if (m_releaseChannel == ComponentData::RELEASE_CHANNEL_PRERELEASE && tagname.toLower() == m_nightlyName) {
//qDebug() << "Release channel pre-release" << tagname << "is nightly" ;
return false;
}
}
//qDebug() << "Release available:" << tagname;
return true;
}
/*
AssetsItemModel
*/
AssetsItemModel::AssetsItemModel() :
UpdatesItemModel("Assets")
{
}
void AssetsItemModel::parseMetaData(int mdt, QJsonDocument * jsonDoc)
{
json = jsonDoc;
switch (mdt) {
case MDT_Asset:
parseAsset();
break;
case MDT_ReleaseAssets:
parseReleaseAssets();
break;
}
}
void AssetsItemModel::parseAsset()
{
clear();
if (json->isObject()) {
const QJsonObject &obj = json->object();
parseJsonObject(obj);
}
}
void AssetsItemModel::parseReleaseAssets()
{
clear();
if (json->isArray()) {
const QJsonArray &array = json->array();
foreach (const QJsonValue &v, array)
{
if (v.isObject()) {
const QJsonObject &obj = v.toObject();
parseJsonObject(obj);
}
}
}
sort(0);
}
void AssetsItemModel::parseJsonObject(const QJsonObject & obj)
{
QStandardItem * item = new QStandardItem();
if (!obj.value("name").isUndefined()) {
item->setText(obj.value("name").toString());
}
if (!obj.value("id").isUndefined()) {
item->setData(obj.value("id").toInt(), UpdatesItemModel::IMDR_Id);
}
if (!obj.value("content_type").isUndefined()) {
item->setData(obj.value("content_type").toString(), UpdatesItemModel::IMDR_Content);
}
if (!obj.value("updated_at").isUndefined()) {
item->setData(QDateTime::fromString(obj.value("updated_at").toString(), Qt::ISODate), UpdatesItemModel::IMDR_Date);
}
item->setData(true, UpdatesItemModel::IMDR_Available);
appendRow(item);
}
/*
UpdatesFilteredItemModel
*/
UpdatesFilteredItemModel::UpdatesFilteredItemModel(UpdatesItemModel * sourceModel, QString name) :
QSortFilterProxyModel(nullptr),
filterFlags(0),
m_name(name)
{
filterText.setPattern("");
filterText.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
setFilterRole(UpdatesItemModel::IMDR_Available);
setFilterKeyColumn(0);
setDynamicSortFilter(true);
setSourceModel(sourceModel);
}
void UpdatesFilteredItemModel::setFilterFlags(const int flags)
{
if (filterFlags != flags) {
filterFlags = flags;
filterText.setPattern("");
invalidateFilter();
}
}
void UpdatesFilteredItemModel::setFilterPattern(const QString & pattern)
{
if (filterText.pattern() != pattern) {
filterText.setPattern(pattern);
filterFlags = 0;
invalidateFilter();
}
}
bool UpdatesFilteredItemModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
{
const QModelIndex & srcIdx = sourceModel()->index(sourceRow, 0, sourceParent);
if (!srcIdx.isValid() || !sourceModel()->data(srcIdx, filterRole()).toBool())
return false;
if (!filterFlags && filterText.pattern().isEmpty())
return true;
if (filterFlags) {
bool ok;
const int flags = sourceModel()->data(srcIdx, UpdatesItemModel::IMDR_Flags).toInt(&ok);
return (ok && (!flags || (filterFlags & flags)));
}
else {
return sourceModel()->data(srcIdx, Qt::DisplayRole).toString().contains(filterText);
}
}
void UpdatesFilteredItemModel::dumpContents()
{
qDebug() << "Contents of" << m_name;
for (int i = 0; i < rowCount(); ++i) {
qDebug() << "row:" << i
<< "text:" << data(index(i, 0), Qt::DisplayRole).toString()
<< "id:" << data(index(i, 0), UpdatesItemModel::IMDR_Id).toInt()
<< "date:" << data(index(i, 0), UpdatesItemModel::IMDR_Date).toDateTime()
<< "tag:" << data(index(i, 0), UpdatesItemModel::IMDR_Tag).toString()
<< "avail:" << data(index(i, 0), UpdatesItemModel::IMDR_Available).toBool()
<< "flags:" << data(index(i, 0), UpdatesItemModel::IMDR_Flags).toInt()
<< "content:" << data(index(i, 0), UpdatesItemModel::IMDR_Content).toString()
<< "prerelease:" << data(index(i, 0), UpdatesItemModel::IMDR_Prerelease).toBool();
}
}
QMap<int, QVariant> UpdatesFilteredItemModel::itemMetaData(const int id)
{
const QModelIndexList idxlst = match(index(0, 0), UpdatesItemModel::IMDR_Id, QVariant(id), 1, Qt::MatchExactly);
if (!idxlst.isEmpty())
return itemData(idxlst.at(0));
return QMap<int, QVariant>();
}
QVariant UpdatesFilteredItemModel::metaDataValue(const int id, const int role)
{
//qDebug() << "id:" << id << "role:";
const QModelIndexList idxlst = match(index(0, 0), UpdatesItemModel::IMDR_Id, QVariant(id), 1, Qt::MatchExactly);
if (!idxlst.isEmpty())
return data(idxlst.at(0), role);
return QVariant();
}
bool UpdatesFilteredItemModel::setMetaDataValue(const int id, const int role, const QVariant value)
{
//qDebug() << "id:" << id << "role:" << role << "value:" << value;
const QModelIndexList idxlst = match(index(0, 0), UpdatesItemModel::IMDR_Id, QVariant(id), 1, Qt::MatchExactly);
if (!idxlst.isEmpty())
return setData(idxlst.at(0), value, role);
return false;
}
int UpdatesFilteredItemModel::id(const int row)
{
const QModelIndex & idx = index(row, 0);
if (!idx.isValid())
return 0;
bool ok;
const int id = data(idx, UpdatesItemModel::IMDR_Id).toInt(&ok);
if (ok)
return id;
return 0;
}
int UpdatesFilteredItemModel::id(const QVariant value, const Qt::MatchFlags flags, const int role)
{
const QModelIndexList idxlst = match(index(0, 0), role, value, 1, flags);
if (!idxlst.isEmpty()) {
bool ok;
const int id = data(idxlst.at(0), UpdatesItemModel::IMDR_Id).toInt(&ok);
if (ok)
return id;
}
return 0;
}
QStringList UpdatesFilteredItemModel::list()
{
QStringList strl;
for (int i = 0; i < rowCount(); i++)
strl << data(index(i, 0)).toString();
return strl;
}
/*
ReleasesFilteredItemModel
*/
ReleasesFilteredItemModel::ReleasesFilteredItemModel(UpdatesItemModel * sourceModel) :
UpdatesFilteredItemModel(sourceModel, "Filtered Releases")
{
setSortRole(UpdatesItemModel::IMDR_Date);
}
int ReleasesFilteredItemModel::channelLatestId()
{
return rows() > 0 ? id(0) : 0; // assumes model sorted descending date
}
/*
AssetsFilteredItemModel
*/
AssetsFilteredItemModel::AssetsFilteredItemModel(UpdatesItemModel * sourceModel) :
UpdatesFilteredItemModel(sourceModel, "Filtered Assets")
{
}
bool AssetsFilteredItemModel::setFlags(const int id, const int flags)
{
return setMetaDataValue(id, UpdatesItemModel::IMDR_Flags, QVariant(flags));
}
bool AssetsFilteredItemModel::setSubDirectory(const int id, const QString path)
{
return setMetaDataValue(id, UpdatesItemModel::IMDR_SubDirectory, QVariant(path));
}
bool AssetsFilteredItemModel::setCopyFilter(const int id, const QString filter)
{
return setMetaDataValue(id, UpdatesItemModel::IMDR_CopyFilter, QVariant(filter));
}
/*
ReleasesMetaData
*/
ReleasesMetaData::ReleasesMetaData(QWidget * parent) :
QWidget(parent),
m_repo(""),
m_id(0)
{
itemModel = new ReleasesItemModel();
filteredItemModel = new ReleasesFilteredItemModel(itemModel);
}
bool ReleasesMetaData::refreshRequired()
{
if (m_id != 0)
return itemModel->releaseChannelChanged();
return true;
}
/*
AssetsMetaData
*/
AssetsMetaData::AssetsMetaData(QWidget * parent) :
QWidget(parent)
{
itemModel = new AssetsItemModel();
filteredItemModel = new AssetsFilteredItemModel(itemModel);
}
+300
View File
@@ -0,0 +1,300 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <QtCore>
#include <QWidget>
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
constexpr char GITHUB_API_REPOS[] {"https://api.github.com/repos"};
constexpr char GH_REPOS_EDGETX[] {"https://api.github.com/repos/EdgeTX"};
constexpr char GH_ACCEPT_HEADER_BINARY[] {"application/octet-stream"};
constexpr char GH_ACCEPT_HEADER_METADATA[] {"application/vnd.github.v3+json"};
constexpr char GH_ACCEPT_HEADER_RAW[] {"application/vnd.github.v3.raw"};
enum MetaDataType {
MDT_Release,
MDT_Releases,
MDT_Asset,
MDT_ReleaseAssets
};
QString metaDataTypeToString(MetaDataType val);
class UpdatesItemModel : public QStandardItemModel
{
Q_OBJECT
public:
enum ItemModelDataRoles {
IMDR_Id = Qt::UserRole,
IMDR_Date,
IMDR_Tag,
IMDR_Prerelease,
IMDR_Content,
IMDR_Available,
IMDR_Flags,
IMDR_CopyFilter,
IMDR_SubDirectory
};
Q_ENUM(ItemModelDataRoles)
explicit UpdatesItemModel(QString name = "") :
QStandardItemModel(nullptr),
json(nullptr),
m_name(name) {}
virtual ~UpdatesItemModel() {}
protected:
QJsonDocument * json;
private:
QString m_name;
};
class ReleasesItemModel : public UpdatesItemModel
{
Q_OBJECT
friend class ReleasesMetaData;
public:
explicit ReleasesItemModel();
virtual ~ReleasesItemModel() {}
void setNightlyName(const QString name) { m_nightlyName = name.toLower(); }
void setSettingsIndex(const int index) { m_settingsIdx = index; }
void parseMetaData(const int mdt, QJsonDocument * json);
int settingsIndex() { return m_settingsIdx; }
bool releaseChannelChanged();
private:
int m_settingsIdx;
QString m_nightlyName;
int m_releaseChannel;
bool isReleaseAvailable(const QString tagname, const bool prerelease);
void parseRelease();
void parseReleases();
void parseJsonObject(const QJsonObject & obj);
};
class AssetsItemModel : public UpdatesItemModel
{
Q_OBJECT
friend class AssetsMetaData;
public:
explicit AssetsItemModel();
virtual ~AssetsItemModel() {}
void parseMetaData(int mdt, QJsonDocument * json);
private:
void parseAsset();
void parseReleaseAssets();
void parseJsonObject(const QJsonObject & obj);
};
class UpdatesFilteredItemModel: public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit UpdatesFilteredItemModel(UpdatesItemModel * sourceModel, QString name = "");
virtual ~UpdatesFilteredItemModel() {};
void dumpContents();
QStringList list();
int id(const int row);
int id(const QVariant value, const Qt::MatchFlags flags = Qt::MatchExactly, const int role = Qt::DisplayRole);
int rows() { return rowCount(); }
QString date(const int id) { return metaDataValue(id, UpdatesItemModel::IMDR_Date).toString(); }
QString name(const int id) { return metaDataValue(id, Qt::DisplayRole).toString(); }
public slots:
void setFilterFlags(const int flags);
void setFilterPattern(const QString & pattern);
signals:
protected:
int filterFlags;
QRegularExpression filterText;
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
QMap<int, QVariant> itemMetaData(int id);
QVariant metaDataValue(const int id, const int role);
bool setMetaDataValue(const int id, const int role, const QVariant value);
private:
QString m_name;
};
class ReleasesFilteredItemModel: public UpdatesFilteredItemModel
{
Q_OBJECT
public:
protected:
friend class ReleasesMetaData;
explicit ReleasesFilteredItemModel(UpdatesItemModel * sourceModel);
virtual ~ReleasesFilteredItemModel() {};
int channelLatestId();
bool prerelease(const int id) { return metaDataValue(id, UpdatesItemModel::IMDR_Prerelease).toBool(); }
QString version(const int id) { return metaDataValue(id, UpdatesItemModel::IMDR_Tag).toString(); }
private:
};
class AssetsFilteredItemModel : public UpdatesFilteredItemModel
{
Q_OBJECT
public:
protected:
friend class AssetsMetaData;
explicit AssetsFilteredItemModel(UpdatesItemModel * sourceModel);
virtual ~AssetsFilteredItemModel() {};
bool setFlags(const int id, const int flags);
bool setSubDirectory(const int id, const QString path);
bool setCopyFilter(const int id, const QString filter);
QString filename(int id) { return metaDataValue(id, Qt::DisplayRole).toString(); }
private:
};
class ReleasesMetaData : public QWidget
{
Q_OBJECT
public:
explicit ReleasesMetaData(QWidget * parent);
virtual ~ReleasesMetaData() {};
bool refreshRequired();
void setRepo(QString repo) { m_repo = repo; }
void setNightlyName(QString name) { itemModel->setNightlyName(name); }
void setSettingsIndex(int index) { itemModel->setSettingsIndex(index); }
void setId(int id) { m_id = id; }
int id() { return m_id; }
int getSetId() { m_id = filteredItemModel->channelLatestId(); return m_id; }
int getSetId(int row) { m_id = filteredItemModel->id(row); return m_id; }
int getSetId(QVariant value, Qt::MatchFlags flags = Qt::MatchExactly, int role = Qt::DisplayRole)
{ m_id = filteredItemModel->id(value, flags, role); return m_id; }
void parseMetaData(int mdt, QJsonDocument * jsonDoc)
{ itemModel->parseMetaData(mdt, jsonDoc); }
int count() { return filteredItemModel->rows(); }
QStringList list() { return filteredItemModel->list(); }
void dumpContentsFiltered() { filteredItemModel->dumpContents(); }
QString date() { return filteredItemModel->date(m_id); }
QString name() { return filteredItemModel->name(m_id); }
bool prerelease() { return filteredItemModel->prerelease(m_id); }
QString version() { return filteredItemModel->version(m_id); }
QString urlReleases() { return m_repo % "/releases"; }
QString urlReleaseLatest() { return urlReleases() % "/latest"; }
QString urlRelease() { return urlReleases() % QString("/%1").arg(m_id); }
private:
ReleasesItemModel *itemModel;
ReleasesFilteredItemModel *filteredItemModel;
QString m_repo;
int m_id;
};
class AssetsMetaData : public QWidget
{
Q_OBJECT
public:
explicit AssetsMetaData(QWidget * parent);
virtual ~AssetsMetaData() {};
void setRepo(QString repo) { m_repo = repo; }
void setId(int id) { m_id = id; }
int id() { return m_id; }
int getSetId(int row) { m_id = filteredItemModel->id(row); return m_id; }
int getSetId(QVariant value, Qt::MatchFlags flags = Qt::MatchExactly, int role = Qt::DisplayRole)
{ m_id = filteredItemModel->id(value, flags, role); return m_id; }
void parseMetaData(int mdt, QJsonDocument * jsonDoc) { itemModel->parseMetaData(mdt, jsonDoc); }
bool setFlags(int flags) { return filteredItemModel->setFlags(m_id, flags); }
void setFilterFlags(int flags) { filteredItemModel->setFilterFlags(flags); }
void setFilterPattern(const QString & pattern) { filteredItemModel->setFilterPattern(pattern); }
bool setSubDirectory(const QString path) { return filteredItemModel->setSubDirectory(m_id, path); }
bool setCopyFilter(const QString filter) { return filteredItemModel->setCopyFilter(m_id, filter); }
int count() { return filteredItemModel->rows(); }
QStringList list() { return filteredItemModel->list(); }
void dumpContentsFiltered() { filteredItemModel->dumpContents(); }
QString date() { return filteredItemModel->date(m_id); }
QString name() { return filteredItemModel->name(m_id); }
QString filename() { return filteredItemModel->metaDataValue(m_id, Qt::DisplayRole).toString(); }
QString contentType() { return filteredItemModel->metaDataValue(m_id, UpdatesItemModel::IMDR_Content).toString(); }
QString subDirectory() { return filteredItemModel->metaDataValue(m_id, UpdatesItemModel::IMDR_SubDirectory).toString(); }
QString copyFilter() { return filteredItemModel->metaDataValue(m_id, UpdatesItemModel::IMDR_CopyFilter).toString(); }
int flags() { return filteredItemModel->metaDataValue(m_id, UpdatesItemModel::IMDR_Flags).toInt(); }
QString urlReleaseAssets(int releaseId, int max)
{ return urlReleases() % QString("/%1/assets").arg(releaseId) % (max > -1 ? QString("\?per_page=%1").arg(max) : ""); }
QString urlAsset() { return urlReleases() % QString("/assets/%1").arg(m_id); }
QString urlContent(QString path) { return m_repo % QString("/contents/%1").arg(path); }
private:
AssetsItemModel *itemModel;
AssetsFilteredItemModel *filteredItemModel;
QString m_repo;
int m_id;
QString urlReleases() { return m_repo % "/releases"; }
};
+143
View File
@@ -0,0 +1,143 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "updatecompanion.h"
#include "constants.h"
#include "version.h"
#include <QMessageBox>
#include <QDesktopServices>
#include <QDirIterator>
#ifdef Q_OS_MACOS
#define
#define OS_FILEPATTERN "edgetx-cpn-osx"
#define OS_INSTALLER_EXTN "*.dmg"
#define OS_INSTALL_QUESTION tr("Would you like to open the disk image to install the new version?")
#elif defined(Q_OS_WIN64)
#define OS_FILEPATTERN "edgetx-cpn-win64"
#define OS_INSTALLER_EXTN "*.exe"
#define OS_INSTALL_QUESTION tr("Would you like to launch the installer?")
#elif defined(Q_OS_WIN32)
#define OS_FILEPATTERN "edgetx-cpn-win32"
#define OS_INSTALLER_EXTN "*.exe"
#define OS_INSTALL_QUESTION tr("Would you like to launch the installer?")
#else
#define OS_FILEPATTERN "edgetx-cpn-linux"
#define OS_INSTALLER_EXTN "*.AppImage"
#define OS_INSTALL_QUESTION tr("Would you like to open the app image to install the new version?")
#endif
UpdateCompanion::UpdateCompanion(QWidget * parent) :
UpdateInterface(parent)
{
setName("Companion");
setRepo(QString(GH_REPOS_EDGETX).append("/edgetx"));
setReleasesNightlyName("nightly");
dfltParams->data.flags = (UPDFLG_Common | UPDFLG_Locked | UPDFLG_AsyncInstall) & ~UPDFLG_CopyDest;
UpdateParameters::AssetParams &ap = dfltParams->addAsset();
ap.filterType = UpdateParameters::UFT_Startswith;
ap.filter = QString("%1").arg(QString(OS_FILEPATTERN));
ap.maxExpected = 1;
ap.flags = dfltParams->data.flags;
}
bool UpdateCompanion::asyncInstall()
{
progressMessage(tr("Async install"));
assets->setFilterFlags(UPDFLG_AsyncInstall);
reportProgress(tr("Asset filter applied: %1 Assets found: %2").arg(updateFlagsToString(UPDFLG_AsyncInstall)).arg(assets->count()), QtDebugMsg);
if (assets->count() != 1) {
reportProgress(tr("Expected 1 asset for install but none found"), QtCriticalMsg);
return false;
}
assets->getSetId(0);
QString installerPath = decompressDir % QString("/A%1/%2").arg(assets->id()).arg(QFileInfo(assets->filename()).completeBaseName());
QDirIterator it(installerPath, { OS_INSTALLER_EXTN }, QDir::Files, QDirIterator::Subdirectories);
bool found = false;
while (it.hasNext())
{
installerPath = it.next();
found = true;
break;
}
if (!found) {
reportProgress(tr("Installer not found in %1 using filter %2").arg(installerPath).arg(OS_INSTALLER_EXTN), QtCriticalMsg);
return false;
}
int ret = QMessageBox::question(parentWidget(), CPN_STR_APP_NAME, OS_INSTALL_QUESTION, QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::Yes) {
if (QDesktopServices::openUrl(QUrl::fromLocalFile(installerPath)))
qApp->exit();
}
return true;
}
const QString UpdateCompanion::currentRelease()
{
#if defined(VERSION_TAG)
return UpdateInterface::latestRelease();
#else
dfltParams->data.currentRelease = QString("EdgeTX v%1.%2 (Custom)").arg(VERSION_MAJOR).arg(VERSION_MINOR);
runParams->data.currentRelease = dfltParams->data.currentRelease;
return dfltParams->data.currentRelease;
#endif
}
const QString UpdateCompanion::currentVersion()
{
#if defined(VERSION_TAG)
return UpdateInterface::latestRelease();
#else
return QString(QString("v%1.%2").arg(VERSION_MAJOR).arg(VERSION_MINOR));
#endif
}
const bool UpdateCompanion::isLatestRelease()
{
#if defined(VERSION_TAG)
return UpdateInterface::isLatestRelease();
#else
return true;
#endif
}
const bool UpdateCompanion::isUpdateAvailable()
{
#if defined(VERSION_TAG)
return UpdateInterface::isUpdateAvailable();
#else
return false;
#endif
}
+41
View File
@@ -0,0 +1,41 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "updateinterface.h"
class UpdateCompanion : public UpdateInterface
{
Q_DECLARE_TR_FUNCTIONS(UpdateCompanion)
public:
explicit UpdateCompanion(QWidget * parent);
virtual ~UpdateCompanion() {}
protected:
virtual bool asyncInstall() override;
virtual const QString currentRelease();
virtual const QString currentVersion();
virtual const bool isLatestRelease();
virtual const bool isUpdateAvailable();
};
+99
View File
@@ -0,0 +1,99 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "updatefirmware.h"
#include "appdata.h"
#include "flashfirmwaredialog.h"
UpdateFirmware::UpdateFirmware(QWidget * parent) :
UpdateInterface(parent)
{
setName("Firmware");
setRepo(QString(GH_REPOS_EDGETX).append("/edgetx"));
setReleasesNightlyName("nightly");
dfltParams->data.flags = UPDFLG_Common | UPDFLG_Locked | UPDFLG_AsyncInstall;
UpdateParameters::AssetParams &ap = dfltParams->addAsset();
ap.filterType = UpdateParameters::UFT_Startswith;
ap.filter = "edgetx-firmware";
ap.maxExpected = 1;
ap.flags = dfltParams->data.flags | UPDFLG_CopyFiles;
ap.destSubDir = "FIRMWARE";
ap.copyFilterType = UpdateParameters::UFT_Expression;
ap.copyFilter = QString("^%1-.*\\.bin$").arg(fwFlavour);
}
bool UpdateFirmware::asyncInstall()
{
progressMessage(tr("Async install"));
assets->setFilterFlags(UPDFLG_AsyncInstall);
reportProgress(tr("Asset filter applied: %1 Assets found: %2").arg(updateFlagsToString(UPDFLG_AsyncInstall)).arg(assets->count()), QtDebugMsg);
if (assets->count() != 1) {
reportProgress(tr("Expected 1 asset for install but none found"), QtCriticalMsg);
return false;
}
QString destPath = updateDir;
if (!assets->subDirectory().isEmpty())
destPath.append("/" % assets->subDirectory());
QRegularExpression filter(runParams->data.assets.at(0).copyFilter, QRegularExpression::CaseInsensitiveOption);
QDirIterator it(destPath);
bool found = false;
while (it.hasNext())
{
QFileInfo file(it.next());
if ((!filter.pattern().isEmpty()) && (!file.fileName().contains(filter)))
continue;
destPath.append("/" % file.fileName());
found = true;
break;
}
if (!found) {
reportProgress(tr("Firmware not found in %1 using filter %2").arg(destPath).arg(filter.pattern()), QtCriticalMsg);
return false;
}
g.currentProfile().fwName(destPath);
reportProgress(tr("Write firmware to radio option setting: %1").arg(g.currentProfile().burnFirmware() ? tr("true") : tr("false")), QtDebugMsg);
if (g.currentProfile().burnFirmware()) {
int ret = QMessageBox::question(this, CPN_STR_APP_NAME, tr("Do you want to write the firmware to the radio now ?"), QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::Yes) {
FlashFirmwareDialog *dlg = new FlashFirmwareDialog(this);
dlg->exec();
dlg->deleteLater();
}
}
return true;
}
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "updateinterface.h"
class UpdateFirmware : public UpdateInterface
{
Q_DECLARE_TR_FUNCTIONS(UpdateFirmware)
public:
explicit UpdateFirmware(QWidget * parent);
virtual ~UpdateFirmware() {}
protected:
virtual bool asyncInstall() override;
};
File diff suppressed because it is too large Load Diff
+299
View File
@@ -0,0 +1,299 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "repomodels.h"
#include "constants.h"
#include "progresswidget.h"
#include <QtCore>
#include <QWidget>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
class UpdateParameters : public QWidget
{
Q_OBJECT
public:
enum UpdateFilterType {
UFT_None,
UFT_Exact,
UFT_Startswith,
UFT_Endswith,
UFT_Contains,
UFT_Expression,
};
static QStringList updateFilterTypeList();
static QString updateFilterTypeToString(UpdateFilterType uft);
struct AssetParams{
int flags;
UpdateFilterType filterType;
QString filter;
int maxExpected;
QString destSubDir;
UpdateFilterType copyFilterType;
QString copyFilter;
};
struct GeneralParams{
int flags;
QString currentRelease;
QString updateRelease;
QString downloadDir;
bool decompressUseDwnld;
QString decompressDir;
bool updateUseSD;
QString updateDir;
QVector<AssetParams> assets;
};
GeneralParams data;
UpdateParameters(QWidget * parent);
virtual ~UpdateParameters() {}
AssetParams & addAsset();
static QString buildFilterPattern(const UpdateFilterType filterType, const QString & filter);
UpdateParameters& operator=(const UpdateParameters& source);
};
class UpdateInterface : public QWidget
{
Q_OBJECT
public:
enum DownloadDataType {
DDT_Binary,
DDT_Content,
DDT_SaveToFile,
DDT_MetaData,
};
Q_ENUM(DownloadDataType)
enum UpdateFlags {
UPDFLG_None = 0,
UPDFLG_Update = 1 << 1,
UPDFLG_Locked = 1 << 2,
UPDFLG_Preparation = 1 << 3,
UPDFLG_Download = 1 << 4,
UPDFLG_DelDownload = 1 << 5,
UPDFLG_Decompress = 1 << 6,
UPDFLG_DelDecompress = 1 << 7,
UPDFLG_CopyDest = 1 << 8,
UPDFLG_CopyFiles = 1 << 9,
UPDFLG_CopyStructure = 1 << 10,
UPDFLG_Housekeeping = 1 << 11,
UPDFLG_AsyncInstall = 1 << 12,
UPDFLG_Common = UPDFLG_Preparation | UPDFLG_Download | UPDFLG_Decompress | UPDFLG_CopyDest | UPDFLG_Housekeeping,
};
Q_ENUM(UpdateFlags)
explicit UpdateInterface(QWidget * parent);
virtual ~UpdateInterface();
const QString getName() const { return name; }
protected:
friend class UpdateFactories;
ReleasesMetaData *releases;
AssetsMetaData *assets;
UpdateParameters *dfltParams;
UpdateParameters *runParams;
ProgressWidget *progress;
QString name;
int settingsIdx;
int resultsPerPage;
QString downloadDir;
QString decompressDir;
QString updateDir;
QString fwFlavour;
QString language;
int logLevel;
virtual bool update();
virtual bool preparation();
virtual bool flagAssets();
virtual bool download();
virtual bool decompress();
virtual bool copyToDestination();
virtual bool copyAsset();
virtual bool housekeeping();
virtual bool asyncInstall();
void setName(QString name);
void setRepo(QString repo) { releases->setRepo(repo); assets->setRepo(repo); }
void setResultsPerPage(int cnt) { resultsPerPage = cnt; }
void setReleasesNightlyName(QString name) { releases->setNightlyName(name); }
void initParamFolders(UpdateParameters * params);
const UpdateParameters * const getDefaultParams() { return dfltParams; }
UpdateParameters * getRunParams() { return runParams; }
void resetRunParams();
void setRunUpdate() { runParams->data.flags |= UPDFLG_Update; }
const QStringList getReleases();
virtual const bool isUpdateAvailable();
virtual bool autoUpdate(ProgressWidget * progress = nullptr);
virtual bool manualUpdate(ProgressWidget * progress = nullptr);
virtual const QString currentVersion();
void clearRelease();
virtual const QString currentRelease();
virtual const QString updateRelease();
virtual const bool isLatestRelease();
virtual const bool isLatestVersion(const QString & current, const QString & latest);
virtual const QString latestRelease();
void getRadioProfileSettings();
bool repoReleasesMetaData();
bool repoReleaseAssetsMetaData();
bool downloadReleasesMetaData();
bool downloadReleaseLatestMetaData();
bool downloadReleaseMetaData(const int releaseId);
bool downloadReleaseAssetsMetaData(const int releaseId);
bool downloadAssetMetaData(const int assetId);
bool getSetAssets(const int flags, const UpdateParameters::UpdateFilterType assetFilterType, const QString & assetsFilter,
const int maxAssetsExpected, const QString & subDirectory,
const UpdateParameters::UpdateFilterType copyFilterType, const QString & copyFilter);
bool downloadAsset(int row);
bool downloadFlaggedAssets();
bool decompressAsset(int row);
bool decompressFlaggedAssets();
bool copyFlaggedAssets();
bool copyStructure();
bool copyFiles();
bool downloadTextFileToBuffer(const QString & path);
void downloadFileToBuffer(const QString & url);
QByteArray * getDownloadBuffer() { return buffer; }
bool convertDownloadToJson(QJsonDocument * json);
bool decompressArchive(const QString & archivePath, const QString & destPath);
bool saveReleaseSettings();
void reportProgress(const QString & text, const int type = QtInfoMsg);
void progressMessage(const QString & text);
void criticalMsg(const QString & msg);
static QString downloadDataTypeToString(DownloadDataType val);
static QString updateFlagsToString(UpdateFlags val);
private slots:
void onDownloadFinished(QNetworkReply * reply, DownloadDataType ddt, int subtype);
private:
QNetworkAccessManager manager;
QNetworkRequest request;
QNetworkReply *reply;
QByteArray *buffer;
QFile *file;
QUrl url;
bool downloadSuccess;
static QString semanticVersion(QString version);
int getSettingsIdx();
void setSettingsIdx();
bool setRunFolders();
bool checkCreateDirectory(const QString & dirSetting, const UpdateFlags flag);
void downloadMetaData(const MetaDataType mdt, const QString & url);
void download(const DownloadDataType type, const int subtype, const QString & urlStr, const char * header, const QString & filePath);
void downloadBinaryToFile(const QString & url, const QString & filename);
void parseMetaData(int mdt);
};
class UpdateFactoryInterface
{
public:
explicit UpdateFactoryInterface() {}
virtual ~UpdateFactoryInterface() {}
virtual UpdateInterface * instance() = 0;
virtual QString name() = 0;
};
template <class T>
class UpdateFactory : public UpdateFactoryInterface
{
public:
explicit UpdateFactory(QWidget * parent) :
UpdateFactoryInterface(),
m_instance(new T(parent)) {}
virtual ~UpdateFactory() {}
virtual UpdateInterface * instance() { return m_instance; }
virtual QString name() { return m_instance->getName(); }
private:
UpdateInterface *m_instance;
};
class UpdateFactories : public QWidget
{
Q_OBJECT
public:
explicit UpdateFactories(QWidget * parent = nullptr);
virtual ~UpdateFactories();
void registerUpdateFactory(UpdateFactoryInterface * factory);
void registerUpdateFactories();
void unregisterUpdateFactories();
const UpdateParameters * const getDefaultParams(const QString & name);
UpdateParameters * const getRunParams(const QString & name);
void resetRunParams(const QString & name);
void resetAllRunParams();
void setRunUpdate(const QString & name);
const QMap<QString, int> sortedComponentsList();
void clearRelease(const QString & name);
const QString currentRelease(const QString & name);
const QString updateRelease(const QString & name);
const bool isLatestRelease(const QString & name);
const QString latestRelease(const QString & name);
const QStringList releases(const QString & name);
bool autoUpdate(ProgressWidget * progress = nullptr);
bool manualUpdate(ProgressWidget * progress = nullptr);
const bool updatesAvailable();
private:
QVector<UpdateFactoryInterface *> registeredUpdateFactories;
};
@@ -0,0 +1,46 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "updatemultiprotocol.h"
UpdateMultiProtocol::UpdateMultiProtocol(QWidget * parent) :
UpdateInterface(parent)
{
setName("Multiprotocol");
setRepo(QString(GITHUB_API_REPOS).append("/pascallanger/DIY-Multiprotocol-TX-Module"));
setResultsPerPage(50); // GitHub REST API default 30
{
UpdateParameters::AssetParams &ap = dfltParams->addAsset();
ap.filterType = UpdateParameters::UFT_Startswith;
ap.filter = "MultiLuaScripts";
ap.maxExpected = 1;
ap.flags = dfltParams->data.flags | UPDFLG_Locked | UPDFLG_CopyStructure;
}
{
UpdateParameters::AssetParams &ap = dfltParams->addAsset();
ap.filterType = UpdateParameters::UFT_Expression;
ap.filter = "^mm-stm-serial-.*\\.bin$";
ap.flags = (dfltParams->data.flags | UPDFLG_CopyFiles) &~ (UPDFLG_Decompress | UPDFLG_DelDecompress);
ap.destSubDir = "FIRMWARE";
}
}
@@ -0,0 +1,37 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#pragma once
#include "updateinterface.h"
class UpdateMultiProtocol : public UpdateInterface
{
Q_DECLARE_TR_FUNCTIONS(UpdateMultiProtocol)
public:
explicit UpdateMultiProtocol(QWidget * parent);
virtual ~UpdateMultiProtocol() {}
};
@@ -0,0 +1,259 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "updateoptionsdialog.h"
#include "ui_updateoptionsdialog.h"
#include "appdata.h"
#include <QAbstractButton>
#include <QStandardItemModel>
#include <QMessageBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTimer>
UpdateOptionsDialog::UpdateOptionsDialog(QWidget * parent, UpdateFactories * factories, const int idx) :
QDialog(parent),
ui(new Ui::UpdateOptionsDialog),
factories(factories),
idx(idx),
name(g.component[idx].name()),
dfltParams(factories->getDefaultParams(name)),
runParams(factories->getRunParams(name))
{
ui->setupUi(this);
setWindowTitle(tr("%1 %2").arg(name).arg(tr("Options")));
ui->leCurrent->setText(dfltParams->data.currentRelease);
connect(ui->btnForget, &QPushButton::clicked, [=]() {
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear current release information.\nWarning: There is no undo! Are you sure?"),
QMessageBox::Yes |QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) {
factories->clearRelease(name);
ui->leCurrent->setText(dfltParams->data.currentRelease);
emit changed(idx);
}
});
ui->cboReleases->addItems(factories->releases(name));
int i = -1;
QVBoxLayout *grpAssetsLayout = new QVBoxLayout();
foreach (const UpdateParameters::AssetParams &ap, dfltParams->data.assets) {
int flags = ap.flags;
const bool locked = flags & UpdateInterface::UPDFLG_Locked;
i++;
QHBoxLayout *layout1 = new QHBoxLayout();
if (i > 0) {
QFrame *line = new QFrame(this);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
line->setLineWidth(1);
line->setMidLineWidth(0);
grpAssetsLayout->addWidget(line);
}
QLabel *aflbl = new QLabel(tr("Filter"));
layout1->addWidget(aflbl);
QComboBox *cboAssetFilterType = new QComboBox();
cboAssetFilterType->setEnabled(!locked);
cboAssetFilterType->addItems(UpdateParameters::updateFilterTypeList());
cboAssetFilterTypes << cboAssetFilterType;
layout1->addWidget(cboAssetFilterType);
QLineEdit *leAssetFilter = new QLineEdit();
leAssetFilter->setEnabled(!locked);
leAssetFilters << leAssetFilter;
layout1->addWidget(leAssetFilter);
connect(leAssetFilter, &QLineEdit::editingFinished, [=]() {
QRegularExpression re(leAssetFilter->text());
leAssetFilter->setStyleSheet((re.isValid() ? "QLineEdit { color : black; }" : "QLineEdit { color : red; }"));
});
connect(cboAssetFilterType, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](const int index) {
if (index == UpdateParameters::UFT_None) {
leAssetFilter->setEnabled(false);
leAssetFilter->setText("");
}
else
leAssetFilter->setEnabled(!locked);
});
QSpacerItem *hsp1 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
layout1->addItem(hsp1);
grpAssetsLayout->addLayout(layout1);
QHBoxLayout *layout2 = new QHBoxLayout();
QCheckBox *chkDownload = new QCheckBox(tr("Download"));
chkDownloads << chkDownload;
layout2->addWidget(chkDownload);
QCheckBox *chkDecompress = new QCheckBox(tr("Decompress"));
chkDecompress->setEnabled(flags & UpdateInterface::UPDFLG_Decompress);
chkDecompresses << chkDecompress;
layout2->addWidget(chkDecompress);
QCheckBox *chkInstall = new QCheckBox(tr("Install"));
chkInstall->setEnabled(flags & UpdateInterface::UPDFLG_AsyncInstall);
chkInstalls << chkInstall;
layout2->addWidget(chkInstall);
QSpacerItem *hsp2 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
layout2->addItem(hsp2);
grpAssetsLayout->addLayout(layout2);
QGridLayout *layout3 = new QGridLayout();
QCheckBox *chkCopy = new QCheckBox(tr("Copy"));
chkCopy->setEnabled(flags & UpdateInterface::UPDFLG_CopyDest);
chkCopies << chkCopy;
layout3->addWidget(chkCopy, 0, 0);
QLabel *lblCopyFilter = new QLabel(tr("Filter"));
lblCopyFilter->setEnabled(flags & UpdateInterface::UPDFLG_CopyDest);
lblCopyFilters << lblCopyFilter;
layout3->addWidget(lblCopyFilter, 0, 1);
QComboBox *cboCopyFilterType = new QComboBox();
cboCopyFilterType->setEnabled(!locked);
cboCopyFilterType->addItems(UpdateParameters::updateFilterTypeList());
cboCopyFilterTypes << cboCopyFilterType;
layout3->addWidget(cboCopyFilterType, 0, 2);
QLineEdit *leCopyFilter = new QLineEdit();
leCopyFilter->setEnabled(flags & UpdateInterface::UPDFLG_CopyDest && (!locked));
leCopyFilters << leCopyFilter;
layout3->addWidget(leCopyFilter, 0, 3);
connect(leCopyFilter, &QLineEdit::editingFinished, [=]() {
QRegularExpression re(leCopyFilter->text());
leCopyFilter->setStyleSheet((re.isValid() ? "QLineEdit { color : black; }" : "QLineEdit { color : red; }"));
});
connect(cboCopyFilterType, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](const int index) {
if (index == UpdateParameters::UFT_None) {
leCopyFilter->setEnabled(false);
leCopyFilter->setText("");
}
else
leCopyFilter->setEnabled(!locked);
});
QLabel *lblSubFolder = new QLabel(tr("Sub folder"));
lblSubFolder->setEnabled(flags & UpdateInterface::UPDFLG_CopyDest);
lblSubFolders << lblSubFolder;
layout3->addWidget(lblSubFolder, 1, 1);
QLineEdit *leSubFolder = new QLineEdit();
leSubFolder->setEnabled(flags & UpdateInterface::UPDFLG_CopyDest && (!locked));
leSubFolders << leSubFolder;
layout3->addWidget(leSubFolder, 1, 2, 1, 2);
grpAssetsLayout->addLayout(layout3);
}
ui->grpAssets->setLayout(grpAssetsLayout);
connect(ui->buttonBox, &QDialogButtonBox::accepted, [=]() {
QDialog::accept();
});
connect(ui->buttonBox, &QDialogButtonBox::clicked, [=](QAbstractButton * button) {
if (ui->buttonBox->standardButton(button) == QDialogButtonBox::RestoreDefaults) {
factories->resetRunParams(name);
update();
}
else if (ui->buttonBox->standardButton(button) == QDialogButtonBox::Discard) {
QDialog::reject();
}
else if (ui->buttonBox->standardButton(button) == QDialogButtonBox::Save) {
runParams->data.updateRelease = ui->cboReleases->currentText();
for (int i = 0; i < runParams->data.assets.size(); i++) {
UpdateParameters::AssetParams &ap = runParams->data.assets[i];
if (!(ap.flags & UpdateInterface::UPDFLG_Locked)) {
ap.filterType = (UpdateParameters::UpdateFilterType)cboAssetFilterTypes.at(i)->currentIndex();
ap.filter = leAssetFilters.at(i)->text();
ap.copyFilterType = (UpdateParameters::UpdateFilterType)cboCopyFilterTypes.at(i)->currentIndex();
ap.copyFilter = leCopyFilters.at(i)->text();
ap.destSubDir = leSubFolders.at(i)->text();
}
chkDownloads.at(i)->isChecked() ? ap.flags |= UpdateInterface::UPDFLG_Download : ap.flags &= ~UpdateInterface::UPDFLG_Download;
chkDecompresses.at(i)->isChecked() ? ap.flags |= UpdateInterface::UPDFLG_Decompress :ap.flags &= ~UpdateInterface::UPDFLG_Decompress;
chkInstalls.at(i)->isChecked() ? ap.flags |= UpdateInterface::UPDFLG_AsyncInstall : ap.flags &= ~UpdateInterface::UPDFLG_AsyncInstall;
chkCopies.at(i)->isChecked() ? ap.flags |= UpdateInterface::UPDFLG_CopyDest : ap.flags &= ~UpdateInterface::UPDFLG_CopyDest;
ui->chkDelDownload->isChecked() ? ap.flags |= UpdateInterface::UPDFLG_DelDownload : ap.flags &= ~UpdateInterface::UPDFLG_DelDownload;
ui->chkDelDecompress->isChecked() ? ap.flags |= UpdateInterface::UPDFLG_DelDecompress : ap.flags &= ~UpdateInterface::UPDFLG_DelDecompress;
}
emit changed(idx);
}
});
update();
QTimer::singleShot(50, this, [=]() {
adjustSize();
});
}
UpdateOptionsDialog::~UpdateOptionsDialog()
{
delete ui;
}
void UpdateOptionsDialog::update()
{
ui->cboReleases->setCurrentText(runParams->data.updateRelease);
int i = 0;
foreach (const UpdateParameters::AssetParams &ap, runParams->data.assets) {
cboAssetFilterTypes.at(i)->setCurrentIndex((int)ap.filterType);
leAssetFilters.at(i)->setText(ap.filter);
chkDownloads.at(i)->setChecked(ap.flags & UpdateInterface::UPDFLG_Download);
chkDecompresses.at(i)->setChecked(ap.flags & UpdateInterface::UPDFLG_Decompress);
chkInstalls.at(i)->setChecked(ap.flags & UpdateInterface::UPDFLG_AsyncInstall);
chkCopies.at(i)->setChecked(ap.flags & UpdateInterface::UPDFLG_CopyDest);
cboCopyFilterTypes.at(i)->setCurrentIndex((int)ap.copyFilterType);
leCopyFilters.at(i)->setText(ap.copyFilter);
leSubFolders.at(i)->setText(ap.destSubDir);
ui->chkDelDownload->setChecked(ap.flags & UpdateInterface::UPDFLG_DelDownload);
ui->chkDelDecompress->setChecked(ap.flags & UpdateInterface::UPDFLG_DelDecompress);
i++;
}
}
@@ -0,0 +1,72 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "updateinterface.h"
#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QCheckBox>
#include <QComboBox>
#include <QVector>
namespace Ui {
class UpdateOptionsDialog;
}
class QAbstractButton;
class UpdateOptionsDialog : public QDialog
{
Q_OBJECT
public:
UpdateOptionsDialog(QWidget * parent, UpdateFactories * factories, const int idx);
virtual ~UpdateOptionsDialog();
signals:
void changed(int index);
private slots:
void update();
private:
Ui::UpdateOptionsDialog *ui;
const UpdateFactories *factories;
const int idx;
const QString name;
const UpdateParameters *dfltParams;
UpdateParameters *runParams;
QVector<QComboBox *> cboAssetFilterTypes;
QVector<QLineEdit *> leAssetFilters;
QVector<QCheckBox *> chkDownloads;
QVector<QCheckBox *> chkDecompresses;
QVector<QCheckBox *> chkInstalls;
QVector<QCheckBox *> chkCopies;
QVector<QLabel *> lblCopyFilters;
QVector<QComboBox *> cboCopyFilterTypes;
QVector<QLineEdit *> leCopyFilters;
QVector<QLabel *> lblSubFolders;
QVector<QLineEdit *> leSubFolders;
};
@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UpdateOptionsDialog</class>
<widget class="QDialog" name="UpdateOptionsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>677</width>
<height>393</height>
</rect>
</property>
<property name="windowTitle">
<string>Advanced Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="grpRelease">
<property name="title">
<string>Release</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QPushButton" name="btnForget">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Clear the last updated release information</string>
</property>
<property name="text">
<string>Forget</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cboReleases"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblCurrentRelease">
<property name="text">
<string>Current</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblUpdateToRelease">
<property name="text">
<string>Update to</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leCurrent">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="grpAssets">
<property name="title">
<string>Assets</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="grpGeneral">
<property name="title">
<string>General</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="chkDelDownload">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Delete downloads</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkDelDecompress">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Delete decompressions</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>286</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Discard|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
+94
View File
@@ -0,0 +1,94 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "updates.h"
#include "updateinterface.h"
#include "updatesdialog.h"
#include "progressdialog.h"
#include "progresswidget.h"
#include "appdata.h"
#include "helpers.h"
#include <QMessageBox>
Updates::Updates(QWidget * parent, UpdateFactories * updateFactories) :
QWidget(parent),
factories(updateFactories)
{
}
Updates::~Updates()
{
}
void Updates::autoUpdates()
{
if (g.updateCheckFreq() == AppData::UPDATE_CHECK_MANUAL)
return;
if (g.lastUpdateCheck().trimmed().isEmpty())
g.lastUpdateCheck(QDateTime::currentDateTime().addDays(-60).toString(Qt::ISODate));
QDateTime dt = QDateTime::fromString(g.lastUpdateCheck(), Qt::ISODate);
if (g.updateCheckFreq() == AppData::UPDATE_CHECK_DAILY)
dt = dt.addDays(1);
else if (g.updateCheckFreq() == AppData::UPDATE_CHECK_WEEKLY)
dt = dt.addDays(7);
else if (g.updateCheckFreq() == AppData::UPDATE_CHECK_MONTHLY)
dt = dt.addDays(30);
if (dt > QDateTime::currentDateTime().toLocalTime()) {
qDebug() << "Update next due:" << dt.toString(Qt::ISODate);
return;
}
g.lastUpdateCheck(QDateTime::currentDateTime().toString(Qt::ISODate));
if (!factories->updatesAvailable())
return;
if (QMessageBox::question(parentWidget(), CPN_STR_APP_NAME % ": " % tr("Checking for Updates"),
tr("One or more updates are available. Update now?"),
(QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::Yes) {
factories->resetAllRunParams();
factories->autoUpdate();
}
}
void Updates::manualUpdates()
{
factories->resetAllRunParams();
UpdatesDialog *dlg = new UpdatesDialog(this, factories);
if (dlg->exec()) {
ProgressDialog progressDialog(this, tr("Update Components"), CompanionIcon("fuses.png"), true);
progressDialog.progress()->lock(true);
progressDialog.progress()->setInfo(tr("Starting..."));
bool ok = factories->manualUpdate(progressDialog.progress());
progressDialog.progress()->lock(false);
progressDialog.progress()->setInfo(tr("Finished %1").arg(ok ? tr("successfully") : tr("with errors")));
progressDialog.exec();
}
delete dlg;
}
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <QtCore>
#include <QWidget>
class UpdateFactories;
class Updates : public QWidget
{
Q_OBJECT
public:
explicit Updates(QWidget * parent, UpdateFactories * updateFactories);
virtual ~Updates();
void autoUpdates();
void manualUpdates();
private:
UpdateFactories *factories;
};
+102
View File
@@ -0,0 +1,102 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "updatesdcard.h"
#include <QMessageBox>
UpdateSDCard::UpdateSDCard(QWidget * parent) :
UpdateInterface(parent)
{
setName("SD Card");
setRepo(QString(GH_REPOS_EDGETX).append("/edgetx-sdcard"));
dfltParams->data.flags = UPDFLG_Common | UPDFLG_Locked;
UpdateParameters::AssetParams &ap = dfltParams->addAsset();
ap.filterType = UpdateParameters::UFT_Startswith;
ap.filter = QString("%1-").arg(fwFlavour);
ap.maxExpected = 1;
ap.flags = dfltParams->data.flags | UPDFLG_CopyStructure;
}
bool UpdateSDCard::flagAssets()
{
progressMessage(tr("Flagging assets"));
/*
{
"targets": [
["Flysky NV14", "nv14-", "nv14"],
["FrSky Horus X10", "x10-", "horus"],
*/
const QString mappingfile = "sdcard.json";
if (!downloadTextFileToBuffer(mappingfile)) {
return false;
}
QJsonDocument *json = new QJsonDocument();
if (!convertDownloadToJson(json)) {
return false;
}
UpdateParameters::AssetParams ap = runParams->data.assets.at(0);
QRegularExpression filter(UpdateParameters::buildFilterPattern(ap.filterType, ap.filter), QRegularExpression::CaseInsensitiveOption);
bool found = false;
QString sdimage;
if (json->isObject()) {
const QJsonObject &obj = json->object();
if (obj.value("targets").isArray()) {
const QJsonArray &t = obj.value("targets").toArray();
foreach (const QJsonValue &v, t) {
if (v.isArray()) {
const QJsonArray &i = v.toArray();
if (i.size() > 2) {
if (i.at(1).toString().contains(filter)) {
sdimage = i.at(2).toString();
found = true;
break;
}
}
}
}
}
}
if (!found) {
reportProgress(tr("Radio flavour %1 not listed in %2").arg(fwFlavour).arg(mappingfile), QtCriticalMsg);
return false;
}
delete json;
if (!getSetAssets(ap.flags, UpdateParameters::UFT_Startswith, sdimage, ap.maxExpected, ap.destSubDir, ap.copyFilterType, ap.copyFilter))
return false;
return true;
}
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "updateinterface.h"
class UpdateSDCard : public UpdateInterface
{
Q_DECLARE_TR_FUNCTIONS(UpdateSDCard)
public:
explicit UpdateSDCard(QWidget * parent);
virtual ~UpdateSDCard() {}
protected:
virtual bool flagAssets() override;
};
+218
View File
@@ -0,0 +1,218 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "updatesdialog.h"
#include "ui_updatesdialog.h"
#include "updateoptionsdialog.h"
#include <QStandardItemModel>
#include <QMap>
#include <QFileDialog>
#include <QTimer>
UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) :
QDialog(parent),
ui(new Ui::UpdatesDialog),
factories(factories)
{
// downloading the release meta data takes a few seconds for each component so display progress
QDialog *status = new QDialog(parent);
status->setWindowTitle(tr("Progress"));
QVBoxLayout *layout = new QVBoxLayout(status);
QLabel *msg = new QLabel(status);
msg->setFixedWidth(400);
msg->setContentsMargins(50, 50, 50, 50);
layout->addWidget(msg);
status->show();
ui->setupUi(this);
ui->leDownloadDir->setText(g.downloadDir());
connect(ui->chkDecompressUseDwnld, &QCheckBox::stateChanged, [=](const int checked) {
if (!checked) {
ui->leDecompressDir->setText(g.decompressDir());
ui->leDecompressDir->setEnabled(true);
ui->btnDecompressSelect->setEnabled(true);
}
else {
ui->leDecompressDir->setText(g.downloadDir());
ui->leDecompressDir->setEnabled(false);
ui->btnDecompressSelect->setEnabled(false);
}
});
ui->chkDecompressUseDwnld->setChecked(!g.decompressUseDwnld());
ui->chkDecompressUseDwnld->setChecked(g.decompressUseDwnld());
connect(ui->chkUpdateUseSD, &QCheckBox::stateChanged, [=](const int checked) {
if (!checked) {
ui->leUpdateDir->setText(g.updateDir());
ui->leUpdateDir->setEnabled(true);
ui->btnUpdateSelect->setEnabled(true);
}
else {
ui->leUpdateDir->setText(g.currentProfile().sdPath());
ui->leUpdateDir->setEnabled(false);
ui->btnUpdateSelect->setEnabled(false);
}
});
ui->chkUpdateUseSD->setChecked(!g.updateUseSD());
ui->chkUpdateUseSD->setChecked(g.updateUseSD());
connect(ui->btnDownloadSelect, &QPushButton::clicked, [=]() {
QString dirPath = QFileDialog::getExistingDirectory(this,tr("Select your download folder"), g.downloadDir());
if (!dirPath.isEmpty()) {
ui->leDownloadDir->setText(dirPath);
}
});
connect(ui->btnDecompressSelect, &QPushButton::clicked, [=]() {
QString dirPath = QFileDialog::getExistingDirectory(this,tr("Select your decompress folder"), g.decompressDir());
if (!dirPath.isEmpty()) {
ui->leDecompressDir->setText(dirPath);
}
});
connect(ui->btnUpdateSelect, &QPushButton::clicked, [=]() {
QString dirPath = QFileDialog::getExistingDirectory(this,tr("Select your update destination folder"), g.updateDir());
if (!dirPath.isEmpty()) {
ui->leUpdateDir->setText(dirPath);
}
});
int row = 0;
int col = 0;
QGridLayout *grid = new QGridLayout();
QLabel *h1 = new QLabel();
grid->addWidget(h1, row, col++);
QLabel *h2 = new QLabel(tr("Name"));
grid->addWidget(h2, row, col++);
QLabel *h3 = new QLabel(tr("Channel"));
grid->addWidget(h3, row, col++);
QLabel *h4 = new QLabel(tr("Current Release"));
grid->addWidget(h4, row, col++);
QLabel *h5 = new QLabel(tr("Update Release"));
grid->addWidget(h5, row, col++);
col++; // options button
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
grid->addItem(spacer, row, col++);
QMapIterator<QString, int> it(factories->sortedComponentsList());
while (it.hasNext()) {
it.next();
int i = it.value();
const QString name = it.key();
if (g.component[i].checkForUpdate()) {
row++;
col = 0;
msg->setText(tr("Retrieving latest release information for %1").arg(name));
chkUpdate[i] = new QCheckBox();
chkUpdate[i]->setProperty("index", i);
chkUpdate[i]->setChecked(!factories->isLatestRelease(name));
grid->addWidget(chkUpdate[i], row, col++);
grid->setAlignment(chkUpdate[i], Qt::AlignHCenter);
QLabel *lblName = new QLabel(name);
grid->addWidget(lblName, row, col++);
QLabel *lblRC = new QLabel(ComponentData::releaseChannelsList().at(g.component[i].releaseChannel()));
grid->addWidget(lblRC, row, col++);
lblCurrentRel[i] = new QLabel(factories->currentRelease(name));
grid->addWidget(lblCurrentRel[i], row, col++);
lblUpdateRel[i] = new QLabel(factories->updateRelease(name));
grid->addWidget(lblUpdateRel[i], row, col++);
btnOptions[i] = new QPushButton(tr("Options"));
connect(btnOptions[i], &QPushButton::clicked, [=]() {
UpdateOptionsDialog *dlg = new UpdateOptionsDialog(this, factories, i);
connect(dlg, &UpdateOptionsDialog::changed, [=](const int i) {
QString name = g.component[i].name();
lblCurrentRel[i]->setText(factories->currentRelease(name));
lblUpdateRel[i]->setText(factories->updateRelease(name));
});
dlg->exec();
dlg->deleteLater();
});
grid->addWidget(btnOptions[i], row, col++);
}
}
ui->grpComponents->setLayout(grid);
connect(ui->buttonBox, &QDialogButtonBox::accepted, [=]() {
QMapIterator<QString, int> it(factories->sortedComponentsList());
while (it.hasNext()) {
it.next();
int i = it.value();
if (g.component[i].checkForUpdate()) {
if (chkUpdate[i]->isChecked()) {
const QString name = it.key();
UpdateParameters *runParams = factories->getRunParams(name);
runParams->data.flags |= UpdateInterface::UPDFLG_Update;
runParams->data.downloadDir = ui->leDownloadDir->text();
runParams->data.decompressUseDwnld = ui->chkDecompressUseDwnld->isChecked();
runParams->data.decompressDir = ui->leDecompressDir->text();
runParams->data.updateUseSD = ui->chkUpdateUseSD->isChecked();
runParams->data.updateDir = ui->leUpdateDir->text();
}
}
}
QDialog::accept();
});
connect(ui->buttonBox, &QDialogButtonBox::rejected, [=]() {
QDialog::reject();
});
ui->leDownloadDir->home(false);
status->hide();
status->deleteLater();
QTimer::singleShot(50, this, [=]() {
adjustSize();
});
}
UpdatesDialog::~UpdatesDialog()
{
delete ui;
}
+57
View File
@@ -0,0 +1,57 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "updateinterface.h"
#include "appdata.h"
#include <QDialog>
#include <QCheckBox>
#include <QLabel>
#include <QPushButton>
namespace Ui {
class UpdatesDialog;
}
class UpdatesDialog : public QDialog
{
Q_OBJECT
public:
UpdatesDialog(QWidget * parent, UpdateFactories * factories);
virtual ~UpdatesDialog();
signals:
private slots:
private:
Ui::UpdatesDialog *ui;
const UpdateFactories *factories;
QCheckBox *chkUpdate[MAX_COMPONENTS];
QLabel *lblCurrentRel[MAX_COMPONENTS];
QLabel *lblUpdateRel[MAX_COMPONENTS];
QPushButton *btnOptions[MAX_COMPONENTS];
};
+216
View File
@@ -0,0 +1,216 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UpdatesDialog</class>
<widget class="QDialog" name="UpdatesDialog">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>525</width>
<height>289</height>
</rect>
</property>
<property name="windowTitle">
<string>Process Updates</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="grpFolders">
<property name="title">
<string>Folders</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QLabel" name="lblDownloadDir">
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leDownloadDir"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lblUpdateDir">
<property name="text">
<string>Update</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="chkDecompressUseDwnld">
<property name="text">
<string>Create sub-folders in Download folder</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leDecompressDir">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblDecompressDir">
<property name="text">
<string>Decompress</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="chkUpdateUseSD">
<property name="text">
<string>Use Radio Profile SD structure</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="leUpdateDir">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QPushButton" name="btnUpdateSelect">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Select folder</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="btnDecompressSelect">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Select folder</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="btnDownloadSelect">
<property name="text">
<string>Select folder</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="grpComponents">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Components</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>UpdatesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>UpdatesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "updatesounds.h"
UpdateSounds::UpdateSounds(QWidget * parent) :
UpdateInterface(parent)
{
setName("Sounds");
setRepo(QString(GH_REPOS_EDGETX).append("/edgetx-sdcard-sounds"));
/*
file: sounds.json
[
{
"language": "cs_CZ",
"name": "Czech Female",
"description": "Czech Female Voice (cs-CZ-Vlasta)",
"directory": "cz"
},
TODO support multiple language sub variants
// eg edgetx-sdcard-sounds-en_gb-libby-2.7.0.zip
ap.filter = QString("^edgetx-sdcard-sounds-%1").arg(language); //return all variants of each language
*/
UpdateParameters::AssetParams &ap = dfltParams->addAsset();
// only supports default for each language
// eg edgetx-sdcard-sounds-en-2.7.0.zip
ap.filterType = UpdateParameters::UFT_Startswith;
ap.filter = QString("edgetx-sdcard-sounds-%1-").arg(language);
// if user changes filter then more than one could be returned
//ap.maxExpected = 1;
ap.flags = dfltParams->data.flags | UPDFLG_CopyStructure;
}
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "updateinterface.h"
class UpdateSounds : public UpdateInterface
{
Q_DECLARE_TR_FUNCTIONS(UpdateSounds)
public:
explicit UpdateSounds(QWidget * parent);
virtual ~UpdateSounds() {}
};
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "updatethemes.h"
#include "eeprominterface.h"
UpdateThemes::UpdateThemes(QWidget * parent) :
UpdateInterface(parent)
{
setName("Themes");
setRepo(QString(GH_REPOS_EDGETX).append("/themes"));
UpdateParameters::AssetParams &ap = dfltParams->addAsset();
ap.filterType = UpdateParameters::UFT_Startswith;
ap.filter = "edgetx-themes";
ap.maxExpected = 1;
ap.flags = dfltParams->data.flags | UPDFLG_CopyStructure;
}
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "updateinterface.h"
class UpdateThemes : public UpdateInterface
{
Q_DECLARE_TR_FUNCTIONS(UpdateThemes)
public:
explicit UpdateThemes(QWidget * parent);
virtual ~UpdateThemes() {}
};