Start of Dolby certificate download.
authorCarl Hetherington <cth@carlh.net>
Wed, 26 Mar 2014 13:36:12 +0000 (13:36 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 26 Mar 2014 13:36:12 +0000 (13:36 +0000)
13 files changed:
src/wx/dolby_certificate_dialog.cc [new file with mode: 0644]
src/wx/dolby_certificate_dialog.h [new file with mode: 0644]
src/wx/doremi_certificate_dialog.cc [new file with mode: 0644]
src/wx/doremi_certificate_dialog.h [new file with mode: 0644]
src/wx/download_certificate_dialog.cc [new file with mode: 0644]
src/wx/download_certificate_dialog.h [new file with mode: 0644]
src/wx/progress.cc [deleted file]
src/wx/progress.h [deleted file]
src/wx/screen_dialog.cc
src/wx/screen_dialog.h
src/wx/wscript
src/wx/wx_util.cc
src/wx/wx_util.h

diff --git a/src/wx/dolby_certificate_dialog.cc b/src/wx/dolby_certificate_dialog.cc
new file mode 100644 (file)
index 0000000..d44c9e7
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <curl/curl.h>
+#include "lib/compose.hpp"
+#include "dolby_certificate_dialog.h"
+#include "wx_util.h"
+
+using std::list;
+using std::string;
+using std::stringstream;
+using std::cout;
+
+DolbyCertificateDialog::DolbyCertificateDialog (wxWindow* parent, boost::function<void (boost::filesystem::path)> load)
+       : DownloadCertificateDialog (parent, load)
+{
+       wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+
+       _country = new wxChoice (this, wxID_ANY);
+       add_label_to_sizer (table, this, _("Country"), true);
+       table->Add (_country, 1, wxEXPAND | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
+       _country->Append (N_("Hashemite Kingdom of Jordan"));
+       
+       _cinema = new wxChoice (this, wxID_ANY);
+       add_label_to_sizer (table, this, _("Cinema"), true);
+       table->Add (_cinema, 1, wxEXPAND | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
+       _cinema->Append (N_("Wometco Dominicana Palacio Del Cine"));
+       _overall_sizer->Add (table);
+
+       add_common_widgets ();
+
+       _country->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::country_selected, this));
+       _cinema->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DolbyCertificateDialog::cinema_selected, this));
+
+       _country->Clear ();
+       _cinema->Clear ();
+}
+
+static size_t
+ftp_data_ls (void* buffer, size_t size, size_t nmemb, void* data)
+{
+       string* s = reinterpret_cast<string *> (data);
+       uint8_t* b = reinterpret_cast<uint8_t *> (buffer);
+       for (size_t i = 0; i < (size * nmemb); ++i) {
+               *s += b[i];
+       }
+       return nmemb;
+}
+
+list<string>
+DolbyCertificateDialog::ftp_ls (string dir) const
+{
+       CURL* curl = curl_easy_init ();
+       if (!curl) {
+               _message->SetLabel (N_("Could not set up libcurl"));
+               return list<string> ();
+       }
+
+       string url = String::compose ("ftp://dolbyrootcertificates:houro61l@ftp.dolby.co.uk/SHA256/%1", dir);
+       if (url.substr (url.length() - 1, 1) != "/") {
+               url += "/";
+       }
+       curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
+
+       string ls_raw;
+       struct curl_slist* commands = 0;
+       commands = curl_slist_append (commands, "NLST");
+       curl_easy_setopt (curl, CURLOPT_POSTQUOTE, commands);
+       curl_easy_setopt (curl, CURLOPT_WRITEDATA, &ls_raw);
+       curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ftp_data_ls);
+       curl_easy_setopt (curl, CURLOPT_FTP_USE_EPSV, 0);
+       CURLcode const r = curl_easy_perform (curl);
+       if (r != CURLE_OK) {
+               _message->SetLabel (_("Problem occurred when contacting Dolby."));
+               return list<string> ();
+       }
+
+       stringstream s (ls_raw);
+       string line;
+       list<string> ls;
+       while (s.good ()) {
+               getline (s, line);
+               if (line.length() > 55) {
+                       string const file = line.substr (55);
+                       if (file != "." && file != "..") {
+                               ls.push_back (file);
+                       }
+               }
+       }
+
+       curl_easy_cleanup (curl);
+
+       return ls;
+}
+
+void
+DolbyCertificateDialog::setup ()
+{
+       _message->SetLabel (_("Fetching available countries"));
+       run_gui_loop ();
+       list<string> const countries = ftp_ls ("");
+       for (list<string>::const_iterator i = countries.begin(); i != countries.end(); ++i) {
+               _country->Append (std_to_wx (*i));
+       }
+       _message->SetLabel ("");
+}
+
+void
+DolbyCertificateDialog::country_selected ()
+{
+       _message->SetLabel (_("Fetching available cinemas"));
+       run_gui_loop ();
+       list<string> const cinemas = ftp_ls (wx_to_std (_country->GetStringSelection()));
+       _cinema->Clear ();
+       for (list<string>::const_iterator i = cinemas.begin(); i != cinemas.end(); ++i) {
+               _cinema->Append (std_to_wx (*i));
+       }
+       _message->SetLabel ("");
+}
+
+void
+DolbyCertificateDialog::cinema_selected ()
+{
+       _download->Enable (true);
+}
+
+void
+DolbyCertificateDialog::download ()
+{
+
+}
diff --git a/src/wx/dolby_certificate_dialog.h b/src/wx/dolby_certificate_dialog.h
new file mode 100644 (file)
index 0000000..7c8e6c5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <curl/curl.h>
+#include "download_certificate_dialog.h"
+
+class DolbyCertificateDialog : public DownloadCertificateDialog
+{
+public:
+       DolbyCertificateDialog (wxWindow *, boost::function<void (boost::filesystem::path)>);
+
+       void setup ();
+
+private:
+       void download ();
+       void country_selected ();
+       void cinema_selected ();
+       std::list<std::string> ftp_ls (std::string) const;
+
+       wxChoice* _country;
+       wxChoice* _cinema;
+};
diff --git a/src/wx/doremi_certificate_dialog.cc b/src/wx/doremi_certificate_dialog.cc
new file mode 100644 (file)
index 0000000..51f2a35
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <curl/curl.h>
+#include <zip.h>
+#include "lib/compose.hpp"
+#include "lib/util.h"
+#include "doremi_certificate_dialog.h"
+#include "wx_util.h"
+
+using std::string;
+using boost::function;
+
+DoremiCertificateDialog::DoremiCertificateDialog (wxWindow* parent, function<void (boost::filesystem::path)> load)
+       : DownloadCertificateDialog (parent, load)
+{
+       wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+
+       add_label_to_sizer (table, this, _("Server serial number"), true);
+       _serial = new wxTextCtrl (this, wxID_ANY);
+       table->Add (_serial, 1, wxEXPAND);
+
+       _overall_sizer->Add (table, 1, wxALL, DCPOMATIC_DIALOG_BORDER);
+
+       add_common_widgets ();
+}
+
+
+
+static size_t
+ftp_data (void* buffer, size_t size, size_t nmemb, void* stream)
+{
+       FILE* f = reinterpret_cast<FILE*> (stream);
+       return fwrite (buffer, size, nmemb, f);
+}
+
+void
+DoremiCertificateDialog::download ()
+{
+       string const serial = wx_to_std (_serial->GetValue ());
+       if (serial.length() != 6) {
+               _message->SetLabel (_("Doremi serial numbers must have 6 digits"));
+               return;
+       }
+       
+       CURL* curl = curl_easy_init ();
+       if (!curl) {
+               _message->SetLabel (N_("Could not set up libcurl"));
+               return;
+       }
+       
+       string const url = String::compose (
+               "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/dcp2000-%2.dcicerts.zip",
+               serial.substr(0, 3), serial
+               );
+       
+       curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
+       
+       ScopedTemporary temp_zip;
+       FILE* f = temp_zip.open ("wb");
+       curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ftp_data);
+       curl_easy_setopt (curl, CURLOPT_WRITEDATA, f);
+
+       _message->SetLabel (_("Downloading certificate from Doremi"));
+       run_gui_loop ();
+
+       CURLcode const cr = curl_easy_perform (curl);
+
+       _gauge->SetValue (50);
+       run_gui_loop ();
+       
+       temp_zip.close ();
+       curl_easy_cleanup (curl);
+       if (cr != CURLE_OK) {
+               _message->SetLabel (wxString::Format (_("Certificate download failed (%d)"), cr));
+               return;
+       }
+       
+       _message->SetLabel (_("Unpacking"));
+       run_gui_loop ();
+       
+       struct zip* zip = zip_open (temp_zip.c_str(), 0, 0);
+       if (!zip) {
+               _message->SetLabel (N_("Could not open certificate ZIP file"));
+               return;
+       }
+       
+       string const name_in_zip = String::compose ("dcp2000-%1.cert.sha256.pem", serial);
+       struct zip_file* zip_file = zip_fopen (zip, name_in_zip.c_str(), 0);
+       if (!zip_file) {
+               _message->SetLabel (N_("Could not find certificate in ZIP file"));
+               return;
+       }
+       
+       ScopedTemporary temp_cert;
+       f = temp_cert.open ("wb");
+       char buffer[4096];
+       while (1) {
+               int const N = zip_fread (zip_file, buffer, sizeof (buffer));
+               fwrite (buffer, 1, N, f);
+               if (N < int (sizeof (buffer))) {
+                       break;
+               }
+       }
+       temp_cert.close ();
+       
+       _gauge->SetValue (100);
+       _message->SetLabel (_("OK"));
+       _load (temp_cert.file ());
+}
diff --git a/src/wx/doremi_certificate_dialog.h b/src/wx/doremi_certificate_dialog.h
new file mode 100644 (file)
index 0000000..c2cb15d
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "download_certificate_dialog.h"
+
+class DoremiCertificateDialog : public DownloadCertificateDialog
+{
+public:
+       DoremiCertificateDialog (wxWindow *, boost::function<void (boost::filesystem::path)>);
+
+private:
+       void download ();
+
+       wxTextCtrl* _serial;
+};
diff --git a/src/wx/download_certificate_dialog.cc b/src/wx/download_certificate_dialog.cc
new file mode 100644 (file)
index 0000000..44a366b
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/bind.hpp>
+#include "download_certificate_dialog.h"
+#include "wx_util.h"
+
+using boost::function;
+
+DownloadCertificateDialog::DownloadCertificateDialog (wxWindow* parent, function<void (boost::filesystem::path)> load)
+       : wxDialog (parent, wxID_ANY, _("Download certificate"))
+       , _load (load)
+{
+       _overall_sizer = new wxBoxSizer (wxVERTICAL);
+}
+
+void
+DownloadCertificateDialog::add_common_widgets ()
+{
+       _download = new wxButton (this, wxID_ANY, _("Download"));
+       _overall_sizer->Add (_download, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
+       _gauge = new wxGauge (this, wxID_ANY, 100);
+       _overall_sizer->Add (_gauge, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
+       _message = new wxStaticText (this, wxID_ANY, wxT (""));
+       _overall_sizer->Add (_message, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
+       
+       wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
+       if (buttons) {
+               _overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
+       }
+
+       SetSizer (_overall_sizer);
+       _overall_sizer->Layout ();
+       _overall_sizer->SetSizeHints (this);
+
+       _download->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DownloadCertificateDialog::download, this));
+       _download->Enable (false);
+}
diff --git a/src/wx/download_certificate_dialog.h b/src/wx/download_certificate_dialog.h
new file mode 100644 (file)
index 0000000..11f1afe
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef DCPOMATIC_DOWNLOAD_CERTIFICATE_DIALOG_H
+#define DCPOMATIC_DOWNLOAD_CERTIFICATE_DIALOG_H
+
+#include <wx/wx.h>
+#include <boost/function.hpp>
+#include <boost/filesystem.hpp>
+
+class DownloadCertificateDialog : public wxDialog
+{
+public:
+       DownloadCertificateDialog (wxWindow *, boost::function<void (boost::filesystem::path)>);
+       virtual void setup () {}
+
+protected:
+       void add_common_widgets ();
+       
+       boost::function<void (boost::filesystem::path)> _load;
+       wxSizer* _overall_sizer;
+       wxGauge* _gauge;
+       wxStaticText* _message;
+       wxButton* _download;
+
+private:
+       virtual void download () = 0;
+};
+
+#endif
diff --git a/src/wx/progress.cc b/src/wx/progress.cc
deleted file mode 100644 (file)
index 9e3da6c..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
-
-    This program 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.
-
-    This program 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 this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include <string>
-#include "progress.h"
-#include "wx_util.h"
-
-using std::string;
-
-Progress::Progress (wxWindow* parent)
-       : wxPanel (parent, wxID_ANY)
-{
-       wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
-
-       _gauge = new wxGauge (this, wxID_ANY, 100);
-       s->Add (_gauge, 1, wxEXPAND);
-       _label = new wxStaticText (this, wxID_ANY, wxT (""));
-       s->Add (_label, 1, wxEXPAND);
-
-       SetSizerAndFit (s);
-}
-
-void
-Progress::set_value (int v)
-{
-       _gauge->SetValue (v);
-       run_gui_loop ();
-}
-
-void
-Progress::set_message (wxString s)
-{
-       _label->SetLabel (s);
-       run_gui_loop ();
-}
-
-void
-Progress::run_gui_loop ()
-{
-       while (wxTheApp->Pending ()) {
-               wxTheApp->Dispatch ();
-       }
-}
-
diff --git a/src/wx/progress.h b/src/wx/progress.h
deleted file mode 100644 (file)
index 9ce3243..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
-
-    This program 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.
-
-    This program 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 this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include <wx/wx.h>
-
-class Progress : public wxPanel
-{
-public:
-       Progress (wxWindow* parent);
-       
-       /** Set progress value.
-        *  @param v Progress from 0 to 100.
-        */
-       void set_value (int v);
-       void set_message (wxString);
-
-private:
-       void run_gui_loop ();
-       
-       wxGauge* _gauge;
-       wxStaticText* _label;
-};
index b077a9bf93b4b29115084a63d9f3303b71800145..ca278a233fc5fe59b5d20df19209b2622486bf1b 100644 (file)
 
 #include <wx/filepicker.h>
 #include <wx/validate.h>
-#include <curl/curl.h>
-#include <zip.h>
 #include <libdcp/exceptions.h>
 #include "lib/compose.hpp"
 #include "lib/util.h"
 #include "screen_dialog.h"
 #include "wx_util.h"
-#include "progress.h"
+#include "doremi_certificate_dialog.h"
+#include "dolby_certificate_dialog.h"
 
 using std::string;
 using std::cout;
@@ -47,11 +46,7 @@ ScreenDialog::ScreenDialog (wxWindow* parent, string title, string name, shared_
        _manufacturer = new wxChoice (this, wxID_ANY);
        table->Add (_manufacturer, 1, wxEXPAND);
 
-       add_label_to_sizer (table, this, "Server serial number", true);
-       _serial = new wxTextCtrl (this, wxID_ANY);
-       table->Add (_serial, 1, wxEXPAND);
-       
-       add_label_to_sizer (table, this, "Certificate", true);
+       add_label_to_sizer (table, this, _("Certificate"), true);
        wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
        _load_certificate = new wxButton (this, wxID_ANY, _("Load from file..."));
        _download_certificate = new wxButton (this, wxID_ANY, _("Download"));
@@ -59,10 +54,6 @@ ScreenDialog::ScreenDialog (wxWindow* parent, string title, string name, shared_
        s->Add (_download_certificate, 1, wxEXPAND);
        table->Add (s, 1, wxEXPAND);
 
-       table->AddSpacer (0);
-       _progress = new Progress (this);
-       table->Add (_progress, 1, wxEXPAND);
-
        table->AddSpacer (0);
        _certificate_text = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (320, 256), wxTE_MULTILINE | wxTE_READONLY);
        if (certificate) {
@@ -87,13 +78,13 @@ ScreenDialog::ScreenDialog (wxWindow* parent, string title, string name, shared_
 
        _manufacturer->Append (_("Unknown"));
        _manufacturer->Append (_("Doremi"));
+       _manufacturer->Append (_("Dolby"));
        _manufacturer->Append (_("Other"));
        _manufacturer->SetSelection (0);
 
        _load_certificate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreenDialog::select_certificate, this));
        _download_certificate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ScreenDialog::download_certificate, this));
        _manufacturer->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&ScreenDialog::setup_sensitivity, this));
