Audacity  3.0.3
ModulePrefs.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ModulePrefs.cpp
6 
7  James Crook
8 
9 *******************************************************************//*******************************************************************/
17 
18 
19 #include "ModulePrefs.h"
20 
21 
22 
23 #include <wx/defs.h>
24 #include <wx/filename.h>
25 
26 #include "../ShuttleGui.h"
27 
28 #include "Prefs.h"
29 #include "../ModuleSettings.h"
30 
32 
33 ModulePrefs::ModulePrefs(wxWindow * parent, wxWindowID winid)
34 /* i18n-hint: Modules are optional extensions to Audacity that add NEW features.*/
35 : PrefsPanel(parent, winid, XO("Modules"))
36 {
37  Populate();
38 }
39 
41 {
42 }
43 
45 {
47 }
48 
50 {
51  return XO("Preferences for Module");
52 }
53 
55 {
56  return "Modules_Preferences";
57 }
58 
60  wxString str;
61  long dummy;
62 
63  // Modules could for example be:
64  // mod-script-pipe
65  // mod-nyq-bench
66  // mod-menu-munger
67  // mod-theming
68 
69  // TODO: On an Audacity upgrade we should (?) actually untick modules.
70  // The old modules might be still around, and we do not want to use them.
71  mModules.clear();
72  mStatuses.clear();
73  mPaths.clear();
74 
75 
76  // Iterate through all Modules listed in prefs.
77  // Get their names and values.
78  gPrefs->SetPath( wxT("Module/") );
79  bool bCont = gPrefs->GetFirstEntry(str, dummy);
80  while ( bCont ) {
81  int iStatus;
82  gPrefs->Read( str, &iStatus, kModuleDisabled );
83  wxString fname;
84  gPrefs->Read( wxString( wxT("/ModulePath/") ) + str, &fname, wxEmptyString );
85  if( !fname.empty() && wxFileExists( fname ) ){
86  if( iStatus > kModuleNew ){
87  iStatus = kModuleNew;
88  gPrefs->Write( str, iStatus );
89  }
90  //wxLogDebug( wxT("Entry: %s Value: %i"), str, iStatus );
91  mModules.push_back( str );
92  mStatuses.push_back( iStatus );
93  mPaths.push_back( fname );
94  }
95  bCont = gPrefs->GetNextEntry(str, dummy);
96  }
97  gPrefs->SetPath( wxT("") );
98 }
99 
101 {
103  //------------------------- Main section --------------------
104  // Now construct the GUI itself.
105  // Use 'eIsCreatingFromPrefs' so that the GUI is
106  // initialised with values from gPrefs.
109  // ----------------------- End of main section --------------
110 }
111 
113 {
114  S.SetBorder(2);
115  S.StartScroller();
116 
117  S.StartStatic( {} );
118  {
119  S.AddFixedText(XO(
120 "These are experimental modules. Enable them only if you've read the Audacity Manual\nand know what you are doing.") );
121  S.AddFixedText(XO(
122 /* i18n-hint preserve the leading spaces */
123 " 'Ask' means Audacity will ask if you want to load the module each time it starts.") );
124  S.AddFixedText(XO(
125 /* i18n-hint preserve the leading spaces */
126 " 'Failed' means Audacity thinks the module is broken and won't run it.") );
127  S.AddFixedText(XO(
128 /* i18n-hint preserve the leading spaces */
129 " 'New' means no choice has been made yet.") );
130  S.AddFixedText(XO(
131 "Changes to these settings only take effect when Audacity starts up."));
132  {
133  S.StartMultiColumn( 2 );
134  int i;
135  for(i=0;i<(int)mModules.size();i++)
136  S.TieChoice( Verbatim( mModules[i] ),
137  mStatuses[i],
138  {
139  XO("Disabled" ) ,
140  XO("Enabled" ) ,
141  XO("Ask" ) ,
142  XO("Failed" ) ,
143  XO("New" ) ,
144  }
145  );
146  S.EndMultiColumn();
147  }
148  if( mModules.size() < 1 )
149  {
150  S.AddFixedText( XO("No modules were found") );
151  }
152  }
153  S.EndStatic();
154  S.EndScroller();
155 }
156 
158 {
159  ShuttleGui S(this, eIsSavingToPrefs);
161  int i;
162  for(i=0;i<(int)mPaths.size();i++)
164  return true;
165 }
166 
167 #ifdef EXPERIMENTAL_MODULE_PREFS
168 namespace{
170  [](wxWindow *parent, wxWindowID winid, AudacityProject *)
171  {
172  wxASSERT(parent); // to justify safenew
173  return safenew ModulePrefs(parent, winid);
174  },
175  false,
176  // Register with an explicit ordering hint because this one is
177  // only conditionally compiled
178  { "", { Registry::OrderingHint::After, "Mouse" } }
179 };
180 }
181 #endif
FileConfig::SetPath
virtual void SetPath(const wxString &strPath) wxOVERRIDE
Definition: FileConfig.cpp:93
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
MODULE_PREFS_PLUGIN_SYMBOL
#define MODULE_PREFS_PLUGIN_SYMBOL
Definition: ModulePrefs.h:24
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
ModulePrefs::mStatuses
std::vector< int > mStatuses
Definition: ModulePrefs.h:42
ModulePrefs::GetDescription
TranslatableString GetDescription() override
Definition: ModulePrefs.cpp:49
ModulePrefs::ModulePrefs
ModulePrefs(wxWindow *parent, wxWindowID winid)
Definition: ModulePrefs.cpp:33
PrefsPanel::Registration
Definition: PrefsPanel.h:84
XO
#define XO(s)
Definition: Internat.h:31
Registry::OrderingHint::After
@ After
Definition: Registry.h:29
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
ModulePrefs::~ModulePrefs
~ModulePrefs()
Definition: ModulePrefs.cpp:40
FileConfig::GetFirstEntry
virtual bool GetFirstEntry(wxString &str, long &lIndex) const wxOVERRIDE
Definition: FileConfig.cpp:113
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
FileConfig::GetNextEntry
virtual bool GetNextEntry(wxString &str, long &lIndex) const wxOVERRIDE
Definition: FileConfig.cpp:118
ShuttleGuiBase::EndScroller
void EndScroller()
Definition: ShuttleGui.cpp:971
ModulePrefs::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: ModulePrefs.cpp:44
ShuttleGuiBase::StartScroller
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:938
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
anonymous_namespace{Contrast.cpp}::sAttachment
AttachedItem sAttachment
Definition: Contrast.cpp:697
ShuttleGuiBase::AddFixedText
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:440
ModulePrefs
A PrefsPanel to enable/disable certain modules. 'Modules' are dynamically linked libraries that modif...
Definition: ModulePrefs.h:27
ModulePrefs::mModules
wxArrayString mModules
Definition: ModulePrefs.h:41
ModulePrefs.h
ModulePrefs::HelpPageName
ManualPageID HelpPageName() override
If not empty string, the Help button is added below the panel.
Definition: ModulePrefs.cpp:54
kModuleNew
@ kModuleNew
Definition: ModuleSettings.h:21
ModulePrefs::Populate
void Populate()
Definition: ModulePrefs.cpp:100
ModulePrefs::Commit
bool Commit() override
Definition: ModulePrefs.cpp:157
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:893
eIsSavingToPrefs
@ eIsSavingToPrefs
Definition: ShuttleGui.h:48
ModulePrefs::mPaths
FilePaths mPaths
Definition: ModulePrefs.h:43
TaggedIdentifier< ManualPageIDTag >
ModuleSettings::SetModuleStatus
void SetModuleStatus(const FilePath &fname, int iStatus)
Definition: ModuleSettings.cpp:75
ModulePrefs::GetAllModuleStatuses
void GetAllModuleStatuses()
Definition: ModulePrefs.cpp:59
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
Verbatim
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
Definition: TranslatableString.h:321
kModuleDisabled
@ kModuleDisabled
Definition: ModuleSettings.h:17
PrefsPanel
Base class for a panel in the PrefsDialog. Classes derived from this class include BatchPrefs,...
Definition: PrefsPanel.h:51
Prefs.h
ModulePrefs::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: ModulePrefs.cpp:112
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
eIsCreatingFromPrefs
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:47
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:922
safenew
#define safenew
Definition: MemoryX.h:10
ShuttleGuiBase::TieChoice
wxChoice * TieChoice(const TranslatableString &Prompt, TranslatableString &Selected, const TranslatableStrings &choices)
Definition: ShuttleGui.cpp:1727
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631