Qt: Show native directory separators in the GUI.

The core still gets '/'s always (it chokes on '\'s), but the Qt
interface always uses the native separators.

In the process of doing this, also removed the custom FileDialog
subclass and made everything use GBAApp::get*FileDialog instead.

Also fixes #552, because I had to change that code anyway.
This commit is contained in:
waddlesplash 2017-03-30 11:11:29 -04:00 committed by endrift
parent 5d13a00cf7
commit 10fe4a743c
6 changed files with 12 additions and 64 deletions

View File

@ -163,7 +163,7 @@ QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QStr
QString filename = QFileDialog::getOpenFileName(owner, title, m_configController.getOption("lastDirectory"), filter); QString filename = QFileDialog::getOpenFileName(owner, title, m_configController.getOption("lastDirectory"), filter);
continueAll(paused); continueAll(paused);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
m_configController.setOption("lastDirectory", QFileInfo(filename).dir().path()); m_configController.setOption("lastDirectory", QFileInfo(filename).dir().canonicalPath());
} }
return filename; return filename;
} }
@ -174,7 +174,7 @@ QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QStr
QString filename = QFileDialog::getSaveFileName(owner, title, m_configController.getOption("lastDirectory"), filter); QString filename = QFileDialog::getSaveFileName(owner, title, m_configController.getOption("lastDirectory"), filter);
continueAll(paused); continueAll(paused);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
m_configController.setOption("lastDirectory", QFileInfo(filename).dir().path()); m_configController.setOption("lastDirectory", QFileInfo(filename).dir().canonicalPath());
} }
return filename; return filename;
} }
@ -185,23 +185,11 @@ QString GBAApp::getOpenDirectoryName(QWidget* owner, const QString& title) {
QString filename = QFileDialog::getExistingDirectory(owner, title, m_configController.getOption("lastDirectory")); QString filename = QFileDialog::getExistingDirectory(owner, title, m_configController.getOption("lastDirectory"));
continueAll(paused); continueAll(paused);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
m_configController.setOption("lastDirectory", QFileInfo(filename).dir().path()); m_configController.setOption("lastDirectory", QFileInfo(filename).dir().canonicalPath());
} }
return filename; return filename;
} }
QFileDialog* GBAApp::getOpenFileDialog(QWidget* owner, const QString& title, const QString& filter) {
FileDialog* dialog = new FileDialog(this, owner, title, filter);
dialog->setAcceptMode(QFileDialog::AcceptOpen);
return dialog;
}
QFileDialog* GBAApp::getSaveFileDialog(QWidget* owner, const QString& title, const QString& filter) {
FileDialog* dialog = new FileDialog(this, owner, title, filter);
dialog->setAcceptMode(QFileDialog::AcceptSave);
return dialog;
}
QString GBAApp::dataDir() { QString GBAApp::dataDir() {
#ifdef DATADIR #ifdef DATADIR
QString path = QString::fromUtf8(DATADIR); QString path = QString::fromUtf8(DATADIR);
@ -241,24 +229,6 @@ bool GBAApp::reloadGameDB() {
} }
#endif #endif
GBAApp::FileDialog::FileDialog(GBAApp* app, QWidget* parent, const QString& caption, const QString& filter)
: QFileDialog(parent, caption, app->m_configController.getOption("lastDirectory"), filter)
, m_app(app)
{
}
int GBAApp::FileDialog::exec() {
QList<Window*> paused;
m_app->pauseAll(&paused);
bool didAccept = QFileDialog::exec() == QDialog::Accepted;
QStringList filenames = selectedFiles();
if (!filenames.isEmpty()) {
m_app->m_configController.setOption("lastDirectory", QFileInfo(filenames[0]).dir().path());
}
m_app->continueAll(paused);
return didAccept;
}
#ifdef USE_SQLITE3 #ifdef USE_SQLITE3
GameDBParser::GameDBParser(NoIntroDB* db, QObject* parent) GameDBParser::GameDBParser(NoIntroDB* db, QObject* parent)
: QObject(parent) : QObject(parent)

View File

@ -55,9 +55,6 @@ public:
QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = QString()); QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = QString());
QString getOpenDirectoryName(QWidget* owner, const QString& title); QString getOpenDirectoryName(QWidget* owner, const QString& title);
QFileDialog* getOpenFileDialog(QWidget* owner, const QString& title, const QString& filter = QString());
QFileDialog* getSaveFileDialog(QWidget* owner, const QString& title, const QString& filter = QString());
const NoIntroDB* gameDB() const { return m_db; } const NoIntroDB* gameDB() const { return m_db; }
bool reloadGameDB(); bool reloadGameDB();
@ -65,16 +62,6 @@ protected:
bool event(QEvent*); bool event(QEvent*);
private: private:
class FileDialog : public QFileDialog {
public:
FileDialog(GBAApp* app, QWidget* parent = nullptr, const QString& caption = QString(),
const QString& filter = QString());
virtual int exec() override;
private:
GBAApp* m_app;
};
Window* newWindowInternal(); Window* newWindowInternal();
void pauseAll(QList<Window*>* paused); void pauseAll(QList<Window*>* paused);

