Camera Switches Page in MVP 60/208060/5
authorOskar Chodowicz <o.chodowicz@samsung.com>
Mon, 17 Jun 2019 17:20:25 +0000 (19:20 +0200)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Thu, 27 Jun 2019 06:57:41 +0000 (08:57 +0200)
Change-Id: I5473263543dfffdce3b257c8ae0c848c41931c5e

src/model/AddSwitchPageModel.cpp
src/model/AddSwitchPageModel.hpp
src/model/CameraSwitchesPageModel.cpp [new file with mode: 0644]
src/model/CameraSwitchesPageModel.hpp [new file with mode: 0644]
src/presenter/AddSwitchPagePresenter.cpp
src/presenter/CameraSwitchesPagePresenter.cpp [new file with mode: 0644]
src/presenter/CameraSwitchesPagePresenter.hpp [new file with mode: 0644]

index a57e396..5a6c939 100644 (file)
@@ -34,7 +34,7 @@ bool AddSwitchPageModel::areAllSwitchesConfigured(const InfoType &switchProvider
                }
                return false;
        };
-       for (auto &aSwitch : getAllSwitchesByProvider(switchProvider)) {
+       for (auto &aSwitch : getAllSwitchesByProviderId(switchProvider.id)) {
                if (!isSwitchConfigured(aSwitch))
                        return false;
        }
@@ -46,10 +46,10 @@ const std::vector<InfoType> &AddSwitchPageModel::getProviders()
        return providers_;
 }
 
