added green color for files being hashed

This commit is contained in:
csoler 2024-03-13 22:20:21 +01:00
parent 7ef81a37ff
commit 0697116289
4 changed files with 61 additions and 17 deletions

View File

@ -146,7 +146,7 @@ static QString purifyFileName(const QString& input,bool& bad)
void RsCollection::merge_in(const QString& fname,uint64_t size,const RsFileHash& hash) void RsCollection::merge_in(const QString& fname,uint64_t size,const RsFileHash& hash)
{ {
mFileTree->addFile(mFileTree->root(),fname.toStdString(),hash,size); mHashes[hash]= mFileTree->addFile(mFileTree->root(),fname.toStdString(),hash,size);
#ifdef TO_REMOVE #ifdef TO_REMOVE
ColFileInfo info ; ColFileInfo info ;
info.type = DIR_TYPE_FILE ; info.type = DIR_TYPE_FILE ;
@ -167,7 +167,7 @@ void RsCollection::recursMergeTree(RsFileTree::DirIndex parent,const RsFileTree&
for(uint32_t i=0;i<dd.subfiles.size();++i) for(uint32_t i=0;i<dd.subfiles.size();++i)
{ {
const RsFileTree::FileData& fd(tree.fileData(dd.subfiles[i])); const RsFileTree::FileData& fd(tree.fileData(dd.subfiles[i]));
mFileTree->addFile(parent,fd.name,fd.hash,fd.size); mHashes[fd.hash] = mFileTree->addFile(parent,fd.name,fd.hash,fd.size);
} }
for(uint32_t i=0;i<dd.subdirs.size();++i) for(uint32_t i=0;i<dd.subdirs.size();++i)
{ {
@ -672,3 +672,5 @@ void RsCollection::saveColl(std::vector<ColFileInfo> colFileInfos, const QString
} }
#endif #endif

View File

@ -739,7 +739,7 @@ void RsCollectionDialog::addSelectionRecursive()
addSelection(true); addSelection(true);
} }
static void recursBuildFileTree(const QString& path,RsFileTree& tree,RsFileTree::DirIndex dir_index,bool recursive,QSet<QString>& paths_to_hash) static void recursBuildFileTree(const QString& path,RsFileTree& tree,RsFileTree::DirIndex dir_index,bool recursive,std::map<QString,RsFileHash>& paths_to_hash)
{ {
QFileInfo fileInfo = path; QFileInfo fileInfo = path;
@ -768,7 +768,7 @@ static void recursBuildFileTree(const QString& path,RsFileTree& tree,RsFileTree:
tree.addFile(dir_index,fileInfo.fileName().toUtf8().constData(),s,fileInfo.size()); tree.addFile(dir_index,fileInfo.fileName().toUtf8().constData(),s,fileInfo.size());
paths_to_hash.insert(fileInfo.filePath().toUtf8().constData()); paths_to_hash.insert(std::make_pair(fileInfo.filePath(),s));
} }
} }
/** /**
@ -787,7 +787,7 @@ void RsCollectionDialog::addSelection(bool recursive)
mCollectionModel->preMods(); mCollectionModel->preMods();
QSet<QString> paths_to_hash; // sha1sum of the paths to hash std::map<QString,RsFileHash> paths_to_hash; // sha1sum of the paths to hash.
foreach (QModelIndex index, milSelectionList) foreach (QModelIndex index, milSelectionList)
if(index.column()==0) //Get only FileName if(index.column()==0) //Get only FileName
@ -865,15 +865,24 @@ void RsCollectionDialog::addSelection(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 #endif
// std::map<Sha1CheckSum,QString> paths_and_hashes;
// for(auto path:paths_to_hash)
// paths_and_hashes.insert(std::make_pair(RsDirUtil::sha1sum((uint8_t*)path.toUtf8().constData(),path.toUtf8().size()),path));
// mCollectionModel->addFilesToHash(paths_and_hashes); mFilesBeingHashed.insert(paths_to_hash.begin(),paths_to_hash.end());
QStringList paths;
std::list<RsFileHash> hashes;
for(auto it:paths_to_hash)
{
paths.push_back(it.first);
hashes.push_back(it.second);
std::cerr << "Setting file has being hased: ID=" << it.second << " - " << it.first.toUtf8().constData() << std::endl;
}
mCollectionModel->notifyFilesBeingHashed(hashes);
mCollectionModel->postMods(); mCollectionModel->postMods();
ui._hashBox->addAttachments(QStringList(paths_to_hash.begin(),paths_to_hash.end()),RS_FILE_REQ_ANONYMOUS_ROUTING /*, 0*/); ui._hashBox->addAttachments(paths,RS_FILE_REQ_ANONYMOUS_ROUTING /*, 0*/);
} }
#ifdef TO_REMOVE #ifdef TO_REMOVE
@ -1238,6 +1247,7 @@ void RsCollectionDialog::fileHashingFinished(QList<HashedFile> hashedFiles)
#endif #endif
// build a map of old-hash to new-hash for the hashed files, so that it can be passed to the mCollection for update // build a map of old-hash to new-hash for the hashed files, so that it can be passed to the mCollection for update
mCollectionModel->preMods();
std::map<RsFileHash,RsFileHash> old_to_new_hashes; std::map<RsFileHash,RsFileHash> old_to_new_hashes;
for(auto f:hashedFiles) for(auto f:hashedFiles)
@ -1249,10 +1259,12 @@ void RsCollectionDialog::fileHashingFinished(QList<HashedFile> hashedFiles)
RsErr() << "Could not find hash-ID correspondence for path " << f.filepath.toUtf8().constData() << ". This is a bug." << std::endl; RsErr() << "Could not find hash-ID correspondence for path " << f.filepath.toUtf8().constData() << ". This is a bug." << std::endl;
continue; continue;
} }
std::cerr << "Will update old hash " << it->second << " to new hash " << f.hash << std::endl;
old_to_new_hashes.insert(std::make_pair(it->second,f.hash)); old_to_new_hashes.insert(std::make_pair(it->second,f.hash));
mFilesBeingHashed.erase(it); mFilesBeingHashed.erase(it);
mCollectionModel->fileHashingFinished(it->second);
} }
mCollectionModel->preMods();
mCollection->updateHashes(old_to_new_hashes); mCollection->updateHashes(old_to_new_hashes);
mCollectionModel->postMods(); mCollectionModel->postMods();

