2011-08-01 21:53:32 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Kevin Kofler <kevin.kofler@chello.at>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, 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 Library 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 "private/componentinstaller_p.h"
|
|
|
|
|
|
|
|
#ifdef PLASMA_ENABLE_PACKAGEKIT_SUPPORT
|
|
|
|
#include <QSet>
|
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QDBusPendingCall>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QLatin1String>
|
|
|
|
#include <QStringList>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class ComponentInstallerPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
#ifdef PLASMA_ENABLE_PACKAGEKIT_SUPPORT
|
|
|
|
QSet<QString> alreadyPrompted;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
class ComponentInstallerSingleton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ComponentInstaller self;
|
|
|
|
};
|
|
|
|
|
2012-07-19 21:16:59 +02:00
|
|
|
Q_GLOBAL_STATIC(ComponentInstallerSingleton, privateComponentInstallerSelf)
|
2011-08-01 21:53:32 +02:00
|
|
|
|
|
|
|
ComponentInstaller *ComponentInstaller::self()
|
|
|
|
{
|
2012-07-19 21:16:59 +02:00
|
|
|
return &privateComponentInstallerSelf()->self;
|
2011-08-01 21:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ComponentInstaller::ComponentInstaller()
|
|
|
|
: d(new ComponentInstallerPrivate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ComponentInstaller::~ComponentInstaller()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentInstaller::installMissingComponent(const QString &type,
|
|
|
|
const QString &name,
|
|
|
|
QWidget *parent, bool force)
|
|
|
|
{
|
|
|
|
#ifdef PLASMA_ENABLE_PACKAGEKIT_SUPPORT
|
|
|
|
QString searchString = type + '-' + name;
|
|
|
|
|
|
|
|
if (!force) {
|
|
|
|
if (d->alreadyPrompted.contains(searchString)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d->alreadyPrompted.insert(searchString);
|
|
|
|
|
|
|
|
QDBusInterface packageKit(QLatin1String("org.freedesktop.PackageKit"),
|
|
|
|
QLatin1String("/org/freedesktop/PackageKit"),
|
|
|
|
QLatin1String("org.freedesktop.PackageKit.Modify"));
|
|
|
|
// We don't check packageKit.isValid() because the service is activated on
|
|
|
|
// demand, so it will show up as "not valid".
|
|
|
|
WId wid = 0;
|
|
|
|
if (parent) {
|
|
|
|
wid = parent->winId();
|
|
|
|
}
|
|
|
|
QStringList resources;
|
|
|
|
resources.append(searchString);
|
|
|
|
packageKit.asyncCall(QLatin1String("InstallResources"), (unsigned int) wid,
|
|
|
|
QLatin1String("plasma-service"), resources, QString());
|
|
|
|
#else
|
|
|
|
Q_UNUSED(type);
|
|
|
|
Q_UNUSED(name);
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
Q_UNUSED(force);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Plasma
|