Commit a4114492 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

update: PoC new application for running headless updates

It could be useful to reduce transcendence to upgrades.
parent 5f26b212
......@@ -49,6 +49,7 @@ configure_file(DiscoverVersion.h.in DiscoverVersion.h)
add_subdirectory(libdiscover)
add_subdirectory(discover)
add_subdirectory(exporter)
add_subdirectory(update)
option(WITH_NOTIFIER "Build and install the notifier plasmoid" ON)
if(WITH_NOTIFIER)
......
......@@ -40,7 +40,6 @@ int main(int argc, char** argv)
MuonExporter exp;
{
QCommandLineParser parser;
parser.addOption(QCommandLineOption(QStringLiteral("backends"), i18n("List all the backends we'll want to have loaded, separated by coma ','."), QStringLiteral("names")));
parser.addPositionalArgument(QStringLiteral("file"), i18n("File to which we'll export"));
DiscoverBackendsFactory::setupCommandLine(&parser);
about.setupCommandLine(&parser);
......
add_executable(plasma-discover-update main.cpp DiscoverUpdate.cpp)
target_link_libraries(plasma-discover-update Discover::Common KF5::CoreAddons KF5::I18n)
install(TARGETS plasma-discover-update ${INSTALL_TARGETS_DEFAULT_ARGS})
/*
* Copyright (C) 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library/Lesser General Public License
* version 2, or (at your option) any later version, as published by the
* Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library/Lesser General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "DiscoverUpdate.h"
#include <resources/ResourcesModel.h>
#include <resources/ResourcesUpdatesModel.h>
#include <QCoreApplication>
DiscoverUpdate::DiscoverUpdate()
: QObject(nullptr)
, m_resourcesUpdatesModel(new ResourcesUpdatesModel)
{
connect(m_resourcesUpdatesModel, &ResourcesUpdatesModel::passiveMessage, this, [] (const QString &message) {
qWarning() << "message" << message;
});
connect(ResourcesModel::global(), &ResourcesModel::fetchingChanged, this, &DiscoverUpdate::start);
connect(m_resourcesUpdatesModel, &ResourcesUpdatesModel::progressingChanged, this, &DiscoverUpdate::start);
connect(ResourcesModel::global(), &ResourcesModel::backendsChanged, this, &DiscoverUpdate::start);
}
DiscoverUpdate::~DiscoverUpdate() = default;
void DiscoverUpdate::start()
{
if (m_resourcesUpdatesModel->isProgressing() || ResourcesModel::global()->isFetching() || m_done)
return;
qDebug() << "ready" << ResourcesModel::global()->updatesCount();
m_resourcesUpdatesModel->prepare();
qDebug() << "steady" << m_resourcesUpdatesModel->rowCount({});
m_resourcesUpdatesModel->updateAll();
auto transaction = m_resourcesUpdatesModel->transaction();
connect(transaction, &Transaction::statusChanged, this, &DiscoverUpdate::transactionStatusChanged);
qDebug() <<"go!" << transaction;
}
void DiscoverUpdate::transactionStatusChanged(Transaction::Status status)
{
m_done = true;
qDebug() <<"status!" << status << ResourcesModel::global()->updatesCount();
if (status == Transaction::DoneStatus || status == Transaction::DoneWithErrorStatus) {
const bool withError = status == Transaction::DoneWithErrorStatus;
QCoreApplication::instance()->exit(withError);
}
}
/*
* Copyright (C) 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library/Lesser General Public License
* version 2, or (at your option) any later version, as published by the
* Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library/Lesser General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef DISCOVERUPDATE_H
#define DISCOVERUPDATE_H
#include <QObject>
#include <QUrl>
#include <QSet>
#include <Transaction/Transaction.h>
class AbstractResource;
class ResourcesUpdatesModel;
class DiscoverUpdate : public QObject
{
Q_OBJECT
public:
explicit DiscoverUpdate();
~DiscoverUpdate() override;
private:
void start();
void transactionStatusChanged(Transaction::Status status);
ResourcesUpdatesModel* const m_resourcesUpdatesModel;
bool m_done = false;
};
#endif // DISCOVERUPDATE_H
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