File indexing completed on 2024-04-28 09:40:24
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 "PkSearchFile.h" 0022 0023 #include <Daemon> 0024 0025 #include <PkStrings.h> 0026 #include <PackageModel.h> 0027 0028 #include <KLocalizedString> 0029 0030 #include <QLoggingCategory> 0031 0032 Q_DECLARE_LOGGING_CATEGORY(APPER_SESSION) 0033 0034 PkSearchFile::PkSearchFile(const QString &file_name, 0035 const QString &interaction, 0036 const QDBusMessage &message, 0037 QWidget *parent) 0038 : SessionTask(0, interaction, message, parent), 0039 m_fileName(file_name), 0040 m_message(message) 0041 { 0042 setWindowTitle(i18n("Search Packages that Provides Files")); 0043 0044 // Check for a leading slash '/' return with an error if it's not there.. 0045 if (!m_fileName.startsWith(QLatin1Char('/'))) { 0046 sendErrorFinished(Failed, QLatin1String("Only full file name path is supported")); 0047 return; 0048 } 0049 0050 auto transaction = new PkTransaction(this); 0051 transaction->setupTransaction(Daemon::searchFiles(m_fileName, Transaction::FilterNewest)); 0052 setTransaction(Transaction::RoleSearchFile, transaction); 0053 connect(transaction, &PkTransaction::finished, this, &PkSearchFile::searchFinished, Qt::UniqueConnection); 0054 connect(transaction, &PkTransaction::package, this, &PkSearchFile::addPackage); 0055 } 0056 0057 PkSearchFile::~PkSearchFile() 0058 { 0059 } 0060 0061 void PkSearchFile::searchSuccess() 0062 { 0063 QModelIndex index = model()->index(0, 0); 0064 bool installed = false; 0065 QString packageID; 0066 if (index.isValid()) { 0067 Transaction::Info info; 0068 info = index.data(PackageModel::InfoRole).value<Transaction::Info>(); 0069 installed = info == Transaction::InfoInstalled; 0070 packageID = index.data(PackageModel::IdRole).toString(); 0071 } 0072 QDBusMessage reply = m_message.createReply(); 0073 reply << installed; 0074 reply << Transaction::packageName(packageID); 0075 qCDebug(APPER_SESSION) << reply; 0076 sendMessageFinished(reply); 0077 } 0078 0079 void PkSearchFile::notFound() 0080 { 0081 QString msg(i18n("The file name could not be found in any software source")); 0082 setError(i18n("Could not find %1", m_fileName), msg); 0083 sendErrorFinished(NoPackagesFound, msg); 0084 } 0085 0086 #include "moc_PkSearchFile.cpp"