Audacity 3.2.0
UpdatePopupDialog.cpp
Go to the documentation of this file.
1/*!********************************************************************
2 Audacity: A Digital Audio Editor
3
4 @file UpdatePopupDialog.cpp
5 @brief Define a dialog for notifying users about new version available.
6
7 Anton Gerasimov
8 **********************************************************************/
9
10#include "UpdatePopupDialog.h"
11#include "UpdateManager.h"
12
13#include "ShuttleGui.h"
14#include "HelpSystem.h"
15
16#include <wx/debug.h>
17#include <wx/sstream.h>
18#include <wx/txtstrm.h>
19#include <wx/display.h>
20
21enum { DontShowID = wxID_HIGHEST + 1 };
22
23BEGIN_EVENT_TABLE (UpdatePopupDialog, wxDialogWrapper)
28
30
31UpdatePopupDialog::UpdatePopupDialog (wxWindow* parent, const VersionPatch& versionPatch, bool configurableNotification)
32 : wxDialogWrapper (parent, -1, XC("Update Audacity", "update dialog"),
33 wxDefaultPosition, wxDefaultSize,
34 wxCAPTION),
35 mVersionPatch(versionPatch)
36{
37 ShuttleGui S (this, eIsCreating);
38 S.SetBorder (5);
39 S.StartVerticalLay (wxEXPAND, 1);
40 {
41 S.AddWindow (AddHtmlContent (S.GetParent()));
42
43 S.StartHorizontalLay (wxEXPAND, 0);
44 {
45 S.SetBorder (5);
46
47 if (configurableNotification)
48 {
49 S.Id(DontShowID).AddCheckBox(
50 XO("Don't show this again at start up"),
52 }
53
54 S.Prop(1).AddSpace(1, 0, 1);
55
56 S.Id (wxID_NO).AddButton (XC ("&Skip", "update dialog"));
57 S.Id (wxID_YES).AddButton (XC("&Install update", "update dialog"));
58
59 S.SetBorder (5);
60 }
61 S.EndHorizontalLay();
62 }
63 S.EndVerticalLay();
64
65 Layout();
66 Fit();
67 Center();
68
69 wxSize sz = GetSize();
70 const auto maxHeight = std::max(1, wxDisplay().GetGeometry().GetHeight() - 100);
71 const auto minHeight = std::min({ sz.y, 600, maxHeight });
72 SetSizeHints(sz.x, minHeight, wxDefaultCoord, maxHeight);
73}
74
76{
77 ;
78}
79
80void UpdatePopupDialog::OnUpdate (wxCommandEvent&)
81{
82 EndModal (wxID_YES);
83}
84
85void UpdatePopupDialog::OnSkip (wxCommandEvent&)
86{
87 EndModal (wxID_NO);
88}
89
90void UpdatePopupDialog::OnDontShow (wxCommandEvent& event)
91{
92 DefaultUpdatesCheckingFlag->Write(!event.IsChecked());
93}
94
96{
97 wxStringOutputStream o;
98 wxTextOutputStream informationStr (o);
99
100#if AUDACITY_BUILD_LEVEL == 0
101 const auto versionPostfix = " Alpha";
102#elif AUDACITY_BUILD_LEVEL == 1
103 const auto versionPostfix = " Beta";
104#else
105 const auto versionPostfix = "";
106#endif
107
108 informationStr
109 << wxT("<html><body><h3>")
110 // i18n-hint Substitution of version number for %s.
111 << XC("Audacity %s is available!", "update dialog")
112 .Format(
113 mVersionPatch.version.GetString() + versionPostfix)
114 .Translation()
115 << wxT("</h3><h5>")
116 << XC("Changelog", "update dialog")
117 << wxT("</h5><p>");
118
119 informationStr << wxT("<ul>");
120 for (auto& logLine : mVersionPatch.changelog)
121 {
122 informationStr << wxT("<li>");
123 // We won't to translate downloaded text.
124 informationStr << logLine;
125 informationStr << wxT("</li>");
126 }
127 informationStr << wxT("</ul></p>");
128
129 informationStr << wxT("<p>");
130 informationStr << wxT("<a href = \"https://github.com/audacity/audacity/releases\">");
131 informationStr << XC("Read more on GitHub", "update dialog");
132 informationStr << wxT("</a>");
133 informationStr << wxT("</p>");
134
135 informationStr << wxT("</body></html>");
136
137 HtmlWindow* html = safenew LinkingHtmlWindow (parent, -1,
138 wxDefaultPosition,
139 wxSize (500, -1),
140 wxHW_SCROLLBAR_AUTO );
141
142 html->SetBorders (20);
143 html->SetPage (o.GetString());
144
145 wxHtmlContainerCell* cell = html->GetInternalRepresentation();
146
147 cell->Layout (500);
148
149 const wxSize size = wxSize (500, cell->GetHeight());
150
151 html->SetMinSize (size);
152 html->SetMaxSize (size);
153 html->SetSize (size);
154
155 return html;
156}
wxT("CloseDown"))
IMPLEMENT_CLASS(AudioSetupToolBar, ToolBar)
END_EVENT_TABLE()
int min(int a, int b)
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
XO("Cut/Copy/Paste")
#define XC(s, c)
Definition: Internat.h:37
#define safenew
Definition: MemoryX.h:10
StickySetting< BoolSetting > DefaultUpdatesCheckingFlag
Definition: Prefs.cpp:63
@ eIsCreating
Definition: ShuttleGui.h:37
#define S(N)
Definition: ToChars.cpp:64
Declare a class that handles managing of updates.
@ DontShowID
Define a dialog for notifying users about new version available.
HtmlWindow Class.
Definition: HtmlWindow.h:37
An HtmlWindow that handles linked clicked - usually the link will go to our own local copy of the man...
Definition: HelpSystem.h:126
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
Show dialog window with update information for the user.
void OnSkip(wxCommandEvent &event)
void OnDontShow(wxCommandEvent &event)
void OnUpdate(wxCommandEvent &event)
HtmlWindow * AddHtmlContent(wxWindow *parent)
const VersionPatch & mVersionPatch
wxString GetString() const
Make string with version by MakeString() from instance values.
Definition: VersionId.cpp:60
A structure that describes patch fields.
Definition: VersionPatch.h:15
VersionId version
Definition: VersionPatch.h:20
wxArrayString changelog
Definition: VersionPatch.h:21