From 6ef3059cedf995ecf129290a3734f2bb18a15792 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Fri, 29 Apr 2011 20:45:36 +0200 Subject: [PATCH] Provide a confirmation dialog for scripted remote widgets Make really really sure the user wants to install the widget on his system. Indeed, they're scripted and the user might not trust the source so provide some information on them and the ability to cancel the action. Implementation wise it uses a KMessageBox from a job which is really not great but the best we can do so far (remote widget support needs a refactoring to be able to improve that). Also, the bad bad man forced me to use a HTML table in the message box label to align properly the information... yes, aseigo, looking at you... the 90s are calling their HTML tables back! --- remote/accessappletjob.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/remote/accessappletjob.cpp b/remote/accessappletjob.cpp index 88bbb3de5..ca4f9a553 100644 --- a/remote/accessappletjob.cpp +++ b/remote/accessappletjob.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include "package.h" @@ -104,6 +105,39 @@ public: QString path = tempDir.name(); source->copyTo(path); + KDesktopFile metadata(path + "/metadata.desktop"); + KConfigGroup group = metadata.desktopGroup(); + + QString iconName = group.readEntry("Icon"); + QString message = i18n("You are about to open a remote widget on your system.
"); + message+= i18n(""); + message+= i18n("", group.readEntry("Name")); + message+= i18n("", group.readEntry("Comment")); + message+= i18n("", + group.readEntry("X-KDE-PluginInfo-Author"), + group.readEntry("X-KDE-PluginInfo-Email")); + message+= i18n("", location.host()); + message+= i18n("
Name:  %1
Description:  %1
Author:  %1 <%2>
Server:  %1
"); + message+= i18n("

Are you sure you want to open this widget on your system?"); + + KDialog *dialog = new KDialog; + dialog->setWindowTitle(i18n("Remote Widget")); + dialog->setButtons(KDialog::Yes|KDialog::No); + dialog->setButtonText(KDialog::Yes, i18n("Open Widget")); + dialog->setButtonText(KDialog::No, i18n("Reject Widget")); + + int answer = KMessageBox::createKMessageBox(dialog, KIcon(iconName), message, + QStringList(), QString(), 0, + KMessageBox::Dangerous); + //int answer = KMessageBox::questionYesNo(0, message, i18n("Remote Widget")); + + if (answer!=KDialog::Yes) { + q->setError(-1); + q->setErrorText(i18n("User rejected")); + q->emitResult(); + return; + } + /** QString metadataFilename = path + "/metadata.desktop"; KDesktopFile cfg(metadataFilename);