--- /dev/null
+#ifndef _CLOCK_UTILS_NOTIFIER_H
+#define _CLOCK_UTILS_NOTIFIER_H
+
+#include <notification.h>
+
+namespace utils {
+
+ class Notifier {
+ public:
+ virtual ~Notifier ();
+ static Notifier &GetInstance();
+
+ Notifier &operator=(const Notifier&) = delete;
+ Notifier(const Notifier &) = delete;
+
+ /*
+ * @brief Posts alarm notification for indicator
+ *
+ * Posting notification for indicator to display alarm
+ * icon if any is activated.
+ *
+ * @return true if succeed, otherwise false
+ */
+ bool AlarmNotiPost();
+
+ /*
+ * @brief Removes alarm notification from indicator
+ *
+ * Removes alarm icon from indicator bar.
+ *
+ * @return true if succeed, otherwise false
+ */
+ bool AlarmNotiDelete();
+ private:
+ Notifier();
+
+ const char *tag_;
+ notification_h noti_ = NULL;
+ notification_h NotificationCreate();
+ };
+
+} /* utils */
+
+
+#endif //_CLOCK_UTILS_NOTIFIER_H
#include "Utils/BinaryFileReader.h"
#include "Utils/BinaryFileWriter.h"
#include "Utils/Utils.h"
+#include "Utils/Notifier.h"
static const char DATABASE_FILE[] = "alarmsdb.cfg";
if (!instance) {
BinaryFileReader reader(Utils::APP_DIR_DATA, DATABASE_FILE);
instance = new AlarmProviderFile(reader);
+
+ if (instance->HasActiveAlarms())
+ Notifier::GetInstance().AlarmNotiPost();
}
return instance;
}
BinaryFileWriter writer(Utils::APP_DIR_DATA, DATABASE_FILE);
instance->Serialize(writer);
writer.Flush();
+
+ if (instance->HasActiveAlarms())
+ Notifier::GetInstance().AlarmNotiPost();
+ else
+ Notifier::GetInstance().AlarmNotiDelete();
}
--- /dev/null
+#include <string>
+
+#include "Utils/Notifier.h"
+#include "Utils/Log.h"
+#include "Utils/Utils.h"
+
+#define ALARM_ICON "alarm_icon.png"
+#define ALARM_NOTI_TAG "system_clock_alarm"
+
+namespace utils {
+
+Notifier &Notifier::GetInstance()
+{
+ static Notifier instance;
+ return instance;
+}
+
+Notifier::Notifier() : tag_(ALARM_NOTI_TAG)
+{
+ noti_ = notification_load_by_tag(tag_);
+ if (noti_) {
+ DBG("notification_load_by_tag succeed");
+ return;
+ }
+
+ noti_ = NotificationCreate();
+ if (!noti_)
+ ERR("Could not create notification");
+}
+
+Notifier::~Notifier()
+{
+ notification_free(noti_);
+}
+
+notification_h Notifier::NotificationCreate()
+{
+ notification_h noti = notification_create(NOTIFICATION_TYPE_NOTI);
+ if (!noti) {
+ ERR("notification_create failed");
+ return nullptr;
+ }
+
+ std::string path = Utils::GetAppResourcePath(Utils::APP_DIR_SHARED_RESOURCE, ALARM_ICON);
+ int ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, path.c_str());
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("notification_set_image failed[%d]: %s", ret, get_error_message(ret));
+ notification_free(noti);
+ return nullptr;
+ }
+
+
+ ret = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_INDICATOR);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("notification_set_display_applist failed[%d]: %s", ret, get_error_message(ret));
+ notification_free(noti);
+ return nullptr;
+ }
+
+ ret = notification_set_tag(noti, tag_);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("notification_set_tag failed[%d]: %s", ret, get_error_message(ret));
+ notification_free(noti);
+ return nullptr;
+ }
+
+ ret = notification_set_sound(noti, NOTIFICATION_SOUND_TYPE_NONE, NULL);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("notification_set_sound failed[%d]: %s", ret, get_error_message(ret));
+ notification_free(noti);
+ return nullptr;
+ }
+
+ return noti;
+}
+
+bool Notifier::AlarmNotiPost()
+{
+ if (!noti_) {
+ ERR("Notification post failed: noti_ == NULL");
+ return false;
+ }
+
+ int ret = notification_post(noti_);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("notification_post failed[%d]: %s", ret, get_error_message(ret));
+ return false;
+ }
+
+ return true;
+}
+
+bool Notifier::AlarmNotiDelete()
+{
+ if (!noti_) {
+ ERR("noti_ == NULL");
+ return false;
+ }
+
+ int ret = notification_delete(noti_);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ ERR("notification_delete failed[%d]: %s", ret, get_error_message(ret));
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace utils