upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Messaging / Attachment.cpp
1 /*
2 * Copyright (c) 2011 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
18 /**
19  * @file       Attachment.cpp
20  * @author     Pawel Misiak (p.misiak@samsung.com)
21  * @version    0.1
22  * @brief
23  */
24 #include <algorithm>
25 #include <dpl/log/log.h>
26 #include <Commons/Exception.h>
27 #include <Filesystem/Manager.h>
28 #include "Attachment.h"
29
30 #include <API/Filesystem/INode.h>
31 #include <Tizen/Filesystem/EventGetNodeData.h>
32 #include <API/Filesystem/IManager.h>
33
34 extern "C" {
35 #include <sys/stat.h>
36 #include <stdlib.h>
37 }
38
39 using namespace WrtDeviceApis::Commons;
40 using namespace std;
41
42 //--------------------------------------------------------------------------
43 namespace TizenApis {
44 namespace Platform {
45 namespace Messaging {
46
47 Attachment::Attachment()
48 {
49     LogDebug("entered");
50 }
51
52 Attachment::Attachment(const string& fullPath,
53         bool isVirtualPath)
54 {
55     LogDebug("entered");
56     init(fullPath, isVirtualPath);
57 }
58
59 Attachment::Attachment(emf_attachment_info_t* att)
60 {
61     LogDebug("entered");
62
63     m_attachShortName = std::string(att->name); //set shot Name
64     m_isDownloaded = att->downloaded;
65     m_attachmentID = att->attachment_id;
66         
67     LogDebug(" showname = " << m_attachShortName << " isDownloaded = " << m_isDownloaded << " attachmentID = " << m_attachmentID);
68     LogDebug("save name is = " << att->savename);
69     if ( att->savename )
70     {
71         init( att->savename, false);
72     }
73 }
74
75 Attachment::Attachment(emf_attachment_data_t* att)
76 {
77         LogDebug("entered");
78
79         m_attachShortName = std::string(att->attachment_name);
80         m_isDownloaded = att->save_status;
81         m_attachmentID = att->attachment_id;    
82         //m_mimeType = std::string(att->attachment_mime_type);
83         LogDebug(" showname = " << m_attachShortName << " isDownloaded = " << m_isDownloaded << " attachmentID = " << m_attachmentID << "Mime= " << m_mimeType);
84         LogDebug("save name is = " << att->attachment_path);
85
86         if ( att->attachment_path)
87         {
88                 init( att->attachment_path, false);
89         }
90 }
91
92 /*
93 Attachment::Attachment(const std::string& fullPath, bool isVirtualPath, 
94         const Api::Filesystem::INode& inode):
95         Api::Filesystem::INode(inode)
96 {
97         LogDebug("entered , inode");
98         init(fullPath, isVirtualPath);  
99 }
100 */
101
102 #if 0
103 Attachment::Attachment(const std::string& fullPath, bool isVirtualPath, const Api::Filesystem::INode& inode):
104         IAttachment(inode)
105 {
106         LogDebug("entered , inode");
107         init(fullPath, isVirtualPath);  
108 }
109 #endif 
110
111 std::string Attachment::getRealPath(const std::string &path) const
112 {
113
114 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
115     Try
116     {
117         Api::Filesystem::IPathPtr currentPath = Api::Filesystem::IPath::create(
118                 path);
119         return currentPath->getFullPath();
120     }
121
122     Catch(WrtDeviceApis::Commons::Exception) {
123         LogError("invalid path");
124         ReThrow(WrtDeviceApis::Commons::InvalidArgumentException);
125     }
126 #endif
127
128         LogDebug(" path = " << path);
129
130         return path;
131
132 }
133
134 }
135 }
136 }
137