moved check about missing local files in channel post to a later stage in the post creation (just before send) so that it always captures it

This commit is contained in:
csoler 2020-12-14 21:48:43 +01:00
parent aad27ff94b
commit 7e7f56440c
2 changed files with 44 additions and 34 deletions

View file

@ -203,7 +203,7 @@ void CreateGxsChannelMsg::pasteLink()
{ {
std::cerr << "Pasting links: " << std::endl; std::cerr << "Pasting links: " << std::endl;
QList<RetroShareLink> links,not_have ; QList<RetroShareLink> links;
RSLinkClipboard::pasteLinks(links) ; RSLinkClipboard::pasteLinks(links) ;
for(QList<RetroShareLink>::const_iterator it(links.begin());it!=links.end();++it) for(QList<RetroShareLink>::const_iterator it(links.begin());it!=links.end();++it)
@ -217,12 +217,17 @@ void CreateGxsChannelMsg::pasteLink()
FileInfo info ; FileInfo info ;
RsFileHash hash( (*it).hash().toStdString()) ; RsFileHash hash( (*it).hash().toStdString()) ;
#ifdef TO_REMOVE
if(rsFiles->alreadyHaveFile( hash,info ) ) if(rsFiles->alreadyHaveFile( hash,info ) )
addAttachment(hash, (*it).name().toUtf8().constData(), (*it).size(), true, RsPeerId()) ; #endif
addAttachment(hash, (*it).name().toUtf8().constData(), (*it).size(), rsFiles->alreadyHaveFile( hash,info ), RsPeerId()) ;
#ifdef TO_REMOVE
else else
not_have.push_back( *it ) ; not_have.push_back( *it ) ;
#endif
} }
#ifdef TO_REMOVE
if(!not_have.empty()) if(!not_have.empty())
{ {
QString msg = tr("You are about to add files you're not actually sharing. Do you still want this to happen?")+"<br><br>" ; QString msg = tr("You are about to add files you're not actually sharing. Do you still want this to happen?")+"<br><br>" ;
@ -234,6 +239,7 @@ void CreateGxsChannelMsg::pasteLink()
for(QList<RetroShareLink>::const_iterator it(not_have.begin());it!=not_have.end();++it) for(QList<RetroShareLink>::const_iterator it(not_have.begin());it!=not_have.end();++it)
addAttachment(RsFileHash((*it).hash().toStdString()), (*it).name().toUtf8().constData(), (*it).size(), false, RsPeerId()) ; addAttachment(RsFileHash((*it).hash().toStdString()), (*it).name().toUtf8().constData(), (*it).size(), false, RsPeerId()) ;
} }
#endif
} }
/* Dropping */ /* Dropping */
@ -520,7 +526,7 @@ void CreateGxsChannelMsg::addHtmlText(const QString& text)
RichTextEditWidget->setText(text) ; RichTextEditWidget->setText(text) ;
} }
void CreateGxsChannelMsg::addAttachment(const std::string &path) bool CreateGxsChannelMsg::addAttachment(const std::string &path)
{ {
/* add a SubFileItem to the attachment section */ /* add a SubFileItem to the attachment section */
#ifdef DEBUG_CREATE_GXS_MSG #ifdef DEBUG_CREATE_GXS_MSG
@ -540,13 +546,12 @@ void CreateGxsChannelMsg::addAttachment(const std::string &path)
for(it= mAttachments.begin(); it != mAttachments.end(); ++it){ for(it= mAttachments.begin(); it != mAttachments.end(); ++it){
if((*it)->FilePath() == path){ if((*it)->FilePath() == path){
QMessageBox::warning(this, tr("RetroShare"), tr("File already Added and Hashed"), QMessageBox::Ok, QMessageBox::Ok); QMessageBox::warning(this, tr("RetroShare"), tr("This file already in this post:")+"<br/>"+QString::fromStdString(path), QMessageBox::Ok, QMessageBox::Ok);
return; return false;
} }
} }
FileInfo fInfo;
std::string filename = RsDirUtil::getTopDir(path); std::string filename = RsDirUtil::getTopDir(path);
uint64_t size = 0; uint64_t size = 0;
RsFileHash hash ; RsFileHash hash ;
@ -570,7 +575,7 @@ void CreateGxsChannelMsg::addAttachment(const std::string &path)
updateAttachmentCount(); updateAttachmentCount();
return; return true;
} }
bool CreateGxsChannelMsg::setThumbNail(const std::string& path, int frame){ bool CreateGxsChannelMsg::setThumbNail(const std::string& path, int frame){
@ -724,31 +729,34 @@ void CreateGxsChannelMsg::sendMsg()
std::string msg = std::string(text.toUtf8()); std::string msg = std::string(text.toUtf8());
std::list<RsGxsFile> files; std::list<RsGxsFile> files;
std::list<RsGxsFile> missing_files;
std::list<SubFileItem *>::iterator fit; for(auto fit :mAttachments)
if (!fit->isHidden())
for(fit = mAttachments.begin(); fit != mAttachments.end(); ++fit)
{
if (!(*fit)->isHidden())
{ {
RsGxsFile fi; RsGxsFile fi;
fi.mHash = (*fit)->FileHash(); fi.mHash = fit->FileHash();
fi.mName = (*fit)->FileName(); fi.mName = fit->FileName();
fi.mSize = (*fit)->FileSize(); fi.mSize = fit->FileSize();
files.push_back(fi); files.push_back(fi);
/* commence downloads - if we don't have the file */ /* if we don't have the file, display info about it */
if (!(*fit)->done()) if (!fit->done() && fit->ready()) // Skips unhashed files.
missing_files.push_back(fi);
}
if(!missing_files.empty())
{ {
if ((*fit)->ready()) QString filesstr = "<br/>";
{
(*fit)->download(); for(auto& file: missing_files)
} filesstr += "<br/>" /*+QString::fromStdString(file.mHash.toStdString()) + " "*/ + QString::fromStdString(file.mName) ;
// Skips unhashed files.
} if(QMessageBox::Cancel == QMessageBox::warning(nullptr,tr("Post refers to non shared files"),
} tr("This post contains files that you are currently not sharing. Do you still want to post?")+filesstr,QMessageBox::Ok,QMessageBox::Cancel))
return;
} }
sendMessage(subject, msg, files); sendMessage(subject, msg, files);

View file

@ -45,7 +45,9 @@ public:
void addHtmlText(const QString& text) ; void addHtmlText(const QString& text) ;
void addSubject(const QString& text) ; void addSubject(const QString& text) ;
void addAttachment(const std::string &path);
// adds a file to be hashed and shared. Returns false if something goes wrong.
bool addAttachment(const std::string &path);
void addAttachment(const RsFileHash &hash, const std::string &fname, uint64_t size, bool local, const RsPeerId &srcId,bool assume_file_ready = false); void addAttachment(const RsFileHash &hash, const std::string &fname, uint64_t size, bool local, const RsPeerId &srcId,bool assume_file_ready = false);
void newChannelMsg(); void newChannelMsg();