More rearrangement and add Barco Alchemy.
authorCarl Hetherington <cth@carlh.net>
Wed, 15 Aug 2018 01:08:05 +0000 (02:08 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 15 Aug 2018 09:57:07 +0000 (10:57 +0100)
15 files changed:
src/lib/config.cc
src/lib/config.h
src/lib/internet.cc
src/lib/internet.h
src/lib/scoped_temporary.h
src/wx/barco_alchemy_certificate_panel.cc [new file with mode: 0644]
src/wx/barco_alchemy_certificate_panel.h [new file with mode: 0644]
src/wx/dolby_doremi_certificate_panel.cc
src/wx/dolby_doremi_certificate_panel.h
src/wx/download_certificate_dialog.cc
src/wx/download_certificate_dialog.h
src/wx/download_certificate_panel.cc
src/wx/download_certificate_panel.h
src/wx/full_config_dialog.cc
src/wx/wscript

index 7e2cdabf649970355fccdf0c81160f6aa692244b..792ce5619571f06304478494e329157bd67456b4 100644 (file)
@@ -156,6 +156,8 @@ Config::set_defaults ()
        for (int i = 0; i < NOTIFICATION_COUNT; ++i) {
                _notification[i] = false;
        }
+       _barco_username = optional<string>();
+       _barco_password = optional<string>();
 
        _allowed_dcp_frame_rates.clear ();
        _allowed_dcp_frame_rates.push_back (24);
@@ -463,6 +465,9 @@ try
                }
        }
 
+       _barco_username = f.optional_string_child("BarcoUsername");
+       _barco_password = f.optional_string_child("BarcoPassword");
+
        /* Replace any cinemas from config.xml with those from the configured file */
        if (boost::filesystem::exists (_cinemas_file)) {
                cxml::Document f ("Cinemas");
@@ -806,6 +811,13 @@ Config::write_config () const
                e->add_child_text (_notification[i] ? "1" : "0");
        }
 
+       if (_barco_username) {
+               root->add_child("BarcoUsername")->add_child_text(*_barco_username);
+       }
+       if (_barco_password) {
+               root->add_child("BarcoPassword")->add_child_text(*_barco_password);
+       }
+
        try {
                doc.write_to_file_formatted(config_file().string());
        } catch (xmlpp::exception& e) {
index dbe6a9c212b1042ab0e65ab4fd22d2b617b2f8a8..8bf766c021a151d36e6b995a231a509e595efb1e 100644 (file)
@@ -423,6 +423,14 @@ public:
                return _notification[n];
        }
 
+       boost::optional<std::string> barco_username () const {
+               return _barco_username;
+       }
+
+       boost::optional<std::string> barco_password () const {
+               return _barco_password;
+       }
+
        /* SET (mostly) */
 
        void set_master_encoding_threads (int n) {
@@ -769,6 +777,22 @@ public:
                maybe_set (_notification[n], v);
        }
 
+       void set_barco_username (std::string u) {
+               maybe_set (_barco_username, u);
+       }
+
+       void unset_barco_username () {
+               maybe_set (_barco_username, boost::optional<std::string>());
+       }
+
+       void set_barco_password (std::string p) {
+               maybe_set (_barco_password, p);
+       }
+
+       void unset_barco_password () {
+               maybe_set (_barco_password, boost::optional<std::string>());
+       }
+
        void changed (Property p = OTHER);
        boost::signals2::signal<void (Property)> Changed;
        /** Emitted if read() failed on an existing Config file.  There is nothing
@@ -944,6 +968,8 @@ private:
        boost::optional<int> _decode_reduction;
        bool _default_notify;
        bool _notification[NOTIFICATION_COUNT];
+       boost::optional<std::string> _barco_username;
+       boost::optional<std::string> _barco_password;
 
        static int const _current_version;
 
index c1bb5e88fbd3d7aab609b202cdd2e960e4ebe304..846dbf7cae3fa7849e97e59ed6b126a1eba68281 100644 (file)
@@ -38,27 +38,23 @@ using boost::optional;
 using boost::function;
 using boost::algorithm::trim;
 
+
 static size_t
-get_from_zip_url_data (void* buffer, size_t size, size_t nmemb, void* stream)
+get_from_url_data (void* buffer, size_t size, size_t nmemb, void* stream)
 {
        FILE* f = reinterpret_cast<FILE*> (stream);
        return fwrite (buffer, size, nmemb, f);
 }
 
-/** @param url URL of ZIP file.
- *  @param file Filename within ZIP file.
- *  @param load Function passed a (temporary) filesystem path of the unpacked file.
- */
+static
 optional<string>
