55#include <wx/filename.h>
56#include <wx/stdpaths.h>
64 L
"/Update/DefaultUpdatesChecking",
true };
66std::unique_ptr<audacity::BasicSettings>
ugPrefs {};
88 using Publisher::Publish;
143static void CopyEntry(wxString path, wxConfigBase *src, wxConfigBase *dst, wxString
entry)
145 switch(src->GetEntryType(
entry)) {
146 case wxConfigBase::Type_Unknown:
147 case wxConfigBase::Type_String: {
148 wxString value = src->Read(
entry,
wxT(
""));
149 dst->Write(path +
entry, value);
152 case wxConfigBase::Type_Boolean: {
154 src->Read(
entry, &value, value);
155 dst->Write(path +
entry, value);
158 case wxConfigBase::Type_Integer: {
160 src->Read(
entry, &value, value);
161 dst->Write(path +
entry, value);
164 case wxConfigBase::Type_Float: {
165 double value =
false;
166 src->Read(
entry, &value, value);
167 dst->Write(path +
entry, value);
175static void CopyEntriesRecursive(wxString path, wxConfigBase *src, wxConfigBase *dst)
181 entryKeepGoing = src->GetFirstEntry(entryName, entryIndex);
182 while (entryKeepGoing) {
183 CopyEntry(path, src, dst, entryName);
184 entryKeepGoing = src->GetNextEntry(entryName, entryIndex);
191 groupKeepGoing = src->GetFirstGroup(groupName, groupIndex);
192 while (groupKeepGoing) {
193 wxString subPath = path+groupName+
wxT(
"/");
194 src->SetPath(subPath);
195 CopyEntriesRecursive(subPath, src, dst);
197 groupKeepGoing = src->GetNextGroup(groupName, groupIndex);
229 std::pair<BoolSetting &, bool> stickyBoolSettings[] {
233 for (
auto &pair : stickyBoolSettings)
234 pair.second = pair.first.
Read();
239 for (
auto &pair : stickyBoolSettings)
240 pair.first.Write(pair.second);
271 for (
auto pSetting : mPending)
272 pSetting->Rollback();
283 const bool inserted =
sScopes.back()->mPending.insert(&setting).second;
287 setting.EnterTransaction(
sScopes.size());
293 if ((*it)->mPending.find(&setting) != (*it)->mPending.end())
296 (*it)->mPending.insert(&setting);
300 return inserted ? Added : PreviouslyAdded;
309 for (
auto pSetting : mPending )
310 if ( !pSetting->Commit() )
330 : mInternals(
std::move( internals ) )
333 if (
size != size2 ) {
339 auto iter2 = msgids.begin();
341 emplace_back( *iter1++, *iter2++ );
347 mMsgids = transform_container<TranslatableStrings>( *
this,
355 mInternals = transform_container<wxArrayStringEx>( *
this,
386 auto index =
Find( value );
388 value = defaultValue;
407 auto index =
Find( value );
435 wxString defaultString;
436 auto index0 =
FindInt( defaultValue );
438 defaultString =
mSymbols[ index0 ].Internal();
444 wxASSERT( index <
mSymbols.size() );
465 auto index = (long)
FindInt( intValue );
466 if ( index >= (
long)
mSymbols.size() )
468 if ( index >= 0 && index < (
long)
mSymbols.size() ) {
486 return wxT(
"/Warnings/") + internalDialogName;
526 return config && config->DeleteEntry(
GetPath() );
532 if (
Write( !value ) )
@ Internal
Indicates internal failure from Audacity.
Toolkit-neutral facade for basic user interface services.
static ProjectFileIORegistry::AttributeWriterEntry entry
void SetPreferencesVersion(int vMajor, int vMinor, int vMicro)
audacity::BasicSettings * gPrefs
void GetPreferencesVersion(int &vMajor, int &vMinor, int &vMicro)
BoolSetting DefaultUpdatesCheckingFlag
std::unique_ptr< audacity::BasicSettings > ugPrefs
wxString WarningDialogKey(const wxString &internalDialogName)
void InitPreferences(std::unique_ptr< audacity::BasicSettings > uPrefs)
void ResetPreferences()
Call this to reset preferences to an (almost)-"new" default state.
std::vector< TranslatableString > TranslatableStrings
This specialization of Setting for bool adds a Toggle method to negate the saved value.
bool Toggle()
Write the negation of the previous value, and then return the current value.
bool Write(const wxString &value)
const EnumValueSymbols mSymbols
const EnumValueSymbols & GetSymbols() const
void SetDefault(long value)
size_t Find(const wxString &value) const
TransactionalSettingBase *const mpOtherSettings
wxString ReadWithDefault(const wxString &) const
virtual void Migrate(wxString &)
const EnumValueSymbol & Default() const
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
const wxString & Internal() const
const TranslatableString & Msgid() const
std::vector< int > mIntValues
void Migrate(wxString &) override
size_t FindInt(int code) const
int ReadIntWithDefault(int defaultValue) const
const wxArrayStringEx & GetInternals() const
EnumValueSymbols()=default
wxArrayStringEx mInternals
TranslatableStrings mMsgids
const TranslatableStrings & GetMsgids() const
An object that sends messages to an open-ended list of subscribed callbacks.
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
CallbackReturn Publish(const Message &message)
Send a message to connected callbacks.
A move-only handle representing a connection to a Publisher.
A listener notified of changes in preferences.
static void Broadcast(int id=0)
Call this static function to notify all PrefsListener objects.
std::unique_ptr< Impl > mpImpl
virtual void UpdateSelectedPrefs(int id)
virtual void UpdatePrefs()=0
audacity::BasicSettings * GetConfig() const
bool Delete()
Delete the key if present, and return true iff it was.
const SettingPath & GetPath() const
bool Write(const bool &value)
Write value to config and return true if successful.
bool Read() const
overload of Read, always returning a value
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
static AddResult Add(TransactionalSettingBase &setting)
virtual void Invalidate()=0
Base class for objects that provide facility to store data persistently, and access it with string ke...
virtual bool Flush() noexcept=0
virtual void Clear()=0
Remove all groups and keys.
virtual bool Write(const wxString &key, bool value)=0
virtual bool Read(const wxString &key, bool *value) const =0
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
std::vector< SettingScope * > sScopes
std::set< PreferenceInitializer * > PreferenceInitializers
PreferenceInitializers & allInitializers()
virtual ~PreferenceInitializer()
static void ReinitializeAll()
Impl(PrefsListener &owner)
Observer::Subscription mSubscription