mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 14:12:43 -04:00
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:
parent
27bc170471
commit
d07dbffa69
3 changed files with 50 additions and 7 deletions
|
@ -36,6 +36,7 @@
|
||||||
#include "msgs/MessageComposer.h"
|
#include "msgs/MessageComposer.h"
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
#include "common/PeerDefs.h"
|
#include "common/PeerDefs.h"
|
||||||
|
#include "common/RsCollectionFile.h"
|
||||||
#include "gui/connect/ConfCertDialog.h"
|
#include "gui/connect/ConfCertDialog.h"
|
||||||
|
|
||||||
#include <retroshare/rsfiles.h>
|
#include <retroshare/rsfiles.h>
|
||||||
|
@ -556,7 +557,18 @@ QString RetroShareLink::toHtmlFull() const
|
||||||
|
|
||||||
QString RetroShareLink::toHtmlSize() 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)
|
bool RetroShareLink::checkName(const QString& name)
|
||||||
|
|
|
@ -132,21 +132,23 @@ RsCollectionFile::RsCollectionFile(const std::vector<DirDetails>& file_infos)
|
||||||
recursAddElements(_xml_doc,file_infos[i],root) ;
|
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);
|
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.setWindowIcon(QIcon(":/images/rstray3.png"));
|
||||||
mb.exec();
|
mb.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsCollectionFile::load(const QString& filename)
|
bool RsCollectionFile::load(const QString& filename, bool showError /*= true*/)
|
||||||
{
|
{
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadOnly))
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
std::cerr << "Cannot open file " << filename.toStdString() << " !!" << std::endl;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +158,9 @@ bool RsCollectionFile::load(const QString& filename)
|
||||||
if (ok) {
|
if (ok) {
|
||||||
_filename = filename;
|
_filename = filename;
|
||||||
} else {
|
} else {
|
||||||
showError(filename, QApplication::translate("RsCollectionFile", "Error parsing xml file"));
|
if (showError) {
|
||||||
|
showErrorBox(filename, QApplication::translate("RsCollectionFile", "Error parsing xml file"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
|
@ -170,7 +174,7 @@ bool RsCollectionFile::load()
|
||||||
|
|
||||||
std::cerr << "Got file name: " << filename.toStdString() << std::endl;
|
std::cerr << "Got file name: " << filename.toStdString() << std::endl;
|
||||||
|
|
||||||
return load(filename);
|
return load(filename, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsCollectionFile::save(const QString& filename) const
|
bool RsCollectionFile::save(const QString& filename) const
|
||||||
|
@ -206,3 +210,26 @@ bool RsCollectionFile::save() const
|
||||||
|
|
||||||
return save(filename);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ class RsCollectionFile
|
||||||
|
|
||||||
// Loads file from disk.
|
// Loads file from disk.
|
||||||
bool load();
|
bool load();
|
||||||
bool load(const QString& filename);
|
bool load(const QString& filename, bool showError = true);
|
||||||
|
|
||||||
// Save to disk
|
// Save to disk
|
||||||
bool save() const ;
|
bool save() const ;
|
||||||
|
@ -56,6 +56,10 @@ class RsCollectionFile
|
||||||
// Download the content.
|
// Download the content.
|
||||||
void downloadFiles() const ;
|
void downloadFiles() const ;
|
||||||
|
|
||||||
|
qulonglong size();
|
||||||
|
|
||||||
|
static bool isCollectionFile(const QString& filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct DLinfo
|
struct DLinfo
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue