2 Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "download_certificate_dialog.h"
23 #include "credentials_download_certificate_panel.h"
24 #include "password_entry.h"
30 using boost::optional;
33 CredentialsDownloadCertificatePanel::CredentialsDownloadCertificatePanel (
34 DownloadCertificateDialog* dialog,
35 function<optional<string> ()> get_username,
36 function<void (string)> set_username,
37 function<void ()> unset_username,
38 function<optional<string> ()> get_password,
39 function<void (string)> set_password,
40 function<void ()> unset_password
42 : DownloadCertificatePanel (dialog)
43 , _get_username (get_username)
44 , _set_username (set_username)
45 , _unset_username (unset_username)
46 , _get_password (get_password)
47 , _set_password (set_password)
48 , _unset_password (unset_password)
50 add_label_to_sizer (_table, this, _("User name"), true, 0, wxALIGN_CENTER_VERTICAL);
51 _username = new wxTextCtrl (this, wxID_ANY, std_to_wx(_get_username().get_value_or("")), wxDefaultPosition, wxSize(300, -1));
52 _table->Add (_username, 1, wxEXPAND);
54 add_label_to_sizer (_table, this, _("Password"), true, 0, wxALIGN_CENTER_VERTICAL);
55 _password = new PasswordEntry (this);
56 _password->set (_get_password().get_value_or(""));
57 _table->Add (_password->get_panel(), 1, wxEXPAND);
59 _username->Bind (wxEVT_TEXT, boost::bind(&CredentialsDownloadCertificatePanel::username_changed, this));
60 _password->Changed.connect (boost::bind(&CredentialsDownloadCertificatePanel::password_changed, this));
62 _overall_sizer->Layout ();
63 _overall_sizer->SetSizeHints (this);
67 CredentialsDownloadCertificatePanel::ready_to_download () const
69 return DownloadCertificatePanel::ready_to_download() && static_cast<bool>(_get_username()) && _get_username().get() != "" && static_cast<bool>(_get_password()) && _get_password().get() != "";
73 CredentialsDownloadCertificatePanel::username_changed ()
75 wxString const s = _username->GetValue();
77 _set_username (wx_to_std(s));
81 _dialog->setup_sensitivity ();
85 CredentialsDownloadCertificatePanel::password_changed ()
87 string const s = _password->get();
93 _dialog->setup_sensitivity ();