Skip to content

Commit

Permalink
Qt: Use relative paths in portable mode when applicable (fixes #838)
Browse files Browse the repository at this point in the history
  • Loading branch information
endrift committed Dec 30, 2020
1 parent 239351b commit bca8cb9
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 208 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -119,6 +119,7 @@ Misc:
- Qt: Discard additional frame draws if waiting fails
- Qt: Unify monospace font usage
- Qt: Add button to jump to log settings
- Qt: Use relative paths in portable mode when applicable (fixes mgba.io/i/838)
- SDL: Fall back to sw blit if OpenGL init fails
- Util: Reset vector size on deinit
- VFS: Change semantics of VFile.sync on mapped files (fixes mgba.io/i/1730)
Expand Down
51 changes: 25 additions & 26 deletions src/platform/qt/SettingsView.cpp
Expand Up @@ -85,11 +85,7 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
}
});
connect(m_ui.savegameBrowse, &QAbstractButton::pressed, [this] () {
QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
if (!path.isNull()) {
m_ui.savegameSameDir->setChecked(false);
m_ui.savegamePath->setText(path);
}
selectPath(m_ui.savegamePath, m_ui.savegameSameDir);
});

if (m_ui.savestatePath->text().isEmpty()) {
Expand All @@ -101,11 +97,7 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
}
});
connect(m_ui.savestateBrowse, &QAbstractButton::pressed, [this] () {
QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
if (!path.isNull()) {
m_ui.savestateSameDir->setChecked(false);
m_ui.savestatePath->setText(path);
}
selectPath(m_ui.savestatePath, m_ui.savestateSameDir);
});

if (m_ui.screenshotPath->text().isEmpty()) {
Expand All @@ -117,11 +109,7 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
}
});
connect(m_ui.screenshotBrowse, &QAbstractButton::pressed, [this] () {
QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
if (!path.isNull()) {
m_ui.screenshotSameDir->setChecked(false);
m_ui.screenshotPath->setText(path);
}
selectPath(m_ui.screenshotPath, m_ui.screenshotSameDir);
});

if (m_ui.patchPath->text().isEmpty()) {
Expand All @@ -133,11 +121,7 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
}
});
connect(m_ui.patchBrowse, &QAbstractButton::pressed, [this] () {
QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
if (!path.isNull()) {
m_ui.patchSameDir->setChecked(false);
m_ui.patchPath->setText(path);
}
selectPath(m_ui.patchPath, m_ui.patchSameDir);
});

if (m_ui.cheatsPath->text().isEmpty()) {
Expand All @@ -149,11 +133,7 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
}
});
connect(m_ui.cheatsBrowse, &QAbstractButton::pressed, [this] () {
QString path = GBAApp::app()->getOpenDirectoryName(this, "Select directory");
if (!path.isNull()) {
m_ui.cheatsSameDir->setChecked(false);
m_ui.cheatsPath->setText(path);
}
selectPath(m_ui.cheatsPath, m_ui.cheatsSameDir);
});
connect(m_ui.clearCache, &QAbstractButton::pressed, this, &SettingsView::libraryCleared);

Expand Down Expand Up @@ -372,10 +352,29 @@ void SettingsView::selectPage(SettingsView::Page page) {
m_ui.tabs->setCurrentRow(m_pageIndex[page]);
}

QString SettingsView::makePortablePath(const QString& path) {
if (m_controller->isPortable()) {
QDir configDir(m_controller->configDir());
QFileInfo pathInfo(path);
if (pathInfo.canonicalPath() == configDir.canonicalPath()) {
return configDir.relativeFilePath(pathInfo.canonicalFilePath());
}
}
return path;
}

void SettingsView::selectBios(QLineEdit* bios) {
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select BIOS"));
if (!filename.isEmpty()) {
bios->setText(filename);
bios->setText(makePortablePath(filename));
}
}

