Audacity  3.0.3
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 "widgets/HelpSystem.h"
15 
16 #include <wx/debug.h>
17 #include <wx/sstream.h>
18 #include <wx/txtstrm.h>
19 
20 enum { DontShowID = wxID_HIGHEST + 1 };
21 
22 BEGIN_EVENT_TABLE (UpdatePopupDialog, wxDialogWrapper)
27 
29 
30 UpdatePopupDialog::UpdatePopupDialog (wxWindow* parent, const VersionPatch& versionPatch, bool configurableNotification)
31  : wxDialogWrapper (parent, -1, XC("Update Audacity", "update dialog"),
32  wxDefaultPosition, wxDefaultSize,
33  wxCAPTION),
34  mVersionPatch(versionPatch)
35 {
36  ShuttleGui S (this, eIsCreating);
37  S.SetBorder (5);
38  S.StartVerticalLay (wxEXPAND, 1);
39  {
40  S.AddWindow (AddHtmlContent (S.GetParent()));
41 
42  S.StartHorizontalLay (wxEXPAND, 0);
43  {
44  S.SetBorder (5);
45 
46  if (configurableNotification)
47  {
49  XO("Don't show this again at start up"),
51  }
52 
53  S.Prop(1).AddSpace(1, 0, 1);
54 
55  S.Id (wxID_NO).AddButton (XC ("&Skip", "update dialog"));
56  S.Id (wxID_YES).AddButton (XC("&Install update", "update dialog"));
57 
58  S.SetBorder (5);
59  }
60  S.EndHorizontalLay();
61  }
62  S.EndVerticalLay();
63 
64  Layout();
65  Fit();
66  Center();
67 }
68 
70 {
71  ;
72 }
73 
74 void UpdatePopupDialog::OnUpdate (wxCommandEvent&)
75 {
76  EndModal (wxID_YES);
77 }
78 
79 void UpdatePopupDialog::OnSkip (wxCommandEvent&)
80 {
81  EndModal (wxID_NO);
82 }
83 
84 void UpdatePopupDialog::OnDontShow (wxCommandEvent& event)
85 {
86  DefaultUpdatesCheckingFlag.Write(!event.IsChecked());
87 }
88 
90 {
91  wxStringOutputStream o;
92  wxTextOutputStream informationStr (o);
93 
94  informationStr
95  << wxT("<html><body><h3>")
96  // i18n-hint Substitution of version number for %s.
97  << XC("Audacity %s is available!", "update dialog").Format(mVersionPatch.version.GetString()).Translation()
98  << wxT("</h3><h5>")
99  << XC("Changelog", "update dialog")
100  << wxT("</h5><p>");
101 
102  informationStr << wxT("<ul>");
103  for (auto& logLine : mVersionPatch.changelog)
104  {
105  informationStr << wxT("<li>");
106  // We won't to translate downloaded text.
107  informationStr << logLine;
108  informationStr << wxT("</li>");
109  }
110  informationStr << wxT("</ul></p>");
111 
112  informationStr << wxT("<p>");
113  informationStr << wxT("<a href = \"https://github.com/audacity/audacity/releases\">");
114  informationStr << XC("Read more on GitHub", "update dialog");
115  informationStr << wxT("</a>");
116  informationStr << wxT("</p>");
117 
118  informationStr << wxT("</body></html>");
119 
120  HtmlWindow* html = safenew LinkingHtmlWindow (parent, -1,
121  wxDefaultPosition,
122  wxSize (500, -1),
123  wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER);
124 
125  html->SetBorders (20);
126  html->SetPage (o.GetString());
127 
128  wxHtmlContainerCell* cell = html->GetInternalRepresentation();
129 
130  cell->Layout (500);
131 
132  const wxSize size = wxSize (500, cell->GetHeight());
133 
134  html->SetMinSize (size);
135  html->SetMaxSize (size);
136  html->SetSize (size);
137 
138  return html;
139 }
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
UpdatePopupDialog::OnSkip
void OnSkip(wxCommandEvent &event)
Definition: UpdatePopupDialog.cpp:79
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:38
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
ShuttleGuiBase::AddCheckBox
wxCheckBox * AddCheckBox(const TranslatableString &Prompt, bool Selected)
Definition: ShuttleGui.cpp:309
VersionPatch::version
VersionId version
Definition: VersionPatch.h:20
HelpSystem.h
UpdatePopupDialog::mVersionPatch
const VersionPatch & mVersionPatch
Definition: UpdatePopupDialog.h:37
UpdatePopupDialog::OnUpdate
void OnUpdate(wxCommandEvent &event)
Definition: UpdatePopupDialog.cpp:74
Setting::Write
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:172
UpdateManager.h
Declare a class that handles managing of updates.
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2459
XO
#define XO(s)
Definition: Internat.h:31
XC
#define XC(s, c)
Definition: Internat.h:37
VersionPatch::changelog
wxArrayString changelog
Definition: VersionPatch.h:21
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2274
Setting::Read
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:128
DefaultUpdatesCheckingFlag
BoolSetting DefaultUpdatesCheckingFlag
Definition: Prefs.cpp:65
UpdatePopupDialog::~UpdatePopupDialog
virtual ~UpdatePopupDialog()
Definition: UpdatePopupDialog.cpp:69
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
DontShowID
@ DontShowID
Definition: UpdatePopupDialog.cpp:20
LinkingHtmlWindow
An HtmlWindow that handles linked clicked - usually the link will go to our own local copy of the man...
Definition: HelpSystem.h:126
HtmlWindow
HtmlWindow Class.
Definition: HtmlWindow.h:37
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:496
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:299
UpdatePopupDialog
Show dialog window with update information for the user.
Definition: UpdatePopupDialog.h:22
ShuttleGui.h
ShuttleGui::Prop
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:725
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:360
UpdatePopupDialog.h
Define a dialog for notifying users about new version available.
wxDialogWrapper
Definition: wxPanelWrapper.h:81
UpdatePopupDialog::OnDontShow
void OnDontShow(wxCommandEvent &event)
Definition: UpdatePopupDialog.cpp:84
VersionId::GetString
wxString GetString() const
Make string with version by MakeString() from instance values.
Definition: VersionId.cpp:46
VersionPatch
A structure that describes patch fields.
Definition: VersionPatch.h:15
UpdatePopupDialog::AddHtmlContent
HtmlWindow * AddHtmlContent(wxWindow *parent)
Definition: UpdatePopupDialog.cpp:89
IMPLEMENT_CLASS
IMPLEMENT_CLASS(ControlToolBar, ToolBar)
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
safenew
#define safenew
Definition: MemoryX.h:10
END_EVENT_TABLE
END_EVENT_TABLE()
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631