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 parentId
;
28 private long creationTimestamp
;
29 private long modifiedTimestamp
;
30 private String remotePath
;
31 private String localPath
;
32 private String mimeType
;
33 private boolean needsUpdating
;
36 * Create new {@link OCFile} with given path
38 * @param path The remote path of the file
40 public OCFile(String path
) {
42 needsUpdating
= 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 localPath
!= null
|| localPath
.equals("");
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 localPath
= 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 creationTimestamp
;
121 * Set a UNIX timestamp of the time the file was created
123 * @param creation_timestamp
126 public void setCreationTimestamp(long creation_timestamp
) {
127 creationTimestamp
= 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 modifiedTimestamp
;
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 modifiedTimestamp
= modification_timestamp
;
150 * Returns the filename and "/" for the root directory
152 * @return The name of the file
154 public String
getFileName() {
155 if (remotePath
!= null
) {
156 File f
= new File(remotePath
);
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
{
181 needsUpdating
= 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() {
197 creationTimestamp
= 0;
198 modifiedTimestamp
= 0;
202 * Sets the ID of the file
203 * @param file_id to set
205 public void setFileId(long file_id
) {
210 * Sets the Mime-Type of the
211 * @param mimetype to set
213 public void setMimetype(String mimetype
) {
218 * Sets the ID of the parent folder
219 * @param parent_id to set
221 public void setParentId(long parent_id
) {
222 parentId
= parent_id
;
226 * Sets the file size in bytes
227 * @param file_len to set
229 public void setFileLength(long file_len
) {
234 * Returns the size of the file in bytes
235 * @return The filesize in bytes
237 public long getFileLength() {
242 * Returns the ID of the parent Folder
245 public long getParentId() {
250 * Check, if this file needs updating
253 public boolean needsUpdatingWhileSaving() {
254 return needsUpdating
;