Add check box for notification (#5342)
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.NotificationEventListener / Tizen.Applications.NotificationEventListener / NotificationListenerManager.cs
index 5f02395..e6c1382 100755 (executable)
@@ -21,12 +21,15 @@ namespace Tizen.Applications.NotificationEventListener
     using System.ComponentModel;
     using System.Runtime.InteropServices;
 
+    using Tizen.Internals;
+
     /// <summary>
     /// This class provides a way to register callback function for some notification events.
     /// </summary>
     /// <remarks>
-    /// The event listener can use this class to get a list of notification or to clear notifications.
+    /// The event listener can use this class to get a list of notifications or to clear notifications.
     /// </remarks>
+    /// <since_tizen> 4 </since_tizen>
     public partial class NotificationListenerManager
     {
         private const string LogTag = "Tizen.Applications.NotificationEventListener";
@@ -39,6 +42,7 @@ namespace Tizen.Applications.NotificationEventListener
 
         private static Interop.NotificationEventListener.ChangedCallback callback;
 
+        [NativeStruct("notification_op", Include="notification_type.h", PkgConfig="notification")]
         [StructLayout(LayoutKind.Sequential)]
         private struct NotificationOperation
         {
@@ -61,13 +65,14 @@ namespace Tizen.Applications.NotificationEventListener
         }
 
         /// <summary>
-        /// Registers a callback for notification insert event.
+        /// Event handler for notification insert event.
         /// </summary>
-        /// <exception cref="ArgumentException">Thrown in case of Invalid parameter.</exception>
-        /// <exception cref="UnauthorizedAccessException"> Thrown in case of Permission deny.</exception>
+        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
+        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
         /// <privilege>http://tizen.org/privilege/notification</privilege>
-        public static event EventHandler<NotificationEventArgs> NotificationAddEventHandler
+        /// <since_tizen> 4 </since_tizen>
+        public static event EventHandler<NotificationEventArgs> Added
         {
             add
             {
@@ -107,13 +112,14 @@ namespace Tizen.Applications.NotificationEventListener
         }
 
         /// <summary>
-        /// Registers a callback for notification update event.
+        /// Event handler for notification update event.
         /// </summary>
-        /// <exception cref="ArgumentException">Thrown in case of Invalid parameter.</exception>
-        /// <exception cref="UnauthorizedAccessException"> Thrown in case of Permission deny.</exception>
+        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
+        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
         /// <privilege>http://tizen.org/privilege/notification</privilege>
-        public static event EventHandler<NotificationEventArgs> NotificationUpdateEventHandler
+        /// <since_tizen> 4 </since_tizen>
+        public static event EventHandler<NotificationEventArgs> Updated
         {
             add
             {
@@ -153,13 +159,14 @@ namespace Tizen.Applications.NotificationEventListener
         }
 
         /// <summary>
-        /// Registers a callback for notification delete event.
+        /// Event handler for notification delete event.
         /// </summary>
-        /// <exception cref="ArgumentException">Thrown in case of Invalid parameter.</exception>
-        /// <exception cref="UnauthorizedAccessException"> Thrown in case of Permission deny.</exception>
+        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
+        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
         /// <privilege>http://tizen.org/privilege/notification</privilege>
-        public static event EventHandler<NotificationDeleteEventArgs> NotificationDeleteEventHandler
+        /// <since_tizen> 4 </since_tizen>
+        public static event EventHandler<NotificationDeleteEventArgs> Deleted
         {
             add
             {
@@ -286,14 +293,15 @@ namespace Tizen.Applications.NotificationEventListener
         }
 
         /// <summary>
-        /// Deletes a Notification with appId and uniqueNumber.
+        /// Deletes a notification with appId and uniqueNumber.
         /// </summary>
         /// <param name="appId">The name of the application you want to delete.</param>
         /// <param name="uniqueNumber">The unique number of the notification.</param>
-        /// <exception cref="ArgumentException">Thrown in case of Invalid parameter.</exception>
-        /// <exception cref="UnauthorizedAccessException"> Thrown in case of Permission deny.</exception>
+        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
+        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
         /// <privilege>http://tizen.org/privilege/notification</privilege>
+        /// <since_tizen> 4 </since_tizen>
         public static void Delete(string appId, int uniqueNumber)
         {
             Interop.NotificationEventListener.ErrorCode err;
@@ -311,11 +319,12 @@ namespace Tizen.Applications.NotificationEventListener
         }
 
         /// <summary>
-        /// Deletes all Notification.
+        /// Deletes all notifications.
         /// </summary>
-        /// <exception cref="UnauthorizedAccessException"> Thrown in case of Permission deny.</exception>
+        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
         /// <privilege>http://tizen.org/privilege/notification</privilege>
+        /// <since_tizen> 4 </since_tizen>
         public static void DeleteAll()
         {
             Interop.NotificationEventListener.ErrorCode err;
@@ -334,11 +343,12 @@ namespace Tizen.Applications.NotificationEventListener
         }
 
         /// <summary>
-        /// Returns the notification list handle.
+        /// Returns the notification list.
         /// </summary>
-        /// <exception cref="UnauthorizedAccessException"> Thrown in case of Permission deny.</exception>
+        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
         /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
         /// <privilege>http://tizen.org/privilege/notification</privilege>
+        /// <since_tizen> 4 </since_tizen>
         public static IList<NotificationEventArgs> GetList()
         {
             Interop.NotificationEventListener.ErrorCode err;
@@ -346,7 +356,7 @@ namespace Tizen.Applications.NotificationEventListener
             IntPtr currentList = IntPtr.Zero;
             IList<NotificationEventArgs> list = new List<NotificationEventArgs>();
 
-            err = Interop.NotificationEventListener.GetList(NotificationType.Notification, -1, out notificationList);
+            err = Interop.NotificationEventListener.GetList(NotificationType.None, -1, out notificationList);
             if (err != Interop.NotificationEventListener.ErrorCode.None)
             {
                 throw NotificationEventListenerErrorFactory.GetException(err, "unable to get notification list");
@@ -370,48 +380,122 @@ namespace Tizen.Applications.NotificationEventListener
                 }
 
                 Interop.NotificationEventListener.NotificationListFree(notificationList);
-                notificationList = IntPtr.Zero;
             }
 
-            err = Interop.NotificationEventListener.GetList(NotificationType.Ongoing, -1, out notificationList);
+            return list;
+        }
+
+        /// <summary>
+        /// Sends occured event from viewer application to the notification owner.
+        /// </summary>
+        /// <param name="uniqueNumber">The unique number of the notification.</param>
+        /// <param name="type">Event type on notification.</param>
+        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
+        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
+        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+        /// <privilege>http://tizen.org/privilege/notification</privilege>
+        /// <since_tizen> 4 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SendEvent(int uniqueNumber, UserEventType type)
+        {
+            Interop.NotificationEventListener.ErrorCode err;
+
+            err = Interop.NotificationEventListener.SendEvent(uniqueNumber, (int)type);
             if (err != Interop.NotificationEventListener.ErrorCode.None)
             {
-                throw NotificationEventListenerErrorFactory.GetException(err, "unable to get notification list");
+                throw NotificationEventListenerErrorFactory.GetException(err, "failed to send event");
             }
+        }
 
-            if (notificationList != IntPtr.Zero)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetChecked(NotificationEventArgs eventargs, bool checkedValue)
+        {
+            Interop.NotificationEventListener.ErrorCode err;
+
+            err = Interop.NotificationEventListener.SetCheckedValue(eventargs.Handle, checkedValue);
+            if (err != Interop.NotificationEventListener.ErrorCode.None)
             {
-                currentList = notificationList;
-                while (currentList != IntPtr.Zero)
-                {
-                    IntPtr notification;
-                    NotificationEventArgs eventargs = new NotificationEventArgs();
+                throw NotificationEventListenerErrorFactory.GetException(err, "failed to set checked");
+            }
+        }
 
-                    notification = Interop.NotificationEventListener.GetData(currentList);
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SendEventWithNotification(NotificationEventArgs eventargs, UserEventType type)
+        {
+            Interop.NotificationEventListener.ErrorCode err;
 
-                    eventargs = NotificationEventArgsBinder.BindObject(notification, false);
+            err = Interop.NotificationEventListener.SendEventWithNotification(eventargs.Handle, (int)type);
+            if (err != Interop.NotificationEventListener.ErrorCode.None)
+            {
+                throw NotificationEventListenerErrorFactory.GetException(err, "failed to send event");
+            }
+        }
 
-                    list.Add(eventargs);
+        /// <summary>
+        /// Returns NotificationEventArgs by UniqueNumber.
+        /// </summary>
+        /// <param name="uniqueNumber">The unique number of the Notification.</param>
+        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
+        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
+        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+        /// <privilege>http://tizen.org/privilege/notification</privilege>
+        /// <since_tizen> 4 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static NotificationEventArgs GetNotificationEventArgs(int uniqueNumber)
+        {
+            if (uniqueNumber <= 0)
+            {
+                throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "Invalid parameter");
+            }
 
-                    currentList = Interop.NotificationEventListener.GetNext(currentList);
+            IntPtr notificationPtr = Interop.NotificationEventListener.LoadNotification(null, uniqueNumber);
+            if (notificationPtr == IntPtr.Zero)
+            {
+                int err = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
+                if (err.Equals((int)Interop.NotificationEventListener.ErrorCode.DbError))
+                {
+                    throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidParameter, "Not exist");
+                }
+                else
+                {
+                    throw NotificationEventListenerErrorFactory.GetException((Interop.NotificationEventListener.ErrorCode)err, "failed to get NotificationEventArgs");
                 }
-
-                Interop.NotificationEventListener.NotificationListFree(notificationList);
             }
 
-            return list;
+            NotificationEventArgs eventArgs = new NotificationEventArgs();
+            eventArgs = NotificationEventArgsBinder.BindObject(notificationPtr, false);
+
+            return eventArgs;
         }
 
+        /// <summary>
+        /// Gets the number of all notifications
+        /// </summary>
+        /// <returns>The number of all notifications</returns>
+        /// <exception cref="UnauthorizedAccessException"> Thrown in case of a permission is denied.</exception>
+        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+        /// <privilege>http://tizen.org/privilege/notification</privilege>
+        /// <since_tizen> 4 </since_tizen>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static void SendEvent(int uniqueNumber, UserEventType type)
+        public static int GetAllCount()
         {
-            Interop.NotificationEventListener.ErrorCode err;
+            int count;
+            Interop.NotificationEventListener.ErrorCode error;
 
-            err = Interop.NotificationEventListener.SendEvent(uniqueNumber, (int)type);
-            if (err != Interop.NotificationEventListener.ErrorCode.None)
+            error = Interop.NotificationEventListener.GetAllCount(NotificationType.None, out count);
+            if (error != Interop.NotificationEventListener.ErrorCode.None)
             {
-                throw NotificationEventListenerErrorFactory.GetException(err, "failed to send event");
+                if (error == Interop.NotificationEventListener.ErrorCode.PermissionDenied)
+                {
+                    throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.PermissionDenied, "failed to get all count");
+                }
+                else
+                {
+                    throw NotificationEventListenerErrorFactory.GetException(Interop.NotificationEventListener.ErrorCode.InvalidOperation, "failed to get all count");
+                }
             }
+
+            return count;
         }
     }
 }