Support subs and tidy up a few things.
[dcpomatic.git] / src / wx / update_dialog.cc
1 /*
2     Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #include "update_dialog.h"
23 #include "static_text.h"
24 #include "wx_util.h"
25 #include "lib/warnings.h"
26 DCPOMATIC_DISABLE_WARNINGS
27 #include <wx/hyperlink.h>
28 DCPOMATIC_ENABLE_WARNINGS
29
30
31 using std::string;
32 using boost::optional;
33
34
35 UpdateDialog::UpdateDialog (wxWindow* parent, optional<string> stable, optional<string> test)
36         : wxDialog (parent, wxID_ANY, _("Update"))
37 {
38         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
39
40         wxStaticText* message;
41
42         if ((stable || test) && !(stable && test)) {
43                 message = new StaticText (this, _("A new version of DCP-o-matic is available."));
44         } else {
45                 message = new StaticText (this, _("New versions of DCP-o-matic are available."));
46         }
47
48         overall_sizer->Add (message, 0, wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
49
50         auto table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
51
52         if (stable) {
53                 add_label_to_sizer (table, this, _("Stable version ") + std_to_wx(stable.get()), true, 0, wxALIGN_CENTER_VERTICAL);
54                 auto h = new wxHyperlinkCtrl (this, wxID_ANY, "dcpomatic.com/download", "https://dcpomatic.com/download");
55                 table->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_DIALOG_BORDER);
56         }
57
58         if (test) {
59                 add_label_to_sizer (table, this, _("Test version ") + std_to_wx(test.get()), true, 0, wxALIGN_CENTER_VERTICAL);
60                 auto h = new wxHyperlinkCtrl (this, wxID_ANY, "dcpomatic.com/test-download", "https://dcpomatic.com/test-download");
61                 table->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_DIALOG_BORDER);
62         }
63
64         overall_sizer->Add (table, 0, wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
65
66         auto buttons = CreateButtonSizer (wxOK);
67         if (buttons) {
68                 overall_sizer->Add (buttons, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
69         }
70
71         SetSizerAndFit (overall_sizer);
72 }