#include "SwitchManager.hpp"
+#include <Elementary.h>
+#include <efl_extension.h>
+
#include "ConditionAll.hpp"
#include "ConditionEqual.hpp"
#include "UIActivity.hpp"
+#include "Window.hpp"
SwitchManager::SwitchManager(const std::shared_ptr<SwitchProvider> &provider,
const std::shared_ptr<Configuration> &configuration,
void SwitchManager::initialize()
{
- auto cond = std::unique_ptr<Condition<SwitchConfigurationItem>>(new ConditionAll<SwitchConfigurationItem>);
- configuration->attach(shared_from_this(), std::move(cond));
+ auto condCI = std::shared_ptr<Condition<SwitchConfigurationItem>>(new ConditionAll<SwitchConfigurationItem>);
+ configuration->attach(shared_from_this(), std::move(condCI));
+
+ auto condSP = std::shared_ptr<Condition<SwitchProvider>>(new ConditionAll<SwitchProvider>);
+ switchProvider->attach(shared_from_this(), std::move(condSP));
auto confItems = configuration->findAll();
if (!sw)
continue;
- auto cond = std::unique_ptr<Condition<Switch>>(new ConditionEqual<Switch>(sw));
- switchProvider->attach(shared_from_this(), std::move(cond));
+ auto condS = std::shared_ptr<Condition<Switch>>(new ConditionEqual<Switch>(sw));
+ switchProvider->attach(shared_from_this(), std::move(condS));
}
}
if (!sw)
return;
- auto cond = std::unique_ptr<Condition<Switch>>(new ConditionEqual<Switch>(sw));
+ auto cond = std::shared_ptr<Condition<Switch>>(new ConditionEqual<Switch>(sw));
switchProvider->attach(shared_from_this(), std::move(cond));
break;
changeActivity(request);
}
+void SwitchManager::update(const std::shared_ptr<SwitchProvider> &provider)
+{
+ DEBUG("notified with provider: %s", provider->getId().c_str());
+
+ auto confItems = configuration->findAll();
+
+ for (auto &item : confItems) {
+ auto sw = provider->findSwitchById(item->getSwitchId());
+ if (sw) {
+ onDisconnection();
+ return;
+ }
+ }
+}
+
void SwitchManager::setActivityProvider(const std::shared_ptr<SwitchProvider> &provider)
{
switchProvider = provider;
activityFactory = factory;
}
+static void windowDeleterCb(void *data, Evas_Object *obj, void *event_info)
+{
+ evas_object_del(obj);
+}
+
+static void onButtonClickCb(void *data, Evas_Object *obj, void *event_info)
+{
+ auto window = static_cast<Evas_Object *>(data);
+ evas_object_del(window);
+}
+
+void SwitchManager::onDisconnection()
+{
+ auto windowHandler = elm_win_add(NULL, "universal-switch-popup", ELM_WIN_NOTIFICATION);
+ if (!windowHandler) {
+ ERROR("Window cannot be created");
+ exit(1);
+ }
+
+ efl_util_set_notification_window_level(windowHandler, EFL_UTIL_NOTIFICATION_LEVEL_2);
+ elm_win_override_set(windowHandler, EINA_TRUE);
+ elm_win_alpha_set(windowHandler, EINA_TRUE);
+
+ int screenWidth = 0;
+ int screenHeight = 0;
+
+ elm_win_screen_size_get(windowHandler, NULL, NULL, &screenWidth, &screenHeight);
+ evas_object_resize(windowHandler, screenWidth, screenHeight);
+ evas_object_show(windowHandler);
+
+ auto popup = elm_popup_add(windowHandler);
+ elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_part_text_set(popup, "title,text", _("IDS_SWITCH_PROVIDER_AccessoryDisconnected_Header"));
+ elm_object_text_set(popup, _("IDS_SWITCH_PROVIDER_AccessoryDisconnected_Content"));
+
+ eext_object_event_callback_add(windowHandler, EEXT_CALLBACK_BACK, windowDeleterCb, NULL);
+ evas_object_smart_callback_add(windowHandler, "dismissed", windowDeleterCb, NULL);
+ evas_object_smart_callback_add(windowHandler, "block,clicked", windowDeleterCb, NULL);
+
+ auto btn = elm_button_add(popup);
+ elm_object_style_set(btn, "bottom");
+ elm_object_text_set(btn, "OK");
+ elm_object_part_content_set(popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", onButtonClickCb, windowHandler);
+ evas_object_show(popup);
+}
+
void SwitchManager::changeActivity(const std::shared_ptr<ActivityChangeRequest> &request)
{
ASSERT(request, "request is not initialized");
#include <memory>
#include <stack>
-class SwitchManager : public SwitchConfigurationItemObserver, public SwitchObserver, public std::enable_shared_from_this<SwitchManager>, public ActivityChangeRequestObserver
+class SwitchManager : public SwitchConfigurationItemObserver, public SwitchObserver, public std::enable_shared_from_this<SwitchManager>, public ActivityChangeRequestObserver, public Observer<SwitchProvider>
{
public:
void update(const std::shared_ptr<SwitchConfigurationItem> &item) override;
void update(const std::shared_ptr<Switch> &item) override;
void update(const std::shared_ptr<ActivityChangeRequest> &request) override;
+ void update(const std::shared_ptr<SwitchProvider> &provider) override;
template<class A>
static std::shared_ptr<A> create(const std::shared_ptr<SwitchProvider> &provider,
void setConfiguration(const std::shared_ptr<Configuration> &configuration);
void setActivityFactory(const std::shared_ptr<ActivityFactory> &factory);
+ void onDisconnection();
+
protected:
SwitchManager(const std::shared_ptr<SwitchProvider> &provider,
const std::shared_ptr<Configuration> &configuration,