From 97bfac4150f0a226832d2b8bd636a5901a7aaf28 Mon Sep 17 00:00:00 2001
From: Pawel Kurowski
Date: Tue, 26 Sep 2017 17:47:16 +0200
Subject: [PATCH] MenuItem - SelectActivity communication via Subject/Observer
mechanism
SelectActivity fixes:
+ AUTO_TAP_WAITING_PERIOD_KEY is a key of type "double", handle is kept in SelectActivity
+ small changes of UI can be done without refreshing whole Menu
+ problematic pointers to std::stack elements was removed
MenuItem:
+ subclass VconfIntTypeMenuItem and VconfBoolTypeMenuItem
Change-Id: Ie2e639e4d6a6811b0541f00e3eb25802b1294893
---
src/MenuBuilder.cpp | 195 +++++++++++++----------
src/MenuBuilder.hpp | 14 +-
src/SelectActivity.cpp | 77 ++++-----
src/Subject.hpp | 2 +-
tests/ui-scenarios/MenuBuilderTests.cpp | 202 +++++++++++++++---------
utils/setVconfKeys.sh | 2 +-
6 files changed, 283 insertions(+), 209 deletions(-)
diff --git a/src/MenuBuilder.cpp b/src/MenuBuilder.cpp
index d3eff02e..c6633ee2 100644
--- a/src/MenuBuilder.cpp
+++ b/src/MenuBuilder.cpp
@@ -7,6 +7,48 @@
#include "Window.hpp"
#include "Quickpanel.hpp"
+#include
+
+class VconfTypeMenuItem : public MenuItem
+{
+public:
+ VconfTypeMenuItem(std::vector names, std::string iconPath, std::string activityType,
+ std::string subMenuLabel, std::string showingStateVconfKey);
+
+ std::string getName() const override;
+
+ void vconfChangeCb();
+ virtual size_t getIndex() const = 0;
+
+ std::stack> callbackHandle;
+ size_t index;
+};
+
+class VconfIntTypeMenuItem : public VconfTypeMenuItem
+{
+public:
+ VconfIntTypeMenuItem(std::vector names, std::string iconPath, std::string activityType,
+ std::string vconfStateKey,
+ std::string subMenuLabel = {}, std::string showingStateVconfKey = {});
+
+ size_t getIndex() const override;
+
+ std::string vconfStateKey;
+};
+
+class VconfBoolTypeMenuItem : public VconfTypeMenuItem
+{
+public:
+ VconfBoolTypeMenuItem(std::vector names, std::string iconPath, std::string activityType,
+ std::vector vconfStateKeys,
+ std::string subMenuLabel = {}, std::string showingStateVconfKey = {});
+
+ size_t getIndex() const override;
+
+ std::vector vconfStateKeys;
+};
+
+
MenuItem::MenuItem(std::vector names, std::string iconPath, std::string activityType, std::string subMenuLabel, std::string showingStateVconfKey)
: names(std::move(names)), iconPath(std::move(iconPath)), activityType(std::move(activityType)),
subMenuLabel(std::move(subMenuLabel)), showingStateVconfKey(std::move(showingStateVconfKey)) {}
@@ -26,16 +68,6 @@ std::string MenuItem::getActivityType() const
return activityType;
}
-VconfKeyType MenuItem::getVconfStateKeysType() const
-{
- return VconfKeyType::NONE;
-}
-
-std::vector MenuItem::getVconfStateKeys() const
-{
- return {};
-}
-
std::string MenuItem::getSubMenuLabel() const
{
return subMenuLabel;
@@ -46,78 +78,81 @@ std::string MenuItem::getShowingStateVconfKey() const
return showingStateVconfKey;
}
-class VconfTypeMenuItem : public MenuItem
+VconfTypeMenuItem::VconfTypeMenuItem(std::vector names, std::string iconPath, std::string activityType,
+ std::string subMenuLabel, std::string showingStateVconfKey)
+ : MenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey)), index(0)
{
-public:
- VconfTypeMenuItem(std::vector names, std::string iconPath, std::string activityType,
- VconfKeyType vconfStateKeysType, std::vector vconfStateKeys,
- std::string subMenuLabel = {}, std::string showingStateVconfKey = {});
-
- std::string getName() const override;
- VconfKeyType getVconfStateKeysType() const override;
- std::vector getVconfStateKeys() const override;
-
-private:
- VconfKeyType vconfStateKeysType;
- std::vector vconfStateKeys;
-};
+ ASSERT(!this->names.empty(), "Forbidden VconfTypeMenuItem");
+}
-class QuickpanelTypeMenuItem : public MenuItem
+std::string VconfTypeMenuItem::getName() const
{
-public:
- QuickpanelTypeMenuItem(std::vector names, std::string iconPath, std::string activityType);
+ return gettext(names[index].c_str());
+}
- std::string getName() const override;
-};
+void VconfTypeMenuItem::vconfChangeCb()
+{
+ index = getIndex();
+ notify(shared_from_this());
+}
-VconfTypeMenuItem::VconfTypeMenuItem(std::vector names, std::string iconPath, std::string activityType,
- VconfKeyType vconfStateKeysType, std::vector vconfStateKeys,
- std::string subMenuLabel, std::string showingStateVconfKey)
- : MenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey)),
- vconfStateKeysType(vconfStateKeysType), vconfStateKeys(std::move(vconfStateKeys))
+VconfIntTypeMenuItem::VconfIntTypeMenuItem(std::vector names, std::string iconPath, std::string activityType,
+ std::string vconfStateKey,
+ std::string subMenuLabel, std::string showingStateVconfKey)
+ : VconfTypeMenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey)),
+ vconfStateKey(std::move(vconfStateKey))
{
- ASSERT(!VconfTypeMenuItem::names.empty() && !VconfTypeMenuItem::vconfStateKeys.empty(), "Forbidden VconfTypeMenuItem");
+ index = getIndex();
+ callbackHandle.push(Singleton::instance()
+ .registerKeyChangedCb(this->vconfStateKey, std::bind(&VconfIntTypeMenuItem::vconfChangeCb, this)));
}
-std::string VconfTypeMenuItem::getName() const
+size_t VconfIntTypeMenuItem::getIndex() const
{
- switch (vconfStateKeysType) {
- case VconfKeyType::BOOL: {
- auto idx = 0;
- for (auto i = 0u; i < vconfStateKeys.size(); ++i) {
- auto val = Singleton::instance().get(vconfStateKeys[i], false) ? 1 : 0;
- idx += val * (1 << i);
- }
- return gettext(names[idx].c_str());
- }
- case VconfKeyType::INT: {
- // Int type vconf key. Correct values starts from 1, 0 means error
- auto idx = Singleton::instance().get(vconfStateKeys[0], 0) - 1;
- if (idx < 0 || idx >= static_cast(names.size())) {
- ASSERT(0, "key = %s value = %d out of bound", vconfStateKeys[0].c_str(), idx);
- return {};
- }
- return gettext(names[idx].c_str());
- }
- case VconfKeyType::NONE:
- case VconfKeyType::DOUBLE:
- case VconfKeyType::STRING:
- ASSERT(0, "Forbidden key type");
+ // Int type vconf key. Correct values starts from 1, 0 means error
+ auto idx = Singleton::instance().get(vconfStateKey, 0) - 1;
+ if (idx < 0 || idx >= static_cast(names.size())) {
+ ERROR("Key = %s value = %d out of bound", vconfStateKey.c_str(), idx);
+ return 0;
}
-
- return {};
+ return static_cast(idx);
}
-VconfKeyType VconfTypeMenuItem::getVconfStateKeysType() const
+VconfBoolTypeMenuItem::VconfBoolTypeMenuItem(std::vector names, std::string iconPath, std::string activityType,
+ std::vector vconfStateKeys,
+ std::string subMenuLabel, std::string showingStateVconfKey)
+ : VconfTypeMenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey)),
+ vconfStateKeys(std::move(vconfStateKeys))
{
- return vconfStateKeysType;
+ index = getIndex();
+ for (auto &key : this->vconfStateKeys)
+ callbackHandle.push(Singleton::instance()
+ .registerKeyChangedCb(key, std::bind(&VconfIntTypeMenuItem::vconfChangeCb, this)));
}
-std::vector VconfTypeMenuItem::getVconfStateKeys() const
+
+size_t VconfBoolTypeMenuItem::getIndex() const
{
- return vconfStateKeys;
+ auto idx = 0;
+ for (auto i = 0u; i < vconfStateKeys.size(); ++i) {
+ auto val = Singleton::instance().get(vconfStateKeys[i], false) ? 1 : 0;
+ idx += val * (1 << i);
+ }
+ if (idx < 0 || idx >= static_cast(names.size())) {
+ ERROR("Index value = %d out of bound", idx);
+ return 0;
+ }
+ return static_cast(idx);
}
+class QuickpanelTypeMenuItem : public MenuItem
+{
+public:
+ QuickpanelTypeMenuItem(std::vector names, std::string iconPath, std::string activityType);
+
+ std::string getName() const override;
+};
+
QuickpanelTypeMenuItem::QuickpanelTypeMenuItem(std::vector names, std::string iconPath, std::string activityType)
: MenuItem(std::move(names), std::move(iconPath), std::move(activityType))
{}
@@ -191,18 +226,16 @@ MenuMap::MenuMap()
auto selectAll = std::make_shared