--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 {
+ class AlarmAddedEvent : public utils::Event {
+ public:
+ AlarmAddedEvent(Alarm &alarm);
+ const Alarm& GetAlarm() const { return alarm_; }
+ static int EventType();
+ private:
+ Alarm &alarm_;
+ static int custom_type_;
+ };
+ class AlarmRemovedEvent : public utils::Event {
+ public:
+ AlarmRemovedEvent(Alarm &alarm);
+ const Alarm& GetAlarm() const { return alarm_; }
+ static int EventType();
+ private:
+ Alarm &alarm_;
+ static int custom_type_;
+ };
+} /* model */
+
+#endif
#include "View/AlarmView.h"
#include "Model/AlarmProvider.h"
+#include "Model/AlarmProviderEvent.h"
namespace presenter {
class AlarmPresenter {
public:
AlarmPresenter(view::AlarmView *view, model::AlarmProvider *model);
+ ~AlarmPresenter();
private:
view::AlarmView *view;
model::AlarmProvider *model;
void ShowAll();
void OnItemSelected(int idx);
void OnItemActiveStatusChanged(int idx);
+ void OnAlarmAddedEvent(utils::Event *e);
};
} /* presenters */
--- /dev/null
+#include "Model/AlarmProviderEvent.h"
+
+using namespace model;
+using namespace utils;
+
+int AlarmAddedEvent::custom_type_;
+int AlarmRemovedEvent::custom_type_;
+
+AlarmAddedEvent::AlarmAddedEvent(Alarm &alarm) :
+ Event(AlarmAddedEvent::EventType()), alarm_(alarm)
+{
+}
+
+int AlarmAddedEvent::EventType()
+{
+ if (custom_type_ == 0) {
+ custom_type_ = EventBus::RegisterNewEventType();
+ }
+ return custom_type_;
+}
+
+AlarmRemovedEvent::AlarmRemovedEvent(Alarm &alarm) :
+ Event(AlarmAddedEvent::EventType()), alarm_(alarm)
+{
+}
+
+int AlarmRemovedEvent::EventType()
+{
+ if (custom_type_ == 0) {
+ custom_type_ = EventBus::RegisterNewEventType();
+ }
+ return custom_type_;
+}
#include "Internal/AlarmProviderFile.h"
+#include "Model/AlarmProviderEvent.h"
+#include "Utils/EventBus.h"
-#include <Ecore_File.h>
#include <cstdlib>
#include <algorithm>
if (it == alarms.end()) {
alarms.push_back(alarm);
+ EventBus::FireEvent(new AlarmAddedEvent(alarm));
}
-
- //FIXME emit AlarmAddedEvent
}
void AlarmProviderFile::Remove(model::Alarm& alarm)
if (it != alarms.end()) {
alarms.erase(it);
+ EventBus::FireEvent(new AlarmRemovedEvent(alarm));
}
-
- //FIXME emit AlarmRemovedEvent
}
AlarmProviderFile::AlarmProviderFile(IReader &r)
#include "Presenter/AlarmPresenter.h"
+#include "Model/AlarmProviderEvent.h"
+#include "Utils/EventBus.h"
#include "log.h"
using namespace presenter;
using namespace view;
using namespace model;
+using namespace utils;
+using std::placeholders::_1;
AlarmPresenter::AlarmPresenter(AlarmView *v, AlarmProvider *m) : view(v), model(m)
{
//view.RegisterOnItemSelected(std::function<>());
//view.RegisterOnAlarmAddClicked(std::function<>());
+ EventBus::RegisterHandler(AlarmAddedEvent::EventType(),
+ std::bind(&AlarmPresenter::OnAlarmAddedEvent, this, _1));
+
ShowAll();
}
+AlarmPresenter::~AlarmPresenter()
+{
+ EventBus::DeregisterHandler(AlarmAddedEvent::EventType(),
+ std::bind(&AlarmPresenter::OnAlarmAddedEvent, this, _1));
+}
+
void AlarmPresenter::ShowAll()
{
std::vector<std::reference_wrapper<Alarm>> alarms = model->GetAlarms();
- DBG("ShowAll()");
view->Clear();
for (auto a: alarms) {
- DBG("ItemAppend()");
view->ItemAppend(
a.get().GetTime(),
a.get().GetName().c_str(),
//AlarmProvider::Sync();
}
+
+void AlarmPresenter::OnAlarmAddedEvent(Event *e)
+{
+ if (!e || (e->GetType() != AlarmAddedEvent::EventType()))
+ return;
+
+ AlarmAddedEvent *ev = dynamic_cast<AlarmAddedEvent*>(e);
+
+ view->ItemAppend(
+ ev->GetAlarm().GetTime(),
+ ev->GetAlarm().GetName().c_str(),
+ ev->GetAlarm().GetWeekFlags(),
+ ev->GetAlarm().IsActivated());
+}