#include "AccessoriesSwitchesPage.hpp"
-#include "setting-accessibility.h"
-#include "WidgetFactory.hpp"
-#include "Layout.hpp"
-
-#include <app.h>
-#define EDJ_ACCESSORY "edje/accessibility-smart-switch-accessory.edj"
-#define PRT_ACCESSORY_LABEL "accessory_label"
-#define EDJ_ACCESSORY_POPUP "edje/accessibility-smart-switch-accessory-popup.edj"
-#define PRT_ACCESSORY_POPUP_ENTRY "accessory_popup_entry"
-#define GRP_ACCESSORY_POPUP "accessory_popup"
-#define GRP_ACCESSORY "accessory"
-#define PRT_ACCESSORY_POPUP_LABEL "accessory_popup_label"
+#include "Layout.hpp"
+#include "Button.hpp"
+#include "Popup.hpp"
+#include "Entry.hpp"
AccessoriesSwitchesPage::AccessoriesSwitchesPage(SettingAccessibility *ad)
: context_(ad)
{
- auto layout = createLayout(context_->md.getNaviframe(), EDJ_ACCESSORY, GRP_ACCESSORY);
+ auto naviframe = context_->md.getNaviframe();
+ auto layout = Widget::make<Layout>(naviframe, EDJ_ACCESSORY, GRP_ACCESSORY);
layout->setText(PRT_ACCESSORY_LABEL, "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_DESC");
- context_->us_configuration.switch_id = {};
+ layout->show();
- Elm_Object_Item *navi_it = elm_naviframe_item_push(context_->md.getNaviframe()->getObject(), _("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_TITLE"), NULL, NULL, layout->getObject(), NULL);
- elm_naviframe_item_pop_cb_set(navi_it, naviframPopCb, context_);
- elm_object_item_domain_text_translatable_set(navi_it, PACKAGE, EINA_TRUE);
+ naviframe->pushBack("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_TITLE", layout, {}, [this]() {
+ setting_accessibility_universal_switch_dbus_config_cancelCaptureSwitch(&context_->config);
+ context_->us_configuration.switch_id = {};
+ });
- Evas_Object *back_btn = WidgetFactory::createButton(context_->md.getNaviframe()->getObject(), {}, WidgetFactory::BACK_BUTTON_ARROW_STYLE, backCb, context_);
- elm_layout_content_set(context_->md.getNaviframe()->getObject(), "prev_btn", back_btn);
+ auto prevBtn = Widget::make<Button>(layout, std::string{}, [naviframe]() {
+ naviframe->popBack();
+ });
+ prevBtn->setStyle(Button::BACK_BUTTON_ARROW_STYLE);
+ prevBtn->show();
+ layout->setPartContent("prev_btn", prevBtn);
+ context_->us_configuration.switch_id = {};
setting_accessibility_universal_switch_dbus_config_captureSwitch(&context_->config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, this);
}
accessories_switch_added_cb_data = cbData;
}
-Evas_Object *AccessoriesSwitchesPage::createEntry(Evas_Object *parent, const char *part_name)
-{
- Evas_Object *entry = elm_entry_add(parent);
- evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_part_content_set(parent, part_name, entry);
- evas_object_show(entry);
-
- return entry;
-}
-
-Layout *AccessoriesSwitchesPage::createLayout(Widget *parent, const std::string &edj_file, const std::string &group)
-{
- char *res_path = app_get_resource_path();
- std::string edj_path;
- if (res_path) {
- edj_path = std::string{res_path} + edj_file;
- free(res_path);
- }
- auto layout = Widget::make<Layout>(parent);
- layout->setFile(edj_path, group);
- layout->setWeightHint(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- layout->show();
-
-
- return layout;
-}
-
void AccessoriesSwitchesPage::captureSwitchCb(void *user_data, const char *switch_id)
{
retm_if(user_data == NULL, "Input argument is NULL");
return;
}
}
-
self->context_->us_configuration.switch_id = switch_id;
- self->settingPopup_ = std::make_unique<SettingPopup>(self, self->context_->md.getNaviframe(),
- "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH", std::string{},
- popupResponseCb,
- std::vector<std::string> {"IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", "IDS_ACCS_UNIVERSAL_SWITCH_SAVE"});
-
- auto layout = self->createLayout(self->settingPopup_->getObject(), EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP);
-
- self->entry = createEntry(layout->getObject(), PRT_ACCESSORY_POPUP_ENTRY);
-
- elm_object_part_text_set(self->entry, "guide", _("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_NAME"));
-
- self->settingPopup_->getObject()->setContent(layout);
+ self->newSwitchPopup();
}
-void AccessoriesSwitchesPage::alreadyMappedSwitchPopup()
+void AccessoriesSwitchesPage::newSwitchPopup()
{
- settingPopup_ = std::make_unique<SettingPopup>(this, context_->md.getNaviframe(),
- "IDS_ACCS_UNIVERSAL_SWITCH_UNABLE_TO_ADD", std::string{},
- okResponseCb,
- std::vector<std::string> {"IDS_ACCS_UNIVERSAL_SWITCH_OK"});
+ auto popup = Widget::make<Popup>(context_->md.getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH");
+ popup->setEextEventCallback(EEXT_CALLBACK_BACK, []() {});
- auto layout = createLayout(settingPopup_->getObject(), EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP);
- layout->setPartText(PRT_ACCESSORY_POPUP_LABEL, "IDS_ACCS_UNIVERSAL_SWITCH_ALREADY_ADDED");
- settingPopup_->getObject()->setContent(layout);
-}
+ auto layout = Widget::make<Layout>(popup, EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP);
+ layout->show();
+ popup->setContent(layout);
+
+ auto entry = Widget::make<Entry>(layout);
+ entry->setWeightHint(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ entry->setPartText("guide", "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_NAME");
+ entry->show();
+ layout->setPartContent(PRT_ACCESSORY_POPUP_ENTRY, entry);
+
+ auto cancelBtnCb = [popup, this]() {
+ auto parent = popup->getParent();
+ parent->removeChild(popup);
+ setting_accessibility_universal_switch_dbus_config_captureSwitch(&context_->config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, this);
+ };
+
+ auto cancelBtn = Widget::make<Button>(popup, "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", cancelBtnCb);
+ cancelBtn->setStyle("popup");
+ cancelBtn->show();
+ popup->setPartContent("button1", cancelBtn);
+
+ auto saveBtnCb = [popup, entry, this]() {
+ if ((switchName_ = entry->getEntryText()).empty()){
+ SETTING_TRACE_END; //TODO probably to remove
+ return;
+ }
-void AccessoriesSwitchesPage::okResponseCb(void *data, Evas_Object *obj, void *event_info)
-{
- retm_if(data == NULL, "Data parameter is NULL");
- auto self = static_cast<AccessoriesSwitchesPage *>(data);
+ actionPage_ = std::make_unique<ActionPage>(this->context_);
+ actionPage_->attachCallback(accessorySwitchActionCb, this);
+ elm_naviframe_item_pop_cb_set(elm_naviframe_top_item_get(context_->md.getNaviframe()->getObject()), renewCaptureSwitchCb, this); //TODO
- renewCaptureSwitchCb(self, NULL);
+ auto parent = popup->getParent();
+ parent->removeChild(popup);
+ };
- self->settingPopup_ = {};
+ auto saveBtn = Widget::make<Button>(popup, "IDS_ACCS_UNIVERSAL_SWITCH_SAVE", saveBtnCb);
+ saveBtn->setStyle("popup");
+ saveBtn->show();
+ popup->setPartContent("button2", saveBtn);
+ popup->show();
}
-void AccessoriesSwitchesPage::popupResponseCb(void *data, Evas_Object *obj, void *event_info)
+void AccessoriesSwitchesPage::alreadyMappedSwitchPopup()
{
- retm_if(data == NULL, "Data parameter is NULL");
- auto self = static_cast<AccessoriesSwitchesPage *>(data);
- auto response_type = get_popup_btn_response_type(obj);
+ auto popup = Widget::make<Popup>(context_->md.getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_UNABLE_TO_ADD");
+ popup->setEextEventCallback(EEXT_CALLBACK_BACK, []() {});
- if (response_type == PopupBtnResponse::OK) {
- self->switchName_ = static_cast<const char *>(elm_entry_entry_get(self->entry));
- if (self->switchName_.empty()) {
- SETTING_TRACE_END;
- return;
- }
+ auto okBtnCb = [popup, this](){
+ setting_accessibility_universal_switch_dbus_config_captureSwitch(&context_->config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, this);
+ auto parent = popup->getParent();
+ parent->removeChild(popup);
+ };
- self->actionPage_ = std::make_unique<ActionPage>(self->context_);
- self->actionPage_->attachCallback(accessorySwitchActionCb, self);
- elm_naviframe_item_pop_cb_set(elm_naviframe_top_item_get(self->context_->md.getNaviframe()->getObject()), renewCaptureSwitchCb, self);
- } else {
- renewCaptureSwitchCb(self, NULL);
- }
+ auto okBtn = Widget::make<Button>(popup, "IDS_ACCS_UNIVERSAL_SWITCH_OK", okBtnCb);
+ okBtn->setStyle("popup");
+ okBtn->show();
+ popup->setPartContent("button1", okBtn);
- self->settingPopup_ = {};
- self->entry = NULL;
+ auto layout = Widget::make<Layout>(popup, EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP);
+ layout->setPartText(PRT_ACCESSORY_POPUP_LABEL, "IDS_ACCS_UNIVERSAL_SWITCH_ALREADY_ADDED");
+ layout->show();
+ popup->setContent(layout);
+ popup->show();
}
void AccessoriesSwitchesPage::accessorySwitchActionCb(SettingAccessibility *ad, const std::string &action, void *user_data)
Eina_Bool AccessoriesSwitchesPage::renewCaptureSwitchCb(void *data, Elm_Object_Item *it)
{
- retv_if(data == NULL, EINA_TRUE);
+ retv_if(data == NULL, EINA_FALSE);
auto self = static_cast<AccessoriesSwitchesPage *>(data);
-
setting_accessibility_universal_switch_dbus_config_captureSwitch(&self->context_->config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, self);
return EINA_TRUE;
-}
-
-Eina_Bool AccessoriesSwitchesPage::naviframPopCb(void *data, Elm_Object_Item *it)
-{
- retv_if(data == NULL, EINA_TRUE);
- auto ad = static_cast<SettingAccessibility *>(data);
-
- setting_accessibility_universal_switch_dbus_config_cancelCaptureSwitch(&ad->config);
- ad->us_configuration.switch_id = {};
-
- return EINA_TRUE;
-}
-
-void AccessoriesSwitchesPage::backCb(void *data, Evas_Object *obj, void *event_info)
-{
- retm_if(data == NULL, "Data argument is NULL");
- auto ad = static_cast<SettingAccessibility *>(data);
- elm_naviframe_item_pop(ad->md.getNaviframe()->getObject());
-}
+}
\ No newline at end of file
#ifndef ACCESSORIES_SWITCHES_PAGE_HPP
#define ACCESSORIES_SWITCHES_PAGE_HPP
-#include "SettingAccessibility.hpp"
-
#include <Elementary.h>
-#include "SettingPopup.hpp"
+
+#include "SettingAccessibility.hpp"
+#include "setting-accessibility.h"
/**
* View allowing to configure switches provided by AccessoriesSwitchProvider.
void attachActionCallback(UniversalSwitchCb cb, void *cbData);
private:
- static Evas_Object *createEntry(Evas_Object *parent, const char *part_name);
- Layout *createLayout(Widget *parent, const std::string &edj_file, const std::string &group);
static void captureSwitchCb(void *user_data, const char *switch_id);
- void alreadyMappedSwitchPopup(); //TODO rename
- static void okResponseCb(void *data, Evas_Object *obj, void *event_info);
- static void popupResponseCb(void *data, Evas_Object *obj, void *event_info);
static void accessorySwitchActionCb(SettingAccessibility *ad, const std::string &action, void *user_data);
static Eina_Bool renewCaptureSwitchCb(void *data, Elm_Object_Item *it);
- static Eina_Bool naviframPopCb(void *data, Elm_Object_Item *it);
- static void backCb(void *data, Evas_Object *obj, void *event_info);
+ void alreadyMappedSwitchPopup(); //TODO rename
+ void newSwitchPopup();
SettingAccessibility *context_ = nullptr;
- UniversalSwitchCb accessories_switch_added_cb = nullptr;
+ UniversalSwitchCb accessories_switch_added_cb;
void *accessories_switch_added_cb_data = nullptr;
std::string switchName_; //TODO remove when lambda expression would be added
- Evas_Object *entry;
- std::unique_ptr<SettingPopup> settingPopup_;
std::unique_ptr<ActionPage> actionPage_;
+
+ const std::string EDJ_ACCESSORY = "edje/accessibility-smart-switch-accessory.edj";
+ const std::string PRT_ACCESSORY_LABEL = "accessory_label";
+ const std::string EDJ_ACCESSORY_POPUP = "edje/accessibility-smart-switch-accessory-popup.edj";
+ const std::string PRT_ACCESSORY_POPUP_ENTRY = "accessory_popup_entry";
+ const std::string GRP_ACCESSORY_POPUP = "accessory_popup";
+ const std::string GRP_ACCESSORY = "accessory";
+ const std::string PRT_ACCESSORY_POPUP_LABEL = "accessory_popup_label";
};
#endif