added RsCollectionModel to RsCollectionDialog (unfiished)

This commit is contained in:
csoler 2024-02-26 22:10:32 +01:00
parent eb0ef1e39b
commit eae4fe86aa
7 changed files with 208 additions and 146 deletions

View File

@ -598,6 +598,10 @@ bool RsCollection::save(QWidget *parent) const
#endif #endif
qulonglong RsCollection::count() const
{
return mFileTree.numFiles();
}
qulonglong RsCollection::size() qulonglong RsCollection::size()
{ {
return mFileTree.totalFileSize(); return mFileTree.totalFileSize();

View File

@ -93,6 +93,8 @@ public:
const RsFileTree& fileTree() const { return mFileTree; } const RsFileTree& fileTree() const { return mFileTree; }
// total size of files in the collection // total size of files in the collection
qulonglong size(); qulonglong size();
// total number of files in the collection
qulonglong count() const;
// Download the content. // Download the content.
void downloadFiles() const ; void downloadFiles() const ;

View File

@ -120,24 +120,31 @@ protected:
/** /**
* @brief RsCollectionDialog::RsCollectionDialog * @brief RsCollectionDialog::RsCollectionDialog
* @param collectionFileName: Filename of RSCollection saved * @param collectionFileName: Filename of RSCollection saved
* @param colFileInfos: Vector of ColFileInfo to be add in intialization
* @param creation: Open dialog as RsColl Creation or RsColl DownLoad * @param creation: Open dialog as RsColl Creation or RsColl DownLoad
* @param readOnly: Open dialog for RsColl as ReadOnly * @param readOnly: Open dialog for RsColl as ReadOnly
*/ */
RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName
, const std::vector<ColFileInfo>& colFileInfos , const bool& creation /* = false */
, const bool& creation /* = false*/ , const bool& readOnly /* = false */)
, const bool& readOnly)
: _fileName(collectionFileName), _creationMode(creation) ,_readOnly(readOnly) : _fileName(collectionFileName), _creationMode(creation) ,_readOnly(readOnly)
{ {
RsCollection::RsCollectionErrorCode err_code;
mCollection = new RsCollection(collectionFileName,err_code);
if(err_code != RsCollection::RsCollectionErrorCode::NO_ERROR)
{
QMessageBox::information(nullptr,tr("Could not load collection file"),tr("Could not load collection file"));
close();
}
ui.setupUi(this) ; ui.setupUi(this) ;
uint32_t size = colFileInfos.size(); // uint32_t size = colFileInfos.size();
for(uint32_t i=0;i<size;++i) // for(uint32_t i=0;i<size;++i)
{ // {
const ColFileInfo &colFileInfo = colFileInfos[i]; // const ColFileInfo &colFileInfo = colFileInfos[i];
_newColFileInfos.push_back(colFileInfo); // _newColFileInfos.push_back(colFileInfo);
} // }
setWindowFlags(Qt::Window); // for maximize button setWindowFlags(Qt::Window); // for maximize button
setWindowFlags(windowFlags() & ~Qt::WindowMinimizeButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowMinimizeButtonHint);
@ -170,6 +177,10 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName
// 1 - add all elements to the list. // 1 - add all elements to the list.
mCollectionModel = new RsCollectionModel(*mCollection);
ui._fileEntriesTW->setModel(mCollectionModel);
#ifdef TO_REMOVE
ui._fileEntriesTW->setColumnCount(COLUMN_COUNT) ; ui._fileEntriesTW->setColumnCount(COLUMN_COUNT) ;
QTreeWidgetItem *headerItem = ui._fileEntriesTW->headerItem(); QTreeWidgetItem *headerItem = ui._fileEntriesTW->headerItem();
@ -178,14 +189,15 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName
headerItem->setText(COLUMN_SIZE, tr("Size")); headerItem->setText(COLUMN_SIZE, tr("Size"));
headerItem->setText(COLUMN_HASH, tr("Hash")); headerItem->setText(COLUMN_HASH, tr("Hash"));
headerItem->setText(COLUMN_FILEC, tr("File Count")); headerItem->setText(COLUMN_FILEC, tr("File Count"));
#endif
bool wrong_chars = !updateList(); bool wrong_chars = !updateList();
// 2 - connect necessary signals/slots // 2 - connect necessary signals/slots
connect(ui._changeFile, SIGNAL(clicked()), this, SLOT(changeFileName())); connect(ui._changeFile, SIGNAL(clicked()), this, SLOT(changeFileName()));
connect(ui._add_PB, SIGNAL(clicked()), this, SLOT(add())); connect(ui._add_PB, SIGNAL(clicked()), this, SLOT(addSelection()));
connect(ui._addRecur_PB, SIGNAL(clicked()), this, SLOT(addRecursive())); connect(ui._addRecur_PB, SIGNAL(clicked()), this, SLOT(addSelectionRecursive()));
connect(ui._remove_PB, SIGNAL(clicked()), this, SLOT(remove())); connect(ui._remove_PB, SIGNAL(clicked()), this, SLOT(remove()));
connect(ui._makeDir_PB, SIGNAL(clicked()), this, SLOT(makeDir())); connect(ui._makeDir_PB, SIGNAL(clicked()), this, SLOT(makeDir()));
connect(ui._removeDuplicate_CB, SIGNAL(clicked(bool)), this, SLOT(updateRemoveDuplicate(bool))); connect(ui._removeDuplicate_CB, SIGNAL(clicked(bool)), this, SLOT(updateRemoveDuplicate(bool)));
@ -193,7 +205,9 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName
connect(ui._save_PB, SIGNAL(clicked()), this, SLOT(save())); connect(ui._save_PB, SIGNAL(clicked()), this, SLOT(save()));
connect(ui._download_PB, SIGNAL(clicked()), this, SLOT(download())); connect(ui._download_PB, SIGNAL(clicked()), this, SLOT(download()));
connect(ui._hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>))); connect(ui._hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
connect(ui._fileEntriesTW, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*,int))); #ifdef TO_REMOVE
connect(ui._fileEntriesTW, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*,int)));
#endif
// 3 Initialize List // 3 Initialize List
_dirModel = new QFileSystemModel(this); _dirModel = new QFileSystemModel(this);
@ -223,7 +237,9 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName
ui._treeViewFrame->setVisible(_creationMode && !_readOnly); ui._treeViewFrame->setVisible(_creationMode && !_readOnly);
ui._download_PB->setVisible(!_creationMode && !_readOnly); ui._download_PB->setVisible(!_creationMode && !_readOnly);
ui._fileEntriesTW->installEventFilter(this); #ifdef TO_REMOVE
ui._fileEntriesTW->installEventFilter(this);
#endif
ui._systemFileTW->installEventFilter(this); ui._systemFileTW->installEventFilter(this);
// 6 Add HashBox // 6 Add HashBox
@ -293,6 +309,7 @@ RsCollectionDialog::~RsCollectionDialog()
*/ */
bool RsCollectionDialog::eventFilter(QObject *obj, QEvent *event) bool RsCollectionDialog::eventFilter(QObject *obj, QEvent *event)
{ {
#ifdef TODO_COLLECTION
if (obj == ui._fileEntriesTW) { if (obj == ui._fileEntriesTW) {
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
@ -350,6 +367,8 @@ bool RsCollectionDialog::eventFilter(QObject *obj, QEvent *event)
// pass the event on to the parent class // pass the event on to the parent class
return QDialog::eventFilter(obj, event); return QDialog::eventFilter(obj, event);
#endif
return true;
} }
/** /**
@ -411,6 +430,7 @@ void RsCollectionDialog::processSettings(bool bLoad)
Settings->endGroup(); Settings->endGroup();
} }
#ifdef TO_REMOVE
/** /**
* @brief RsCollectionDialog::getRootItem: Create the root Item if not existing * @brief RsCollectionDialog::getRootItem: Create the root Item if not existing
* @return: the root item * @return: the root item
@ -418,34 +438,8 @@ void RsCollectionDialog::processSettings(bool bLoad)
QTreeWidgetItem* RsCollectionDialog::getRootItem() QTreeWidgetItem* RsCollectionDialog::getRootItem()
{ {
return ui._fileEntriesTW->invisibleRootItem(); return ui._fileEntriesTW->invisibleRootItem();
// (csoler) I removed this code because it does the job of the invisibleRootItem() method.
//
// QTreeWidgetItem* root= ui._fileEntriesTW->topLevelItem(0);
// if (!root) {
// root= new QTreeWidgetItem;
// root->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsTristate);
// root->setText(COLUMN_FILE, "/");
// root->setToolTip(COLUMN_FILE,tr("This is the root directory."));
// root->setText(COLUMN_FILEPATH, "/");
// root->setText(COLUMN_HASH, "");
// root->setData(COLUMN_HASH, ROLE_NAME, "");
// root->setData(COLUMN_HASH, ROLE_PATH, "");
// root->setData(COLUMN_HASH, ROLE_TYPE, DIR_TYPE_DIR);
// root->setText(COLUMN_SIZE, misc::friendlyUnit(0));
// root->setToolTip(COLUMN_SIZE, tr("Real Size: Waiting child..."));
// root->setData(COLUMN_SIZE, ROLE_SIZE, 0);
// root->setData(COLUMN_SIZE, ROLE_SELSIZE, 0);
// root->setText(COLUMN_FILEC, "0");
// root->setToolTip(COLUMN_FILEC, tr("Real File Count: Waiting child..."));
// root->setData(COLUMN_FILEC, ROLE_FILEC, 0);
// root->setData(COLUMN_FILEC, ROLE_SELFILEC, 0);
// ui._fileEntriesTW->addTopLevelItem(root);
// }
// root->setExpanded(true);
//
// return root;
} }
#endif
/** /**
* @brief RsCollectionDialog::updateList: Update list of item in RsCollection * @brief RsCollectionDialog::updateList: Update list of item in RsCollection
@ -453,6 +447,7 @@ QTreeWidgetItem* RsCollectionDialog::getRootItem()
*/ */
bool RsCollectionDialog::updateList() bool RsCollectionDialog::updateList()
{ {
#ifdef TODO_COLLECTION
bool wrong_chars = false ; bool wrong_chars = false ;
wrong_chars = addChild(getRootItem(), _newColFileInfos); wrong_chars = addChild(getRootItem(), _newColFileInfos);
@ -466,8 +461,11 @@ bool RsCollectionDialog::updateList()
updateSizes() ; updateSizes() ;
return !wrong_chars; return !wrong_chars;
#endif
return true;
} }
#ifdef TO_REMOVE
/** /**
* @brief RsCollectionDialog::addChild: Add Child Item in list * @brief RsCollectionDialog::addChild: Add Child Item in list
* @param parent: Parent Item * @param parent: Parent Item
@ -586,6 +584,7 @@ bool RsCollectionDialog::addChild(QTreeWidgetItem* parent, const std::vector<Col
} }
return wrong_chars; return wrong_chars;
} }
#endif
/** /**
* @brief RsCollectionDialog::directoryLoaded: called when ui._treeView have load an directory as QFileSystemModel don't load all in one time * @brief RsCollectionDialog::directoryLoaded: called when ui._treeView have load an directory as QFileSystemModel don't load all in one time
@ -639,17 +638,8 @@ void RsCollectionDialog::directoryLoaded(QString dirLoaded)
*/ */
void RsCollectionDialog::updateSizes() void RsCollectionDialog::updateSizes()
{ {
uint64_t total_size = 0 ; ui._selectedFiles_TL->setText(QString::number(mCollection->count()));
uint32_t total_count = 0 ; ui._totalSize_TL->setText(misc::friendlyUnit(mCollection->size()));
for(int i=0;i<ui._fileEntriesTW->topLevelItemCount();++i)
{
total_size += ui._fileEntriesTW->topLevelItem(i)->data(COLUMN_SIZE ,ROLE_SELSIZE ).toULongLong();
total_count += ui._fileEntriesTW->topLevelItem(i)->data(COLUMN_FILEC,ROLE_SELFILEC).toULongLong();
}
ui._selectedFiles_TL->setText(QString::number(total_count));
ui._totalSize_TL->setText(misc::friendlyUnit(total_size));
} }
/** /**
@ -716,16 +706,23 @@ void RsCollectionDialog::changeFileName()
RsCollection qddOldFileCollection(fileName,err); RsCollection qddOldFileCollection(fileName,err);
if(err != RsCollection::RsCollectionErrorCode::NO_ERROR) if(err != RsCollection::RsCollectionErrorCode::NO_ERROR)
_collection.merge_in(qddOldFileCollection.fileTree()); {
mCollectionModel->preMods();
mCollection->merge_in(qddOldFileCollection.fileTree());
mCollectionModel->postMods();
}
} }
else if(mb.clickedButton()==btnCancel) else if(mb.clickedButton()==btnCancel)
return; return;
else else
return; return;
} else {//if(file.exists()) }
else
{
//create a new empty file to check if name if good. //create a new empty file to check if name if good.
if (!file.open(QFile::WriteOnly)) return; if (!file.open(QFile::WriteOnly))
return;
file.remove(); file.remove();
} }
@ -736,19 +733,40 @@ void RsCollectionDialog::changeFileName()
/** /**
* @brief RsCollectionDialog::add: */ * @brief RsCollectionDialog::add: */
void RsCollectionDialog::add() void RsCollectionDialog::addSelection()
{ {
addRecursive(false); addSelection(false);
} }
/** /**
* @brief RsCollectionDialog::addRecursive: * @brief RsCollectionDialog::addRecursive:
*/ */
void RsCollectionDialog::addRecursive() void RsCollectionDialog::addSelectionRecursive()
{ {
addRecursive(true); addSelection(true);
} }
static void recursBuildFileTree(const QString& path,RsFileTree& tree,RsFileTree::DirIndex dir_index,bool recursive)
{
QFileInfo fileInfo = path;
if (fileInfo.isDir())
{
auto di = tree.addDirectory(dir_index,fileInfo.fileName().toUtf8().constData());
QDir dirParent = fileInfo.absoluteFilePath();
dirParent.setFilter(QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot);
QFileInfoList childrenList = dirParent.entryInfoList();
for(QFileInfo f:childrenList)
recursBuildFileTree(f.absoluteFilePath(),tree,di,recursive);
}
else
{
#warning TODO: compute the hash
tree.addFile(dir_index,fileInfo.fileName().toUtf8().constData(),RsFileHash(),fileInfo.size());
}
}
/** /**
* @brief RsCollectionDialog::addRecursive: Add Selected item to RSCollection * @brief RsCollectionDialog::addRecursive: Add Selected item to RSCollection
* -Add File seperatly if parent folder not selected * -Add File seperatly if parent folder not selected
@ -756,18 +774,25 @@ void RsCollectionDialog::addRecursive()
* -Get root folder the selected one * -Get root folder the selected one
* @param recursive: If true, add all selected directory childrens * @param recursive: If true, add all selected directory childrens
*/ */
void RsCollectionDialog::addRecursive(bool recursive) void RsCollectionDialog::addSelection(bool recursive)
{ {
QStringList fileToHash; QStringList fileToHash;
QMap<QString, QString > dirToAdd; QMap<QString, QString > dirToAdd;
int count=0;//to not scan all items on list .count() int count=0;//to not scan all items on list .count()
QModelIndexList milSelectionList = ui._systemFileTW->selectionModel()->selectedIndexes(); QModelIndexList milSelectionList = ui._systemFileTW->selectionModel()->selectedIndexes();
foreach (QModelIndex index, milSelectionList)
{
if (index.column()==0){//Get only FileName mCollectionModel->preMods();
QString filePath = _dirModel->filePath(_tree_proxyModel->mapToSource(index));
foreach (QModelIndex index, milSelectionList)
if(index.column()==0) //Get only FileName
{
RsFileTree tree;
recursBuildFileTree(_dirModel->filePath(_tree_proxyModel->mapToSource(index)),tree,tree.root(),recursive);
mCollection->merge_in(tree);
#ifdef TO_REMOVE
QFileInfo fileInfo = filePath; QFileInfo fileInfo = filePath;
if (fileInfo.isDir()) { if (fileInfo.isDir()) {
dirToAdd.insert(fileInfo.absoluteFilePath(),fileInfo.absolutePath()); dirToAdd.insert(fileInfo.absoluteFilePath(),fileInfo.absolutePath());
@ -786,9 +811,10 @@ void RsCollectionDialog::addRecursive(bool recursive)
else else
_listOfFilesAddedInDir.insert(fileInfo.absoluteFilePath(),""); _listOfFilesAddedInDir.insert(fileInfo.absoluteFilePath(),"");
} }
#endif
} }
}
#ifdef TO_REMOVE
// Process Dirs // Process Dirs
QTreeWidgetItem *item = NULL; QTreeWidgetItem *item = NULL;
if (!ui._fileEntriesTW->selectedItems().empty()) if (!ui._fileEntriesTW->selectedItems().empty())
@ -833,6 +859,7 @@ void RsCollectionDialog::addRecursive(bool recursive)
// Process Files once all done // Process Files once all done
ui._hashBox->addAttachments(fileToHash,RS_FILE_REQ_ANONYMOUS_ROUTING /*, 0*/); ui._hashBox->addAttachments(fileToHash,RS_FILE_REQ_ANONYMOUS_ROUTING /*, 0*/);
#endif
} }
/** /**
@ -896,6 +923,7 @@ bool RsCollectionDialog::addAllChild(QFileInfo &fileInfoParent
*/ */
void RsCollectionDialog::remove() void RsCollectionDialog::remove()
{ {
#ifdef TODO_COLLECTION
bool removeOnlyFile=false; bool removeOnlyFile=false;
QString listDir; QString listDir;
// First, check if selection contains directories // First, check if selection contains directories
@ -987,9 +1015,10 @@ void RsCollectionDialog::remove()
} }
updateSizes() ; updateSizes() ;
#endif
} }
#ifdef TODO_COLLECTION
bool RsCollectionDialog::removeItem(QTreeWidgetItem *item, bool &removeOnlyFile) bool RsCollectionDialog::removeItem(QTreeWidgetItem *item, bool &removeOnlyFile)
{ {
if (item){ if (item){
@ -1019,7 +1048,9 @@ bool RsCollectionDialog::removeItem(QTreeWidgetItem *item, bool &removeOnlyFile)
} }
return false; return false;
} }
#endif
#ifdef TO_REMOVE
/** Process each item to make a new RsCollection item */ /** Process each item to make a new RsCollection item */
void RsCollectionDialog::processItem(QMap<QString, QString> &dirToAdd void RsCollectionDialog::processItem(QMap<QString, QString> &dirToAdd
, int &index , int &index
@ -1063,12 +1094,14 @@ void RsCollectionDialog::processItem(QMap<QString, QString> &dirToAdd
} }
} }
} }
#endif
/** /**
* @brief RsCollectionDialog::addDir: Add new empty dir to list * @brief RsCollectionDialog::addDir: Add new empty dir to list
*/ */
void RsCollectionDialog::makeDir() void RsCollectionDialog::makeDir()
{ {
#ifdef TODO_COLLECTION
QString childName=""; QString childName="";
bool ok, badChar, nameOK = false; bool ok, badChar, nameOK = false;
// Ask for name // Ask for name
@ -1149,39 +1182,8 @@ void RsCollectionDialog::makeDir()
_newColFileInfos.push_back(newChild); _newColFileInfos.push_back(newChild);
} }
// // Process all selected items
// int count = ui._fileEntriesTW->selectedItems().count();
// int curs = 0;
// if (count == 0) curs = -1;
//
// for (; curs < count; ++curs)
// {
// QTreeWidgetItem *item = NULL;
// if (curs >= 0) {
// item= ui._fileEntriesTW->selectedItems().at(curs);
// } else {
// item = getRootItem();
// }
// if (item) {
// while (item->parent() != NULL && item->data(COLUMN_HASH, ROLE_TYPE).toUInt() != DIR_TYPE_DIR) {
// item = item->parent();//Only Dir as Parent
// }
// ColFileInfo newChild;
// newChild.name = childName;
// newChild.filename_has_wrong_characters = false;
// newChild.size = 0;
// newChild.type = DIR_TYPE_DIR;
// newChild.path = item->data(COLUMN_HASH, ROLE_PATH).toString()
// + "/" + item->data(COLUMN_HASH, ROLE_NAME).toString();
// if (item == getRootItem()) newChild.path = "";
//
// _newColFileInfos.push_back(newChild);
// }
// }
updateList(); updateList();
#endif
} }
/** /**
@ -1212,9 +1214,9 @@ void RsCollectionDialog::fileHashingFinished(QList<HashedFile> hashedFiles)
colFileInfo.path = _listOfFilesAddedInDir.value(hashedFile.filepath,""); colFileInfo.path = _listOfFilesAddedInDir.value(hashedFile.filepath,"");
_listOfFilesAddedInDir.remove(hashedFile.filepath); _listOfFilesAddedInDir.remove(hashedFile.filepath);
} }
#ifdef TODO_COLLECTION
_newColFileInfos.push_back(colFileInfo); _newColFileInfos.push_back(colFileInfo);
#endif
} }
std::cerr << "RsCollectionDialog::fileHashingFinished message : " << message.toStdString() << std::endl; std::cerr << "RsCollectionDialog::fileHashingFinished message : " << message.toStdString() << std::endl;
@ -1222,6 +1224,7 @@ void RsCollectionDialog::fileHashingFinished(QList<HashedFile> hashedFiles)
updateList(); updateList();
} }
#ifdef TO_REMOVE
void RsCollectionDialog::itemChanged(QTreeWidgetItem *item, int col) void RsCollectionDialog::itemChanged(QTreeWidgetItem *item, int col)
{ {
if (col != COLUMN_FILE) return; if (col != COLUMN_FILE) return;
@ -1254,6 +1257,7 @@ void RsCollectionDialog::itemChanged(QTreeWidgetItem *item, int col)
updateSizes() ; updateSizes() ;
} }
#endif
/** /**
* @brief RsCollectionDialog::updateRemoveDuplicate Remove all duplicate file when checked. * @brief RsCollectionDialog::updateRemoveDuplicate Remove all duplicate file when checked.
@ -1261,6 +1265,7 @@ void RsCollectionDialog::itemChanged(QTreeWidgetItem *item, int col)
*/ */
void RsCollectionDialog::updateRemoveDuplicate(bool checked) void RsCollectionDialog::updateRemoveDuplicate(bool checked)
{ {
#ifdef TODO_COLLECTION
if (checked) { if (checked) {
bool bRemoveAll = false; bool bRemoveAll = false;
QTreeWidgetItemIterator it(ui._fileEntriesTW); QTreeWidgetItemIterator it(ui._fileEntriesTW);
@ -1341,6 +1346,7 @@ void RsCollectionDialog::updateRemoveDuplicate(bool checked)
} }
} }
} }
#endif
} }
/** /**
@ -1357,14 +1363,13 @@ void RsCollectionDialog::cancel()
*/ */
void RsCollectionDialog::download() void RsCollectionDialog::download()
{ {
#ifdef TODO_COLLECTION
std::cerr << "Downloading!" << std::endl; std::cerr << "Downloading!" << std::endl;
QString dldir = ui.downloadFolder_LE->text(); QString dldir = ui.downloadFolder_LE->text();
std::cerr << "downloading all these files:" << std::endl; std::cerr << "downloading all these files:" << std::endl;
QTreeWidgetItemIterator itemIterator(ui._fileEntriesTW);
QTreeWidgetItem *item;
while ((item = *itemIterator) != NULL) { while ((item = *itemIterator) != NULL) {
++itemIterator; ++itemIterator;
@ -1399,6 +1404,7 @@ void RsCollectionDialog::download()
} }
close(); close();
#endif
} }
/** /**
@ -1406,18 +1412,20 @@ void RsCollectionDialog::download()
*/ */
void RsCollectionDialog::save() void RsCollectionDialog::save()
{ {
mCollection->save(_fileName);
#ifdef TO_REMOVE
std::cerr << "Saving!" << std::endl; std::cerr << "Saving!" << std::endl;
_newColFileInfos.clear(); _newColFileInfos.clear();
QTreeWidgetItem* root = getRootItem(); QTreeWidgetItem* root = getRootItem();
if (root) { if (root) {
saveChild(root); saveChild(root);
#ifdef TODO_COLLECTION
emit saveColl(_newColFileInfos, _fileName); emit saveColl(_newColFileInfos, _fileName);
#endif
} }
close(); close();
#endif
} }
#ifdef TO_REMOVE
/** /**
* @brief RsCollectionDialog::saveChild: Save each child in _newColFileInfos * @brief RsCollectionDialog::saveChild: Save each child in _newColFileInfos
* @param parent * @param parent
@ -1444,29 +1452,16 @@ void RsCollectionDialog::saveChild(QTreeWidgetItem *parentItem, ColFileInfo *par
} }
} }
} }
#endif
bool RsCollectionDialog::openExistingCollection(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/) bool RsCollectionDialog::openExistingCollection(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/)
{ {
#ifdef TODO return RsCollectionDialog(fileName,readOnly,showError).exec();
RsCollection::RsCollectionErrorCode err;
RsCollection col(fileName,err);
if(err != RsCollection::RsCollectionErrorCode::NO_ERROR)
{
RsCollectionDialog rcd = new RsCollectionDialog(col, true, readOnly);
return rcd.exec() ;
}
if(showError)
QMessageBox::information(nullptr,tr("Error openning RsCollection"),RsCollection::errorString(err));
#endif
return false;
} }
bool RsCollectionDialog::openNewCollection(const RsFileTree& tree,const QString& proposed_file_name) bool RsCollectionDialog::openNewCollection(const RsFileTree& tree,const QString& proposed_file_name)
{ {
#ifdef TODO #ifdef TODO_COLLECTION
QString fileName = proposed_file_name; QString fileName = proposed_file_name;
if(!misc::getSaveFileName(nullptr, RshareSettings::LASTDIR_EXTRAFILE if(!misc::getSaveFileName(nullptr, RshareSettings::LASTDIR_EXTRAFILE

View File

@ -20,6 +20,7 @@
#include "ui_RsCollectionDialog.h" #include "ui_RsCollectionDialog.h"
#include "RsCollection.h" #include "RsCollection.h"
#include "RsCollectionModel.h"
#include <QFileSystemModel> #include <QFileSystemModel>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
@ -41,26 +42,29 @@ public:
protected: protected:
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev);
RsCollectionDialog(const QString& filename, const std::vector<ColFileInfo> &colFileInfos, const bool& creation, RsCollectionDialog(const QString& filename, const bool& creation, const bool& readOnly = false) ;
const bool& readOnly = false) ;
private slots: private slots:
void directoryLoaded(QString dirLoaded); void directoryLoaded(QString dirLoaded);
void updateSizes() ; void updateSizes() ;
void changeFileName() ; void changeFileName() ;
void add() ; void addSelection() ;
void addRecursive() ; void addSelectionRecursive() ;
void remove() ; void remove() ;
void chooseDestinationDirectory(); void chooseDestinationDirectory();
void setDestinationDirectory(); void setDestinationDirectory();
void openDestinationDirectoryMenu(); void openDestinationDirectoryMenu();
#ifdef TO_REMOVE
void processItem(QMap<QString, QString> &dirToAdd void processItem(QMap<QString, QString> &dirToAdd
, int &index , int &index
, ColFileInfo &parent , ColFileInfo &parent
) ; ) ;
#endif
void makeDir() ; void makeDir() ;
void fileHashingFinished(QList<HashedFile> hashedFiles) ; void fileHashingFinished(QList<HashedFile> hashedFiles) ;
void itemChanged(QTreeWidgetItem* item,int col) ; #ifdef TO_REMOVE
void itemChanged(QTreeWidgetItem* item,int col) ;
#endif
void updateRemoveDuplicate(bool checked); void updateRemoveDuplicate(bool checked);
void cancel() ; void cancel() ;
void download() ; void download() ;
@ -71,22 +75,23 @@ signals:
private: private:
void processSettings(bool bLoad) ; void processSettings(bool bLoad) ;
QTreeWidgetItem* getRootItem();
bool updateList(); bool updateList();
bool addChild(QTreeWidgetItem *parent, const std::vector<ColFileInfo> &child); #ifdef TO_REMOVE
QTreeWidgetItem* getRootItem();
bool addChild(QTreeWidgetItem *parent, const std::vector<ColFileInfo> &child);
bool removeItem(QTreeWidgetItem *item, bool &removeOnlyFile) ; bool removeItem(QTreeWidgetItem *item, bool &removeOnlyFile) ;
void addRecursive(bool recursive) ; void saveChild(QTreeWidgetItem *parentItem, ColFileInfo *parentInfo = NULL);
#endif
void addSelection(bool recursive) ;
bool addAllChild(QFileInfo &fileInfoParent bool addAllChild(QFileInfo &fileInfoParent
, QMap<QString, QString > &dirToAdd , QMap<QString, QString > &dirToAdd
, QStringList &fileToHash , QStringList &fileToHash
, int &count); , int &count);
void saveChild(QTreeWidgetItem *parentItem, ColFileInfo *parentInfo = NULL);
Ui::RsCollectionDialog ui; Ui::RsCollectionDialog ui;
QString _fileName ; QString _fileName ;
const bool _creationMode ; const bool _creationMode ;
const bool _readOnly; const bool _readOnly;
std::vector<ColFileInfo> _newColFileInfos ;
QFileSystemModel *_dirModel; QFileSystemModel *_dirModel;
QSortFilterProxyModel *_tree_proxyModel; QSortFilterProxyModel *_tree_proxyModel;
@ -94,5 +99,6 @@ private:
bool _dirLoaded; bool _dirLoaded;
QHash<QString,QString> _listOfFilesAddedInDir; QHash<QString,QString> _listOfFilesAddedInDir;
RsCollection _collection; RsCollectionModel *mCollectionModel;
RsCollection *mCollection;
}; };

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>600</width> <width>671</width>
<height>400</height> <height>400</height>
</rect> </rect>
</property> </property>
@ -17,7 +17,7 @@
<string>Collection</string> <string>Collection</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="../images.qrc"> <iconset>
<normaloff>:/images/mimetypes/rscollection-16.png</normaloff>:/images/mimetypes/rscollection-16.png</iconset> <normaloff>:/images/mimetypes/rscollection-16.png</normaloff>:/images/mimetypes/rscollection-16.png</iconset>
</property> </property>
<property name="sizeGripEnabled"> <property name="sizeGripEnabled">
@ -382,7 +382,7 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QTreeWidget" name="_fileEntriesTW"> <widget class="QTreeView" name="_fileEntriesTW">
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set> <set>QAbstractItemView::NoEditTriggers</set>
</property> </property>
@ -398,11 +398,6 @@
<property name="allColumnsShowFocus"> <property name="allColumnsShowFocus">
<bool>true</bool> <bool>true</bool>
</property> </property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget> </widget>
</widget> </widget>
</item> </item>
@ -517,7 +512,6 @@
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../images.qrc"/> <include location="../images.qrc"/>
<include location="../../../../plugins/FeedReader/gui/FeedReader_images.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -2,6 +2,10 @@
#include "RsCollectionModel.h" #include "RsCollectionModel.h"
RsCollectionModel::RsCollectionModel(const RsCollection& col, QObject *parent)
: QAbstractItemModel(parent),mCollection(col)
{}
// Indernal Id is always a quintptr_t (basically a uint with the size of a pointer). Depending on the // 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 // 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) // the remaining bits for the index (which will be accordingly understood as a FileIndex or a DirIndex)
@ -35,6 +39,21 @@ int RsCollectionModel::rowCount(const QModelIndex& parent) const
return mCollection.fileTree().directoryData(i.index).subdirs.size() + mCollection.fileTree().directoryData(i.index).subfiles.size(); return mCollection.fileTree().directoryData(i.index).subdirs.size() + mCollection.fileTree().directoryData(i.index).subfiles.size();
} }
bool RsCollectionModel::hasChildren(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 false;
else
return mCollection.fileTree().directoryData(i.index).subdirs.size() + mCollection.fileTree().directoryData(i.index).subfiles.size() > 0;
}
int RsCollectionModel::columnCount(const QModelIndex&) const int RsCollectionModel::columnCount(const QModelIndex&) const
{ {
return 4; return 4;
@ -180,8 +199,47 @@ QVariant RsCollectionModel::decorationRole(const EntryIndex& i,int col) const
return QVariant(); return QVariant();
} }
void RsCollectionModel::preMods()
{
mUpdating = true;
emit layoutAboutToBeChanged();
}
void RsCollectionModel::postMods()
{
// update all the local structures
mDirParents.clear();
mFileParents.clear();
mDirSizes.clear();
uint64_t s;
recursUpdateLocalStructures(mCollection.fileTree().root(),s);
mUpdating = false;
emit layoutChanged();
}
void RsCollectionModel::recursUpdateLocalStructures(RsFileTree::DirIndex dir_index,uint64_t& total_size)
{
total_size = 0;
const auto& dd(mCollection.fileTree().directoryData(dir_index));
for(uint32_t i=0;i<dd.subfiles.size();++i)
{
total_size += mCollection.fileTree().fileData(dd.subfiles[i]).size;
mFileParents[dd.subfiles[i]] = dir_index;
}
for(uint32_t i=0;i<dd.subdirs.size();++i)
{
uint64_t ss;
recursUpdateLocalStructures(dd.subdirs[i],ss);
total_size += ss;
mDirParents[dd.subdirs[i]] = dir_index;
}
mDirSizes[dir_index] = total_size;
}

View File

@ -10,7 +10,7 @@ class RsCollectionModel: public QAbstractItemModel
enum Roles{ FileNameRole = Qt::UserRole+1, SortRole = Qt::UserRole+2, FilterRole = Qt::UserRole+3 }; enum Roles{ FileNameRole = Qt::UserRole+1, SortRole = Qt::UserRole+2, FilterRole = Qt::UserRole+3 };
RsCollectionModel(const RsCollection& col, QObject *parent = 0); RsCollectionModel(const RsCollection& col, QObject *parent = 0);
virtual ~RsCollectionModel() ; virtual ~RsCollectionModel() = default;
/* Callback from Core */ /* Callback from Core */
void preMods(); // always call this before updating the RsCollection! void preMods(); // always call this before updating the RsCollection!
@ -22,7 +22,6 @@ class RsCollectionModel: public QAbstractItemModel
void filterItems(const std::list<std::string>& keywords, uint32_t& found) ; void filterItems(const std::list<std::string>& keywords, uint32_t& found) ;
// Overloaded from QAbstractItemModel // 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 index(int row, int column, const QModelIndex & parent = QModelIndex() ) const override;
virtual QModelIndex parent ( const QModelIndex & index ) const override; virtual QModelIndex parent ( const QModelIndex & index ) const override;
@ -31,15 +30,17 @@ class RsCollectionModel: public QAbstractItemModel
virtual bool hasChildren(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 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 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
#ifdef TODO
virtual Qt::ItemFlags flags ( const QModelIndex & index ) const override;
virtual QStringList mimeTypes () const override; virtual QStringList mimeTypes () const override;
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const override; virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const override;
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
virtual Qt::DropActions supportedDragActions() const override; virtual Qt::DropActions supportedDragActions() const override;
#endif
#endif #endif
protected: private:
struct EntryIndex { struct EntryIndex {
bool is_file; // false=dir, true=file bool is_file; // false=dir, true=file
uint64_t index; uint64_t index;
@ -47,6 +48,8 @@ class RsCollectionModel: public QAbstractItemModel
static bool convertIndexToInternalId(const EntryIndex& e,quintptr& ref); static bool convertIndexToInternalId(const EntryIndex& e,quintptr& ref);
static bool convertInternalIdToIndex(quintptr ref, EntryIndex& e); static bool convertInternalIdToIndex(quintptr ref, EntryIndex& e);
void recursUpdateLocalStructures(RsFileTree::DirIndex dir_index,uint64_t& total_size);
QVariant displayRole(const EntryIndex&,int col) const ; QVariant displayRole(const EntryIndex&,int col) const ;
QVariant sortRole(const EntryIndex&,int col) const ; QVariant sortRole(const EntryIndex&,int col) const ;
QVariant decorationRole(const EntryIndex&,int col) const ; QVariant decorationRole(const EntryIndex&,int col) const ;