summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-03-19 22:30:05 +0000
committerCarl Hetherington <cth@carlh.net>2019-04-08 00:22:40 +0100
commit8f0620c52d92166e91902d61a74b6c57d39d6776 (patch)
treeb15f39ddd83abfbfce1c277cbba93fea869f73f1
parent7990591ca2f8fe61d280a445f49adce738000ed3 (diff)
Hide passwords in text fields.
-rw-r--r--src/wx/full_config_dialog.cc73
-rw-r--r--src/wx/password_entry.cc76
-rw-r--r--src/wx/password_entry.h44
-rw-r--r--src/wx/wscript1
-rw-r--r--src/wx/wx_util.cc11
-rw-r--r--src/wx/wx_util.h2
6 files changed, 170 insertions, 37 deletions
diff --git a/src/wx/full_config_dialog.cc b/src/wx/full_config_dialog.cc
index e6147c3ea..9d4270542 100644
--- a/src/wx/full_config_dialog.cc
+++ b/src/wx/full_config_dialog.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -39,6 +39,7 @@
#include "static_text.h"
#include "check_box.h"
#include "dcpomatic_button.h"
+#include "password_entry.h"
#include "lib/config.h"
#include "lib/ratio.h"
#include "lib/filter.h"
@@ -669,8 +670,8 @@ private:
table->Add (_tms_user, 1, wxEXPAND);
add_label_to_sizer (table, _panel, _("Password"), true);
- _tms_password = new wxTextCtrl (_panel, wxID_ANY);
- table->Add (_tms_password, 1, wxEXPAND);
+ _tms_password = new PasswordEntry (_panel);
+ table->Add (_tms_password->get_panel(), 1, wxEXPAND);
_tms_protocol->Append (_("SCP (for AAM and Doremi)"));
_tms_protocol->Append (_("FTP (for Dolby)"));
@@ -679,7 +680,7 @@ private:
_tms_ip->Bind (wxEVT_TEXT, boost::bind (&TMSPage::tms_ip_changed, this));
_tms_path->Bind (wxEVT_TEXT, boost::bind (&TMSPage::tms_path_changed, this));
_tms_user->Bind (wxEVT_TEXT, boost::bind (&TMSPage::tms_user_changed, this));
- _tms_password->Bind (wxEVT_TEXT, boost::bind (&TMSPage::tms_password_changed, this));
+ _tms_password->Changed.connect (boost::bind (&TMSPage::tms_password_changed, this));
}
void config_changed ()
@@ -715,14 +716,14 @@ private:
void tms_password_changed ()
{
- Config::instance()->set_tms_password (wx_to_std (_tms_password->GetValue ()));
+ Config::instance()->set_tms_password (_tms_password->get());
}
wxChoice* _tms_protocol;
wxTextCtrl* _tms_ip;
wxTextCtrl* _tms_path;
wxTextCtrl* _tms_user;
- wxTextCtrl* _tms_password;
+ PasswordEntry* _tms_password;
};
static string
@@ -782,14 +783,14 @@ private:
table->Add (_user, 1, wxEXPAND | wxALL);
add_label_to_sizer (table, _panel, _("Password"), true);
- _password = new wxTextCtrl (_panel, wxID_ANY);
- table->Add (_password, 1, wxEXPAND | wxALL);
+ _password = new PasswordEntry (_panel);
+ table->Add (_password->get_panel(), 1, wxEXPAND | wxALL);
_server->Bind (wxEVT_TEXT, boost::bind (&EmailPage::server_changed, this));
_port->Bind (wxEVT_SPINCTRL, boost::bind (&EmailPage::port_changed, this));
_protocol->Bind (wxEVT_CHOICE, boost::bind (&EmailPage::protocol_changed, this));
_user->Bind (wxEVT_TEXT, boost::bind (&EmailPage::user_changed, this));
- _password->Bind (wxEVT_TEXT, boost::bind (&EmailPage::password_changed, this));
+ _password->Changed.connect (boost::bind (&EmailPage::password_changed, this));
}
void config_changed ()
@@ -813,7 +814,7 @@ private:
break;
}
checked_set (_user, config->mail_user ());
- checked_set (_password, config->mail_password ());
+ checked_set (_password, config->mail_password());
}
void server_changed ()
@@ -851,14 +852,14 @@ private:
void password_changed ()
{
- Config::instance()->set_mail_password (wx_to_std (_password->GetValue ()));
+ Config::instance()->set_mail_password(_password->get());
}
wxTextCtrl* _server;
wxSpinCtrl* _port;
wxChoice* _protocol;
wxTextCtrl* _user;
- wxTextCtrl* _password;
+ PasswordEntry* _password;
};
class KDMEmailPage : public StandardPage
@@ -1012,31 +1013,31 @@ public:
table->Add (_barco_username, 1, wxEXPAND | wxALL);
add_label_to_sizer (table, _panel, _("certificates.barco.com password"), true);
- _barco_password = new wxTextCtrl (_panel, wxID_ANY);
- table->Add (_barco_password, 1, wxEXPAND | wxALL);
+ _barco_password = new PasswordEntry (_panel);
+ table->Add (_barco_password->get_panel(), 1, wxEXPAND | wxALL);
add_label_to_sizer (table, _panel, _("certificates.christiedigital.com user name"), true);
_christie_username = new wxTextCtrl (_panel, wxID_ANY);
table->Add (_christie_username, 1, wxEXPAND | wxALL);
add_label_to_sizer (table, _panel, _("certificates.christiedigital.com password"), true);
- _christie_password = new wxTextCtrl (_panel, wxID_ANY);
- table->Add (_christie_password, 1, wxEXPAND | wxALL);
+ _christie_password = new PasswordEntry (_panel);
+ table->Add (_christie_password->get_panel(), 1, wxEXPAND | wxALL);
add_label_to_sizer (table, _panel, _("GDC user name"), true);
_gdc_username = new wxTextCtrl (_panel, wxID_ANY);
table->Add (_gdc_username, 1, wxEXPAND | wxALL);
add_label_to_sizer (table, _panel, _("GDC password"), true);
- _gdc_password = new wxTextCtrl (_panel, wxID_ANY);
- table->Add (_gdc_password, 1, wxEXPAND | wxALL);
+ _gdc_password = new PasswordEntry (_panel);
+ table->Add (_gdc_password->get_panel(), 1, wxEXPAND | wxALL);
_barco_username->Bind (wxEVT_TEXT, boost::bind(&AccountsPage::barco_username_changed, this));
- _barco_password->Bind (wxEVT_TEXT, boost::bind(&AccountsPage::barco_password_changed, this));
+ _barco_password->Changed.connect (boost::bind(&AccountsPage::barco_password_changed, this));
_christie_username->Bind (wxEVT_TEXT, boost::bind(&AccountsPage::christie_username_changed, this));
- _christie_password->Bind (wxEVT_TEXT, boost::bind(&AccountsPage::christie_password_changed, this));
+ _christie_password->Changed.connect (boost::bind(&AccountsPage::christie_password_changed, this));
_gdc_username->Bind (wxEVT_TEXT, boost::bind(&AccountsPage::gdc_username_changed, this));
- _gdc_password->Bind (wxEVT_TEXT, boost::bind(&AccountsPage::gdc_password_changed, this));
+ _gdc_password->Changed.connect (boost::bind(&AccountsPage::gdc_password_changed, this));
}
void config_changed ()
@@ -1063,11 +1064,11 @@ public:
void barco_password_changed ()
{
- wxString const s = _barco_password->GetValue();
- if (!s.IsEmpty()) {
- Config::instance()->set_barco_password (wx_to_std(s));
+ string const s = _barco_password->get();
+ if (!s.empty()) {
+ Config::instance()->set_barco_password(s);
} else {
- Config::instance()->unset_barco_password ();
+ Config::instance()->unset_barco_password();
}
}
@@ -1083,11 +1084,11 @@ public:
void christie_password_changed ()
{
- wxString const s = _christie_password->GetValue();
- if (!s.IsEmpty()) {
- Config::instance()->set_christie_password (wx_to_std(s));
+ string const s = _christie_password->get();
+ if (!s.empty()) {
+ Config::instance()->set_christie_password(s);
} else {
- Config::instance()->unset_christie_password ();
+ Config::instance()->unset_christie_password();
}
}
@@ -1103,21 +1104,21 @@ public:
void gdc_password_changed ()
{
- wxString const s = _gdc_password->GetValue();
- if (!s.IsEmpty()) {
- Config::instance()->set_gdc_password (wx_to_std(s));
+ string const s = _gdc_password->get();
+ if (!s.empty()) {
+ Config::instance()->set_gdc_password(s);
} else {
- Config::instance()->unset_gdc_password ();
+ Config::instance()->unset_gdc_password();
}
}
private:
wxTextCtrl* _barco_username;
- wxTextCtrl* _barco_password;
+ PasswordEntry* _barco_password;
wxTextCtrl* _christie_username;
- wxTextCtrl* _christie_password;
+ PasswordEntry* _christie_password;
wxTextCtrl* _gdc_username;
- wxTextCtrl* _gdc_password;
+ PasswordEntry* _gdc_password;
};
diff --git a/src/wx/password_entry.cc b/src/wx/password_entry.cc
new file mode 100644
index 000000000..f44ed9cb0
--- /dev/null
+++ b/src/wx/password_entry.cc
@@ -0,0 +1,76 @@
+/*
+ Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "password_entry.h"
+#include "check_box.h"
+#include "wx_util.h"
+
+using std::string;
+using boost::bind;
+
+PasswordEntry::PasswordEntry (wxWindow* parent)
+{
+ _panel = new wxPanel (parent, wxID_ANY);
+ wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
+ _text = new wxTextCtrl (_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
+ sizer->Add (_text, 1, wxRIGHT, DCPOMATIC_SIZER_GAP);
+ _show = new CheckBox (_panel, _("Show"));
+ sizer->Add (_show, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
+ _panel->SetSizerAndFit (sizer);
+
+ _show->Bind (wxEVT_CHECKBOX, bind(&PasswordEntry::show_clicked, this));
+ _text->Bind (wxEVT_TEXT, bind(boost::ref(Changed)));
+}
+
+wxPanel *
+PasswordEntry::get_panel () const
+{
+ return _panel;
+}
+
+void
+PasswordEntry::show_clicked ()
+{
+ _panel->Freeze ();
+ wxString const pass = _text->GetValue ();
+ wxSizer* sizer = _text->GetContainingSizer ();
+ long from, to;
+ _text->GetSelection (&from, &to);
+ sizer->Detach (_text);
+ delete _text;
+ _text = new wxTextCtrl (_panel, wxID_ANY, pass, wxDefaultPosition, wxDefaultSize, _show->GetValue() ? 0 : wxTE_PASSWORD);
+ _text->SetSelection (from, to);
+ _text->Bind (wxEVT_TEXT, bind(boost::ref(Changed)));
+ sizer->Prepend (_text, 1, wxRIGHT, DCPOMATIC_SIZER_GAP);
+ sizer->Layout ();
+ _panel->Thaw ();
+}
+
+string
+PasswordEntry::get () const
+{
+ return wx_to_std (_text->GetValue());
+}
+
+void
+PasswordEntry::set (string s)
+{
+ _text->SetValue (std_to_wx(s));
+}
diff --git a/src/wx/password_entry.h b/src/wx/password_entry.h
new file mode 100644
index 000000000..b7cc93319
--- /dev/null
+++ b/src/wx/password_entry.h
@@ -0,0 +1,44 @@
+/*
+ Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <wx/wx.h>
+#include <boost/signals2.hpp>
+
+class CheckBox;
+
+class PasswordEntry
+{
+public:
+ PasswordEntry (wxWindow* parent);
+
+ wxPanel* get_panel () const;
+
+ std::string get () const;
+ void set (std::string);
+
+ boost::signals2::signal<void ()> Changed;
+
+private:
+ void show_clicked ();
+
+ wxPanel* _panel;
+ wxTextCtrl* _text;
+ CheckBox* _show;
+};
diff --git a/src/wx/wscript b/src/wx/wscript
index 7f953df49..4cd3bcb19 100644
--- a/src/wx/wscript
+++ b/src/wx/wscript
@@ -93,6 +93,7 @@ sources = """
new_dkdm_folder_dialog.cc
normal_job_view.cc
paste_dialog.cc
+ password_entry.cc
player_config_dialog.cc
player_information.cc
playhead_to_timecode_dialog.cc
diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc
index 747d1df04..bfc7c3069 100644
--- a/src/wx/wx_util.cc
+++ b/src/wx/wx_util.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -25,6 +25,7 @@
#include "wx_util.h"
#include "file_picker_ctrl.h"
#include "static_text.h"
+#include "password_entry.h"
#include "lib/config.h"
#include "lib/job_manager.h"
#include "lib/util.h"
@@ -293,6 +294,14 @@ checked_set (wxTextCtrl* widget, string value)
}
void
+checked_set (PasswordEntry* entry, string value)
+{
+ if (entry->get() != value) {
+ entry->set(value);
+ }
+}
+
+void
checked_set (wxTextCtrl* widget, wxString value)
{
if (widget->GetValue() != value) {
diff --git a/src/wx/wx_util.h b/src/wx/wx_util.h
index d6de3b427..0b16943ff 100644
--- a/src/wx/wx_util.h
+++ b/src/wx/wx_util.h
@@ -41,6 +41,7 @@ class wxSpinCtrl;
class wxSpinCtrlDouble;
class wxGridBagSizer;
class wxSplashScreen;
+class PasswordEntry;
#define DCPOMATIC_SIZER_X_GAP 8
#define DCPOMATIC_SIZER_Y_GAP 8
@@ -99,6 +100,7 @@ extern void checked_set (wxChoice* widget, std::string value);
extern void checked_set (wxChoice* widget, std::vector<std::pair<std::string, std::string> > items);
extern void checked_set (wxTextCtrl* widget, std::string value);
extern void checked_set (wxTextCtrl* widget, wxString value);
+extern void checked_set (PasswordEntry* widget, std::string value);
extern void checked_set (wxCheckBox* widget, bool value);
extern void checked_set (wxRadioButton* widget, bool value);
extern void checked_set (wxStaticText* widget, std::string value);