From fc9ed005bf7215ae300988b115e670491b397b1e Mon Sep 17 00:00:00 2001 From: joss17 Date: Mon, 11 May 2009 14:35:50 +0000 Subject: [PATCH] Refuse directory drop for extrafile git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1220 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/chat/PopupChatDialog.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 199af8f95..c3e698850 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -20,6 +20,7 @@ ****************************************************************/ #include +#include #include "PopupChatDialog.h" @@ -849,7 +850,7 @@ void PopupChatDialog::dropEvent(QDropEvent *event) if (event->mimeData()->hasUrls()) { - std::cerr << "GeneralMsgDialog::dropEvent() Urls:"; + std::cerr << "PopupChatDialog::dropEvent() Urls:"; std::cerr << std::endl; QList urls = event->mimeData()->urls(); @@ -864,8 +865,21 @@ void PopupChatDialog::dropEvent(QDropEvent *event) if (localpath.size() > 0) { - - PopupChatDialog::addAttachment(localpath); + struct stat buf; + //Check that the file does exist and is not a directory + if ((-1 == stat(localpath.c_str(), &buf))) { + std::cerr << "PopupChatDialog::dropEvent() file does not exists."<< std::endl; + QMessageBox mb(tr("Drop file error."), tr("The dropped does not exist."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } else if (S_ISDIR(buf.st_mode)) { + std::cerr << "PopupChatDialog::dropEvent() directory not accepted."<< std::endl; + QMessageBox mb(tr("Drop file error."), tr("Directory can't be dropped, only files are accepted."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } else { + PopupChatDialog::addAttachment(localpath); + } } } }