62bf0656804c1099f6e35f32119d41ece66fc990
1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
.datamodel
;
26 private long parent_id_
;
28 private long creation_timestamp_
;
29 private long modified_timestamp_
;
31 private String storage_path_
;
32 private String mimetype_
;
33 private boolean update_while_saving_
;
36 * Create new {@link OCFile} with given path
38 * @param path The remote path of the file
40 public OCFile(String path
) {
42 update_while_saving_
= false
;
47 * Gets the ID of the file
51 public long getFileId() {
56 * Returns the path of the file
60 public String
getPath() {
65 * Can be used to check, whether or not this file exists in the database
68 * @return true, if the file exists in the database
70 public boolean fileExists() {
75 * Use this to find out if this file is a Directory
77 * @return true if it is a directory
79 public boolean isDirectory() {
80 return mimetype_
!= null
&& mimetype_
.equals("DIR");
84 * Use this to check if this file is available locally
86 * @return true if it is
88 public boolean isDownloaded() {
89 return storage_path_
!= null
;
93 * The path, where the file is stored locally
95 * @return The local path to the file
97 public String
getStoragePath() {
102 * Can be used to set the path where the file is stored
104 * @param storage_path
107 public void setStoragePath(String storage_path
) {
108 storage_path_
= storage_path
;
112 * Get a UNIX timestamp of the file creation time
114 * @return A UNIX timestamp of the time that file was created
116 public long getCreationTimestamp() {
117 return creation_timestamp_
;
121 * Set a UNIX timestamp of the time the file was created
123 * @param creation_timestamp
126 public void setCreationTimestamp(long creation_timestamp
) {
127 creation_timestamp_
= creation_timestamp
;
131 * Get a UNIX timestamp of the file modification time
133 * @return A UNIX timestamp of the modification time
135 public long getModificationTimestamp() {
136 return modified_timestamp_
;
140 * Set a UNIX timestamp of the time the time the file was modified.
142 * @param modification_timestamp
145 public void setModificationTimestamp(long modification_timestamp
) {
146 modified_timestamp_
= modification_timestamp
;
150 * Returns the filename and "/" for the root directory
152 * @return The name of the file
154 public String
getFileName() {
156 File f
= new File(path_
);
157 return f
.getName().equals("") ?
"/" : f
.getName();
163 * Can be used to get the Mimetype
165 * @return the Mimetype as a String
167 public String
getMimetype() {
172 * Adds a file to this directory. If this file is not a directory, an
173 * exception gets thrown.
176 * @throws IllegalStateException if you try to add a something and this is not a directory
178 public void addFile(OCFile file
) throws IllegalStateException
{
180 file
.parent_id_
= id_
;
181 update_while_saving_
= true
;
184 throw new IllegalStateException("This is not a directory where you can add stuff to!");
188 * Used internally. Reset all file properties
190 private void resetData() {
194 storage_path_
= null
;
197 creation_timestamp_
= 0;
198 modified_timestamp_
= 0;
201 public void setFileId(long file_id
) {
205 public void setMimetype(String mimetype
) {
206 mimetype_
= mimetype
;
209 public void setParentId(long parent_id
) {
210 parent_id_
= parent_id
;
213 public void setFileLength(long file_len
) {
217 public long getFileLength() {
221 public long getParentId() {
225 public boolean needsUpdatingWhileSaving() {
226 return update_while_saving_
;