55#include <wx/filename.h>
56#include <wx/stdpaths.h>
64 L
"/Update/DefaultUpdatesChecking",
true };
66std::unique_ptr<audacity::BasicSettings>
ugPrefs {};
88 std::vector<std::unique_ptr<PreferencesResetHandler>>
mHandlers;
98 mHandlers.push_back(std::move(
handler));
104 handler->OnSettingResetBegin();
117 using Publisher::Publish;
172static void CopyEntry(wxString path, wxConfigBase *src, wxConfigBase *dst, wxString
entry)
174 switch(src->GetEntryType(
entry)) {
175 case wxConfigBase::Type_Unknown:
176 case wxConfigBase::Type_String: {
177 wxString value = src->Read(
entry,
wxT(
""));
178 dst->Write(path +
entry, value);
181 case wxConfigBase::Type_Boolean: {
183 src->Read(
entry, &value, value);
184 dst->Write(path +
entry, value);
187 case wxConfigBase::Type_Integer: {
189 src->Read(
entry, &value, value);
190 dst->Write(path +
entry, value);
193 case wxConfigBase::Type_Float: {
194 double value =
false;
195 src->Read(
entry, &value, value);
196 dst->Write(path +
entry, value);
204static void CopyEntriesRecursive(wxString path, wxConfigBase *src, wxConfigBase *dst)
210 entryKeepGoing = src->GetFirstEntry(entryName, entryIndex);
211 while (entryKeepGoing) {
212 CopyEntry(path, src, dst, entryName);
213 entryKeepGoing = src->GetNextEntry(entryName, entryIndex);
220 groupKeepGoing = src->GetFirstGroup(groupName, groupIndex);
221 while (groupKeepGoing) {
222 wxString subPath = path+groupName+
wxT(
"/");
223 src->SetPath(subPath);
224 CopyEntriesRecursive(subPath, src, dst);
226 groupKeepGoing = src->GetNextGroup(groupName, groupIndex);
290 for (
auto pSetting : mPending)
291 pSetting->Rollback();
302 const bool inserted =
sScopes.back()->mPending.insert(&setting).second;
306 setting.EnterTransaction(
sScopes.size());
312 if ((*it)->mPending.find(&setting) != (*it)->mPending.end())
315 (*it)->mPending.insert(&setting);
319 return inserted ? Added : PreviouslyAdded;
328 for (
auto pSetting : mPending )
329 if ( !pSetting->Commit() )
349 : mInternals(
std::move( internals ) )
352 if (
size != size2 ) {
358 auto iter2 = msgids.begin();
360 emplace_back( *iter1++, *iter2++ );
366 mMsgids = transform_container<TranslatableStrings>( *
this,
374 mInternals = transform_container<wxArrayStringEx>( *
this,
405 auto index =
Find( value );
407 value = defaultValue;
426 auto index =
Find( value );
454 wxString defaultString;
455 auto index0 =
FindInt( defaultValue );
457 defaultString =
mSymbols[ index0 ].Internal();
463 wxASSERT( index <
mSymbols.size() );
484 auto index = (long)
FindInt( intValue );
485 if ( index >= (
long)
mSymbols.size() )
487 if ( index >= 0 && index < (
long)
mSymbols.size() ) {
512 return wxT(
"/Warnings/") + internalDialogName;
552 return config && config->DeleteEntry(
GetPath() );
558 return Write( !value );
@ Internal
Indicates internal failure from Audacity.
Toolkit-neutral facade for basic user interface services.
static ProjectFileIORegistry::AttributeWriterEntry entry
StickySetting< BoolSetting > DefaultUpdatesCheckingFlag
void SetPreferencesVersion(int vMajor, int vMinor, int vMicro)
audacity::BasicSettings * gPrefs
void GetPreferencesVersion(int &vMajor, int &vMinor, int &vMicro)
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
bool Toggle()
Write the negation of the previous value, and return true if successful.
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.
virtual ~PreferencesResetHandler()
static void Register(std::unique_ptr< PreferencesResetHandler > handler)
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
static AddResult Add(TransactionalSettingBase &setting)
virtual void Invalidate()=0
void Register(std::unique_ptr< PreferencesResetHandler > handler)
static PreferencesResetHandlerRegistry & Get()
std::vector< std::unique_ptr< PreferencesResetHandler > > mHandlers
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.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
std::vector< SettingScope * > sScopes
std::set< PreferenceInitializer * > PreferenceInitializers
PreferenceInitializers & allInitializers()
AuthorizationHandler handler
const char * end(const char *str) noexcept
virtual ~PreferenceInitializer()
static void ReinitializeAll()
Impl(PrefsListener &owner)
Observer::Subscription mSubscription