Commit 12906bbf authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

PackageKit: de-couple proceeding from EULA so it can be used by anything else

parent 8f7fa400
......@@ -173,14 +173,31 @@ void PKTransaction::cleanup(PackageKit::Transaction::Exit exit, uint runtime)
setStatus(Transaction::CancelledStatus);
}
void PKTransaction::processProceedFunction()
{
auto t = m_proceedFunctions.takeFirst()();
connect(t, &PackageKit::Transaction::finished, this, [this](PackageKit::Transaction::Exit status) {
if (status != PackageKit::Transaction::Exit::ExitSuccess) {
qWarning() << "transaction failed" << sender() << status;
cancel();
return;
}
if (!m_proceedFunctions.isEmpty()) {
processProceedFunction();
} else {
start();
}
});
}
void PKTransaction::proceed()
{
if (!m_requiredEula.isEmpty()) {
PackageKit::Transaction* t = PackageKit::Daemon::acceptEula(m_requiredEula.takeFirst());
connect(t, &PackageKit::Transaction::finished, this, &PKTransaction::start);
return;
if (!m_proceedFunctions.isEmpty()) {
processProceedFunction();
} else {
trigger(PackageKit::Transaction::TransactionFlagOnlyTrusted);
}
trigger(PackageKit::Transaction::TransactionFlagOnlyTrusted);
}
void PKTransaction::packageResolved(PackageKit::Transaction::Info info, const QString& packageId)
......@@ -210,7 +227,10 @@ PackageKit::Transaction* PKTransaction::transaction()
void PKTransaction::eulaRequired(const QString& eulaID, const QString& packageID, const QString& vendor, const QString& licenseAgreement)
{
m_requiredEula += eulaID;
m_proceedFunctions << [eulaID](){
return PackageKit::Daemon::acceptEula(eulaID);
};
Q_EMIT proceedRequest(i18n("Accept EULA"), i18n("The package %1 and its vendor %2 require that you accept their license:\n %3",
PackageKit::Daemon::packageName(packageID), vendor, licenseAgreement));
}
......
......@@ -40,6 +40,8 @@ class PKTransaction : public Transaction
void start();
private:
void processProceedFunction();
void cleanup(PackageKit::Transaction::Exit, uint);
void errorFound(PackageKit::Transaction::Error err, const QString& error);
void mediaChange(PackageKit::Transaction::MediaType media, const QString& type, const QString& text);
......@@ -54,7 +56,7 @@ class PKTransaction : public Transaction
QPointer<PackageKit::Transaction> m_trans;
const QVector<AbstractResource*> m_apps;
QSet<QString> m_pkgnames;
QVector<QString> m_requiredEula;
QVector<std::function<PackageKit::Transaction*()>> m_proceedFunctions;
QMap<PackageKit::Transaction::Info, QStringList> m_newPackageStates;
};
......
......@@ -122,14 +122,31 @@ QSet<QString> PackageKitUpdater::involvedPackages(const QSet<AbstractResource*>&
return packageIds;
}
void PackageKitUpdater::processProceedFunction()
{
auto t = m_proceedFunctions.takeFirst()();
connect(t, &PackageKit::Transaction::finished, this, [this](PackageKit::Transaction::Exit status) {
if (status != PackageKit::Transaction::Exit::ExitSuccess) {
qWarning() << "transaction failed" << sender() << status;
cancel();
return;
}
if (!m_proceedFunctions.isEmpty()) {
processProceedFunction();
} else {
start();
}
});
}
void PackageKitUpdater::proceed()
{
if (!m_requiredEula.isEmpty()) {
PackageKit::Transaction* t = PackageKit::Daemon::acceptEula(m_requiredEula.takeFirst());
connect(t, &PackageKit::Transaction::finished, this, &PackageKitUpdater::start);
return;
if (!m_proceedFunctions.isEmpty()) {
processProceedFunction();
} else {
setupTransaction(PackageKit::Transaction::TransactionFlagOnlyTrusted);
}
setupTransaction(PackageKit::Transaction::TransactionFlagOnlyTrusted);
}
void PackageKitUpdater::start()
......@@ -155,7 +172,6 @@ void PackageKitUpdater::finished(PackageKit::Transaction::Exit exit, uint /*time
if (!m_packagesRemoved.isEmpty())
Q_EMIT proceedRequest(i18n("Packages to remove"), i18n("The following packages will be removed by the update:\n%1", PackageKitResource::joinPackages(m_packagesRemoved)));
else {
Q_ASSERT(m_requiredEula.isEmpty());
proceed();
}
return;
......@@ -271,7 +287,9 @@ void PackageKitUpdater::requireRestart(PackageKit::Transaction::Restart restart,
void PackageKitUpdater::eulaRequired(const QString& eulaID, const QString& packageID, const QString& vendor, const QString& licenseAgreement)
{
m_requiredEula += eulaID;
m_proceedFunctions << [eulaID](){
return PackageKit::Daemon::acceptEula(eulaID);
};
Q_EMIT proceedRequest(i18n("Accept EULA"), i18n("The package %1 and its vendor %2 require that you accept their license:\n %3",
PackageKit::Daemon::packageName(packageID), vendor, licenseAgreement));
}
......
......@@ -70,6 +70,7 @@ class PackageKitUpdater : public AbstractBackendUpdater
void packageResolved(PackageKit::Transaction::Info info, const QString& packageId);
private:
void processProceedFunction();
void itemProgress(const QString &itemID, PackageKit::Transaction::Status status, uint percentage);
void fetchLastUpdateTime();
void lastUpdateTimeReceived(QDBusPendingCallWatcher* w);
......@@ -87,7 +88,7 @@ class PackageKitUpdater : public AbstractBackendUpdater
int m_percentage;
QDateTime m_lastUpdate;
QStringList m_packagesRemoved;
QVector<QString> m_requiredEula;
QVector<std::function<PackageKit::Transaction*()>> m_proceedFunctions;
};
......
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