forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModulePrefs.cpp
More file actions
242 lines (200 loc) · 6.69 KB
/
Copy pathModulePrefs.cpp
File metadata and controls
242 lines (200 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/**********************************************************************
Audacity: A Digital Audio Editor
ModulePrefs.cpp
James Crook
*******************************************************************//**
\class ModulePrefs
\brief A PrefsPanel to enable/disable certain modules. 'Modules' are
dynamically linked libraries that modify Audacity. They are plug-ins
with names like mnod-script-pipe that add NEW features.
*//*******************************************************************/
#include "../Audacity.h"
#include "ModulePrefs.h"
#include <wx/defs.h>
#include <wx/filename.h>
#include "../ShuttleGui.h"
#include "../Prefs.h"
////////////////////////////////////////////////////////////////////////////////
ModulePrefs::ModulePrefs(wxWindow * parent, wxWindowID winid)
/* i18n-hint: Modules are optional extensions to Audacity that add NEW features.*/
: PrefsPanel(parent, winid, XO("Modules"))
{
Populate();
}
ModulePrefs::~ModulePrefs()
{
}
ComponentInterfaceSymbol ModulePrefs::GetSymbol()
{
return MODULE_PREFS_PLUGIN_SYMBOL;
}
TranslatableString ModulePrefs::GetDescription()
{
return XO("Preferences for Module");
}
wxString ModulePrefs::HelpPageName()
{
return "Modules_Preferences";
}
void ModulePrefs::GetAllModuleStatuses(){
wxString str;
long dummy;
// Modules could for example be:
// mod-script-pipe
// mod-nyq-bench
// mod-menu-munger
// mod-theming
// TODO: On an Audacity upgrade we should (?) actually untick modules.
// The old modules might be still around, and we do not want to use them.
mModules.clear();
mStatuses.clear();
mPaths.clear();
// Iterate through all Modules listed in prefs.
// Get their names and values.
gPrefs->SetPath( wxT("Module/") );
bool bCont = gPrefs->GetFirstEntry(str, dummy);
while ( bCont ) {
int iStatus;
gPrefs->Read( str, &iStatus, kModuleDisabled );
wxString fname;
gPrefs->Read( wxString( wxT("/ModulePath/") ) + str, &fname, wxEmptyString );
if( !fname.empty() && wxFileExists( fname ) ){
if( iStatus > kModuleNew ){
iStatus = kModuleNew;
gPrefs->Write( str, iStatus );
}
//wxLogDebug( wxT("Entry: %s Value: %i"), str, iStatus );
mModules.push_back( str );
mStatuses.push_back( iStatus );
mPaths.push_back( fname );
}
bCont = gPrefs->GetNextEntry(str, dummy);
}
gPrefs->SetPath( wxT("") );
}
void ModulePrefs::Populate()
{
GetAllModuleStatuses();
//------------------------- Main section --------------------
// Now construct the GUI itself.
// Use 'eIsCreatingFromPrefs' so that the GUI is
// initialised with values from gPrefs.
ShuttleGui S(this, eIsCreatingFromPrefs);
PopulateOrExchange(S);
// ----------------------- End of main section --------------
}
void ModulePrefs::PopulateOrExchange(ShuttleGui & S)
{
S.SetBorder(2);
S.StartScroller();
S.StartStatic( {} );
{
S.AddFixedText(XO(
"These are experimental modules. Enable them only if you've read the Audacity Manual\nand know what you are doing.") );
S.AddFixedText(XO(
/* i18n-hint preserve the leading spaces */
" 'Ask' means Audacity will ask if you want to load the module each time it starts.") );
S.AddFixedText(XO(
/* i18n-hint preserve the leading spaces */
" 'Failed' means Audacity thinks the module is broken and won't run it.") );
S.AddFixedText(XO(
/* i18n-hint preserve the leading spaces */
" 'New' means no choice has been made yet.") );
S.AddFixedText(XO(
"Changes to these settings only take effect when Audacity starts up."));
{
S.StartMultiColumn( 2 );
int i;
for(i=0;i<(int)mModules.size();i++)
S.TieChoice( Verbatim( mModules[i] ),
mStatuses[i],
{
XO("Disabled" ) ,
XO("Enabled" ) ,
XO("Ask" ) ,
XO("Failed" ) ,
XO("New" ) ,
}
);
S.EndMultiColumn();
}
if( mModules.size() < 1 )
{
S.AddFixedText( XO("No modules were found") );
}
}
S.EndStatic();
S.EndScroller();
}
bool ModulePrefs::Commit()
{
ShuttleGui S(this, eIsSavingToPrefs);
PopulateOrExchange(S);
int i;
for(i=0;i<(int)mPaths.size();i++)
SetModuleStatus( mPaths[i], mStatuses[i] );
return true;
}
// static function that tells us about a module.
int ModulePrefs::GetModuleStatus(const FilePath &fname)
{
// Default status is NEW module, and we will ask once.
int iStatus = kModuleNew;
wxFileName FileName( fname );
wxString ShortName = FileName.GetName().Lower();
wxString PathPref = wxString( wxT("/ModulePath/") ) + ShortName;
wxString StatusPref = wxString( wxT("/Module/") ) + ShortName;
wxString DateTimePref = wxString( wxT("/ModuleDateTime/") ) + ShortName;
wxString ModulePath = gPrefs->Read( PathPref, wxEmptyString );
if( ModulePath.IsSameAs( fname ) )
{
gPrefs->Read( StatusPref, &iStatus, kModuleNew );
wxDateTime DateTime = FileName.GetModificationTime();
wxDateTime OldDateTime;
OldDateTime.ParseISOCombined( gPrefs->Read( DateTimePref, wxEmptyString ) );
// Some platforms return milliseconds, some do not...level the playing field
DateTime.SetMillisecond( 0 );
OldDateTime.SetMillisecond( 0 );
// fix up a bad status or reset for newer module
if( iStatus > kModuleNew || !OldDateTime.IsEqualTo( DateTime ) )
{
iStatus=kModuleNew;
}
}
else
{
// Remove previously saved since it's no longer valid
gPrefs->DeleteEntry( PathPref );
gPrefs->DeleteEntry( StatusPref );
gPrefs->DeleteEntry( DateTimePref );
}
return iStatus;
}
void ModulePrefs::SetModuleStatus(const FilePath &fname, int iStatus)
{
wxFileName FileName( fname );
wxDateTime DateTime = FileName.GetModificationTime();
wxString ShortName = FileName.GetName().Lower();
wxString PrefName = wxString( wxT("/Module/") ) + ShortName;
gPrefs->Write( PrefName, iStatus );
PrefName = wxString( wxT("/ModulePath/") ) + ShortName;
gPrefs->Write( PrefName, fname );
PrefName = wxString( wxT("/ModuleDateTime/") ) + ShortName;
gPrefs->Write( PrefName, DateTime.FormatISOCombined() );
gPrefs->Flush();
}
#ifdef EXPERIMENTAL_MODULE_PREFS
namespace{
PrefsPanel::Registration sAttachment{ "Module",
[](wxWindow *parent, wxWindowID winid, AudacityProject *)
{
wxASSERT(parent); // to justify safenew
return safenew ModulePrefs(parent, winid);
},
false,
// Register with an explicit ordering hint because this one is
// only conditionally compiled
{ "", { Registry::OrderingHint::After, "Mouse" } }
};
}
#endif