File indexing completed on 2022-09-27 16:24:38

0001 /***************************************************************************
0002  *   Copyright (C) 2009-2011 by Daniel Nicoletti                           *
0003  *   dantti12@gmail.com                                                    *
0004  *   Copyright (C) 2011 Kevin Kofler <kevin.kofler@chello.at>              *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; see the file COPYING. If not, write to       *
0018  *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
0019  *   Boston, MA 02110-1301, USA.                                           *
0020  ***************************************************************************/
0021 
0022 #include "PkInstallPlasmaResources.h"
0023 
0024 #include "IntroDialog.h"
0025 
0026 #include <Daemon>
0027 #include <PkStrings.h>
0028 
0029 #include <QStandardItemModel>
0030 #include <KLocalizedString>
0031 
0032 #include <QLoggingCategory>
0033 
0034 PkInstallPlasmaResources::PkInstallPlasmaResources(uint xid,
0035                                                    const QStringList &resources,
0036                                                    const QString &interaction,
0037                                                    const QDBusMessage &message,
0038                                                    QWidget *parent)
0039     : SessionTask(xid, interaction, message, parent)
0040 {
0041     setWindowTitle(i18n("Install Plasma Resources"));
0042 
0043     auto introDialog = new IntroDialog(this);
0044     auto model = new QStandardItemModel(this);
0045     introDialog->setModel(model);
0046     connect(introDialog, &IntroDialog::continueChanged, this, &PkInstallPlasmaResources::enableButtonOk);
0047     setMainWidget(introDialog);
0048 
0049     // Resources are strings like "dataengine-weather"
0050     for (const QString &service : resources) {
0051         QString prettyService = service;
0052         if (service.startsWith(QLatin1String("dataengine-"))) {
0053             prettyService = i18n("%1 data engine", service.mid(11));
0054         } else if (service.startsWith(QLatin1String("scriptengine-"))) {
0055             prettyService = i18n("%1 script engine", service.mid(13));
0056         }
0057 
0058         auto item = new QStandardItem(prettyService);
0059         item->setIcon(QIcon::fromTheme(QLatin1String("application-x-plasma")).pixmap(32, 32));
0060         item->setFlags(Qt::ItemIsEnabled);
0061         model->appendRow(item);
0062 
0063         m_resources << service;
0064     }
0065 
0066     if (m_resources.isEmpty()) {
0067         introDialog->setDescription(i18n("No supported resources were provided"));
0068     } else {
0069         QString description = i18np("The following service is required. "
0070                                     "Do you want to search for this now?",
0071                                     "The following services are required. "
0072                                     "Do you want to search for these now?",
0073                                     m_resources.size());
0074         introDialog->setDescription(description);
0075         enableButtonOk(true);
0076     }
0077 
0078     QString title = i18np("Plasma requires an additional service for this operation",
0079                           "Plasma requires additional services for this operation",
0080                           m_resources.size());
0081 
0082     setTitle(title);
0083 }
0084 
0085 PkInstallPlasmaResources::~PkInstallPlasmaResources()
0086 {
0087 }
0088 
0089 void PkInstallPlasmaResources::search()
0090 {
0091     auto transaction = new PkTransaction(this);
0092     Transaction *t;
0093     t = Daemon::whatProvides(m_resources,
0094                              Transaction::FilterNotInstalled | Transaction::FilterArch | Transaction::FilterNewest);
0095     transaction->setupTransaction(t);
0096     setTransaction(Transaction::RoleWhatProvides, transaction);
0097     connect(transaction, &PkTransaction::finished, this, &PkInstallPlasmaResources::searchFinished, Qt::UniqueConnection);
0098     connect(transaction, &PkTransaction::package, this, &PkInstallPlasmaResources::addPackage);
0099 }
0100 
0101 void PkInstallPlasmaResources::notFound()
0102 {
0103     QString msg = i18n("Failed to search for Plasma service");
0104     if (showWarning()) {
0105         setInfo(msg,
0106                 i18n("Could not find service "
0107                      "in any configured software source"));
0108     }
0109     sendErrorFinished(NoPackagesFound, msg);
0110 }
0111 
0112 #include "moc_PkInstallPlasmaResources.cpp"