File indexing completed on 2024-04-14 15:48:57

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 "PkIsInstalled.h"
0022 
0023 #include <Daemon>
0024 
0025 #include <PkStrings.h>
0026 
0027 #include <KLocalizedString>
0028 #include <QLoggingCategory>
0029 
0030 Q_DECLARE_LOGGING_CATEGORY(APPER_SESSION)
0031 
0032 PkIsInstalled::PkIsInstalled(const QString &package_name,
0033                              const QString &interaction,
0034                              const QDBusMessage &message,
0035                              QWidget *parent)
0036  : SessionTask(0, interaction, message, parent),
0037    m_packageName(package_name),
0038    m_message(message)
0039 {
0040     setWindowTitle(i18n("Querying if a Package is Installed"));
0041 
0042     auto transaction = new PkTransaction(this);
0043     transaction->setupTransaction(Daemon::resolve(m_packageName, Transaction::FilterInstalled));
0044     setTransaction(Transaction::RoleResolve, transaction);
0045     connect(transaction, &PkTransaction::finished, this, &PkIsInstalled::searchFinished, Qt::UniqueConnection);
0046     connect(transaction, &PkTransaction::package, this, &PkIsInstalled::addPackage);
0047 }
0048 
0049 PkIsInstalled::~PkIsInstalled()
0050 {
0051 }
0052 
0053 void PkIsInstalled::searchFinished(PkTransaction::ExitStatus status)
0054 {
0055     qCDebug(APPER_SESSION);
0056     if (status == PkTransaction::Success) {
0057         QDBusMessage reply = m_message.createReply();
0058         reply << (bool) foundPackagesSize();
0059         sendMessageFinished(reply);
0060     } else if (status == PkTransaction::Cancelled) {
0061         sendErrorFinished(Cancelled, i18n("User canceled the transaction"));
0062     } else {
0063         sendErrorFinished(InternalError, i18n("An unknown error happened"));
0064     }
0065 }
0066 
0067 #include "moc_PkIsInstalled.cpp"