~ubuntu-branches/debian/stretch/apper/stretch

« back to all changes in this revision

Viewing changes to Sentinel/UpdateIcon.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klumpp
  • Date: 2012-05-22 10:45:24 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120522104524-jqbl47ulmak7sho6
Tags: 0.7.2-1
* New upstream release: 0.7.2
  - Automatic Refresh Cache properly fixed
  - Initial Listaller support (optional)
  - Supported filter added (depends on the backend)
  - KDED plugin runs on a separate thread to avoid
     desktop freezes
  - Fixed updating packages that were on untrusted repos
  - Fresh manual pages (thanks to Matthias)
  - Many other bug- and Krazy fixes
* Updated debian/copyright
* Switch to compat-level 9
* Updated watch file
* Split out arch-indep apper-data package
* Add apper-appsetup package for Listaller modules
* Remove old replacement for KPackageKit: No longer required
* Removed manpages: Pages are upstream now
* Override lintian false-positive about icon-sizes
* Allow DM upload

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <KMenu>
37
37
#include <KToolInvocation>
38
38
 
39
 
#include <Solid/PowerManagement>
40
 
 
41
39
#include <KDebug>
42
40
 
43
41
#include <Daemon>
44
42
 
45
43
#define UPDATES_ICON "system-software-update"
 
44
#define SYSTEM_READY "system_ready"
46
45
 
47
46
using namespace PackageKit;
48
47
 
51
50
      m_getUpdatesT(0),
52
51
      m_statusNotifierItem(0)
53
52
{
54
 
    connect(Daemon::global(), SIGNAL(updatesChanged()), this, SLOT(update()));
55
53
}
56
54
 
57
55
UpdateIcon::~UpdateIcon()
58
56
{
59
 
    removeStatusNotifierItem();
60
57
}
61
58
 
62
59
void UpdateIcon::showSettings()
64
61
    KToolInvocation::startServiceByDesktopName("apper_settings");
65
62
}
66
63
 
67
 
void UpdateIcon::refresh(bool update)
68
 
{
69
 
    if (!systemIsReady(true)) {
70
 
        kDebug() << "Not checking for updates, as we might be on battery or mobile connection";
71
 
        return;
72
 
    }
73
 
 
74
 
    if (!isRunning()) {
75
 
        SET_PROXY
76
 
        increaseRunning();
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
80
 
        if (update) {
81
 
            connect(t, SIGNAL(finished(PackageKit::Transaction::Exit, uint)),
82
 
                    this, SLOT(update()));
83
 
        }
84
 
        connect(t, SIGNAL(finished(PackageKit::Transaction::Exit, uint)),
85
 
                this, SLOT(decreaseRunning()));
86
 
        t->refreshCache(true);
87
 
        if (t->error()) {
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));
91
 
            notify->sendEvent();
92
 
        }
93
 
    }
94
 
}
95
 
    
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)
100
65
{
101
66
    // This is really necessary to don't bother the user with
102
67
    // tons of popups
103
 
    if (doRefresh) {
104
 
        // Force an update after refresh cache
105
 
        refresh(true);
106
 
    } else {
107
 
        update();
108
 
    }
109
 
}
110
 
 
111
 
void UpdateIcon::update()
112
 
{
113
68
    if (m_getUpdatesT) {
114
69
        return;
115
70
    }
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()));
174
130
    }
175
131
 
207
163
            }
208
164
        }
209
165
 
 
166
        uint updateType;
 
167
        bool systemReady;
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";
216
174
        }
219
177
            // update all
220
178
            SET_PROXY
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
241
200
            SET_PROXY
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
279
239
        notify->sendEvent();
280
240
        
281
241
        // run get-updates again so that non auto-installed updates can be displayed
282
 
        update();
 
242
        checkForUpdates(sender()->property(SYSTEM_READY).toBool());
283
243
    } else {
284
244
        KIcon icon("dialog-cancel");
285
245
        // use of QSize does the right thing
301
261
        m_statusNotifierItem = 0;
302
262
    }
303
263
}
304
 
 
305
 
bool UpdateIcon::systemIsReady(bool checkUpdates)
306
 
{
307
 
    Daemon::Network networkState = Daemon::networkState();
308
 
 
309
 
    // test whether network is connected
310
 
    if (networkState == Daemon::NetworkOffline || networkState == Daemon::UnknownNetwork) {
311
 
        kDebug() << "nerwork state" << networkState;
312
 
        return false;
313
 
    }
314
 
 
315
 
    KConfig config("apper");
316
 
    KConfigGroup checkUpdateGroup(&config, "CheckUpdate");
317
 
    bool ignoreBattery;
318
 
    if (checkUpdates) {
319
 
        ignoreBattery = checkUpdateGroup.readEntry("checkUpdatesOnBattery", false);
320
 
    } else {
321
 
        ignoreBattery = checkUpdateGroup.readEntry("installUpdatesOnBattery", false);
322
 
    }
323
 
 
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()) {
327
 
//        return false;
328
 
        kDebug() << "should conserve??";
329
 
    }
330
 
    
331
 
    bool ignoreMobile;
332
 
    if (checkUpdates) {
333
 
        ignoreMobile = checkUpdateGroup.readEntry("checkUpdatesOnMobile", false);
334
 
    } else {
335
 
        ignoreMobile = checkUpdateGroup.readEntry("installUpdatesOnMobile", false);
336
 
    }
337
 
 
338
 
    // check how applications should behave (e.g. on battery power)
339
 
    if (!ignoreMobile && networkState == Daemon::NetworkMobile) {
340
 
        return false;
341
 
    } 
342
 
 
343
 
    return true;
344
 
}