Dive media: implement "Open folder of selected media files"

Add a context-menu entry to TabDivePhotos which opens the folder(s)
of all selected files.

Fixes #1514.

Suggested-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-07-18 23:09:31 +02:00 committed by Robert C. Helling
parent 325b8bba35
commit 4f42e4fd50
2 changed files with 19 additions and 0 deletions

View file

@ -10,6 +10,7 @@
#include <QMenu>
#include <QUrl>
#include <QMessageBox>
#include <QFileInfo>
//TODO: Remove those in the future.
#include "../mainwindow.h"
@ -54,6 +55,7 @@ void TabDivePhotos::contextMenuEvent(QContextMenuEvent *event)
popup.addSeparator();
popup.addAction(tr("Delete selected media files"), this, SLOT(removeSelectedPhotos()));
popup.addAction(tr("Delete all media files"), this, SLOT(removeAllPhotos()));
popup.addAction(tr("Open folder of selected media files"), this, SLOT(openFolderOfSelectedFiles()));
popup.addAction(tr("Recalculate selected thumbnails"), this, SLOT(recalculateSelectedThumbnails()));
popup.exec(event->globalPos());
event->accept();
@ -83,6 +85,22 @@ void TabDivePhotos::removeSelectedPhotos()
DivePictureModel::instance()->removePictures(getSelectedFilenames());
}
void TabDivePhotos::openFolderOfSelectedFiles()
{
QVector<QString> directories;
for (const QString &filename: getSelectedFilenames()) {
QFileInfo info(filename);
if (!info.exists())
continue;
QString path = info.absolutePath();
if (path.isEmpty() || directories.contains(path))
continue;
directories.append(path);
}
for (const QString &dir: directories)
QDesktopServices::openUrl(QUrl::fromLocalFile(dir));
}
void TabDivePhotos::recalculateSelectedThumbnails()
{
Thumbnailer::instance()->calculateThumbnails(getSelectedFilenames());

View file

@ -27,6 +27,7 @@ private slots:
void removeAllPhotos();
void removeSelectedPhotos();
void recalculateSelectedThumbnails();
void openFolderOfSelectedFiles();
void changeZoomLevel(int delta);
private: