57#include <wx/filename.h>
58#include <wx/stdpaths.h>
66 L
"/Update/DefaultUpdatesChecking",
true };
86 using Publisher::Publish;
141static void CopyEntry(wxString path, wxConfigBase *src, wxConfigBase *dst, wxString
entry)
143 switch(src->GetEntryType(
entry)) {
144 case wxConfigBase::Type_Unknown:
145 case wxConfigBase::Type_String: {
146 wxString value = src->Read(
entry,
wxT(
""));
147 dst->Write(path +
entry, value);
150 case wxConfigBase::Type_Boolean: {
152 src->Read(
entry, &value, value);
153 dst->Write(path +
entry, value);
156 case wxConfigBase::Type_Integer: {
158 src->Read(
entry, &value, value);
159 dst->Write(path +
entry, value);
162 case wxConfigBase::Type_Float: {
163 double value =
false;
164 src->Read(
entry, &value, value);
165 dst->Write(path +
entry, value);
173static void CopyEntriesRecursive(wxString path, wxConfigBase *src, wxConfigBase *dst)
179 entryKeepGoing = src->GetFirstEntry(entryName, entryIndex);
180 while (entryKeepGoing) {
181 CopyEntry(path, src, dst, entryName);
182 entryKeepGoing = src->GetNextEntry(entryName, entryIndex);
189 groupKeepGoing = src->GetFirstGroup(groupName, groupIndex);
190 while (groupKeepGoing) {
191 wxString subPath = path+groupName+
wxT(
"/");
192 src->SetPath(subPath);
193 CopyEntriesRecursive(subPath, src, dst);
195 groupKeepGoing = src->GetNextGroup(groupName, groupIndex);
204 wxConfigBase::Set(
gPrefs);
213 std::pair<BoolSetting &, bool> stickyBoolSettings[] {
217 for (
auto &pair : stickyBoolSettings)
218 pair.second = pair.first.
Read();
223 for (
auto &pair : stickyBoolSettings)
224 pair.first.Write(pair.second);
230 wxConfigBase::Set(NULL);
256 for (
auto pSetting : mPending)
257 pSetting->Rollback();
268 const bool inserted =
sScopes.back()->mPending.insert(&setting).second;
272 setting.EnterTransaction(
sScopes.size());
278 if ((*it)->mPending.find(&setting) != (*it)->mPending.end())
281 (*it)->mPending.insert(&setting);
285 return inserted ? Added : PreviouslyAdded;
294 for (
auto pSetting : mPending )
295 if ( !pSetting->Commit() )
315 : mInternals(
std::move( internals ) )
318 if (
size != size2 ) {
324 auto iter2 = msgids.begin();
326 emplace_back( *iter1++, *iter2++ );
332 mMsgids = transform_container<TranslatableStrings>( *
this,
340 mInternals = transform_container<wxArrayStringEx>( *
this,
363 if ( !
gPrefs->Read(
mKey, &value, defaultValue) )
371 auto index =
Find( value );
373 value = defaultValue;
392 auto index =
Find( value );
420 wxString defaultString;
421 auto index0 =
FindInt( defaultValue );
423 defaultString =
mSymbols[ index0 ].Internal();
429 wxASSERT( index <
mSymbols.size() );
450 auto index = (long)
FindInt( intValue );
451 if ( index >= (
long)
mSymbols.size() )
453 if ( index >= 0 && index < (
long)
mSymbols.size() ) {
471 return wxT(
"/Warnings/") + internalDialogName;
511 return config && config->DeleteEntry(
GetPath() );
517 if (
Write( !value ) )
@ Internal
Indicates internal failure from Audacity.
Toolkit-neutral facade for basic user interface services.
std::unique_ptr< FileConfig > ugPrefs
BoolSetting DefaultUpdatesCheckingFlag
wxString WarningDialogKey(const wxString &internalDialogName)
void InitPreferences(std::unique_ptr< FileConfig > 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
virtual bool DeleteAll() wxOVERRIDE
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
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
bool Delete()
Delete the key if present, and return true iff it was.
wxConfigBase * GetConfig() const
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
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