diff --git a/retroshare-gui/src/gui/channels/CreateChannelMsg.cpp b/retroshare-gui/src/gui/channels/CreateChannelMsg.cpp index 83e6300cd..a289a729f 100644 --- a/retroshare-gui/src/gui/channels/CreateChannelMsg.cpp +++ b/retroshare-gui/src/gui/channels/CreateChannelMsg.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "CreateChannelMsg.h" #include "gui/feeds/SubFileItem.h" @@ -123,8 +124,7 @@ void CreateChannelMsg::dropEvent(QDropEvent *event) return; } - std::cerr << "CreateChannelMsg::dropEvent() Formats"; - std::cerr << std::endl; + std::cerr << "CreateChannelMsg::dropEvent() Formats" << std::endl; QStringList formats = event->mimeData()->formats(); QStringList::iterator it; for(it = formats.begin(); it != formats.end(); it++) @@ -143,22 +143,31 @@ void CreateChannelMsg::dropEvent(QDropEvent *event) if (event->mimeData()->hasUrls()) { - std::cerr << "CreateChannelMsg::dropEvent() Urls:"; - std::cerr << std::endl; + std::cerr << "CreateChannelMsg::dropEvent() Urls:" << std::endl; QList urls = event->mimeData()->urls(); QList::iterator uit; for(uit = urls.begin(); uit != urls.end(); uit++) { - std::string localpath = uit->toLocalFile().toUtf8().constData(); - std::cerr << "Whole URL: " << uit->toString().toStdString(); - std::cerr << std::endl; - std::cerr << "or As Local File: " << uit->toLocalFile().toStdString(); - std::cerr << std::endl; + QString localpath = uit->toLocalFile(); + std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl; + std::cerr << "or As Local File: " << localpath.toStdString() << std::endl; - if (localpath.size() > 0) + if (localpath.isEmpty() == false) { - addAttachment(localpath); + // Check that the file does exist and is not a directory + QDir dir(localpath); + if (dir.exists()) { + std::cerr << "CreateChannelMsg::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,this); + mb.exec(); + } else if (QFile::exists(localpath)) { + addAttachment(localpath.toUtf8().constData()); + } else { + std::cerr << "CreateChannelMsg::dropEvent() file does not exists."<< std::endl; + QMessageBox mb(tr("Drop file error."), tr("File not found or file name not accepted."),QMessageBox::Information,QMessageBox::Ok,0,0,this); + mb.exec(); + } } } } diff --git a/retroshare-gui/src/gui/forums/CreateForumMsg.cpp b/retroshare-gui/src/gui/forums/CreateForumMsg.cpp index f08e5786a..9adf342b0 100644 --- a/retroshare-gui/src/gui/forums/CreateForumMsg.cpp +++ b/retroshare-gui/src/gui/forums/CreateForumMsg.cpp @@ -255,46 +255,46 @@ void CreateForumMsg::dropEvent(QDropEvent *event) { if (!(Qt::CopyAction & event->possibleActions())) { - std::cerr << "CreateForumMsg::dropEvent() Rejecting uncopyable DropAction" << std::endl; + std::cerr << "CreateForumMsg::dropEvent() Rejecting uncopyable DropAction" << std::endl; /* can't do it */ return; } - std::cerr << "CreateForumMsg::dropEvent() Formats" << std::endl; + std::cerr << "CreateForumMsg::dropEvent() Formats" << std::endl; QStringList formats = event->mimeData()->formats(); QStringList::iterator it; for(it = formats.begin(); it != formats.end(); it++) { - std::cerr << "Format: " << (*it).toStdString() << std::endl; + std::cerr << "Format: " << (*it).toStdString() << std::endl; } if (event->mimeData()->hasUrls()) { - std::cerr << "CreateForumMsg::dropEvent() Urls:" << std::endl; + std::cerr << "CreateForumMsg::dropEvent() Urls:" << std::endl; QList urls = event->mimeData()->urls(); QList::iterator uit; for(uit = urls.begin(); uit != urls.end(); uit++) { - std::string localpath = uit->toLocalFile().toStdString(); - std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl; - std::cerr << "or As Local File: " << localpath << std::endl; + QString localpath = uit->toLocalFile(); + std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl; + std::cerr << "or As Local File: " << localpath.toStdString() << std::endl; - if (localpath.size() > 0) + if (localpath.isEmpty() == false) { - struct stat buf; - //Check that the file does exist and is not a directory - if ((-1 == stat(localpath.c_str(), &buf))) { - std::cerr << "CreateForumMsg::dropEvent() file does not exists."<< std::endl; - QMessageBox mb(tr("Drop file error."), tr("File not found or file name not accepted."),QMessageBox::Information,QMessageBox::Ok,0,0,this); - mb.exec(); - } else if (S_ISDIR(buf.st_mode)) { - std::cerr << "CreateForumMsg::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,this); - mb.exec(); + // Check that the file does exist and is not a directory + QDir dir(localpath); + if (dir.exists()) { + std::cerr << "CreateForumMsg::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,this); + mb.exec(); + } else if (QFile::exists(localpath)) { + addAttachment(localpath.toUtf8().constData()); } else { - CreateForumMsg::addAttachment(localpath); + std::cerr << "CreateForumMsg::dropEvent() file does not exists."<< std::endl; + QMessageBox mb(tr("Drop file error."), tr("File not found or file name not accepted."),QMessageBox::Information,QMessageBox::Ok,0,0,this); + mb.exec(); } } }