added new folder capability in collection

This commit is contained in:
csoler 2024-03-14 22:44:49 +01:00
parent 27f0962654
commit a36f7221e7
6 changed files with 49 additions and 12 deletions

View File

@ -144,9 +144,9 @@ static QString purifyFileName(const QString& input,bool& bad)
return output ;
}
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,RsFileTree::DirIndex parent_index)
{
mHashes[hash]= mFileTree->addFile(mFileTree->root(),fname.toStdString(),hash,size);
mHashes[hash]= mFileTree->addFile(parent_index,fname.toStdString(),hash,size);
#ifdef TO_REMOVE
ColFileInfo info ;
info.type = DIR_TYPE_FILE ;
@ -157,9 +157,9 @@ void RsCollection::merge_in(const QString& fname,uint64_t size,const RsFileHash&
recursAddElements(_xml_doc,info,_root) ;
#endif
}
void RsCollection::merge_in(const RsFileTree& tree)
void RsCollection::merge_in(const RsFileTree& tree, RsFileTree::DirIndex parent_index)
{
recursMergeTree(mFileTree->root(),tree,tree.directoryData(tree.root())) ;
recursMergeTree(mFileTree->root(),tree,tree.directoryData(parent_index)) ;
}
void RsCollection::recursMergeTree(RsFileTree::DirIndex parent,const RsFileTree& tree,const RsFileTree::DirData& dd)

View File

@ -77,8 +77,8 @@ public:
virtual ~RsCollection() ;
void merge_in(const QString& fname,uint64_t size,const RsFileHash& hash) ;
void merge_in(const RsFileTree& tree) ;
void merge_in(const QString& fname,uint64_t size,const RsFileHash& hash,RsFileTree::DirIndex parent_index=0) ;
void merge_in(const RsFileTree& tree,RsFileTree::DirIndex parent_index=0) ;
static const QString ExtensionString ;

View File

@ -1132,6 +1132,32 @@ void RsCollectionDialog::processItem(QMap<QString, QString> &dirToAdd
*/
void RsCollectionDialog::makeDir()
{
QModelIndexList selected_indices = ui._fileEntriesTW->selectionModel()->selectedIndexes();
if(selected_indices.size() > 1)
{
QMessageBox::information(nullptr,tr("Too many places selected"),tr("Please select at most one directory where to create the new folder"));
return;
}
QModelIndex place_index;
if(!selected_indices.empty())
place_index = selected_indices.first();
RsCollectionModel::EntryIndex e = mCollectionModel->getIndex(place_index);
if(e.is_file)
{
QMessageBox::information(nullptr,tr("Selected place cannot be a file"),tr("Please select at most one directory where to create the new folder"));
return;
}
QString childName = QInputDialog::getText(this, tr("New Directory"), tr("Enter the new directory's name"), QLineEdit::Normal);
mCollectionModel->preMods();
mCollection->merge_in(*RsFileTree::fromDirectory(childName.toUtf8().constData()),e.index);
mCollectionModel->postMods();
#ifdef TODO_COLLECTION
QString childName="";
bool ok, badChar, nameOK = false;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>671</width>
<height>400</height>
<width>761</width>
<height>434</height>
</rect>
</property>
<property name="contextMenuPolicy">
@ -283,7 +283,7 @@
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/feedback_arrow.png</normaloff>:/images/feedback_arrow.png</iconset>
<normaloff>:/images/start.png</normaloff>:/images/start.png</iconset>
</property>
</widget>
</item>
@ -309,7 +309,7 @@
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/update.png</normaloff>:/images/update.png</iconset>
<normaloff>:/images/startall.png</normaloff>:/images/startall.png</iconset>
</property>
</widget>
</item>
@ -334,8 +334,8 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset>
<normaloff>:/images/deletemail24.png</normaloff>:/images/deletemail24.png</iconset>
<iconset resource="../images.qrc">
<normaloff>:/images/delete.png</normaloff>:/images/delete.png</iconset>
</property>
</widget>
</item>

View File

@ -438,6 +438,15 @@ QVariant RsCollectionModel::decorationRole(const EntryIndex& i,int col) const
return QVariant();
}
RsCollectionModel::EntryIndex RsCollectionModel::getIndex(const QModelIndex& i) const
{
EntryIndex res;
res.is_file = false;
res.index = 0;
convertInternalIdToIndex(i.internalId(),res);
return res;
}
bool RsCollectionModel::isChecked(EntryIndex i)
{
if(i.is_file)

View File

@ -51,6 +51,8 @@ class RsCollectionModel: public QAbstractItemModel
void notifyFilesBeingHashed(const std::list<RsFileHash>& files);
void fileHashingFinished(const RsFileHash& hash);
bool isChecked(EntryIndex);
EntryIndex getIndex(const QModelIndex& i) const;
signals:
void sizesChanged(); // tells that the total size of the top level dir has changed (due to selection)