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

Implement checking for offline updates results

CCMAIL: sitter@kde.org
parent f3397611
......@@ -21,7 +21,7 @@ install(TARGETS packagekit-backend DESTINATION ${PLUGIN_INSTALL_DIR}/discover)
#notifier
add_library(DiscoverPackageKitNotifier MODULE PackageKitNotifier.cpp)
target_link_libraries(DiscoverPackageKitNotifier PRIVATE PK::packagekitqt5 Discover::Notifiers KF5::I18n KF5::Notifications)
target_link_libraries(DiscoverPackageKitNotifier PRIVATE PK::packagekitqt5 Discover::Notifiers KF5::I18n KF5::Notifications KF5::ConfigCore)
set_target_properties(DiscoverPackageKitNotifier PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/plasma-discover)
install(TARGETS DiscoverPackageKitNotifier DESTINATION ${PLUGIN_INSTALL_DIR}/discover-notifier)
......@@ -30,6 +30,6 @@ install(FILES packagekit-backend-categories.xml DESTINATION ${DATA_INSTALL_DIR}/
add_subdirectory(categoryimages)
if(packagekitqt5_VERSION VERSION_GREATER 0.9.7)
target_compile_definitions(packagekit-backend -DPKQT_0_10)
target_compile_definitions(DiscoverPackageKitNotifier -DPKQT_0_10)
target_compile_definitions(packagekit-backend PUBLIC -DPKQT_0_10)
target_compile_definitions(DiscoverPackageKitNotifier PUBLIC -DPKQT_0_10)
endif()
......@@ -30,7 +30,12 @@
#include <KNotification>
#include <PackageKit/Daemon>
#include <QDBusInterface>
#include <QFile>
#include <KLocalizedString>
#include <KDesktopFile>
#include <KConfigGroup>
#include "pk-offline-private.h"
PackageKitNotifier::PackageKitNotifier(QObject* parent)
: BackendNotifierModule(parent)
......@@ -65,12 +70,56 @@ PackageKitNotifier::PackageKitNotifier(QObject* parent)
connect(process, static_cast<void(QProcess::*)(int)>(&QProcess::finished), regularCheck, static_cast<void(QTimer::*)()>(&QTimer::start));
} else
regularCheck->start();
QTimer::singleShot(3000, this, &PackageKitNotifier::checkOfflineUpdates);
}
PackageKitNotifier::~PackageKitNotifier()
{
}
void PackageKitNotifier::checkOfflineUpdates()
{
if (!QFile::exists(QStringLiteral(PK_OFFLINE_RESULTS_FILENAME))) {
return;
}
qDebug() << "found offline update results at " << PK_OFFLINE_RESULTS_FILENAME;
KDesktopFile file(QStringLiteral(PK_OFFLINE_RESULTS_FILENAME));
KConfigGroup group(&file, PK_OFFLINE_RESULTS_GROUP);
const bool success = group.readEntry("Success", false);
const QString packagesJoined = group.readEntry("Packages");
const auto packages = packagesJoined.splitRef(QLatin1Char(','));
if (!success) {
const QString errorDetails = group.readEntry("ErrorDetails");
KNotification *notification = new KNotification(QLatin1String("offlineupdate-failed"), KNotification::Persistent | KNotification::DefaultEvent);
notification->setIconName(QStringLiteral("error"));
notification->setText(i18n("Offline Updates"));
notification->setText(i18n("Failed to update %1 packages\n%2", packages.count(), errorDetails));
notification->setActions(QStringList{QLatin1String("Open Discover")});
connect(notification, &KNotification::action1Activated, this, [] () {
QProcess::startDetached(QStringLiteral("plasma-discover"));
});
notification->sendEvent();
} else {
KNotification *notification = new KNotification(QLatin1String("offlineupdate-successful"));
notification->setIconName(QStringLiteral("system-software-update"));
notification->setTitle(i18n("Offline Updates"));
notification->setText(i18n("Successfully updated %1 packages", packages.count()));
notification->setActions(QStringList{QLatin1String("Open Discover")});
connect(notification, &KNotification::action1Activated, this, [] () {
QProcess::startDetached(QStringLiteral("plasma-discover"));
});
notification->sendEvent();
}
}
void PackageKitNotifier::recheckSystemUpdateNeeded()
{
if (PackageKit::Daemon::global()->isRunning()) {
......
......@@ -51,6 +51,7 @@ private Q_SLOTS:
void onDistroUpgrade(PackageKit::Transaction::DistroUpgrade type, const QString &name, const QString &description);
private:
void checkOfflineUpdates();
void requireRestartNotification(PackageKit::Transaction::Restart type);
QProcess* checkAptVariable(const QString &aptconfig, const QLatin1String& varname, std::function<void(const QStringRef& val)> func);
......
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