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
;
23 import android
.os
.Parcel
;
24 import android
.os
.Parcelable
;
26 public class OCFile
implements Parcelable
{
28 public static final Parcelable
.Creator
<OCFile
> CREATOR
= new Parcelable
.Creator
<OCFile
>() {
30 public OCFile
createFromParcel(Parcel source
) {
31 return new OCFile(source
);
35 public OCFile
[] newArray(int size
) {
36 return new OCFile
[size
];
41 private long mParentId
;
43 private long mCreationTimestamp
;
44 private long mModifiedTimestamp
;
45 private String mRemotePath
;
46 private String mLocalPath
;
47 private String mMimeType
;
48 private boolean mNeedsUpdating
;
51 * Create new {@link OCFile} with given path
54 * The remote path of the file
56 public OCFile(String path
) {
58 mNeedsUpdating
= false
;
63 * Reconstruct from parcel
68 private OCFile(Parcel source
) {
69 mId
= source
.readLong();
70 mParentId
= source
.readLong();
71 mLength
= source
.readLong();
72 mCreationTimestamp
= source
.readLong();
73 mModifiedTimestamp
= source
.readLong();
74 mRemotePath
= source
.readString();
75 mLocalPath
= source
.readString();
76 mMimeType
= source
.readString();
77 mNeedsUpdating
= source
.readInt() == 0;
81 * Gets the ID of the file
85 public long getFileId() {
90 * Returns the path of the file
94 public String
getPath() {
99 * Can be used to check, whether or not this file exists in the database
102 * @return true, if the file exists in the database
104 public boolean fileExists() {
109 * Use this to find out if this file is a Directory
111 * @return true if it is a directory
113 public boolean isDirectory() {
114 return mMimeType
!= null
&& mMimeType
.equals("DIR");
118 * Use this to check if this file is available locally
120 * @return true if it is
122 public boolean isDownloaded() {
123 return mLocalPath
!= null
|| mLocalPath
.equals("");
127 * The path, where the file is stored locally
129 * @return The local path to the file
131 public String
getStoragePath() {
136 * Can be used to set the path where the file is stored
138 * @param storage_path
141 public void setStoragePath(String storage_path
) {
142 mLocalPath
= storage_path
;
146 * Get a UNIX timestamp of the file creation time
148 * @return A UNIX timestamp of the time that file was created
150 public long getCreationTimestamp() {
151 return mCreationTimestamp
;
155 * Set a UNIX timestamp of the time the file was created
157 * @param creation_timestamp
160 public void setCreationTimestamp(long creation_timestamp
) {
161 mCreationTimestamp
= creation_timestamp
;
165 * Get a UNIX timestamp of the file modification time
167 * @return A UNIX timestamp of the modification time
169 public long getModificationTimestamp() {
170 return mModifiedTimestamp
;
174 * Set a UNIX timestamp of the time the time the file was modified.
176 * @param modification_timestamp
179 public void setModificationTimestamp(long modification_timestamp
) {
180 mModifiedTimestamp
= modification_timestamp
;
184 * Returns the filename and "/" for the root directory
186 * @return The name of the file
188 public String
getFileName() {
189 if (mRemotePath
!= null
) {
190 File f
= new File(mRemotePath
);
191 return f
.getName().equals("") ?
"/" : f
.getName();
197 * Can be used to get the Mimetype
199 * @return the Mimetype as a String
201 public String
getMimetype() {
206 * Adds a file to this directory. If this file is not a directory, an
207 * exception gets thrown.
211 * @throws IllegalStateException
212 * if you try to add a something and this is not a directory
214 public void addFile(OCFile file
) throws IllegalStateException
{
216 file
.mParentId
= mId
;
217 mNeedsUpdating
= true
;
220 throw new IllegalStateException(
221 "This is not a directory where you can add stuff to!");
225 * Used internally. Reset all file properties
227 private void resetData() {
234 mCreationTimestamp
= 0;
235 mModifiedTimestamp
= 0;
239 * Sets the ID of the file
244 public void setFileId(long file_id
) {
249 * Sets the Mime-Type of the
254 public void setMimetype(String mimetype
) {
255 mMimeType
= mimetype
;
259 * Sets the ID of the parent folder
264 public void setParentId(long parent_id
) {
265 mParentId
= parent_id
;
269 * Sets the file size in bytes
274 public void setFileLength(long file_len
) {
279 * Returns the size of the file in bytes
281 * @return The filesize in bytes
283 public long getFileLength() {
288 * Returns the ID of the parent Folder
292 public long getParentId() {
297 * Check, if this file needs updating
301 public boolean needsUpdatingWhileSaving() {
302 return mNeedsUpdating
;
306 public int describeContents() {
307 return this.hashCode();
311 public void writeToParcel(Parcel dest
, int flags
) {
313 dest
.writeLong(mParentId
);
314 dest
.writeLong(mLength
);
315 dest
.writeLong(mCreationTimestamp
);
316 dest
.writeLong(mModifiedTimestamp
);
317 dest
.writeString(mRemotePath
);
318 dest
.writeString(mLocalPath
);
319 dest
.writeString(mMimeType
);
320 dest
.writeInt(mNeedsUpdating ?
0 : 1); // No writeBoolean method exists