1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 19:52:09 +01:00

Added "Open directory" action for desktop systems

closes #522
This commit is contained in:
Martin Tůma 2023-10-13 02:21:34 +02:00
parent 7988801822
commit 1033ca2840
2 changed files with 31 additions and 10 deletions

View File

@ -214,12 +214,11 @@ void GUI::createActions()
connect(_openFileAction, &QAction::triggered, this, connect(_openFileAction, &QAction::triggered, this,
QOverload<>::of(&GUI::openFile)); QOverload<>::of(&GUI::openFile));
addAction(_openFileAction); addAction(_openFileAction);
#ifdef Q_OS_ANDROID
_openDirAction = new QAction(QIcon(OPEN_FILE_ICON), tr("Open directory..."), _openDirAction = new QAction(QIcon(OPEN_FILE_ICON), tr("Open directory..."),
this); this);
_openDirAction->setMenuRole(QAction::NoRole); _openDirAction->setMenuRole(QAction::NoRole);
connect(_openDirAction, &QAction::triggered, this, &GUI::openDir); connect(_openDirAction, &QAction::triggered, this,
#endif // Q_OS_ANDROID QOverload<>::of(&GUI::openDir));
_printFileAction = new QAction(QIcon(PRINT_FILE_ICON), tr("Print..."), _printFileAction = new QAction(QIcon(PRINT_FILE_ICON), tr("Print..."),
this); this);
_printFileAction->setMenuRole(QAction::NoRole); _printFileAction->setMenuRole(QAction::NoRole);
@ -607,9 +606,7 @@ void GUI::createMenus()
{ {
QMenu *fileMenu = menuBar()->addMenu(tr("&File")); QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(_openFileAction); fileMenu->addAction(_openFileAction);
#ifdef Q_OS_ANDROID
fileMenu->addAction(_openDirAction); fileMenu->addAction(_openDirAction);
#endif // Q_OS_ANDROID
fileMenu->addSeparator(); fileMenu->addSeparator();
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
fileMenu->addAction(_printFileAction); fileMenu->addAction(_printFileAction);
@ -956,19 +953,42 @@ void GUI::openFile()
_dataDir = QFileInfo(files.last()).path(); _dataDir = QFileInfo(files.last()).path();
} }
#ifdef Q_OS_ANDROID #ifndef Q_OS_ANDROID
void GUI::openDir(const QString &path, int &showError)
{
QDir md(path);
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
md.setSorting(QDir::DirsLast);
QFileInfoList ml = md.entryInfoList();
for (int i = 0; i < ml.size(); i++) {
const QFileInfo &fi = ml.at(i);
if (fi.isDir())
openDir(fi.absoluteFilePath(), showError);
else
openFile(fi.absoluteFilePath(), true, showError);
}
}
#endif // Q_OS_ANDROID
void GUI::openDir() void GUI::openDir()
{ {
QString dir(QFileDialog::getExistingDirectory(this, tr("Open directory"), QString dir(QFileDialog::getExistingDirectory(this, tr("Open directory"),
_dataDir)); _dataDir));
int showError = 1;
if (!dir.isEmpty()) { if (!dir.isEmpty()) {
#ifdef Q_OS_ANDROID
int showError = 1;
_browser->setCurrentDir(dir); _browser->setCurrentDir(dir);
openFile(_browser->current(), true, showError); openFile(_browser->current(), true, showError);
#else // Q_OS_ANDROID
int showError = 2;
openDir(dir, showError);
_dataDir = dir;
#endif // Q_OS_ANDROID
} }
} }
#endif // Q_OS_ANDROID
bool GUI::openFile(const QString &fileName, bool tryUnknown, int &showError) bool GUI::openFile(const QString &fileName, bool tryUnknown, int &showError)
{ {

View File

@ -59,9 +59,7 @@ private slots:
void exportPDFFile(); void exportPDFFile();
void exportPNGFile(); void exportPNGFile();
void openFile(); void openFile();
#ifdef Q_OS_ANDROID
void openDir(); void openDir();
#endif // Q_OS_ANDROID
void closeAll(); void closeAll();
void reloadFiles(); void reloadFiles();
void statistics(); void statistics();
@ -149,6 +147,9 @@ private:
void createGraphTabs(); void createGraphTabs();
void createBrowser(); void createBrowser();
#ifndef Q_OS_ANDROID
void openDir(const QString &path, int &showError);
#endif // Q_OS_ANDROID
bool openPOIFile(const QString &fileName); bool openPOIFile(const QString &fileName);
bool loadFile(const QString &fileName, bool tryUnknown, int &showError); bool loadFile(const QString &fileName, bool tryUnknown, int &showError);
void loadData(const Data &data); void loadData(const Data &data);