View File

@ -409,10 +409,10 @@ void GameController::loadGame(VFile* vf, const QString& path, const QString& bas
closeGame(); closeGame();
QFileInfo info(base); QFileInfo info(base);
if (info.isDir()) { if (info.isDir()) {
m_fname = base + QDir::separator() + path; m_fname = QFileInfo(base + '/' + path).canonicalFilePath();
m_fsub = QString(); m_fsub = QString();
} else { } else {
m_fname = base; m_fname = info.canonicalFilePath();
m_fsub = path; m_fsub = path;
} }
m_vf = vf; m_vf = vf;

View File

@ -244,12 +244,8 @@ void ObjView::updateTilesGB(bool force) {
void ObjView::exportObj() { void ObjView::exportObj() {
GameController::Interrupter interrupter(m_controller); GameController::Interrupter interrupter(m_controller);
QFileDialog* dialog = GBAApp::app()->getSaveFileDialog(this, tr("Export sprite"), QString filename = GBAApp::app()->getSaveFileName(this, tr("Export sprite"),
tr("Portable Network Graphics (*.png)")); tr("Portable Network Graphics (*.png)"));
if (!dialog->exec()) {
return;
}
QString filename = dialog->selectedFiles()[0];
VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC); VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) { if (!vf) {
LOG(QT, ERROR) << tr("Failed to open output PNG file: %1").arg(filename); LOG(QT, ERROR) << tr("Failed to open output PNG file: %1").arg(filename);

View File

@ -134,21 +134,16 @@ void PaletteView::exportPalette(int start, int length) {
} }
GameController::Interrupter interrupter(m_controller); GameController::Interrupter interrupter(m_controller);
QFileDialog* dialog = GBAApp::app()->getSaveFileDialog(this, tr("Export palette"), QString filename = GBAApp::app()->getSaveFileName(this, tr("Export palette"),
tr("Windows PAL (*.pal);;Adobe Color Table (*.act)")); tr("Windows PAL (*.pal);;Adobe Color Table (*.act)"));
if (!dialog->exec()) {
return;
}
QString filename = dialog->selectedFiles()[0];
VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC); VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) { if (!vf) {
LOG(QT, ERROR) << tr("Failed to open output palette file: %1").arg(filename); LOG(QT, ERROR) << tr("Failed to open output palette file: %1").arg(filename);
return; return;
} }
QString filter = dialog->selectedNameFilter(); if (filename.endsWith(".pal", Qt::CaseInsensitive)) {
if (filter.contains("*.pal")) {
exportPaletteRIFF(vf, length, &static_cast<GBA*>(m_controller->thread()->core->board)->video.palette[start]); exportPaletteRIFF(vf, length, &static_cast<GBA*>(m_controller->thread()->core->board)->video.palette[start]);
} else if (filter.contains("*.act")) { } else if (filename.endsWith(".act", Qt::CaseInsensitive)) {
exportPaletteACT(vf, length, &static_cast<GBA*>(m_controller->thread()->core->board)->video.palette[start]); exportPaletteACT(vf, length, &static_cast<GBA*>(m_controller->thread()->core->board)->video.palette[start]);
} }
vf->close(vf); vf->close(vf);

View File

@ -1580,7 +1580,7 @@ void Window::updateMRU() {
m_mruMenu->clear(); m_mruMenu->clear();
int i = 0; int i = 0;
for (const QString& file : m_mruFiles) { for (const QString& file : m_mruFiles) {
QAction* item = new QAction(file, m_mruMenu); QAction* item = new QAction(QDir::toNativeSeparators(file).replace("&", "&&"), m_mruMenu);
item->setShortcut(QString("Ctrl+%1").arg(i)); item->setShortcut(QString("Ctrl+%1").arg(i));
connect(item, &QAction::triggered, [this, file]() { m_controller->loadGame(file); }); connect(item, &QAction::triggered, [this, file]() { m_controller->loadGame(file); });
m_mruMenu->addAction(item); m_mruMenu->addAction(item);