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!
This commit is contained in:
Kevin Ottens 2011-04-29 20:45:36 +02:00
parent 280547a3b0
commit 6ef3059ced

View File

@ -27,6 +27,7 @@
#include <kzip.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <ktempdir.h>
#include <kdesktopfile.h>
#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.<br>");
message+= i18n("<table width=\"100%\">");
message+= i18n("<tr><td align=\"right\"><b>Name:</b></td><td>&nbsp; %1</td></tr>", group.readEntry("Name"));
message+= i18n("<tr><td align=\"right\"><b>Description:</b></td><td>&nbsp; %1</td></tr>", group.readEntry("Comment"));
message+= i18n("<tr><td align=\"right\"><b>Author:</b></td><td>&nbsp; %1 &lt;%2&gt;</td></tr>",
group.readEntry("X-KDE-PluginInfo-Author"),
group.readEntry("X-KDE-PluginInfo-Email"));
message+= i18n("<tr><td align=\"right\"><b>Server:</b></td><td>&nbsp; %1</td></tr>", location.host());
message+= i18n("</table>");
message+= i18n("<br><br>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);