~dantti/apper/master

« back to all changes in this revision

Viewing changes to Sentinel/PkInstallPlasmaResources.cpp

  • Committer: Daniel Nicoletti
  • Date: 2012-12-16 13:51:04 UTC
  • Revision ID: git-v1:4e1499a55d1ec8a637f03979cde84aaa4a4440ba
Renaming ApperSentinel to ApperPkSession since that's all it will do now

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2009-2011 by Daniel Nicoletti                           *
3
 
 *   dantti12@gmail.com                                                    *
4
 
 *   Copyright (C) 2011 Kevin Kofler <kevin.kofler@chello.at>              *
5
 
 *                                                                         *
6
 
 *   This program is free software; you can redistribute it and/or modify  *
7
 
 *   it under the terms of the GNU General Public License as published by  *
8
 
 *   the Free Software Foundation; either version 2 of the License, or     *
9
 
 *   (at your option) any later version.                                   *
10
 
 *                                                                         *
11
 
 *   This program is distributed in the hope that it will be useful,       *
12
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 
 *   GNU General Public License for more details.                          *
15
 
 *                                                                         *
16
 
 *   You should have received a copy of the GNU General Public License     *
17
 
 *   along with this program; see the file COPYING. If not, write to       *
18
 
 *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
19
 
 *   Boston, MA 02110-1301, USA.                                           *
20
 
 ***************************************************************************/
21
 
 
22
 
#include "PkInstallPlasmaResources.h"
23
 
 
24
 
#include "IntroDialog.h"
25
 
 
26
 
#include <PkStrings.h>
27
 
 
28
 
#include <QStandardItemModel>
29
 
#include <KLocale>
30
 
 
31
 
#include <KDebug>
32
 
 
33
 
PkInstallPlasmaResources::PkInstallPlasmaResources(uint xid,
34
 
                                                   const QStringList &resources,
35
 
                                                   const QString &interaction,
36
 
                                                   const QDBusMessage &message,
37
 
                                                   QWidget *parent)
38
 
    : SessionTask(xid, interaction, message, parent)
39
 
{
40
 
    setWindowTitle(i18n("Install Plasma Resources"));
41
 
 
42
 
    IntroDialog *introDialog = new IntroDialog(this);
43
 
    QStandardItemModel *model = new QStandardItemModel(this);
44
 
    introDialog->setModel(model);
45
 
    connect(introDialog, SIGNAL(continueChanged(bool)),
46
 
            this, SLOT(enableButtonOk(bool)));
47
 
    setMainWidget(introDialog);
48
 
 
49
 
    // Resources are strings like "dataengine-weather"
50
 
    foreach (const QString &service, resources) {
51
 
        QString prettyService = service;
52
 
        if (service.startsWith(QLatin1String("dataengine-"))) {
53
 
            prettyService = i18n("%1 data engine", service.mid(11));
54
 
        } else if (service.startsWith(QLatin1String("scriptengine-"))) {
55
 
            prettyService = i18n("%1 script engine", service.mid(13));
56
 
        }
57
 
 
58
 
        QStandardItem *item = new QStandardItem(prettyService);
59
 
        item->setIcon(KIcon("application-x-plasma").pixmap(32, 32));
60
 
        item->setFlags(Qt::ItemIsEnabled);
61
 
        model->appendRow(item);
62
 
 
63
 
        m_resources << service;
64
 
    }
65
 
 
66
 
    if (m_resources.isEmpty()) {
67
 
        introDialog->setDescription(i18n("No supported resources were provided"));
68
 
    } else {
69
 
        QString description = i18np("The following service is required. "
70
 
                                    "Do you want to search for this now?",
71
 
                                    "The following services are required. "
72
 
                                    "Do you want to search for these now?",
73
 
                                    m_resources.size());
74
 
        introDialog->setDescription(description);
75
 
        enableButtonOk(true);
76
 
    }
77
 
 
78
 
    QString title = i18np("Plasma requires an additional service for this operation",
79
 
                          "Plasma requires additional services for this operation",
80
 
                          m_resources.size());
81
 
 
82
 
    setTitle(title);
83
 
}
84
 
 
85
 
PkInstallPlasmaResources::~PkInstallPlasmaResources()
86
 
{
87
 
}
88
 
 
89
 
void PkInstallPlasmaResources::search()
90
 
{
91
 
    PkTransaction *transaction = new PkTransaction(this);
92
 
    setTransaction(Transaction::RoleWhatProvides, transaction);
93
 
    connect(transaction, SIGNAL(finished(PkTransaction::ExitStatus)),
94
 
            this, SLOT(searchFinished(PkTransaction::ExitStatus)), Qt::UniqueConnection);
95
 
    connect(transaction, SIGNAL(package(PackageKit::Transaction::Info,QString,QString)),
96
 
            this, SLOT(addPackage(PackageKit::Transaction::Info,QString,QString)));
97
 
    transaction->whatProvides(Transaction::ProvidesPlasmaService,
98
 
                              m_resources,
99
 
                              Transaction::FilterNotInstalled | Transaction::FilterArch | Transaction::FilterNewest);
100
 
    if (transaction->error()) {
101
 
        QString msg(i18n("Failed to search for provides"));
102
 
        if (showWarning()) {
103
 
            setError(msg,
104
 
                     PkStrings::daemonError(transaction->error()));
105
 
        }
106
 
        sendErrorFinished(Failed, msg);
107
 
    }
108
 
}
109
 
 
110
 
void PkInstallPlasmaResources::notFound()
111
 
{
112
 
    QString msg = i18n("Failed to search for Plasma service");
113
 
    if (showWarning()) {
114
 
        setInfo(msg,
115
 
                i18n("Could not find service "
116
 
                     "in any configured software source"));
117
 
    }
118
 
    sendErrorFinished(NoPackagesFound, msg);
119
 
}
120
 
 
121
 
#include "PkInstallPlasmaResources.moc"