1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/***************************************************************************
* Copyright (C) 2008-2011 Daniel Nicoletti *
* dantti12@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "DBusInterface.h"
#include "apperdadaptor.h"
#include <QtDBus/QDBusConnection>
#ifdef HAVE_DEBCONFKDE
#include <KDialog>
#include <KWindowSystem>
#include <Transaction>
using namespace PackageKit;
#endif
#include <KDebug>
DBusInterface::DBusInterface(QObject *parent) :
QObject(parent)
{
kDebug() << "Creating Helper";
(void) new ApperdAdaptor(this);
if (!QDBusConnection::sessionBus().registerService("org.kde.apperd")) {
kDebug() << "another helper is already running";
return;
}
if (!QDBusConnection::sessionBus().registerObject("/", this)) {
kDebug() << "unable to register service interface to dbus";
return;
}
}
DBusInterface::~DBusInterface()
{
kDebug() << "-------------DBusInterface-------------" << QThread::currentThreadId();
}
void DBusInterface::RefreshCache()
{
emit refreshCache();
}
void DBusInterface::SetupDebconfDialog(const QString &tid, const QString &socketPath, uint xidParent)
{
#ifdef HAVE_DEBCONFKDE
kDebug() << tid << socketPath << xidParent;
DebconfGui *gui;
if (m_debconfGuis.contains(socketPath)) {
gui = m_debconfGuis[socketPath];
} else {
// Create the Transaction object to delete
// the DebconfGui class when the transaction finishes
Transaction *transaction = new Transaction(QDBusObjectPath(tid));
transaction->setProperty("socketPath", socketPath);
connect(transaction, SIGNAL(finished(PackageKit::Transaction::Exit,uint)),
this, SLOT(transactionFinished()));
// Setup the Debconf dialog
gui = new DebconfGui(socketPath);
gui->setWindowModality(Qt::WindowModal);
gui->setWindowFlags(Qt::Dialog);
m_debconfGuis[socketPath] = gui;
connect(gui, SIGNAL(activated()), this, SLOT(debconfActivate()));
connect(gui, SIGNAL(deactivated()), gui, SLOT(hide()));
}
gui->setProperty("xidParent", xidParent);
#else
Q_UNUSED(tid)
Q_UNUSED(socketPath)
Q_UNUSED(xidParent)
kDebug() << "Not compiled with Debconf support - ignoring";
#endif //HAVE_DEBCONFKDE
}
void DBusInterface::WatchTransaction(const QDBusObjectPath &tid)
{
emit watchTransaction(tid);
}
void DBusInterface::debconfActivate()
{
#ifdef HAVE_DEBCONFKDE
// Correct the parent
kDebug();
DebconfGui *gui = qobject_cast<DebconfGui*>(sender());
uint xidParent = gui->property("xidParent").toUInt();
KWindowSystem::setMainWindow(gui, xidParent);
gui->show();
#endif
}
void DBusInterface::transactionFinished()
{
#ifdef HAVE_DEBCONFKDE
QString socketPath = sender()->property("socketPath").toString();
if (m_debconfGuis.contains(socketPath)) {
// remove the gui from the list and also delete it
m_debconfGuis.take(socketPath)->deleteLater();
}
#endif // HAVE_DEBCONFKDE
}
|