Skip to content

Commit 0701eac

Browse files
committed
fix crash on Windows folder shortcut in Files
https://forum.shotcut.org/t/hidden-muted-clip-still-causes-disk-file- access/47929/4 Also, fixes double-click/enter to open folder shortcut.
1 parent 9087ef7 commit 0701eac

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

src/docks/filesdock.cpp

+25-28
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ class FilesModel : public QFileSystemModel
231231

232232
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
233233
{
234-
const auto isDir = fileInfo(index).isDir();
234+
const auto info = fileInfo(index);
235+
const auto isDir = info.isDir();
235236
if (MediaTypeStringRole == role || (index.column() == 2 && Qt::DisplayRole == role)) {
236237
QString names[] = {
237238
tr("Video"),
@@ -245,18 +246,19 @@ class FilesModel : public QFileSystemModel
245246
}
246247
switch (role) {
247248
case Qt::ToolTipRole:
248-
return QDir::toNativeSeparators(filePath(index));
249+
return QDir::toNativeSeparators(info.filePath());
249250
case DateRole:
250-
return fileInfo(index).lastModified();
251+
return info.lastModified();
251252
case MediaTypeRole:
252253
return isDir ? PlaylistModel::Other : mediaType(index);
253254
case ThumbnailRole: {
254-
const auto path = filePath(index);
255+
const auto path = info.filePath();
255256
const auto thumbnailKey = FilesThumbnailTask::cacheKey(path);
256257
auto image = DB.getThumbnail(thumbnailKey);
257258
if (image.isNull()) {
258259
::cacheThumbnail(const_cast<FilesModel *>(this), path, image, index);
259-
if (!path.endsWith(QStringLiteral(".mlt"), Qt::CaseInsensitive))
260+
if (!path.endsWith(QStringLiteral(".mlt"), Qt::CaseInsensitive)
261+
&& !info.isShortcut())
260262
QThreadPool::globalInstance()->start(
261263
new FilesThumbnailTask(const_cast<FilesModel *>(this), path, index));
262264
}
@@ -385,11 +387,13 @@ class FilesTileDelegate : public QStyledItemDelegate
385387
}
386388

387389
auto thumbRect = thumb.rect();
388-
const float width = qRound(16.f / 9.f * option.rect.height());
389-
thumbRect = QRect(0, 0, width, qRound(width * thumbRect.height() / thumbRect.width()));
390-
thumbRect.moveCenter(option.rect.center());
391-
thumbRect.moveLeft(0);
392-
painter->drawImage(thumbRect, thumb);
390+
if (thumbRect.width() > 0) {
391+
const float width = qRound(16.f / 9.f * option.rect.height());
392+
thumbRect = QRect(0, 0, width, qRound(width * thumbRect.height() / thumbRect.width()));
393+
thumbRect.moveCenter(option.rect.center());
394+
thumbRect.moveLeft(0);
395+
painter->drawImage(thumbRect, thumb);
396+
}
393397
auto textRect = option.rect;
394398
textRect.setHeight(lineHeight * 3 + kTilePaddingPx);
395399
textRect.moveCenter(option.rect.center());
@@ -398,10 +402,9 @@ class FilesTileDelegate : public QStyledItemDelegate
398402
QPoint textPoint = textRect.topLeft();
399403
textPoint.setY(textPoint.y() + lineHeight);
400404
painter->setFont(boldFont);
401-
painter->drawText(textPoint,
402-
painter->fontMetrics().elidedText(fileInfo.fileName(),
403-
Qt::ElideMiddle,
404-
textRect.width()));
405+
auto name = fileInfo.isShortcut() ? fileInfo.baseName() : fileInfo.fileName();
406+
name = painter->fontMetrics().elidedText(name, Qt::ElideMiddle, textRect.width());
407+
painter->drawText(textPoint, name);
405408
painter->setFont(oldFont);
406409

407410
textPoint.setY(textPoint.y() + lineHeight);
@@ -411,11 +414,11 @@ class FilesTileDelegate : public QStyledItemDelegate
411414
.toDateTime()
412415
.toString("yyyy-MM-dd HH:mm:ss")));
413416
textPoint.setY(textPoint.y() + lineHeight);
414-
if (!fileInfo.isDir()) {
417+
if (fileInfo.isFile()) {
415418
// Get the text of the second (size) column
416419
auto myindex = index.model()->index(index.row(), 1, index.parent());
417-
auto mediaType = myindex.data(Qt::DisplayRole).toString();
418-
painter->drawText(textPoint, tr("Size: %1").arg(mediaType));
420+
auto size = myindex.data(Qt::DisplayRole).toString();
421+
painter->drawText(textPoint, tr("Size: %1").arg(size));
419422
}
420423
}
421424

@@ -682,19 +685,12 @@ FilesDock::FilesDock(QWidget *parent)
682685
ui->tableView->horizontalHeader()->setSectionsMovable(true);
683686
ui->tableView->setColumnWidth(1, 100);
684687
connect(ui->tableView, &QAbstractItemView::activated, this, [=](const QModelIndex &index) {
685-
auto sourceIndex = m_filesProxyModel->mapToSource(index);
686-
auto filePath = m_filesModel->filePath(sourceIndex);
688+
const auto sourceIndex = m_filesProxyModel->mapToSource(index);
689+
const auto filePath = m_filesModel->filePath(sourceIndex);
687690

688691
LOG_DEBUG() << "activated" << filePath;
689692
if (m_filesModel->isDir(sourceIndex)) {
690-
m_filesModel->setRootPath(filePath);
691-
Settings.setFilesCurrentDir(filePath);
692-
changeFilesDirectory(index);
693-
m_view->setCurrentIndex(QModelIndex());
694-
const auto dirsIndex = m_dirsModel->index(filePath);
695-
ui->treeView->setExpanded(dirsIndex, true);
696-
ui->treeView->scrollTo(dirsIndex);
697-
ui->treeView->setCurrentIndex(dirsIndex);
693+
changeDirectory(filePath);
698694
return;
699695
}
700696
m_selectionModel->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
@@ -1106,7 +1102,8 @@ void FilesDock::changeDirectory(const QString &filePath, bool updateLocation)
11061102
}
11071103
index = m_filesModel->setRootPath(path);
11081104
Settings.setFilesCurrentDir(path);
1109-
ui->locationsCombo->setToolTip(QDir::toNativeSeparators(path));
1105+
path = QDir::toNativeSeparators(path);
1106+
ui->locationsCombo->setToolTip(path);
11101107
if (updateLocation && path != ui->locationsCombo->currentText())
11111108
ui->locationsCombo->setCurrentText(path);
11121109
m_view->setRootIndex(m_filesProxyModel->mapFromSource(index));

0 commit comments

Comments
 (0)