Some more changes for utf8 in Windows.

Changes in RetroShareLink and drag'n'drop of files.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3511 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-09-17 21:54:25 +00:00
parent fff12a58c6
commit 5277ca61e2
6 changed files with 106 additions and 107 deletions

View File

@ -20,6 +20,7 @@
****************************************************************/ ****************************************************************/
#include <QFile> #include <QFile>
#include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QShortcut> #include <QShortcut>
#include <QWidgetAction> #include <QWidgetAction>
@ -1561,7 +1562,7 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file)
// sprintf(fileSizeChar, "%lld", file->FileSize()); // sprintf(fileSizeChar, "%lld", file->FileSize());
// std::string fileSize = *(&fileSizeChar); // std::string fileSize = *(&fileSizeChar);
std::string mesgString = RetroShareLink(QString::fromStdString(file->FileName()), std::string mesgString = RetroShareLink(QString::fromUtf8(file->FileName().c_str()),
file->FileSize(), file->FileSize(),
QString::fromStdString(file->FileHash())).toHtml().toStdString() ; QString::fromStdString(file->FileHash())).toHtml().toStdString() ;
@ -1610,26 +1611,26 @@ void PeersDialog::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
if ((-1 == stat(localpath.c_str(), &buf))) { QDir dir(localpath);
std::cerr << "PeersDialog::dropEvent() file does not exists."<< std::endl; if (dir.exists()) {
QMessageBox mb(tr("Drop file error."), tr("File not found or file name not accepted."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.exec();
} else if (S_ISDIR(buf.st_mode)) {
std::cerr << "PeersDialog::dropEvent() directory not accepted."<< std::endl; std::cerr << "PeersDialog::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); 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.setButtonText( QMessageBox::Ok, "OK" );
mb.exec(); mb.exec();
} else if (QFile::exists(localpath)) {
PeersDialog::addAttachment(localpath.toUtf8().constData());
} else { } else {
PeersDialog::addAttachment(localpath); std::cerr << "PeersDialog::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);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.exec();
} }
} }
} }

View File

@ -252,14 +252,14 @@ bool RetroShareLink::process(std::list<std::string> *psrcIds, int flag)
case TYPE_FILE: case TYPE_FILE:
{ {
std::cerr << " RetroShareLink::process FileRequest : fileName : " << name().toStdString() << ". fileHash : " << hash().toStdString() << ". fileSize : " << size() << std::endl; std::cerr << " RetroShareLink::process FileRequest : fileName : " << name().toUtf8().constData() << ". fileHash : " << hash().toStdString() << ". fileSize : " << size() << std::endl;
std::list<std::string> srcIds; std::list<std::string> srcIds;
if (psrcIds) { if (psrcIds) {
srcIds = *psrcIds; srcIds = *psrcIds;
} }
if (rsFiles->FileRequest(name().toStdString(), hash().toStdString(), size(), "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) { if (rsFiles->FileRequest(name().toUtf8().constData(), hash().toStdString(), size(), "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) {
if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) { if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) {
QMessageBox mb(QObject::tr("File Request Confirmation"), QObject::tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0); QMessageBox mb(QObject::tr("File Request Confirmation"), QObject::tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" ); mb.setButtonText( QMessageBox::Ok, "OK" );

View File

@ -275,7 +275,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
if (!rsFiles->RequestDirDetails(dirStub.ref, details, flags) || details.type != DIR_TYPE_FILE) if (!rsFiles->RequestDirDetails(dirStub.ref, details, flags) || details.type != DIR_TYPE_FILE)
continue; continue;
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str()); RetroShareLink link(QString::fromUtf8(details.name.c_str()), details.count, details.hash.c_str());
if(link.valid() && link.type() == RetroShareLink::TYPE_FILE) if(link.valid() && link.type() == RetroShareLink::TYPE_FILE)
urls.push_back(link) ; urls.push_back(link) ;
@ -283,7 +283,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
} }
else else
{ {
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str()); RetroShareLink link(QString::fromUtf8(details.name.c_str()), details.count, details.hash.c_str());
if(link.valid() && link.type() == RetroShareLink::TYPE_FILE) if(link.valid() && link.type() == RetroShareLink::TYPE_FILE)
urls.push_back(link) ; urls.push_back(link) ;

View File

@ -920,7 +920,7 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file)
message+= RetroShareLink(QString::fromStdString(file->FileName()),file->FileSize(),QString::fromStdString(file->FileHash())).toHtmlSize(); message+= RetroShareLink(QString::fromUtf8(file->FileName().c_str()),file->FileSize(),QString::fromStdString(file->FileHash())).toHtmlSize();
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "PopupChatDialog::anchorClicked message : " << message.toStdString() << std::endl; std::cerr << "PopupChatDialog::anchorClicked message : " << message.toStdString() << std::endl;
@ -974,28 +974,26 @@ void PopupChatDialog::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::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: " << localpath;
std::cerr << 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
if ((-1 == stat(localpath.c_str(), &buf))) { QDir dir(localpath);
std::cerr << "PopupChatDialog::dropEvent() file does not exists."<< std::endl; if (dir.exists()) {
QMessageBox mb(tr("Drop file error."), tr("File not found or file name not accepted."),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; 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); 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.setButtonText( QMessageBox::Ok, "OK" );
mb.exec(); mb.exec();
} else if (QFile::exists(localpath)) {
PopupChatDialog::addAttachment(localpath.toUtf8().constData(), false);
} else { } else {
PopupChatDialog::addAttachment(localpath,false); std::cerr << "PopupChatDialog::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);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.exec();
} }
} }
} }

