2018-11-11 14:41:06 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/common/RsCollection.h *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2011, Retroshare Team <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2011-11-07 18:07:25 -05:00
|
|
|
|
|
|
|
// Implements a RetroShare collection file. Such a file contains
|
|
|
|
//
|
|
|
|
// - a directory structure
|
|
|
|
// - retroshare links to put files in
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-05-29 10:49:45 -04:00
|
|
|
#include <QObject>
|
2011-11-07 18:07:25 -05:00
|
|
|
#include <QString>
|
|
|
|
#include <QDomDocument>
|
2014-05-29 10:49:45 -04:00
|
|
|
#include <QFile>
|
2011-11-07 18:07:25 -05:00
|
|
|
#include <retroshare/rsfiles.h>
|
2014-05-29 10:49:45 -04:00
|
|
|
#include <QMetaType>
|
2011-11-07 18:07:25 -05:00
|
|
|
|
|
|
|
class QDomElement ;
|
2012-08-31 10:07:15 -04:00
|
|
|
class QWidget;
|
2011-11-07 18:07:25 -05:00
|
|
|
|
2014-05-29 10:49:45 -04:00
|
|
|
class ColFileInfo
|
2011-11-07 18:07:25 -05:00
|
|
|
{
|
|
|
|
public:
|
2014-05-29 10:49:45 -04:00
|
|
|
ColFileInfo(): name(""), size(0), path(""), hash(""), type(0), filename_has_wrong_characters(false), checked(false) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
QString name ;
|
|
|
|
qulonglong size ;
|
|
|
|
QString path ;
|
|
|
|
QString hash ;
|
|
|
|
uint8_t type;
|
|
|
|
bool filename_has_wrong_characters ;
|
|
|
|
std::vector<ColFileInfo> children;
|
|
|
|
bool checked;
|
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(ColFileInfo)
|
|
|
|
|
2017-10-19 16:14:04 -04:00
|
|
|
class RsCollection : public QObject
|
2014-05-29 10:49:45 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2011-11-07 18:07:25 -05:00
|
|
|
|
2014-05-29 10:49:45 -04:00
|
|
|
public:
|
2011-11-07 18:07:25 -05:00
|
|
|
|
2017-10-19 16:14:04 -04:00
|
|
|
RsCollection(QObject *parent = 0) ;
|
2017-10-19 04:19:56 -04:00
|
|
|
// create from list of files and directories
|
2017-11-12 16:46:29 -05:00
|
|
|
RsCollection(const std::vector<DirDetails>& file_entries, FileSearchFlags flags, QObject *parent = 0) ;
|
2020-03-11 18:11:59 -04:00
|
|
|
RsCollection(const RsFileTree& fr);
|
2017-10-19 16:14:04 -04:00
|
|
|
virtual ~RsCollection() ;
|
2014-05-29 10:49:45 -04:00
|
|
|
|
2017-10-21 11:35:06 -04:00
|
|
|
void merge_in(const QString& fname,uint64_t size,const RsFileHash& hash) ;
|
2020-03-11 18:11:59 -04:00
|
|
|
void merge_in(const RsFileTree& tree) ;
|
2014-05-29 10:49:45 -04:00
|
|
|
|
2017-10-21 11:35:06 -04:00
|
|
|
static const QString ExtensionString ;
|
2011-11-07 18:07:25 -05:00
|
|
|
|
2017-10-19 04:19:56 -04:00
|
|
|
// Loads file from disk.
|
|
|
|
bool load(QWidget *parent);
|
2014-05-29 10:49:45 -04:00
|
|
|
bool load(const QString& fileName, bool showError = true);
|
2011-11-25 18:46:41 -05:00
|
|
|
|
2017-10-19 04:19:56 -04:00
|
|
|
// Save to disk
|
|
|
|
bool save(QWidget *parent) const ;
|
2014-05-29 10:49:45 -04:00
|
|
|
bool save(const QString& fileName) const ;
|
|
|
|
|
|
|
|
// Open new collection
|
2017-11-14 11:52:48 -05:00
|
|
|
bool openNewColl(QWidget *parent, QString fileName = "");
|
2014-05-29 10:49:45 -04:00
|
|
|
// Open existing collection
|
|
|
|
bool openColl(const QString& fileName, bool readOnly = false, bool showError = true);
|
2011-11-07 18:07:25 -05:00
|
|
|
|
2017-10-19 04:19:56 -04:00
|
|
|
// Download the content.
|
|
|
|
void downloadFiles() const ;
|
2018-05-11 04:14:06 -04:00
|
|
|
// Auto Download all the content.
|
|
|
|
void autoDownloadFiles() const ;
|
2011-11-07 18:07:25 -05:00
|
|
|
|
2017-10-19 04:19:56 -04:00
|
|
|
qulonglong size();
|
2011-12-10 16:38:38 -05:00
|
|
|
|
2014-05-29 10:49:45 -04:00
|
|
|
static bool isCollectionFile(const QString& fileName);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void saveColl(std::vector<ColFileInfo> colFileInfos, const QString& fileName);
|
2011-12-10 16:38:38 -05:00
|
|
|
|
2017-10-19 04:19:56 -04:00
|
|
|
private:
|
2011-11-07 18:07:25 -05:00
|
|
|
|
2017-11-12 16:46:29 -05:00
|
|
|
void recursAddElements(QDomDocument&, const DirDetails&, QDomElement&, FileSearchFlags flags) const ;
|
2014-05-29 10:49:45 -04:00
|
|
|
void recursAddElements(QDomDocument&,const ColFileInfo&,QDomElement&) const;
|
2020-03-11 18:11:59 -04:00
|
|
|
void recursAddElements(
|
|
|
|
QDomDocument& doc, const RsFileTree& ft, uint32_t index,
|
|
|
|
QDomElement& e ) const;
|
2017-10-19 16:14:04 -04:00
|
|
|
|
2014-05-29 10:49:45 -04:00
|
|
|
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);
|
2018-05-11 04:14:06 -04:00
|
|
|
// Auto Download recursively.
|
|
|
|
void autoDownloadFiles(ColFileInfo colFileInfo, QString dlDir) const ;
|
2011-11-07 18:07:25 -05:00
|
|
|
|
2017-10-19 04:19:56 -04:00
|
|
|
QDomDocument _xml_doc ;
|
2014-05-29 10:49:45 -04:00
|
|
|
QString _fileName ;
|
|
|
|
bool _saved;
|
2017-10-21 11:35:06 -04:00
|
|
|
QDomElement _root ;
|
2011-11-09 16:26:51 -05:00
|
|
|
|
2017-10-19 04:19:56 -04:00
|
|
|
friend class RsCollectionDialog ;
|
2011-11-07 18:07:25 -05:00
|
|
|
};
|
|
|
|
|