git repos / SagoImageBrowser

commit 700d6f2d

Poul Sander · 2026-06-06 15:44
700d6f2d0b08a4b3ace155f86a5988d2cf639415 patch · browse files
parent 237d2c816459e2a34d843e5160a1ef523a8f2ca7

Show filename and make an option for "Move to Trash"

Changed files

M src/exifreader.cpp before
M src/exifreader.h before
M src/mainwindow.cpp before
M src/mainwindow.h before
diff --git a/src/exifreader.cpp b/src/exifreader.cpp index 3f94eb8..0ee3e61 100644 --- a/src/exifreader.cpp +++ b/src/exifreader.cpp
@@ -7,6 +7,7 @@
#include <sys/stat.h>
#include <fcntl.h>
+#include <filesystem>
#include <unistd.h>
// Raw EXIF date format is "YYYY:MM:DD HH:MM:SS"; reformat date separators to dashes
@@ -39,7 +40,7 @@ bool ExifData::isEmpty() const
&& dateTime.isEmpty() && make.isEmpty() && model.isEmpty()
&& exposureTime.isEmpty() && fNumber.isEmpty() && iso.isEmpty()
&& focalLength.isEmpty() && flash.isEmpty()
- && dimensions.isEmpty() && fileSize.isEmpty();
+ && filename.isEmpty() && dimensions.isEmpty() && fileSize.isEmpty();
}
QList<QPair<QString, QString>> ExifData::toList() const
@@ -55,6 +56,7 @@ QList<QPair<QString, QString>> ExifData::toList() const
addField(result, "ISO", iso);
addField(result, "Focal Length", focalLength);
addField(result, "Flash", flash);
+ addField(result, "Filename", filename);
addField(result, "Dimensions", dimensions);
addField(result, "File Size", fileSize);
return result;
@@ -68,6 +70,14 @@ ExifData ExifReader::read(const QByteArray &path)
if (::stat(path.constData(), &st) != 0 || !S_ISREG(st.st_mode))
return data;
+ // Filename
+ {
+ const std::filesystem::path fsPath(path.toStdString());
+ const std::string nativeName = fsPath.filename().native();
+ data.filename = QString::fromLocal8Bit(
+ nativeName.data(), static_cast<qsizetype>(nativeName.size()));
+ }
+
// File size
{
qint64 size = static_cast<qint64>(st.st_size);
diff --git a/src/exifreader.h b/src/exifreader.h index 450d5cd..c6b1d29 100644 --- a/src/exifreader.h +++ b/src/exifreader.h
@@ -16,6 +16,7 @@ struct ExifData {
QString iso;
QString focalLength;
QString flash;
+ QString filename;
QString dimensions;
QString fileSize;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e631c72..3872413 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp
@@ -36,6 +36,7 @@
#include <QCompleter>
#include <QClipboard>
#include <QDialogButtonBox>
+#include <QFile>
#include <QFileInfo>
#include <QGuiApplication>
#include <QVBoxLayout>
@@ -635,6 +636,7 @@ void MainWindow::showImageContextMenu(const QPoint &pos)
QAction *copyFullPathAction = menu.addAction(tr("Copy full path"));
menu.addSeparator();
QAction *editDescriptionAction = menu.addAction(tr("Edit description"));
+ QAction *moveToTrashAction = menu.addAction(tr("Move to trash"));
QAction *chosen = menu.exec(m_listView->viewport()->mapToGlobal(pos));
if (chosen == copyFilenameAction) {
@@ -643,9 +645,40 @@ void MainWindow::showImageContextMenu(const QPoint &pos)
QGuiApplication::clipboard()->setText(displayPath(path));
} else if (chosen == editDescriptionAction) {
onEditCaption();
+ } else if (chosen == moveToTrashAction) {
+ moveImageToTrash(path);
}
}
+void MainWindow::moveImageToTrash(const QByteArray &path)
+{
+ if (path.isEmpty())
+ return;
+
+ const QString fileName = filenameFromPath(path);
+ const QMessageBox::StandardButton answer = QMessageBox::question(
+ this,
+ tr("Move to Trash"),
+ tr("Move \"%1\" to the trash?").arg(fileName),
+ QMessageBox::Yes | QMessageBox::Cancel,
+ QMessageBox::Cancel);
+ if (answer != QMessageBox::Yes)
+ return;
+
+ if (!QFile::moveToTrash(displayPath(path))) {
+ QMessageBox::warning(this, tr("Cannot Move to Trash"),
+ tr("The file could not be moved to the trash.\n\n%1")
+ .arg(displayPath(path)));
+ return;
+ }
+
+ const QByteArray currentDir = m_imageModel->currentDirectory();
+ m_previewLabel->clear();
+ m_exifTable->setRowCount(0);
+ m_imageModel->setDirectory(currentDir);
+ QTimer::singleShot(0, this, &MainWindow::loadVisibleThumbnails);
+}
+
void MainWindow::leaveSingleImageMode()
{
if (isFullScreen()) {
diff --git a/src/mainwindow.h b/src/mainwindow.h index 1e3e8b4..51043c2 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h
@@ -48,6 +48,7 @@ private:
void leaveSingleImageMode();
void onEditCaption();
void showImageContextMenu(const QPoint &pos);
+ void moveImageToTrash(const QByteArray &path);
void onPathEntered();
void updatePathField(const QByteArray &path);
QList<QByteArray> computeNeighborPaths(const QModelIndex &index) const;