File indexing completed on 2024-04-14 15:48:51
0001 /*************************************************************************** 0002 * Copyright (C) 2008-2011 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; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 0019 ***************************************************************************/ 0020 0021 #include "DBusInterface.h" 0022 0023 #include "apperdadaptor.h" 0024 0025 #include <QtDBus/QDBusConnection> 0026 0027 #ifdef HAVE_DEBCONFKDE 0028 #include <KDialog> 0029 #include <KWindowSystem> 0030 #include <Transaction> 0031 using namespace PackageKit; 0032 #endif 0033 0034 #include <QLoggingCategory> 0035 0036 Q_DECLARE_LOGGING_CATEGORY(APPER_DAEMON) 0037 0038 DBusInterface::DBusInterface(QObject *parent) : 0039 QObject(parent) 0040 { 0041 qCDebug(APPER_DAEMON) << "Creating Helper"; 0042 (void) new ApperdAdaptor(this); 0043 if (!QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.apperd"))) { 0044 qCDebug(APPER_DAEMON) << "another helper is already running"; 0045 return; 0046 } 0047 0048 if (!QDBusConnection::sessionBus().registerObject(QStringLiteral("/"), this)) { 0049 qCDebug(APPER_DAEMON) << "unable to register service interface to dbus"; 0050 return; 0051 } 0052 } 0053 0054 DBusInterface::~DBusInterface() 0055 { 0056 qCDebug(APPER_DAEMON) << "-------------DBusInterface-------------" << QThread::currentThreadId(); 0057 } 0058 0059 void DBusInterface::RefreshCache() 0060 { 0061 emit refreshCache(); 0062 } 0063 0064 void DBusInterface::SetupDebconfDialog(const QString &tid, const QString &socketPath, uint xidParent) 0065 { 0066 #ifdef HAVE_DEBCONFKDE 0067 qCDebug(APPER_DAEMON) << tid << socketPath << xidParent; 0068 DebconfGui *gui; 0069 if (m_debconfGuis.contains(socketPath)) { 0070 gui = m_debconfGuis[socketPath]; 0071 } else { 0072 // Create the Transaction object to delete 0073 // the DebconfGui class when the transaction finishes 0074 auto transaction = new Transaction(QDBusObjectPath(tid)); 0075 transaction->setProperty("socketPath", socketPath); 0076 connect(transaction, &Transaction::finished, this, &DBusInterface::transactionFinished); 0077 0078 // Setup the Debconf dialog 0079 gui = new DebconfGui(socketPath); 0080 gui->setWindowModality(Qt::WindowModal); 0081 gui->setWindowFlags(Qt::Dialog); 0082 m_debconfGuis[socketPath] = gui; 0083 connect(gui, SIGNAL(activated()), this, SLOT(debconfActivate())); 0084 connect(gui, SIGNAL(deactivated()), gui, SLOT(hide())); 0085 } 0086 gui->setProperty("xidParent", xidParent); 0087 #else 0088 Q_UNUSED(tid) 0089 Q_UNUSED(socketPath) 0090 Q_UNUSED(xidParent) 0091 qCDebug(APPER_DAEMON) << "Not compiled with Debconf support - ignoring"; 0092 #endif //HAVE_DEBCONFKDE 0093 } 0094 0095 void DBusInterface::WatchTransaction(const QDBusObjectPath &tid) 0096 { 0097 emit watchTransaction(tid); 0098 } 0099 0100 void DBusInterface::debconfActivate() 0101 { 0102 #ifdef HAVE_DEBCONFKDE 0103 // Correct the parent 0104 qCDebug(APPER_DAEMON); 0105 DebconfGui *gui = qobject_cast<DebconfGui*>(sender()); 0106 uint xidParent = gui->property("xidParent").toUInt(); 0107 KWindowSystem::setMainWindow(gui, xidParent); 0108 gui->show(); 0109 #endif 0110 } 0111 0112 void DBusInterface::transactionFinished() 0113 { 0114 #ifdef HAVE_DEBCONFKDE 0115 QString socketPath = sender()->property("socketPath").toString(); 0116 if (m_debconfGuis.contains(socketPath)) { 0117 // remove the gui from the list and also delete it 0118 m_debconfGuis.take(socketPath)->deleteLater(); 0119 } 0120 #endif // HAVE_DEBCONFKDE 0121 } 0122 0123 #include "moc_DBusInterface.cpp"