- new_file.path_ = path;
- new_file.length_ = length;
- new_file.creation_timestamp_ = creation_timestamp;
- new_file.modified_timestamp_ = modified_timestamp;
- new_file.mimetype_ = mimetype;
- new_file.parent_id_ = parent_id;
-
- return new_file;
- }
-
- public static OCFile createNewFile(ContentResolver contentResolver, Account a,
- String path, int length, int creation_timestamp, int modified_timestamp,
- String mimetype, long parent_id) {
- OCFile new_file = new OCFile(contentResolver, a);
- Cursor c = new_file.cr_.query(ProviderTableMeta.CONTENT_URI_FILE, null,
- ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND "
- + ProviderTableMeta.FILE_PATH + "=?", new String[]{new_file.account_.name,
- path}, null);
- if (c.moveToFirst())
- new_file.setFileData(c);
- c.close();
-
- new_file.path_ = path;
- new_file.length_ = length;
- new_file.creation_timestamp_ = creation_timestamp;
- new_file.modified_timestamp_ = modified_timestamp;
- new_file.mimetype_ = mimetype;
- new_file.parent_id_ = parent_id;
-
- return new_file;
- }
-
- public OCFile(ContentResolver cr, Account account, long id) {
- cr_ = cr;
- account_ = account;
- Cursor c = cr_.query(ProviderTableMeta.CONTENT_URI_FILE, null,
- ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND "
- + ProviderTableMeta._ID + "=?",
- new String[]{account_.name, String.valueOf(id)}, null);
- if (c.moveToFirst())
- setFileData(c);
- }
-
- public OCFile(ContentResolver cr, Account account, String path) {
- cr_ = cr;
- account_ = account;
-
- Cursor c = cr_.query(ProviderTableMeta.CONTENT_URI_FILE, null,
- ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND "
- + ProviderTableMeta.FILE_PATH + "=?", new String[]{account_.name,
- path}, null);
- if (c.moveToFirst()) {
- setFileData(c);
- if (path_ != null)
- path_ = path;
+ /**
+ * Reconstruct from parcel
+ *
+ * @param source The source parcel
+ */
+ private OCFile(Parcel source) {
+ mId = source.readLong();
+ mParentId = source.readLong();
+ mLength = source.readLong();
+ mCreationTimestamp = source.readLong();
+ mModifiedTimestamp = source.readLong();
+ mRemotePath = source.readString();
+ mLocalPath = source.readString();
+ mMimeType = source.readString();
+ mNeedsUpdating = source.readInt() == 0;
+ }
+
+ /**
+ * Gets the ID of the file
+ *
+ * @return the file ID
+ */
+ public long getFileId() {
+ return mId;
+ }
+
+ /**
+ * Returns the remote path of the file on ownCloud
+ *
+ * @return The remote path to the file
+ */
+ public String getRemotePath() {
+ return mRemotePath;
+ }
+
+ /**
+ * Can be used to check, whether or not this file exists in the database
+ * already
+ *
+ * @return true, if the file exists in the database
+ */
+ public boolean fileExists() {
+ return mId != -1;
+ }
+
+ /**
+ * Use this to find out if this file is a Directory
+ *
+ * @return true if it is a directory
+ */
+ public boolean isDirectory() {
+ return mMimeType != null && mMimeType.equals("DIR");
+ }
+
+ /**
+ * Use this to check if this file is available locally
+ *
+ * @return true if it is
+ */
+ public boolean isDownloaded() {
+ return mLocalPath != null && !mLocalPath.equals("");
+ }
+
+ /**
+ * The path, where the file is stored locally
+ *
+ * @return The local path to the file
+ */
+ public String getStoragePath() {
+ return mLocalPath;
+ }
+
+ /**
+ * Can be used to set the path where the file is stored
+ *
+ * @param storage_path to set
+ */
+ public void setStoragePath(String storage_path) {
+ mLocalPath = storage_path;
+ }
+
+ /**
+ * Get a UNIX timestamp of the file creation time
+ *
+ * @return A UNIX timestamp of the time that file was created
+ */
+ public long getCreationTimestamp() {
+ return mCreationTimestamp;
+ }
+
+ /**
+ * Set a UNIX timestamp of the time the file was created
+ *
+ * @param creation_timestamp to set
+ */
+ public void setCreationTimestamp(long creation_timestamp) {
+ mCreationTimestamp = creation_timestamp;
+ }
+
+ /**
+ * Get a UNIX timestamp of the file modification time
+ *
+ * @return A UNIX timestamp of the modification time
+ */
+ public long getModificationTimestamp() {
+ return mModifiedTimestamp;