#include <app_alarm.h>
#include "Model/Alarm.h"
#include "Common/Defines.h"
+#include "log.h"
using namespace model;
using namespace utils;
app_control_h ctrl;
int err = app_control_create(&ctrl);
- if (err != APP_CONTROL_ERROR_NONE)
+ if (err != APP_CONTROL_ERROR_NONE) {
+ ERR("app_control_create failed: %s", get_error_message(err));
return NULL;
+ }
err = app_control_set_app_id(ctrl, PACKAGE);
if (err != APP_CONTROL_ERROR_NONE) {
+ ERR("app_control_set_app_id failed: %s", get_error_message(err));
app_control_destroy(ctrl);
return NULL;
}
snooze.attempts_max = 3;
activated = false;
snooze_enabled = false;
+ snooze.alarm_id = -1;
alarm_id = -1;
}
void Alarm::Activate()
{
+ int err;
struct tm tmtime = {0, };
if (activated)
return;
+ err = alarm_get_current_time(&tmtime);
+ if (err != ALARM_ERROR_NONE) {
+ ERR("alarm_get_current_time failed: %s", get_error_message(err));
+ return;
+ }
+
app_control_h control = AppControlCreate();
if (!control) {
- // log error
+ DBG("AppControlCreate failed");
return;
}
tmtime.tm_min= time.Min;
tmtime.tm_sec= time.Sec;
- int err = alarm_schedule_with_recurrence_week_flag(
+ err = alarm_schedule_with_recurrence_week_flag(
control,
&tmtime,
flags.GetBitMask(),
&alarm_id);
- if (err != ALARM_ERROR_NONE) {
+ if (err == ALARM_ERROR_NONE) {
activated = true;
} else {
- // log error
+ ERR("alarm_schedule_with_recurrence_week_flag failed: %s", get_error_message(err));
}
app_control_destroy(control);
int err = alarm_cancel(alarm_id);
if (err != ALARM_ERROR_NONE) {
+ ERR("alarm_cancel failed: %s", get_error_message(err));
}
- err = alarm_cancel(snooze.alarm_id);
- if (err != ALARM_ERROR_NONE) {
+ if (snooze.alarm_id != -1 ) {
+ err = alarm_cancel(snooze.alarm_id);
+ if (err != ALARM_ERROR_NONE) {
+ ERR("alarm_cancel failed: %s", get_error_message(err));
+ } else {
+ snooze.alarm_id = -1;
+ }
}
activated = false;
if (err == ALARM_ERROR_NONE) {
snooze.attempt++;
} else {
- // log error
+ ERR("alarm_schedule_once_after_delay failed: %s", get_error_message(err));
}
app_control_destroy(control);
{
view->SetButtonClickedCallback(std::bind(&AlarmPresenter::OnAddButtonClicked, this));
view->SetDeleteItemClickedCallback(std::bind(&AlarmPresenter::OnDeleteItemClicked, this));
+ view->SetItemToggleCallback(std::bind(&AlarmPresenter::OnItemActiveStatusChanged, this, _1));
EventBus::RegisterHandler(AlarmAddedEvent::EventType(),
std::bind(&AlarmPresenter::OnAlarmAddedEvent, this, _1));
void AlarmPresenter::OnItemActiveStatusChanged(int idx)
{
- // get Alarm reference
- /*
- Alarm *alarm;
- bool active = false;
+ auto it = alarms_.find(idx);
- if (!active)
- alarm->Activate();
- else
- alarm->Deactivate();
- */
+ if (it == alarms_.end())
+ return;
+
+ Alarm &alarm = it->second.get();
- //view.ItemUpdate(idx, a.GetTime(), a.GetName(), a.GetFlags(), a.IsActivated());
+ if (alarm.IsActivated()) {
+ alarm.Deactivate();
+ }
+ else {
+ alarm.Activate();
+ }
- //AlarmProvider::Sync();
+ AlarmProvider::Sync();
}
void AlarmPresenter::OnAlarmAddedEvent(Event *e)
elm_object_item_signal_emit(id->it, "alarm,state,enabled", "clock");
else
elm_object_item_signal_emit(id->it, "alarm,state,disabled", "clock");
+
+ if (id->instance->onToggled) id->instance->onToggled((uintptr_t)id->it);
}
void AlarmView::ItemRealized(void *data, Evas_Object *obj, void *info)
void AlarmView::MoreButtonClicked(void *data, Evas_Object *obj, void *info)
{
AlarmView *view = static_cast<AlarmView*>(data);
-
- DBG("More button clicked");
view->ShowDeletePopup();
}