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)
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 
47  XO ("Don't show this again at start up"),
49 
50  S.Prop(1).AddSpace(1, 0, 1);
51 
52  S.Id (wxID_NO).AddButton (XC ("&Skip", "update dialog"));
53  S.Id (wxID_YES).AddButton (XC("&Install update", "update dialog"));
54 
55  S.SetBorder (5);
56  }
57  S.EndHorizontalLay();
58  }
59  S.EndVerticalLay();
60 
61  Layout();
62  Fit();
63  Center();
64 }
65 
67 {
68  ;
69 }
70 
71 void UpdatePopupDialog::OnUpdate (wxCommandEvent&)
72 {
73  EndModal (wxID_YES);
74 }
75 
76 void UpdatePopupDialog::OnSkip (wxCommandEvent&)
77 {
78  EndModal (wxID_NO);
79 }
80 
81 void UpdatePopupDialog::OnDontShow (wxCommandEvent& event)
82 {
83  DefaultUpdatesCheckingFlag.Write(!event.IsChecked());
84 }
85 
87 {
88  wxStringOutputStream o;
89  wxTextOutputStream informationStr (o);
90 
91  informationStr
92  << wxT("<html><body><h3>")
93  // i18n-hint Substitution of version number for %s.
94  << XC("Audacity %s is available!", "update dialog").Format(mVersionPatch.version.GetString()).Translation()
95  << wxT("</h3><h5>")
96  << XC("Changelog", "update dialog")
97  << wxT("</h5><p>");
98 
99  informationStr << wxT("<ul>");
100  for (auto& logLine : mVersionPatch.changelog)
101  {
102  informationStr << wxT("<li>");
103  // We won't to translate downloaded text.
104  informationStr << logLine;
105  informationStr << wxT("</li>");
106  }
107  informationStr << wxT("</ul></p>");
108 
109  informationStr << wxT("<p>");
110  informationStr << wxT("<a href = \"https://github.com/audacity/audacity/releases\">");
111  informationStr << XC("Read more on GitHub", "update dialog");
112  informationStr << wxT("</a>");
113  informationStr << wxT("</p>");
114 
115  informationStr << wxT("</body></html>");
116 
117  HtmlWindow* html = safenew LinkingHtmlWindow (parent, -1,
118  wxDefaultPosition,
119  wxSize (500, -1),
120  wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER);
121 
122  html->SetBorders (20);
123  html->SetPage (o.GetString());
124 
125  wxHtmlContainerCell* cell = html->GetInternalRepresentation();
126 
127  cell->Layout (500);
128 
129  const wxSize size = wxSize (500, cell->GetHeight());
130 
131  html->SetMinSize (size);
132  html->SetMaxSize (size);
133  html->SetSize (size);
134 
135  return html;
136 }
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
UpdatePopupDialog::OnSkip
void OnSkip(wxCommandEvent &event)
Definition: UpdatePopupDialog.cpp:76
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:71
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:2447
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:66
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:81
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:86
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