Audacity  2.2.2
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 #include "../Audacity.h"
19 
20 #include <wx/defs.h>
21 #include <wx/filename.h>
22 
23 #include "../ShuttleGui.h"
24 
25 #include "ModulePrefs.h"
26 #include "../Prefs.h"
27 #include "../Internat.h"
28 
30 
31 /* i18n-hint: Modules are optional extensions to Audacity that add NEW features.*/
32 ModulePrefs::ModulePrefs(wxWindow * parent, wxWindowID winid)
33 : PrefsPanel(parent, winid, _("Modules"))
34 {
35  Populate();
36 }
37 
39 {
40 }
41 
43  wxString str;
44  long dummy;
45 
46  // Modules could for example be:
47  // mod-script-pipe
48  // mod-nyq-bench
49  // mod-track-panel
50  // mod-menu-munger
51  // mod-theming
52 
53  // TODO: On an Audacity upgrade we should (?) actually untick modules.
54  // The old modules might be still around, and we do not want to use them.
55  mModules.Clear();
56  mStatuses.clear();
57  mPaths.Clear();
58 
59 
60  // Iterate through all Modules listed in prefs.
61  // Get their names and values.
62  gPrefs->SetPath( wxT("Module/") );
63  bool bCont = gPrefs->GetFirstEntry(str, dummy);
64  while ( bCont ) {
65  int iStatus;
66  gPrefs->Read( str, &iStatus, kModuleDisabled );
67  wxString fname;
68  gPrefs->Read( wxString( wxT("/ModulePath/") ) + str, &fname, wxEmptyString );
69  if( fname != wxEmptyString && wxFileExists( fname ) ){
70  if( iStatus > kModuleNew ){
71  iStatus = kModuleNew;
72  gPrefs->Write( str, iStatus );
73  }
74  //wxLogDebug( wxT("Entry: %s Value: %i"), str, iStatus );
75  mModules.Add( str );
76  mStatuses.push_back( iStatus );
77  mPaths.Add( fname );
78  }
79  bCont = gPrefs->GetNextEntry(str, dummy);
80  }
81  gPrefs->SetPath( wxT("") );
82 }
83 
85 {
87  //------------------------- Main section --------------------
88  // Now construct the GUI itself.
89  // Use 'eIsCreatingFromPrefs' so that the GUI is
90  // initialised with values from gPrefs.
93  // ----------------------- End of main section --------------
94 }
95 
97 {
98  wxArrayString StatusChoices;
99  StatusChoices.Add( _("Disabled" ) );
100  StatusChoices.Add( _("Enabled" ) );
101  StatusChoices.Add( _("Ask" ) );
102  StatusChoices.Add( _("Failed" ) );
103  StatusChoices.Add( _("New" ) );
104 
105  S.SetBorder(2);
106  S.StartScroller();
107 
108  S.StartStatic( {} );
109  {
110  S.AddFixedText(_("These are experimental modules. Enable them only if you've read the Audacity Manual\nand know what you are doing.") );
111  S.AddFixedText(wxString(wxT(" ")) + _("'Ask' means Audacity will ask if you want to load the module each time it starts.") );
112  S.AddFixedText(wxString(wxT(" ")) + _("'Failed' means Audacity thinks the module is broken and won't run it.") );
113  S.AddFixedText(wxString(wxT(" ")) + _("'New' means no choice has been made yet.") );
114  S.AddFixedText(_("Changes to these settings only take effect when Audacity starts up."));
115  {
116  S.StartMultiColumn( 2 );
117  int i;
118  for(i=0;i<(int)mModules.GetCount();i++)
119  S.TieChoice( mModules[i], mStatuses[i], &StatusChoices );
120  S.EndMultiColumn();
121  }
122  if( mModules.GetCount() < 1 )
123  {
124  S.AddFixedText( _("No modules were found") );
125  }
126  }
127  S.EndStatic();
128  S.EndScroller();
129 }
130 
132 {
133  ShuttleGui S(this, eIsSavingToPrefs);
135  int i;
136  for(i=0;i<(int)mPaths.GetCount();i++)
137  SetModuleStatus( mPaths[i], mStatuses[i] );
138  return true;
139 }
140 
141 
142 // static function that tells us about a module.
143 int ModulePrefs::GetModuleStatus(const wxString &fname){
144  // Default status is NEW module, and we will ask once.
145  int iStatus = kModuleNew;
146 
147  wxString ShortName = wxFileName( fname ).GetName();
148  wxString PrefName = wxString( wxT("/Module/") ) + ShortName.Lower();
149 
150  gPrefs->Read( PrefName, &iStatus, kModuleNew );
151  // fix up a bad status.
152  if( iStatus > kModuleNew )
153  iStatus=kModuleNew;
154  return iStatus;
155 }
156 
157 void ModulePrefs::SetModuleStatus(const wxString &fname, int iStatus){
158  wxString ShortName = wxFileName( fname ).GetName();
159  wxString PrefName = wxString( wxT("/Module/") ) + ShortName.Lower();
160  gPrefs->Write( PrefName, iStatus );
161  PrefName = wxString( wxT("/ModulePath/") ) + ShortName.Lower();
162  gPrefs->Write( PrefName, fname );
163  gPrefs->Flush();
164 }
165 
167 {
168  return "Modules_Preferences";
169 }
170 
171 PrefsPanel *ModulePrefsFactory::operator () (wxWindow *parent, wxWindowID winid)
172 {
173  wxASSERT(parent); // to justify safenew
174  return safenew ModulePrefs(parent, winid);
175 }
wxChoice * TieChoice(const wxString &Prompt, WrappedType &WrappedRef, const wxArrayString *pChoices)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
std::vector< int > mStatuses
Definition: ModulePrefs.h:50
void EndMultiColumn()
void EndScroller()
Definition: ShuttleGui.cpp:770
wxArrayString mModules
Definition: ModulePrefs.h:49
wxString HelpPageName() override
#define safenew
Definition: Audacity.h:223
static void SetModuleStatus(const wxString &fname, int iStatus)
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:733
void PopulateOrExchange(ShuttleGui &S)
Definition: ModulePrefs.cpp:96
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:998
void GetAllModuleStatuses()
Definition: ModulePrefs.cpp:42
void AddFixedText(const wxString &Str, bool bCenter=false)
Definition: ShuttleGui.cpp:356
static int GetModuleStatus(const wxString &fname)
ModulePrefs(wxWindow *parent, wxWindowID winid)
Definition: ModulePrefs.cpp:32
bool Commit() override
PrefsPanel * operator()(wxWindow *parent, wxWindowID winid) override
Used within the PrefsDialog, classes derived from this class include AudioIOPrefs, BatchPrefs, DirectoriesPrefs, FileFormatPrefs, GUIPrefs, KeyConfigPrefs, MousePrefs, QualityPrefs, SpectrumPrefs and ThemePrefs.
Definition: PrefsPanel.h:43
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
A PrefsPanel to enable/disable certain modules. 'Modules' are dynamically linked libraries that modif...
Definition: ModulePrefs.h:34
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:701
wxArrayString mPaths
Definition: ModulePrefs.h:51
void Populate()
Definition: ModulePrefs.cpp:84
void SetBorder(int Border)
Definition: ShuttleGui.h:251