File indexing completed on 2024-11-17 04:55:43
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "PKResolveTransaction.h" 0008 #include "PackageKitBackend.h" 0009 #include <PackageKit/Daemon> 0010 0011 #include <QDebug> 0012 0013 PKResolveTransaction::PKResolveTransaction(PackageKitBackend *backend) 0014 : m_backend(backend) 0015 { 0016 m_floodTimer.setInterval(1000); 0017 m_floodTimer.setSingleShot(true); 0018 connect(&m_floodTimer, &QTimer::timeout, this, &PKResolveTransaction::start); 0019 } 0020 0021 void PKResolveTransaction::start() 0022 { 0023 Q_EMIT started(); 0024 0025 PackageKit::Transaction *tArch = PackageKit::Daemon::resolve(m_packageNames, PackageKit::Transaction::FilterArch); 0026 connect(tArch, &PackageKit::Transaction::package, m_backend, &PackageKitBackend::addPackageArch); 0027 connect(tArch, &PackageKit::Transaction::errorCode, m_backend, &PackageKitBackend::transactionError); 0028 0029 PackageKit::Transaction *tNotArch = PackageKit::Daemon::resolve(m_packageNames, PackageKit::Transaction::FilterNotArch); 0030 connect(tNotArch, &PackageKit::Transaction::package, m_backend, &PackageKitBackend::addPackageNotArch); 0031 connect(tNotArch, &PackageKit::Transaction::errorCode, m_backend, &PackageKitBackend::transactionError); 0032 0033 m_transactions = {tArch, tNotArch}; 0034 0035 for (auto transaction : std::as_const(m_transactions)) { 0036 connect(transaction, &PackageKit::Transaction::finished, this, &PKResolveTransaction::transactionFinished); 0037 } 0038 } 0039 0040 void PKResolveTransaction::transactionFinished(PackageKit::Transaction::Exit exit) 0041 { 0042 auto transaction = qobject_cast<PackageKit::Transaction *>(sender()); 0043 if (exit != PackageKit::Transaction::ExitSuccess) { 0044 qWarning() << "failed" << exit << transaction; 0045 } 0046 0047 m_transactions.removeAll(transaction); 0048 if (m_transactions.isEmpty()) { 0049 Q_EMIT allFinished(); 0050 deleteLater(); 0051 } 0052 } 0053 0054 void PKResolveTransaction::addPackageNames(const QStringList &packageNames) 0055 { 0056 m_packageNames += packageNames; 0057 m_packageNames.removeDuplicates(); 0058 m_floodTimer.start(); 0059 }