View File

@ -169,7 +169,7 @@ void AttachFileItem::updateItemStatic()
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
QString filename = QString::fromStdString(mFileName); QString filename = QString::fromUtf8(mFileName.c_str());
mDivisor = 1; mDivisor = 1;
if (mFileSize > 10000000) /* 10 Mb */ if (mFileSize > 10000000) /* 10 Mb */
@ -239,7 +239,7 @@ void AttachFileItem::updateItemStatic()
break; break;
case AFI_STATE_EXTRA: case AFI_STATE_EXTRA:
filename = QString::fromStdString(mPath); filename = QString::fromUtf8(mPath.c_str());
progressBar->setRange(0, 100); progressBar->setRange(0, 100);
progressBar->setFormat("HASHING"); progressBar->setFormat("HASHING");

View File

@ -264,7 +264,7 @@ void MessageComposer::recommendFriend(std::list <std::string> &peerids)
continue; continue;
} }
RetroShareLink link(QString::fromStdString(detail.name), QString::fromStdString(detail.id)); RetroShareLink link(QString::fromUtf8(detail.name.c_str()), QString::fromStdString(detail.id));
if (link.valid() == false || link.type() != RetroShareLink::TYPE_PERSON) { if (link.valid() == false || link.type() != RetroShareLink::TYPE_PERSON) {
continue; continue;
} }
@ -1297,7 +1297,7 @@ void MessageComposer::attachFile()
// select a file // select a file
QString qfile = QFileDialog::getOpenFileName(this, tr("Add Extra File"), "", "", 0, QString qfile = QFileDialog::getOpenFileName(this, tr("Add Extra File"), "", "", 0,
QFileDialog::DontResolveSymlinks); QFileDialog::DontResolveSymlinks);
std::string filePath = qfile.toStdString(); std::string filePath = qfile.toUtf8().constData();
if (filePath != "") if (filePath != "")
{ {
MessageComposer::addAttachment(filePath); MessageComposer::addAttachment(filePath);
@ -1342,7 +1342,7 @@ void MessageComposer::fileHashingFinished(AttachFileItem* file) {
return; return;
} }
RetroShareLink message(QString::fromStdString(file->FileName()), file->FileSize(), QString::fromStdString(file->FileHash())); RetroShareLink message(QString::fromUtf8(file->FileName().c_str()), file->FileSize(), QString::fromStdString(file->FileHash()));
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "MessageComposer::anchorClicked message : " << message.toHtmlFull().toStdString() << std::endl; std::cerr << "MessageComposer::anchorClicked message : " << message.toHtmlFull().toStdString() << std::endl;
#endif #endif