various improvements to collection links

This commit is contained in:
csoler 2017-10-19 10:19:56 +02:00
parent 9206daca37
commit 32be00614d
7 changed files with 69 additions and 20 deletions

View File

@ -71,11 +71,12 @@ void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const Di
std::cerr << "(EE) Cannot request dir details for pointer " << dd.children[i].ref << std::endl;
}
bool FileTreeImpl::getDirectoryContent(uint32_t index,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const
bool FileTreeImpl::getDirectoryContent(uint32_t index,std::string& name,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const
{
if(index >= mDirs.size())
return false ;
name = mDirs[index].name;
subdirs = mDirs[index].subdirs ;
subfiles.clear() ;

View File

@ -10,7 +10,7 @@ public:
}
virtual std::string toRadix64() const ;
virtual bool getDirectoryContent(uint32_t index,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const ;
virtual bool getDirectoryContent(uint32_t index,std::string& name,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const ;
virtual void print() const ;
bool serialise(unsigned char *& data,uint32_t& data_size) const ;

View File

@ -158,7 +158,7 @@ public:
};
virtual uint32_t root() const { return 0;}
virtual bool getDirectoryContent(uint32_t index,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const = 0;
virtual bool getDirectoryContent(uint32_t index,std::string& name,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const = 0;
virtual void print() const=0;

View File

@ -1014,6 +1014,7 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point )
switch (type) {
case DIR_TYPE_DIR :
contextMnu.addAction(openfolderAct) ;
contextMnu.addAction(copylinkAct) ;
contextMnu.addSeparator() ;//------------------------------------
contextMnu.addMenu(&collectionMenu) ;
break ;

View File

@ -1393,10 +1393,12 @@ static void processList(const QStringList &list, const QString &textSingular, co
case TYPE_COLLECTION:
{
//FileHierarchy fh ;
//fh.initFromRadix(_radix);
FileTree *ft = FileTree::create(_radix.toStdString()) ;
QMessageBox::information(NULL,"Unimplemented code","File collection links not handled yet.") ;
RsCollectionEditor colled(*ft,NULL) ;
colled.exec();
delete ft;
}
break;

View File

@ -43,6 +43,15 @@ RsCollectionEditor::RsCollectionEditor(QObject *parent)
{
}
RsCollectionEditor::RsCollectionEditor(const FileTree& fr, QObject *parent)
: QObject(parent), _xml_doc("RsCollection")
{
QDomElement root = _xml_doc.createElement("RsCollection");
_xml_doc.appendChild(root);
recursAddElements(_xml_doc,fr,0,root) ;
}
RsCollectionEditor::RsCollectionEditor(const std::vector<DirDetails>& file_infos, QObject *parent)
: QObject(parent), _xml_doc("RsCollection")
{
@ -186,7 +195,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo&
f.setAttribute(QString("size"),QString::number(colFileInfo.size)) ;
e.appendChild(f) ;
}
}
else if (colFileInfo.type == DIR_TYPE_DIR)
{
QDomElement d = doc.createElement("Directory") ;
@ -194,7 +203,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo&
d.setAttribute(QString("name"),colFileInfo.name) ;
for (std::vector<ColFileInfo>::const_iterator it = colFileInfo.children.begin(); it != colFileInfo.children.end(); ++it)
{
{
recursAddElements(doc,(*it),d) ;
}
@ -202,6 +211,34 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo&
}
}
void RsCollectionEditor::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const
{
std::vector<uint32_t> subdirs ;
std::vector<FileTree::FileData> subfiles ;
std::string name;
if(!ft.getDirectoryContent(index,name,subdirs,subfiles))
return ;
QDomElement d = doc.createElement("Directory") ;
d.setAttribute(QString::fromUtf8()("name"),QString::fromUtf8(name.c_str())) ;
e.appendChild(d) ;
for (uint32_t i=0;i<subdirs.size();++i)
recursAddElements(doc,ft,subdirs[i],d) ;
for(uint32_t i=0;i<subfiles.size();++i)
{
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("size"),QString::number(subfiles[i].size)) ;
e.appendChild(f) ;
}
}
static void showErrorBox(const QString& fileName, const QString& error)
{
QMessageBox mb(QMessageBox::Warning, QObject::tr("Failed to process collection file"), QObject::tr("The collection file %1 could not be opened.\nReported error is: \n\n%2").arg(fileName).arg(error), QMessageBox::Ok);
@ -306,6 +343,10 @@ bool RsCollectionEditor::checkFile(const QString& fileName, bool showError)
return false;
}
bool RsCollectionEditor::load(const FileTree& f)
{
}
bool RsCollectionEditor::load(QWidget *parent)
{
QString fileName;

View File

@ -63,20 +63,24 @@ class RsCollectionEditor : public QObject
public:
RsCollectionEditor(QObject *parent = 0) ;
// create from list of files and directories
// 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() ;
static const QString ExtensionString ;
// Loads file from disk.
bool load(QWidget *parent);
// Loads file from disk.
bool load(QWidget *parent);
bool load(const QString& fileName, bool showError = true);
// Save to disk
bool save(QWidget *parent) const ;
// Loads from FileTree
bool load(const FileTree& f);
// Save to disk
bool save(QWidget *parent) const ;
bool save(const QString& fileName) const ;
// Open new collection
@ -84,28 +88,28 @@ public:
// Open existing collection
bool openColl(const QString& fileName, bool readOnly = false, bool showError = true);
// Download the content.
void downloadFiles() const ;
// Download the content.
void downloadFiles() const ;
qulonglong size();
qulonglong size();
static bool isCollectionFile(const QString& fileName);
private slots:
void saveColl(std::vector<ColFileInfo> colFileInfos, const QString& fileName);
private:
private:
void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ;
void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ;
void recursAddElements(QDomDocument&,const ColFileInfo&,QDomElement&) 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);
QDomDocument _xml_doc ;
QDomDocument _xml_doc ;
QString _fileName ;
bool _saved;
friend class RsCollectionDialog ;
friend class RsCollectionDialog ;
};