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