View File

@ -1,4 +1,5 @@
#include <string> #include <string>
#include <QBrush>
#include "RsCollectionModel.h" #include "RsCollectionModel.h"
@ -238,6 +239,7 @@ QVariant RsCollectionModel::data(const QModelIndex& index, int role) const
case Qt::DisplayRole: return displayRole(i,index.column()); case Qt::DisplayRole: return displayRole(i,index.column());
case Qt::DecorationRole: return decorationRole(i,index.column()); case Qt::DecorationRole: return decorationRole(i,index.column());
case Qt::CheckStateRole: return checkStateRole(i,index.column()); case Qt::CheckStateRole: return checkStateRole(i,index.column());
case Qt::TextColorRole: return textColorRole(i,index.column());
default: default:
return QVariant(); return QVariant();
} }
@ -364,6 +366,13 @@ bool RsCollectionModel::setData(const QModelIndex& index,const QVariant& value,i
return QAbstractItemModel::setData(index,value,role); return QAbstractItemModel::setData(index,value,role);
} }
QVariant RsCollectionModel::textColorRole(const EntryIndex& i,int col) const
{
if(i.is_file && mFilesBeingHashed.find(mCollection.fileTree().fileData(i.index).hash) != mFilesBeingHashed.end())
return QVariant(QBrush(QColor::fromRgbF(0.1,0.9,0.2)));
else
return QVariant();
}
QVariant RsCollectionModel::checkStateRole(const EntryIndex& i,int col) const QVariant RsCollectionModel::checkStateRole(const EntryIndex& i,int col) const
{ {
if(col == COLLECTION_MODEL_FILENAME) if(col == COLLECTION_MODEL_FILENAME)
@ -393,18 +402,25 @@ QVariant RsCollectionModel::displayRole(const EntryIndex& i,int col) const
{ {
switch(col) switch(col)
{ {
case COLLECTION_MODEL_FILENAME: return (i.is_file)? case COLLECTION_MODEL_FILENAME: if(i.is_file)
(QString::fromUtf8(mCollection.fileTree().fileData(i.index).name.c_str())) return QString::fromUtf8(mCollection.fileTree().fileData(i.index).name.c_str());
: (QString::fromUtf8(mCollection.fileTree().directoryData(i.index).name.c_str())); else
return QString::fromUtf8(mCollection.fileTree().directoryData(i.index).name.c_str());
case COLLECTION_MODEL_SIZE: if(i.is_file) case COLLECTION_MODEL_SIZE: if(i.is_file)
return QVariant((qulonglong)mCollection.fileTree().fileData(i.index).size) ; return QVariant((qulonglong)mCollection.fileTree().fileData(i.index).size) ;
else else
return QVariant((qulonglong)mDirInfos[i.index].total_size); return QVariant((qulonglong)mDirInfos[i.index].total_size);
case COLLECTION_MODEL_HASH: return (i.is_file)? case COLLECTION_MODEL_HASH: if(i.is_file)
QString::fromStdString(mCollection.fileTree().fileData(i.index).hash.toStdString()) {
:QVariant(); if(mFilesBeingHashed.find(mCollection.fileTree().fileData(i.index).hash)!=mFilesBeingHashed.end())
return tr("[File is being hashed]");
else
return QString::fromStdString(mCollection.fileTree().fileData(i.index).hash.toStdString());
}
else
return QVariant();
case COLLECTION_MODEL_COUNT: if(i.is_file) case COLLECTION_MODEL_COUNT: if(i.is_file)
return (qulonglong)mFileInfos[i.index].is_checked; return (qulonglong)mFileInfos[i.index].is_checked;
@ -422,6 +438,15 @@ QVariant RsCollectionModel::decorationRole(const EntryIndex& i,int col) const
return QVariant(); return QVariant();
} }
void RsCollectionModel::notifyFilesBeingHashed(const std::list<RsFileHash>& files)
{
mFilesBeingHashed.insert(files.begin(),files.end());
}
void RsCollectionModel::fileHashingFinished(const RsFileHash& hash)
{
mFilesBeingHashed.erase(hash);
}
void RsCollectionModel::preMods() void RsCollectionModel::preMods()
{ {
mUpdating = true; mUpdating = true;

View File

@ -48,6 +48,8 @@ class RsCollectionModel: public QAbstractItemModel
uint64_t totalSize() const { return mDirInfos[0].total_size; } uint64_t totalSize() const { return mDirInfos[0].total_size; }
uint64_t totalSelected() const { return mDirInfos[0].total_count; } uint64_t totalSelected() const { return mDirInfos[0].total_count; }
void notifyFilesBeingHashed(const std::list<RsFileHash>& files);
void fileHashingFinished(const RsFileHash& hash);
signals: signals:
void sizesChanged(); // tells that the total size of the top level dir has changed (due to selection) void sizesChanged(); // tells that the total size of the top level dir has changed (due to selection)
@ -61,6 +63,7 @@ class RsCollectionModel: public QAbstractItemModel
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 ;
QVariant checkStateRole(const EntryIndex& i,int col) const; QVariant checkStateRole(const EntryIndex& i,int col) const;
QVariant textColorRole(const EntryIndex& i,int col) const;
//QVariant filterRole(const DirDetails& details,int coln) const; //QVariant filterRole(const DirDetails& details,int coln) const;
void debugDump(); void debugDump();
@ -96,5 +99,7 @@ class RsCollectionModel: public QAbstractItemModel
std::vector<ModelFileInfo> mFileInfos; std::vector<ModelFileInfo> mFileInfos;
std::vector<ModelDirInfo> mDirInfos; std::vector<ModelDirInfo> mDirInfos;
std::set<RsFileHash> mFilesBeingHashed;
// std::set<void*> mFilteredPointers ; // std::set<void*> mFilteredPointers ;
}; };