~ubuntu-branches/ubuntu/vivid/muon/vivid-proposed

« back to all changes in this revision

Viewing changes to discover/ApplicationUpdates.cpp

Tags: upstream-1.3.65
Import upstream version 1.3.65

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright © 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>       *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or         *
 
5
 *   modify it under the terms of the GNU General Public License as        *
 
6
 *   published by the Free Software Foundation; either version 2 of        *
 
7
 *   the License or (at your option) version 3 or any later version        *
 
8
 *   accepted by the membership of KDE e.V. (or its successor approved     *
 
9
 *   by the membership of KDE e.V.), which shall act as a proxy            *
 
10
 *   defined in Section 14 of version 3 of the license.                    *
 
11
 *                                                                         *
 
12
 *   This program is distributed in the hope that it will be useful,       *
 
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
15
 *   GNU General Public License for more details.                          *
 
16
 *                                                                         *
 
17
 *   You should have received a copy of the GNU General Public License     *
 
18
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 
19
 ***************************************************************************/
 
20
 
 
21
#include "ApplicationUpdates.h"
 
22
#include "BackendsSingleton.h"
 
23
#include <Application.h>
 
24
#include <ApplicationBackend.h>
 
25
#include "MuonInstallerMainWindow.h"
 
26
#include <LibQApt/Backend>
 
27
#include <QDebug>
 
28
 
 
29
ApplicationUpdates::ApplicationUpdates(QObject* parent): QObject(parent)
 
30
{
 
31
    QApt::Backend* backend = BackendsSingleton::self()->backend();
 
32
    connect(backend, SIGNAL(errorOccurred(QApt::ErrorCode,QVariantMap)), this,
 
33
            SLOT(errorOccurred(QApt::ErrorCode,QVariantMap)));
 
34
    connect(backend, SIGNAL(commitProgress(QString,int)),
 
35
            SIGNAL(progress(QString,int)));
 
36
    connect(backend, SIGNAL(downloadMessage(int,QString)), SIGNAL(downloadMessage(int,QString)));
 
37
    connect(backend, SIGNAL(debInstallMessage(QString)), SIGNAL(installMessage(QString)));
 
38
    connect(backend, SIGNAL(workerEvent(QApt::WorkerEvent)),
 
39
            this, SLOT(workerEvent(QApt::WorkerEvent)));
 
40
}
 
41
 
 
42
void ApplicationUpdates::upgradeAll()
 
43
{
 
44
    QApt::Backend* backend = BackendsSingleton::self()->backend();
 
45
    QApt::PackageList packages = backend->upgradeablePackages();
 
46
    foreach(QApt::Package* p, packages) {
 
47
        p->setInstall();
 
48
    }
 
49
    backend->commitChanges();
 
50
}
 
51
 
 
52
void ApplicationUpdates::workerEvent(QApt::WorkerEvent e)
 
53
{
 
54
    if(e==QApt::CommitChangesFinished) {
 
55
        qDebug() << "updates done. Reloading...";
 
56
        
 
57
        //when it's done, trigger a reload of the whole system
 
58
        BackendsSingleton::self()->applicationBackend()->reload();
 
59
        emit updatesFinnished();
 
60
    }
 
61
}
 
62
 
 
63
void ApplicationUpdates::errorOccurred(QApt::ErrorCode e, const QVariantMap&)
 
64
{
 
65
    switch(e) {
 
66
        case QApt::AuthError:
 
67
            emit updatesFinnished();
 
68
            BackendsSingleton::self()->backend()->undo();
 
69
            break;
 
70
        default:
 
71
            break;
 
72
    }
 
73
}