[PATCH] Support looking up Plasma services.
Kevin Kofler
kevin.kofler at chello.at
Sun Jun 19 18:41:32 PDT 2011
---
Sentinel/CMakeLists.txt | 1 +
Sentinel/PkInstallPlasmaResources.cpp | 174 +++++++++++++++++++++++++++++++
Sentinel/PkInstallPlasmaResources.h | 57 ++++++++++
Sentinel/PkInterface.cpp | 12 ++
Sentinel/PkInterface.h | 1 +
Sentinel/org.freedesktop.PackageKit.xml | 40 +++++++
6 files changed, 285 insertions(+), 0 deletions(-)
diff --git a/Sentinel/CMakeLists.txt b/Sentinel/CMakeLists.txt
index 2bdfe6c..b20ad30 100644
--- a/Sentinel/CMakeLists.txt
+++ b/Sentinel/CMakeLists.txt
@@ -19,6 +19,7 @@ set(sentinel_SRCS
PkInstallMimeTypes.cpp
PkInstallGStreamerResources.cpp
PkInstallFontconfigResources.cpp
+ PkInstallPlasmaResources.cpp
FilesModel.cpp
PkInstallPackageFiles.cpp
PkInstallProvideFiles.cpp
diff --git a/Sentinel/PkInstallPlasmaResources.cpp b/Sentinel/PkInstallPlasmaResources.cpp
new file mode 100644
index 0000000..509a609
--- /dev/null
+++ b/Sentinel/PkInstallPlasmaResources.cpp
@@ -0,0 +1,174 @@
+/***************************************************************************
+ * Copyright (C) 2009-2011 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 "IntroDialog.h"
+
+#include <KpkReviewChanges.h>
+#include <KpkStrings.h>
+
+#include <QStandardItemModel>
+#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_introDialog = new IntroDialog(this);
+ setMainWidget(m_introDialog);
+ QStandardItemModel *model = new QStandardItemModel(this);
+
+ // Resources are strings like "dataengine-weather"
+ foreach (const QString &service, 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));
+ }
+
+ QStandardItem *item = new QStandardItem(prettyService);
+ item->setIcon(KIcon("x-kde-nsplugin-generated").pixmap(32, 32));
+ model->appendRow(item);
+
+ m_resources << service;
+ }
+
+ QString description = i18np("The following service is required. "
+ "Do you want to search for this now?",
+ "The following services are required. "
+ "Do you want to search for these now?",
+ m_resources.size());
+
+ QString title = i18np("Plasma requires an additional service for this operation",
+ "Plasma requires additional services for this operation",
+ m_resources.size());
+
+ m_introDialog->setDescription(description);
+ m_introDialog->setTitle(title);
+}
+
+PkInstallPlasmaResources::~PkInstallPlasmaResources()
+{
+}
+
+void PkInstallPlasmaResources::slotButtonClicked(int bt)
+{
+ if (bt == KDialog::Ok) {
+ if (mainWidget() == m_introDialog) {
+ Transaction *t = new Transaction(this);
+ PkTransaction *trans = new PkTransaction(t, this);
+ connect(t, SIGNAL(finished(PackageKit::Transaction::Exit, uint)),
+ this, SLOT(whatProvidesFinished(PackageKit::Transaction::Exit)));
+ connect(t, SIGNAL(package(const PackageKit::Package &)),
+ this, SLOT(addPackage(const PackageKit::Package &)));
+ t->whatProvides(Transaction::ProvidesPlasmaService,
+ m_resources,
+ Transaction::FilterNotInstalled | Transaction::FilterArch | Transaction::FilterNewest);
+ if (t->error()) {
+ QString msg(i18n("Failed to search for provides"));
+ if (showWarning()) {
+ KMessageBox::sorry(this,
+ KpkStrings::daemonError(t->error()),
+ msg);
+ }
+ sendErrorFinished(Failed, msg);
+ }
+
+ setMainWidget(trans);
+// trans->installFiles(m_model->files());
+ enableButtonOk(false);
+ }
+ } else {
+ sendErrorFinished(Cancelled, "Aborted");
+ }
+ KDialog::slotButtonClicked(bt);
+}
+
+void PkInstallPlasmaResources::start()
+{
+
+
+// if (ret == KMessageBox::Yes) {
+// Transaction *t = new Transaction(this);
+// t->whatProvides(Transaction::ProvidesPlasmaService,
+// search,
+// Transaction::FilterNotInstalled |
+// Transaction::FilterArch |
+// Transaction::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::Transaction::Exit, uint)),
+// this, SLOT(whatProvidesFinished(PackageKit::Transaction::Exit)));
+// connect(t, SIGNAL(package(const PackageKit::Package &)),
+// this, SLOT(addPackage(const PackageKit::Package &)));
+// if (showProgress()) {
+// kTransaction()->setTransaction(t);
+// kTransaction()->show();
+// }
+// }
+// } else {
+// sendErrorFinished(Cancelled, i18n("did not agree to search"));
+// }
+}
+
+void PkInstallPlasmaResources::whatProvidesFinished(PackageKit::Transaction::Exit status)
+{
+ kDebug() << "Finished.";
+ if (status == Transaction::ExitSuccess) {
+ if (m_foundPackages.size()) {
+ KpkReviewChanges *frm = new KpkReviewChanges(m_foundPackages, this);
+ setMainWidget(frm);
+// if (frm->exec(operationModes()) == 0) {
+// sendErrorFinished(Failed, "Transaction did not finish with success");
+// } else {
+// finishTaskOk();
+// }
+ } else {
+ if (showWarning()) {
+ KMessageBox::sorry(this,
+ 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(const PackageKit::Package &package)
+{
+ m_foundPackages.append(package);
+}
+
+#include "PkInstallPlasmaResources.moc"
diff --git a/Sentinel/PkInstallPlasmaResources.h b/Sentinel/PkInstallPlasmaResources.h
new file mode 100644
index 0000000..b957f76
--- /dev/null
+++ b/Sentinel/PkInstallPlasmaResources.h
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * 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 <Transaction>
+
+using namespace PackageKit;
+
+class IntroDialog;
+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 slotButtonClicked(int bt);
+ void whatProvidesFinished(PackageKit::Transaction::Exit status);
+ void addPackage(const PackageKit::Package &package);
+
+private:
+ IntroDialog *m_introDialog;
+ QList<Package> m_foundPackages;
+ QStringList m_resources;
+};
+
+#endif
diff --git a/Sentinel/PkInterface.cpp b/Sentinel/PkInterface.cpp
index 3fef71d..ba9fc1f 100644
--- a/Sentinel/PkInterface.cpp
+++ b/Sentinel/PkInterface.cpp
@@ -30,6 +30,7 @@
#include "PkInstallMimeTypes.h"
#include "PkInstallGStreamerResources.h"
#include "PkInstallFontconfigResources.h"
+#include "PkInstallPlasmaResources.h"
#include "PkInstallPackageFiles.h"
#include "PkInstallProvideFiles.h"
#include "PkInstallCatalogs.h"
@@ -97,6 +98,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/Sentinel/PkInterface.h b/Sentinel/PkInterface.h
index 13cac77..913a74a 100644
--- a/Sentinel/PkInterface.h
+++ b/Sentinel/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/Sentinel/org.freedesktop.PackageKit.xml b/Sentinel/org.freedesktop.PackageKit.xml
index dd4d2e5..b89d839 100644
--- a/Sentinel/org.freedesktop.PackageKit.xml
+++ b/Sentinel/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="gnome-packagekit-plasma.patch"
Content-Disposition: attachment; filename="gnome-packagekit-plasma.patch"
Content-Transfer-Encoding: 8Bit
More information about the PackageKit
mailing list