mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-11-29 11:56:37 -05:00
renamed RsCollectionEditor into RsCollection. Added download of FileTree links
This commit is contained in:
parent
32be00614d
commit
74d5069225
13 changed files with 132 additions and 139 deletions
|
|
@ -23,7 +23,7 @@
|
|||
#include <QFileInfo>
|
||||
|
||||
#include "FilesDefs.h"
|
||||
#include "RsCollectionEditor.h"
|
||||
#include "RsCollection.h"
|
||||
|
||||
static QString getInfoFromFilename(const QString& filename, bool anyForUnknown, bool image)
|
||||
{
|
||||
|
|
@ -54,7 +54,7 @@ static QString getInfoFromFilename(const QString& filename, bool anyForUnknown,
|
|||
return image ? ":/images/FileTypeDocument.png" : QApplication::translate("FilesDefs", "Document");
|
||||
} else if (ext == "pdf") {
|
||||
return image ? ":/images/mimetypes/pdf.png" : QApplication::translate("FilesDefs", "Document");
|
||||
} else if (ext == RsCollectionEditor::ExtensionString) {
|
||||
} else if (ext == RsCollection::ExtensionString) {
|
||||
return image ? ":/images/mimetypes/rscollection-16.png" : QApplication::translate("FilesDefs", "RetroShare collection file");
|
||||
} else if (ext == "sub" || ext == "srt") {
|
||||
return image ? ":/images/FileTypeAny.png" : QApplication::translate("FilesDefs", "Subtitles");
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include <stdexcept>
|
||||
#include <retroshare/rsfiles.h>
|
||||
|
||||
#include "RsCollectionEditor.h"
|
||||
#include "RsCollection.h"
|
||||
#include "RsCollectionDialog.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
|
|
@ -36,15 +36,15 @@
|
|||
#include <QMessageBox>
|
||||
#include <QIcon>
|
||||
|
||||
const QString RsCollectionEditor::ExtensionString = QString("rscollection") ;
|
||||
const QString RsCollection::ExtensionString = QString("rscollection") ;
|
||||
|
||||
RsCollectionEditor::RsCollectionEditor(QObject *parent)
|
||||
RsCollection::RsCollection(QObject *parent)
|
||||
: QObject(parent), _xml_doc("RsCollection")
|
||||
{
|
||||
}
|
||||
|
||||
RsCollectionEditor::RsCollectionEditor(const FileTree& fr, QObject *parent)
|
||||
: QObject(parent), _xml_doc("RsCollection")
|
||||
RsCollection::RsCollection(const FileTree& fr)
|
||||
: _xml_doc("RsCollection")
|
||||
{
|
||||
QDomElement root = _xml_doc.createElement("RsCollection");
|
||||
_xml_doc.appendChild(root);
|
||||
|
|
@ -52,7 +52,7 @@ RsCollectionEditor::RsCollectionEditor(const FileTree& fr, QObject *parent)
|
|||
recursAddElements(_xml_doc,fr,0,root) ;
|
||||
}
|
||||
|
||||
RsCollectionEditor::RsCollectionEditor(const std::vector<DirDetails>& file_infos, QObject *parent)
|
||||
RsCollection::RsCollection(const std::vector<DirDetails>& file_infos, QObject *parent)
|
||||
: QObject(parent), _xml_doc("RsCollection")
|
||||
{
|
||||
QDomElement root = _xml_doc.createElement("RsCollection");
|
||||
|
|
@ -62,11 +62,11 @@ RsCollectionEditor::RsCollectionEditor(const std::vector<DirDetails>& file_infos
|
|||
recursAddElements(_xml_doc,file_infos[i],root) ;
|
||||
}
|
||||
|
||||
RsCollectionEditor::~RsCollectionEditor()
|
||||
RsCollection::~RsCollection()
|
||||
{
|
||||
}
|
||||
|
||||
void RsCollectionEditor::downloadFiles() const
|
||||
void RsCollection::downloadFiles() const
|
||||
{
|
||||
// print out the element names of all elements that are direct children
|
||||
// of the outermost element.
|
||||
|
|
@ -96,7 +96,7 @@ static QString purifyFileName(const QString& input,bool& bad)
|
|||
return output ;
|
||||
}
|
||||
|
||||
void RsCollectionEditor::recursCollectColFileInfos(const QDomElement& e,std::vector<ColFileInfo>& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const
|
||||
void RsCollection::recursCollectColFileInfos(const QDomElement& e,std::vector<ColFileInfo>& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const
|
||||
{
|
||||
QDomNode n = e.firstChild() ;
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ void RsCollectionEditor::recursCollectColFileInfos(const QDomElement& e,std::vec
|
|||
}
|
||||
|
||||
|
||||
void RsCollectionEditor::recursAddElements(QDomDocument& doc,const DirDetails& details,QDomElement& e) const
|
||||
void RsCollection::recursAddElements(QDomDocument& doc,const DirDetails& details,QDomElement& e) const
|
||||
{
|
||||
if (details.type == DIR_TYPE_FILE)
|
||||
{
|
||||
|
|
@ -184,7 +184,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const DirDetails& d
|
|||
}
|
||||
}
|
||||
|
||||
void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& colFileInfo,QDomElement& e) const
|
||||
void RsCollection::recursAddElements(QDomDocument& doc,const ColFileInfo& colFileInfo,QDomElement& e) const
|
||||
{
|
||||
if (colFileInfo.type == DIR_TYPE_FILE)
|
||||
{
|
||||
|
|
@ -211,7 +211,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo&
|
|||
}
|
||||
}
|
||||
|
||||
void RsCollectionEditor::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const
|
||||
void RsCollection::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const
|
||||
{
|
||||
std::vector<uint32_t> subdirs ;
|
||||
std::vector<FileTree::FileData> subfiles ;
|
||||
|
|
@ -221,7 +221,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const FileTree& ft,
|
|||
return ;
|
||||
|
||||
QDomElement d = doc.createElement("Directory") ;
|
||||
d.setAttribute(QString::fromUtf8()("name"),QString::fromUtf8(name.c_str())) ;
|
||||
d.setAttribute(QString("name"),QString::fromUtf8(name.c_str())) ;
|
||||
e.appendChild(d) ;
|
||||
|
||||
for (uint32_t i=0;i<subdirs.size();++i)
|
||||
|
|
@ -232,7 +232,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const FileTree& ft,
|
|||
QDomElement f = doc.createElement("File") ;
|
||||
|
||||
f.setAttribute(QString("name"),QString::fromUtf8(subfiles[i].name.c_str())) ;
|
||||
f.setAttribute(QString("sha1"),QString::fromStdString(subfiles[i].hash)) ;
|
||||
f.setAttribute(QString("sha1"),QString::fromStdString(subfiles[i].hash.toStdString())) ;
|
||||
f.setAttribute(QString("size"),QString::number(subfiles[i].size)) ;
|
||||
|
||||
e.appendChild(f) ;
|
||||
|
|
@ -245,7 +245,7 @@ static void showErrorBox(const QString& fileName, const QString& error)
|
|||
mb.exec();
|
||||
}
|
||||
|
||||
bool RsCollectionEditor::load(const QString& fileName, bool showError /* = true*/)
|
||||
bool RsCollection::load(const QString& fileName, bool showError /* = true*/)
|
||||
{
|
||||
|
||||
if (!checkFile(fileName,showError)) return false;
|
||||
|
|
@ -272,10 +272,10 @@ bool RsCollectionEditor::load(const QString& fileName, bool showError /* = true*
|
|||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
// check that the file is a valid rscollection file, and not a lol bomb or some shit like this
|
||||
bool RsCollectionEditor::checkFile(const QString& fileName, bool showError)
|
||||
bool RsCollection::checkFile(const QString& fileName, bool showError)
|
||||
{
|
||||
QFile file(fileName);
|
||||
|
||||
|
|
@ -342,15 +342,10 @@ bool RsCollectionEditor::checkFile(const QString& fileName, bool showError)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RsCollectionEditor::load(const FileTree& f)
|
||||
{
|
||||
}
|
||||
|
||||
bool RsCollectionEditor::load(QWidget *parent)
|
||||
bool RsCollection::load(QWidget *parent)
|
||||
{
|
||||
QString fileName;
|
||||
if (!misc::getOpenFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Open collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionEditor::ExtensionString + ")", fileName))
|
||||
if (!misc::getOpenFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Open collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollection::ExtensionString + ")", fileName))
|
||||
return false;
|
||||
|
||||
std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
|
||||
|
|
@ -358,7 +353,7 @@ bool RsCollectionEditor::load(QWidget *parent)
|
|||
return load(fileName, true);
|
||||
}
|
||||
|
||||
bool RsCollectionEditor::save(const QString& fileName) const
|
||||
bool RsCollection::save(const QString& fileName) const
|
||||
{
|
||||
QFile file(fileName);
|
||||
|
||||
|
|
@ -378,14 +373,14 @@ bool RsCollectionEditor::save(const QString& fileName) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool RsCollectionEditor::save(QWidget *parent) const
|
||||
bool RsCollection::save(QWidget *parent) const
|
||||
{
|
||||
QString fileName;
|
||||
if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Create collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionEditor::ExtensionString + ")", fileName))
|
||||
if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Create collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollection::ExtensionString + ")", fileName))
|
||||
return false;
|
||||
|
||||
if (!fileName.endsWith("." + RsCollectionEditor::ExtensionString))
|
||||
fileName += "." + RsCollectionEditor::ExtensionString ;
|
||||
if (!fileName.endsWith("." + RsCollection::ExtensionString))
|
||||
fileName += "." + RsCollection::ExtensionString ;
|
||||
|
||||
std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
|
||||
|
||||
|
|
@ -393,17 +388,17 @@ bool RsCollectionEditor::save(QWidget *parent) const
|
|||
}
|
||||
|
||||
|
||||
bool RsCollectionEditor::openNewColl(QWidget *parent)
|
||||
bool RsCollection::openNewColl(QWidget *parent)
|
||||
{
|
||||
QString fileName;
|
||||
if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE
|
||||
, QApplication::translate("RsCollectionFile", "Create collection file")
|
||||
, QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionEditor::ExtensionString + ")"
|
||||
, QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollection::ExtensionString + ")"
|
||||
, fileName,0, QFileDialog::DontConfirmOverwrite))
|
||||
return false;
|
||||
|
||||
if (!fileName.endsWith("." + RsCollectionEditor::ExtensionString))
|
||||
fileName += "." + RsCollectionEditor::ExtensionString ;
|
||||
if (!fileName.endsWith("." + RsCollection::ExtensionString))
|
||||
fileName += "." + RsCollection::ExtensionString ;
|
||||
|
||||
std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
|
||||
|
||||
|
|
@ -460,7 +455,7 @@ bool RsCollectionEditor::openNewColl(QWidget *parent)
|
|||
return _saved;
|
||||
}
|
||||
|
||||
bool RsCollectionEditor::openColl(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/)
|
||||
bool RsCollection::openColl(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/)
|
||||
{
|
||||
if (load(fileName, showError)) {
|
||||
std::vector<ColFileInfo> colFileInfos ;
|
||||
|
|
@ -474,11 +469,11 @@ bool RsCollectionEditor::openColl(const QString& fileName, bool readOnly /* = fa
|
|||
delete rcd;
|
||||
|
||||
return _saved;
|
||||
}//if (load(fileName, showError))
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
qulonglong RsCollectionEditor::size()
|
||||
qulonglong RsCollection::size()
|
||||
{
|
||||
QDomElement docElem = _xml_doc.documentElement();
|
||||
|
||||
|
|
@ -494,14 +489,14 @@ qulonglong RsCollectionEditor::size()
|
|||
return size;
|
||||
}
|
||||
|
||||
bool RsCollectionEditor::isCollectionFile(const QString &fileName)
|
||||
bool RsCollection::isCollectionFile(const QString &fileName)
|
||||
{
|
||||
QString ext = QFileInfo(fileName).suffix().toLower();
|
||||
|
||||
return (ext == RsCollectionEditor::ExtensionString);
|
||||
return (ext == RsCollection::ExtensionString);
|
||||
}
|
||||
|
||||
void RsCollectionEditor::saveColl(std::vector<ColFileInfo> colFileInfos, const QString &fileName)
|
||||
void RsCollection::saveColl(std::vector<ColFileInfo> colFileInfos, const QString &fileName)
|
||||
{
|
||||
|
||||
QDomElement root = _xml_doc.elementsByTagName("RsCollection").at(0).toElement();
|
||||
|
|
@ -56,17 +56,17 @@ public:
|
|||
};
|
||||
Q_DECLARE_METATYPE(ColFileInfo)
|
||||
|
||||
class RsCollectionEditor : public QObject
|
||||
class RsCollection : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
RsCollectionEditor(QObject *parent = 0) ;
|
||||
RsCollection(QObject *parent = 0) ;
|
||||
// create from list of files and directories
|
||||
RsCollectionEditor(const std::vector<DirDetails>& file_entries, QObject *parent = 0) ;
|
||||
RsCollectionEditor(const FileTree& fr, QObject *parent);
|
||||
virtual ~RsCollectionEditor() ;
|
||||
RsCollection(const std::vector<DirDetails>& file_entries, QObject *parent = 0) ;
|
||||
RsCollection(const FileTree& fr);
|
||||
virtual ~RsCollection() ;
|
||||
|
||||
static const QString ExtensionString ;
|
||||
|
||||
|
|
@ -76,9 +76,6 @@ public:
|
|||
bool load(QWidget *parent);
|
||||
bool load(const QString& fileName, bool showError = true);
|
||||
|
||||
// Loads from FileTree
|
||||
bool load(const FileTree& f);
|
||||
|
||||
// Save to disk
|
||||
bool save(QWidget *parent) const ;
|
||||
bool save(const QString& fileName) const ;
|
||||
|
|
@ -102,6 +99,8 @@ private:
|
|||
|
||||
void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ;
|
||||
void recursAddElements(QDomDocument&,const ColFileInfo&,QDomElement&) const;
|
||||
void recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const;
|
||||
|
||||
void recursCollectColFileInfos(const QDomElement&,std::vector<ColFileInfo>& colFileInfos,const QString& current_dir,bool bad_chars_in_parent) const ;
|
||||
// check that the file is a valid rscollection file, and not a lol bomb or some shit like this
|
||||
static bool checkFile(const QString &fileName, bool showError);
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
#include <QDateTime>
|
||||
#include <QInputDialog>
|
||||
#include "RsCollectionDialog.h"
|
||||
#include "RsCollectionEditor.h"
|
||||
#include "RsCollection.h"
|
||||
#include "util/misc.h"
|
||||
#define COLUMN_FILE 0
|
||||
#define COLUMN_FILEPATH 1
|
||||
|
|
@ -591,12 +591,12 @@ void RsCollectionDialog::changeFileName()
|
|||
QString fileName;
|
||||
if(!misc::getSaveFileName(this, RshareSettings::LASTDIR_EXTRAFILE
|
||||
, QApplication::translate("RsCollectionFile", "Create collection file")
|
||||
, QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionEditor::ExtensionString + ")"
|
||||
, QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollection::ExtensionString + ")"
|
||||
, fileName,0, QFileDialog::DontConfirmOverwrite))
|
||||
return;
|
||||
|
||||
if (!fileName.endsWith("." + RsCollectionEditor::ExtensionString))
|
||||
fileName += "." + RsCollectionEditor::ExtensionString ;
|
||||
if (!fileName.endsWith("." + RsCollection::ExtensionString))
|
||||
fileName += "." + RsCollection::ExtensionString ;
|
||||
|
||||
std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
|
||||
|
||||
|
|
@ -604,7 +604,7 @@ void RsCollectionDialog::changeFileName()
|
|||
|
||||
if(file.exists())
|
||||
{
|
||||
RsCollectionEditor collFile;
|
||||
RsCollection collFile;
|
||||
if (!collFile.checkFile(fileName,true)) return;
|
||||
|
||||
QMessageBox mb;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
****************************************************************/
|
||||
|
||||
#include "ui_RsCollectionDialog.h"
|
||||
#include "RsCollectionEditor.h"
|
||||
#include "RsCollection.h"
|
||||
#include <QFileSystemModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@
|
|||
#include <stdexcept>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
#include "RsCollectionEditor.h"
|
||||
#include "RsCollection.h"
|
||||
#include "RsUrlHandler.h"
|
||||
|
||||
bool RsUrlHandler::openUrl(const QUrl& url)
|
||||
{
|
||||
if(url.scheme() == QString("file") && url.toLocalFile().endsWith("."+RsCollectionEditor::ExtensionString))
|
||||
if(url.scheme() == QString("file") && url.toLocalFile().endsWith("."+RsCollection::ExtensionString))
|
||||
{
|
||||
RsCollectionEditor collection ;
|
||||
RsCollection collection ;
|
||||
if(collection.load(url.toLocalFile()))
|
||||
{
|
||||
collection.downloadFiles() ;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue