From ae130674ba1958f07ab1e07bb719d71567e8ec0e Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 15 Mar 2013 23:08:54 +0000 Subject: [PATCH] added warnign when openning http/https links using system services git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6226 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/MainWindow.cpp | 27 +++++++++++++++++++++++++-- retroshare-gui/src/gui/MainWindow.h | 3 ++- retroshare-gui/src/main.cpp | 4 ++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 75649350f..d22c21a78 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -205,7 +205,9 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) } /* add url handler for RetroShare links */ - QDesktopServices::setUrlHandler(RSLINK_SCHEME, this, "linkActivated"); + QDesktopServices::setUrlHandler(RSLINK_SCHEME, this, "retroshareLinkActivated"); + QDesktopServices::setUrlHandler("http", this, "externalLinkActivated"); + QDesktopServices::setUrlHandler("https", this, "externalLinkActivated"); // Setting icons this->setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png"))); @@ -1278,8 +1280,29 @@ void MainWindow::statusChangedComboBox(int index) /* no object known */ setStatus(NULL, statusComboBox->itemData(index, Qt::UserRole).toInt()); } +void MainWindow::externalLinkActivated(const QUrl &url) +{ + static bool already_warned = false ; -void MainWindow::linkActivated(const QUrl &url) + if(!already_warned) + { + QMessageBox mb(QObject::tr("Confirmation"), QObject::tr("Do you want this link to be handled by your system?")+"

"+ url.toString()+"

"+tr("Make sure this link has not been forged to drag you to a malicious website."), QMessageBox::Question, QMessageBox::Yes,QMessageBox::No, 0); + mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png"))); + + QCheckBox *checkbox = new QCheckBox("Don't ask me again") ; + mb.layout()->addWidget(checkbox) ; + + int res = mb.exec() ; + + if (res == QMessageBox::No) + return ; + else if(checkbox->isChecked()) + already_warned = true ; + } + + QDesktopServices::openUrl(url) ; +} +void MainWindow::retroshareLinkActivated(const QUrl &url) { RetroShareLink link(url); diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index 7c7824dbd..ed822d78e 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -161,7 +161,8 @@ public slots: void displayDiskSpaceWarning(int loc,int size_limit_mb) ; void checkAndSetIdle(int idleTime); - void linkActivated(const QUrl &url); + void retroshareLinkActivated(const QUrl &url); + void externalLinkActivated(const QUrl &url); protected: /** Default Constructor */ diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 6e380ea99..568b5fdb6 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -304,7 +304,7 @@ int main(int argc, char *argv[]) /* Create event receiver */ eventReceiver = new EventReceiver; if (eventReceiver->start()) { - QObject::connect(eventReceiver, SIGNAL(linkReceived(const QUrl&)), w, SLOT(linkActivated(const QUrl&))); + QObject::connect(eventReceiver, SIGNAL(linkReceived(const QUrl&)), w, SLOT(retroshareLinkActivated(const QUrl&))); } } @@ -312,7 +312,7 @@ int main(int argc, char *argv[]) /* Now use link from the command line, because no RetroShare was running */ RetroShareLink link(QString::fromStdString(url)); if (link.valid()) { - w->linkActivated(link.toUrl()); + w->retroshareLinkActivated(link.toUrl()); } }