File indexing completed on 2024-04-28 05:44:58
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 "PkInstallPackageNames.h" 0022 0023 #include <PkStrings.h> 0024 0025 #include <KLocalizedString> 0026 #include <QStandardItemModel> 0027 0028 #include <QLoggingCategory> 0029 0030 #include <Daemon> 0031 0032 #include "IntroDialog.h" 0033 0034 PkInstallPackageNames::PkInstallPackageNames(uint xid, 0035 const QStringList &packages, 0036 const QString &interaction, 0037 const QDBusMessage &message, 0038 QWidget *parent) : 0039 SessionTask(xid, interaction, message, parent), 0040 m_packages(packages), 0041 m_message(message) 0042 { 0043 setWindowTitle(i18n("Install Packages by Name")); 0044 0045 auto introDialog = new IntroDialog(this); 0046 auto model = new QStandardItemModel(this); 0047 introDialog->setModel(model); 0048 connect(introDialog, &IntroDialog::continueChanged, this, &PkInstallPackageNames::enableButtonOk); 0049 setMainWidget(introDialog); 0050 0051 for (const QString &package : packages) { 0052 QStandardItem *item = new QStandardItem(package); 0053 item->setIcon(QIcon::fromTheme(QLatin1String("package-x-generic")).pixmap(32, 32)); 0054 item->setFlags(Qt::ItemIsEnabled); 0055 model->appendRow(item); 0056 } 0057 0058 if (m_packages.isEmpty()) { 0059 introDialog->setDescription(i18n("No package names were provided")); 0060 } else { 0061 QString description; 0062 description = i18np("Do you want to search for and install this package now?", 0063 "Do you want to search for and install these packages now?", 0064 m_packages.size()); 0065 introDialog->setDescription(description); 0066 enableButtonOk(true); 0067 } 0068 0069 QString title; 0070 // this will come from DBus interface 0071 if (parentTitle.isNull()) { 0072 title = i18np("An application wants to install a package", 0073 "An application wants to install packages", 0074 m_packages.size()); 0075 } else { 0076 title = i18np("The application <i>%2</i> wants to install a package", 0077 "The application <i>%2</i> wants to install packages", 0078 m_packages.size(), 0079 parentTitle); 0080 } 0081 setTitle(title); 0082 } 0083 0084 PkInstallPackageNames::~PkInstallPackageNames() 0085 { 0086 } 0087 0088 void PkInstallPackageNames::search() 0089 { 0090 auto transaction = new PkTransaction(this); 0091 transaction->setupTransaction(Daemon::resolve(m_packages, Transaction::FilterArch | Transaction::FilterNewest)); 0092 setTransaction(Transaction::RoleResolve, transaction); 0093 connect(transaction, &PkTransaction::finished, this, &PkInstallPackageNames::searchFinished, Qt::UniqueConnection); 0094 connect(transaction, &PkTransaction::package, this, &PkInstallPackageNames::addPackage); 0095 } 0096 0097 void PkInstallPackageNames::notFound() 0098 { 0099 if (m_alreadyInstalled.size()) { 0100 if (showWarning()) { 0101 setInfo(i18n("Failed to install packages"), 0102 i18np("The package %2 is already installed", 0103 "The packages %2 are already installed", 0104 m_alreadyInstalled.size(), 0105 m_alreadyInstalled.join(QLatin1Char(',')))); 0106 } 0107 sendErrorFinished(Failed, QLatin1String("package already found")); 0108 } else { 0109 if (showWarning()) { 0110 setInfo(i18n("Could not find %1", m_packages.join(QLatin1String(", "))), 0111 i18np("The package could not be found in any software source", 0112 "The packages could not be found in any software source", 0113 m_packages.size())); 0114 } 0115 sendErrorFinished(NoPackagesFound, QLatin1String("no package found")); 0116 } 0117 } 0118 0119 void PkInstallPackageNames::searchFailed() 0120 { 0121 sendErrorFinished(Failed, QLatin1String("failed to resolve package name")); 0122 } 0123 0124 void PkInstallPackageNames::addPackage(Transaction::Info info, const QString &packageID, const QString &summary) 0125 { 0126 if (info != Transaction::InfoInstalled) { 0127 SessionTask::addPackage(info, packageID, summary); 0128 } else { 0129 m_alreadyInstalled << Transaction::packageName(packageID); 0130 } 0131 } 0132 0133 #include "moc_PkInstallPackageNames.cpp"