Fixed drag and drop of files to a forum message with utf8 chars.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4198 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-05-13 20:06:16 +00:00
parent 4d4c4c0a47
commit fcee4ebc32
2 changed files with 39 additions and 30 deletions

View File

@ -24,6 +24,7 @@
#include <QTimer> #include <QTimer>
#include <QMessageBox> #include <QMessageBox>
#include <QBuffer> #include <QBuffer>
#include <QDir>
#include "CreateChannelMsg.h" #include "CreateChannelMsg.h"
#include "gui/feeds/SubFileItem.h" #include "gui/feeds/SubFileItem.h"
@ -123,8 +124,7 @@ void CreateChannelMsg::dropEvent(QDropEvent *event)
return; return;
} }
std::cerr << "CreateChannelMsg::dropEvent() Formats"; std::cerr << "CreateChannelMsg::dropEvent() Formats" << std::endl;
std::cerr << std::endl;
QStringList formats = event->mimeData()->formats(); QStringList formats = event->mimeData()->formats();
QStringList::iterator it; QStringList::iterator it;
for(it = formats.begin(); it != formats.end(); it++) for(it = formats.begin(); it != formats.end(); it++)
@ -143,22 +143,31 @@ void CreateChannelMsg::dropEvent(QDropEvent *event)
if (event->mimeData()->hasUrls()) if (event->mimeData()->hasUrls())
{ {
std::cerr << "CreateChannelMsg::dropEvent() Urls:"; std::cerr << "CreateChannelMsg::dropEvent() Urls:" << std::endl;
std::cerr << std::endl;
QList<QUrl> urls = event->mimeData()->urls(); QList<QUrl> urls = event->mimeData()->urls();
QList<QUrl>::iterator uit; QList<QUrl>::iterator uit;
for(uit = urls.begin(); uit != urls.end(); uit++) for(uit = urls.begin(); uit != urls.end(); uit++)
{ {
std::string localpath = uit->toLocalFile().toUtf8().constData(); QString localpath = uit->toLocalFile();
std::cerr << "Whole URL: " << uit->toString().toStdString(); std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl;
std::cerr << std::endl; std::cerr << "or As Local File: " << localpath.toStdString() << std::endl;
std::cerr << "or As Local File: " << uit->toLocalFile().toStdString();
std::cerr << 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();
}
} }
} }
} }

View File

@ -277,24 +277,24 @@ void CreateForumMsg::dropEvent(QDropEvent *event)
QList<QUrl>::iterator uit; QList<QUrl>::iterator uit;
for(uit = urls.begin(); uit != urls.end(); uit++) for(uit = urls.begin(); uit != urls.end(); uit++)
{ {
std::string localpath = uit->toLocalFile().toStdString(); QString localpath = uit->toLocalFile();
std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl; std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl;
std::cerr << "or As Local File: " << localpath << 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
//Check that the file does exist and is not a directory QDir dir(localpath);
if ((-1 == stat(localpath.c_str(), &buf))) { if (dir.exists()) {
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; 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); 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(); mb.exec();
} else if (QFile::exists(localpath)) {
addAttachment(localpath.toUtf8().constData());
} else { } 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();
} }
} }
} }