Skip to content

Commit

Permalink
Merge pull request #587 from l3u/display_options
Browse files Browse the repository at this point in the history
Add more options for the password displaying
  • Loading branch information
annejan authored Jan 28, 2023
2 parents 00eac1e + c384dee commit bc2c04c
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/configdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ ConfigDialog::ConfigDialog(MainWindow *parent)
QtPassSettings::getAutoclearPanelSeconds());
ui->checkBoxHidePassword->setChecked(QtPassSettings::isHidePassword());
ui->checkBoxHideContent->setChecked(QtPassSettings::isHideContent());
ui->checkBoxUseMonospace->setChecked(QtPassSettings::isUseMonospace());
ui->checkBoxDisplayAsIs->setChecked(QtPassSettings::isDisplayAsIs());
ui->checkBoxNoLineWrapping->setChecked(QtPassSettings::isNoLineWrapping());
ui->checkBoxAddGPGId->setChecked(QtPassSettings::isAddGPGId(true));

if (QSystemTrayIcon::isSystemTrayAvailable()) {
Expand Down Expand Up @@ -203,6 +206,9 @@ void ConfigDialog::on_accepted() {
ui->spinBoxAutoclearPanelSeconds->value());
QtPassSettings::setHidePassword(ui->checkBoxHidePassword->isChecked());
QtPassSettings::setHideContent(ui->checkBoxHideContent->isChecked());
QtPassSettings::setUseMonospace(ui->checkBoxUseMonospace->isChecked());
QtPassSettings::setDisplayAsIs(ui->checkBoxDisplayAsIs->isChecked());
QtPassSettings::setNoLineWrapping(ui->checkBoxNoLineWrapping->isChecked());
QtPassSettings::setAddGPGId(ui->checkBoxAddGPGId->isChecked());
QtPassSettings::setUseTrayIcon(ui->checkBoxUseTrayIcon->isEnabled() &&
ui->checkBoxUseTrayIcon->isChecked());
Expand Down
40 changes: 39 additions & 1 deletion src/configdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>659</width>
<height>650</height>
<height>728</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -212,6 +212,44 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_19">
<item>
<widget class="QCheckBox" name="checkBoxUseMonospace">
<property name="text">
<string>Use a monospace font</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxDisplayAsIs">
<property name="text">
<string>Display the files content as-is</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxNoLineWrapping">
<property name="text">
<string>No line wrapping</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
Expand Down
29 changes: 26 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ MainWindow::MainWindow(const QString &searchText, QWidget *parent)
connect(ui->treeView, &DeselectableTreeView::emptyClicked, this,
&MainWindow::deselect);

if (QtPassSettings::isUseMonospace()) {
ui->textBrowser->setFont(QFont(QStringLiteral("Monospace")));
}
if (QtPassSettings::isNoLineWrapping()) {
ui->textBrowser->setLineWrapMode(QTextBrowser::NoWrap);
}
ui->textBrowser->setOpenExternalLinks(true);
ui->textBrowser->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->textBrowser, &QWidget::customContextMenuRequested, this,
Expand Down Expand Up @@ -239,6 +245,19 @@ void MainWindow::config() {
d->wizard(); // does shit
if (d->exec()) {
if (d->result() == QDialog::Accepted) {
// Update the textBrowser font
if (QtPassSettings::isUseMonospace()) {
ui->textBrowser->setFont(QFont(QStringLiteral("Monospace")));
} else {
ui->textBrowser->setFont(QFont());
}
// Update the textBrowser line wrap mode
if (QtPassSettings::isNoLineWrapping()) {
ui->textBrowser->setLineWrapMode(QTextBrowser::NoWrap);
} else {
ui->textBrowser->setLineWrapMode(QTextBrowser::WidgetWidth);
}

if (QtPassSettings::isAlwaysOnTop()) {
Qt::WindowFlags flags = windowFlags();
this->setWindowFlags(flags | Qt::WindowStaysOnTopHint);
Expand Down Expand Up @@ -385,7 +404,7 @@ void MainWindow::passShowHandler(const QString &p_output) {
// show what is needed:
if (QtPassSettings::isHideContent()) {
output = "***" + tr("Content hidden") + "***";
} else {
} else if (! QtPassSettings::isDisplayAsIs()) {
if (!password.isEmpty()) {
// set the password, it is hidden if needed in addToGridLayout
addToGridLayout(0, tr("Password"), password);
Expand Down Expand Up @@ -1099,13 +1118,17 @@ void MainWindow::addToGridLayout(int position, const QString &field,
}

// set the echo mode to password, if the field is "password"
const QString lineStyle = QtPassSettings::isUseMonospace()
? "border-style: none; background: transparent; font-family: monospace;"
: "border-style: none; background: transparent;";

if (QtPassSettings::isHidePassword() && trimmedField == tr("Password")) {

auto *line = new QLineEdit();
line->setObjectName(trimmedField);
line->setText(trimmedValue);
line->setReadOnly(true);
line->setStyleSheet("border-style: none ; background: transparent;");
line->setStyleSheet(lineStyle);
line->setContentsMargins(0, 0, 0, 0);
line->setEchoMode(QLineEdit::Password);
QPushButtonShowPassword *showButton =
Expand All @@ -1129,7 +1152,7 @@ void MainWindow::addToGridLayout(int position, const QString &field,
R"(<a href="\1">\1</a>)");
line->setText(trimmedValue);
line->setReadOnly(true);
line->setStyleSheet("border-style: none ; background: transparent;");
line->setStyleSheet(lineStyle);
line->setContentsMargins(0, 0, 0, 0);
frame->layout()->addWidget(line);
}
Expand Down
27 changes: 27 additions & 0 deletions src/qtpasssettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,33 @@ void QtPassSettings::setHideContent(const bool &hideContent) {
getInstance()->setValue(SettingsConstants::hideContent, hideContent);
}

bool QtPassSettings::isUseMonospace(const bool &defaultValue) {
return getInstance()
->value(SettingsConstants::useMonospace, defaultValue)
.toBool();
}
void QtPassSettings::setUseMonospace(const bool &useMonospace) {
getInstance()->setValue(SettingsConstants::useMonospace, useMonospace);
}

bool QtPassSettings::isDisplayAsIs(const bool &defaultValue) {
return getInstance()
->value(SettingsConstants::displayAsIs, defaultValue)
.toBool();
}
void QtPassSettings::setDisplayAsIs(const bool &displayAsIs) {
getInstance()->setValue(SettingsConstants::displayAsIs, displayAsIs);
}

bool QtPassSettings::isNoLineWrapping(const bool &defaultValue) {
return getInstance()
->value(SettingsConstants::noLineWrapping, defaultValue)
.toBool();
}
void QtPassSettings::setNoLineWrapping(const bool &noLineWrapping) {
getInstance()->setValue(SettingsConstants::noLineWrapping, noLineWrapping);
}

bool QtPassSettings::isAddGPGId(const bool &defaultValue) {
return getInstance()
->value(SettingsConstants::addGPGId, defaultValue)
Expand Down
9 changes: 9 additions & 0 deletions src/qtpasssettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ class QtPassSettings : public QSettings {
static bool isHideContent(const bool &defaultValue = QVariant().toBool());
static void setHideContent(const bool &hideContent);

static bool isUseMonospace(const bool &defaultValue = QVariant().toBool());
static void setUseMonospace(const bool &useMonospace);

static bool isDisplayAsIs(const bool &defaultValue = QVariant().toBool());
static void setDisplayAsIs(const bool &displayAsIs);

static bool isNoLineWrapping(const bool &defaultValue = QVariant().toBool());
static void setNoLineWrapping(const bool &noLineWrapping);

static bool isAddGPGId(const bool &defaultValue = QVariant().toBool());
static void setAddGPGId(const bool &addGPGId);

Expand Down
3 changes: 3 additions & 0 deletions src/settingsconstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const QString SettingsConstants::autoclearPanelSeconds =
"autoclearPanelSeconds";
const QString SettingsConstants::hidePassword = "hidePassword";
const QString SettingsConstants::hideContent = "hideContent";
const QString SettingsConstants::useMonospace = "useMonospace";
const QString SettingsConstants::displayAsIs = "displayAsIs";
const QString SettingsConstants::noLineWrapping = "noLineWrapping";
const QString SettingsConstants::addGPGId = "addGPGId";
const QString SettingsConstants::passStore = "passStore";
const QString SettingsConstants::passExecutable = "passExecutable";
Expand Down
3 changes: 3 additions & 0 deletions src/settingsconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class SettingsConstants {
const static QString autoclearPanelSeconds;
const static QString hidePassword;
const static QString hideContent;
const static QString useMonospace;
const static QString displayAsIs;
const static QString noLineWrapping;
const static QString addGPGId;
const static QString passStore;
const static QString passExecutable;
Expand Down

0 comments on commit bc2c04c

Please sign in to comment.