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

0001 /**************************************************************************
0002 *   Copyright (C) 2009-2011 by Daniel Nicoletti                           *
0003  *   dantti12@gmail.com                                                    *
0004 *                                                                         *
0005 *   This program is free software; you can redistribute it and/or modify  *
0006 *   it under the terms of the GNU General Public License as published by  *
0007 *   the Free Software Foundation; either version 2 of the License, or     *
0008 *   (at your option) any later version.                                   *
0009 *                                                                         *
0010 *   This program is distributed in the hope that it will be useful,       *
0011 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013 *   GNU General Public License for more details.                          *
0014 *                                                                         *
0015 *   You should have received a copy of the GNU General Public License     *
0016 *   along with this program; see the file COPYING. If not, write to       *
0017 *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
0018 *   Boston, MA 02110-1301, USA.                                           *
0019 ***************************************************************************/
0020 
0021 #include "PkInstallPrinterDrivers.h"
0022 
0023 #include <Daemon>
0024 
0025 #include <PkStrings.h>
0026 
0027 #include <KLocalizedString>
0028 
0029 #include <QLoggingCategory>
0030 
0031 #include <QTextStream>
0032 
0033 PkInstallPrinterDrivers::PkInstallPrinterDrivers(uint xid,
0034                                                  const QStringList &resources,
0035                                                  const QString &interaction,
0036                                                  const QDBusMessage &message,
0037                                                  QWidget *parent) :
0038     SessionTask(xid, interaction, message, parent),
0039     m_resources(resources)
0040 {
0041     setWindowTitle(i18n("Install Printer Drivers"));
0042     // TODO confirm operation
0043     QStringList search;
0044     for (const QString &deviceid : resources) {
0045         QString mfg, mdl;
0046         const QStringList fields = deviceid.split(QLatin1Char(';'));
0047         for (const QString &field : fields) {
0048             const QString keyvalue = field.trimmed();
0049             if (keyvalue.startsWith(QLatin1String("MFG:"))) {
0050                 mfg = keyvalue.mid(4);
0051             } else if (keyvalue.startsWith(QLatin1String("MDL:"))) {
0052                 mdl = keyvalue.mid(4);
0053             }
0054         }
0055 
0056         if (!mfg.isEmpty() && !mdl.isEmpty()) {
0057             QString prov;
0058             QTextStream out(&prov);
0059             out << mfg.toLower().replace(QLatin1Char(' '), QLatin1Char('_')) << QLatin1Char(';')
0060                 << mdl.toLower().replace(QLatin1Char(' '), QLatin1Char('_')) << QLatin1Char(';');
0061             search << prov;
0062         }
0063     }
0064 
0065     auto transaction = new PkTransaction(this);
0066     Transaction *t;
0067     t = Daemon::whatProvides(search,
0068                              Transaction::FilterNotInstalled | Transaction::FilterArch |  Transaction::FilterNewest);
0069     transaction->setupTransaction(t);
0070     setTransaction(Transaction::RoleWhatProvides, transaction);
0071     connect(transaction, &PkTransaction::finished, this, &PkInstallPrinterDrivers::searchFinished, Qt::UniqueConnection);
0072     connect(transaction, &PkTransaction::package, this, &PkInstallPrinterDrivers::addPackage);
0073 }
0074 
0075 PkInstallPrinterDrivers::~PkInstallPrinterDrivers()
0076 {
0077 }
0078 
0079 void PkInstallPrinterDrivers::notFound()
0080 {
0081     if (showWarning()) {
0082         setInfo(i18n("Failed to search for printer driver"),
0083                 i18n("Could not find printer driver "
0084                      "in any configured software source"));
0085     }
0086     sendErrorFinished(NoPackagesFound, QLatin1String("failed to find printer driver"));
0087 }
0088 
0089 #include "moc_PkInstallPrinterDrivers.cpp"