Merge pull request #354 from LukeOwncloud/added_more_git_notes_to_setup_md
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / RemoveFileOperation.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.operations;
19
20 import com.owncloud.android.datamodel.FileDataStorageManager;
21 import com.owncloud.android.datamodel.OCFile;
22 import com.owncloud.android.lib.network.OwnCloudClient;
23 import com.owncloud.android.lib.operations.common.RemoteOperation;
24 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
25 import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
26 import com.owncloud.android.lib.operations.remote.RemoveRemoteFileOperation;
27
28
29 /**
30 * Remote operation performing the removal of a remote file or folder in the ownCloud server.
31 *
32 * @author David A. Velasco
33 */
34 public class RemoveFileOperation extends RemoteOperation {
35
36 // private static final String TAG = RemoveFileOperation.class.getSimpleName();
37
38 OCFile mFileToRemove;
39 boolean mDeleteLocalCopy;
40 FileDataStorageManager mDataStorageManager;
41
42
43 /**
44 * Constructor
45 *
46 * @param fileToRemove OCFile instance describing the remote file or folder to remove from the server
47 * @param deleteLocalCopy When 'true', and a local copy of the file exists, it is also removed.
48 * @param storageManager Reference to the local database corresponding to the account where the file is contained.
49 */
50 public RemoveFileOperation(OCFile fileToRemove, boolean deleteLocalCopy, FileDataStorageManager storageManager) {
51 mFileToRemove = fileToRemove;
52 mDeleteLocalCopy = deleteLocalCopy;
53 mDataStorageManager = storageManager;
54 }
55
56
57 /**
58 * Getter for the file to remove (or removed, if the operation was successfully performed).
59 *
60 * @return File to remove or already removed.
61 */
62 public OCFile getFile() {
63 return mFileToRemove;
64 }
65
66 /**
67 * Performs the remove operation
68 *
69 * @param client Client object to communicate with the remote ownCloud server.
70 */
71 @Override
72 protected RemoteOperationResult run(OwnCloudClient client) {
73 RemoteOperationResult result = null;
74
75 RemoveRemoteFileOperation operation = new RemoveRemoteFileOperation(mFileToRemove.getRemotePath());
76 result = operation.execute(client);
77
78 if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) {
79 mDataStorageManager.removeFile(mFileToRemove, true, mDeleteLocalCopy);
80 }
81
82 return result;
83 }
84
85 }