Audacity 3.2.0
HelpText.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 HelpText.cpp
6
7 James Crook
8
9********************************************************************//********************************************************************/
14
15
16#include "HelpText.h"
17
18#include <wx/colour.h>
19#include <wx/sstream.h>
20#include <wx/txtstrm.h>
21
22#include "FileNames.h"
23#include "Internat.h"
24#include "AllThemeResources.h"
25#include "Theme.h"
26
27#ifdef HAS_WHATS_NEW
28
29namespace
30{
31const char* WhatsNewURL = "https://audacityteam.org/3.2.0-video";
32}
33
34#endif
35
36wxString HtmlColourOfIndex( int i ){
37 wxColour c = theTheme.Colour(i);
38 return wxString::Format("\"#%02X%02X%02X\"",
39 c.Red(), c.Green(), c.Blue() );
40}
41
42static wxString WrapText( const wxString & Text )
43{
44 return wxString(wxT(""))+
45 wxT("<html><head></head>") +
46 wxT("<body bgcolor=") + HtmlColourOfIndex(clrTrackInfo) + wxT(">") +
47 wxT("<font color=") + HtmlColourOfIndex(clrTrackPanelText) + wxT(">") +
48 wxT("<p>") + Text +
49 wxT("</font>")+
50 wxT("</body></html>");
51}
52
53static wxString InnerLink( const wxString &Key, const wxString& Text )
54{
55 return wxString(wxT("")) +
56 wxT("<a href='innerlink:") +
57 Key +
58 wxT("'>") +
59 Text +
60 wxT("</a>");
61}
62
63static wxString WikiLink( const wxString &Key, const wxString& Text )
64{
65 return wxString(wxT("")) +
66 wxT("<a href='https://www.audacityteam.org/wiki/index.php?title=") +
67 Key +
68 wxT("'>") +
69 Text +
70 wxT("</a>");
71}
72
73static wxString FileLink( const wxString &Key, const wxString& Text )
74{
75 return wxString(wxT("")) +
76 wxT("<a href='") +
77 wxT("file:") +
79 Key +
80 wxT("'>") +
81 Text +
82 wxT("</a>");
83}
84
85static wxString TypedLink( const wxString &Key, const wxString& Text )
86{
87 return wxString(wxT("")) +
88 wxT("<a href='") +
89 Key +
90 wxT("'>") +
91 Text +
92 wxT("</a>");
93}
94
95static wxString LinkExpand( const wxString & Text )
96{
97 wxString Temp = Text;
98 int i,j,k;
99 while( (i=Temp.First( wxT("[[") ))!= wxNOT_FOUND )
100 {
101 wxString Key = Temp.Mid(i+2);
102 j = Key.First( wxT("|") );
103 if( j==wxNOT_FOUND )
104 return Temp;
105 wxString LinkText = Key.Mid( j+1);
106 k = LinkText.First( wxT("]]") );
107 if( k==wxNOT_FOUND )
108 return Temp;
109 Key = Key.Mid( 0, j );
110 LinkText = LinkText.Mid( 0, k );
111
112 LinkText=wxString("<font color=") + HtmlColourOfIndex(clrSample) + wxT(">") +LinkText+"</font>";
113 wxString Replacement;
114 if( Key.StartsWith( wxT("wiki:") ))
115 {
116 Replacement = WikiLink( Key.Mid( 5 ), LinkText );
117 }
118 else if( Key.StartsWith( wxT("file:") ))
119 {
120 Replacement = FileLink( Key.Mid( 5 ), LinkText );
121 }
122 else if( Key.StartsWith( wxT("http:") ))
123 {
124 Replacement = TypedLink( Key, LinkText );
125 }
126 else if( Key.StartsWith( wxT("https:") ))
127 {
128 Replacement = TypedLink( Key, LinkText );
129 }
130 else if( Key.StartsWith( wxT("mailto:") ))
131 {
132 Replacement = TypedLink( Key, LinkText );
133 }
134 else if( Key.StartsWith( wxT("*URL*") ))
135 {
136 Replacement = TypedLink( Key, LinkText );
137 }
138 else
139 {
140 Replacement = InnerLink( Key, LinkText );
141 }
142
143
144 Temp = Temp.Mid( 0, i ) + Replacement + Temp.Mid( i + j + k + 5 );// 5 for the [[|]]
145 }
146 return Temp;
147}
148
149TranslatableString TitleText( const wxString & Key )
150{
151 if(Key==wxT("welcome"))
152 {
153 return XO("Welcome!");
154 }
155
156 if(Key ==wxT("play") )
157 {
158 /* i18n-hint: Title for a topic.*/
159 return XO("Playing Audio");
160 }
161 if((Key ==wxT("record") ) || (Key ==wxT("norecord") ))
162 {
163 /* i18n-hint: Title for a topic.*/
164 return XO("Recording Audio");
165 }
166 if(Key ==wxT("inputdevice") )
167 {
168 /* i18n-hint: Title for a topic.*/
169 return XO("Recording - Choosing the Recording Device");
170 }
171 if(Key ==wxT("inputsource") )
172 {
173 /* i18n-hint: Title for a topic.*/
174 return XO("Recording - Choosing the Recording Source");
175 }
176 if(Key ==wxT("inputlevel") )
177 {
178 /* i18n-hint: Title for a topic.*/
179 return XO("Recording - Setting the Recording Level");
180 }
181 if((Key ==wxT("edit") ) || (Key==wxT("grey")))
182 {
183 /* i18n-hint: Title for a topic.*/
184 return XO("Editing and greyed out Menus");
185 }
186 if(Key ==wxT("export") )
187 {
188 /* i18n-hint: Title for a topic.*/
189 return XO("Exporting an Audio File");
190 }
191 if(Key ==wxT("save") )
192 {
193 /* i18n-hint: Title for a topic.*/
194 return XO("Saving an Audacity Project");
195 }
196 if(Key ==wxT("wma-proprietary") )
197 {
198 /* i18n-hint: Title for a topic.*/
199 return XO("Support for Other Formats");
200 }
201 if(Key ==wxT("burncd") )
202 {
203 /* i18n-hint: Title for a topic.*/
204 return XO("Burn to CD" );
205 }
206 if(Key == wxT("remotehelp") )
207 {
208 return XO("No Local Help");
209 }
210 // Uh oh, no translation...
211 return Verbatim( Key );
212}
213
214static wxString HelpTextBuiltIn( const wxString & Key )
215{
216 // PRL: Is it necessary to define these outside of conditional compilation so that both get into the .pot file?
217 const auto alphamsg = XO(
218"<br><br>The version of Audacity you are using is an <b>Alpha test version</b>.");
219 const auto betamsg = XO(
220"<br><br>The version of Audacity you are using is a <b>Beta test version</b>.");
221
222 if (Key == wxT("welcome"))
223 {
224 wxStringOutputStream o;
225 wxTextOutputStream s(o);
226 s
227#if defined(IS_ALPHA) || defined(IS_BETA)
228 << wxT("<hr><center><h3>")
229 << XO("Get the Official Released Version of Audacity")
230 << wxT("</h3></center>")
231 << VerCheckHtml()
232#ifdef IS_ALPHA
233 << alphamsg
234#else
235 << betamsg
236#endif
237 << wxT(" ")
238 << XO(
239"We strongly recommend that you use our latest stable released version, which has full documentation and support.<br><br>")
240 << XO(
241"You can help us get Audacity ready for release by joining our [[https://www.audacityteam.org/community/|community]].<hr><br><br>")
242#endif
243
244 << wxT("<center><h3>")
245#ifndef HAS_WHATS_NEW
246 << wxT("Audacity ") << AUDACITY_VERSION_STRING
247#else
248 /* i18n-hint: %s is replaced with Audacity version */
249 << XO("What's new in Audacity %s").Format(AUDACITY_VERSION_STRING)
250 << wxT(R"(<p><a href=")") << WhatsNewURL << wxT(R"(">)")
251 << wxT(R"(<img src="memory:whats_new_btn.jpeg" width="263" height="148" /></a></p>)")
252#endif
253 << wxT("</h3><h3>")
254 << XO("How to get help")
255 << wxT("</h3></center>")
256 << XO("These are our support methods:")
257 << wxT("<p><ul><li>")
258 /* i18n-hint: Preserve '[[help:Quick_Help|' as it's the name of a link.*/
259 << XO("[[help:Quick_Help|Quick Help]]")
260 << wxT("</li><li>")
261 << XO(
262/* i18n-hint: Preserve '[[help:Main_Page|' as it's the name of a link.*/
263" [[help:Main_Page|Manual]]")
264 << wxT("</li><li>")
265 << XO("[[https://support.audacityteam.org/|Tutorials & How-tos]]")
266 << wxT("</li><li>")
267 << XO(
268" [[https://forum.audacityteam.org/|Forum]] - ask your question directly, online.")
269 << wxT("</li></ul></p>")
270 ;
271
272 auto result = o.GetString();
273
274 return WrapText( result );
275 }
276 if(Key==wxT("wma-proprietary"))
277 {
278 wxStringOutputStream o;
279 wxTextOutputStream s(o);
280 s
281 << wxT("<p>")
282 << XO(
283"Audacity can import unprotected files in many other formats (such as M4A and WMA, \
284compressed WAV files from portable recorders and audio from video files) if you download and install \
285the optional [[https://manual.audacityteam.org/man/faq_opening_and_saving_files.html#foreign| \
286FFmpeg library]] to your computer.")
287 << wxT("</p><p>")
288 << XO(
289"You can also read our help on importing \
290[[https://manual.audacityteam.org/man/playing_and_recording.html#midi|MIDI files]] \
291and tracks from [[https://manual.audacityteam.org/man/faq_opening_and_saving_files.html#fromcd| \
292audio CDs]].")
293 << wxT("</p>")
294 ;
295 return WrapText( o.GetString() );
296 }
297
298 // Remote help allows us to link to a local copy of the help if it exists,
299 // or provide a message that takes you to the Internet if it does not.
300 // It's used by the menu item Help > Index
301 if(Key == wxT("remotehelp") )
302 {
303 wxStringOutputStream o;
304 wxTextOutputStream s(o);
305 s
306// *URL* will be replaced by whatever URL we are looking for.
307// DA: View the manual on line is expected.
308#ifdef EXPERIMENTAL_DA
309 << XO(
310"The Manual does not appear to be installed. \
311Please [[*URL*|view the Manual online]].<br><br>\
312To always view the Manual online, change \"Location of Manual\" in \
313Interface Preferences to \"From Internet\".")
314#else
315 << XO(
316"The Manual does not appear to be installed. \
317Please [[*URL*|view the Manual online]] or \
318[[https://manual.audacityteam.org/man/unzipping_the_manual.html| \
319download the Manual]].<br><br>\
320To always view the Manual online, change \"Location of Manual\" in \
321Interface Preferences to \"From Internet\".")
322#endif
323 ;
324 return WrapText( o.GetString() );
325 }
326 return {};
327}
328
329wxString HelpText( const wxString & Key )
330{
331
332 // Possible future enhancement...
333 // We could look for the text as a local file and use
334 // that if we find it...
335 // if( wxFileExists( Path+Key ) )
336 // ...
337
338 wxString Text;
339 Text = HelpTextBuiltIn( Key );
340
341 if( !Text.empty())
342 return LinkExpand( Text );
343
344 // Perhaps useful for debugging - we'll return key that we didn't find.
345 return WrapText( Key );
346}
347
348
349wxString FormatHtmlText( const wxString & Text ){
350
351 wxString localeStr = wxLocale::GetSystemEncodingName();
352
353 return
354 wxT("<html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=") +
355 localeStr +
356 wxT("\"></head>") +
357 WrapText( LinkExpand( Text ))+
358 wxT("</html>");
359}
360
361// Function to give the extra arguments to put on the version check string.
362const wxString VerCheckArgs(){
363 wxString result = wxString("from_ver=") + AUDACITY_VERSION_STRING;
364#ifdef REV_LONG
365 result += wxString("&CommitId=")+wxString(REV_LONG).Left(6);
366#endif
367 result += wxString("&Time=") + wxString( __DATE__ ) + wxString( __TIME__ );
368 result.Replace(" ","");
369 return result;
370}
371
372// Text of hyperlink to check versions.
373const wxString VerCheckHtml()
374{
375 wxStringOutputStream o;
376 wxTextOutputStream s(o);
377 s
378 << "<center>[["
379 << VerCheckUrl().GET()
380 << "|"
381 << XO("Check Online")
382 << "]]</center>\n";
383 return o.GetString();
384}
385
386// Url with Version check args attached.
388{
389 //The version we intend to use for live Audacity.
390#define VER_CHECK_URL "https://www.audacityteam.org/download/?"
391//For testing of our scriptlet.
392//#define VER_CHECK_URL "http://www.audacityteam.org/slug/?"
393//For testing locally
394//#define VER_CHECK_URL "http://localhost:63342/WorkingDocs/demos/download.html?"
395
396 return wxString( wxT(VER_CHECK_URL)) +VerCheckArgs();
397}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
TranslatableString TitleText(const wxString &Key)
Definition: HelpText.cpp:149
static wxString TypedLink(const wxString &Key, const wxString &Text)
Definition: HelpText.cpp:85
const wxString VerCheckArgs()
Definition: HelpText.cpp:362
static wxString HelpTextBuiltIn(const wxString &Key)
Definition: HelpText.cpp:214
static wxString WrapText(const wxString &Text)
Definition: HelpText.cpp:42
static wxString LinkExpand(const wxString &Text)
Definition: HelpText.cpp:95
wxString FormatHtmlText(const wxString &Text)
Definition: HelpText.cpp:349
const URLString VerCheckUrl()
Definition: HelpText.cpp:387
const wxString VerCheckHtml()
Definition: HelpText.cpp:373
static wxString WikiLink(const wxString &Key, const wxString &Text)
Definition: HelpText.cpp:63
#define VER_CHECK_URL
static wxString FileLink(const wxString &Key, const wxString &Text)
Definition: HelpText.cpp:73
wxString HelpText(const wxString &Key)
Definition: HelpText.cpp:329
static wxString InnerLink(const wxString &Key, const wxString &Text)
Definition: HelpText.cpp:53
wxString HtmlColourOfIndex(int i)
Definition: HelpText.cpp:36
THEME_API Theme theTheme
Definition: Theme.cpp:82
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
Template generates different TaggedIdentifier classes that don't interconvert implicitly.
Definition: Identifier.h:113
wxColour & Colour(int iIndex)
Holds a msgid for the translation catalog; may also bind format arguments.
FILES_API FilePath HtmlHelpDir()