void SettingsView::selectPath(QLineEdit* field, QCheckBox* sameDir) {
QString path = GBAApp::app()->getOpenDirectoryName(this, tr("Select directory"));
if (!path.isNull()) {
sameDir->setChecked(false);
field->setText(makePortablePath(path));
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/platform/qt/SettingsView.h
Expand Up @@ -66,6 +66,7 @@ public slots:

private slots:
void selectBios(QLineEdit*);
void selectPath(QLineEdit*, QCheckBox*);
void updateConfig();
void reloadConfig();

Expand All @@ -84,6 +85,8 @@ private slots:

QMap<Page, int> m_pageIndex;

QString makePortablePath(const QString& path);

void addPage(const QString& name, QWidget* view, Page index);

void saveSetting(const char* key, const QAbstractButton*);
Expand Down
33 changes: 19 additions & 14 deletions src/platform/qt/ts/mgba-de.ts
Expand Up @@ -3724,64 +3724,69 @@ Game Boy Advance ist ein eingetragenes Warenzeichen von Nintendo Co., Ltd.</tran
<context>
<name>QGBA::SettingsView</name>
<message>
<location filename="../SettingsView.cpp" line="163"/>
<location filename="../SettingsView.cpp" line="206"/>
<location filename="../SettingsView.cpp" line="143"/>
<location filename="../SettingsView.cpp" line="186"/>
<source>Qt Multimedia</source>
<translation>Qt Multimedia</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="170"/>
<location filename="../SettingsView.cpp" line="150"/>
<source>SDL</source>
<translation>SDL</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="178"/>
<location filename="../SettingsView.cpp" line="158"/>
<source>Software (Qt)</source>
<translation>Software (Qt)</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="184"/>
<location filename="../SettingsView.cpp" line="164"/>
<source>OpenGL</source>
<translation>OpenGL</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="191"/>
<location filename="../SettingsView.cpp" line="171"/>
<source>OpenGL (force version 1.x)</source>
<translation>OpenGL (erzwinge Version 1.x)</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="199"/>
<location filename="../SettingsView.cpp" line="179"/>
<source>None (Still Image)</source>
<translation>Keiner (Standbild)</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="289"/>
<location filename="../SettingsView.cpp" line="269"/>
<source>Keyboard</source>
<translation>Tastatur</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="297"/>
<location filename="../SettingsView.cpp" line="277"/>
<source>Controllers</source>
<translation>Gamepads</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="343"/>
<location filename="../SettingsView.cpp" line="323"/>
<source>Shortcuts</source>
<translation>Tastenkürzel</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="355"/>
<location filename="../SettingsView.cpp" line="365"/>
<location filename="../SettingsView.cpp" line="335"/>
<location filename="../SettingsView.cpp" line="345"/>
<source>Shaders</source>
<translation>Shader</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="376"/>
<location filename="../SettingsView.cpp" line="367"/>
<source>Select BIOS</source>
<translation>BIOS auswählen</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="715"/>
<location filename="../SettingsView.cpp" line="374"/>
<source>Select directory</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="714"/>
<source>(%1×%2)</source>
<translation>(%1×%2)</translation>
</message>
Expand Down
33 changes: 19 additions & 14 deletions src/platform/qt/ts/mgba-en.ts
Expand Up @@ -3723,64 +3723,69 @@ Game Boy Advance is a registered trademark of Nintendo Co., Ltd.</source>
<context>
<name>QGBA::SettingsView</name>
<message>
<location filename="../SettingsView.cpp" line="163"/>
<location filename="../SettingsView.cpp" line="206"/>
<location filename="../SettingsView.cpp" line="143"/>
<location filename="../SettingsView.cpp" line="186"/>
<source>Qt Multimedia</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="170"/>
<location filename="../SettingsView.cpp" line="150"/>
<source>SDL</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="178"/>
<location filename="../SettingsView.cpp" line="158"/>
<source>Software (Qt)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="184"/>
<location filename="../SettingsView.cpp" line="164"/>
<source>OpenGL</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="191"/>
<location filename="../SettingsView.cpp" line="171"/>
<source>OpenGL (force version 1.x)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="199"/>
<location filename="../SettingsView.cpp" line="179"/>
<source>None (Still Image)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="289"/>
<location filename="../SettingsView.cpp" line="269"/>
<source>Keyboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="297"/>
<location filename="../SettingsView.cpp" line="277"/>
<source>Controllers</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="343"/>
<location filename="../SettingsView.cpp" line="323"/>
<source>Shortcuts</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="355"/>
<location filename="../SettingsView.cpp" line="365"/>
<location filename="../SettingsView.cpp" line="335"/>
<location filename="../SettingsView.cpp" line="345"/>
<source>Shaders</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="376"/>
<location filename="../SettingsView.cpp" line="367"/>
<source>Select BIOS</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="715"/>
<location filename="../SettingsView.cpp" line="374"/>
<source>Select directory</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="714"/>
<source>(%1×%2)</source>
<translation type="unfinished"></translation>
</message>
Expand Down
33 changes: 19 additions & 14 deletions src/platform/qt/ts/mgba-es.ts
Expand Up @@ -3724,64 +3724,69 @@ Game Boy Advance es una marca registrada de Nintendo Co., Ltd.</translation>
<context>
<name>QGBA::SettingsView</name>
<message>
<location filename="../SettingsView.cpp" line="163"/>
<location filename="../SettingsView.cpp" line="206"/>
<location filename="../SettingsView.cpp" line="143"/>
<location filename="../SettingsView.cpp" line="186"/>
<source>Qt Multimedia</source>
<translation>Qt Multimedia</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="170"/>
<location filename="../SettingsView.cpp" line="150"/>
<source>SDL</source>
<translation>SDL</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="178"/>
<location filename="../SettingsView.cpp" line="158"/>
<source>Software (Qt)</source>
<translation>Software (Qt)</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="184"/>
<location filename="../SettingsView.cpp" line="164"/>
<source>OpenGL</source>
<translation>OpenGL</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="191"/>
<location filename="../SettingsView.cpp" line="171"/>
<source>OpenGL (force version 1.x)</source>
<translation>OpenGL (forzar versión 1.x)</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="199"/>
<location filename="../SettingsView.cpp" line="179"/>
<source>None (Still Image)</source>
<translation>Nada (imagen estática)</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="289"/>
<location filename="../SettingsView.cpp" line="269"/>
<source>Keyboard</source>
<translation>Teclado</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="297"/>
<location filename="../SettingsView.cpp" line="277"/>
<source>Controllers</source>
<translation>Controladores</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="343"/>
<location filename="../SettingsView.cpp" line="323"/>
<source>Shortcuts</source>
<translation>Atajos de teclado</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="355"/>
<location filename="../SettingsView.cpp" line="365"/>
<location filename="../SettingsView.cpp" line="335"/>
<location filename="../SettingsView.cpp" line="345"/>
<source>Shaders</source>
<translation>Shaders</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="376"/>
<location filename="../SettingsView.cpp" line="367"/>
<source>Select BIOS</source>
<translation>Seleccionar BIOS</translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="715"/>
<location filename="../SettingsView.cpp" line="374"/>
<source>Select directory</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../SettingsView.cpp" line="714"/>
<source>(%1×%2)</source>
<translation></translation>
</message>
Expand Down

0 comments on commit bca8cb9

Please sign in to comment.