mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-31 07:59:27 +02:00
ModuleManager does not depend on ModulePrefs, which contains GUI code
This commit is contained in:
parent
f5be1de058
commit
b92f2579b7
@ -182,6 +182,8 @@ list( APPEND SOURCES
|
||||
ModuleConstants.h
|
||||
ModuleManager.cpp
|
||||
ModuleManager.h
|
||||
ModuleSettings.cpp
|
||||
ModuleSettings.h
|
||||
NoteTrack.cpp
|
||||
NoteTrack.h
|
||||
NumberScale.h
|
||||
|
@ -36,7 +36,7 @@ i.e. an alternative to the usual interface, for Audacity.
|
||||
|
||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||
#include "Prefs.h"
|
||||
#include "./prefs/ModulePrefs.h"
|
||||
#include "ModuleSettings.h"
|
||||
#endif
|
||||
|
||||
#include "widgets/MultiDialog.h"
|
||||
@ -256,7 +256,7 @@ void ModuleManager::TryLoadModules(
|
||||
continue;
|
||||
|
||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||
int iModuleStatus = ModulePrefs::GetModuleStatus( file );
|
||||
int iModuleStatus = ModuleSettings::GetModuleStatus( file );
|
||||
if( iModuleStatus == kModuleDisabled )
|
||||
continue;
|
||||
if( iModuleStatus == kModuleFailed )
|
||||
@ -265,7 +265,7 @@ void ModuleManager::TryLoadModules(
|
||||
if( iModuleStatus == kModuleNew ){
|
||||
// To ensure it is noted in config file and so
|
||||
// appears on modules page.
|
||||
ModulePrefs::SetModuleStatus( file, kModuleNew);
|
||||
ModuleSettings::SetModuleStatus( file, kModuleNew);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@ void ModuleManager::TryLoadModules(
|
||||
// If we're not prompting always, accept the answer permanently
|
||||
if( iModuleStatus == kModuleNew ){
|
||||
iModuleStatus = (action==1)?kModuleDisabled : kModuleEnabled;
|
||||
ModulePrefs::SetModuleStatus( file, iModuleStatus );
|
||||
ModuleSettings::SetModuleStatus( file, iModuleStatus );
|
||||
}
|
||||
#endif
|
||||
if(action == 1){ // "No"
|
||||
@ -301,7 +301,7 @@ void ModuleManager::TryLoadModules(
|
||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||
// Before attempting to load, we set the state to bad.
|
||||
// That way, if we crash, we won't try again.
|
||||
ModulePrefs::SetModuleStatus( file, kModuleFailed );
|
||||
ModuleSettings::SetModuleStatus( file, kModuleFailed );
|
||||
#endif
|
||||
|
||||
wxString Error;
|
||||
@ -326,7 +326,7 @@ void ModuleManager::TryLoadModules(
|
||||
|
||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||
// Loaded successfully, restore the status.
|
||||
ModulePrefs::SetModuleStatus(file, iModuleStatus);
|
||||
ModuleSettings::SetModuleStatus(file, iModuleStatus);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -334,7 +334,7 @@ void ModuleManager::TryLoadModules(
|
||||
// Module is not yet decided in this pass.
|
||||
// Maybe it depends on another which has not yet been loaded.
|
||||
// But don't take the kModuleAsk path again in a later pass.
|
||||
ModulePrefs::SetModuleStatus( file, kModuleEnabled );
|
||||
ModuleSettings::SetModuleStatus( file, kModuleEnabled );
|
||||
errors.emplace_back( std::move( umodule ), Error );
|
||||
}
|
||||
}
|
||||
@ -363,7 +363,7 @@ void ModuleManager::Initialize()
|
||||
for ( const auto &pair : errors ) {
|
||||
auto &pModule = pair.first;
|
||||
pModule->ShowLoadFailureError(pair.second);
|
||||
ModulePrefs::SetModuleStatus( pModule->GetName(), kModuleFailed );
|
||||
ModuleSettings::SetModuleStatus( pModule->GetName(), kModuleFailed );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,170 +2,20 @@
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
ModulePrefs.cpp
|
||||
@file ModuleSettings.cpp
|
||||
|
||||
James Crook
|
||||
Paul Licameli split from ModulePrefs.cpp
|
||||
|
||||
*******************************************************************//**
|
||||
**********************************************************************/
|
||||
|
||||
\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 "ModuleSettings.h"
|
||||
|
||||
*//*******************************************************************/
|
||||
#include "Prefs.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)
|
||||
int ModuleSettings::GetModuleStatus(const FilePath &fname)
|
||||
{
|
||||
// Default status is NEW module, and we will ask once.
|
||||
int iStatus = kModuleNew;
|
||||
@ -207,7 +57,7 @@ int ModulePrefs::GetModuleStatus(const FilePath &fname)
|
||||
return iStatus;
|
||||
}
|
||||
|
||||
void ModulePrefs::SetModuleStatus(const FilePath &fname, int iStatus)
|
||||
void ModuleSettings::SetModuleStatus(const FilePath &fname, int iStatus)
|
||||
{
|
||||
wxFileName FileName( fname );
|
||||
wxDateTime DateTime = FileName.GetModificationTime();
|
||||
@ -225,18 +75,3 @@ void ModulePrefs::SetModuleStatus(const FilePath &fname, int iStatus)
|
||||
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
|
||||
|
@ -2,24 +2,16 @@
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
ModulePrefs.h
|
||||
@file ModuleSettings.h
|
||||
|
||||
Brian Gunlogson
|
||||
Joshua Haberman
|
||||
James Crook
|
||||
Paul Licameli split from ModulePrefs.h
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __AUDACITY_MODULE_PREFS__
|
||||
#define __AUDACITY_MODULE_PREFS__
|
||||
#ifndef __AUDACITY_MODULE_SETTINGS__
|
||||
#define __AUDACITY_MODULE_SETTINGS__
|
||||
|
||||
#include <wx/defs.h>
|
||||
|
||||
#include "PrefsPanel.h"
|
||||
|
||||
|
||||
class wxArrayString;
|
||||
class ShuttleGui;
|
||||
#include "audacity/Types.h"
|
||||
|
||||
enum {
|
||||
kModuleDisabled = 0,
|
||||
@ -29,30 +21,11 @@ enum {
|
||||
kModuleNew = 4 // Audacity will ask once, and remember the answer.
|
||||
};
|
||||
|
||||
namespace ModuleSettings {
|
||||
|
||||
#define MODULE_PREFS_PLUGIN_SYMBOL ComponentInterfaceSymbol{ XO("Module") }
|
||||
int GetModuleStatus( const FilePath &fname );
|
||||
void SetModuleStatus( const FilePath &fname, int iStatus );
|
||||
|
||||
class ModulePrefs final : public PrefsPanel
|
||||
{
|
||||
public:
|
||||
ModulePrefs(wxWindow * parent, wxWindowID winid);
|
||||
~ModulePrefs();
|
||||
ComponentInterfaceSymbol GetSymbol() override;
|
||||
TranslatableString GetDescription() override;
|
||||
|
||||
bool Commit() override;
|
||||
wxString HelpPageName() override;
|
||||
void PopulateOrExchange(ShuttleGui & S) override;
|
||||
|
||||
static int GetModuleStatus( const FilePath &fname );
|
||||
static void SetModuleStatus( const FilePath &fname, int iStatus );
|
||||
|
||||
private:
|
||||
void GetAllModuleStatuses();
|
||||
void Populate();
|
||||
wxArrayString mModules;
|
||||
std::vector<int> mStatuses;
|
||||
FilePaths mPaths;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -11,7 +11,7 @@
|
||||
\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.
|
||||
with names like mod-script-pipe that add NEW features.
|
||||
|
||||
*//*******************************************************************/
|
||||
|
||||
@ -26,6 +26,7 @@ with names like mnod-script-pipe that add NEW features.
|
||||
#include "../ShuttleGui.h"
|
||||
|
||||
#include "../Prefs.h"
|
||||
#include "../ModuleSettings.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -159,72 +160,10 @@ bool ModulePrefs::Commit()
|
||||
PopulateOrExchange(S);
|
||||
int i;
|
||||
for(i=0;i<(int)mPaths.size();i++)
|
||||
SetModuleStatus( mPaths[i], mStatuses[i] );
|
||||
ModuleSettings::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",
|
||||
|
@ -21,15 +21,6 @@
|
||||
class wxArrayString;
|
||||
class ShuttleGui;
|
||||
|
||||
enum {
|
||||
kModuleDisabled = 0,
|
||||
kModuleEnabled = 1,
|
||||
kModuleAsk = 2, // Will ask, each time, when audacity starts.
|
||||
kModuleFailed = 3, // Audacity thinks this is a bad module.
|
||||
kModuleNew = 4 // Audacity will ask once, and remember the answer.
|
||||
};
|
||||
|
||||
|
||||
#define MODULE_PREFS_PLUGIN_SYMBOL ComponentInterfaceSymbol{ XO("Module") }
|
||||
|
||||
class ModulePrefs final : public PrefsPanel
|
||||
@ -44,9 +35,6 @@ class ModulePrefs final : public PrefsPanel
|
||||
wxString HelpPageName() override;
|
||||
void PopulateOrExchange(ShuttleGui & S) override;
|
||||
|
||||
static int GetModuleStatus( const FilePath &fname );
|
||||
static void SetModuleStatus( const FilePath &fname, int iStatus );
|
||||
|
||||
private:
|
||||
void GetAllModuleStatuses();
|
||||
void Populate();
|
||||
|
Loading…
x
Reference in New Issue
Block a user