sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FIoFileAttributes.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FIoFileAttributes.h
20  * @brief       This is the header file for the %FileAttributes class.
21  *
22  * This header file contains the declarations of the %FileAttributes class.
23  */
24
25 #ifndef _FIO_FILE_ATTRIBUTES_H_
26 #define _FIO_FILE_ATTRIBUTES_H_
27
28 #include <FBaseObject.h>
29
30 namespace Tizen { namespace Base
31 {
32 class DateTime;
33 }}
34
35 namespace Tizen { namespace Io
36 {
37
38 /**
39  * @class       FileAttributes
40  * @brief       This class provides a collection of basic file attributes.
41  *
42  * @since       2.0
43  *
44  * @final       This class is not intended for extension.
45  *
46  * The %FileAttributes class provides the attributes of a file or directory.
47  * It can be used to determine the various file properties such as file attributes
48  * (read-only, hidden, system, or directory), creation time, last modified time, and file size.
49  *
50  * For more information on the class features,
51  * see <a href="../org.tizen.native.appprogramming/html/guide/io/io_namespace.htm">Io Guide</a>.
52  *
53  * The following example demonstrates how to use the %FileAttributes class.
54  *
55  * @code
56 #include <FBase.h>
57 #include <FIo.h>
58
59 using namespace Tizen::Base;
60 using namespace Tizen::Io;
61
62 int main(void)
63 {
64         String fileName(L"test.txt");
65         File file;
66         FileAttributes attr;
67         long long size;
68         DateTime dtCreate ;
69         DateTime dtModified ;
70         result r = E_SUCCESS;
71
72         r = File::GetAttributes(App::GetInstance()->GetAppDataPath() + fileName, attr);
73         if (IsFailed(r))
74         {
75                 goto CATCH;
76         }
77
78         size = attr.GetFileSize();
79         AppLog("* size=%d", size);
80
81         dtCreate = attr.GetDateTime();
82         AppLog("* creation time: %d year, %d month, %d day, %d hour, %d min, %d sec.\n",
83                 dtCreate.GetYear(),
84                 dtCreate.GetMonth(),
85                 dtCreate.GetDay(),
86                 dtCreate.GetHour(),
87                 dtCreate.GetMinute(),
88                 dtCreate.GetSecond()
89         );
90
91         dtModified = attr.GetLastModifiedTime();
92         AppLog("* last modified time: %d year, %d month, %d day, %d hour, %d min, %d sec.\n",
93                 dtModified.GetYear(),
94                 dtModified.GetMonth(),
95                 dtModified.GetDay(),
96                 dtModified.GetHour(),
97                 dtModified.GetMinute(),
98                 dtModified.GetSecond()
99         );
100
101         if (attr.IsDirectory())
102         {
103                 AppLog("* This is a directory.");
104         }
105         if (attr.IsHidden())
106         {
107                 AppLog("* This is a hidden file.");
108         }
109         if (attr.IsReadOnly())
110         {
111                 AppLog("* This is a read-only file.");
112         }
113
114         AppLog("Succeeded!");
115         return 0;
116
117 CATCH:
118         AppLog("Failed...");
119         return -1;
120 }
121  * @endcode
122  */
123 class _OSP_EXPORT_ FileAttributes
124         : public Tizen::Base::Object
125 {
126
127 public:
128         /**
129         * This is the default constructor for this class.
130         *
131         * @since                2.0
132         */
133         FileAttributes(void);
134
135         /**
136         * This destructor overrides Tizen::Base::Object::~Object().
137         *
138         * @since                2.0
139         */
140         virtual ~FileAttributes(void);
141
142         /**
143         * Copying of objects using this copy constructor is allowed.
144         *
145         * @since                2.0
146         *
147         * @param[in]    rhs             An instance of %FileAttributes
148         */
149         FileAttributes(const FileAttributes& rhs);
150
151         /**
152         * Assigns the value of the specified instance to the current instance of %FileAttributes.
153         *
154         * @since                2.0
155         *
156         * @return               The reference of this instance
157         * @param[in]    rhs             An instance of %FileAttributes
158         */
159         FileAttributes& operator =(const FileAttributes& rhs);
160
161         /**
162         * Compares the specified instance of Object to the calling instance of %FileAttributes.
163         *
164         * @since                2.0
165         *
166         * @return               @c true if the values of the specified instance equals the values of the current instance, @n
167         *                               else @c false
168         * @param[in]    object          The object to compare with the current instance
169         */
170         virtual bool Equals(const Tizen::Base::Object& object) const;
171
172         /**
173         * Gets the hash value of the current instance.
174         *
175         * @since                2.0
176         *
177         * @return               An integer value indicating the hash value of the current instance
178         */
179         virtual int GetHashCode(void) const;
180
181         /**
182         * Gets the file size.
183         *
184         * @since                2.0
185         *
186         * @return               The file size in bytes
187         */
188         long long GetFileSize(void) const;
189
190         /**
191         * Checks whether the current file is a directory.
192         *
193         * @since                2.0
194         *
195         * @return               @c true if the file is a directory, @n
196         *                               else @c false
197         */
198         bool IsDirectory(void) const;
199
200         /**
201         * Checks whether the file has a hidden attribute.
202         *
203         * @since                2.0
204         *
205         * @return               @c true if the file has a hidden attribute, @n
206         *                               else @c false
207         */
208         bool IsHidden(void) const;
209
210         /**
211         * Checks whether the file has a read-only attribute.
212         *
213         * @since                2.0
214         *
215         * @return               @c true if the file has a read-only attribute, @n
216         *                               else @c false
217         */
218         bool IsReadOnly(void) const;
219
220         /**
221         * Gets the date and time of the file creation.
222         *
223         * @since                2.0
224         *
225         * @return               The date and time of the file creation
226         */
227         Tizen::Base::DateTime GetDateTime(void) const;
228
229         /**
230         * Gets the date and time of the last modification to the file.
231         *
232         * @since                2.0
233         *
234         * @return               The date and time of the last modification to the file
235         */
236         Tizen::Base::DateTime GetLastModifiedTime(void) const;
237
238 private:
239         class _FileAttributesImpl* __pFileAttributesImpl;
240
241         friend class _FileAttributesImpl;
242
243 }; // FileAttributes
244
245 }} // Tizen::Io
246
247 #endif //_FIO_FILE_ATTRIBUTES_H_
248