Hide passwords in text fields.
authorCarl Hetherington <cth@carlh.net>
Tue, 19 Mar 2019 22:30:05 +0000 (22:30 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 10 May 2019 22:43:42 +0000 (23:43 +0100)
src/wx/full_config_dialog.cc
src/wx/password_entry.cc [new file with mode: 0644]
src/wx/password_entry.h [new file with mode: 0644]
src/wx/wscript
src/wx/wx_util.cc
src/wx/wx_util.h

index e6147c3eab706dfbfcfc62111362a3c3758c3875..9d427054267237a307da9877701e39bfb2d0d3a2 100644 (file)
@@ -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 (file)
index 0000000..f44ed9c
--- /dev/null
@@ -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 (file)
index 0000000..b7cc933
--- /dev/null
@@ -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;
+};
index 349842797cc6fede6077470db3561b39342061ac..aad7ecc6339bfc9e9ebbd23ca1baa18e8a46c266 100644 (file)
@@ -94,6 +94,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
index 747d1df04c269290fc350d6cdf474dda61f0d2c9..bfc7c30690936ec405cd0833c6719030d1403d62 100644 (file)
@@ -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"
@@ -292,6 +293,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)
 {
index 920d6f2440cf8cd36c8abccbdd36d2e8ba50efee..1b3c4a2aec19c577c58a6883deba627e2a271f5a 100644 (file)
@@ -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);