-       _serial->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&ScreenDialog::setup_sensitivity, this));
 
        setup_sensitivity ();
 }
@@ -125,89 +116,27 @@ void
 ScreenDialog::select_certificate ()
 {
        wxFileDialog* d = new wxFileDialog (this, _("Select Certificate File"));
-
        if (d->ShowModal () == wxID_OK) {
                load_certificate (boost::filesystem::path (wx_to_std (d->GetPath ())));
        }
-       
        d->Destroy ();
 
        setup_sensitivity ();
 }
 
-static size_t
-ftp_data (void* buffer, size_t size, size_t nmemb, void* stream)
-{
-       FILE* f = reinterpret_cast<FILE*> (stream);
-       return fwrite (buffer, size, nmemb, f);
-}
-
 void
 ScreenDialog::download_certificate ()
 {
        if (_manufacturer->GetStringSelection() == _("Doremi")) {
-               string const serial = wx_to_std (_serial->GetValue ());
-               if (serial.length() != 6) {
-                       error_dialog (this, _("Doremi serial numbers must have 6 numbers"));
-                       return;
-               }
-
-               CURL* curl = curl_easy_init ();
-               if (!curl) {
-                       error_dialog (this, N_("Could not set up libcurl"));
-                       return;
-               }
-
-               string const url = String::compose (
-                       "ftp://service:t3chn1c1an@ftp.doremilabs.com/Certificates/%1xxx/dcp2000-%2.dcicerts.zip",
-                       serial.substr(0, 3), serial
-                       );
-
-               curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
-
-               ScopedTemporary temp_zip;
-               FILE* f = temp_zip.open ("wb");
-               curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ftp_data);
-               curl_easy_setopt (curl, CURLOPT_WRITEDATA, f);
-               _progress->set_message (_("Downloading certificate from Doremi"));
-               CURLcode const cr = curl_easy_perform (curl);
-               _progress->set_value (50);
-               temp_zip.close ();
-               curl_easy_cleanup (curl);
-               if (cr != CURLE_OK) {
-                       _progress->set_message (wxString::Format (_("Certificate download failed (%d)"), cr));
-                       return;
-               }
-
-               _progress->set_message (_("Unpacking"));
-               struct zip* zip = zip_open (temp_zip.c_str(), 0, 0);
-               if (!zip) {
-                       _progress->set_message ("Could not open certificate ZIP file");
-                       return;
-               }
-
-               string const name_in_zip = String::compose ("dcp2000-%1.cert.sha256.pem", serial);
-               struct zip_file* zip_file = zip_fopen (zip, name_in_zip.c_str(), 0);
-               if (!zip_file) {
-                       _progress->set_message ("Could not find certificate in ZIP file");
-                       return;
-               }
-
-               ScopedTemporary temp_cert;
-               f = temp_cert.open ("wb");
-               char buffer[4096];
-               while (1) {
-                       int const N = zip_fread (zip_file, buffer, sizeof (buffer));
-                       fwrite (buffer, 1, N, f);
-                       if (N < int (sizeof (buffer))) {
-                               break;
-                       }
-               }
-               temp_cert.close ();
-
-               _progress->set_value (100);
-               _progress->set_message (_("OK"));
-               load_certificate (temp_cert.file ());
+               DownloadCertificateDialog* d = new DoremiCertificateDialog (this, boost::bind (&ScreenDialog::load_certificate, this, _1));
+               d->setup ();
+               d->ShowModal ();
+               d->Destroy ();
+       } else if (_manufacturer->GetStringSelection() == _("Dolby")) {
+               DownloadCertificateDialog* d = new DolbyCertificateDialog (this, boost::bind (&ScreenDialog::load_certificate, this, _1));
+               d->setup ();
+               d->ShowModal ();
+               d->Destroy ();
        }
 }
 
