ChangeScanningDirectionActivity 98/159698/6
authorPawel Kurowski <p.kurowski2@samsung.com>
Fri, 10 Nov 2017 19:08:56 +0000 (20:08 +0100)
committerLukasz Oleksak <l.oleksak@samsung.com>
Tue, 14 Nov 2017 10:59:51 +0000 (10:59 +0000)
Change-Id: If9d4424d0e82b7732ac618849dc708736c6ad393

src/ChangeIntTypeVconfKeyActivity.cpp
src/MenuBuilder.cpp

index 8f7c84b..6c6807c 100644 (file)
@@ -7,43 +7,70 @@
 
 #include <memory>
 
+#define GET_SIZE(x) (sizeof(x) / sizeof(*x))
+
+
+/**
+ * TODO:
+ * 1. Add calculator functionality:
+ * -  increaseByOne
+ * -  increaseByAnotherKeyValue
+ * 2. Atomic operation (change all, or none of values)
+ */
+
 template <typename DerivedType>
-class ChangeIntTypeVconfKeyActivity : public Activity, private RegisterActivity<DerivedType>
+class ChangeIntTypeVconfKeysActivity : public Activity, private RegisterActivity<DerivedType>
 {
 public:
        constexpr static const char *activityType = DerivedType::activityType;
-       ChangeIntTypeVconfKeyActivity() : Activity(activityType) {}
+       ChangeIntTypeVconfKeysActivity() : Activity(activityType) {}
 
        void process() override
        {
-               auto state = Singleton<VConfInterface>::instance().get(DerivedType::KEY, 0);
-               if (!state) {
-                       markAsCompleted();
-                       return;
+               static_assert(GET_SIZE(DerivedType::KEYS) == GET_SIZE(DerivedType::STATES), "Incorrect activity");
+
+               for (auto i = 0u; i < GET_SIZE(DerivedType::KEYS); i++) {
+                       auto state = Singleton<VConfInterface>::instance().get({DerivedType::KEYS[i]}, 0);
+                       if (!state) {
+                               markAsCompleted();
+                               return;
+                       }
+
+                       state = state % DerivedType::STATES[i] + 1;
+                       Singleton<VConfInterface>::instance().set({DerivedType::KEYS[i]}, state);
                }
 
-               state = state % DerivedType::STATES + 1;
-               Singleton<VConfInterface>::instance().set(DerivedType::KEY, state);
                markAsCompleted();
        }
 };
 
-class ChangeScanningMethodActivity : public ChangeIntTypeVconfKeyActivity<ChangeScanningMethodActivity>
+class ChangeScanningMethodActivity : public ChangeIntTypeVconfKeysActivity<ChangeScanningMethodActivity>
 {
 public:
        static constexpr const char *activityType = "CHANGE_SCANNING_METHOD";
-       static constexpr const char *KEY = VCONF_KEY_SCAN_METHOD;
-       static constexpr int STATES = 2;
+       static constexpr const char *KEYS[] = {VCONF_KEY_SCAN_METHOD};
+       static constexpr const int STATES[] = {2};
 };
 
-class ChangeTextEditionModeActivity : public ChangeIntTypeVconfKeyActivity<ChangeTextEditionModeActivity>
+class ChangeTextEditionModeActivity : public ChangeIntTypeVconfKeysActivity<ChangeTextEditionModeActivity>
 {
 public:
        static constexpr const char *activityType = "CHANGE_TEXT_EDITION_MODE";
-       static constexpr const char *KEY = VCONF_KEY_TEXT_EDITION_MODE;
-       static constexpr int STATES = 2;
+       static constexpr const char *KEYS[] = {VCONF_KEY_TEXT_EDITION_MODE};
+       static constexpr const int STATES[] = {2};
 };
 
+class ChangeScanningDirectionActivity : public ChangeIntTypeVconfKeysActivity<ChangeScanningDirectionActivity>
+{
+public:
+       static constexpr const char *activityType = "CHANGE_SCANNING_DIRECTION_MODE";
+       static constexpr const char *KEYS[] = {VCONF_KEY_SCAN_DIRECTION_VERTICAL, VCONF_KEY_SCAN_DIRECTION_HORIZONTAL};
+       static constexpr const int STATES[] = {2, 2};
+};
+
+constexpr const char *ChangeScanningDirectionActivity::KEYS[];
+constexpr const int ChangeScanningDirectionActivity::STATES[];
+
 namespace
 {
        enum granularity {
index a9a03ab..3b031ab 100644 (file)
@@ -478,7 +478,7 @@ MenuBuilderImplementation::MenuBuilderImplementation()
        auto scanVerticalDirection      =       std::make_shared<VconfIntTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_BOTTOM_TO_TOP", "IDS_TOP_TO_BOTTOM"},
                                                                                defaultImg,
-                                                                               std::string {}/*TODO add activity*/,
+                                                                               "CHANGE_SCANNING_DIRECTION_MODE",
                                                                                std::string {VCONF_KEY_SCAN_DIRECTION_VERTICAL});
        auto turnOnOffVoice                     =       std::make_shared<VconfBoolTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_TURN_ON_VOICE", "IDS_TURN_OFF_VOICE"},