remove badge dependency for legacy NotificationManager
[platform/framework/native/appfw.git] / src / io / FIo_FileAttributesImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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  * @file        FIo_FileAttributesImpl.cpp
19  * @brief       This is the implementation file for _FileAttributesImpl class.
20  */
21
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <errno.h>
25
26 #include <FBaseString.h>
27 #include <FBaseResult.h>
28 #include <FIoFile.h>
29 #include <FBaseSysLog.h>
30
31 #include <FBase_StringConverter.h>
32 #include <FBase_NativeError.h>
33 #include <FIo_FileAttributesImpl.h>
34
35 using namespace Tizen::Base;
36
37 namespace Tizen { namespace Io
38 {
39
40 _FileAttributesImpl::_FileAttributesImpl(void)
41         : __fileSize(0)
42         , __directory(false)
43         , __hidden(false)
44         , __readOnly(false)
45 {
46 }
47
48 _FileAttributesImpl::~_FileAttributesImpl(void)
49 {
50 }
51
52 _FileAttributesImpl::_FileAttributesImpl(const _FileAttributesImpl& fileAttributesImpl)
53         : __fileSize(0)
54         , __directory(false)
55         , __hidden(false)
56         , __readOnly(false)
57 {
58         __fileSize = fileAttributesImpl.__fileSize;
59         __directory = fileAttributesImpl.__directory;
60         __hidden = fileAttributesImpl.__hidden;
61         __readOnly = fileAttributesImpl.__readOnly;
62         __creationTime = fileAttributesImpl.__creationTime;
63         __lastModifiedTime = fileAttributesImpl.__lastModifiedTime;
64 }
65
66 _FileAttributesImpl&
67 _FileAttributesImpl::operator =(const _FileAttributesImpl& fileAttributesImpl)
68 {
69         if (&fileAttributesImpl != this)
70         {
71                 __fileSize = fileAttributesImpl.__fileSize;
72                 __directory = fileAttributesImpl.__directory;
73                 __hidden = fileAttributesImpl.__hidden;
74                 __readOnly = fileAttributesImpl.__readOnly;
75                 __creationTime = fileAttributesImpl.__creationTime;
76                 __lastModifiedTime = fileAttributesImpl.__lastModifiedTime;
77         }
78
79         return *this;
80 }
81
82 _FileAttributesImpl*
83 _FileAttributesImpl::GetInstance(FileAttributes& fileAttributes)
84 {
85         return fileAttributes.__pFileAttributesImpl;
86 }
87
88 const _FileAttributesImpl*
89 _FileAttributesImpl::GetInstance(const FileAttributes& fileAttributes)
90 {
91         return fileAttributes.__pFileAttributesImpl;
92 }
93
94 bool
95 _FileAttributesImpl::Equals(const Object& object) const
96 {
97         const _FileAttributesImpl* pOther = dynamic_cast< const _FileAttributesImpl* >(&object);
98         if (pOther == null)
99         {
100                 return false;
101         }
102
103         if (__fileSize == pOther->__fileSize && __directory == pOther->__directory &&
104                         __hidden == pOther->__hidden && __readOnly == pOther->__readOnly &&
105                         __creationTime == pOther->__creationTime && __lastModifiedTime == pOther->__lastModifiedTime)
106         {
107                 return true;
108         }
109
110         return false;
111 }
112
113 int
114 _FileAttributesImpl::GetHashCode(void) const
115 {
116         String hashCode;
117
118         hashCode.Append(static_cast< long >(__fileSize));
119         hashCode.Append(static_cast< int >(__directory));
120         hashCode.Append(static_cast< int >(__hidden));
121         hashCode.Append(static_cast< int >(__readOnly));
122         hashCode.Append(__creationTime.ToString());
123         hashCode.Append(__lastModifiedTime.ToString());
124
125         return hashCode.GetHashCode();
126 }
127
128 long long
129 _FileAttributesImpl::GetFileSize(void) const
130 {
131         SetLastResult(E_SUCCESS);
132         return __fileSize;
133 }
134
135 DateTime
136 _FileAttributesImpl::GetDateTime(void) const
137 {
138         SetLastResult(E_SUCCESS);
139         return __creationTime;
140 }
141
142 DateTime
143 _FileAttributesImpl::GetLastModifiedTime(void) const
144 {
145         SetLastResult(E_SUCCESS);
146         return __lastModifiedTime;
147 }
148
149 bool
150 _FileAttributesImpl::IsDirectory(void) const
151 {
152         SetLastResult(E_SUCCESS);
153         return __directory;
154 }
155
156 bool
157 _FileAttributesImpl::IsHidden(void) const
158 {
159         SetLastResult(E_SUCCESS);
160         return __hidden;
161 }
162
163 bool
164 _FileAttributesImpl::IsReadOnly(void) const
165 {
166         SetLastResult(E_SUCCESS);
167         return __readOnly;
168 }
169
170 void
171 _FileAttributesImpl::Set(const DateTime& dateTime, const DateTime& modifiedTime, off64_t fileSize,
172                                                  unsigned long attribute, bool hidden)
173 {
174         __fileSize = fileSize;
175         __directory = S_ISDIR(attribute) ? true : false;
176         __hidden = hidden;
177         __readOnly = (attribute & (S_IWUSR)) ? false : true;
178
179         __creationTime = dateTime;
180         __lastModifiedTime = modifiedTime;
181
182         SetLastResult(E_SUCCESS);
183 }
184
185 }} // Tizen::Io
186