-get_from_zip_url (string url, string file, bool pasv, function<void (boost::filesystem::path)> load)
+get_from_url (string url, bool pasv, ScopedTemporary& temp)
 {
-       /* Download the ZIP file to temp_zip */
        CURL* curl = curl_easy_init ();
-       curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
+       curl_easy_setopt (curl, CURLOPT_URL, url.c_str());
 
-       ScopedTemporary temp_zip;
-       FILE* f = temp_zip.open ("wb");
-       curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, get_from_zip_url_data);
+       FILE* f = temp.open ("w");
+       curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, get_from_url_data);
        curl_easy_setopt (curl, CURLOPT_WRITEDATA, f);
        curl_easy_setopt (curl, CURLOPT_FTP_USE_EPSV, 0);
        curl_easy_setopt (curl, CURLOPT_FTP_USE_EPRT, 0);
@@ -71,10 +67,39 @@ get_from_zip_url (string url, string file, bool pasv, function<void (boost::file
 
        CURLcode const cr = curl_easy_perform (curl);
 
-       temp_zip.close ();
+       temp.close ();
        curl_easy_cleanup (curl);
        if (cr != CURLE_OK) {
-               return String::compose (_("Download failed (%1/%2 error %3)"), url, file, (int) cr);
+               return String::compose (_("Download failed (%1 error %2)"), url, (int) cr);
+       }
+
+       return optional<string>();
+}
+
+optional<string>
+get_from_url (string url, bool pasv, function<void (boost::filesystem::path)> load)
+{
+       ScopedTemporary temp;
+       optional<string> e = get_from_url (url, pasv, temp);
+       if (e) {
+               return e;
+       }
+       load (temp.file());
+       return optional<string>();
+}
+
+/** @param url URL of ZIP file.
+ *  @param file Filename within ZIP file.
+ *  @param load Function passed a (temporary) filesystem path of the unpacked file.
+ */
+optional<string>
+get_from_zip_url (string url, string file, bool pasv, function<void (boost::filesystem::path)> load)
+{
+       /* Download the ZIP file to temp_zip */
+       ScopedTemporary temp_zip;
+       optional<string> e = get_from_url (url, pasv, temp_zip);
+       if (e) {
+               return e;
        }
 
        /* Open the ZIP file and read `file' out of it */
@@ -110,7 +135,7 @@ get_from_zip_url (string url, string file, bool pasv, function<void (boost::file
        }
 
        ScopedTemporary temp_cert;
-       f = temp_cert.open ("wb");
+       FILE* f = temp_cert.open ("wb");
        char buffer[4096];
        while (true) {
                int const N = zip_fread (file_in_zip, buffer, sizeof (buffer));
index 9b88bde973fe409d055f2b29e6f70bbfad7cd469..15746a44af8cf726cce096f1bb4e8b24b10f725d 100644 (file)
@@ -22,4 +22,5 @@
 #include <boost/function.hpp>
 #include <boost/filesystem.hpp>
 
+boost::optional<std::string> get_from_url (std::string url, bool pasv, boost::function<void (boost::filesystem::path)> load);
 boost::optional<std::string> get_from_zip_url (std::string url, std::string file, bool pasv, boost::function<void (boost::filesystem::path)> load);
index 87c8e387f338b31ca7df40f1f32c23a290f6f4ca..986f565a0896a64e507eba34ba7bdbc1d8c94d14 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 */
 
 #include <boost/filesystem.hpp>
+#include <boost/noncopyable.hpp>
 #include <cstdio>
 
 /** @class ScopedTemporary
  *  @brief A temporary file which is deleted when the ScopedTemporary object goes out of scope.
  */
-class ScopedTemporary
+class ScopedTemporary : public boost::noncopyable
 {
 public:
        ScopedTemporary ();
diff --git a/src/wx/barco_alchemy_certificate_panel.cc b/src/wx/barco_alchemy_certificate_panel.cc
new file mode 100644 (file)
index 0000000..ba7deb8
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+    Copyright (C) 2018 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 "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"
+
+using std::string;
+using boost::optional;
+
+BarcoAlchemyCertificatePanel::BarcoAlchemyCertificatePanel (DownloadCertificateDialog* dialog)
+       : DownloadCertificatePanel (dialog)
+{
+
+}
+
+bool
+BarcoAlchemyCertificatePanel::ready_to_download () const
+{
+       return _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 (
+               "ftp://%1:%2@certificates.barco.com/%3xxx/%4/Barco-ICMP.%5_cert.pem",
+               Config::instance()->barco_username().get(),
+               Config::instance()->barco_password().get(),
+               serial.substr(0, 7),
+               serial,
+               serial
+               );
+
+       optional<string> error = get_from_url (url, true, boost::bind (&DownloadCertificatePanel::load, this, _1));
+       if (error) {
+               _dialog->message()->SetLabel(wxT(""));
+               error_dialog (this, std_to_wx(*error));
+       } else {
+               _dialog->message()->SetLabel (_("Certificate downloaded"));
+               _dialog->setup_sensitivity ();
+       }
+}
+
+wxString
+BarcoAlchemyCertificatePanel::name () const
+{
+       return _("Barco Alchemy");
+}
diff --git a/src/wx/barco_alchemy_certificate_panel.h b/src/wx/barco_alchemy_certificate_panel.h
new file mode 100644 (file)
index 0000000..83a74fa
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+    Copyright (C) 2018 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 "download_certificate_panel.h"
+
+class BarcoAlchemyCertificatePanel : public DownloadCertificatePanel
+{
+public:
+       BarcoAlchemyCertificatePanel (DownloadCertificateDialog* dialog);
+
+       bool ready_to_download () const;
+       void do_download ();
+       wxString name () const;
+};
index f0f0a2601e219d6d97a74df045d644dad3a51662..ea0207a9ba067875decfd86654c4707e85b1b947 100644 (file)
@@ -38,8 +38,8 @@ using boost::function;
 using boost::optional;
 using dcp::raw_convert;
 
-DolbyDoremiCertificatePanel::DolbyDoremiCertificatePanel (wxWindow* parent, wxStaticText* message, DownloadCertificateDialog* dialog)
-       : DownloadCertificatePanel (parent, message, dialog)
+DolbyDoremiCertificatePanel::DolbyDoremiCertificatePanel (DownloadCertificateDialog* dialog)
+       : DownloadCertificatePanel (dialog)
 {
 
 }
@@ -139,8 +139,10 @@ try_cp850 (list<string>& urls, list<string>& files, string prefix, string serial
 }
 
 void
-DolbyDoremiCertificatePanel::do_download (string serial)
+DolbyDoremiCertificatePanel::do_download ()
 {
+       string const serial = wx_to_std (_serial->GetValue());
+
        /* Try dcp2000, imb and ims prefixes (see mantis #375) */
 
        string const prefix = "ftp://anonymous@ftp.cinema.dolby.com/Certificates/";
@@ -184,10 +186,10 @@ DolbyDoremiCertificatePanel::do_download (string serial)
        }
 
        if (ok) {
-               _message->SetLabel (_("Certificate downloaded"));
+               _dialog->message()->SetLabel (_("Certificate downloaded"));
                _dialog->setup_sensitivity ();
        } else {
-               _message->SetLabel (wxT (""));
+               _dialog->message()->SetLabel (wxT (""));
 
                string s;
                BOOST_FOREACH (string e, errors) {
index 21f9286218bebb1b58518002d62bca53fc1c497d..6652810732cf81855aa37873bf16f80310c052d2 100644 (file)
@@ -23,8 +23,8 @@
 class DolbyDoremiCertificatePanel : public DownloadCertificatePanel
 {
 public:
-       DolbyDoremiCertificatePanel (wxWindow* parent, wxStaticText* message, DownloadCertificateDialog* dialog);
+       DolbyDoremiCertificatePanel (DownloadCertificateDialog* dialog);
 
-       void do_download (std::string serial);
+       void do_download ();
        wxString name () const;
 };
index a2219cd6fec7a865d182d3a003a349a70130fae6..6ca605f563374a439125b648caad51429e0c2bcd 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "dolby_doremi_certificate_panel.h"
+#include "barco_alchemy_certificate_panel.h"
 #include "download_certificate_dialog.h"
 #include "wx_util.h"
 
@@ -42,7 +43,8 @@ DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent)
        font.SetPointSize (font.GetPointSize() - 1);
        _message->SetFont (font);
 
-       _pages.push_back (new DolbyDoremiCertificatePanel (_notebook, _message, this));
+       _pages.push_back (new DolbyDoremiCertificatePanel (this));
+       _pages.push_back (new BarcoAlchemyCertificatePanel (this));
 
        BOOST_FOREACH (DownloadCertificatePanel* i, _pages) {
                _notebook->AddPage (i, i->name(), true);
@@ -59,8 +61,9 @@ DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent)
        _download->Bind (wxEVT_BUTTON, boost::bind (&DownloadCertificateDialog::download, this));
        _download->Enable (false);
 
-       wxNotebookEvent ev;
-       page_changed (ev);
+       _notebook->SetSelection (0);
+
+       setup_sensitivity ();
 }
 
 DownloadCertificateDialog::~DownloadCertificateDialog ()
index 0df504975e6f904d0193cced64644203c703dbea..180c132789312ca5c04c92c42f063184d8a009d0 100644 (file)
@@ -33,6 +33,14 @@ public:
 
        void setup_sensitivity ();
 
+       wxNotebook* notebook () const {
+               return _notebook;
+       }
+
+       wxStaticText* message () const {
+               return _message;
+       }
+
 private:
        void download ();
        void page_changed (wxNotebookEvent &);
index f9a88a7bbddbcaa823eb3af619a2462f6a554721..2f3b435efaba5a4f66cc2a72f432ae1a20ad8ea3 100644 (file)
 using boost::function;
 using boost::optional;
 
-DownloadCertificatePanel::DownloadCertificatePanel (wxWindow* parent, wxStaticText* message, DownloadCertificateDialog* dialog)
-       : wxPanel (parent, wxID_ANY)
+DownloadCertificatePanel::DownloadCertificatePanel (DownloadCertificateDialog* dialog)
+       : wxPanel (dialog->notebook(), wxID_ANY)
        , _dialog (dialog)
-       , _message (message)
 {
        _overall_sizer = new wxBoxSizer (wxVERTICAL);
        SetSizer (_overall_sizer);
@@ -71,12 +70,12 @@ DownloadCertificatePanel::certificate () const
 void
 DownloadCertificatePanel::download ()
 {
-       _message->SetLabel (_("Downloading certificate"));
+       _dialog->message()->SetLabel (_("Downloading certificate"));
 
        /* Hack: without this the SetLabel() above has no visible effect */
        wxMilliSleep (200);
 
-       signal_manager->when_idle (boost::bind (&DownloadCertificatePanel::do_download, this, wx_to_std(_serial->GetValue())));
+       signal_manager->when_idle (boost::bind (&DownloadCertificatePanel::do_download, this));
 }
 
 bool
index 252474c59802e357151b36a076f047eb6610ec5e..55594c74c66b6f1df48a43d927608594f54e6c93 100644 (file)
@@ -30,12 +30,12 @@ class DownloadCertificateDialog;
 class DownloadCertificatePanel : public wxPanel
 {
 public:
-       DownloadCertificatePanel (wxWindow* parent, wxStaticText* message, DownloadCertificateDialog* dialog);
+       DownloadCertificatePanel (DownloadCertificateDialog* dialog);
 
-       virtual void do_download (std::string serial) = 0;
+       virtual void do_download () = 0;
        virtual wxString name () const = 0;
+       virtual bool ready_to_download () const;
 
-       bool ready_to_download () const;
        void download ();
        void load (boost::filesystem::path);
        boost::optional<dcp::Certificate> certificate () const;
@@ -43,12 +43,11 @@ public:
 protected:
        DownloadCertificateDialog* _dialog;
        wxFlexGridSizer* _table;
-       wxStaticText* _message;
+       wxTextCtrl* _serial;
 
 private:
        wxSizer* _overall_sizer;
        boost::optional<dcp::Certificate> _certificate;
-       wxTextCtrl* _serial;
 };
 
 #endif
index 52397361830036d394fb30e0e95f81d51605a982..bf26519e1fb2206cb1519cc9e00e65d6d03cf9f0 100644 (file)
@@ -910,6 +910,77 @@ private:
        wxButton* _reset_email;
 };
 
+class AccountsPage : public StandardPage
+{
+public:
+       AccountsPage (wxSize panel_size, int border)
+               : StandardPage (panel_size, border)
+       {}
+
+       wxString GetName () const
+       {
+               return _("Accounts");
+       }
+
+#ifdef DCPOMATIC_OSX
+       wxBitmap GetLargeIcon () const
+       {
+               return wxBitmap ("accounts", wxBITMAP_TYPE_PNG_RESOURCE);
+       }
+#endif
+
+       void setup ()
+       {
+               wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+               table->AddGrowableCol (1, 1);
+               _panel->GetSizer()->Add (table, 1, wxEXPAND | wxALL, _border);
+
+               add_label_to_sizer (table, _panel, _("certificates.barco.com username"), true);
+               _barco_username = new wxTextCtrl (_panel, wxID_ANY);
+               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_username->Bind (wxEVT_TEXT, boost::bind(&AccountsPage::barco_username_changed, this));
+               _barco_password->Bind (wxEVT_TEXT, boost::bind(&AccountsPage::barco_password_changed, this));
+       }
+
+       void config_changed ()
+       {
+               Config* config = Config::instance ();
+
+               checked_set (_barco_username, config->barco_username().get_value_or(""));
+               checked_set (_barco_password, config->barco_password().get_value_or(""));
+       }
+
+       void barco_username_changed ()
+       {
+               wxString const s = _barco_username->GetValue();
+               if (!s.IsEmpty()) {
+                       Config::instance()->set_barco_username (wx_to_std(s));
+               } else {
+                       Config::instance()->unset_barco_username ();
+               }
+       }
+
+       void barco_password_changed ()
+       {
+               wxString const s = _barco_password->GetValue();
+               if (!s.IsEmpty()) {
+                       Config::instance()->set_barco_password (wx_to_std(s));
+               } else {
+                       Config::instance()->unset_barco_password ();
+               }
+       }
+
+private:
+       wxTextCtrl* _barco_username;
+       wxTextCtrl* _barco_password;
+};
+
+
 class NotificationsPage : public StandardPage
 {
 public:
@@ -1430,6 +1501,7 @@ create_full_config_dialog ()
        e->AddPage (new TMSPage (ps, border));
        e->AddPage (new EmailPage (ps, border));
        e->AddPage (new KDMEmailPage (ps, border));
+       e->AddPage (new AccountsPage (ps, border));
        e->AddPage (new NotificationsPage (ps, border));
        e->AddPage (new CoverSheetPage (ps, border));
        e->AddPage (new AdvancedPage (ps, border));
index 0a32d1dfefcc527f2fdffcb4da6e257162972cb4..39617b840425d01ff98d7750cdac9f2bb1d9ed82 100644 (file)
@@ -31,6 +31,7 @@ sources = """
           audio_mapping_view.cc
           audio_panel.cc
           audio_plot.cc
+          barco_alchemy_certificate_panel.cc
           batch_job_view.cc
           subtitle_appearance_dialog.cc
           text_panel.cc