--- /dev/null
+#include "SelectActionPageModel.hpp"
+
+#include "DBus.hpp"
+#include "UniversalSwitchConstants.hpp"
+
+std::vector<InfoType> SelectActionPageModel::getBindableActivityTypes()
+{
+ std::vector<InfoType> bindableActivities{};
+ auto dBusClient = DBus::DBusClient{BUS, PATH, IFACE, DBus::ConnectionType::SESSION};
+ auto reply = dBusClient.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string>>>()>("getBindableActivityTypes").call();
+ if (reply) {
+ for (auto activity : std::get<0>(reply))
+ bindableActivities.push_back(InfoType{std::get<0>(activity), std::get<1>(activity), std::get<2>(activity)});
+ } else {
+ ERROR("Error on function getBindableActivityTypes call");
+ ERROR("%s", reply.getError().message.c_str());
+ }
+ return bindableActivities;
+}
+
+void SelectActionPageModel::updateSwitch(const SwitchConfigurationItem &item)
+{
+ auto dBusClient = DBus::DBusClient{BUS, PATH, IFACE, DBus::ConnectionType::SESSION};
+ auto reply = dBusClient.method<DBus::ValueOrError<>(std::string, std::string, std::string)>("updateSwitchConfigurationItem").call(item.switchId, item.userName, item.activityType);
+ if (reply)
+ DEBUG("Switch: %s updated successfully", item.switchId.c_str());
+ else {
+ ERROR("Error on function updateSwitchConfigurationItem call");
+ ERROR("%s", reply.getError().message.c_str());
+ }
+}
+
+void SelectActionPageModel::addSwitch(const SwitchConfigurationItem &item)
+{
+ auto dBusClient = DBus::DBusClient{BUS, PATH, IFACE, DBus::ConnectionType::SESSION};
+ auto reply = dBusClient.method<DBus::ValueOrError<>(std::string, std::string, std::string)>("addSwitchConfigurationItem").call(item.switchId, item.userName, item.activityType);
+ if (reply)
+ DEBUG("Switch: %s added successfully", item.switchId.c_str());
+ else {
+ ERROR("Error on function addSwitchConfigurationItem call");
+ ERROR("%s", reply.getError().message.c_str());
+ }
+}
\ No newline at end of file
--- /dev/null
+#ifndef SELECT_ACTION_PAGE_MODEL_HPP
+#define SELECT_ACTION_PAGE_MODEL_HPP
+
+#include "ObservableProperty.hpp"
+#include "UniversalSwitchTypes.hpp"
+#include "VConf.hpp"
+
+class SelectActionPageModel
+{
+ public:
+ std::vector<InfoType> getBindableActivityTypes();
+ void updateSwitch(const SwitchConfigurationItem &item);
+ void addSwitch(const SwitchConfigurationItem &item);
+};
+
+#endif
\ No newline at end of file
#include "AddSwitchPagePresenter.hpp"
+#include "AppContext.hpp"
+#include "SelectActionPagePresenter.hpp"
+#include "UniversalSwitchConstants.hpp"
+
AddSwitchPagePresenter::AddSwitchPagePresenter()
{
setTitle("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES");
groups_.emplace_back("");
auto &items = groups_.back().items_;
- for (auto provider : model_.getProviders()) {
+ for (auto &provider : model_.getProviders()) {
items.push_back(std::make_unique<ListItem>(
provider.name,
provider.description,
- [this](auto item) {
- //Page for adding special switch should be added here
+ [=](auto item) {
+ this->createPageForProvider(provider);
}));
}
auto onConfigurationChange = [this](auto changeTime) {
};
model_.switchesConfigurationChanged_.attach(onConfigurationChange);
onConfigurationChange(std::chrono::system_clock::now());
+}
+
+void AddSwitchPagePresenter::createPageForProvider(const InfoType &provider)
+{
+ if (provider.id == ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER) {
+ createPageForScreenProvider();
+ return;
+ }
+ if (provider.id == ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER) {
+ createPageForAccessoriesProvider();
+ return;
+ }
+ if (provider.id == ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER) {
+ createPageForCameraProvider();
+ return;
+ }
+}
+
+void AddSwitchPagePresenter::createPageForScreenProvider()
+{
+ auto switches = model_.getAllSwitchesByProvider(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER);
+ if (switches.size() != 1)
+ return;
+ auto screenSwitch = switches[0];
+ Singleton<AppContext>::instance().push(std::make_unique<SelectActionPagePresenter>(screenSwitch.id, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN, ChangeType::ADD, 1));
+}
+
+void AddSwitchPagePresenter::createPageForAccessoriesProvider()
+{
+ //Singleton<AppContext>::instance().push(std::make_unique<AccessoriesProviderPagePresenter>());
+}
+
+void AddSwitchPagePresenter::createPageForCameraProvider()
+{
+ //Singleton<AppContext>::instance().push(std::make_unique<CameraProviderPagePresenter>());
}
\ No newline at end of file
#include "AddSwitchPageModel.hpp"
#include "ListPresenter.hpp"
+#include "UniversalSwitchTypes.hpp"
class AddSwitchPagePresenter : public ListPresenter
{
private:
AddSwitchPageModel model_;
+ void createPageForProvider(const InfoType &provider);
+ void createPageForScreenProvider();
+ void createPageForAccessoriesProvider();
+ void createPageForCameraProvider();
};
#endif
--- /dev/null
+#include "SelectActionPagePresenter.hpp"
+
+SelectActionPagePresenter::SelectActionPagePresenter(std::string switchId, std::string userName, ChangeType changeType, int countOfPagesToPop)
+ : switchId_(std::move(switchId)), userName_(std::move(userName)), changeType_(changeType), countOfPagesToPop_(countOfPagesToPop)
+{
+ setTitle("IDS_ACCS_UNIVERSAL_SWITCH_SELECT_ACTION");
+ groups_.emplace_back("");
+ auto &items = groups_.back().items_;
+
+ for (auto &activity : model_.getBindableActivityTypes()) {
+ items.push_back(std::make_unique<ListItem>(
+ activity.name,
+ std::string{},
+ [=](auto item) {
+ this->addOrUpdateSwitchConfigurationItem(activity.id);
+ },
+ ListItem::WidgetType::radio));
+ }
+}
+
+void SelectActionPagePresenter::addOrUpdateSwitchConfigurationItem(const std::string &activityType)
+{
+ switch (changeType_) {
+ case ChangeType::ADD:
+ model_.addSwitch({switchId_, userName_, activityType});
+ break;
+ case ChangeType::UPDATE:
+ model_.addSwitch({switchId_, userName_, activityType});
+ break;
+ default:
+ ASSERT(0, "Unhandled change type");
+ break;
+ }
+ //Singleton<AppContext>::instance().pop(countOfPagesToPop+1);
+}
\ No newline at end of file
--- /dev/null
+#ifndef SELECT_ACTION_PAGE_PRESENTER_HPP
+#define SELECT_ACTION_PAGE_PRESENTER_HPP
+
+#include "ListPresenter.hpp"
+#include "SelectActionPageModel.hpp"
+#include "UniversalSwitchTypes.hpp"
+
+class SelectActionPagePresenter : public ListPresenter
+{
+ public:
+ SelectActionPagePresenter(std::string switchId, std::string userName, ChangeType changeType, int countOfPagesToPop);
+
+ private:
+ void addOrUpdateSwitchConfigurationItem(const std::string &activityType);
+ const std::string switchId_;
+ const std::string userName_;
+ ChangeType changeType_;
+ const int countOfPagesToPop_;
+ SelectActionPageModel model_;
+};
+
+#endif
#define ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON RESDIR "/icons/plus.png"
+#define ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER "ScreenSwitchProvider"
+#define ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER "AccessoriesSwitchProvider"
+#define ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER "CameraSwitchProvider"
+#define ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN "Screen"
+
#endif