Audacity  3.0.3
LibraryPrefs.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  LibraryPrefs.cpp
6 
7  Joshua Haberman
8  Dominic Mazzoni
9  James Crook
10 
11 *******************************************************************//*******************************************************************/
18 
19 
20 #include "LibraryPrefs.h"
21 
22 #include <wx/defs.h>
23 #include <wx/button.h>
24 #include <wx/stattext.h>
25 
26 #include "../FFmpeg.h"
27 #include "../export/ExportMP3.h"
28 #include "../widgets/HelpSystem.h"
29 #include "../widgets/AudacityMessageBox.h"
30 #include "../widgets/ReadOnlyText.h"
31 #include "../widgets/wxTextCtrlWrapper.h"
32 
33 
35 
36 #define ID_MP3_FIND_BUTTON 7001
37 #define ID_MP3_DOWN_BUTTON 7002
38 #define ID_FFMPEG_FIND_BUTTON 7003
39 #define ID_FFMPEG_DOWN_BUTTON 7004
40 
41 BEGIN_EVENT_TABLE(LibraryPrefs, PrefsPanel)
47 
48 LibraryPrefs::LibraryPrefs(wxWindow * parent, wxWindowID winid)
49 /* i18-hint: refers to optional plug-in software libraries */
50 : PrefsPanel(parent, winid, XO("Libraries"))
51 {
52  Populate();
53 }
54 
56 {
57 }
58 
60 {
62 }
63 
65 {
66  return XO("Preferences for Library");
67 }
68 
70 {
71  return "Libraries_Preferences";
72 }
73 
76 {
77  //------------------------- Main section --------------------
78  // Now construct the GUI itself.
79  // Use 'eIsCreatingFromPrefs' so that the GUI is
80  // initialised with values from gPrefs.
83  // ----------------------- End of main section --------------
84 
85  // Set the MP3 Version string.
88 }
89 
96 {
97  S.SetBorder(2);
98  S.StartScroller();
99 
100  S.StartStatic(XO("LAME MP3 Export Library"));
101  {
102  S.StartTwoColumn();
103  {
104  mMP3Version = S
105  .Position(wxALIGN_CENTRE_VERTICAL)
106  .AddReadOnlyText(XO("MP3 Library Version:"), "");
107  }
108  S.EndTwoColumn();
109  }
110  S.EndStatic();
111 
112  S.StartStatic(XO("FFmpeg Import/Export Library"));
113  {
114  S.StartTwoColumn();
115  {
116  auto version =
117 #if defined(USE_FFMPEG)
118  XO("No compatible FFmpeg library was found");
119 #else
120  XO("FFmpeg support is not compiled in");
121 #endif
122 
123  mFFmpegVersion = S
124  .Position(wxALIGN_CENTRE_VERTICAL)
125  .AddReadOnlyText(XO("FFmpeg Library Version:"), version.Translation());
126 
127  S.AddVariableText(XO("FFmpeg Library:"),
128  true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
130  S
131 #if !defined(USE_FFMPEG) || defined(DISABLE_DYNAMIC_LOADING_FFMPEG)
132  .Disable()
133 #endif
134  .AddButton(XXO("Loca&te..."),
135  wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
136  S.AddVariableText(XO("FFmpeg Library:"),
137  true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
139  S
140 #if !defined(USE_FFMPEG) || defined(DISABLE_DYNAMIC_LOADING_FFMPEG)
141  .Disable()
142 #endif
143  .AddButton(XXO("Dow&nload"),
144  wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
145  }
146  S.EndTwoColumn();
147  }
148  S.EndStatic();
149  S.EndScroller();
150 
151 }
152 
156 {
157  mMP3Version->SetValue(GetMP3Version(this, prompt));
158 }
159 
162 void LibraryPrefs::OnMP3FindButton(wxCommandEvent & WXUNUSED(event))
163 {
164  SetMP3VersionText(true);
165 }
166 
168 void LibraryPrefs::OnMP3DownButton(wxCommandEvent & WXUNUSED(event))
169 {
170  // Modal help dialogue required here
171  HelpSystem::ShowHelp(this, L"FAQ:Installing_the_LAME_MP3_Encoder", true);
172 }
173 
175 {
177 }
178 
179 void LibraryPrefs::OnFFmpegFindButton(wxCommandEvent & WXUNUSED(event))
180 {
181 #ifdef USE_FFMPEG
183  bool showerrs =
184 #if defined(_DEBUG)
185  true;
186 #else
187  false;
188 #endif
189 
190  FFmpegLibsPtr->FreeLibs();
191  // Load the libs ('true' means that all errors will be shown)
192  bool locate = !LoadFFmpeg(showerrs);
193 
194  // Libs are fine, don't show "locate" dialog unless user really wants it
195  if (!locate) {
196  int response = AudacityMessageBox(
197  XO(
198 "Audacity has automatically detected valid FFmpeg libraries.\nDo you still want to locate them manually?"),
199  XO("Success"),
200  wxCENTRE | wxYES_NO | wxNO_DEFAULT |wxICON_QUESTION);
201  if (response == wxYES) {
202  locate = true;
203  }
204  }
205 
206  if (locate) {
207  // Show "Locate FFmpeg" dialog
208  FFmpegLibsPtr->FindLibs(this);
209  FFmpegLibsPtr->FreeLibs();
210  LoadFFmpeg(showerrs);
211  }
213 
214  DropFFmpegLibs();
215 #endif
216 }
217 
218 void LibraryPrefs::OnFFmpegDownButton(wxCommandEvent & WXUNUSED(event))
219 {
220  HelpSystem::ShowHelp(this, L"FAQ:Installing_the_FFmpeg_Import_Export_Library", true);
221 }
222 
224 {
225  ShuttleGui S(this, eIsSavingToPrefs);
227 
228  return true;
229 }
230 
231 #if !defined(DISABLE_DYNAMIC_LOADING_FFMPEG) || !defined(DISABLE_DYNAMIC_LOADING_LAME)
232 namespace{
234  [](wxWindow *parent, wxWindowID winid, AudacityProject *)
235  {
236  wxASSERT(parent); // to justify safenew
237  return safenew LibraryPrefs(parent, winid);
238  },
239  false,
240  // Register with an explicit ordering hint because this one is
241  // only conditionally compiled
242  { "", { Registry::OrderingHint::Before, "Directories" } }
243 };
244 }
245 #endif
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption=XO("Message"), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: AudacityMessageBox.h:20
LibraryPrefs::GetDescription
TranslatableString GetDescription() override
Definition: LibraryPrefs.cpp:64
LibraryPrefs::SetFFmpegVersionText
void SetFFmpegVersionText()
Definition: LibraryPrefs.cpp:174
LibraryPrefs::Commit
bool Commit() override
Definition: LibraryPrefs.cpp:223
ID_MP3_DOWN_BUTTON
#define ID_MP3_DOWN_BUTTON
Definition: LibraryPrefs.cpp:37
ID_MP3_FIND_BUTTON
#define ID_MP3_FIND_BUTTON
Definition: LibraryPrefs.cpp:36
ReadOnlyText::SetValue
void SetValue(const wxString &value)
Definition: ReadOnlyText.h:125
ID_FFMPEG_DOWN_BUTTON
#define ID_FFMPEG_DOWN_BUTTON
Definition: LibraryPrefs.cpp:39
GetMP3Version
TranslatableString GetMP3Version(wxWindow *parent, bool prompt)
Definition: ExportMP3.cpp:2232
PrefsPanel::Registration
Definition: PrefsPanel.h:84
XO
#define XO(s)
Definition: Internat.h:31
LibraryPrefs::OnMP3DownButton
void OnMP3DownButton(wxCommandEvent &e)
Opens help on downloading a suitable MP3 library is.
Definition: LibraryPrefs.cpp:168
PickFFmpegLibs
FFmpegLibs * PickFFmpegLibs()
Definition: FFmpeg.cpp:51
anonymous_namespace{LibraryPrefs.cpp}::sAttachment
PrefsPanel::Registration sAttachment
Definition: LibraryPrefs.cpp:233
HelpSystem::ShowHelp
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:237
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
FFmpegLibs
Class used to dynamically load FFmpeg libraries.
Definition: FFmpeg.h:207
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2274
LoadFFmpeg
bool LoadFFmpeg(bool showerror)
Definition: FFmpeg.cpp:71
ShuttleGuiBase::EndScroller
void EndScroller()
Definition: ShuttleGui.cpp:971
XXO
#define XXO(s)
Definition: Internat.h:44
ShuttleGuiBase::StartScroller
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:938
LibraryPrefs::OnFFmpegFindButton
void OnFFmpegFindButton(wxCommandEvent &e)
Definition: LibraryPrefs.cpp:179
LibraryPrefs::OnMP3FindButton
void OnMP3FindButton(wxCommandEvent &e)
Definition: LibraryPrefs.cpp:162
ShuttleGui::Disable
ShuttleGui & Disable(bool disabled=true)
Definition: ShuttleGui.h:650
LibraryPrefs::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: LibraryPrefs.cpp:95
GetFFmpegVersion
TranslatableString GetFFmpegVersion()
Definition: FFmpeg.cpp:113
LIBRARY_PREFS_PLUGIN_SYMBOL
#define LIBRARY_PREFS_PLUGIN_SYMBOL
Definition: LibraryPrefs.h:25
ID_FFMPEG_FIND_BUTTON
#define ID_FFMPEG_FIND_BUTTON
Definition: LibraryPrefs.cpp:38
ShuttleGuiBase::StartTwoColumn
void StartTwoColumn()
Definition: ShuttleGui.h:366
Registry::OrderingHint::Before
@ Before
Definition: Registry.h:29
ShuttleGuiBase::AddReadOnlyText
ReadOnlyText * AddReadOnlyText(const TranslatableString &Caption, const wxString &Value)
Definition: ShuttleGui.cpp:496
LibraryPrefs.h
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:360
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:893
eIsSavingToPrefs
@ eIsSavingToPrefs
Definition: ShuttleGui.h:48
LibraryPrefs::OnFFmpegDownButton
void OnFFmpegDownButton(wxCommandEvent &e)
Definition: LibraryPrefs.cpp:218
ShuttleGui::Position
ShuttleGui & Position(int flags)
Definition: ShuttleGui.h:712
TaggedIdentifier< ManualPageIDTag >
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:113
LibraryPrefs::mFFmpegVersion
ReadOnlyText * mFFmpegVersion
Definition: LibraryPrefs.h:50
DropFFmpegLibs
void DropFFmpegLibs()
Definition: FFmpeg.cpp:61
LibraryPrefs
A PrefsPanel used to select manage external libraries like the MP3 and FFmpeg encoding libraries.
Definition: LibraryPrefs.h:28
LibraryPrefs::HelpPageName
ManualPageID HelpPageName() override
If not empty string, the Help button is added below the panel.
Definition: LibraryPrefs.cpp:69
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
ShuttleGuiBase::EndTwoColumn
void EndTwoColumn()
Definition: ShuttleGui.h:367
eIsCreatingFromPrefs
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:47
ShuttleGuiBase::AddVariableText
wxStaticText * AddVariableText(const TranslatableString &Str, bool bCenter=false, int PositionFlags=0, int wrapWidth=0)
Definition: ShuttleGui.cpp:463
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:922
safenew
#define safenew
Definition: MemoryX.h:10
LibraryPrefs::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: LibraryPrefs.cpp:59
END_EVENT_TABLE
END_EVENT_TABLE()
LibraryPrefs::mMP3Version
ReadOnlyText * mMP3Version
Definition: LibraryPrefs.h:49
FFmpegLibsPtr
std::unique_ptr< FFmpegLibs > FFmpegLibsPtr
Definition: FFmpeg.cpp:45
LibraryPrefs::Populate
void Populate()
Creates the dialog and its contents.
Definition: LibraryPrefs.cpp:75
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
LibraryPrefs::~LibraryPrefs
~LibraryPrefs()
Definition: LibraryPrefs.cpp:55
LibraryPrefs::SetMP3VersionText
void SetMP3VersionText(bool prompt=false)
Definition: LibraryPrefs.cpp:155