-std::vector<InfoType> AddSwitchPageModel::getAllSwitchesByProvider(const InfoType &switchProvider)
+std::vector<InfoType> AddSwitchPageModel::getAllSwitchesByProviderId(const std::string &providerId)
 {
        std::vector<InfoType> allSwitches;
-       auto reply = dBusClient_.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string>>>(std::string)>("getAllSwitchesByProviderId").call(switchProvider.id);
+       auto reply = dBusClient_.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string>>>(std::string)>("getAllSwitchesByProviderId").call(providerId);
        if (reply) {
                for (auto aSwitch : std::get<0>(reply))
                        allSwitches.push_back(InfoType{std::get<0>(aSwitch), std::get<1>(aSwitch), std::get<2>(aSwitch)});
index 216b2af..eba90d0 100644 (file)
@@ -15,7 +15,7 @@ class AddSwitchPageModel
        const std::vector<InfoType> &getProviders();
        bool areAllSwitchesConfigured(const InfoType &switchProvider);
        ObservableProperty<std::chrono::system_clock::time_point> switchesConfigurationChanged_;
-       std::vector<InfoType> getAllSwitchesByProvider(const InfoType &switchProvider);
+       std::vector<InfoType> getAllSwitchesByProviderId(const std::string &providerId);
 
        private:
        void synchronizeProviders();
diff --git a/src/model/CameraSwitchesPageModel.cpp b/src/model/CameraSwitchesPageModel.cpp
new file mode 100644 (file)
index 0000000..4785267
--- /dev/null
@@ -0,0 +1,32 @@
+#include "CameraSwitchesPageModel.hpp"
+
+#include "DBus.hpp"
+#include "UniversalSwitchConstants.hpp"
+
+std::vector<InfoType> CameraSwitchesPageModel::getAllSwitchesByProvider(const std::string &providerId)
+{
+       std::vector<InfoType> allSwitches;
+       auto reply = DBus::DBusClient{BUS, PATH, IFACE, DBus::ConnectionType::SESSION}.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string>>>(std::string)>("getAllSwitchesByProviderId").call(providerId);
+       if (reply) {
+               for (auto aSwitch : std::get<0>(reply))
+                       allSwitches.push_back(InfoType{std::get<0>(aSwitch), std::get<1>(aSwitch), std::get<2>(aSwitch)});
+       } else {
+               ERROR("Error on function getAllSwitchesByProviderId call");
+               ERROR("%s", reply.getError().message.c_str());
+       }
+       return allSwitches;
+}
+
+bool CameraSwitchesPageModel::isSwitchConfigured(const std::string &switchId)
+{
+       auto reply = DBus::DBusClient{BUS, PATH, IFACE, DBus::ConnectionType::SESSION}.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string>>>()>("getAllSwitchConfigurationItems").call();
+       if (reply) {
+               for (auto item : std::get<0>(reply))
+                       if (std::get<0>(item) == switchId)
+                               return true;
+       } else {
+               ERROR("Error on function getAllSwitchConfigurationItems call");
+               ERROR("%s", reply.getError().message.c_str());
+       }
+       return false;
+}
diff --git a/src/model/CameraSwitchesPageModel.hpp b/src/model/CameraSwitchesPageModel.hpp
new file mode 100644 (file)
index 0000000..50a63a7
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef CAMERA_SWITCHES_PAGE_MODEL_HPP
+#define CAMERA_SWITCHES_PAGE_MODEL_HPP
+
+#include "ObservableProperty.hpp"
+#include "UniversalSwitchTypes.hpp"
+#include "VConf.hpp"
+
+class CameraSwitchesPageModel
+{
+       public:
+       std::vector<InfoType> getAllSwitchesByProvider(const std::string &provider);
+       bool isSwitchConfigured(const std::string &switchId);
+};
+
+#endif
\ No newline at end of file
index f29b61c..cb0bd00 100644 (file)
@@ -1,6 +1,7 @@
 #include "AddSwitchPagePresenter.hpp"
 
 #include "AppContext.hpp"
+#include "CameraSwitchesPagePresenter.hpp"
 #include "SelectActionPagePresenter.hpp"
 #include "UniversalSwitchConstants.hpp"
 
@@ -45,7 +46,7 @@ void AddSwitchPagePresenter::createPageForProvider(const InfoType &provider)
 
 void AddSwitchPagePresenter::createPageForScreenProvider()
 {
-       auto switches = model_.getAllSwitchesByProvider(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER);
+       auto switches = model_.getAllSwitchesByProviderId(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER);
        if (switches.size() != 1)
                return;
        auto screenSwitch = switches[0];
@@ -59,5 +60,5 @@ void AddSwitchPagePresenter::createPageForAccessoriesProvider()
 
 void AddSwitchPagePresenter::createPageForCameraProvider()
 {
-       //Singleton<AppContext>::instance().push(std::make_unique<CameraProviderPagePresenter>());
+       Singleton<AppContext>::instance().push(std::make_unique<CameraSwitchesPagePresenter>());
 }
\ No newline at end of file
diff --git a/src/presenter/CameraSwitchesPagePresenter.cpp b/src/presenter/CameraSwitchesPagePresenter.cpp
new file mode 100644 (file)
index 0000000..f7b51ea
--- /dev/null
@@ -0,0 +1,31 @@
+#include "CameraSwitchesPagePresenter.hpp"
+
+#include "AppContext.hpp"
+#include "SelectActionPagePresenter.hpp"
+#include "UniversalSwitchConstants.hpp"
+
+CameraSwitchesPagePresenter::CameraSwitchesPagePresenter()
+{
+       setTitle("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_CAMERA_TITLE");
+       groups_.emplace_back("");
+       groups_.back().items_.push_back(std::make_unique<ListItem>(
+               std::string{},
+               "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_CAMERA_COMMENT"));
+
+       groups_.emplace_back("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_CAMERA_GROUP_HEAD");
+       auto &items = groups_.back().items_;
+       for (auto &aSwitch : model_.getAllSwitchesByProvider(ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER)) {
+               items.push_back(std::make_unique<ListItem>(
+                       aSwitch.name,
+                       aSwitch.description,
+                       [=](auto item) {
+                               this->createSelectActionPageForSwitch(aSwitch);
+                       }));
+               items.back()->enabled_ = !model_.isSwitchConfigured(aSwitch.id);
+       }
+}
+
+void CameraSwitchesPagePresenter::createSelectActionPageForSwitch(const InfoType &aSwitch)
+{
+       Singleton<AppContext>::instance().push(std::make_unique<SelectActionPagePresenter>(aSwitch.id, aSwitch.name, ChangeType::ADD, 2));
+}
\ No newline at end of file
diff --git a/src/presenter/CameraSwitchesPagePresenter.hpp b/src/presenter/CameraSwitchesPagePresenter.hpp
new file mode 100644 (file)
index 0000000..a358446
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef CAMERA_SWITCHES_PAGE_PRESENTER_HPP
+#define CAMERA_SWITCHES_PAGE_PRESENTER_HPP
+
+#include "CameraSwitchesPageModel.hpp"
+#include "ListPresenter.hpp"
+
+class CameraSwitchesPagePresenter : public ListPresenter
+{
+       public:
+       CameraSwitchesPagePresenter();
+
+       private:
+       CameraSwitchesPageModel model_;
+       void createSelectActionPageForSwitch(const InfoType &aSwitch);
+};
+
+#endif