mirror of
https://github.com/altlinux/ALTMediaWriter.git
synced 2024-10-26 08:55:03 +03:00
implement LIVE variant type
clean up custom release/variant logic
This commit is contained in:
parent
f6275fbadd
commit
00b0658ca2
@ -99,7 +99,7 @@ Item {
|
||||
}
|
||||
Arrow {
|
||||
id: arrow
|
||||
visible: !release.isLocal
|
||||
visible: !release.isCustom
|
||||
anchors {
|
||||
verticalCenter: parent.verticalCenter
|
||||
right: parent.right
|
||||
@ -146,7 +146,7 @@ Item {
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
function action() {
|
||||
if (release.isLocal) {
|
||||
if (release.isCustom) {
|
||||
releases.selectedIndex = index
|
||||
fileDialog.visible = true
|
||||
} else {
|
||||
|
@ -287,7 +287,7 @@ Dialog {
|
||||
InfoMessage {
|
||||
id: messageSelectedImage
|
||||
width: infoColumn.width
|
||||
visible: releases.selected.isLocal
|
||||
visible: releases.selected.isCustom
|
||||
text: "<font color=\"gray\">" + qsTr("Selected:") + "</font> " + (releases.variant.image ? (((String)(releases.variant.image)).split("/").slice(-1)[0]) : ("<font color=\"gray\">" + qsTr("None") + "</font>"))
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ Release::Release(ReleaseManager *parent, const QString &name, const QString &dis
|
||||
, m_description(description)
|
||||
, m_icon(icon)
|
||||
, m_screenshots(screenshots)
|
||||
, m_isCustom(false)
|
||||
{
|
||||
// TODO: connect to release's signal in parent, not the other way around, won't need to have parent be releasemanager then
|
||||
connect(
|
||||
@ -40,34 +41,21 @@ Release::Release(ReleaseManager *parent, const QString &name, const QString &dis
|
||||
parent, &ReleaseManager::variantChangedFilter);
|
||||
}
|
||||
|
||||
void Release::setLocalFile(const QString &path) {
|
||||
if (QFile::exists(path)) {
|
||||
qWarning() << path << "doesn't exist";
|
||||
return;
|
||||
}
|
||||
Release *Release::custom(ReleaseManager *parent) {
|
||||
auto customRelease = new Release(parent, QString(), tr("Custom image"), QT_TRANSLATE_NOOP("Release", "Pick a file from your drive(s)"), { QT_TRANSLATE_NOOP("Release", "<p>Here you can choose a OS image from your hard drive to be written to your flash disk</p><p>Currently it is only supported to write raw disk images (.iso or .bin)</p>") }, "qrc:/logo/custom", {});
|
||||
customRelease->m_isCustom = true;
|
||||
customRelease->setLocalFile(QString());
|
||||
|
||||
// TODO: don't need to delete, can change path in variant. Though have to consider the case where path doesn't exist.
|
||||
|
||||
// Delete old variant
|
||||
for (auto variant : m_variants) {
|
||||
variant->deleteLater();
|
||||
}
|
||||
m_variants.clear();
|
||||
|
||||
// Add new variant
|
||||
auto local_variant = new Variant(path, this);
|
||||
m_variants.append(local_variant);
|
||||
emit variantsChanged();
|
||||
emit selectedVariantChanged();
|
||||
return customRelease;
|
||||
}
|
||||
|
||||
void Release::updateUrl(const QString &url, Architecture *architecture, ImageType *imageType, const QString &board) {
|
||||
void Release::updateUrl(const QString &url, Architecture *architecture, ImageType *imageType, const QString &board, const bool live) {
|
||||
// If variant already exists, update it
|
||||
Variant *variant_in_list =
|
||||
[=]() -> Variant * {
|
||||
for (auto variant : m_variants) {
|
||||
// TODO: equals?
|
||||
if (variant->arch() == architecture && variant->board() == board) {
|
||||
if (variant->arch() == architecture && variant->imageType() == imageType && variant->board() == board && variant->live() == live) {
|
||||
return variant;
|
||||
}
|
||||
}
|
||||
@ -96,7 +84,7 @@ void Release::updateUrl(const QString &url, Architecture *architecture, ImageTyp
|
||||
}
|
||||
return out;
|
||||
}();
|
||||
auto new_variant = new Variant(url, architecture, imageType, board, this);
|
||||
auto new_variant = new Variant(url, architecture, imageType, board, live, this);
|
||||
|
||||
m_variants.insert(insert_index, new_variant);
|
||||
emit variantsChanged();
|
||||
@ -108,6 +96,24 @@ void Release::updateUrl(const QString &url, Architecture *architecture, ImageTyp
|
||||
}
|
||||
}
|
||||
|
||||
void Release::setLocalFile(const QString &path) {
|
||||
// Delete old custom variant (there's only one, but iterate anyway)
|
||||
for (auto variant : m_variants) {
|
||||
variant->deleteLater();
|
||||
}
|
||||
m_variants.clear();
|
||||
|
||||
// Add new variant
|
||||
ImageType *image_type = ImageType::fromFilename(path);
|
||||
auto customVariant = new Variant(path, Architecture::fromId(Architecture::UNKNOWN), image_type, QString(), false, this);
|
||||
// NOTE: start out in ready because don't need to download
|
||||
customVariant->setStatus(Variant::READY);
|
||||
m_variants.append(customVariant);
|
||||
|
||||
emit variantsChanged();
|
||||
emit selectedVariantChanged();
|
||||
}
|
||||
|
||||
QString Release::name() const {
|
||||
return m_name;
|
||||
}
|
||||
@ -124,8 +130,8 @@ QString Release::description() const {
|
||||
return m_description;
|
||||
}
|
||||
|
||||
bool Release::isLocal() const {
|
||||
return m_name == "custom";
|
||||
bool Release::isCustom() const {
|
||||
return m_isCustom;
|
||||
}
|
||||
|
||||
QString Release::icon() const {
|
||||
|
@ -40,7 +40,7 @@ class ImageType;
|
||||
* @property name the name of the release, like "Fedora Workstation"
|
||||
* @property summary the summary describing the release - displayed on the main screen
|
||||
* @property description the extensive description of the release - displayed on the detail screen
|
||||
* @property isLocal true if name is "custom"
|
||||
* @property isCustom true if this is the custom release
|
||||
* @property icon path of the icon of this release
|
||||
* @property screenshots a list of paths to screenshots (typically HTTP URLs)
|
||||
* @property versions a list of available versions of the @ref ReleaseVersion class
|
||||
@ -54,7 +54,7 @@ class Release : public QObject {
|
||||
Q_PROPERTY(QString summary READ summary CONSTANT)
|
||||
Q_PROPERTY(QString description READ description CONSTANT)
|
||||
|
||||
Q_PROPERTY(bool isLocal READ isLocal CONSTANT)
|
||||
Q_PROPERTY(bool isCustom READ isCustom CONSTANT)
|
||||
|
||||
Q_PROPERTY(QString icon READ icon CONSTANT)
|
||||
Q_PROPERTY(QStringList screenshots READ screenshots CONSTANT)
|
||||
@ -64,15 +64,19 @@ class Release : public QObject {
|
||||
Q_PROPERTY(int variantIndex READ selectedVariantIndex WRITE setSelectedVariantIndex NOTIFY selectedVariantChanged)
|
||||
public:
|
||||
Release(ReleaseManager *parent, const QString &name, const QString &displayName, const QString &summary, const QString &description, const QString &icon, const QStringList &screenshots);
|
||||
Q_INVOKABLE void setLocalFile(const QString &path);
|
||||
void updateUrl(const QString &url, Architecture *architecture, ImageType *imageType, const QString &board);
|
||||
|
||||
static Release *custom(ReleaseManager *parent);
|
||||
|
||||
void updateUrl(const QString &url, Architecture *architecture, ImageType *imageType, const QString &board, const bool live);
|
||||
ReleaseManager *manager();
|
||||
|
||||
Q_INVOKABLE void setLocalFile(const QString &path);
|
||||
|
||||
QString name() const;
|
||||
QString displayName() const;
|
||||
QString summary() const;
|
||||
QString description() const;
|
||||
bool isLocal() const;
|
||||
bool isCustom() const;
|
||||
QString icon() const;
|
||||
QStringList screenshots() const;
|
||||
|
||||
@ -94,6 +98,7 @@ private:
|
||||
QStringList m_screenshots;
|
||||
QList<Variant *> m_variants;
|
||||
int m_selectedVariant = 0;
|
||||
bool m_isCustom;
|
||||
};
|
||||
|
||||
#endif // RELEASE_H
|
||||
|
@ -137,7 +137,7 @@ bool ReleaseManager::filterAcceptsRow(int source_row, const QModelIndex &source_
|
||||
// Don't filter when on front page, just show 3 releases
|
||||
const bool on_front_page = (source_row < FRONTPAGE_ROW_COUNT);
|
||||
return on_front_page;
|
||||
} else if (release->isLocal()) {
|
||||
} else if (release->isCustom()) {
|
||||
// Always show local release
|
||||
return true;
|
||||
} else {
|
||||
@ -455,6 +455,16 @@ void ReleaseManager::loadVariants(const QString &variantsFile) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const bool live =
|
||||
[variantData]() {
|
||||
const QString live_string = yml_get(variantData, "live");
|
||||
if (!live_string.isEmpty()) {
|
||||
return (live_string == "1");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}();
|
||||
|
||||
qDebug() << "Loading variant:" << name << arch->abbreviation().first() << board << imageType->abbreviation().first() << QUrl(url).fileName();
|
||||
|
||||
for (int i = 0; i < m_sourceModel->rowCount(); i++) {
|
||||
@ -463,7 +473,7 @@ void ReleaseManager::loadVariants(const QString &variantsFile) {
|
||||
if (release->name().toLower().contains(name)) {
|
||||
// Select first release to get a valid variant to avoid null selected variant
|
||||
m_selectedIndex = i;
|
||||
release->updateUrl(url, arch, imageType, board);
|
||||
release->updateUrl(url, arch, imageType, board, live);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -617,10 +627,7 @@ ReleaseListModel::ReleaseListModel(const QList<QString> §ionsFiles, ReleaseM
|
||||
}
|
||||
}
|
||||
|
||||
// Create custom release and variant
|
||||
// Insert custom release at the end of the front page
|
||||
const auto customRelease = new Release(manager(), "custom", tr("Custom image"), QT_TRANSLATE_NOOP("Release", "Pick a file from your drive(s)"), { QT_TRANSLATE_NOOP("Release", "<p>Here you can choose a OS image from your hard drive to be written to your flash disk</p><p>Currently it is only supported to write raw disk images (.iso or .bin)</p>") }, "qrc:/logo/custom", {});
|
||||
customRelease->updateUrl(QString(), Architecture::fromId(Architecture::UNKNOWN), ImageType::all()[ImageType::ISO], QString("UNKNOWN BOARD"));
|
||||
auto customRelease = Release::custom(manager());
|
||||
m_releases.insert(FRONTPAGE_ROW_COUNT - 1, customRelease);
|
||||
}
|
||||
|
||||
|
@ -31,28 +31,18 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QDir>
|
||||
|
||||
Variant::Variant(QString url, Architecture *arch, ImageType *imageType, QString board, Release *parent)
|
||||
Variant::Variant(QString url, Architecture *arch, ImageType *imageType, QString board, const bool live, Release *parent)
|
||||
: QObject(parent)
|
||||
, m_arch(arch)
|
||||
, m_image_type(imageType)
|
||||
, m_board(board)
|
||||
, m_live(live)
|
||||
, m_url(url)
|
||||
, m_progress(new Progress(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Variant::Variant(const QString &file, Release *parent)
|
||||
: QObject(parent)
|
||||
, m_image(file)
|
||||
, m_arch(Architecture::fromId(Architecture::X86_64))
|
||||
, m_image_type(ImageType::fromFilename(file))
|
||||
, m_board("UNKNOWN BOARD")
|
||||
, m_progress(new Progress(this))
|
||||
{
|
||||
m_status = READY;
|
||||
}
|
||||
|
||||
bool Variant::updateUrl(const QString &url) {
|
||||
bool changed = false;
|
||||
if (!url.isEmpty() && m_url.toUtf8().trimmed() != url.toUtf8().trimmed()) {
|
||||
@ -84,12 +74,22 @@ QString Variant::board() const {
|
||||
return m_board;
|
||||
}
|
||||
|
||||
bool Variant::live() const {
|
||||
return m_live;
|
||||
}
|
||||
|
||||
QString Variant::name() const {
|
||||
return m_arch->description() + " | " + m_board;
|
||||
QString out = m_arch->description() + " | " + m_board;
|
||||
|
||||
if (m_live) {
|
||||
out += " LIVE";
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QString Variant::fullName() {
|
||||
if (release()->isLocal())
|
||||
if (release()->isCustom())
|
||||
return QFileInfo(image()).fileName();
|
||||
else
|
||||
return QString("%1 %2").arg(release()->displayName(), name());
|
||||
|
@ -92,8 +92,7 @@ public:
|
||||
tr("Error")
|
||||
};
|
||||
|
||||
Variant(QString url, Architecture *arch, ImageType *imageType, QString board, Release *parent);
|
||||
Variant(const QString &file, Release *parent);
|
||||
Variant(QString url, Architecture *arch, ImageType *imageType, QString board, const bool live, Release *parent);
|
||||
|
||||
bool updateUrl(const QString &url);
|
||||
|
||||
@ -105,6 +104,7 @@ public:
|
||||
QString name() const;
|
||||
QString fullName();
|
||||
QString board() const;
|
||||
bool live() const;
|
||||
|
||||
QString url() const;
|
||||
QString image() const;
|
||||
@ -140,6 +140,7 @@ private:
|
||||
Architecture *m_arch;
|
||||
ImageType *m_image_type;
|
||||
QString m_board {};
|
||||
bool m_live;
|
||||
QString m_url {};
|
||||
qreal m_size = 0.0;
|
||||
Status m_status { PREPARING };
|
||||
|
@ -93,7 +93,7 @@ Item {
|
||||
dlDialog.visible = true
|
||||
releases.variant.download()
|
||||
}
|
||||
enabled: !releases.selected.isLocal || releases.variant.image
|
||||
enabled: !releases.selected.isCustom || releases.variant.image
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ Item {
|
||||
ColumnLayout {
|
||||
width: parent.width
|
||||
spacing: 6
|
||||
opacity: releases.selected.isLocal ? 0.0 : 1.0
|
||||
opacity: releases.selected.isCustom ? 0.0 : 1.0
|
||||
Text {
|
||||
font.pointSize: 10
|
||||
color: mixColors(palette.window, palette.windowText, 0.3)
|
||||
|
Loading…
Reference in New Issue
Block a user