- 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;
- }
- }
-
- public long getFileId() {
- return id_;
- }
-
- public String getPath() {
- return path_;
- }
-
- public boolean fileExtist() {
- return id_ != -1;
- }
-
- public boolean isDirectory() {
- return mimetype_ != null && mimetype_.equals("DIR");
- }
-
- public boolean isDownloaded() {
- return storage_path_ != null;
- }
-
- public String getStoragePath() {
- return storage_path_;
- }
- public void setStoragePath(String storage_path) {
- storage_path_ = storage_path;
- }
-
- public long getCreationTimestamp() {
- return creation_timestamp_;
- }
- public void setCreationTimestamp(long creation_timestamp) {
- creation_timestamp_ = creation_timestamp;
- }
-
- public long getModificationTimestamp() {
- return modified_timestamp_;
- }
- public void setModificationTimestamp(long modification_timestamp) {
- modified_timestamp_ = modification_timestamp;
- }
-
- public String getFileName() {
- if (path_ != null) {
- File f = new File(path_);
- return f.getName().equals("") ? "/" : f.getName();
- }
- return null;
- }
-
- public String getMimetype() {
- return mimetype_;
- }
-
- public void save() {
- ContentValues cv = new ContentValues();
- cv.put(ProviderTableMeta.FILE_MODIFIED, modified_timestamp_);
- cv.put(ProviderTableMeta.FILE_CREATION, creation_timestamp_);
- cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, length_);
- cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, mimetype_);
- cv.put(ProviderTableMeta.FILE_NAME, getFileName());
- if (parent_id_ != 0)
- cv.put(ProviderTableMeta.FILE_PARENT, parent_id_);
- cv.put(ProviderTableMeta.FILE_PATH, path_);
- cv.put(ProviderTableMeta.FILE_STORAGE_PATH, storage_path_);
- cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, account_.name);
-
- if (fileExtist()) {
- if (cp_ != null) {
- try {
- cp_.update(ProviderTableMeta.CONTENT_URI, cv, ProviderTableMeta._ID
- + "=?", new String[]{String.valueOf(id_)});
- } catch (RemoteException e) {
- Log.e(TAG, e.getMessage());
- return;
+ /**
+ * 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
+ *
+ * TODO use a better condition not dependent upon mLenght being synchronized; to change when downloads are done through a temporal file
+ *
+ * @return true if it is
+ */
+ public boolean isDown() {
+ if (mLocalPath != null && mLocalPath.length() > 0) {
+ File file = new File(mLocalPath);
+ return (file.exists() && file.length() == mLength);
+ }
+ return false;
+ }
+
+ /**
+ * Use this to check if this file is downloading
+ *
+ * TODO use a better condition not dependent upon mLenght being synchronized; to change when downloads are done through a temporal file
+ *
+ * @return true if it is in a download in progress
+ */
+ public boolean isDownloading() {
+ if (mLocalPath != null && mLocalPath.length() > 0) {
+ File file = new File(mLocalPath);
+ return (file.exists() && file.length() < mLength);
+ }
+ return false;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Set a UNIX timestamp of the time the time the file was modified.
+ *
+ * @param modification_timestamp to set
+ */
+ public void setModificationTimestamp(long modification_timestamp) {
+ mModifiedTimestamp = modification_timestamp;
+ }
+
+ /**
+ * Returns the filename and "/" for the root directory
+ *
+ * @return The name of the file
+ */
+ public String getFileName() {
+ File f = new File(getRemotePath());
+ return f.getName().length() == 0 ? "/" : f.getName();
+ }
+
+ /**
+ * Can be used to get the Mimetype
+ *
+ * @return the Mimetype as a String
+ */
+ public String getMimetype() {
+ return mMimeType;
+ }
+
+ /**
+ * Adds a file to this directory. If this file is not a directory, an
+ * exception gets thrown.
+ *
+ * @param file to add
+ * @throws IllegalStateException if you try to add a something and this is
+ * not a directory
+ */
+ public void addFile(OCFile file) throws IllegalStateException {
+ if (isDirectory()) {
+ file.mParentId = mId;
+ mNeedsUpdating = true;
+ return;