@@ -217,5 +146,8 @@ ScreenDialog::setup_sensitivity ()
        wxButton* ok = dynamic_cast<wxButton*> (FindWindowById (wxID_OK, this));
        ok->Enable (_certificate);
 
-       _download_certificate->Enable (_manufacturer->GetStringSelection() == _("Doremi") && !_serial->GetValue().IsEmpty ());
+       _download_certificate->Enable (
+               _manufacturer->GetStringSelection() == _("Doremi") ||
+               _manufacturer->GetStringSelection() == _("Dolby")
+               );
 }
index 1fcc8d5641085a4e2f2b99e31848e3afd294c3db..385707ea839785dbd6c42a22b34e27f40a59ecce 100644 (file)
@@ -39,8 +39,6 @@ private:
        
        wxTextCtrl* _name;
        wxChoice* _manufacturer;
-       wxTextCtrl* _serial;
-       Progress* _progress;
        wxButton* _load_certificate;
        wxButton* _download_certificate;
        wxTextCtrl* _certificate_text;
index 56476c4ce9a5128b690f737e26991beb81e63258..2fa37216b33fed605d688e57a891bf9179642484 100644 (file)
@@ -17,6 +17,9 @@ sources = """
           content_menu.cc
           dci_metadata_dialog.cc
           dir_picker_ctrl.cc
+          dolby_certificate_dialog.cc
+          doremi_certificate_dialog.cc
+          download_certificate_dialog.cc
           film_editor.cc
           film_editor_panel.cc
           film_viewer.cc
@@ -29,7 +32,6 @@ sources = """
           kdm_dialog.cc
           new_film_dialog.cc
           preset_colour_conversion_dialog.cc
-          progress.cc
           properties_dialog.cc
           repeat_dialog.cc
           screen_dialog.cc
index 367d1edbbf522d12634dbc2c967bea73732f83cd..96278b82bac0d1197a26ae68da601c9084a912a3 100644 (file)
@@ -296,3 +296,11 @@ wx_get (wxChoice* w)
 {
        return w->GetSelection ();
 }
+
+void
+run_gui_loop ()
+{
+       while (wxTheApp->Pending ()) {
+               wxTheApp->Dispatch ();
+       }
+}
index 8ac824c508d81d1edc5640de2df33f7a792cfdc2..0afd82b900a104834936dd75a3029ede0d0d9e04 100644 (file)
@@ -48,6 +48,7 @@ extern wxStaticText* add_label_to_grid_bag_sizer (wxGridBagSizer *, wxWindow *,
 extern std::string wx_to_std (wxString);
 extern wxString std_to_wx (std::string);
 extern void dcpomatic_setup_i18n ();
+extern void run_gui_loop ();
 
 /** @class ThreadedStaticText
  *