--- /dev/null
+#include "AddSwitchPageModel.hpp"
+
+#include "UniversalSwitchConstants.hpp"
+
+AddSwitchPageModel::AddSwitchPageModel()
+{
+ dBusClient_ = DBus::DBusClient(BUS, PATH, IFACE, DBus::ConnectionType::SESSION);
+ synchronizeProviders();
+ dBusClient_.addSignal<void()>(std::string{"switchesConfigurationChanged"}, [this]() {
+ this->switchesConfigurationChanged_ = std::chrono::system_clock::now();
+ });
+}
+
+void AddSwitchPageModel::synchronizeProviders()
+{
+ providers_.clear();
+ auto reply = dBusClient_.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string>>>()>("getAllSwitchProviders").call();
+ if (reply) {
+ for (auto provider : std::get<0>(reply))
+ providers_.push_back(InfoType{std::get<0>(provider), std::get<1>(provider), std::get<2>(provider)});
+ } else {
+ ERROR("Error on function getAllSwitchProviders call");
+ ERROR("%s", reply.getError().message.c_str());
+ }
+}
+
+bool AddSwitchPageModel::areAllSwitchesConfigured(const InfoType &switchProvider)
+{
+ auto configuredSwitches = getAllSwitchConfigurationItems();
+ auto isSwitchConfigured = [&](const InfoType &switchItem) {
+ for (auto &configured : configuredSwitches) {
+ if (switchItem.id == configured.switchId)
+ return true;
+ }
+ return false;
+ };
+ for (auto &aSwitch : getAllSwitchesByProvider(switchProvider)) {
+ if (!isSwitchConfigured(aSwitch))
+ return false;
+ }
+ return true;
+}
+
+const std::vector<InfoType> &AddSwitchPageModel::getProviders()
+{
+ return providers_;
+}
+
+std::vector<InfoType> AddSwitchPageModel::getAllSwitchesByProvider(const InfoType &switchProvider)
+{
+ 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);
+ 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 getAllSwitchProviders call");
+ ERROR("%s", reply.getError().message.c_str());
+ }
+ return allSwitches;
+}
+
+std::vector<SwitchConfigurationItem> AddSwitchPageModel::getAllSwitchConfigurationItems()
+{
+ std::vector<SwitchConfigurationItem> configurationItems{};
+ auto reply = dBusClient_.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string, ChangeType>>>()>("getAllSwitchConfigurationItems").call();
+ if (reply) {
+ for (auto item : std::get<0>(reply))
+ configurationItems.push_back(SwitchConfigurationItem{std::get<0>(item), std::get<1>(item), std::get<2>(item)});
+ } else {
+ ERROR("Error on function getAllSwitchConfigurationItems call");
+ ERROR("%s", reply.getError().message.c_str());
+ }
+ return configurationItems;
+}
--- /dev/null
+#ifndef ADD_SWITCH_PAGE_MODEL_HPP
+#define ADD_SWITCH_PAGE_MODEL_HPP
+
+#include "DBus.hpp"
+#include "ObservableProperty.hpp"
+#include "UniversalSwitchTypes.hpp"
+#include "VConf.hpp"
+
+#include <chrono>
+
+class AddSwitchPageModel
+{
+ public:
+ 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);
+
+ private:
+ void synchronizeProviders();
+ std::vector<SwitchConfigurationItem> getAllSwitchConfigurationItems();
+
+ DBus::DBusClient dBusClient_;
+ std::vector<InfoType> providers_;
+};
+
+#endif
\ No newline at end of file
auto reply = dBusClient_.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string, ChangeType>>>()>("getAllSwitchConfigurationItems").call();
if (reply) {
for (auto item : std::get<0>(reply))
- configurationItems.push_back(SwitchConfigurationItem{std::get<0>(item), std::get<1>(item), std::get<2>(item), std::get<3>(item)});
+ configurationItems.push_back(SwitchConfigurationItem{std::get<0>(item), std::get<1>(item), std::get<2>(item)});
} else {
ERROR("Error on function getAllSwitchConfigurationItems call");
ERROR("%s", reply.getError().message.c_str());
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(SwitchInfoType{std::get<0>(activity), std::get<1>(activity), std::get<2>(activity)});
+ 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());
private:
void synchronizeBindableActivities();
- std::vector<SwitchInfoType> bindableActivities_;
+ std::vector<InfoType> bindableActivities_;
DBus::DBusClient dBusClient_;
};
--- /dev/null
+#include "AddSwitchPagePresenter.hpp"
+
+AddSwitchPagePresenter::AddSwitchPagePresenter()
+{
+ setTitle("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES");
+ groups_.emplace_back("");
+ auto &items = groups_.back().items_;
+ 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 onConfigurationChange = [this](auto changeTime) {
+ auto providers = this->model_.getProviders();
+ auto size = providers.size();
+ for (auto i = 0u; i < size; ++i)
+ this->groups_.back().items_[i]->enabled_ = !this->model_.areAllSwitchesConfigured(providers[i]);
+ };
+ model_.switchesConfigurationChanged_.attach(onConfigurationChange);
+ onConfigurationChange(std::chrono::system_clock::now());
+}
\ No newline at end of file
--- /dev/null
+#ifndef ADD_SWITCH_PAGE_PRESENTER_HPP
+#define ADD_SWITCH_PAGE_PRESENTER_HPP
+
+#include "AddSwitchPageModel.hpp"
+#include "ListPresenter.hpp"
+
+class AddSwitchPagePresenter : public ListPresenter
+{
+ public:
+ AddSwitchPagePresenter();
+
+ private:
+ AddSwitchPageModel model_;
+};
+
+#endif
#include "SwitchesPagePresenter.hpp"
+#include "AddSwitchPagePresenter.hpp"
+#include "AppContext.hpp"
#include "UniversalSwitchConstants.hpp"
SwitchesPagePresenter::SwitchesPagePresenter()
"IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES_ADD_SWITCH",
std::string{},
[this](auto item) {
- //AddSwitchPage should be added here
+ Singleton<AppContext>::instance().push(std::make_unique<AddSwitchPagePresenter>());
},
ListItem::WidgetType::icon,
std::function<void(ListItem * item)>{},
std::string switchId;
std::string userName;
std::string activityType;
- ChangeType changetype;
};
-struct SwitchInfoType
+struct InfoType
{
std::string id;
std::string name;