Alarm: enable platform alarms
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Sun, 11 Sep 2016 11:51:25 +0000 (13:51 +0200)
committerr.czerski <r.czerski@samsung.com>
Tue, 13 Sep 2016 14:07:06 +0000 (16:07 +0200)
Add required privilage and fix minor issues to enable
registering platform alarms.

Change-Id: Ibf61c072fd56352dc9b6520ab25102b1edeefee7

clock/src/Clock.cpp
clock/src/Model/Alarm.cpp
clock/src/Presenter/AlarmPresenter.cpp
clock/src/View/AlarmView.cpp
clock/tizen-manifest.xml

index 0efebdc..1370f47 100644 (file)
@@ -41,6 +41,7 @@ app_create(void *data)
 static void
 app_control(app_control_h app_control, void *data)
 {
+       DBG("app_control");
        /* Handle the launch request. */
 }
 
index eae1826..e267971 100644 (file)
@@ -1,6 +1,7 @@
 #include <app_alarm.h>
 #include "Model/Alarm.h"
 #include "Common/Defines.h"
+#include "log.h"
 
 using namespace model;
 using namespace utils;
@@ -10,11 +11,14 @@ static app_control_h AppControlCreate()
        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;
        }
@@ -28,19 +32,27 @@ Alarm::Alarm() :
        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;
        }
 
@@ -48,15 +60,15 @@ void Alarm::Activate()
        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);
@@ -69,9 +81,15 @@ void Alarm::Deactivate()
 
        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;
@@ -92,7 +110,7 @@ void Alarm::Snooze()
        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);
index 60a701b..3851ae3 100644 (file)
@@ -14,6 +14,7 @@ AlarmPresenter::AlarmPresenter(AlarmView *v, AlarmProvider *m) : view(v), model(
 {
        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));
@@ -60,20 +61,21 @@ void AlarmPresenter::OnAddButtonClicked()
 
 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)
index fc920e9..9de5f56 100644 (file)
@@ -52,6 +52,8 @@ void AlarmView::ItemClicked(void *data, Evas_Object *obj, void *info)
                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)
@@ -169,8 +171,6 @@ AlarmView::AlarmView()
 void AlarmView::MoreButtonClicked(void *data, Evas_Object *obj, void *info)
 {
        AlarmView *view = static_cast<AlarmView*>(data);
-
-       DBG("More button clicked");
        view->ShowDeletePopup();
 }
 
index ac8581e..14fc7ef 100644 (file)
@@ -5,4 +5,8 @@
                <icon>clock.png</icon>
                <label>Clock</label>
        </ui-application>
+    <privileges>
+        <privilege>http://tizen.org/privilege/alarm</privilege>
+        <privilege>http://tizen.org/privilege/alarm.set</privilege>
+    </privileges>
 </manifest>