[PATCH] Support looking up Plasma services.
Kevin Kofler
kevin.kofler at chello.at
Sun Jun 19 19:05:07 PDT 2011
---
SmartIcon/CMakeLists.txt | 1 +
SmartIcon/PkInstallPlasmaResources.cpp | 140 ++++++++++++++++++++++++++++++
SmartIcon/PkInstallPlasmaResources.h | 54 ++++++++++++
SmartIcon/PkInterface.cpp | 12 +++
SmartIcon/PkInterface.h | 1 +
SmartIcon/org.freedesktop.PackageKit.xml | 40 +++++++++
6 files changed, 248 insertions(+), 0 deletions(-)
diff --git a/SmartIcon/CMakeLists.txt b/SmartIcon/CMakeLists.txt
index 89bcb6a..4ca8049 100644
--- a/SmartIcon/CMakeLists.txt
+++ b/SmartIcon/CMakeLists.txt
@@ -15,6 +15,7 @@ set(kpackagekit_smart_icon_SRCS
PkInstallMimeTypes.cpp
PkInstallGStreamerResources.cpp
PkInstallFontconfigResources.cpp
+ PkInstallPlasmaResources.cpp
PkInstallPackageFiles.cpp
PkInstallProvideFiles.cpp
PkInstallCatalogs.cpp
diff --git a/SmartIcon/PkInstallPlasmaResources.cpp b/SmartIcon/PkInstallPlasmaResources.cpp
new file mode 100644
index 0000000..0c14eae
--- /dev/null
+++ b/SmartIcon/PkInstallPlasmaResources.cpp
@@ -0,0 +1,140 @@
+/***************************************************************************
+ * Copyright (C) 2009-2010 by Daniel Nicoletti *
+ * dantti85-pk at yahoo.com.br *
+ * Copyright (C) 2011 Kevin Kofler <kevin.kofler at chello.at> *
+ * *
+ * 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; see the file COPYING. If not, write to *
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "PkInstallPlasmaResources.h"
+
+#include <KpkReviewChanges.h>
+#include <KpkTransaction.h>
+#include <KpkStrings.h>
+
+#include <KLocale>
+#include <KMessageBox>
+
+#include <KDebug>
+
+PkInstallPlasmaResources::PkInstallPlasmaResources(uint xid,
+ const QStringList &resources,
+ const QString &interaction,
+ const QDBusMessage &message,
+ QWidget *parent)
+ : KpkAbstractTask(xid, interaction, message, parent),
+ m_resources(resources)
+{
+}
+
+PkInstallPlasmaResources::~PkInstallPlasmaResources()
+{
+}
+
+void PkInstallPlasmaResources::start()
+{
+ int ret = KMessageBox::Yes;
+ QStringList niceNames;
+ QStringList search;
+ if (showConfirmSearch()) {
+ // Resources are strings like "dataengine-weather"
+ foreach (const QString &service, m_resources) {
+ QString prettyService = service;
+ if (service.startsWith("dataengine-")) {
+ prettyService = i18n("%1 data engine", service.mid(11));
+ } else if (service.startsWith("scriptengine-")) {
+ prettyService = i18n("%1 script engine", service.mid(13));
+ }
+
+ niceNames << prettyService;
+ search << service;
+ }
+
+ QString message = i18np("The following service is required: <ul><li>%2</li></ul>"
+ "Do you want to search for this now?",
+ "The following services are required: <ul><li>%2</li></ul>"
+ "Do you want to search for these now?",
+ niceNames.size(),
+ niceNames.join("</li><li>"));
+
+ QString title = i18np("Plasma requires an additional service for this operation",
+ "Plasma requires additional services for this operation",
+ m_resources.size());
+
+ QString msg = "<h3>" + title + "</h3>" + message;
+ KGuiItem searchBt = KStandardGuiItem::yes();
+ searchBt.setText(i18nc("Search for packages" ,"Search"));
+ searchBt.setIcon(KIcon("edit-find"));
+ ret = KMessageBox::questionYesNoWId(parentWId(), msg, title, searchBt);
+ }
+
+ if (ret == KMessageBox::Yes) {
+ Transaction *t = Client::instance()->whatProvides(Enum::ProvidesPlasmaService,
+ search,
+ Enum::FilterNotInstalled |
+ Enum::FilterArch |
+ Enum::FilterNewest);
+ if (t->error()) {
+ QString msg(i18n("Failed to search for provides"));
+ KMessageBox::sorryWId(parentWId(), KpkStrings::daemonError(t->error()), msg);
+ sendErrorFinished(InternalError, msg);
+ } else {
+ connect(t, SIGNAL(finished(PackageKit::Enum::Exit, uint)),
+ this, SLOT(whatProvidesFinished(PackageKit::Enum::Exit)));
+ connect(t, SIGNAL(package(QSharedPointer<PackageKit::Package>)),
+ this, SLOT(addPackage(QSharedPointer<PackageKit::Package>)));
+ if (showProgress()) {
+ kTransaction()->setTransaction(t);
+ kTransaction()->show();
+ }
+ }
+ } else {
+ sendErrorFinished(Cancelled, i18n("did not agree to search"));
+ }
+}
+
+void PkInstallPlasmaResources::whatProvidesFinished(PackageKit::Enum::Exit status)
+{
+ kDebug() << "Finished.";
+ if (status == Enum::ExitSuccess) {
+ if (m_foundPackages.size()) {
+ kTransaction()->hide();
+ KpkReviewChanges *frm = new KpkReviewChanges(m_foundPackages, this, parentWId());
+ if (frm->exec(operationModes()) == 0) {
+ sendErrorFinished(Failed, "Transaction did not finish with success");
+ } else {
+ finishTaskOk();
+ }
+ } else {
+ if (showWarning()) {
+ KMessageBox::sorryWId(parentWId(),
+ i18n("Could not find service "
+ "in any configured software source"),
+ i18n("Failed to search for Plasma service"));
+ }
+ sendErrorFinished(NoPackagesFound, "failed to find Plasma service");
+ }
+ } else {
+ sendErrorFinished(Failed, "what provides failed");
+ }
+}
+
+void PkInstallPlasmaResources::addPackage(QSharedPointer<PackageKit::Package> package)
+{
+ m_foundPackages.append(package);
+}
+
+#include "PkInstallPlasmaResources.moc"
diff --git a/SmartIcon/PkInstallPlasmaResources.h b/SmartIcon/PkInstallPlasmaResources.h
new file mode 100644
index 0000000..c733d31
--- /dev/null
+++ b/SmartIcon/PkInstallPlasmaResources.h
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * Copyright (C) 2009-2010 by Daniel Nicoletti *
+ * dantti85-pk at yahoo.com.br *
+ * Copyright (C) 2011 Kevin Kofler <kevin.kofler at chello.at> *
+ * *
+ * 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; see the file COPYING. If not, write to *
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef PK_INSTALL_PLASMA_RESOURCES_H
+#define PK_INSTALL_PLASMA_RESOURCES_H
+
+#include "KpkAbstractTask.h"
+
+#include <QPackageKit>
+
+using namespace PackageKit;
+
+class PkInstallPlasmaResources : public KpkAbstractTask
+{
+Q_OBJECT
+public:
+ PkInstallPlasmaResources(uint xid,
+ const QStringList &resources,
+ const QString &interaction,
+ const QDBusMessage &message,
+ QWidget *parent = 0);
+ ~PkInstallPlasmaResources();
+
+public slots:
+ void start();
+
+private slots:
+ void whatProvidesFinished(PackageKit::Enum::Exit status);
+ void addPackage(QSharedPointer<PackageKit::Package> package);
+
+private:
+ QList<QSharedPointer<PackageKit::Package> > m_foundPackages;
+ QStringList m_resources;
+};
+
+#endif
diff --git a/SmartIcon/PkInterface.cpp b/SmartIcon/PkInterface.cpp
index 3968843..48ec0c3 100644
--- a/SmartIcon/PkInterface.cpp
+++ b/SmartIcon/PkInterface.cpp
@@ -31,6 +31,7 @@
#include "PkInstallMimeTypes.h"
#include "PkInstallGStreamerResources.h"
#include "PkInstallFontconfigResources.h"
+#include "PkInstallPlasmaResources.h"
#include "PkInstallPackageFiles.h"
#include "PkInstallProvideFiles.h"
#include "PkInstallCatalogs.h"
@@ -98,6 +99,17 @@ void PkInterface::InstallGStreamerResources(uint xid, const QStringList &resourc
task->run();
}
+void PkInterface::InstallPlasmaResources(uint xid, const QStringList &resources, const QString &interaction)
+{
+ increaseRunning();
+ kDebug() << xid << resources << interaction;
+ setDelayedReply(true);
+ PkInstallPlasmaResources *task;
+ task = new PkInstallPlasmaResources(xid, resources, interaction, message());
+ connect(task, SIGNAL(finished()), this, SLOT(decreaseRunning()));
+ task->run();
+}
+
void PkInterface::InstallMimeTypes(uint xid, const QStringList &mime_types, const QString &interaction)
{
increaseRunning();
diff --git a/SmartIcon/PkInterface.h b/SmartIcon/PkInterface.h
index 61357c6..1cad358 100644
--- a/SmartIcon/PkInterface.h
+++ b/SmartIcon/PkInterface.h
@@ -36,6 +36,7 @@ public slots:
void InstallCatalogs(uint xid, const QStringList &files, const QString &interaction);
void InstallFontconfigResources(uint xid, const QStringList &resources, const QString &interaction);
void InstallGStreamerResources(uint xid, const QStringList &resources, const QString &interaction);
+ void InstallPlasmaResources(uint xid, const QStringList &resources, const QString &interaction);
void InstallMimeTypes(uint xid, const QStringList &mime_types, const QString &interaction);
void InstallPackageFiles(uint xid, const QStringList &files, const QString &interaction);
void InstallPackageNames(uint xid, const QStringList &packages, const QString &interaction);
diff --git a/SmartIcon/org.freedesktop.PackageKit.xml b/SmartIcon/org.freedesktop.PackageKit.xml
index dd4d2e5..b89d839 100644
--- a/SmartIcon/org.freedesktop.PackageKit.xml
+++ b/SmartIcon/org.freedesktop.PackageKit.xml
@@ -404,6 +404,46 @@
</method>
<!--*****************************************************************************************-->
+ <method name="InstallPlasmaResources">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ Installs plasma resources (usually services) from a configured software source.
+ </doc:para>
+ </doc:description>
+ </doc:doc>
+ <arg type="u" name="xid" direction="in">
+ <doc:doc>
+ <doc:summary>
+ <doc:para>
+ The X window handle ID, used for focus stealing prevention and setting modality.
+ </doc:para>
+ </doc:summary>
+ </doc:doc>
+ </arg>
+ <arg type="as" name="resources" direction="in">
+ <doc:doc>
+ <doc:summary>
+ <doc:para>
+ An array of service descriptors from Plasma, e.g. <doc:tt>dataengine-weather</doc:tt>
+ </doc:para>
+ </doc:summary>
+ </doc:doc>
+ </arg>
+ <arg type="s" name="interaction" direction="in">
+ <doc:doc>
+ <doc:summary>
+ <doc:para>
+ An optional interaction mode, e.g.
+ <doc:tt>show-confirm-search,show-confirm-deps,show-confirm-install,show-progress,show-finished,show-warning</doc:tt>
+ </doc:para>
+ </doc:summary>
+ </doc:doc>
+ </arg>
+ </method>
+
+ <!--*****************************************************************************************-->
<method name="RemovePackageByFiles">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<doc:doc>
--
1.7.4.4
--nextPart2287280.guGZAbPHS5
Content-Type: text/x-patch; name="packagekit-plasma.patch"
Content-Disposition: attachment; filename="packagekit-plasma.patch"
Content-Transfer-Encoding: 8Bit
More information about the PackageKit
mailing list