mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #449 from PhenomRetroShare/Add_RemoveDuplicateCBInRSCollEditor
Add Remove Duplicate checkbox in RsCollection editor.
This commit is contained in:
commit
edce1e953c
@ -160,6 +160,7 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName
|
||||
connect(ui._addRecur_PB, SIGNAL(clicked()), this, SLOT(addRecursive()));
|
||||
connect(ui._remove_PB, SIGNAL(clicked()), this, SLOT(remove()));
|
||||
connect(ui._makeDir_PB, SIGNAL(clicked()), this, SLOT(makeDir()));
|
||||
connect(ui._removeDuplicate_CB, SIGNAL(clicked(bool)), this, SLOT(updateRemoveDuplicate(bool)));
|
||||
connect(ui._cancel_PB, SIGNAL(clicked()), this, SLOT(cancel()));
|
||||
connect(ui._save_PB, SIGNAL(clicked()), this, SLOT(save()));
|
||||
connect(ui._download_PB, SIGNAL(clicked()), this, SLOT(download()));
|
||||
@ -190,6 +191,7 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName
|
||||
// 5 Activate button follow creationMode
|
||||
ui._changeFile->setVisible(_creationMode && !_readOnly);
|
||||
ui._makeDir_PB->setVisible(_creationMode && !_readOnly);
|
||||
ui._removeDuplicate_CB->setVisible(_creationMode && !_readOnly);
|
||||
ui._save_PB->setVisible(_creationMode && !_readOnly);
|
||||
ui._treeViewFrame->setVisible(_creationMode && !_readOnly);
|
||||
ui._download_PB->setVisible(!_creationMode && !_readOnly);
|
||||
@ -408,7 +410,10 @@ bool RsCollectionDialog::addChild(QTreeWidgetItem* parent, const std::vector<Col
|
||||
if (colFileInfo.type == DIR_TYPE_DIR){
|
||||
founds = ui._fileEntriesTW->findItems(colFileInfo.path + "/" +colFileInfo.name, Qt::MatchExactly | Qt::MatchRecursive, COLUMN_FILEPATH);
|
||||
} else {
|
||||
founds = ui._fileEntriesTW->findItems(colFileInfo.hash, Qt::MatchExactly | Qt::MatchRecursive, COLUMN_HASH);
|
||||
founds = ui._fileEntriesTW->findItems(colFileInfo.path + "/" +colFileInfo.name, Qt::MatchExactly | Qt::MatchRecursive, COLUMN_FILEPATH);
|
||||
if (ui._removeDuplicate_CB->isChecked()) {
|
||||
founds << ui._fileEntriesTW->findItems(colFileInfo.hash, Qt::MatchExactly | Qt::MatchRecursive, COLUMN_HASH);
|
||||
}
|
||||
}
|
||||
if (founds.empty()) {
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem;
|
||||
@ -493,7 +498,8 @@ bool RsCollectionDialog::addChild(QTreeWidgetItem* parent, const std::vector<Col
|
||||
|
||||
if (colFileInfo.type == DIR_TYPE_DIR) {
|
||||
wrong_chars |= addChild(founds.at(0), colFileInfo.children);
|
||||
} }
|
||||
}
|
||||
}
|
||||
}
|
||||
return wrong_chars;
|
||||
}
|
||||
@ -827,9 +833,29 @@ void RsCollectionDialog::remove()
|
||||
//msgBox->setInformativeText(); If text too long, no scroll, so I add an text edit
|
||||
QGridLayout* layout = qobject_cast<QGridLayout*>(msgBox->layout());
|
||||
if (layout) {
|
||||
QTextEdit* edit = new QTextEdit(tr("Do you want to remove them and all their children, too? <br>") + listDir);
|
||||
int newRow = 1;
|
||||
for (int row = layout->count()-1; row >= 0; --row) {
|
||||
for (int col = layout->columnCount()-1; col >= 0; --col) {
|
||||
QLayoutItem *item = layout->itemAtPosition(row, col);
|
||||
if (item) {
|
||||
int index = layout->indexOf(item->widget());
|
||||
int r=0, c=0, rSpan=0, cSpan=0;
|
||||
layout->getItemPosition(index, &r, &c, &rSpan, &cSpan);
|
||||
if (r>0) {
|
||||
layout->removeItem(item);
|
||||
layout->addItem(item, r+3, c, rSpan, cSpan);
|
||||
} else if (rSpan>1) {
|
||||
newRow = rSpan + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QLabel *label = new QLabel(tr("Do you want to remove them and all their children, too?"));
|
||||
layout->addWidget(label,newRow, 0, 1, layout->columnCount(), Qt::AlignHCenter );
|
||||
QTextEdit *edit = new QTextEdit(listDir);
|
||||
edit->setReadOnly(true);
|
||||
layout->addWidget(edit,0 ,1);
|
||||
edit->setWordWrapMode(QTextOption::NoWrap);
|
||||
layout->addWidget(edit,newRow+1, 0, 1, layout->columnCount(), Qt::AlignHCenter );
|
||||
}
|
||||
|
||||
msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
@ -1063,6 +1089,79 @@ void RsCollectionDialog::itemChanged(QTreeWidgetItem *item, int col)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RsCollectionDialog::updateRemoveDuplicate Remove all duplicate file when checked.
|
||||
* @param checked
|
||||
*/
|
||||
void RsCollectionDialog::updateRemoveDuplicate(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
QTreeWidgetItemIterator it(ui._fileEntriesTW);
|
||||
QTreeWidgetItem *item;
|
||||
while ((item = *it) != NULL) {
|
||||
++it;
|
||||
if (item->data(COLUMN_HASH, ROLE_TYPE).toUInt() != DIR_TYPE_DIR) {
|
||||
QList<QTreeWidgetItem*> founds;
|
||||
founds << ui._fileEntriesTW->findItems(item->text(COLUMN_HASH), Qt::MatchExactly | Qt::MatchRecursive, COLUMN_HASH);
|
||||
if (founds.count() > 1) {
|
||||
QMessageBox* msgBox = new QMessageBox(QMessageBox::Information, "", "");
|
||||
msgBox->setText("Warning, duplicate file found.");
|
||||
//msgBox->setInformativeText(); If text too long, no scroll, so I add an text edit
|
||||
msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
msgBox->setDefaultButton(QMessageBox::Yes);
|
||||
|
||||
QGridLayout* layout = qobject_cast<QGridLayout*>(msgBox->layout());
|
||||
if (layout) {
|
||||
int newRow = 1;
|
||||
for (int row = layout->count()-1; row >= 0; --row) {
|
||||
for (int col = layout->columnCount()-1; col >= 0; --col) {
|
||||
QLayoutItem *item = layout->itemAtPosition(row, col);
|
||||
if (item) {
|
||||
int index = layout->indexOf(item->widget());
|
||||
int r=0, c=0, rSpan=0, cSpan=0;
|
||||
layout->getItemPosition(index, &r, &c, &rSpan, &cSpan);
|
||||
if (r>0) {
|
||||
layout->removeItem(item);
|
||||
layout->addItem(item, r+3, c, rSpan, cSpan);
|
||||
} else if (rSpan>1) {
|
||||
newRow = rSpan + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QLabel *label = new QLabel(tr("Do you want to remove this file from the list?"));
|
||||
layout->addWidget(label,newRow, 0, 1, layout->columnCount(), Qt::AlignHCenter );
|
||||
QTextEdit *edit = new QTextEdit(item->text(COLUMN_FILEPATH));
|
||||
edit->setReadOnly(true);
|
||||
edit->setWordWrapMode(QTextOption::NoWrap);
|
||||
layout->addWidget(edit,newRow+1, 0, 1, layout->columnCount(), Qt::AlignHCenter );
|
||||
}
|
||||
|
||||
int ret = msgBox->exec();
|
||||
switch (ret) {
|
||||
case QMessageBox::Yes:
|
||||
item->parent()->removeChild(item);
|
||||
break;
|
||||
case QMessageBox::No:
|
||||
break;
|
||||
case QMessageBox::Cancel: {
|
||||
delete msgBox;
|
||||
ui._removeDuplicate_CB->setChecked(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// should never be reached
|
||||
break;
|
||||
}
|
||||
delete msgBox;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RsCollectionDialog::cancel: Cancel RScollection editing or donwloading
|
||||
*/
|
||||
|
@ -56,6 +56,7 @@ private slots:
|
||||
void makeDir() ;
|
||||
void fileHashingFinished(QList<HashedFile> hashedFiles) ;
|
||||
void itemChanged(QTreeWidgetItem* item,int col) ;
|
||||
void updateRemoveDuplicate(bool checked);
|
||||
void cancel() ;
|
||||
void download() ;
|
||||
void save() ;
|
||||
|
@ -21,7 +21,16 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
@ -59,7 +68,16 @@
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -83,7 +101,16 @@
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -197,7 +224,16 @@
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -207,7 +243,16 @@
|
||||
</property>
|
||||
<widget class="QFrame" name="_treeViewFrame">
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -359,6 +404,13 @@
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="_removeDuplicate_CB">
|
||||
<property name="text">
|
||||
<string>Remove Duplicate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
@ -405,12 +457,6 @@
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder></zorder>
|
||||
<zorder></zorder>
|
||||
<zorder>_mainSplitter</zorder>
|
||||
<zorder>_listSplitter</zorder>
|
||||
<zorder></zorder>
|
||||
<zorder>_mainSplitter</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
Loading…
Reference in New Issue
Block a user