/* ownCloud Android client application
* Copyright (C) 2012 Bartek Przybylski
+ * Copyright (C) 2012-2013 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
import java.util.List;
import java.util.Vector;
+import com.owncloud.android.Log_OC;
import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.utils.FileStorageUtils;
import android.database.Cursor;
import android.net.Uri;
import android.os.RemoteException;
-import android.util.Log;
public class FileDataStorageManager implements DataStorageManager {
private ContentResolver mContentResolver;
private ContentProviderClient mContentProvider;
private Account mAccount;
-
+
private static String TAG = "FileDataStorageManager";
-
+
public FileDataStorageManager(Account account, ContentResolver cr) {
mContentProvider = null;
mContentResolver = cr;
file = createFileInstance(c);
}
c.close();
+ if (file == null && OCFile.PATH_SEPARATOR.equals(path)) {
+ return createRootDir(); // root should always exist
+ }
return file;
}
+
+ private OCFile createRootDir() {
+ OCFile file = new OCFile(OCFile.PATH_SEPARATOR);
+ file.setMimetype("DIR");
+ file.setParentId(DataStorageManager.ROOT_PARENT_ID);
+ saveFile(file);
+ return file;
+ }
+
@Override
public OCFile getFileById(long id) {
Cursor c = getCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
boolean overriden = false;
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
+ cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
cv, ProviderTableMeta._ID + "=?",
new String[] { String.valueOf(file.getFileId()) });
} catch (RemoteException e) {
- Log.e(TAG,
+ Log_OC.e(TAG,
"Fail to insert insert file to database "
+ e.getMessage());
}
result_uri = getContentProvider().insert(
ProviderTableMeta.CONTENT_URI_FILE, cv);
} catch (RemoteException e) {
- Log.e(TAG,
+ Log_OC.e(TAG,
"Fail to insert insert file to database "
+ e.getMessage());
}
file = filesIt.next();
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
+ cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
}
} catch (OperationApplicationException e) {
- Log.e(TAG, "Fail to update/insert list of files to database " + e.getMessage());
+ Log_OC.e(TAG, "Fail to update/insert list of files to database " + e.getMessage());
} catch (RemoteException e) {
- Log.e(TAG, "Fail to update/insert list of files to database " + e.getMessage());
+ Log_OC.e(TAG, "Fail to update/insert list of files to database " + e.getMessage());
}
// update new id in file objects for insertions
if (results[i].uri != null) {
newId = Long.parseLong(results[i].uri.getPathSegments().get(1));
files.get(i).setFileId(newId);
- //Log.v(TAG, "Found and added id in insertion for " + files.get(i).getRemotePath());
+ //Log_OC.v(TAG, "Found and added id in insertion for " + files.get(i).getRemotePath());
}
}
}
@Override
public Vector<OCFile> getDirectoryContent(OCFile f) {
+ Vector<OCFile> ret = new Vector<OCFile>();
if (f != null && f.isDirectory() && f.getFileId() != -1) {
- Vector<OCFile> ret = new Vector<OCFile>();
Uri req_uri = Uri.withAppendedPath(
ProviderTableMeta.CONTENT_URI_DIR,
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
new String[] { mAccount.name }, null);
} catch (RemoteException e) {
- Log.e(TAG, e.getMessage());
+ Log_OC.e(TAG, e.getMessage());
return ret;
}
} else {
Collections.sort(ret);
- return ret;
}
- return null;
+ return ret;
}
private boolean fileExists(String cmp_key, String value) {
+ ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
new String[] { value, mAccount.name }, null);
} catch (RemoteException e) {
- Log.e(TAG,
+ Log_OC.e(TAG,
"Couldn't determine file existance, assuming non existance: "
+ e.getMessage());
return false;
+ "=?", new String[] { value, mAccount.name },
null);
} catch (RemoteException e) {
- Log.e(TAG, "Could not get file details: " + e.getMessage());
+ Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
c = null;
}
}
.getColumnIndex(ProviderTableMeta.FILE_CREATION)));
file.setModificationTimestamp(c.getLong(c
.getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
+ file.setModificationTimestampAtLastSyncForData(c.getLong(c
+ .getColumnIndex(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
file.setLastSyncDateForProperties(c.getLong(c
.getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
file.setLastSyncDateForData(c.getLong(c.
// TODO consider possible failures
if (dir != null && dir.isDirectory() && dir.getFileId() != -1) {
Vector<OCFile> children = getDirectoryContent(dir);
- if (children != null) {
+ if (children.size() > 0) {
OCFile child = null;
for (int i=0; i<children.size(); i++) {
child = children.get(i);
}
}
}
- if (removeDBData) {
- removeFile(dir, true);
- }
+ }
+ if (removeDBData) {
+ removeFile(dir, true);
}
}
}
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ?",
new String[] { mAccount.name, dir.getRemotePath() + "%" }, null);
} catch (RemoteException e) {
- Log.e(TAG, e.getMessage());
+ Log_OC.e(TAG, e.getMessage());
}
} else {
c = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
}
} catch (OperationApplicationException e) {
- Log.e(TAG, "Fail to update descendants of " + dir.getFileId() + " in database", e);
+ Log_OC.e(TAG, "Fail to update descendants of " + dir.getFileId() + " in database", e);
} catch (RemoteException e) {
- Log.e(TAG, "Fail to update desendants of " + dir.getFileId() + " in database", e);
+ Log_OC.e(TAG, "Fail to update desendants of " + dir.getFileId() + " in database", e);
}
}
}
+ @Override
+ public Vector<OCFile> getDirectoryImages(OCFile directory) {
+ Vector<OCFile> ret = new Vector<OCFile>();
+ if (directory != null) {
+ // TODO better implementation, filtering in the access to database (if possible) instead of here
+ Vector<OCFile> tmp = getDirectoryContent(directory);
+ OCFile current = null;
+ for (int i=0; i<tmp.size(); i++) {
+ current = tmp.get(i);
+ if (current.isImage()) {
+ ret.add(current);
+ }
+ }
+ }
+ return ret;
+ }
+
}