Added the real size of all files of a collection to the link when added with drag and drop.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4722 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-12-10 21:38:38 +00:00
parent 27bc170471
commit d07dbffa69
3 changed files with 50 additions and 7 deletions

View File

@ -36,6 +36,7 @@
#include "msgs/MessageComposer.h"
#include "util/misc.h"
#include "common/PeerDefs.h"
#include "common/RsCollectionFile.h"
#include "gui/connect/ConfCertDialog.h"
#include <retroshare/rsfiles.h>
@ -556,7 +557,18 @@ QString RetroShareLink::toHtmlFull() const
QString RetroShareLink::toHtmlSize() const
{
return QString("<a href=\"") + toString() + "\">" + name() +"</a>" + " " + "<font color=\"blue\">" + "(" + misc::friendlyUnit(_size) + ")" +"</font>";
QString size = QString("(%1)").arg(misc::friendlyUnit(_size));
if (RsCollectionFile::isCollectionFile(name())) {
FileInfo finfo;
if (rsFiles->FileDetails(hash().toStdString(), RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL, finfo)) {
RsCollectionFile collection;
if (collection.load(QString::fromUtf8(finfo.path.c_str()), false)) {
size += QString(" [%1]").arg(misc::friendlyUnit(collection.size()));
}
}
}
QString link = QString("<a href=\"%1\">%2</a> <font color=\"blue\">%3</font>").arg(toString()).arg(name()).arg(size);
return link;
}
bool RetroShareLink::checkName(const QString& name)

View File

@ -132,21 +132,23 @@ RsCollectionFile::RsCollectionFile(const std::vector<DirDetails>& file_infos)
recursAddElements(_xml_doc,file_infos[i],root) ;
}
static void showError(const QString& filename, const QString& error)
static void showErrorBox(const QString& filename, const QString& error)
{
QMessageBox mb(QMessageBox::Warning, QObject::tr("Treatment of collection file has failed"), QObject::tr("The collection file %1 could not be openned.\nReported error is: %2").arg(filename).arg(error), QMessageBox::Ok);
mb.setWindowIcon(QIcon(":/images/rstray3.png"));
mb.exec();
}
bool RsCollectionFile::load(const QString& filename)
bool RsCollectionFile::load(const QString& filename, bool showError /*= true*/)
{
QFile file(filename);
if (!file.open(QIODevice::ReadOnly))
{
std::cerr << "Cannot open file " << filename.toStdString() << " !!" << std::endl;
showError(filename, QApplication::translate("RsCollectionFile", "Cannot open file %1").arg(filename));
if (showError) {
showErrorBox(filename, QApplication::translate("RsCollectionFile", "Cannot open file %1").arg(filename));
}
return false;
}
@ -156,7 +158,9 @@ bool RsCollectionFile::load(const QString& filename)
if (ok) {
_filename = filename;
} else {
showError(filename, QApplication::translate("RsCollectionFile", "Error parsing xml file"));
if (showError) {
showErrorBox(filename, QApplication::translate("RsCollectionFile", "Error parsing xml file"));
}
}
return ok;
@ -170,7 +174,7 @@ bool RsCollectionFile::load()
std::cerr << "Got file name: " << filename.toStdString() << std::endl;
return load(filename);
return load(filename, true);
}
bool RsCollectionFile::save(const QString& filename) const
@ -206,3 +210,26 @@ bool RsCollectionFile::save() const
return save(filename);
}
qulonglong RsCollectionFile::size()
{
QDomElement docElem = _xml_doc.documentElement();
std::vector<DLinfo> dlinfos;
recursCollectDLinfos(docElem, dlinfos, QString());
uint64_t size = 0;
for (uint32_t i = 0; i < dlinfos.size(); ++i) {
size += dlinfos[i].size;
}
return size;
}
bool RsCollectionFile::isCollectionFile(const QString &filename)
{
QString ext = QFileInfo(filename).suffix().toLower();
return (ext == RsCollectionFile::ExtensionString);
}

View File

@ -47,7 +47,7 @@ class RsCollectionFile
// Loads file from disk.
bool load();
bool load(const QString& filename);
bool load(const QString& filename, bool showError = true);
// Save to disk
bool save() const ;
@ -56,6 +56,10 @@ class RsCollectionFile
// Download the content.
void downloadFiles() const ;
qulonglong size();
static bool isCollectionFile(const QString& filename);
private:
struct DLinfo
{