Skip to content

Commit

Permalink
UI: Add "Show" button to password text properties
Browse files Browse the repository at this point in the history
Allows the user to be able to optionally toggle the password text if
they wish.  Mostly useful for troubleshooting purposes.
  • Loading branch information
jp9000 committed May 25, 2015
1 parent 5cb8916 commit cce2eb9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions obs/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SceneProjector="Fullscreen Projector (Scene)"
SourceProjector="Fullscreen Projector (Source)"
Clear="Clear"
Revert="Revert"
Show="Show"

# "name already exists" dialog box
NameExists.Title="Name already exists"
Expand Down
36 changes: 31 additions & 5 deletions obs/properties-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ QWidget *OBSPropertiesView::AddCheckbox(obs_property_t *prop)
return NewWidget(prop, checkbox, SIGNAL(stateChanged(int)));
}

QWidget *OBSPropertiesView::AddText(obs_property_t *prop)
QWidget *OBSPropertiesView::AddText(obs_property_t *prop, QFormLayout *layout,
QLabel *&label)
{
const char *name = obs_property_name(prop);
const char *val = obs_data_get_string(settings, name);
Expand All @@ -193,13 +194,32 @@ QWidget *OBSPropertiesView::AddText(obs_property_t *prop)
if (type == OBS_TEXT_MULTILINE) {
QPlainTextEdit *edit = new QPlainTextEdit(QT_UTF8(val));
return NewWidget(prop, edit, SIGNAL(textChanged()));
}

QLineEdit *edit = new QLineEdit();
} else if (type == OBS_TEXT_PASSWORD) {
QLayout *subLayout = new QHBoxLayout();
QLineEdit *edit = new QLineEdit();
QPushButton *show = new QPushButton();

if (type == OBS_TEXT_PASSWORD)
show->setText(QTStr("Show"));
show->setCheckable(true);
edit->setText(QT_UTF8(val));
edit->setEchoMode(QLineEdit::Password);

subLayout->addWidget(edit);
subLayout->addWidget(show);

WidgetInfo *info = new WidgetInfo(this, prop, edit);
connect(show, &QAbstractButton::toggled,
info, &WidgetInfo::TogglePasswordText);
children.emplace_back(info);

label = new QLabel(QT_UTF8(obs_property_description(prop)));
layout->addRow(label, subLayout);
return nullptr;
}

QLineEdit *edit = new QLineEdit();

edit->setText(QT_UTF8(val));

return NewWidget(prop, edit, SIGNAL(textEdited(const QString &)));
Expand Down Expand Up @@ -571,7 +591,7 @@ void OBSPropertiesView::AddProperty(obs_property_t *property,
AddFloat(property, layout, &label);
break;
case OBS_PROPERTY_TEXT:
widget = AddText(property);
widget = AddText(property, layout, label);
break;
case OBS_PROPERTY_PATH:
AddPath(property, layout, &label);
Expand Down Expand Up @@ -794,6 +814,12 @@ void WidgetInfo::ButtonClicked()
}
}

void WidgetInfo::TogglePasswordText(bool show)
{
reinterpret_cast<QLineEdit*>(widget)->setEchoMode(
show ? QLineEdit::Normal : QLineEdit::Password);
}

void WidgetInfo::ControlChanged()
{
const char *setting = obs_property_name(property);
Expand Down
8 changes: 7 additions & 1 deletion obs/properties-view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ typedef void (*PropertiesUpdateCallback)(void *obj,
class WidgetInfo : public QObject {
Q_OBJECT

friend class OBSPropertiesView;

private:
OBSPropertiesView *view;
obs_property_t *property;
Expand All @@ -33,13 +35,16 @@ class WidgetInfo : public QObject {
bool FontChanged(const char *setting);
void ButtonClicked();

void TogglePasswordText(bool checked);

public:
inline WidgetInfo(OBSPropertiesView *view_, obs_property_t *prop,
QWidget *widget_)
: view(view_), property(prop), widget(widget_)
{}

public slots:

void ControlChanged();
};

Expand Down Expand Up @@ -72,7 +77,8 @@ class OBSPropertiesView : public VScrollArea {
const char *signal);

QWidget *AddCheckbox(obs_property_t *prop);
QWidget *AddText(obs_property_t *prop);
QWidget *AddText(obs_property_t *prop, QFormLayout *layout,
QLabel *&label);
void AddPath(obs_property_t *prop, QFormLayout *layout, QLabel **label);
void AddInt(obs_property_t *prop, QFormLayout *layout, QLabel **label);
void AddFloat(obs_property_t *prop, QFormLayout *layout,
Expand Down

0 comments on commit cce2eb9

Please sign in to comment.