Tizen 2.1 base
[framework/osp/app-controls.git] / src / message-app-control / MessageAppControlDllEntry.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file         BluetoothAppControlDllEntry.cpp
20  * @brief       This is the implementation for the BluetoothAppControlDllEntry.cpp class.
21  */
22
23 #include <appsvc/appsvc.h>
24
25 #include <FBaseSysLog.h>
26 #include <FAppAppControl.h>
27
28 #include <FBase_StringConverter.h>
29 #include <FApp_AppControlManager.h>
30 #include <FApp_AppMessageImpl.h>
31 #include <FApp_Aul.h>
32
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42
43 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
44 result _OSP_EXPORT_ TerminateAppControl(int req);
45 static int __processId = -1;
46
47 static const wchar_t __allowedAppControlMessageTable[][2][64] =
48 {
49         {L"osp.appcontrol.MESSAGE", L"osp.appcontrol.operation.EDIT"},
50         {L"osp.appcontrol.provider.message", L"osp.appcontrol.operation.compose"},
51         {L"http://tizen.org/appcontrol/provider/message", L"http://tizen.org/appcontrol/operation/compose"},
52         {L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose"},
53 };
54
55 static const wchar_t __allowedAppControlEmailTable[][2][64] =
56 {
57         {L"osp.appcontrol.EMAIL", L"osp.appcontrol.operation.EDIT"},
58         {L"osp.appcontrol.provider.email", L"osp.appcontrol.operation.compose"},
59         {L"http://tizen.org/appcontrol/provider/email", L"http://tizen.org/appcontrol/operation/compose"},
60         {L"tizen.email", L"http://tizen.org/appcontrol/operation/compose"},
61 };
62
63
64 result
65 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
66 {
67         SysLog(NID_APP, "StartAppControl: Entry to Message AppControl");
68
69         result r = E_SUCCESS;
70
71         SysLog(NID_APP, "aId : %ls, oId : %ls", aId.GetPointer(), oId.GetPointer());
72
73         const bool isMessage = _AppControlManager::IsAllowedAppControl(__allowedAppControlMessageTable, 4, aId, oId);
74         const bool isEmail = _AppControlManager::IsAllowedAppControl(__allowedAppControlEmailTable, 4, aId, oId);
75
76         SysTryReturnResult(NID_APP, isMessage || isEmail, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
77
78         if (isMessage)
79         {
80                 SysLog(NID_APP, "Message AppControl starts..");
81
82                 _AppMessageImpl msg;
83                 msg.AddData(pMap);
84
85                 // to
86                 String tmp = msg.GetValue(L"to");
87                 if (!tmp.IsEmpty())
88                 {
89                         // cc
90                         String tmpCc = msg.GetValue(L"cc");
91                         if (!tmpCc.IsEmpty())
92                         {
93                                 tmp.Append(L';' + tmpCc);
94                         }
95
96                         // bcc
97                         String tmpBcc = msg.GetValue(L"bcc");
98                         if (!tmpBcc.IsEmpty())
99                         {
100                                 tmp.Append(L';' + tmpBcc);
101                         }
102
103                         tmp.Replace(L';', L',');
104                         msg.AddData(SERVICE_DATA_TO, tmp);
105                 }
106
107                 // subject
108                 tmp = msg.GetValue(L"subject");
109                 if (!tmp.IsEmpty())
110                 {
111                         SysLog(NID_APP, "subject: [%ls]", tmp.GetPointer());
112                         msg.AddData(SERVICE_DATA_SUBJECT, tmp);
113                 }
114
115                 // text
116                 tmp = msg.GetValue(L"text");
117                 if (!tmp.IsEmpty())
118                 {
119                         SysLog(NID_APP, "text: [%ls]", tmp.GetPointer());
120                         msg.AddData(SERVICE_DATA_TEXT, tmp);
121                 }
122
123                 // vcard
124                 String tmpVcard = msg.GetValue(L"attachVcard");
125
126                 // vcalendar
127                 String tmpVcal = msg.GetValue(L"attachVcalendar");
128
129                 // video
130                 String tmpVideo = msg.GetValue(L"attachVideo");
131                 if (!tmpVideo.IsEmpty())
132                 {
133                         String delim(L'\n');
134                         String tmpTotal = tmpVcard + delim + tmpVcal + delim + tmpVideo;
135                         SysLog(NID_APP, "total: [%ls]", tmpTotal.GetPointer());
136                         msg.AddData(L"ATTACHFILE", tmpTotal);
137                 }
138                 else
139                 {
140                         // image
141                         String tmpImage = msg.GetValue(L"attachImage");
142
143                         // audio
144                         String tmpAudio = msg.GetValue(L"attachAudio");
145
146                         String delim(L'\n');
147                         String tmpTotal = tmpVcard + delim + tmpVcal + delim + tmpImage + delim + tmpAudio;
148                         SysLog(NID_APP, "total: [%ls]", tmpTotal.GetPointer());
149                         msg.AddData(L"ATTACHFILE", tmpTotal);
150                 }
151
152                 __processId = _AppControlManager::GetInstance()->Launch(msg, "msg-composer-efl", APPSVC_OPERATION_SEND, NULL, NULL, NULL, 0);
153
154                 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Email AppControl is failed.");
155                 SysLog(NID_APP, "StartAppControl: Launching Message AppControl succeeded.");
156
157         }
158         if (isEmail)
159         {
160                 SysLog(NID_APP, "Email AppControl starts..");
161
162                 char* pUri = NULL;
163                 _AppMessageImpl msg;
164                 msg.AddData(pMap);
165
166                 String attach = msg.GetValue(L"attachments");
167                 if (!attach.IsEmpty())
168                 {
169                         pUri = _StringConverter::CopyToCharArrayN(attach);
170                 }
171
172                 String tmp = msg.GetValue(L"to");
173                 if (!tmp.IsEmpty())
174                 {
175                         msg.AddData(SERVICE_DATA_TO, tmp);
176                 }
177
178                 tmp = msg.GetValue(L"cc");
179                 if (!tmp.IsEmpty())
180                 {
181                         msg.AddData(SERVICE_DATA_CC, tmp);
182                 }
183
184                 tmp = msg.GetValue(L"bcc");
185                 if (!tmp.IsEmpty())
186                 {
187                         msg.AddData(SERVICE_DATA_BCC, tmp);
188                 }
189
190                 tmp = msg.GetValue(L"subject");
191                 if (!tmp.IsEmpty())
192                 {
193                         msg.AddData(SERVICE_DATA_SUBJECT, tmp);
194                 }
195
196                 tmp = msg.GetValue(L"text");
197                 if (!tmp.IsEmpty())
198                 {
199                         msg.AddData(SERVICE_DATA_TEXT, tmp);
200                 }
201
202                 __processId = _AppControlManager::GetInstance()->Launch(msg, "email-composer-efl", APPSVC_OPERATION_SEND, NULL, pUri, NULL, 0);
203
204                 delete [] pUri;
205
206                 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Email AppControl is failed.");
207                 SysLog(NID_APP, "StartAppControl: Launching Email AppControl succeeded.");
208         }
209
210         return r;
211 }
212
213 result
214 TerminateAppControl(int req)
215 {
216         if (__processId >= 0)
217         {
218                 _Aul::TerminateApplicationByPid(__processId);           
219         }
220         return E_SUCCESS;
221 }
222
223 #ifdef __cplusplus
224 }
225 #endif