Skip to content

Commit

Permalink
Merge pull request #1164 from deXol/develop
Browse files Browse the repository at this point in the history
Prevent Linux Mint dark mode readability issues, fix #1158
  • Loading branch information
limpkin authored Apr 15, 2023
2 parents 91bff07 + c723c5d commit 13fa0ec
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 19 deletions.
39 changes: 39 additions & 0 deletions src/AppGui.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ 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, CredentialView, QTreeView"
"{ color: black; background-color : white; }"
"QGroupBox { color: black; }"
);
#endif

return true;
}

Expand Down Expand Up @@ -756,6 +764,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;
Expand Down
3 changes: 3 additions & 0 deletions src/AppGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/BleDev.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down
7 changes: 7 additions & 0 deletions src/CredentialsManagement.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/CredentialsManagement.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/DbExportsRegistryController.cpp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "DbExportsRegistryController.h"
#include "PromptWidget.h"
#include "AppGui.h"

#include <QFileDialog>
#include <QFileInfo>
Expand Down Expand Up @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions src/FidoManagement.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions src/FilesManagement.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/MainWindow.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions src/MainWindow.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions src/SSHManagement.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion src/WindowLog.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
******************************************************************************/
#include "WindowLog.h"
#include "ui_WindowLog.h"
#include "AppGui.h"

WindowLog::WindowLog(QWidget *parent) :
QMainWindow(parent),
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 13fa0ec

Please sign in to comment.