2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * @file IAttachment.cpp
22 * @author Pawel Misiak (p.misiak@samsung.com)
27 #include <dpl/log/log.h>
28 #include <dpl/errno_string.h>
29 #include <Commons/Exception.h>
30 #include "IAttachment.h"
37 using namespace WrtDeviceApis::Commons;
40 //--------------------------------------------------------------------------
45 IAttachment::IAttachment() :
46 m_validAttachment(false)
50 void IAttachment::init(const string& fullPath,
56 std::string l_fullPath;
57 LogDebug("FULL Path : " << fullPath);
60 LogDebug("translating path");
61 l_fullPath = getRealPath(fullPath);
63 l_fullPath = fullPath;
65 LogDebug("real path " << l_fullPath);
67 char buff[PATH_MAX + 1];
68 if (NULL == realpath(l_fullPath.c_str(), buff)) {
69 std::string errnoString = DPL::GetErrnoString();
70 LogError("get full path problem " << errnoString);
71 ThrowMsg(InvalidArgumentException,
72 "get full path problem " << errnoString);
75 if (-1 == lstat(buff, &buffer)) {
76 LogError("Attachment file not exist");
77 ThrowMsg(InvalidArgumentException, "Attachment file not exist");
80 if (!S_ISREG(buffer.st_mode)) {
81 LogError("Attachment file not exist");
82 ThrowMsg(InvalidArgumentException, "Attachment file not exist");
84 m_fileSize = buffer.st_size;
85 m_attachFullPath = l_fullPath;
87 m_isCreatedProperly = true;
91 Catch(WrtDeviceApis::Commons::Exception) {
92 LogError("attachment not created properly");
93 m_isCreatedProperly = false;
97 IAttachment::~IAttachment()
102 string IAttachment::getShortName() const
104 return m_attachShortName;
107 string IAttachment::getFullPath() const
109 return m_attachFullPath;
112 unsigned int IAttachment::getFileSize() const
117 std::string IAttachment::getMimeType() const
122 void IAttachment::setMimeType(const std::string &mimeType)
124 m_mimeType = mimeType;
127 Api::Messaging::IMessagePtr IAttachment::getMessage() const
132 void IAttachment::setMessage(const Api::Messaging::IMessagePtr& message)
137 int IAttachment::getAttachmentID() const
139 return m_attachmentID;
142 void IAttachment::setAttachmentID(int id)
147 bool IAttachment::getDownloaded() const
149 return m_isDownloaded;
152 void IAttachment::setDownloaded(bool downloaded)
154 m_isDownloaded = downloaded;
157 bool IAttachment::getIsCreatedProperly() const
159 return m_isCreatedProperly;
162 void IAttachment::rename(const string& newName)
164 // path for attachment is still not changed
165 m_attachShortName = newName;
166 m_validAttachment = false;
169 void IAttachment::makeShortName()
172 // find position of last occurence of / sign (get only file name from all path
173 pos = m_attachFullPath.find_last_of("/");
174 if ((pos + 1) >= m_attachFullPath.size()) {
175 LogError("Problem with short name creation");
176 Throw(InvalidArgumentException);
178 m_attachShortName = m_attachFullPath.substr(pos + 1);