}
return false;
};
- for (auto &aSwitch : getAllSwitchesByProvider(switchProvider)) {
+ for (auto &aSwitch : getAllSwitchesByProviderId(switchProvider.id)) {
if (!isSwitchConfigured(aSwitch))
return false;
}
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)});
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();
--- /dev/null
+#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;
+}
--- /dev/null
+#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
#include "AddSwitchPagePresenter.hpp"
#include "AppContext.hpp"
+#include "CameraSwitchesPagePresenter.hpp"
#include "SelectActionPagePresenter.hpp"
#include "UniversalSwitchConstants.hpp"
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];
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
--- /dev/null
+#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
--- /dev/null
+#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