Handle tilde with custom paths

This commit is contained in:
varjolintu 2021-06-22 20:24:30 +03:00 committed by Jonathan White
parent 986fa42ca8
commit 250cd1933c
4 changed files with 40 additions and 12 deletions

View file

@ -20,6 +20,7 @@
#include "BrowserSettings.h" #include "BrowserSettings.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/PasswordHealth.h" #include "core/PasswordHealth.h"
#include <QDir>
#include <QJsonObject> #include <QJsonObject>
@ -516,3 +517,27 @@ void BrowserSettings::updateBinaryPaths()
{ {
m_nativeMessageInstaller.updateBinaryPaths(); m_nativeMessageInstaller.updateBinaryPaths();
} }
QString BrowserSettings::replaceHomePath(QString location)
{
#ifndef Q_OS_WIN
auto homePath = QDir::homePath();
if (location.startsWith(homePath)) {
location.replace(homePath, "~");
}
#endif
return location;
}
QString BrowserSettings::replaceTildeHomePath(QString location)
{
#ifndef Q_OS_WIN
auto homePath = QDir::homePath();
if (location.startsWith("~")) {
location.replace("~", homePath);
}
#endif
return location;
}

View file

@ -120,6 +120,8 @@ public:
PasswordGenerator::GeneratorFlags passwordGeneratorFlags(); PasswordGenerator::GeneratorFlags passwordGeneratorFlags();
QJsonObject generatePassword(); QJsonObject generatePassword();
void updateBinaryPaths(); void updateBinaryPaths();
QString replaceHomePath(QString location);
QString replaceTildeHomePath(QString location);
private: private:
static BrowserSettings* m_instance; static BrowserSettings* m_instance;

View file

