From 90026f931f61e70e1b1393318c5b54c0dba9abe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Wed, 2 Apr 2025 20:27:59 +0200 Subject: [PATCH] Add open file and open file location to DB view --- batchprocessing.cpp | 31 ++++++++++++++++++------------- batchprocessing.h | 2 ++ databaseview.cpp | 19 ++++++++++++++++++- databaseview.h | 2 ++ 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/batchprocessing.cpp b/batchprocessing.cpp index ef8e365..8ebc475 100644 --- a/batchprocessing.cpp +++ b/batchprocessing.cpp @@ -183,19 +183,7 @@ void BatchProcessing::browse() void BatchProcessing::openScriptDir() { -#ifdef Q_OS_LINUX - QDBusConnection con = QDBusConnection::sessionBus(); - QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.FileManager1", "/org/freedesktop/FileManager1", "org.freedesktop.FileManager1", "ShowFolders"); - QList args = {QStringList(QUrl::fromLocalFile(_scriptBasePath).toString()), QString()}; - message.setArguments(args); - con.call(message); -#endif -#ifdef Q_OS_WINDOWS - QProcess::startDetached("explorer.exe", {QDir::toNativeSeparators(_scriptBasePath)}); -#endif -#ifdef Q_OS_MACOS - QDesktopServices::openUrl(QUrl::fromLocalFile(_scriptBasePath)); -#endif + openDir(_scriptBasePath); } void BatchProcessing::runScript() @@ -309,3 +297,20 @@ void BatchProcessing::plot(const QVector &points) diag->resize(640, 480); diag->show(); } + +void openDir(const QString &path) +{ +#ifdef Q_OS_LINUX + QDBusConnection con = QDBusConnection::sessionBus(); + QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.FileManager1", "/org/freedesktop/FileManager1", "org.freedesktop.FileManager1", "ShowFolders"); + QList args = {QStringList(QUrl::fromLocalFile(path).toString()), QString()}; + message.setArguments(args); + con.call(message); +#endif +#ifdef Q_OS_WINDOWS + QProcess::startDetached("explorer.exe", {QDir::toNativeSeparators(path)}); +#endif +#ifdef Q_OS_MACOS + QDesktopServices::openUrl(QUrl::fromLocalFile(path)); +#endif +} diff --git a/batchprocessing.h b/batchprocessing.h index dce4bc3..57d6709 100644 --- a/batchprocessing.h +++ b/batchprocessing.h @@ -45,4 +45,6 @@ public slots: void plot(const QVector &points); }; +void openDir(const QString &path); + #endif // BATCHPROCESSING_H diff --git a/databaseview.cpp b/databaseview.cpp index 8082074..ebe5c4b 100644 --- a/databaseview.cpp +++ b/databaseview.cpp @@ -10,6 +10,7 @@ #include #include #include +#include "batchprocessing.h" const QStringList DEFAULT_COLUMNS = {"EXPTIME", "OBJECT", "RA", "DEC"}; @@ -214,6 +215,8 @@ void DatabaseTableView::contextMenuEvent(QContextMenuEvent *event) QMenu menu; QAction *mark = menu.addAction(tr("Mark")); QAction *unmark = menu.addAction(tr("Unmark")); + QAction *open = menu.addAction(tr("Open")); + QAction *openDirAction = menu.addAction(tr("Open file location")); QAction *a = menu.exec(event->globalPos()); if(a == nullptr) @@ -225,7 +228,10 @@ void DatabaseTableView::contextMenuEvent(QContextMenuEvent *event) emit filesMarked(indexes); else if(a == unmark) emit filesUnmarked(indexes); - + else if(a == open) + emit openFile(indexes); + else if(a == openDirAction) + emit openDir(indexes); } DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent) @@ -270,6 +276,17 @@ DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent m_database->unmark(files); m_model->filesUnmarked(indexes); }); + connect(m_tableView, &DatabaseTableView::openFile, [this](QModelIndexList indexes){ + if(indexes.size()) + emit loadFile(m_model->data(indexes.front().siblingAtColumn(0)).toString()); + }); + connect(m_tableView, &DatabaseTableView::openDir, [this](QModelIndexList indexes){ + if(indexes.size()) + { + QFileInfo info(m_model->data(indexes.front().siblingAtColumn(0)).toString()); + openDir(info.absolutePath()); + } + }); auto addFilterItems = [](QComboBox *combobox, const QStringList &fitsKeywords) { diff --git a/databaseview.h b/databaseview.h index a62e3cf..d0edbcc 100644 --- a/databaseview.h +++ b/databaseview.h @@ -52,6 +52,8 @@ protected: signals: void filesMarked(QModelIndexList indexes); void filesUnmarked(QModelIndexList indexes); + void openFile(QModelIndexList indexes); + void openDir(QModelIndexList indexes); }; class DataBaseView : public QWidget