diff --git a/PkUpdates.cxx b/PkUpdates.cxx
index 5dd96d9..aa5b29d 100644
--- a/PkUpdates.cxx
+++ b/PkUpdates.cxx
@@ -1,285 +1,285 @@
/*
Copyright 2017 Martin Koller, kollix@aon.at
This file is part of liquidshell.
liquidshell is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
liquidshell 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 General Public License
along with liquidshell. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//--------------------------------------------------------------------------------
PkUpdates::PkUpdates(QWidget *parent)
: SysTrayItem(parent)
{
KConfig config;
KConfigGroup group = config.group("SoftwareUpdates");
- if ( !group.hasKey("SoftwareUpdates") ) // create config entry so that one knows it exists
+ if ( !group.hasKey("enabled") ) // create config entry so that one knows it exists
group.writeEntry("enabled", true);
bool isEnabled = group.readEntry("enabled", true);
if ( !isEnabled )
{
hide();
return;
}
setPixmap(QIcon::fromTheme("system-software-update").pixmap(size()));
connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this, [this]() { createToolTip(); });
// check every hour if the next checkpoint was reached. This ensures that
// we check for updates even when the computer was suspended for a while
// and therefore a normal QTimer timeout for 1 day will not be reached in 1 day
// TODO check again. start() was missing
updateTimer.setInterval(3600 * 1000);
updateTimer.start();
connect(&updateTimer, &QTimer::timeout, this, &PkUpdates::checkForUpdatesReached);
QTimer::singleShot(0, this, &PkUpdates::checkForUpdatesReached);
}
//--------------------------------------------------------------------------------
void PkUpdates::checkForUpdatesReached()
{
QDateTime current = QDateTime::currentDateTime();
if ( !nextCheck.isValid() || (current >= nextCheck) )
{
checkForUpdates();
nextCheck = current.addDays(1);
}
}
//--------------------------------------------------------------------------------
void PkUpdates::checkForUpdates()
{
setPixmap(QIcon::fromTheme("system-software-update").pixmap(size()));
setToolTip(i18n("Checking for updates ..."));
packages.clear();
PackageKit::Transaction *transaction = PackageKit::Daemon::refreshCache(true);
connect(transaction, &PackageKit::Transaction::errorCode, this, &PkUpdates::transactionError);
connect(transaction, &PackageKit::Transaction::finished, this, &PkUpdates::refreshFinished);
}
//--------------------------------------------------------------------------------
void PkUpdates::refreshFinished(PackageKit::Transaction::Exit status, uint runtime)
{
Q_UNUSED(runtime)
if ( status != PackageKit::Transaction::ExitSuccess )
return;
PackageKit::Transaction *transaction = PackageKit::Daemon::getUpdates();
connect(transaction, &PackageKit::Transaction::package, this, &PkUpdates::package);
connect(transaction, &PackageKit::Transaction::errorCode, this, &PkUpdates::transactionError);
connect(transaction, &PackageKit::Transaction::finished, this,
[this]()
{
if ( updateList )
updateList->setPackages(packages);
createToolTip(true);
});
connect(transaction, &PackageKit::Transaction::percentageChanged, this,
[this, transaction]()
{
if ( (transaction->percentage() <= 100) && (transaction->status() != PackageKit::Transaction::StatusFinished) )
setToolTip(i18n("Checking for updates ... %1%", transaction->percentage()));
});
}
//--------------------------------------------------------------------------------
void PkUpdates::package(PackageKit::Transaction::Info info, const QString &packageID, const QString &summary)
{
PackageData pkg;
pkg.id = packageID;
pkg.summary = summary;
packages.insert(info, pkg);
}
//--------------------------------------------------------------------------------
void PkUpdates::transactionError(PackageKit::Transaction::Error error, const QString &details)
{
Q_UNUSED(error)
setToolTip(i18n("Last check: %1\nError on checking for updates: %2",
QDateTime::currentDateTime().toString(Qt::SystemLocaleShortDate), details));
KNotification::event("update error", i18n("Software Update Error"), details,
QIcon::fromTheme("dialog-error").pixmap(32), this);
}
//--------------------------------------------------------------------------------
void PkUpdates::createToolTip(bool notify)
{
PackageKit::Transaction::Info info = PackageKit::Transaction::InfoUnknown;
QString tooltip;
int count = 0;
QList list = packages.values(PackageKit::Transaction::InfoSecurity);
if ( list.count() )
{
info = PackageKit::Transaction::InfoSecurity;
count += list.count();
tooltip += i18np("%1 security update available", "%1 security updates available", list.count());
addItems(tooltip, list);
}
list = packages.values(PackageKit::Transaction::InfoImportant);
if ( list.count() )
{
if ( info == PackageKit::Transaction::InfoUnknown )
info = PackageKit::Transaction::InfoImportant;
count += list.count();
tooltip += i18np("%1 important update available", "%1 important updates available", list.count());
addItems(tooltip, list);
}
list = packages.values(PackageKit::Transaction::InfoBugfix);
if ( list.count() )
{
if ( info == PackageKit::Transaction::InfoUnknown )
info = PackageKit::Transaction::InfoBugfix;
count += list.count();
tooltip += i18np("%1 bugfix update available", "%1 bugfix updates available", list.count());
addItems(tooltip, list);
}
int others = packages.count() - count;
if ( tooltip.isEmpty() )
{
if ( others )
{
setToolTip(i18np("Last check: %1\nNo important updates available\n%2 other",
"Last check: %1\nNo important updates available\n%2 others",
QDateTime::currentDateTime().toString(Qt::SystemLocaleShortDate), others));
}
else
{
setToolTip(i18n("Last check: %1\nNo important updates available",
QDateTime::currentDateTime().toString(Qt::SystemLocaleShortDate)));
}
setPixmap(QIcon::fromTheme("update-none").pixmap(size()));
}
else
{
if ( others )
tooltip += i18np("
%1 other", "
%1 others", others);
tooltip = i18n("Last check: %1
%2",
QDateTime::currentDateTime().toString(Qt::SystemLocaleShortDate), tooltip);
setToolTip(tooltip);
QString icon;
switch ( info )
{
case PackageKit::Transaction::InfoSecurity: icon = "update-high"; break;
case PackageKit::Transaction::InfoImportant: icon = "update-medium"; break;
case PackageKit::Transaction::InfoBugfix: icon = "update-low"; break;
default: ;
}
setPixmap(QIcon::fromTheme(icon).pixmap(size()));
if ( notify )
{
KNotification::event("updates available", i18n("Software Updates Available"), tooltip,
QIcon::fromTheme(icon).pixmap(32), this, KNotification::Persistent);
}
}
}
//--------------------------------------------------------------------------------
void PkUpdates::addItems(QString &tooltip, const QList &list) const
{
tooltip += "";
int count = std::min(3, list.count());
if ( list.count() == 4 ) // if there's just one more, show it directly instead of "1 more"
count++;
for (int i = 0; i < count; i++)
tooltip += "- " + list[i].summary + "
";
if ( list.count() > 4 )
tooltip += i18n("- %1 more ...
", list.count() - count);
tooltip += "
";
}
//--------------------------------------------------------------------------------
QWidget *PkUpdates::getDetailsList()
{
if ( !updateList )
{
updateList = new PkUpdateList(this);
updateList->setPackages(packages);
connect(updateList, &PkUpdateList::refreshRequested, this, &PkUpdates::checkForUpdates);
connect(updateList, &PkUpdateList::packageInstalled, this, &PkUpdates::packageInstalled);
}
return updateList;
}
//--------------------------------------------------------------------------------
void PkUpdates::packageInstalled(const QString &id)
{
for (PackageList::iterator it = packages.begin(); it != packages.end(); ++it)
{
if ( (*it).id == id )
{
packages.erase(it);
break;
}
}
createToolTip();
}
//--------------------------------------------------------------------------------