[dasher: 14/61] Generalised pre set notifications for parameters and reworked alphabet history.
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 14/61] Generalised pre set notifications for parameters and reworked alphabet history.
- Date: Thu, 28 Dec 2017 10:03:46 +0000 (UTC)
commit 7275e3d78d10e7ff241dc39e46e45fd132846907
Author: Ada Majorek <amajorek google com>
Date: Thu Apr 7 11:12:18 2016 -0700
Generalised pre set notifications for parameters and reworked alphabet history.
fixes https://github.com/ipomoena/dasher/issues/93
Src/DasherCore/DashIntfSettings.cpp | 1 -
Src/DasherCore/DasherInterfaceBase.cpp | 49 ++++++++++++++++++++-----------
Src/DasherCore/DasherInterfaceBase.h | 11 ++++++-
Src/DasherCore/Observable.h | 1 -
Src/DasherCore/SettingsStore.cpp | 6 ++++
Src/DasherCore/SettingsStore.h | 4 ++-
Src/Win32/Widgets/StatusControl.cpp | 6 +++-
7 files changed, 54 insertions(+), 24 deletions(-)
---
diff --git a/Src/DasherCore/DashIntfSettings.cpp b/Src/DasherCore/DashIntfSettings.cpp
index 75e3448..6c1844d 100644
--- a/Src/DasherCore/DashIntfSettings.cpp
+++ b/Src/DasherCore/DashIntfSettings.cpp
@@ -28,6 +28,5 @@ void CDashIntfSettings::SetLongParameter(int iParameter, long lValue) {
}
void CDashIntfSettings::SetStringParameter(int iParameter, const string &strValue) {
- CDasherInterfaceBase::PreSetNotify(iParameter, strValue);
CDasherInterfaceBase::SetStringParameter(iParameter, strValue);
}
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index e76d50a..d9bb868 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -81,9 +81,17 @@ static char THIS_FILE[] = __FILE__;
#endif
#endif
-CDasherInterfaceBase::CDasherInterfaceBase(CSettingsStore *pSettingsStore, CFileUtils* fileUtils) :
CSettingsUser(pSettingsStore), m_pDasherModel(new CDasherModel()), m_pFramerate(new CFrameRate(this)),
m_pSettingsStore(pSettingsStore), m_pLockLabel(NULL) {
+CDasherInterfaceBase::CDasherInterfaceBase(CSettingsStore *pSettingsStore, CFileUtils* fileUtils)
+ : CSettingsUser(pSettingsStore),
+ m_pDasherModel(new CDasherModel()),
+ m_pFramerate(new CFrameRate(this)),
+ m_pSettingsStore(pSettingsStore),
+ m_pLockLabel(NULL),
+ m_preSetObserver(*pSettingsStore){
pSettingsStore->Register(this);
+ pSettingsStore->PreSetObservable().Register(&m_preSetObserver);
+
m_fileUtils = fileUtils;
// Ensure that pointers to 'owned' objects are set to NULL.
@@ -195,26 +203,31 @@ CDasherInterfaceBase::~CDasherInterfaceBase() {
delete m_pFramerate;
}
-
-void CDasherInterfaceBase::PreSetNotify(int iParameter, const std::string &sNewValue) {
- // FIXME - make this a more general 'pre-set' event in the message
- // infrastructure
-
+void CDasherInterfaceBase::CPreSetObserver::HandleEvent(int iParameter) {
switch(iParameter) {
case SP_ALPHABET_ID:
+ string value = m_settingsStore.GetStringParameter(SP_ALPHABET_ID);
// Cycle the alphabet history
- if(GetStringParameter(SP_ALPHABET_ID) != sNewValue) {
- if(GetStringParameter(SP_ALPHABET_1) != sNewValue) {
- if(GetStringParameter(SP_ALPHABET_2) != sNewValue) {
- if(GetStringParameter(SP_ALPHABET_3) != sNewValue)
- SetStringParameter(SP_ALPHABET_4, GetStringParameter(SP_ALPHABET_3));
- SetStringParameter(SP_ALPHABET_3, GetStringParameter(SP_ALPHABET_2));
- }
- SetStringParameter(SP_ALPHABET_2, GetStringParameter(SP_ALPHABET_1));
- }
- SetStringParameter(SP_ALPHABET_1, GetStringParameter(SP_ALPHABET_ID));
- }
-
+ vector<string> newHistory;
+ newHistory.push_back(value);
+ string v;
+ if ((v = m_settingsStore.GetStringParameter(SP_ALPHABET_1)) != value)
+ newHistory.push_back(v);
+ if ((v = m_settingsStore.GetStringParameter(SP_ALPHABET_2)) != value)
+ newHistory.push_back(v);
+ if ((v = m_settingsStore.GetStringParameter(SP_ALPHABET_3)) != value)
+ newHistory.push_back(v);
+ if ((v = m_settingsStore.GetStringParameter(SP_ALPHABET_4)) != value)
+ newHistory.push_back(v);
+
+ // Fill empty slots.
+ while (newHistory.size() < 4)
+ newHistory.push_back("");
+
+ m_settingsStore.SetStringParameter(SP_ALPHABET_1, newHistory[0]);
+ m_settingsStore.SetStringParameter(SP_ALPHABET_2, newHistory[1]);
+ m_settingsStore.SetStringParameter(SP_ALPHABET_3, newHistory[2]);
+ m_settingsStore.SetStringParameter(SP_ALPHABET_4, newHistory[3]);
break;
}
}
diff --git a/Src/DasherCore/DasherInterfaceBase.h b/Src/DasherCore/DasherInterfaceBase.h
index ffd9be4..b5c448a 100644
--- a/Src/DasherCore/DasherInterfaceBase.h
+++ b/Src/DasherCore/DasherInterfaceBase.h
@@ -147,8 +147,6 @@ public:
virtual void HandleEvent(int iParameter);
- void PreSetNotify(int iParameter, const std::string &sValue);
-
///Locks/unlocks Dasher. The default here stores the lock message and percentage
/// in m_strLockMessage, such that NewFrame renders this instead of the canvas
/// if we are locked. Subclasses may override to implement better (GUI)
@@ -528,6 +526,15 @@ protected:
/// this interface was created, as ClSet and ResetParameter need to access it.
/// (TODO _could_ move these into CSettingsUser, but that seems uglier given so few clients?)
CSettingsStore * const m_pSettingsStore;
+
+ class CPreSetObserver : public Observer<int> {
+ CSettingsStore& m_settingsStore;
+ public:
+ CPreSetObserver(CSettingsStore& settingsStore) : m_settingsStore(settingsStore) {};
+ void HandleEvent(int evt) override;
+ };
+
+ CPreSetObserver m_preSetObserver;
CFileUtils* m_fileUtils;
//The default expansion policy to use - an amortized policy depending on the LP_NODE_BUDGET parameter.
diff --git a/Src/DasherCore/Observable.h b/Src/DasherCore/Observable.h
index e83749c..5ddb3a0 100644
--- a/Src/DasherCore/Observable.h
+++ b/Src/DasherCore/Observable.h
@@ -22,7 +22,6 @@ public:
Observable();
void Register(Observer<T> *pLstnr);
void Unregister(Observer<T> *pLstnr);
-protected:
void DispatchEvent(T t);
private:
typedef typename std::list< Observer<T>* > ListenerList;
diff --git a/Src/DasherCore/SettingsStore.cpp b/Src/DasherCore/SettingsStore.cpp
index 0b24f24..2599aa0 100644
--- a/Src/DasherCore/SettingsStore.cpp
+++ b/Src/DasherCore/SettingsStore.cpp
@@ -141,6 +141,8 @@ void CSettingsStore::SetBoolParameter(int iParameter, bool bValue) {
if(bValue == GetBoolParameter(iParameter))
return;
+ pre_set_observable_.DispatchEvent(iParameter);
+
// Set the value
p->second.bool_value = bValue;
@@ -160,6 +162,8 @@ void CSettingsStore::SetLongParameter(int iParameter, long lValue) {
if(lValue == GetLongParameter(iParameter))
return;
+ pre_set_observable_.DispatchEvent(iParameter);
+
// Set the value
p->second.long_value = lValue;
@@ -179,6 +183,8 @@ void CSettingsStore::SetStringParameter(int iParameter, const std::string sValue
if(sValue == GetStringParameter(iParameter))
return;
+ pre_set_observable_.DispatchEvent(iParameter);
+
// Set the value
p->second.string_value = sValue;
diff --git a/Src/DasherCore/SettingsStore.h b/Src/DasherCore/SettingsStore.h
index 1c56795..5707d1e 100644
--- a/Src/DasherCore/SettingsStore.h
+++ b/Src/DasherCore/SettingsStore.h
@@ -36,7 +36,7 @@ namespace Dasher {
/// The public interface uses UTF-8 strings. All Keys should be
/// in American English and encodable in ASCII. However,
/// string Values may contain special characters where appropriate.
- class CSettingsStore : public Observable<int> {
+class CSettingsStore : public Observable<int> {
public:
CSettingsStore();
@@ -61,6 +61,7 @@ public:
void AddParameters(const Settings::bp_table* table, size_t count);
void AddParameters(const Settings::lp_table* table, size_t count);
void AddParameters(const Settings::sp_table* table, size_t count);
+ Observable<int>& PreSetObservable() { return pre_set_observable_; }
protected:
///Loads all (persistent) prefs from disk, using+storing default values when no
@@ -124,6 +125,7 @@ private:
};
std::unordered_map<int, Parameter> parameters_;
+ Observable<int> pre_set_observable_;
};
/// Superclass for anything that wants to use/access/store persistent settings.
/// (The nearest thing remaining to the old CDasherComponent,
diff --git a/Src/Win32/Widgets/StatusControl.cpp b/Src/Win32/Widgets/StatusControl.cpp
index c1f1d5e..9f55680 100644
--- a/Src/Win32/Widgets/StatusControl.cpp
+++ b/Src/Win32/Widgets/StatusControl.cpp
@@ -10,7 +10,11 @@ CStatusControl::CStatusControl(Dasher::CSettingsUser *pCreateFrom, CAppSettings
void CStatusControl::HandleEvent(int iParameter) {
switch (iParameter) {
- case SP_ALPHABET_ID:
+ case SP_ALPHABET_ID:
+ case SP_ALPHABET_1:
+ case SP_ALPHABET_2:
+ case SP_ALPHABET_3:
+ case SP_ALPHABET_4:
PopulateCombo();
break;
case LP_MAX_BITRATE:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]