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.
19 #include <dpl/errno_string.h>
20 #include <Commons/Exception.h>
21 #include "IAttachment.h"
30 using namespace WrtDeviceApis::Commons;
33 //--------------------------------------------------------------------------
37 IAttachment::IAttachment() :
38 m_validAttachment(false),
39 m_hasDummyFile(false),
44 void IAttachment::init(const string& fullPath,
50 std::string l_fullPath;
51 LoggerD("FULL Path : " << fullPath);
54 LoggerD("translating path");
55 l_fullPath = getRealPath(fullPath);
57 l_fullPath = fullPath;
59 LoggerD("real path " << l_fullPath);
61 char buff[PATH_MAX + 1];
62 if ((NULL == realpath(l_fullPath.c_str(), buff)) || (l_fullPath.size() > PATH_MAX + 1)) {
63 std::string errnoString = DPL::GetErrnoString();
64 LoggerE("get full path problem " << errnoString);
66 m_attachFullPath = "";
67 m_attachShortName = "";
68 m_isCreatedProperly = true;
69 m_validAttachment = false;
73 if (-1 == lstat(buff, &buffer)) {
74 LoggerE("Attachment file not exist");
75 m_validAttachment = false;
78 if (!S_ISREG(buffer.st_mode)) {
79 LoggerE("Attachment file not exist");
80 m_validAttachment = false;
82 m_fileSize = buffer.st_size;
83 m_attachFullPath = l_fullPath;
85 m_isCreatedProperly = true;
86 m_validAttachment = true;
89 Catch(WrtDeviceApis::Commons::Exception) {
90 LoggerE("attachment not created properly");
91 m_isCreatedProperly = false;
95 IAttachment::~IAttachment()
100 string IAttachment::getShortName() const
102 return m_attachShortName;
105 string IAttachment::getFullPath() const
107 return m_attachFullPath;
110 unsigned int IAttachment::getFileSize() const
115 std::string IAttachment::getMimeType() const
120 void IAttachment::setMimeType(const std::string &mimeType)
122 m_mimeType = mimeType;
125 void IAttachment::setDummyFilePath(const std::string& dummyFilePath)
127 m_dummyFilePath = dummyFilePath;
129 char buff[PATH_MAX + 1];
130 if ( NULL != realpath(m_dummyFilePath.c_str(), buff))
132 LoggerD("dummy File is valided " << m_dummyFilePath);
133 m_hasDummyFile = true;
137 std::string errnoString = DPL::GetErrnoString();
138 LoggerE("get full path problem " << errnoString);
139 m_hasDummyFile = false;
144 std::string IAttachment::getDummyFilePath() const
146 return m_dummyFilePath;
149 bool IAttachment::hasDummyFile() const
151 return m_hasDummyFile;
157 void IAttachment::setVirtualPath(const std::string& virtualPath)
159 m_virtualPath = m_virtualPath;
162 std::string IAttachment::getVirtualPath()
164 return m_virtualPath;
168 IMessagePtr IAttachment::getMessage() const
173 void IAttachment::setMessage(const IMessagePtr& message)
178 int IAttachment::getAttachmentID() const
180 return m_attachmentID;
183 void IAttachment::setAttachmentID(int id)
188 bool IAttachment::getDownloaded() const
190 return m_isDownloaded;
193 void IAttachment::setDownloaded(bool downloaded)
195 m_isDownloaded = downloaded;
198 bool IAttachment::getIsInlineAttachment() const
200 return m_isInlineAttachment;
203 void IAttachment::setIsInlineAttachment(bool isInlineAttachment)
205 m_isInlineAttachment = isInlineAttachment;
209 bool IAttachment::getIsCreatedProperly() const
211 return m_isCreatedProperly;
214 bool IAttachment::getIsValidAttachment() const
216 LoggerE("m_validAttachment : " << m_validAttachment);
217 return m_validAttachment;
220 void IAttachment::rename(const string& newName)
222 // path for attachment is still not changed
223 m_attachShortName = newName;
224 m_validAttachment = false;
227 void IAttachment::makeShortName()
230 // find position of last occurence of / sign (get only file name from all path
231 pos = m_attachFullPath.find_last_of("/");
232 if ((pos + 1) >= m_attachFullPath.size()) {
233 LoggerE("Problem with short name creation");
234 Throw(InvalidArgumentException);
236 m_attachShortName = m_attachFullPath.substr(pos + 1);