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/>.
21 #include "download_certificate_dialog.h"
22 #include "credentials_download_certificate_panel.h"
23 #include "password_entry.h"
28 using boost::optional;
30 CredentialsDownloadCertificatePanel::CredentialsDownloadCertificatePanel (
31 DownloadCertificateDialog* dialog,
32 function<optional<string> ()> get_username,
33 function<void (string)> set_username,
34 function<void ()> unset_username,
35 function<optional<string> ()> get_password,
36 function<void (string)> set_password,
37 function<void ()> unset_password
39 : DownloadCertificatePanel (dialog)
40 , _get_username (get_username)
41 , _set_username (set_username)
42 , _unset_username (unset_username)
43 , _get_password (get_password)
44 , _set_password (set_password)
45 , _unset_password (unset_password)
47 add_label_to_sizer (_table, this, _("User name"), true, 0, wxALIGN_CENTER_VERTICAL);
48 _username = new wxTextCtrl (this, wxID_ANY, std_to_wx(_get_username().get_value_or("")), wxDefaultPosition, wxSize(300, -1));
49 _table->Add (_username, 1, wxEXPAND);
51 add_label_to_sizer (_table, this, _("Password"), true, 0, wxALIGN_CENTER_VERTICAL);
52 _password = new PasswordEntry (this);
53 _password->set (_get_password().get_value_or(""));
54 _table->Add (_password->get_panel(), 1, wxEXPAND);
56 _username->Bind (wxEVT_TEXT, boost::bind(&CredentialsDownloadCertificatePanel::username_changed, this));
57 _password->Changed.connect (boost::bind(&CredentialsDownloadCertificatePanel::password_changed, this));
59 _overall_sizer->Layout ();
60 _overall_sizer->SetSizeHints (this);
64 CredentialsDownloadCertificatePanel::ready_to_download () const
66 return DownloadCertificatePanel::ready_to_download() && static_cast<bool>(_get_username()) && _get_username().get() != "" && static_cast<bool>(_get_password()) && _get_password().get() != "";
70 CredentialsDownloadCertificatePanel::username_changed ()
72 wxString const s = _username->GetValue();
74 _set_username (wx_to_std(s));
78 _dialog->setup_sensitivity ();
82 CredentialsDownloadCertificatePanel::password_changed ()
84 string const s = _password->get();
90 _dialog->setup_sensitivity ();