From fcc97cd94d054253bf75312ea274e0611eac421f Mon Sep 17 00:00:00 2001 From: Oliver Toth Date: Tue, 4 Apr 2023 21:42:50 +0200 Subject: [PATCH 1/2] Prevent Linux Mint dark mode readability issues, fix #1158 --- src/AppGui.cpp | 40 +++++++++++++++++++++++++++++ src/AppGui.h | 3 +++ src/BleDev.cpp | 4 +-- src/CredentialsManagement.cpp | 7 +++++ src/CredentialsManagement.h | 2 +- src/DbExportsRegistryController.cpp | 3 ++- src/FidoManagement.cpp | 5 ++++ src/FilesManagement.cpp | 17 +++++++----- src/MainWindow.cpp | 6 ++--- src/MainWindow.h | 4 +-- src/SSHManagement.cpp | 6 ++--- src/WindowLog.cpp | 3 ++- 12 files changed, 81 insertions(+), 19 deletions(-) mode change 100644 => 100755 src/AppGui.cpp mode change 100644 => 100755 src/BleDev.cpp mode change 100644 => 100755 src/CredentialsManagement.cpp mode change 100644 => 100755 src/CredentialsManagement.h mode change 100644 => 100755 src/DbExportsRegistryController.cpp mode change 100644 => 100755 src/FidoManagement.cpp mode change 100644 => 100755 src/FilesManagement.cpp mode change 100644 => 100755 src/MainWindow.cpp mode change 100644 => 100755 src/MainWindow.h mode change 100644 => 100755 src/SSHManagement.cpp mode change 100644 => 100755 src/WindowLog.cpp diff --git a/src/AppGui.cpp b/src/AppGui.cpp old mode 100644 new mode 100755 index c5427bdc..798e4f9c --- a/src/AppGui.cpp +++ b/src/AppGui.cpp @@ -293,6 +293,15 @@ bool AppGui::initialize() "{ color: black }"); #endif +#ifdef Q_OS_LINUX + // Enforce white background and black text color to fix dark mode on Linux + this->setStyleSheet("QCheckBox:unchecked, QCheckBox:checked, QCheckBox, QRadioButton" + "{ color: black; background-color : white; }" + "QGroupBox { color: black; }" + "CredentialView, QTreeView { color: black; background-color: black; }" + ); +#endif + return true; } @@ -756,6 +765,37 @@ QString AppGui::getDataDirPath() return dataDir.absolutePath(); } +QString AppGui::getFileName(QWidget* parent, const QString &title, const QString &dir, const QString &filter /* = QString{} */, bool acceptSave /*= false*/) +{ + QFileDialog dialog(parent, title, dir, filter); +#ifdef Q_OS_UNIX + // Force white background and black text color to fix dark mode issue + dialog.setStyleSheet("QWidget { background-color: white; color: black }"); +#endif + if (acceptSave) + { + dialog.setAcceptMode(QFileDialog::AcceptSave); + } + if (dialog.exec() == QDialog::Accepted) + { + QUrl url = dialog.selectedUrls().value(0); + if (url.isLocalFile() || url.isEmpty()) + { + return url.toLocalFile(); + } + else + { + return url.toString(); + } + } + return QString{}; +} + +QString AppGui::getSaveFileName(QWidget *parent, const QString &title, const QString &dir, const QString &filter) +{ + return getFileName(parent, title, dir, filter, true); +} + void AppGui::setupLanguage() { QString locale; diff --git a/src/AppGui.h b/src/AppGui.h index c96574b3..351f09f2 100644 --- a/src/AppGui.h +++ b/src/AppGui.h @@ -54,6 +54,9 @@ class AppGui : public QApplication static QString getDataDirPath(); + static QString getFileName(QWidget* parent, const QString &title, const QString &dir, const QString &filter = QString{}, bool acceptSave = false); + static QString getSaveFileName(QWidget* parent, const QString &title, const QString &dir, const QString &filter = QString{}); + private slots: void restartDaemon(); void connectedChanged(); diff --git a/src/BleDev.cpp b/src/BleDev.cpp old mode 100644 new mode 100755 index 3ef302cd..8aad31a3 --- a/src/BleDev.cpp +++ b/src/BleDev.cpp @@ -190,7 +190,7 @@ void BleDev::on_btnFileBrowser_clicked() bool skipDeviceChecks = wsClient->get_status() == Common::NoBundle && DeviceDetector::instance().isCtrlPressed(); - QString fileName = QFileDialog::getOpenFileName(this, tr("Select bundle file"), + QString fileName = AppGui::getFileName(this, tr("Select bundle file"), s.value("last_used_path/bundle_dir", QDir::homePath()).toString(), "*.img"); @@ -274,7 +274,7 @@ void BleDev::on_btnFetchDataBrowse_clicked() { QSettings s; - QString fileName = QFileDialog::getSaveFileName(this, tr("Select file to fetch data"), + QString fileName = AppGui::getSaveFileName(this, tr("Select file to fetch data"), s.value("last_used_path/fetchdata_dir", QDir::homePath()).toString(), "*.bin"); diff --git a/src/CredentialsManagement.cpp b/src/CredentialsManagement.cpp old mode 100644 new mode 100755 index ab7ad776..199ccffc --- a/src/CredentialsManagement.cpp +++ b/src/CredentialsManagement.cpp @@ -209,6 +209,13 @@ CredentialsManagement::CredentialsManagement(QWidget *parent) : connect(this, &CredentialsManagement::editedCredentialLinked, ui->credDisplayPasswordInput, &LockedPasswordLineEdit::onCredentialLinked); ui->credentialTreeView->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->credentialTreeView, &CredentialView::customContextMenuRequested, this, &CredentialsManagement::onTreeViewContextMenuRequested); + +#ifdef Q_OS_LINUX + // Force white background and black text color for CredentialsManagement to make UI visible in dark mode + ui->credentialsListWdiget->setStyleSheet("QWidget { background-color : white; color : black; }"); + ui->pageUnlocked->setStyleSheet("QLineEdit { background-color : white; color : black; }"); + ui->quickInsertWidget->setStyleSheet("QLineEdit { background-color : white; color : black; }"); +#endif } void CredentialsManagement::setFilterCredLayout() diff --git a/src/CredentialsManagement.h b/src/CredentialsManagement.h old mode 100644 new mode 100755 index f9246b18..0e288327 --- a/src/CredentialsManagement.h +++ b/src/CredentialsManagement.h @@ -146,7 +146,7 @@ private slots: void initKeyAfterInput(QComboBox * cbKeyAfter); void changeCurrentFavorite(int iFavorite); - virtual void changeEvent(QEvent *event); + virtual void changeEvent(QEvent *event) override; int getCategory(const QModelIndex &srcIndex); void checkLinkingOnLoginSelected(const QModelIndex &srcIndex); diff --git a/src/DbExportsRegistryController.cpp b/src/DbExportsRegistryController.cpp old mode 100644 new mode 100755 index 33ec1d1d..3e7c43b2 --- a/src/DbExportsRegistryController.cpp +++ b/src/DbExportsRegistryController.cpp @@ -1,5 +1,6 @@ #include "DbExportsRegistryController.h" #include "PromptWidget.h" +#include "AppGui.h" #include #include @@ -134,7 +135,7 @@ void DbExportsRegistryController::handleExportDbResult(const QByteArray &d, bool return; } - QString fname = QFileDialog::getSaveFileName(window, tr("Save database export..."), + QString fname = AppGui::getSaveFileName(window, tr("Save database export..."), s.value("last_used_path/export_dir", QDir::homePath()).toString(), "Memory exports (*.bin);;All files (*.*)"); if (fname.isEmpty()) diff --git a/src/FidoManagement.cpp b/src/FidoManagement.cpp old mode 100644 new mode 100755 index 386dbc84..9dae60f8 --- a/src/FidoManagement.cpp +++ b/src/FidoManagement.cpp @@ -38,6 +38,11 @@ FidoManagement::FidoManagement(QWidget *parent) : connect(ui->pushButtonDiscard, &AnimatedColorButton::actionValidated, this, &FidoManagement::on_pushButtonDiscard_clicked); connect(ui->fidoTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FidoManagement::onCredentialSelected); + +#ifdef Q_OS_LINUX + // Force white background and black text color for FidoManagement to make UI visible in dark mode + ui->fidoTreeView->setStyleSheet("QWidget { background-color : white; color : black; }"); +#endif } void FidoManagement::setWsClient(WSClient *c) diff --git a/src/FilesManagement.cpp b/src/FilesManagement.cpp old mode 100644 new mode 100755 index 66755097..c1aa3b21 --- a/src/FilesManagement.cpp +++ b/src/FilesManagement.cpp @@ -132,6 +132,12 @@ FilesManagement::FilesManagement(QWidget *parent) : ui->filesCacheListWidget->setVisible(false); ui->emptyCacheLabel->setVisible(false); + +#ifdef Q_OS_LINUX + ui->filesCacheListWidget->setStyleSheet("QListView, QToolButton { background-color : white; color : black; }"); + ui->lineEditFilename->setStyleSheet("QLineEdit { background-color : white; color : black; }"); + ui->addFileServiceInput->setStyleSheet("QLineEdit { background-color : white; color : black; }"); +#endif } FilesManagement::~FilesManagement() @@ -418,8 +424,8 @@ void FilesManagement::on_pushButtonUpdateFile_clicked() QSettings s; - fileName = QFileDialog::getOpenFileName(this, tr("Load file to device..."), - s.value("last_used_path/load_file_dir", QDir::homePath()).toString()); + + fileName = AppGui::getFileName(this, tr("Load file to device..."), s.value("last_used_path/load_file_dir", QDir::homePath()).toString()); if (fileName.isEmpty()) return; @@ -448,7 +454,7 @@ void FilesManagement::on_pushButtonSaveFile_clicked() QSettings s; - fileName = QFileDialog::getSaveFileName(this, tr("Save to file..."), + fileName = AppGui::getSaveFileName(this, tr("Save to file..."), s.value("last_used_path/save_file_dir", QDir::homePath()).toString()); if (fileName.isEmpty()) @@ -528,7 +534,7 @@ void FilesManagement::dataFileRequested(const QString &service, const QByteArray QSettings s; QDir d = s.value("last_used_path/save_file_dir", QDir::homePath()).toString(); - fileName = QFileDialog::getSaveFileName(this, tr("Save to file..."), d.filePath(service)); + fileName = AppGui::getSaveFileName(this, tr("Save to file..."), d.filePath(service)); if (fileName.isEmpty()) { @@ -661,8 +667,7 @@ void FilesManagement::on_pushButtonFilename_clicked() { QSettings s; - fileName = QFileDialog::getOpenFileName(this, tr("Load file to device..."), - s.value("last_used_path/load_file_dir", QDir::homePath()).toString()); + fileName = AppGui::getFileName(this, tr("Load file to device..."), s.value("last_used_path/load_file_dir", QDir::homePath()).toString()); if (fileName.isEmpty()) return; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp old mode 100644 new mode 100755 index e756f0ed..79ab22a6 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1480,7 +1480,7 @@ void MainWindow::on_pushButtonImportFile_clicked() { QSettings s; - QString fname = QFileDialog::getOpenFileName(this, tr("Select database export..."), + QString fname = AppGui::getFileName(this, tr("Select database export..."), s.value("last_used_path/import_dir", QDir::homePath()).toString(), "Memory exports (*.bin);;All files (*.*)"); if (fname.isEmpty()) @@ -1513,7 +1513,7 @@ void MainWindow::dbExported(const QByteArray &d, bool success) QMessageBox::warning(this, tr("Error"), tr(d)); else { - QString fname = QFileDialog::getSaveFileName(this, tr("Save database export..."), + QString fname = AppGui::getSaveFileName(this, tr("Save database export..."), s.value("last_used_path/export_dir", QDir::homePath()).toString(), "Memory exports (*.bin);;All files (*.*)"); if (!fname.isEmpty()) @@ -2043,7 +2043,7 @@ void MainWindow::on_pushButtonImportCSV_clicked() { QSettings s; - QString fname = QFileDialog::getOpenFileName(this, tr("Select CSV file to import..."), + QString fname = AppGui::getFileName(this, tr("Select CSV file to import..."), s.value("last_used_path/import_csv_dir", QDir::homePath()).toString(), "CSV files (*.csv);;All files (*.*)"); if (fname.isEmpty()) diff --git a/src/MainWindow.h b/src/MainWindow.h old mode 100644 new mode 100755 index 68e7fee0..7608df0a --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -224,8 +224,8 @@ private slots: void setUIDRequestInstructionsWithId(const QString &id = "XXXX"); void setSecurityChallengeText(const QString &id = "XXXX", const QString &bundleVersion = "XXXX"); - virtual void closeEvent(QCloseEvent *event); - virtual void changeEvent(QEvent *event); + virtual void closeEvent(QCloseEvent *event) override; + virtual void changeEvent(QEvent *event) override; void updateDeviceDependentUI(); diff --git a/src/SSHManagement.cpp b/src/SSHManagement.cpp old mode 100644 new mode 100755 index 5d1dac4f..b7e21cfd --- a/src/SSHManagement.cpp +++ b/src/SSHManagement.cpp @@ -285,7 +285,7 @@ void SSHManagement::onExportPublicKey() if (!it) return; QSettings s; - QString fname = QFileDialog::getSaveFileName(this, tr("Save public key"), + QString fname = AppGui::getSaveFileName(this, tr("Save public key"), s.value("last_used_path/ssh_key_dir", QDir::homePath()).toString(), tr("OpenSsh public key (*.pub *.*)")); if (fname.isEmpty()) return; @@ -309,7 +309,7 @@ void SSHManagement::onExportPrivateKey() if (!it) return; QSettings s; - QString fname = QFileDialog::getSaveFileName(this, tr("Save private key"), + QString fname = AppGui::getSaveFileName(this, tr("Save private key"), s.value("last_used_path/ssh_key_dir", QDir::homePath()).toString(), tr("OpenSsh private key (*.key *.*)")); if (fname.isEmpty()) return; @@ -346,7 +346,7 @@ void SSHManagement::on_pushButtonImport_clicked() } const auto fname = - QFileDialog::getOpenFileName(this, tr("OpenSSH private key"), + AppGui::getFileName(this, tr("OpenSSH private key"), s.value("last_used_path/ssh_key_dir", def_dir).toString(), tr("OpenSSH private key (*.key *.pem *.* *)")); if (fname.isEmpty()) diff --git a/src/WindowLog.cpp b/src/WindowLog.cpp old mode 100644 new mode 100755 index 8cff0b64..80530cb3 --- a/src/WindowLog.cpp +++ b/src/WindowLog.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "WindowLog.h" #include "ui_WindowLog.h" +#include "AppGui.h" WindowLog::WindowLog(QWidget *parent) : QMainWindow(parent), @@ -57,7 +58,7 @@ void WindowLog::changeEvent(QEvent *event) void WindowLog::on_pushButtonSaveLog_clicked() { QSettings s; - QString fname = QFileDialog::getSaveFileName(this, tr("Save logs to file"), + QString fname = AppGui::getSaveFileName(this, tr("Save logs to file"), s.value("last_used_path/save_logs_dir", QDir::homePath()).toString(), "Text file (*.txt);;All files (*.*)"); if (!fname.isEmpty()) From c723c5dbb59e458e28d3f12fcdaa5d2ab2a32306 Mon Sep 17 00:00:00 2001 From: Oliver Toth Date: Wed, 5 Apr 2023 19:52:50 +0200 Subject: [PATCH 2/2] Fix CSS in AppGui --- src/AppGui.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AppGui.cpp b/src/AppGui.cpp index 798e4f9c..88936d47 100755 --- a/src/AppGui.cpp +++ b/src/AppGui.cpp @@ -295,10 +295,9 @@ bool AppGui::initialize() #ifdef Q_OS_LINUX // Enforce white background and black text color to fix dark mode on Linux - this->setStyleSheet("QCheckBox:unchecked, QCheckBox:checked, QCheckBox, QRadioButton" + this->setStyleSheet("QCheckBox:unchecked, QCheckBox:checked, QCheckBox, QRadioButton, CredentialView, QTreeView" "{ color: black; background-color : white; }" "QGroupBox { color: black; }" - "CredentialView, QTreeView { color: black; background-color: black; }" ); #endif