Trim spaces from entries to certificate download pages.
[dcpomatic.git] / src / wx / barco_alchemy_certificate_panel.cc
index 84048c65cf98d97b767577668d14e489e9dad93c..19bd18a8dc02c731118c0ae73eba682fb45e43af 100644 (file)
 
 */
 
+
 #include "barco_alchemy_certificate_panel.h"
 #include "download_certificate_dialog.h"
 #include "wx_util.h"
 #include "lib/internet.h"
 #include "lib/compose.hpp"
 #include "lib/config.h"
+#include <boost/algorithm/string.hpp>
+
 
 using std::string;
+using namespace boost::algorithm;
 using boost::optional;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
+
 
 BarcoAlchemyCertificatePanel::BarcoAlchemyCertificatePanel (DownloadCertificateDialog* dialog)
-       : DownloadCertificatePanel (dialog)
+       : CredentialsDownloadCertificatePanel (
+                       dialog,
+                       boost::bind(&Config::barco_username, Config::instance()),
+                       boost::bind(&Config::set_barco_username, Config::instance(), _1),
+                       boost::bind(&Config::unset_barco_username, Config::instance()),
+                       boost::bind(&Config::barco_password, Config::instance()),
+                       boost::bind(&Config::set_barco_password, Config::instance(), _1),
+                       boost::bind(&Config::unset_barco_password, Config::instance())
+                       )
 {
 
 }
@@ -37,21 +53,15 @@ BarcoAlchemyCertificatePanel::BarcoAlchemyCertificatePanel (DownloadCertificateD
 bool
 BarcoAlchemyCertificatePanel::ready_to_download () const
 {
-       return _serial->GetValue().Length() == 10;
+       return CredentialsDownloadCertificatePanel::ready_to_download() && _serial->GetValue().Length() == 10;
 }
 
 void
 BarcoAlchemyCertificatePanel::do_download ()
 {
-       Config* config = Config::instance ();
-       if (!config->barco_username() || !config->barco_password()) {
-               _dialog->message()->SetLabel(wxT(""));
-               error_dialog (this, _("No Barco username/password configured.  Add your account details to the Accounts page in Preferences."));
-               return;
-       }
-
-       string const serial = wx_to_std (_serial->GetValue());
-       string const url = String::compose (
+       string serial = wx_to_std (_serial->GetValue());
+       trim(serial);
+       string url = String::compose (
                "ftp://%1:%2@certificates.barco.com/%3xxx/%4/Barco-ICMP.%5_cert.pem",
                Config::instance()->barco_username().get(),
                Config::instance()->barco_password().get(),
@@ -59,8 +69,9 @@ BarcoAlchemyCertificatePanel::do_download ()
                serial,
                serial
                );
+       trim(url);
 
-       optional<string> error = get_from_url (url, true, false, boost::bind (&DownloadCertificatePanel::load, this, _1));
+       auto error = get_from_url (url, true, false, boost::bind (&DownloadCertificatePanel::load_certificate, this, _1, _2));
        if (error) {
                _dialog->message()->SetLabel(wxT(""));
                error_dialog (this, std_to_wx(*error));