@@ -98,7 +98,7 @@ DocsetsDialog::DocsetsDialog(Core::Application *app, QWidget *parent) :
98
98
[this , selectionModel]() {
99
99
ui->removeDocsetsButton ->setEnabled (selectionModel->hasSelection ());
100
100
101
- for (const QModelIndex &index : selectionModel->selectedIndexes ()) {
101
+ for (const QModelIndex &index : selectionModel->selectedRows ()) {
102
102
if (index .data (ListModel::UpdateAvailableRole).toBool ()) {
103
103
ui->updateSelectedDocsetsButton ->setEnabled (true );
104
104
return ;
@@ -135,7 +135,7 @@ DocsetsDialog::DocsetsDialog(Core::Application *app, QWidget *parent) :
135
135
136
136
selectionModel = ui->availableDocsetList ->selectionModel ();
137
137
connect (selectionModel, &QItemSelectionModel::selectionChanged, [this , selectionModel]() {
138
- for (const QModelIndex &index : selectionModel->selectedIndexes ()) {
138
+ for (const QModelIndex &index : selectionModel->selectedRows ()) {
139
139
if (!index .data (ProgressItemDelegate::ShowProgressRole).toBool ()) {
140
140
ui->downloadDocsetsButton ->setEnabled (true );
141
141
return ;
@@ -217,7 +217,7 @@ void DocsetsDialog::addDashFeed()
217
217
218
218
void DocsetsDialog::updateSelectedDocsets ()
219
219
{
220
- for (const QModelIndex &index : ui->installedDocsetList ->selectionModel ()->selectedIndexes ()) {
220
+ for (const QModelIndex &index : ui->installedDocsetList ->selectionModel ()->selectedRows ()) {
221
221
if (!index .data (Registry::ListModel::UpdateAvailableRole).toBool ())
222
222
continue ;
223
223
@@ -245,7 +245,7 @@ void DocsetsDialog::removeSelectedDocsets()
245
245
246
246
int ret;
247
247
248
- const QModelIndexList selectedIndexes = selectonModel->selectedIndexes ();
248
+ const QModelIndexList selectedIndexes = selectonModel->selectedRows ();
249
249
if (selectedIndexes.size () == 1 ) {
250
250
const QString docsetTitle = selectedIndexes.first ().data ().toString ();
251
251
ret = QMessageBox::question (this , QStringLiteral (" Zeal" ),
@@ -286,7 +286,7 @@ void DocsetsDialog::updateDocsetFilter(const QString &filterString)
286
286
void DocsetsDialog::downloadSelectedDocsets ()
287
287
{
288
288
QItemSelectionModel *selectionModel = ui->availableDocsetList ->selectionModel ();
289
- for (const QModelIndex &index : selectionModel->selectedIndexes ()) {
289
+ for (const QModelIndex &index : selectionModel->selectedRows ()) {
290
290
selectionModel->select (index , QItemSelectionModel::Deselect);
291
291
292
292
// Do nothing if a download is already in progress.
@@ -693,18 +693,21 @@ void DocsetsDialog::removeDocset(const QString &name)
693
693
const QString tmpPath = docsetPath + QLatin1String (" .deleteme." )
694
694
+ QString::number (QDateTime::currentMSecsSinceEpoch ());
695
695
696
- // Rename first to allow simultaneous installation.
697
- // TODO: Check for error
698
- QDir ().rename (docsetPath, tmpPath);
699
-
696
+ // Remove from registry first to avoid renaming files in use on Windows.
700
697
m_docsetRegistry->remove (name);
701
698
702
- QFuture<bool > future = QtConcurrent::run ([tmpPath] {
703
- return QDir (tmpPath).removeRecursively ();
704
- });
699
+ // Rename first to allow simultaneous installation.
700
+ if (!QDir ().rename (docsetPath, tmpPath)) {
701
+ const QString error = tr (" Cannot delete docset <b>%1</b>! Please try closing other "
702
+ " applications first, as they may be accessing the docset "
703
+ " files." ).arg (title);
704
+ QMessageBox::warning (this , QStringLiteral (" Zeal" ), error);
705
+ m_docsetsBeingDeleted.removeOne (name);
706
+ m_docsetRegistry->addDocset (docsetPath);
707
+ return ;
708
+ }
705
709
706
710
QFutureWatcher<bool > *watcher = new QFutureWatcher<bool >();
707
- watcher->setFuture (future);
708
711
connect (watcher, &QFutureWatcher<void >::finished, [=] {
709
712
if (!watcher->result ()) {
710
713
QMessageBox::warning (this , QStringLiteral (" Zeal" ),
@@ -719,6 +722,10 @@ void DocsetsDialog::removeDocset(const QString &name)
719
722
720
723
m_docsetsBeingDeleted.removeOne (name);
721
724
});
725
+
726
+ watcher->setFuture (QtConcurrent::run ([tmpPath] {
727
+ return QDir (tmpPath).removeRecursively ();
728
+ }));
722
729
}
723
730
724
731
void DocsetsDialog::updateCombinedProgress ()
@@ -749,7 +756,7 @@ void DocsetsDialog::resetProgress()
749
756
ui->addFeedButton ->setEnabled (true );
750
757
QItemSelectionModel *selectionModel = ui->installedDocsetList ->selectionModel ();
751
758
bool hasSelectedUpdates = false ;
752
- for (const QModelIndex &index : selectionModel->selectedIndexes ()) {
759
+ for (const QModelIndex &index : selectionModel->selectedRows ()) {
753
760
if (index .data (Registry::ListModel::UpdateAvailableRole).toBool ()) {
754
761
hasSelectedUpdates = true ;
755
762
break ;
0 commit comments