android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java     
|   11 ++-
 android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java 
|   32 ++++++++++
 2 files changed, 41 insertions(+), 2 deletions(-)

New commits:
commit d6f9e415375f53eba7c5e147c7ff30c03a6db731
Author: Jacobo Aragunde Pérez <jaragu...@igalia.com>
Date:   Tue Jan 27 12:44:42 2015 +0000

    Android: download documents from ownCloud.
    
    Documents are downloaded to the private cache directory of the app,
    and opened from there. That directory is cleared and created again
    every time the application starts up.
    
    Change-Id: I5c05c8ae750b6ced3b419c67d84063e8ee3d84aa
    Reviewed-on: https://gerrit.libreoffice.org/16192
    Reviewed-by: Jacobo Aragunde Pérez <jaragu...@igalia.com>
    Tested-by: Jacobo Aragunde Pérez <jaragu...@igalia.com>

diff --git 
a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java 
b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
index 8e6d6cf..a8d1a06 100644
--- a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
+++ b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudFile.java
@@ -10,6 +10,7 @@ import java.util.List;
 import org.libreoffice.storage.IFile;
 
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
 import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
 import com.owncloud.android.lib.resources.files.RemoteFile;
 
@@ -97,8 +98,14 @@ public class OwnCloudFile implements IFile {
 
     @Override
     public File getDocument() {
-        // TODO Auto-generated method stub
-        return null;
+        if (isDirectory()) {
+            return null;
+        }
+        File downFolder = provider.getCacheDir();
+        DownloadRemoteFileOperation operation = new 
DownloadRemoteFileOperation(
+                file.getRemotePath(), downFolder.getAbsolutePath());
+        operation.execute(provider.getClient());
+        return new File(downFolder.getAbsolutePath() + file.getRemotePath());
     }
 
     @Override
diff --git 
a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
 
b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
index 7bd78e3..db2b698 100644
--- 
a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
+++ 
b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
@@ -1,5 +1,6 @@
 package org.libreoffice.storage.owncloud;
 
+import java.io.File;
 import java.net.URI;
 
 import org.libreoffice.R;
@@ -23,6 +24,7 @@ import com.owncloud.android.lib.resources.files.RemoteFile;
 public class OwnCloudProvider implements IDocumentProvider {
 
     private OwnCloudClient client;
+    private File cacheDir;
 
     // TODO: these must be configurable
     final private String serverUrl = "http://10.0.2.2/owncloud";; //emulator 
host machine
@@ -36,6 +38,13 @@ public class OwnCloudProvider implements IDocumentProvider {
         client.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(
                 userName, password));
 
+        // make sure cache directory exists, and clear it
+        // TODO: probably we should do smarter cache management
+        cacheDir = new File(context.getCacheDir(), "ownCloud");
+        if (cacheDir.exists()) {
+            deleteRecursive(cacheDir);
+        }
+        cacheDir.mkdirs();
     }
 
     @Override
@@ -73,4 +82,27 @@ public class OwnCloudProvider implements IDocumentProvider {
         return client;
     }
 
+    /**
+     * Used by OwnCloudFiles to get the cache directory they should download
+     * files to.
+     *
+     * @return cache directory.
+     */
+    protected File getCacheDir() {
+        return cacheDir;
+    }
+
+    /**
+     * Deletes files and recursively deletes directories.
+     *
+     * @param file
+     *            File or directory to be deleted.
+     */
+    private void deleteRecursive(File file) {
+        if (file.isDirectory()) {
+            for (File child : file.listFiles())
+                deleteRecursive(child);
+        }
+        file.delete();
+    }
 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to