diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index 346e3abb9..fc2ff9d52 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -19,6 +19,7 @@ #include "src/core.h" #include "src/misc/style.h" +#include "src/widget/widget.h" #include #include @@ -326,7 +327,6 @@ void FileTransferWidget::onFileTransferFinished(ToxFile file) ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/yes.svg")); ui->topButton->setObjectName("ok"); - ui->topButton->setEnabled(openExtensions.contains(QFileInfo(file.fileName).suffix())); ui->topButton->show(); ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/dir.svg")); @@ -431,11 +431,12 @@ void FileTransferWidget::handleButton(QPushButton *btn) if(btn->objectName() == "ok") { - QDesktopServices::openUrl(QUrl("file://" + fileInfo.filePath, QUrl::TolerantMode)); + if (Widget::confirmExecutableOpen(QFileInfo(fileInfo.filePath))) + QDesktopServices::openUrl(QUrl("file://" + fileInfo.filePath, QUrl::TolerantMode)); } else if (btn->objectName() == "dir") { - QString dirPath = QDir(QFileInfo(fileInfo.filePath).dir()).path(); + QString dirPath = QFileInfo(fileInfo.filePath).dir().path(); QDesktopServices::openUrl(QUrl("file://" + dirPath, QUrl::TolerantMode)); } diff --git a/src/widget/form/filesform.cpp b/src/widget/form/filesform.cpp index 426fa0a68..9373b5552 100644 --- a/src/widget/form/filesform.cpp +++ b/src/widget/form/filesform.cpp @@ -16,6 +16,7 @@ #include "filesform.h" #include "ui_mainwindow.h" +#include "src/widget/widget.h" #include #include #include @@ -80,6 +81,10 @@ void FilesForm::onFileUploadComplete(const QString& path) void FilesForm::onFileActivated(QListWidgetItem* item) { ListWidgetItem* tmp = dynamic_cast (item); + + if (!Widget::confirmExecutableOpen(QFileInfo(tmp->path))) + return; + QUrl url = QUrl::fromLocalFile(tmp->path); qDebug() << "Opening '" << url << "'"; QDesktopServices::openUrl(url); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index e0da17cdb..476ad41b9 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -498,6 +498,19 @@ void Widget::onTransferClicked() activeChatroomWidget = nullptr; } +bool Widget::confirmExecutableOpen(const QFileInfo file) +{ + if (file.isExecutable()) + { + if(!GUI::askQuestion(tr("Executable file", "popup title"), tr("You have asked qTox to open an executable file. Executable files can potentially damage your computer. Are you sure want to open this file?", "popup text"), false, true)) + { + return false; + } + } + + return true; +} + void Widget::onIconClick(QSystemTrayIcon::ActivationReason reason) { switch (reason) diff --git a/src/widget/widget.h b/src/widget/widget.h index e8f7d0d2b..eaa3342ef 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "form/addfriendform.h" #include "form/settingswidget.h" #include "form/settings/identityform.h" @@ -69,6 +70,8 @@ public: virtual void changeEvent(QEvent *event); virtual void resizeEvent(QResizeEvent *event); + static bool confirmExecutableOpen(const QFileInfo file); + void clearAllReceipts(); void reloadHistory();