Commit 27ea0cb4 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

updates: Make it possible to trigger offline updates

parent 5421b099
......@@ -12,8 +12,6 @@
#include <QAction>
#include <QSet>
#include <KSharedConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include "libdiscover_backend_debug.h"
......@@ -273,19 +271,12 @@ void PackageKitUpdater::proceed()
bool PackageKitUpdater::useOfflineUpdates() const
{
if (qEnvironmentVariableIntValue("PK_OFFLINE_UPDATE"))
return true;
KConfigGroup group(KSharedConfig::openConfig(), "Software");
return group.readEntry<bool>("UseOfflineUpdates", false);
return m_useOfflineUpdates || qEnvironmentVariableIntValue("PK_OFFLINE_UPDATE");
}
void PackageKitUpdater::setUseOfflineUpdates(bool use)
void PackageKitUpdater::setOfflineUpdates(bool use)
{
// To enable from command line use:
// kwriteconfig5 --file discoverrc --group Software --key UseOfflineUpdates true
KConfigGroup group(KSharedConfig::openConfig(), "Software");
group.writeEntry<bool>("UseOfflineUpdates", use);
m_useOfflineUpdates = use;
}
void PackageKitUpdater::start()
......
......@@ -38,6 +38,7 @@ class PackageKitUpdater : public AbstractBackendUpdater
quint64 downloadSpeed() const override;
void proceed() override;
void setOfflineUpdates(bool use) override;
public Q_SLOTS:
///must be implemented if ever isCancelable is true
......@@ -71,7 +72,6 @@ class PackageKitUpdater : public AbstractBackendUpdater
void lastUpdateTimeReceived(QDBusPendingCallWatcher* w);
void setupTransaction(PackageKit::Transaction::TransactionFlags flags);
bool useOfflineUpdates() const;
void setUseOfflineUpdates(bool use);
QSet<QString> involvedPackages(const QSet<AbstractResource*>& packages) const;
QSet<AbstractResource*> packagesForPackageId(const QSet<QString>& packages) const;
......@@ -82,6 +82,7 @@ class PackageKitUpdater : public AbstractBackendUpdater
QSet<AbstractResource*> m_allUpgradeable;
bool m_isCancelable;
bool m_isProgressing;
bool m_useOfflineUpdates = false;
int m_percentage;
QDateTime m_lastUpdate;
QMap<PackageKit::Transaction::Info, QStringList> m_packagesModified;
......
......@@ -37,3 +37,8 @@ bool AbstractBackendUpdater::needsReboot() const
{
return m_needsReboot;
}
void AbstractBackendUpdater::setOfflineUpdates(bool useOfflineUpdates)
{
Q_UNUSED(useOfflineUpdates);
}
......@@ -122,6 +122,8 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
bool needsReboot() const;
virtual void setOfflineUpdates(bool useOfflineUpdates);
public Q_SLOTS:
/**
* If \isCancelable is true during the transaction, this method has
......
......@@ -15,6 +15,8 @@
#include <KLocalizedString>
#include <KFormat>
#include <KSharedConfig>
#include <KConfigGroup>
class UpdateTransaction : public Transaction
{
......@@ -130,6 +132,11 @@ void ResourcesUpdatesModel::init()
}
}
// To enable from command line use:
// kwriteconfig5 --file discoverrc --group Software --key UseOfflineUpdates true
KConfigGroup group(KSharedConfig::openConfig(), "Software");
m_offlineUpdates = group.readEntry<bool>("UseOfflineUpdates", false);
auto tm = TransactionModel::global();
foreach(auto t, tm->transactions()) {
auto updateTransaction = qobject_cast<UpdateTransaction*>(t);
......@@ -158,7 +165,9 @@ void ResourcesUpdatesModel::prepare()
qCWarning(LIBDISCOVER_LOG) << "trying to set up a running instance";
return;
}
foreach(AbstractBackendUpdater* upd, m_updaters) {
upd->setOfflineUpdates(m_offlineUpdates);
upd->prepare();
}
}
......@@ -276,4 +285,9 @@ bool ResourcesUpdatesModel::needsReboot() const
return false;
}
void ResourcesUpdatesModel::setOfflineUpdates(bool offline)
{
m_offlineUpdates = offline;
}
#include "ResourcesUpdatesModel.moc"
......@@ -30,6 +30,7 @@ class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel
Q_SCRIPTABLE void prepare();
void setOfflineUpdates(bool offline);
bool isProgressing() const;
QList<AbstractResource*> toUpdate() const;
QDateTime lastUpdate() const;
......@@ -64,6 +65,7 @@ class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel
QVector<AbstractBackendUpdater*> m_updaters;
bool m_lastIsProgressing;
bool m_offlineUpdates = false;
QPointer<UpdateTransaction> m_transaction;
};
......
......@@ -29,6 +29,7 @@ void DiscoverUpdate::start()
if (m_resourcesUpdatesModel->isProgressing() || ResourcesModel::global()->isFetching() || m_done)
return;
m_resourcesUpdatesModel->setOfflineUpdates(m_offlineUpdates);
qDebug() << "ready" << ResourcesModel::global()->updatesCount();
m_resourcesUpdatesModel->prepare();
qDebug() << "steady" << m_resourcesUpdatesModel->rowCount({});
......
......@@ -23,12 +23,16 @@ class DiscoverUpdate : public QObject
explicit DiscoverUpdate();
~DiscoverUpdate() override;
void setOfflineUpdates(bool offline) {
m_offlineUpdates = offline;
}
private:
void start();
void transactionStatusChanged(Transaction::Status status);
ResourcesUpdatesModel* const m_resourcesUpdatesModel;
bool m_done = false;
bool m_offlineUpdates = false;
};
#endif // DISCOVERUPDATE_H
......@@ -25,11 +25,15 @@ int main(int argc, char** argv)
DiscoverUpdate exp;
{
QCommandLineParser parser;
QCommandLineOption offlineUpdate(QStringLiteral("offline"), i18n("Prefer updates that will only apply upon reboot"));
parser.addOption(offlineUpdate);
DiscoverBackendsFactory::setupCommandLine(&parser);
about.setupCommandLine(&parser);
parser.process(app);
about.processCommandLine(&parser);
DiscoverBackendsFactory::processCommandLine(&parser, false);
exp.setOfflineUpdates(parser.isSet(offlineUpdate));
}
return app.exec();
......
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