mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
started implementing RsCollectionModel
This commit is contained in:
parent
5bc071b03c
commit
97309f2f9f
@ -68,7 +68,7 @@ RsCollection::~RsCollection()
|
||||
|
||||
void RsCollection::downloadFiles() const
|
||||
{
|
||||
#ifdef TODO
|
||||
#ifdef TODO_COLLECTION
|
||||
// print out the element names of all elements that are direct children
|
||||
// of the outermost element.
|
||||
QDomElement docElem = _xml_doc.documentElement();
|
||||
@ -83,7 +83,7 @@ void RsCollection::downloadFiles() const
|
||||
|
||||
void RsCollection::autoDownloadFiles() const
|
||||
{
|
||||
#ifdef TODO
|
||||
#ifdef TODO_COLLECTION
|
||||
QDomElement docElem = _xml_doc.documentElement();
|
||||
|
||||
std::vector<ColFileInfo> colFileInfos;
|
||||
@ -322,13 +322,13 @@ void RsCollection::recursAddElements(
|
||||
d.appendChild(f) ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
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);
|
||||
mb.exec();
|
||||
}
|
||||
#endif
|
||||
|
||||
QString RsCollection::errorString(RsCollectionErrorCode code)
|
||||
{
|
||||
@ -563,6 +563,7 @@ bool RsCollection::recursParseXml(QDomDocument& doc,const QDomNode& e,const RsFi
|
||||
|
||||
n = n.nextSibling() ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool RsCollection::recursExportToXml(QDomDocument& doc,QDomElement& e,const RsFileTree::DirData& dd) const
|
||||
{
|
||||
|
@ -91,14 +91,14 @@ public:
|
||||
|
||||
// returns the file tree
|
||||
const RsFileTree& fileTree() const { return mFileTree; }
|
||||
// total size of files in the collection
|
||||
qulonglong size();
|
||||
|
||||
// Download the content.
|
||||
void downloadFiles() const ;
|
||||
// Auto Download all the content.
|
||||
void autoDownloadFiles() const ;
|
||||
|
||||
qulonglong size();
|
||||
|
||||
static bool isCollectionFile(const QString& fileName);
|
||||
|
||||
private:
|
||||
|
@ -0,0 +1,56 @@
|
||||
#include <string>
|
||||
|
||||
#include "RsCollectionModel.h"
|
||||
|
||||
// Indernal Id is always a quintptr_t (basically a uint with the size of a pointer). Depending on the
|
||||
// architecture, the pointer may have 4 or 8 bytes. We use the low-level bit for type (0=dir, 1=file) and
|
||||
// the remaining bits for the index (which will be accordingly understood as a FileIndex or a DirIndex)
|
||||
// This way, index 0 is always the top dir.
|
||||
|
||||
bool RsCollectionModel::convertIndexToInternalId(const EntryIndex& e,quintptr& ref)
|
||||
{
|
||||
ref = (e.index << 1) || e.is_file;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsCollectionModel::convertInternalIdToIndex(quintptr ref, EntryIndex& e)
|
||||
{
|
||||
e.is_file = (bool)(ref & 1);
|
||||
e.index = ref >> 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int RsCollectionModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
if(!parent.isValid())
|
||||
return mCollection.fileTree().root();
|
||||
|
||||
EntryIndex i;
|
||||
if(!convertInternalIdToIndex(parent.internalId(),i))
|
||||
return 0;
|
||||
|
||||
if(i.is_file)
|
||||
return 0;
|
||||
else
|
||||
return mCollection.fileTree().directoryData(i.index).subdirs.size();
|
||||
}
|
||||
|
||||
int RsCollectionModel::columnCount(const QModelIndex&) const
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
QVariant RsCollectionModel::headerData(int section, Qt::Orientation,int) const
|
||||
{
|
||||
switch(section)
|
||||
{
|
||||
case 0: return tr("File");
|
||||
case 1: return tr("Path");
|
||||
case 2: return tr("Size");
|
||||
case 3: return tr("Hash");
|
||||
case 4: return tr("Count");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
#include "RsCollection.h"
|
||||
|
||||
class RsCollectionModel: public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Roles{ FileNameRole = Qt::UserRole+1, SortRole = Qt::UserRole+2, FilterRole = Qt::UserRole+3 };
|
||||
|
||||
RsCollectionModel(bool mode, QObject *parent = 0);
|
||||
virtual ~RsCollectionModel() ;
|
||||
|
||||
|
||||
/* Callback from Core */
|
||||
void preMods();
|
||||
void postMods();
|
||||
|
||||
/* Callback from GUI */
|
||||
|
||||
void update() {}
|
||||
void filterItems(const std::list<std::string>& keywords, uint32_t& found) ;
|
||||
|
||||
// Overloaded from QAbstractItemModel
|
||||
virtual Qt::ItemFlags flags ( const QModelIndex & index ) const override;
|
||||
virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const override;
|
||||
virtual QModelIndex parent ( const QModelIndex & index ) const override;
|
||||
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const override;
|
||||
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
virtual QStringList mimeTypes () const override;
|
||||
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const override;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
||||
virtual Qt::DropActions supportedDragActions() const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
struct EntryIndex {
|
||||
bool is_file; // false=dir, true=file
|
||||
uint64_t index;
|
||||
};
|
||||
static bool convertIndexToInternalId(const EntryIndex& e,quintptr& ref);
|
||||
static bool convertInternalIdToIndex(quintptr ref, EntryIndex& e);
|
||||
|
||||
// virtual QVariant displayRole(const DirDetails&,int) const = 0 ;
|
||||
// virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const =0;
|
||||
|
||||
// QVariant decorationRole(const DirDetails&,int) const ;
|
||||
// QVariant filterRole(const DirDetails& details,int coln) const;
|
||||
|
||||
bool mUpdating ;
|
||||
|
||||
const RsCollection& mCollection;
|
||||
|
||||
// std::set<void*> mFilteredPointers ;
|
||||
};
|
Loading…
Reference in New Issue
Block a user