26#include "config-plasma.h"
30#include <kmessagebox.h>
32#include <kdesktopfile.h>
35#include "private/applet_p.h"
40class AccessAppletJobPrivate
43 AccessAppletJobPrivate(
const KUrl &location, AccessAppletJob *owner)
66 kDebug() <<
"Plasmoid Access Job triggers an error.";
67 q->setError(job->error());
68 q->setErrorText(job->errorText());
73 if (job->
result().type() == QVariant::String) {
74 QString pluginName = job->
result().toString();
75 kDebug() <<
"Server responded with a pluginname, trying to load: " << pluginName;
79 applet->d->remoteLocation = location.prettyUrl();
82 q->setErrorText(i18n(
"The \"%1\" widget is not installed.", pluginName));
87 kDebug() <<
"Server responded with a plasmoid package";
89 QByteArray
package = job->result().toByteArray();
90 QDataStream stream(&package, QIODevice::ReadOnly);
92 KZip archive(stream.device());
93 if (!archive.open(QIODevice::ReadOnly)) {
94 kWarning() <<
"Could not open package file";
96 q->setErrorText(i18n(
"Server sent an invalid plasmoid package."));
101 const KArchiveDirectory *source = archive.directory();
104 tempDir.setAutoRemove(
false);
105 QString path = tempDir.name();
106 source->copyTo(path);
108 KDesktopFile metadata(path +
"/metadata.desktop");
109 KConfigGroup group = metadata.desktopGroup();
111 QString iconName = group.readEntry(
"Icon");
112 QString message = i18n(
"You are about to open a remote widget on your system.<br>");
113 message+= i18n(
"<table width=\"100%\">");
114 message+= i18n(
"<tr><td align=\"right\"><b>Name:</b></td><td> %1</td></tr>", group.readEntry(
"Name"));
115 message+= i18n(
"<tr><td align=\"right\"><b>Description:</b></td><td> %1</td></tr>", group.readEntry(
"Comment"));
116 message+= i18n(
"<tr><td align=\"right\"><b>Author:</b></td><td> %1 <%2></td></tr>",
117 group.readEntry(
"X-KDE-PluginInfo-Author"),
118 group.readEntry(
"X-KDE-PluginInfo-Email"));
119 message+= i18n(
"<tr><td align=\"right\"><b>Server:</b></td><td> %1</td></tr>", location.host());
120 message+= i18n(
"</table>");
121 message+= i18n(
"<br><br>Are you sure you want to open this widget on your system?");
123 KDialog *dialog =
new KDialog;
124 dialog->setWindowTitle(i18n(
"Remote Widget"));
125 dialog->setButtons(KDialog::Yes|KDialog::No);
126 dialog->setButtonText(KDialog::Yes, i18n(
"Open Widget"));
127 dialog->setButtonText(KDialog::No, i18n(
"Reject Widget"));
129 int answer = KMessageBox::createKMessageBox(dialog, KIcon(iconName), message,
130 QStringList(), QString(), 0,
131 KMessageBox::Dangerous);
134 if (answer!=KDialog::Yes) {
136 q->setErrorText(i18n(
"User rejected"));
149 applet = Applet::loadPlasmoid(path);
151 applet->d->remoteLocation = location.prettyUrl();
162 kWarning() <<
"Plasmoid access job timed out";
164 q->setErrorText(i18n(
"Timeout"));
173AccessAppletJob::AccessAppletJob(
const KUrl &location,
QObject *parent)
175 d(new AccessAppletJobPrivate(location, this))
177 QTimer::singleShot(30000,
this, SLOT(slotTimeout()));
180AccessAppletJob::~AccessAppletJob()
190void AccessAppletJob::start()
192#ifdef ENABLE_REMOTE_WIDGETS
193 kDebug() <<
"fetching a plasmoid from location = " << d->location.prettyUrl();
198 kWarning() <<
"libplasma was compiled without support for remote services. Accessing remote applet failed because of that.";
200 setErrorText(i18n(
"Your system does not provide support for the 'remote widgets' feature. Access Failed."));
207#include "accessappletjob.moc"
static Applet * load(const QString &name, uint appletId=0, const QVariantList &args=QVariantList())
Attempts to load an applet.
This class provides jobs for use with Plasma::Service.
This class provides a generic API for write access to settings or services.
Q_INVOKABLE KConfigGroup operationDescription(const QString &operationName)
Retrieves the parameters for a given operation.
Q_INVOKABLE ServiceJob * startOperationCall(const KConfigGroup &description, QObject *parent=0)
Called to create a ServiceJob which is associated with a given operation and parameter set.
static Service * access(const KUrl &url, QObject *parent=0)
Used to access a service from an url.
Namespace for everything in libplasma.