2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <Commons/Exception.h>
20 #include "BinarySms.h"
23 #include "EmptyMessage.h"
24 #include "MessageFactory.h"
25 #include "IAttachment.h"
29 using namespace WrtDeviceApis::Commons;
30 using namespace DeviceAPI::Messaging;
35 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
36 const std::string& id)
43 IEmail* retEmail = NULL;
44 IBinarySms* retBinarySms = NULL;
45 IEmptyMessage* retEmptyMessage = NULL;
47 IMessagePtr imsg(NULL);
52 LoggerD("creation sms message with id");
54 imsg = (IMessagePtr) retSms;
60 LoggerD("creation binary sms message with id");
61 retBinarySms = new BinarySms(id);
62 imsg = (IMessagePtr) retBinarySms;
68 LoggerD("creation mms message with id");
70 imsg = (IMessagePtr) retMms;
72 std::vector<IAttachmentPtr> attachments = retMms->getAttachments();
75 for (; idx < attachments.size() ; idx++ )
77 LoggerD("set Messsage ID = " << attachments[idx]->getAttachmentID());
78 attachments[idx]->setMessage(imsg);
84 LoggerD("creation email message with id");
85 retEmail= new Email(id);
86 imsg = (IMessagePtr) retEmail;
91 LoggerD("creation empty message with id");
92 retEmptyMessage = new EmptyMessage(id);
93 imsg = (IMessagePtr) retEmptyMessage;
97 LoggerE("creation error, unknown message type");
105 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
108 std::ostringstream stream;
110 std::string idStr = stream.str();
111 return createMessage(msgType, idStr);
114 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
115 const int id, const msg_struct_t msg_data)
118 IMessage* retVal = NULL;
119 std::ostringstream stream;
121 std::string idStr = stream.str();
125 LoggerD("creation sms message with data");
126 retVal = new Sms(idStr, msg_data);
130 LoggerD("creation mms message with data");
131 retVal = new Mms(idStr, msg_data);
135 LoggerD("creation empty message with data");
136 retVal = new EmptyMessage(idStr);
140 LoggerE("creation error, unknown message type");
144 return IMessagePtr(retVal);
147 IMessagePtr MessageFactory::createMessage(const MessageType msgType,
148 EmailAccountInfo& account, const std::string& id )
150 LoggerI("enter, CreateMessage with account");
152 std::ostringstream stream;
154 std::string idStr = stream.str();
156 LoggerI("createMessage with , idstr =" << idStr);
158 if (msgType == EMAIL)
160 LoggerD("Account Address:" << &account);
161 IMessage* retVal = NULL;
162 LoggerD("creation email message with account");
163 retVal = new Email(account);
164 return IMessagePtr(retVal);
167 return createMessage(msgType, idStr);
171 IMessagePtr MessageFactory::createEmailMessage(const int accountId, const int mailId)
173 LoggerI("enter, Create Email Message with account ID");
174 IEmail* email = NULL;
175 LoggerD("creation email message with account ID");
176 std::stringstream stream;
181 ThrowMsg(UnknownException, "Couldn't convert e-mail account id");
184 email = new Email(stream.str(), accountId);
186 IMessagePtr imsg(email);
188 std::vector<IAttachmentPtr> attachments = email->getAttachments();
189 std::vector<IAttachmentPtr> inlineAttachments = email->getInlineAttachments();
191 for (idx = 0; idx < attachments.size() ; idx++ )
193 LoggerD("set Attachment ID = " << attachments[idx]->getAttachmentID());
194 attachments[idx]->setMessage(imsg);
197 for (idx = 0; idx < inlineAttachments.size() ; idx++ )
199 LoggerD("set inline Attachment ID = " << inlineAttachments[idx]->getAttachmentID());
200 inlineAttachments[idx]->setMessage(imsg);
207 IMessage* retVal = NULL;
208 LoggerD("creation email message with account ID");
211 std::stringstream stream;
214 ThrowMsg(UnknownException, "Couldn't convert e-mail account id");
217 retVal = new Email(stream.str(), accountId);
223 return IMessagePtr(retVal);
227 IMessagePtr MessageFactory::createEmailMessage()
229 LoggerI("enter, Create Temporary Email Message without account");
231 IEmail* email = NULL;
233 email = new Email(TEMP_FOLDER); //create dumy email.
235 IMessagePtr imsg(email);
240 IMessagePtr MessageFactory::createVirtualMessage()
242 return IMessagePtr(new VirtualMessage());
245 VirtualMessagePtr MessageFactory::convertToVirtualMessage(IMessagePtr msg)
247 VirtualMessagePtr tmp = DPL::DynamicPointerCast<VirtualMessage >(msg);
249 ThrowMsg(ConversionException,
250 "Conversion IMessage to VirtualMessagePtr error");
255 ISmsPtr MessageFactory::convertToSms(IMessagePtr msg)
257 ISmsPtr tmp = DPL::DynamicPointerCast<ISms >(msg);
259 ThrowMsg(ConversionException, "Conversion IMessage to ISms error");
264 IBinarySmsPtr MessageFactory::convertToBinarySms(IMessagePtr msg)
266 IBinarySmsPtr tmp = DPL::DynamicPointerCast<IBinarySms >(msg);
268 ThrowMsg(ConversionException, "Conversion IMessage to IBinarySms error");
273 IMmsPtr MessageFactory::convertToMms(IMessagePtr msg)
275 IMmsPtr tmp = DPL::DynamicPointerCast<IMms >(msg);
277 ThrowMsg(ConversionException, "Conversion IMessage to IMms error");
282 IEmailPtr MessageFactory::convertToEmail(IMessagePtr msg)
284 IEmailPtr tmp = DPL::DynamicPointerCast<IEmail >(msg);
286 ThrowMsg(ConversionException, "Conversion IMessage to IEmail error");