#include "Internal/AlarmBinaryStorage.h"
#include "Model/Alarm.h"
+#include "Utils/Signal.h"
#include <vector>
#include <functional>
* false otherwise.
*/
bool HasActiveAlarms();
+
+ /**
+ * @brief Signal emitted when new alarm has been added.
+ */
+ utils::Signal<void(Alarm&)> OnAlarmRemoved;
+
+ /**
+ * @brief Signal emitted when alarm has been removed.
+ */
+ utils::Signal<void(Alarm&)> OnAlarmAdded;
private:
/**
* Alarm provider private backend implementation
+++ /dev/null
-/*
-* Copyright 2016 Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _CLOCK_ALARM_PROVIDER_EVENT_H_
-#define _CLOCK_ALARM_PROVIDER_EVENT_H_
-
-#include "Utils/EventBus.h"
-#include "Model/Alarm.h"
-
-namespace model {
- /**
- * @brief Global event that is announce that alarm was added to Provider
- */
- class AlarmAddedEvent : public utils::Event {
- public:
- /**
- * @brief Creates AlarmAddedEvent instance
- * @param alarm added alarm.
- */
- AlarmAddedEvent(Alarm &alarm) : alarm_(alarm) {}
- /**
- * @brief Gets event target
- * @return added alarm.
- */
- Alarm& GetAlarm() { return alarm_; }
- private:
- Alarm &alarm_;
- };
-
- /**
- * @brief Global event that is announce that alarm was removed from Provider
- */
- class AlarmRemovedEvent : public utils::Event {
- public:
- /**
- * @brief Creates AlarmRemovedEvent instance
- * @param alarm removed alarm reference.
- */
- AlarmRemovedEvent(Alarm &alarm) : alarm_(alarm) {}
- /**
- * @brief Gets event target
- * @return removed alarm reference.
- */
- Alarm& GetAlarm() { return alarm_; }
- private:
- Alarm &alarm_;
- };
-} /* model */
-
-#endif
#include "View/AlarmView.h"
#include "Model/AlarmProvider.h"
-#include "Model/AlarmProviderEvent.h"
#include "Utils/EventBus.h"
#include <map>
void OnItemSelected(int idx);
void OnAddButtonClicked();
void OnItemActiveStatusChanged(int idx);
- void OnAlarmAddedEvent(utils::Event &e);
- void OnAlarmRemovedEvent(utils::Event &e);
+ void OnAlarmAddedEvent(model::Alarm &e);
+ void OnAlarmRemovedEvent(model::Alarm &e);
void OnAlarmEditedEvent(utils::Event &e);
void OnDeleteItemClicked();
void UpdateBackgroundLabel();
*/
#include "Internal/AlarmBinaryStorage.h"
-#include "Model/AlarmProviderEvent.h"
#include "Utils/EventBus.h"
#include <cstdlib>
if (it == alarms.end()) {
alarms.push_back(alarm);
- AlarmAddedEvent ev(alarms.back());
- EventBus::FireEvent(ev);
}
}
auto it = std::find(alarms.begin(), alarms.end(), alarm.get());
if (it != alarms.end()) {
- AlarmRemovedEvent ev(alarm);
- EventBus::FireEvent(ev);
alarm.get().Deactivate();
alarms.erase(it);
}
void AlarmProvider::Add(Alarm& alarm)
{
impl_->Add(alarm);
+ OnAlarmAdded(impl_->GetAlarms().back().get());
Sync();
}
void AlarmProvider::Remove(std::reference_wrapper<Alarm> alarm)
{
+ OnAlarmRemoved(alarm);
impl_->Remove(alarm);
Sync();
}
*/
#include "Presenter/AlarmPresenter.h"
-#include "Model/AlarmProviderEvent.h"
#include "Model/AlarmEvent.h"
#include "Utils/EventBus.h"
#include "Utils/Log.h"
connections_.push_back(
view_->OnMenuButtonClicked.Connect(std::bind(&AlarmPresenter::OnMenuButtonClicked, this)));
- connections_.push_back(EventBus::AddListener<AlarmAddedEvent>(
+ connections_.push_back(m->OnAlarmAdded.Connect(
std::bind(&AlarmPresenter::OnAlarmAddedEvent, this, _1)));
- connections_.push_back(EventBus::AddListener<AlarmRemovedEvent>(
+ connections_.push_back(m->OnAlarmRemoved.Connect(
std::bind(&AlarmPresenter::OnAlarmRemovedEvent, this, _1)));
connections_.push_back(EventBus::AddListener<AlarmEditedEvent>(
std::bind(&AlarmPresenter::OnAlarmEditedEvent, this, _1)));
model_->Sync();
}
-void AlarmPresenter::OnAlarmAddedEvent(Event &e)
+void AlarmPresenter::OnAlarmAddedEvent(Alarm &alarm)
{
- AlarmAddedEvent &ev = dynamic_cast<AlarmAddedEvent&>(e);
-
int id = view_->ItemAppend(
- ev.GetAlarm().GetTime(),
- ev.GetAlarm().GetName().c_str(),
- ev.GetAlarm().GetWeekFlags(),
- ev.GetAlarm().IsActivated());
- alarms_.insert(std::map<int, std::reference_wrapper<Alarm>>::value_type (id, std::reference_wrapper<Alarm>(ev.GetAlarm())));
+ alarm.GetTime(),
+ alarm.GetName().c_str(),
+ alarm.GetWeekFlags(),
+ alarm.IsActivated());
+ alarms_.insert(std::map<int, std::reference_wrapper<Alarm>>::value_type (id, std::reference_wrapper<Alarm>(alarm)));
UpdateBackgroundLabel();
}
view_->ShowDeletePopup();
}
-void AlarmPresenter::OnAlarmRemovedEvent(Event &e)
+void AlarmPresenter::OnAlarmRemovedEvent(Alarm &alarm)
{
- AlarmRemovedEvent &ev = dynamic_cast<AlarmRemovedEvent&>(e);
-
for (auto it = alarms_.begin(); it != alarms_.end(); ++it) {
- if (ev.GetAlarm() == it->second.get()) {
+ if (alarm == it->second.get()) {
view_->RemoveItem(it->first);
alarms_.erase(it);
break;