Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.Download / Tizen.Content.Download / Notification.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 using System;
18 using Tizen.Applications;
19
20 namespace Tizen.Content.Download
21 {
22     /// <summary>
23     /// The Notification class consists of all the properties required to set notifications for download operation.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public class Notification
27     {
28         private int _downloadId;
29
30         internal Notification(int requestId)
31         {
32             _downloadId = requestId;
33         }
34
35         /// <summary>
36         /// Title of the notification.
37         /// If user tries to get before setting, empty string is returned.
38         /// </summary>
39         /// <since_tizen> 3 </since_tizen>
40         /// <privilege>http://tizen.org/privilege/download</privilege>
41         /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception>
42         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation</exception>
43         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
44         public string Title
45         {
46             get
47             {
48                 string title;
49                 int ret = Interop.Download.GetNotificationTitle(_downloadId, out title);
50                 if (ret != (int)DownloadError.None)
51                 {
52                     Log.Error(Globals.LogTag, "Failed to get Notification Title, " + (DownloadError)ret);
53                     return String.Empty;
54                 }
55                 return title;
56             }
57             set
58             {
59                 int ret = Interop.Download.SetNotificationTitle(_downloadId, value.ToString());
60                 if (ret != (int)DownloadError.None)
61                 {
62                     DownloadErrorFactory.ThrowException(ret, "Failed to set Notification Title");
63                 }
64             }
65         }
66
67         /// <summary>
68         /// Description of the notification.
69         /// If user tries to get before setting, empty string is returned.
70         /// </summary>
71         /// <since_tizen> 3 </since_tizen>
72         /// <privilege>http://tizen.org/privilege/download</privilege>
73         /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception>
74         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation</exception>
75         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
76         public string Description
77         {
78             get
79             {
80                 string description;
81                 int ret = Interop.Download.GetNotificationDescription(_downloadId, out description);
82                 if (ret != (int)DownloadError.None)
83                 {
84                     Log.Error(Globals.LogTag, "Failed to get Notification Description, " + (DownloadError)ret);
85                     return String.Empty;
86                 }
87                 return description;
88             }
89             set
90             {
91                 int ret = Interop.Download.SetNotificationDescription(_downloadId, value.ToString());
92                 if (ret != (int)DownloadError.None)
93                 {
94                     DownloadErrorFactory.ThrowException(ret, "Failed to set Notification Description");
95                 }
96             }
97         }
98
99         /// <summary>
100         /// Type of Notification.
101         /// If user tries to get before setting, default NotificationType None is returned.
102         /// </summary>
103         /// <since_tizen> 3 </since_tizen>
104         /// <privilege>http://tizen.org/privilege/download</privilege>
105         /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception>
106         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation</exception>
107         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
108         public NotificationType Type
109         {
110             get
111             {
112                 int type;
113                 int ret = Interop.Download.GetNotificationType(_downloadId, out type);
114                 if (ret != (int)DownloadError.None)
115                 {
116                     Log.Error(Globals.LogTag, "Failed to get NotificationType, " + (DownloadError)ret);
117                     return 0;
118                 }
119                 return (NotificationType)type;
120             }
121             set
122             {
123                 int ret = Interop.Download.SetNotificationType(_downloadId, (int)value);
124                 if (ret != (int)DownloadError.None)
125                 {
126                     DownloadErrorFactory.ThrowException(ret, "Failed to set NotificationType");
127                 }
128             }
129         }
130
131         /// <summary>
132         /// AppControl for an ongoing download notification.
133         /// If user tries to get before setting, null is returned.
134         /// </summary>
135         /// <since_tizen> 3 </since_tizen>
136         /// <privilege>http://tizen.org/privilege/download</privilege>
137         /// <remarks>
138         /// When the notification message is clicked, the action is decided by the app control.
139         /// </remarks>
140         /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception>
141         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation</exception>
142         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
143         public AppControl AppControlOngoing
144         {
145             get
146             {
147                 SafeAppControlHandle handle;
148                 int ret = Interop.Download.GetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Downloading, out handle);
149                 if (ret != (int)DownloadError.None)
150                 {
151                     Log.Error(Globals.LogTag, "Failed to get Ongoing type NotificationAppControl, " + (DownloadError)ret);
152                     return null;
153                 }
154                 return new AppControl(handle);
155             }
156             set
157             {
158                 int ret = Interop.Download.SetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Downloading, value.SafeAppControlHandle);
159                 if (ret != (int)DownloadError.None)
160                 {
161                     DownloadErrorFactory.ThrowException(ret, "Failed to set Ongoing type NotificationAppControl");
162                 }
163             }
164         }
165
166         /// <summary>
167         /// AppControl for a completed download notification.
168         /// If user tries to get before setting, null is returned.
169         /// </summary>
170         /// <since_tizen> 3 </since_tizen>
171         /// <privilege>http://tizen.org/privilege/download</privilege>
172         /// <remarks>
173         /// When the notification message is clicked, the action is decided by the app control
174         /// </remarks>
175         /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception>
176         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation</exception>
177         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
178         public AppControl AppControlCompleted
179         {
180             get
181             {
182                 SafeAppControlHandle handle;
183                 int ret = Interop.Download.GetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Completed, out handle);
184                 if (ret != (int)DownloadError.None)
185                 {
186                     Log.Error(Globals.LogTag, "Failed to get Complete type NotificationAppControl, " + (DownloadError)ret);
187                     return null;
188                 }
189                 return new AppControl(handle);
190             }
191             set
192             {
193                 int ret = Interop.Download.SetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Completed, value.SafeAppControlHandle);
194                 if (ret != (int)DownloadError.None)
195                 {
196                     DownloadErrorFactory.ThrowException(ret, "Failed to set Complete type NotificationAppControl");
197                 }
198             }
199         }
200
201         /// <summary>
202         /// AppControl for a failed download notification.
203         /// If user tries to get before setting, null is returned.
204         /// </summary>
205         /// <since_tizen> 3 </since_tizen>
206         /// <privilege>http://tizen.org/privilege/download</privilege>
207         /// <remarks>
208         /// When the notification message is clicked, the action is decided by the app control
209         /// </remarks>
210         /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception>
211         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation</exception>
212         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
213         public AppControl AppControlFailed
214         {
215             get
216             {
217                 SafeAppControlHandle handle;
218                 int ret = Interop.Download.GetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Failed, out handle);
219                 if (ret != (int)DownloadError.None)
220                 {
221                     Log.Error(Globals.LogTag, "Failed to get Fail type NotificationAppControl, " + (DownloadError)ret);
222                     return null;
223                 }
224                 return new AppControl(handle);
225             }
226             set
227             {
228                 int ret = Interop.Download.SetNotificationAppControl(_downloadId, (int)NotificationAppControlType.Failed, value.SafeAppControlHandle);
229                 if (ret != (int)DownloadError.None)
230                 {
231                     DownloadErrorFactory.ThrowException(ret, "Failed to set Fail type NotificationAppControl");
232                 }
233             }
234         }
235     }
236 }
237