Commit 07d31cc3 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Move the upgrade text into the C++ backend code for better reusability

This way it can be called from other C++ components
parent 3856dc0b
......@@ -275,27 +275,7 @@ DiscoverPage
Label {
Layout.fillWidth: true
elide: truncated ? Text.ElideLeft : Text.ElideRight
text: {
if (installedVersion == availableVersion) {
// Update of the same version; show when old and new are
// the same (common with Flatpak runtimes)
return i18n("Update to version %1", availableVersion);
} else if (installedVersion && availableVersion) {
// Old and new version numbers
// This thing with \x9C is a fancy feature in QML text handling:
// when the string will be elided, it shows the string after
// the last \x9C. This allows us to show a smaller string
// when there's now enough room
// All of this is mostly for the benefit of KDE Neon users,
// since the version strings there are really really long
return i18nc("Do not translate or alter \\x9C", "%1 → %2\x9C%1 → %2\x9C%2", installedVersion, availableVersion);
} else {
// Available version only, for when the installed version
// isn't available for some reason
return availableVersion;
}
}
text: upgradeText
opacity: listItem.hovered? 0.8 : 0.6
}
}
......
......@@ -32,22 +32,6 @@ QString UpdateItem::name() const
return m_app->name();
}
// Deprecated; use availableVersion() instead
QString UpdateItem::version() const
{
return m_app->availableVersion();
}
QString UpdateItem::availableVersion() const
{
return m_app->availableVersion();
}
QString UpdateItem::installedVersion() const
{
return m_app->installedVersion();
}
QVariant UpdateItem::icon() const
{
return m_app->icon();
......
......@@ -34,9 +34,6 @@ public:
AbstractResource *app() const;
QString name() const;
QString version() const; // Deprecated; use availableVersion() instead
QString availableVersion() const;
QString installedVersion() const;
QVariant icon() const;
qint64 size() const;
Qt::CheckState checked() const;
......
......@@ -52,8 +52,7 @@ QHash<int,QByteArray> UpdateModel::roleNames() const
ret.insert(SizeRole, "size");
ret.insert(SectionRole, "section");
ret.insert(ChangelogRole, "changelog");
ret.insert(InstalledVersionRole, "installedVersion");
ret.insert(AvailableVersionRole, "availableVersion");
ret.insert(UpgradeTextRole, "upgradeText");
return ret;
}
......@@ -113,10 +112,8 @@ QVariant UpdateModel::data(const QModelIndex &index, int role) const
return item->icon();
case Qt::CheckStateRole:
return item->checked();
case InstalledVersionRole:
return item->installedVersion();
case AvailableVersionRole:
return item->availableVersion();
case UpgradeTextRole:
return item->resource()->upgradeText();
case SizeRole:
return KFormat().formatByteSize(item->size());
case ResourceRole:
......@@ -325,7 +322,7 @@ void UpdateModel::resourceDataChanged(AbstractResource* res, const QVector<QByte
const auto index = indexFromItem(item);
if (properties.contains("state"))
Q_EMIT dataChanged(index, index, {SizeRole, AvailableVersionRole});
Q_EMIT dataChanged(index, index, {SizeRole, UpgradeTextRole});
else if (properties.contains("size")) {
Q_EMIT dataChanged(index, index, {SizeRole});
m_updateSizeTimer->start();
......
......@@ -34,8 +34,7 @@ public:
SectionResourceProgressRole,
ChangelogRole,
SectionRole,
InstalledVersionRole,
AvailableVersionRole,
UpgradeTextRole
};
Q_ENUM(Roles)
......
......@@ -232,3 +232,27 @@ QString AbstractResource::executeLabel() const
{
return i18n("Launch");
}
QString AbstractResource::upgradeText() const
{
QString installed = installedVersion(), available = availableVersion();
if (installed == available) {
// Update of the same version; show when old and new are
// the same (common with Flatpak runtimes)
return i18n("Update to version %1", available);
} else if (!installed.isEmpty() && !available.isEmpty()) {
// Old and new version numbers
// This thing with \x9C is a fancy feature in QML text handling:
// when the string will be elided, it shows the string after
// the last \x9C. This allows us to show a smaller string
// when there's now enough room
// All of this is mostly for the benefit of KDE Neon users,
// since the version strings there are really really long
return i18nc("Do not translate or alter \\x9C", "%1 → %2\x9C%1 → %2\x9C%2", installed, available);
} else {
// Available version only, for when the installed version
// isn't available for some reason
return available;
}
}
......@@ -68,6 +68,7 @@ class DISCOVERCOMMON_EXPORT AbstractResource : public QObject
Q_PROPERTY(QString sourceIcon READ sourceIcon CONSTANT)
Q_PROPERTY(QString author READ author CONSTANT)
Q_PROPERTY(QDate releaseDate READ releaseDate NOTIFY stateChanged)
Q_PROPERTY(QString upgradeText READ upgradeText NOTIFY stateChanged)
public:
/**
* This describes the state of the resource
......@@ -204,6 +205,8 @@ class DISCOVERCOMMON_EXPORT AbstractResource : public QObject
virtual QSet<QString> alternativeAppstreamIds() const { return {}; }
QString upgradeText() const;
public Q_SLOTS:
virtual void fetchScreenshots();
virtual void fetchChangelog() = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment