diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-08-15 02:08:05 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-08-15 10:57:07 +0100 |
| commit | f8acc34bcb4401184064598353d6c54df3cab1f9 (patch) | |
| tree | f3861ef2b616beb1de08f14a70605480e1feeebc /src | |
| parent | 6a69f5ba3ce43094493785bb449c91001557b80d (diff) | |
More rearrangement and add Barco Alchemy.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/config.cc | 12 | ||||
| -rw-r--r-- | src/lib/config.h | 26 | ||||
| -rw-r--r-- | src/lib/internet.cc | 53 | ||||
| -rw-r--r-- | src/lib/internet.h | 1 | ||||
| -rw-r--r-- | src/lib/scoped_temporary.h | 5 | ||||
| -rw-r--r-- | src/wx/barco_alchemy_certificate_panel.cc | 77 | ||||
| -rw-r--r-- | src/wx/barco_alchemy_certificate_panel.h | 31 | ||||
| -rw-r--r-- | src/wx/dolby_doremi_certificate_panel.cc | 12 | ||||
| -rw-r--r-- | src/wx/dolby_doremi_certificate_panel.h | 4 | ||||
| -rw-r--r-- | src/wx/download_certificate_dialog.cc | 9 | ||||
| -rw-r--r-- | src/wx/download_certificate_dialog.h | 8 | ||||
| -rw-r--r-- | src/wx/download_certificate_panel.cc | 9 | ||||
| -rw-r--r-- | src/wx/download_certificate_panel.h | 9 | ||||
| -rw-r--r-- | src/wx/full_config_dialog.cc | 72 | ||||
| -rw-r--r-- | src/wx/wscript | 1 |
15 files changed, 293 insertions, 36 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index 7e2cdabf6..792ce5619 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -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) { diff --git a/src/lib/config.h b/src/lib/config.h index dbe6a9c21..8bf766c02 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -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; diff --git a/src/lib/internet.cc b/src/lib/internet.cc index c1bb5e88f..846dbf7ca 100644 --- a/src/lib/internet.cc +++ b/src/lib/internet.cc @@ -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)); diff --git a/src/lib/internet.h b/src/lib/internet.h index 9b88bde97..15746a44a 100644 --- a/src/lib/internet.h +++ b/src/lib/internet.h @@ -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); diff --git a/src/lib/scoped_temporary.h b/src/lib/scoped_temporary.h index 87c8e387f..986f565a0 100644 --- a/src/lib/scoped_temporary.h +++ b/src/lib/scoped_temporary.h @@ -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. @@ -19,12 +19,13 @@ */ #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 index 000000000..ba7deb8fd --- /dev/null +++ b/src/wx/barco_alchemy_certificate_panel.cc @@ -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 index 000000000..83a74fa21 --- /dev/null +++ b/src/wx/barco_alchemy_certificate_panel.h @@ -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; +}; diff --git a/src/wx/dolby_doremi_certificate_panel.cc b/src/wx/dolby_doremi_certificate_panel.cc index f0f0a2601..ea0207a9b 100644 --- a/src/wx/dolby_doremi_certificate_panel.cc +++ b/src/wx/dolby_doremi_certificate_panel.cc @@ -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) { diff --git a/src/wx/dolby_doremi_certificate_panel.h b/src/wx/dolby_doremi_certificate_panel.h index 21f928621..665281073 100644 --- a/src/wx/dolby_doremi_certificate_panel.h +++ b/src/wx/dolby_doremi_certificate_panel.h @@ -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; }; diff --git a/src/wx/download_certificate_dialog.cc b/src/wx/download_certificate_dialog.cc index a2219cd6f..6ca605f56 100644 --- a/src/wx/download_certificate_dialog.cc +++ b/src/wx/download_certificate_dialog.cc @@ -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 () diff --git a/src/wx/download_certificate_dialog.h b/src/wx/download_certificate_dialog.h index 0df504975..180c13278 100644 --- a/src/wx/download_certificate_dialog.h +++ b/src/wx/download_certificate_dialog.h @@ -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 &); diff --git a/src/wx/download_certificate_panel.cc b/src/wx/download_certificate_panel.cc index f9a88a7bb..2f3b435ef 100644 --- a/src/wx/download_certificate_panel.cc +++ b/src/wx/download_certificate_panel.cc @@ -29,10 +29,9 @@ 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 diff --git a/src/wx/download_certificate_panel.h b/src/wx/download_certificate_panel.h index 252474c59..55594c74c 100644 --- a/src/wx/download_certificate_panel.h +++ b/src/wx/download_certificate_panel.h @@ -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 diff --git a/src/wx/full_config_dialog.cc b/src/wx/full_config_dialog.cc index 523973618..bf26519e1 100644 --- a/src/wx/full_config_dialog.cc +++ b/src/wx/full_config_dialog.cc @@ -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)); diff --git a/src/wx/wscript b/src/wx/wscript index 0a32d1dfe..39617b840 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -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 |
