Modify the argument of notification_load for core-notification module requests. ...
[platform/framework/native/shell.git] / src / core / FShell_NotificationManagerImpl.cpp
index 8828ca2..a84a6f4 100644 (file)
@@ -27,6 +27,7 @@
 #include <FBaseSysLog.h>
 #include <FIoFile.h>
 #include <FAppApp.h>
+#include <FGrpColor.h>
 #include <FShellNotificationManager.h>
 #include <FShellNotificationRequest.h>
 #include <FShellIBadgeEventListener.h>
@@ -40,6 +41,7 @@ using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::App;
 using namespace Tizen::Io;
+using namespace Tizen::Graphics;
 
 extern "C" int service_create_request(bundle *data, service_h *service);
 extern "C" int service_to_bundle(service_h service, bundle** data);
@@ -173,6 +175,8 @@ _BadgeManagerImpl::RemovePrimaryBadgeEventListener(IBadgeEventListener& primaryL
 _NotificationManagerImpl::_NotificationManagerImpl(void)
        : __notifyPrivateId(-1)
        , __notifyPrivateIdForOngoing(-1)
+       , __lastNotifyPrivateId(-1)
+       , __lightActivated(false)
 {
 }
 
@@ -447,6 +451,7 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
        {
                SysTryReturnResult(NID_SHELL, false, E_INVALID_ARG, "Invalid argument is used.");
        }
+       __lastAppId = pAppIdChar.get();
 
        const int badgeNumber = notifyRequest.GetBadgeNumber();
        const int badgeOffset = notifyRequest.GetBadgeOffset();
@@ -495,6 +500,7 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
        const String& soundPath = notifyRequest.GetSoundFilePath();
        const notification_type_e notiType = isOngoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
        int notiPrivateId = isOngoing ? __notifyPrivateIdForOngoing : __notifyPrivateId;
+       __lastNotifyPrivateId = notiPrivateId;
        notification_h notiHandle = null;
        bundle* pBundle = null;
        bool needUpdate = false;
@@ -759,6 +765,10 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
                }
        }
 
+       // light
+       Color lightColor;
+       int lightColor32 = 0;
+
        // Set - service
        int retVal = SERVICE_ERROR_NONE;
        int previousDisplaySet = NOTIFICATION_DISPLAY_APP_ALL;
@@ -894,6 +904,29 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
                SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification area failed.", GetErrorMessage(r));
        }
 
+       // Set LED
+       lightColor = pRequestImpl->GetColor();
+       lightColor32 = lightColor.GetRGB32();
+
+       if (lightColor32 == 0 || (pRequestImpl->GetOnTime() == 0))
+       {       // Turn off case
+               if (needUpdate && __lightActivated)
+               {       // Not for first insertion
+                       r = ConvertNotificationResult(notification_set_led(notiHandle, NOTIFICATION_LED_OP_OFF, 0x00000000));
+                       SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification led failed.", GetErrorMessage(r));
+                       __lightActivated = false;
+               }
+       }
+       else
+       {
+               r = ConvertNotificationResult(notification_set_led(notiHandle, NOTIFICATION_LED_OP_ON_CUSTOM_COLOR, lightColor32));
+               SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification led failed.", GetErrorMessage(r));
+
+               r = ConvertNotificationResult(notification_set_led_time_period(notiHandle, pRequestImpl->GetOnTime(), pRequestImpl->GetOffTime()));
+               SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Setting the notification led time period failed.", GetErrorMessage(r));
+               __lightActivated = true;
+       }
+
        // insert for new notification
        if (!needUpdate)
        {       // new
@@ -910,6 +943,7 @@ _NotificationManagerImpl::NotifyMessage(_NotifyType notifyType, bool isOngoing,
                {
                        __notifyPrivateId = notiPrivateId;
                }
+               __lastNotifyPrivateId = notiPrivateId;
        }
        else
        {
@@ -951,7 +985,8 @@ _NotificationManagerImpl::RemoveNotification(bool onGoing)
 
        if (notiPrivateId != -1)
        {
-               notification_h notiHandle = notification_load(null, notiPrivateId);
+               std::unique_ptr<char[]> pAppIdTemp(_StringConverter::CopyToCharArrayN(__lastAppId));
+               notification_h notiHandle = notification_load(pAppIdTemp.get(), notiPrivateId);
                if (notiHandle)
                {
                        err = notification_delete(notiHandle);
@@ -1087,6 +1122,18 @@ _NotificationManagerImpl::RemoveBadgeEventListener(IBadgeEventListener& listener
        return _BadgeManagerImpl::GetInstance()->RemovePrimaryBadgeEventListener(*this);
 }
 
+int
+_NotificationManagerImpl::GetLastNotificationId(void) const
+{
+       return __lastNotifyPrivateId;
+}
+
+const Tizen::Base::String&
+_NotificationManagerImpl::GetLastAppId(void) const
+{
+       return __lastAppId;
+}
+
 void
 _NotificationManagerImpl::OnBadgeUpdated(const Tizen::App::AppId& appId, int badgeNumber)
 {