commit 48607848
Can now open a file or folder
Changed files
| M | src/main.cpp before |
| M | src/mainwindow.cpp before |
| M | src/mainwindow.h before |
diff --git a/src/main.cpp b/src/main.cpp
index 71f4eb5..66a3644 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,4 +1,5 @@
#include <QApplication>
+#include <QTimer>
#include "mainwindow.h"
int main(int argc, char *argv[])
@@ -8,5 +9,11 @@ int main(int argc, char *argv[])
MainWindow w;
w.showMaximized();
+ const QStringList args = app.arguments();
+ if (args.size() > 1) {
+ const QString path = args.at(1);
+ QTimer::singleShot(0, &w, [&w, path]() { w.openPath(path); });
+ }
+
return app.exec();
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 3191178..12ff796 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -171,6 +171,34 @@ void MainWindow::navigateToFolder(const QString &path)
});
}
+void MainWindow::openPath(const QString &path)
+{
+ QFileInfo info(path);
+ if (!info.exists())
+ return;
+
+ if (info.isDir()) {
+ navigateToFolder(info.absoluteFilePath());
+ } else if (info.isFile()) {
+ navigateToFolder(info.absolutePath());
+
+ // ImageModel::setDirectory is synchronous, so items are ready now.
+ // Find the file in the model and open it.
+ for (int i = 0; i < m_imageModel->rowCount(); ++i) {
+ QModelIndex idx = m_imageModel->index(i);
+ if (m_imageModel->filePath(idx) == info.absoluteFilePath()) {
+ m_listView->setCurrentIndex(idx);
+ m_listView->scrollTo(idx);
+ showPreview(idx);
+ // ImageModel only lists image files and folders; non-folder = image.
+ if (!m_imageModel->isFolder(idx))
+ enterSingleImageMode(idx);
+ break;
+ }
+ }
+ }
+}
+
void MainWindow::selectPreviousFolderIfExists()
{
if (m_previousFolderPath.isEmpty())
diff --git a/src/mainwindow.h b/src/mainwindow.h
index ba593b4..fef271a 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -21,6 +21,7 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = nullptr);
+ void openPath(const QString &path);
private:
void setupUi();