- } else {
- new_entry = cr_.insert(ProviderTableMeta.CONTENT_URI_FILE, cv);
- }
- try {
- String p = new_entry.getEncodedPath();
- id_ = Integer.parseInt(p.substring(p.lastIndexOf('/')+1));
- } catch (NumberFormatException e) {
- Log.e(TAG, "Can't retrieve file id from uri: " + new_entry.toString()
- + ", reason: " + e.getMessage());
- id_ = -1;
- }
- }
- }
-
- public Vector<OCFile> getDirectoryContent() {
- if (isDirectory() && id_ != -1) {
- Vector<OCFile> ret = new Vector<OCFile>();
-
- Uri req_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR,
- String.valueOf(id_));
- Cursor c = null;
- if (cp_ != null) {
- try {
- c = cp_.query(req_uri, null, null, null, null);
- } catch (RemoteException e) {
- Log.e(TAG, e.getMessage());
- return ret;
+ };
+
+ private long mId;
+ private long mParentId;
+ private long mLength;
+ private long mCreationTimestamp;
+ private long mModifiedTimestamp;
+ private String mRemotePath;
+ private String mLocalPath;
+ private String mMimeType;
+ private boolean mNeedsUpdating;
+ private long mLastSyncDate;
+
+ /**
+ * Create new {@link OCFile} with given path
+ *
+ * @param path The remote path of the file
+ * @throws MalformedURLException
+ */
+ public OCFile(String path) {
+ resetData();
+ mNeedsUpdating = false;
+ /// dvelasco: the encoding / decoding problem should be completely translated to WebdavClient & WebdavEntry, but at this moment we are in a little hurry
+ if (path != null && path.length() > 0) {
+ try {
+ new URL("http://silly.test.com:8888" + path);
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("Trying to create a OCFile with a non valid remote path: " + path , e);
+ }
+ } else throw new RuntimeException("Trying to create a OCFile with a non valid remote path: " + path);
+ // save encoded paths have a problem: normalization; this is a quick&dirty fix to avoid duplications
+ mRemotePath = Uri.encode(Uri.decode(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;
+ }
+
+ /**
+ * Returns the remote path of the file on ownCloud
+ *
+ * @return The remote path to the file
+ */
+ public String getURLDecodedRemotePath() {
+ return Uri.decode(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;
+ }
+
+ /**
+ * 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(getURLDecodedRemotePath());
+ 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;