Commit a6f7aaa6 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

sources: fix source actions in older versions of Qt

QList is not iterable over there, so we had to turn it into a QVariantList.

BUG: 415666
parent 895b2e69
......@@ -73,9 +73,9 @@ bool DummySourcesBackend::removeSource(const QString& id)
return m_sources->removeRow(it->row());
}
QList<QAction*> DummySourcesBackend::actions() const
QVariantList DummySourcesBackend::actions() const
{
return QList<QAction*>() << m_testAction;
return QVariantList() << QVariant::fromValue<QObject*>(m_testAction);
}
bool DummySourcesBackend::moveSource(const QString& sourceId, int delta)
......
......@@ -33,7 +33,7 @@ public:
bool addSource(const QString& id) override;
bool removeSource(const QString& id) override;
QString idDescription() override { return QStringLiteral("Random weird text"); }
QList<QAction*> actions() const override;
QVariantList actions() const override;
bool supportsAdding() const override { return true; }
bool canMoveSources() const override { return true; }
......
......@@ -170,9 +170,9 @@ bool FlatpakSourcesBackend::removeSource(const QString &id)
return false;
}
QList<QAction*> FlatpakSourcesBackend::actions() const
QVariantList FlatpakSourcesBackend::actions() const
{
return { m_flathubAction };
return { QVariant::fromValue<QObject*>(m_flathubAction) };
}
bool FlatpakSourcesBackend::listRepositories(FlatpakInstallation* installation)
......@@ -248,7 +248,8 @@ void FlatpakSourcesBackend::addRemote(FlatpakRemote *remote, FlatpakInstallation
const QUrl remoteUrl(QString::fromUtf8(flatpak_remote_get_url(remote)));
const auto theActions = actions();
for(QAction *action: theActions) {
for(const QVariant& act: theActions) {
QAction* action = qobject_cast<QAction*>(act.value<QObject*>());
if (action->toolTip() == id) {
action->setEnabled(false);
action->setVisible(false);
......
......@@ -41,7 +41,7 @@ public:
bool addSource(const QString &id) override;
bool removeSource(const QString &id) override;
QString idDescription() override;
QList<QAction*> actions() const override;
QVariantList actions() const override;
bool supportsAdding() const override { return true; }
bool canFilterSources() const override { return true; }
......
......@@ -78,7 +78,7 @@ private Q_SLOTS:
QSignalSpy initializedSpy(m_appBackend, SIGNAL(initialized()));
if (m->rowCount() == 1) {
QSignalSpy spy(m, &SourcesModel::rowsInserted);
bk->actions().constFirst()->trigger();
qobject_cast<QAction*>(bk->actions().constFirst().value<QObject*>())->trigger();
QVERIFY(spy.count() || spy.wait(20000));
}
QVERIFY(initializedSpy.count() || initializedSpy.wait(20000));
......
......@@ -136,7 +136,7 @@ bool FwupdSourcesBackend::removeSource(const QString& id)
return false;
}
QList<QAction*> FwupdSourcesBackend::actions() const
QVariantList FwupdSourcesBackend::actions() const
{
return {} ;
}
......
......@@ -39,7 +39,7 @@ public:
bool addSource(const QString& id) override;
bool removeSource(const QString& id) override;
QString idDescription() override { return QString(); }
QList<QAction*> actions() const override;
QVariantList actions() const override;
bool supportsAdding() const override { return false; }
void eulaRequired(const QString& remoteName, const QString& licenseAgreement);
void populateSources();
......
......@@ -85,7 +85,7 @@ PackageKitSourcesBackend::PackageKitSourcesBackend(AbstractResourcesBackend* par
auto addNativeSourcesManager = [this](const QString &file){
auto service = PackageKitBackend::locateService(file);
if (!service.isEmpty())
m_actions += createActionForService(service, this);
m_actions += QVariant::fromValue<QObject*>(createActionForService(service, this));
};
//New Ubuntu
......@@ -155,7 +155,7 @@ bool PackageKitSourcesBackend::removeSource(const QString& id)
return false;
}
QList<QAction *> PackageKitSourcesBackend::actions() const
QVariantList PackageKitSourcesBackend::actions() const
{
return m_actions;
}
......
......@@ -40,7 +40,7 @@ class PackageKitSourcesBackend : public AbstractSourcesBackend
bool removeSource(const QString& id) override;
QAbstractItemModel* sources() override;
QList<QAction*> actions() const override;
QVariantList actions() const override;
void transactionError(PackageKit::Transaction::Error, const QString& message);
......@@ -50,7 +50,7 @@ class PackageKitSourcesBackend : public AbstractSourcesBackend
QStandardItem* findItemForId(const QString &id) const;
PKSourcesModel* m_sources;
QList<QAction*> m_actions;
QVariantList m_actions;
};
#endif // PACKAGEKITSOURCESBACKEND_H
......@@ -57,7 +57,7 @@ public:
bool addSource(const QString& /*id*/) override { return false; }
bool removeSource(const QString& /*id*/) override { return false;}
QString idDescription() override { return QStringLiteral("Snap"); }
QList<QAction*> actions() const override { return {}; }
QVariantList actions() const override { return {}; }
bool supportsAdding() const override { return false; }
bool canMoveSources() const override { return false; }
......
......@@ -34,7 +34,7 @@ class DISCOVERCOMMON_EXPORT AbstractSourcesBackend : public QObject
Q_PROPERTY(AbstractResourcesBackend* resourcesBackend READ resourcesBackend CONSTANT)
Q_PROPERTY(QAbstractItemModel* sources READ sources CONSTANT)
Q_PROPERTY(QString idDescription READ idDescription CONSTANT)
Q_PROPERTY(QList<QAction*> actions READ actions CONSTANT)
Q_PROPERTY(QVariantList actions READ actions CONSTANT) //TODO Make it a QVector<QAction*> again when we depend on newer than Qt 5.12
Q_PROPERTY(bool supportsAdding READ supportsAdding CONSTANT)
Q_PROPERTY(bool canMoveSources READ canMoveSources CONSTANT)
Q_PROPERTY(bool canFilterSources READ canFilterSources CONSTANT)
......@@ -56,7 +56,7 @@ class DISCOVERCOMMON_EXPORT AbstractSourcesBackend : public QObject
Q_SCRIPTABLE virtual bool removeSource(const QString& id) = 0;
virtual QAbstractItemModel* sources() = 0;
virtual QList<QAction*> actions() const = 0;
virtual QVariantList actions() const = 0;
virtual bool supportsAdding() const = 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