@ -123,7 +123,7 @@ void BrowserSettingsWidget::loadSettings()
m_ui->supportKphFields->setChecked(settings->supportKphFields()); m_ui->supportKphFields->setChecked(settings->supportKphFields());
m_ui->noMigrationPrompt->setChecked(settings->noMigrationPrompt()); m_ui->noMigrationPrompt->setChecked(settings->noMigrationPrompt());
m_ui->useCustomProxy->setChecked(settings->useCustomProxy()); m_ui->useCustomProxy->setChecked(settings->useCustomProxy());
m_ui->customProxyLocation->setText(settings->customProxyLocation()); m_ui->customProxyLocation->setText(settings->replaceHomePath(settings->customProxyLocation()));
m_ui->updateBinaryPath->setChecked(settings->updateBinaryPath()); m_ui->updateBinaryPath->setChecked(settings->updateBinaryPath());
m_ui->allowExpiredCredentials->setChecked(settings->allowExpiredCredentials()); m_ui->allowExpiredCredentials->setChecked(settings->allowExpiredCredentials());
m_ui->chromeSupport->setChecked(settings->browserSupport(BrowserShared::CHROME)); m_ui->chromeSupport->setChecked(settings->browserSupport(BrowserShared::CHROME));
@ -175,7 +175,7 @@ void BrowserSettingsWidget::loadSettings()
if (typeIndex >= 0) { if (typeIndex >= 0) {
m_ui->browserTypeComboBox->setCurrentIndex(typeIndex); m_ui->browserTypeComboBox->setCurrentIndex(typeIndex);
} }
m_ui->customBrowserLocation->setText(settings->customBrowserLocation()); m_ui->customBrowserLocation->setText(settings->replaceHomePath(settings->customBrowserLocation()));
#ifdef QT_DEBUG #ifdef QT_DEBUG
m_ui->customExtensionId->setText(settings->customExtensionId()); m_ui->customExtensionId->setText(settings->customExtensionId());
@ -186,7 +186,8 @@ void BrowserSettingsWidget::loadSettings()
void BrowserSettingsWidget::validateCustomProxyLocation() void BrowserSettingsWidget::validateCustomProxyLocation()
{ {
auto path = m_ui->customProxyLocation->text(); auto path = browserSettings()->customProxyLocation();
if (m_ui->useCustomProxy->isChecked() && !QFile::exists(path)) { if (m_ui->useCustomProxy->isChecked() && !QFile::exists(path)) {
m_ui->warningWidget->showMessage(tr("<b>Error:</b> The custom proxy location cannot be found!" m_ui->warningWidget->showMessage(tr("<b>Error:</b> The custom proxy location cannot be found!"
"<br/>Browser integration WILL NOT WORK without the proxy application."), "<br/>Browser integration WILL NOT WORK without the proxy application."),
@ -207,7 +208,7 @@ void BrowserSettingsWidget::saveSettings()
settings->setMatchUrlScheme(m_ui->matchUrlScheme->isChecked()); settings->setMatchUrlScheme(m_ui->matchUrlScheme->isChecked());
settings->setUseCustomProxy(m_ui->useCustomProxy->isChecked()); settings->setUseCustomProxy(m_ui->useCustomProxy->isChecked());
settings->setCustomProxyLocation(m_ui->customProxyLocation->text()); settings->setCustomProxyLocation(browserSettings()->replaceTildeHomePath(m_ui->customProxyLocation->text()));
settings->setUpdateBinaryPath(m_ui->updateBinaryPath->isChecked()); settings->setUpdateBinaryPath(m_ui->updateBinaryPath->isChecked());
settings->setAllowExpiredCredentials(m_ui->allowExpiredCredentials->isChecked()); settings->setAllowExpiredCredentials(m_ui->allowExpiredCredentials->isChecked());
@ -232,16 +233,12 @@ void BrowserSettingsWidget::saveSettings()
settings->setBrowserSupport(BrowserShared::TOR_BROWSER, m_ui->torBrowserSupport->isChecked()); settings->setBrowserSupport(BrowserShared::TOR_BROWSER, m_ui->torBrowserSupport->isChecked());
// Custom browser settings // Custom browser settings
bool customBrowserEnabled = m_ui->customBrowserSupport->isChecked(); auto customBrowserEnabled = m_ui->customBrowserSupport->isChecked();
settings->setCustomBrowserType(m_ui->browserTypeComboBox->currentData().toInt()); settings->setCustomBrowserType(m_ui->browserTypeComboBox->currentData().toInt());
settings->setCustomBrowserLocation(m_ui->customBrowserLocation->text()); settings->setCustomBrowserLocation(
customBrowserEnabled ? browserSettings()->replaceTildeHomePath(m_ui->customBrowserLocation->text()) : "");
settings->setCustomBrowserSupport(customBrowserEnabled); settings->setCustomBrowserSupport(customBrowserEnabled);
settings->setBrowserSupport(BrowserShared::CUSTOM, customBrowserEnabled); settings->setBrowserSupport(BrowserShared::CUSTOM, customBrowserEnabled);
// If we disabled the custom browser support make sure to clear variables
if (!customBrowserEnabled) {
settings->setCustomBrowserLocation("");
}
#endif #endif
} }
@ -256,6 +253,8 @@ void BrowserSettingsWidget::showProxyLocationFileDialog()
tr("Select custom proxy location"), tr("Select custom proxy location"),
QFileInfo(QCoreApplication::applicationDirPath()).filePath(), QFileInfo(QCoreApplication::applicationDirPath()).filePath(),
fileTypeFilter); fileTypeFilter);
proxyLocation = browserSettings()->replaceHomePath(proxyLocation);
m_ui->customProxyLocation->setText(proxyLocation); m_ui->customProxyLocation->setText(proxyLocation);
validateCustomProxyLocation(); validateCustomProxyLocation();
} }
@ -265,6 +264,8 @@ void BrowserSettingsWidget::showCustomBrowserLocationFileDialog()
auto location = QFileDialog::getExistingDirectory(this, auto location = QFileDialog::getExistingDirectory(this,
tr("Select native messaging host folder location"), tr("Select native messaging host folder location"),
QFileInfo(QCoreApplication::applicationDirPath()).filePath()); QFileInfo(QCoreApplication::applicationDirPath()).filePath());
location = browserSettings()->replaceHomePath(location);
if (!location.isEmpty()) { if (!location.isEmpty()) {
m_ui->customBrowserLocation->setText(location); m_ui->customBrowserLocation->setText(location);
} }

View file

@ -515,7 +515,7 @@
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property> </property>
<property name="placeholderText"> <property name="placeholderText">
<string>~/.custom/config/Mozilla/native-messaging-hosts/</string> <string>~/.config/Mozilla/native-messaging-hosts/</string>
</property> </property>
</widget> </widget>
</item> </item>