[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.Messaging / Tizen.Messaging.Messages / MmsMessage.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 System.Collections.Generic;
19
20 namespace Tizen.Messaging.Messages
21 {
22     /// <summary>
23     /// This class represents multimedia messages.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public class MmsMessage : Message
27     {
28         private IList<MessagesAttachment> _attachment = new List<MessagesAttachment>();
29
30         /// <summary>
31         /// Creates a multimedia message.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         public MmsMessage() : base(MessageType.Mms)
35         {
36         }
37
38         internal MmsMessage(IntPtr messageHandle) : base(messageHandle)
39         {
40             GetAllAttachments();
41         }
42
43         /// <summary>
44         /// The subject of the multimedia message.
45         /// </summary>
46         /// <since_tizen> 3 </since_tizen>
47         public string Subject
48         {
49             get
50             {
51                 string subject = null;
52                 int ret = Interop.Messages.GetSubject(_messageHandle, out subject);
53                 if (ret != (int)MessagesError.None)
54                 {
55                     Log.Error(Globals.LogTag, "Failed to get subject, Error - " + (MessagesError)ret);
56                 }
57
58                 return subject;
59             }
60             set
61             {
62                 int ret = Interop.Messages.SetSubject(_messageHandle, value);
63                 if (ret != (int)MessagesError.None)
64                 {
65                     Log.Error(Globals.LogTag, "Failed to set subject, Error - " + (MessagesError)ret);
66                     MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
67                 }
68             }
69         }
70
71         /// <summary>
72         /// The collection of normal message recipients.
73         /// </summary>
74         /// <since_tizen> 3 </since_tizen>
75         public ICollection<MessagesAddress> To
76         {
77             get
78             {
79                 return _to;
80             }
81         }
82
83         /// <summary>
84         /// The collection of CC (carbon copy) message recipients.
85         /// </summary>
86         /// <since_tizen> 3 </since_tizen>
87         public ICollection<MessagesAddress> Cc
88         {
89             get
90             {
91                 return _cc;
92             }
93         }
94
95         /// <summary>
96         /// The collection of BCC (blind carbon copy) message recipients.
97         /// </summary>
98         /// <since_tizen> 3 </since_tizen>
99         public ICollection<MessagesAddress> Bcc
100         {
101             get
102             {
103                 return _bcc;
104             }
105         }
106
107         /// <summary>
108         /// The list of attachment files.
109         /// </summary>
110         /// <since_tizen> 3 </since_tizen>
111         public IList<MessagesAttachment> Attachments
112         {
113             get
114             {
115                 return _attachment;
116             }
117         }
118
119         internal void SetAttachments()
120         {
121             foreach (var it in _attachment)
122             {
123                 AddAttachment(it);
124             }
125         }
126
127         private void AddAttachment(MessagesAttachment attach)
128         {
129             int ret = Interop.Messages.AddAttachment(_messageHandle, (int)attach.Type, attach.FilePath);
130             if (ret != (int)MessagesError.None)
131             {
132                 Log.Error(Globals.LogTag, "Failed to add attachment, Error - " + (MessagesError)ret);
133                 MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
134             }
135         }
136
137         private void GetAllAttachments()
138         {
139             int count;
140
141             int ret = Interop.Messages.GetAttachmentCount(_messageHandle, out count);
142             if (ret != (int)MessagesError.None)
143             {
144                 Log.Error(Globals.LogTag, "Failed to get attachment count, Error - " + (MessagesError)ret);
145                 MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
146             }
147
148             string path;
149             int type;
150             var attachmentList = new List<MessagesAttachment>();
151
152             for (int i = 0; i < count; i++)
153             {
154                 ret = Interop.Messages.GetAttachment(_messageHandle, i, out type, out path);
155                 if (ret != (int)MessagesError.None)
156                 {
157                     Log.Error(Globals.LogTag, "Failed to get attachment, Error - " + (MessagesError)ret);
158                     MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle);
159                 }
160
161                 var attachmentItem = new MessagesAttachment((MediaType)type, path);
162                 attachmentList.Add(attachmentItem);
163             }
164
165             _attachment = attachmentList;
166         }
167
168     }
169 }