37
37
#include <KToolInvocation>
39
#include <Solid/PowerManagement>
45
43
#define UPDATES_ICON "system-software-update"
44
#define SYSTEM_READY "system_ready"
47
46
using namespace PackageKit;
52
51
m_statusNotifierItem(0)
54
connect(Daemon::global(), SIGNAL(updatesChanged()), this, SLOT(update()));
57
55
UpdateIcon::~UpdateIcon()
59
removeStatusNotifierItem();
62
59
void UpdateIcon::showSettings()
64
61
KToolInvocation::startServiceByDesktopName("apper_settings");
67
void UpdateIcon::refresh(bool update)
69
if (!systemIsReady(true)) {
70
kDebug() << "Not checking for updates, as we might be on battery or mobile connection";
77
Transaction *t = new Transaction(this);
78
// ignore if there is an error
79
// Be silent! don't bother the user if the cache couldn't be refreshed
81
connect(t, SIGNAL(finished(PackageKit::Transaction::Exit, uint)),
82
this, SLOT(update()));
84
connect(t, SIGNAL(finished(PackageKit::Transaction::Exit, uint)),
85
this, SLOT(decreaseRunning()));
86
t->refreshCache(true);
88
KNotification *notify = new KNotification("TransactionError", 0);
89
notify->setText(PkStrings::daemonError(t->error()));
90
notify->setPixmap(KIcon("dialog-error").pixmap(KPK_ICON_SIZE, KPK_ICON_SIZE));
96
// refresh the cache and try to update,
97
// if it can't automatically update show
98
// a notification about updates available
99
void UpdateIcon::refreshAndUpdate(bool doRefresh)
64
void UpdateIcon::checkForUpdates(bool system_ready)
101
66
// This is really necessary to don't bother the user with
104
// Force an update after refresh cache
111
void UpdateIcon::update()
113
68
if (m_getUpdatesT) {
124
79
if (interval != Enum::Never || updateType == Enum::All || updateType == Enum::Security) {
125
80
m_updateList.clear();
126
81
m_getUpdatesT = new Transaction(this);
82
m_getUpdatesT->setProperty(SYSTEM_READY, system_ready);
127
83
connect(m_getUpdatesT, SIGNAL(package(PackageKit::Package)),
128
84
this, SLOT(packageToUpdate(PackageKit::Package)));
129
connect(m_getUpdatesT, SIGNAL(finished(PackageKit::Transaction::Exit, uint)),
85
connect(m_getUpdatesT, SIGNAL(finished(PackageKit::Transaction::Exit,uint)),
130
86
this, SLOT(getUpdateFinished()));
131
87
m_getUpdatesT->getUpdates();
132
88
if (m_getUpdatesT->error()) {
169
125
this, SLOT(removeStatusNotifierItem()));
170
126
m_statusNotifierItem->setContextMenu(menu);
171
127
// Show updates on the left click
172
connect(m_statusNotifierItem, SIGNAL(activateRequested(bool, QPoint)),
128
connect(m_statusNotifierItem, SIGNAL(activateRequested(bool,QPoint)),
173
129
this, SLOT(showUpdates()));
210
168
KConfig config("apper");
211
169
KConfigGroup checkUpdateGroup(&config, "CheckUpdate");
212
uint updateType = static_cast<uint>(checkUpdateGroup.readEntry("autoUpdate", Enum::AutoUpdateDefault));
213
bool systemReady = systemIsReady(true);
170
updateType = static_cast<uint>(checkUpdateGroup.readEntry("autoUpdate", Enum::AutoUpdateDefault));
171
systemReady = sender()->property(SYSTEM_READY).toBool();
214
172
if (!systemReady && (updateType == Enum::All || (updateType == Enum::Security && !securityUpdateList.isEmpty()))) {
215
173
kDebug() << "Not auto updating packages updates, as we might be on battery or mobile connection";
221
179
Transaction *t = new Transaction(this);
222
connect(t, SIGNAL(finished(PackageKit::Transaction::Exit, uint)),
180
connect(t, SIGNAL(finished(PackageKit::Transaction::Exit,uint)),
223
181
this, SLOT(autoUpdatesFinished(PackageKit::Transaction::Exit)));
182
t->setProperty(SYSTEM_READY, systemReady);
224
183
t->updatePackages(m_updateList, true);
225
184
if (!t->error()) {
226
185
// don't be interactive to not upset an idle user
240
199
// Defaults to security
242
201
Transaction *t = new Transaction(this);
243
connect(t, SIGNAL(finished(PackageKit::Transaction::Exit, uint)),
202
connect(t, SIGNAL(finished(PackageKit::Transaction::Exit,uint)),
244
203
this, SLOT(autoUpdatesFinished(PackageKit::Transaction::Exit)));
204
t->setProperty(SYSTEM_READY, systemReady);
245
205
t->updatePackages(securityUpdateList, true);
246
206
if (!t->error()) {
247
207
// don't be interactive to not upset an idle user
301
261
m_statusNotifierItem = 0;
305
bool UpdateIcon::systemIsReady(bool checkUpdates)
307
Daemon::Network networkState = Daemon::networkState();
309
// test whether network is connected
310
if (networkState == Daemon::NetworkOffline || networkState == Daemon::UnknownNetwork) {
311
kDebug() << "nerwork state" << networkState;
315
KConfig config("apper");
316
KConfigGroup checkUpdateGroup(&config, "CheckUpdate");
319
ignoreBattery = checkUpdateGroup.readEntry("checkUpdatesOnBattery", false);
321
ignoreBattery = checkUpdateGroup.readEntry("installUpdatesOnBattery", false);
324
// THIS IS NOT working on my computer
325
// check how applications should behave (e.g. on battery power)
326
if (!ignoreBattery && Solid::PowerManagement::appShouldConserveResources()) {
328
kDebug() << "should conserve??";
333
ignoreMobile = checkUpdateGroup.readEntry("checkUpdatesOnMobile", false);
335
ignoreMobile = checkUpdateGroup.readEntry("installUpdatesOnMobile", false);
338
// check how applications should behave (e.g. on battery power)
339
if (!ignoreMobile && networkState == Daemon::NetworkMobile) {