path = owncloud-android-library
url = git://github.com/owncloud/android-library.git
branch = develop
+[submodule "ocdoc"]
+ path = user_manual/ocdoc
+ url = https://github.com/owncloud/documentation
+ branch = master
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:0.14.0'
+ classpath 'com.android.tools.build:gradle:1.0.0'
}
}
-#Wed Oct 15 10:45:44 CEST 2014
+#Mon Jan 19 09:42:11 CET 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
<string name="auth_host_url">Dirección del servidor https://…</string>
<string name="auth_username">Nombre de usuario</string>
<string name="auth_password">Contraseña</string>
- <string name="auth_register">Nuevo para %1$s?</string>
+ <string name="auth_register">¿Nuevo para %1$s?</string>
<string name="sync_string_files">Archivos</string>
<string name="setup_btn_connect">Conectar</string>
<string name="uploader_btn_upload_text">Subir</string>
<string name="common_choose_account">Choisissez un compte</string>
<string name="sync_fail_ticker">La synchronisation a échoué</string>
<string name="sync_fail_ticker_unauthorized">Échec de la synchronisation, vous devez vous reconnecter à nouveau</string>
- <string name="sync_fail_content">La synchronisation de %1$s ne peut pas être complétée</string>
- <string name="sync_fail_content_unauthorized">Mot de passe invalide pour %1$s</string>
+ <string name="sync_fail_content">La synchronisation de %1$s n\'a pu être terminée</string>
+ <string name="sync_fail_content_unauthorized">Mot de passe non valide pour %1$s</string>
<string name="sync_conflicts_in_favourites_ticker">Des conflits ont été trouvés</string>
- <string name="sync_conflicts_in_favourites_content">%1$d fichiers à garder synchronisés n\'ont put être synchronisé</string>
+ <string name="sync_conflicts_in_favourites_content">%1$d fichiers à garder synchronisés n\'ont pu être synchronisés</string>
<string name="sync_fail_in_favourites_ticker">La synchronisation des fichiers a échoué</string>
<string name="sync_fail_in_favourites_content">Le contenu de %1$d fichiers n\'a pu être synchronisé (%2$d conflits)</string>
<string name="sync_foreign_files_forgotten_ticker">Certains fichiers locaux ont été oubliés</string>
<string name="media_err_unsupported">Le codec de ce média n\'est pas pris en charge </string>
<string name="media_err_io">Le fichier média ne peut pas être lu</string>
<string name="media_err_malformed">Le fichier média n\'est pas correctement encodé</string>
- <string name="media_err_timeout">Délai dépassé pour la lecture du morceau.</string>
+ <string name="media_err_timeout">Délai dépassé pour la lecture du morceau</string>
<string name="media_err_invalid_progressive_playback">Le fichier média ne peut pas être diffusé</string>
<string name="media_err_unknown">Le fichier média ne peut être joué avec le lecteur standard</string>
<string name="media_err_security_ex">Erreur de sécurité à la lecture de %1$s</string>
<?xml version='1.0' encoding='UTF-8'?>
<resources>
+ <string name="about_android">%1$s Android aplikacija</string>
+ <string name="about_version">verzija %1$s</string>
+ <string name="actionbar_sync">Osvježi račun</string>
<string name="actionbar_upload">Učitaj</string>
+ <string name="actionbar_upload_from_apps">Sadržaj iz drugih aplikacija</string>
<string name="actionbar_upload_files">Datoteke</string>
+ <string name="actionbar_open_with">Otvori sa</string>
<string name="actionbar_mkdir">Nova mapa</string>
<string name="actionbar_settings">Postavke</string>
+ <string name="actionbar_see_details">Detalji</string>
<string name="actionbar_send_file">Pošaljite</string>
+ <string name="actionbar_sort">Sortiraj</string>
+ <string name="actionbar_sort_title">Sortiraj po</string>
+ <string-array name="actionbar_sortby">
+ <item>A-Z</item>
+ <item>Najnoviji- Stariji</item>
+ </string-array>
<!--TODO re-enable when server-side folder size calculation is available
<item>Biggest - Smallest</item>-->
<string name="prefs_category_general">Općenito</string>
<string name="prefs_category_more">više</string>
<string name="prefs_accounts">Korisnićki računi</string>
+ <string name="prefs_manage_accounts">Upravljaj računima</string>
+ <string name="prefs_pincode">PIN aplikacije</string>
+ <string name="prefs_pincode_summary">Zaštit svog klijenta</string>
+ <string name="prefs_instant_upload">Trenutni upload slika</string>
+ <string name="prefs_instant_upload_summary">Trenutni upload slika snimljenih kamerom</string>
+ <string name="prefs_instant_video_upload">Trenutni upload videa</string>
+ <string name="prefs_instant_video_upload_summary">Trenutni upload videa snimljen kamerom</string>
<string name="prefs_help">Pomoć</string>
<string name="auth_username">Korisničko ime</string>
<string name="auth_password">Lozinka</string>
<string name="auth_trying_to_login">Trying to login…</string>
<string name="common_rename">Promjeni ime</string>
<string name="common_remove">Makni</string>
+ <string name="ssl_validator_btn_details_see">Detalji</string>
<string name="activity_chooser_send_file_title">Pošaljite</string>
<string name="empty"></string>
<string name="prefs_category_accounts">Korisnićki računi</string>
<string name="auth_redirect_non_secure_connection_title">Zabezpečené pripojenie je presmerované na nezabezpečenú trasu.</string>
<string name="actionbar_logger">Logy</string>
<string name="log_send_history_button">Odoslať históriu</string>
+ <string name="log_send_no_mail_app">Nebola nájdená aplikácia pre odosielanie log protokolov. Nainštalujte si mailovú aplikáciu!</string>
+ <string name="log_send_mail_subject">%1$s Android app logs</string>
+ <string name="log_progress_dialog_text">Načítavam dáta...</string>
<string name="saml_authentication_required_text">Vyžaduje sa overenie</string>
<string name="saml_authentication_wrong_pass">Nesprávne heslo</string>
<string name="actionbar_move">Presunúť</string>
<string name="forbidden_permissions_move">pre presun tohoto súboru</string>
<string name="prefs_category_instant_uploading">Okamžité nahratie</string>
<string name="prefs_category_security">Zabezpečenie</string>
+ <string name="prefs_instant_video_upload_path_title">Cesta pre nahrávanie videí</string>
<string name="shared_subject_header">zdieľané</string>
+ <string name="with_you_subject_header">s vami</string>
+ <string name="subject_token">%1$s %2$s >>%3$s<< %4$s</string>
</resources>
<string name="prefs_category_security">安全性</string>
<string name="prefs_instant_video_upload_path_title">影片上傳路徑</string>
<string name="shared_subject_header">以分享的</string>
+ <string name="with_you_subject_header">與你</string>
+ <string name="subject_token">%1$s %2$s >>%3$s<< %4$s</string>
</resources>
<string name="prefs_category_security">Security</string>
<string name="prefs_instant_video_upload_path_title">Upload Video Path</string>
+ <string name="download_folder_failed_content">Download of %1$s folder could not be completed</string>
<string name="shared_subject_header">shared</string>
<string name="with_you_subject_header">with you</string>
android:summary="@string/prefs_pincode_summary"/>
</PreferenceCategory>
- <PreferenceCategory android:title="@string/prefs_category_instant_uploading">
- <com.owncloud.android.ui.PreferenceWithLongSummary
- android:title="@string/prefs_instant_upload_path_title"
- android:key="instant_upload_path" />
- <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
+ <PreferenceCategory android:title="@string/prefs_category_instant_uploading" android:key="instant_uploading_category">
+ <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
android:title="@string/prefs_instant_upload"
android:summary="@string/prefs_instant_upload_summary"/>
- <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_uploading"
- android:disableDependentsState="true"
+ <com.owncloud.android.ui.PreferenceWithLongSummary
+ android:title="@string/prefs_instant_upload_path_title"
+ android:key="instant_upload_path" />
+ <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
android:title="@string/instant_upload_on_wifi"
android:key="instant_upload_on_wifi"/>
+ <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_video_uploading"
+ android:title="@string/prefs_instant_video_upload"
+ android:summary="@string/prefs_instant_video_upload_summary" />
<com.owncloud.android.ui.PreferenceWithLongSummary
android:title="@string/prefs_instant_video_upload_path_title"
android:key="instant_video_upload_path" />
- <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_video_uploading"
- android:title="@string/prefs_instant_video_upload"
- android:summary="@string/prefs_instant_video_upload_summary"/>
- <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_video_uploading"
- android:disableDependentsState="true"
+ <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
android:title="@string/instant_video_upload_on_wifi"
android:key="instant_video_upload_on_wifi"/>
<!-- DISABLED FOR RELEASE UNTIL FIXED
\r
if (mOperationsServiceBinder != null) {\r
//Log_OC.wtf(TAG, "getting access token..." );\r
- mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
+ mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(getServerInfoIntent);\r
}\r
}\r
\r
normalizeUrlSuffix(uri)\r
);\r
if (mOperationsServiceBinder != null) {\r
- mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
+ mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(getServerInfoIntent);\r
} else {\r
Log_OC.wtf(TAG, "Server check tried with OperationService unbound!" );\r
}\r
\r
if (mOperationsServiceBinder != null) {\r
//Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." );\r
- mWaitingForOpId = mOperationsServiceBinder.newOperation(existenceCheckIntent);\r
+ mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(existenceCheckIntent);\r
}\r
}\r
\r
\r
if (mOperationsServiceBinder != null) {\r
//Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." );\r
- mWaitingForOpId = mOperationsServiceBinder.newOperation(getUserNameIntent);\r
+ mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(getUserNameIntent);\r
}\r
}\r
\r
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
+ cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
boolean sameRemotePath = fileExists(file.getRemotePath());
if (sameRemotePath ||
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail());
+ cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) {
file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
file.setNeedsUpdateThumbnail(c.getInt(
c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false);
+ file.setDownloading(c.getInt(
+ c.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1 ? true : false);
}
return file;
ProviderTableMeta.FILE_UPDATE_THUMBNAIL,
file.needsUpdateThumbnail() ? 1 : 0
);
+ cv.put(
+ ProviderTableMeta.FILE_IS_DOWNLOADING,
+ file.isDownloading() ? 1 : 0
+ );
boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) {
private boolean mNeedsUpdateThumbnail;
+ private boolean mIsDownloading;
+
/**
* Create new {@link OCFile} with given path.
mPermissions = source.readString();
mRemoteId = source.readString();
mNeedsUpdateThumbnail = source.readInt() == 0;
+ mIsDownloading = source.readInt() == 0;
}
dest.writeString(mPermissions);
dest.writeString(mRemoteId);
dest.writeInt(mNeedsUpdateThumbnail ? 1 : 0);
+ dest.writeInt(mIsDownloading ? 1 : 0);
}
/**
mPermissions = null;
mRemoteId = null;
mNeedsUpdateThumbnail = false;
+ mIsDownloading = false;
}
/**
this.mRemoteId = remoteId;
}
+ public boolean isDownloading() {
+ return mIsDownloading;
+ }
+
+ public void setDownloading(boolean isDownloading) {
+ this.mIsDownloading = isDownloading;
+ }
+
+ public boolean isSynchronizing() {
+ // TODO real implementation
+ return false;
+ }
}
db.execSQL("ALTER TABLE " + TABLE_INSTANT_UPLOAD + " ADD COLUMN attempt INTEGER;");
}
db.execSQL("ALTER TABLE " + TABLE_INSTANT_UPLOAD + " ADD COLUMN message TEXT;");
-
+ }
+
+ @Override
+ public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ //downgrading is the exception, so deleting and re-creating is acceptable.
+ //otherwise exception will be thrown (cannot downgrade) and oc app will crash.
+ db.execSQL("DROP TABLE IF EXISTS " + TABLE_INSTANT_UPLOAD + ";");
+ onCreate(db);
}
}
}
public class ProviderMeta {\r
\r
public static final String DB_NAME = "filelist";\r
- public static final int DB_VERSION = 8;\r
+ public static final int DB_VERSION = 9;\r
\r
private ProviderMeta() {\r
}\r
public static final String FILE_PERMISSIONS = "permissions";\r
public static final String FILE_REMOTE_ID = "remote_id";\r
public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail";\r
+ public static final String FILE_IS_DOWNLOADING= "is_downloading";\r
\r
public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME\r
+ " collate nocase asc";\r
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
+import com.owncloud.android.services.OperationsService;
+import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.activity.ComponentsGetter;
/**
*
* @param targetFile {@link OCFile} target of the action to filter in the {@link Menu}.
* @param account ownCloud {@link Account} holding targetFile.
- * @param cg Accessor to app components, needed to get access the
- * {@link FileUploader} and {@link FileDownloader} services.
+ * @param cg Accessor to app components, needed to access the
+ * {@link FileUploader} and {@link FileDownloader} services
* @param context Android {@link Context}, needed to access build setup resources.
*/
public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg, Context context) {
boolean uploading = false;
if (mComponentsGetter != null && mFile != null && mAccount != null) {
FileDownloaderBinder downloaderBinder = mComponentsGetter.getFileDownloaderBinder();
- downloading = downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile);
+ downloading = (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile));
+ OperationsServiceBinder opsBinder = mComponentsGetter.getOperationsServiceBinder();
+ downloading |= (opsBinder != null && opsBinder.isSynchronizing(mAccount, mFile.getRemotePath()));
FileUploaderBinder uploaderBinder = mComponentsGetter.getFileUploaderBinder();
- uploading = uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile);
+ uploading = (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile));
}
/// decision is taken for each possible action on a file in the menu
// DOWNLOAD
- if (mFile == null || mFile.isFolder() || mFile.isDown() || downloading || uploading) {
+ if (mFile == null || mFile.isDown() || downloading || uploading) {
toHide.add(R.id.action_download_file);
} else {
// CANCEL DOWNLOAD
- if (mFile == null || !downloading || mFile.isFolder()) {
+ if (mFile == null || !downloading) {
toHide.add(R.id.action_cancel_download);
} else {
toShow.add(R.id.action_cancel_download);
/* ownCloud Android client application
- * Copyright (C) 2012-2014 ownCloud Inc.
+ * Copyright (C) 2012-2015 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
service.putExtra(OperationsService.EXTRA_SEND_INTENT, sendIntent);
- mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
} else {
Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
service.setAction(OperationsService.ACTION_UNSHARE);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
- mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
mFileActivity.showLoadingDialog();
public void syncFile(OCFile file) {
- // Sync file
- Intent service = new Intent(mFileActivity, OperationsService.class);
- service.setAction(OperationsService.ACTION_SYNC_FILE);
- service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
- service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
- service.putExtra(OperationsService.EXTRA_SYNC_FILE_CONTENTS, true);
- mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service);
- mFileActivity.showLoadingDialog();
+ if (!file.isFolder()){
+ Intent intent = new Intent(mFileActivity, OperationsService.class);
+ intent.setAction(OperationsService.ACTION_SYNC_FILE);
+ intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ intent.putExtra(OperationsService.EXTRA_SYNC_FILE_CONTENTS, true);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(intent);
+ mFileActivity.showLoadingDialog();
+
+ } else {
+ Intent intent = new Intent(mFileActivity, OperationsService.class);
+ intent.setAction(OperationsService.ACTION_SYNC_FOLDER);
+ intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ mFileActivity.startService(intent);
+ }
}
-
public void renameFile(OCFile file, String newFilename) {
// RenameFile
Intent service = new Intent(mFileActivity, OperationsService.class);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
service.putExtra(OperationsService.EXTRA_NEWNAME, newFilename);
- mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
mFileActivity.showLoadingDialog();
}
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
service.putExtra(OperationsService.EXTRA_REMOVE_ONLY_LOCAL, onlyLocalCopy);
- mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
mFileActivity.showLoadingDialog();
}
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);
service.putExtra(OperationsService.EXTRA_CREATE_FULL_PATH, createFullPath);
- mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
mFileActivity.showLoadingDialog();
}
-
+ /**
+ * Cancel the transference in downloads (files/folders) and file uploads
+ * @param file OCFile
+ */
public void cancelTransference(OCFile file) {
Account account = mFileActivity.getAccount();
+ if (file.isFolder()) {
+ OperationsService.OperationsServiceBinder opsBinder = mFileActivity.getOperationsServiceBinder();
+ if (opsBinder != null) {
+ opsBinder.cancel(account, file);
+ }
+ }
+
+ // for both files and folders
FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder();
- FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
+ FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
+ downloaderBinder.cancel(account, file);
+
+ // TODO - review why is this here, and solve in a better way
// Remove etag for parent, if file is a keep_in_sync
if (file.keepInSync()) {
- OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId());
- parent.setEtag("");
- mFileActivity.getStorageManager().saveFile(parent);
+ OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId());
+ parent.setEtag("");
+ mFileActivity.getStorageManager().saveFile(parent);
}
-
- downloaderBinder.cancel(account, file);
-
+
} else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
uploaderBinder.cancel(account, file);
}
service.putExtra(OperationsService.EXTRA_NEW_PARENT_PATH, newfile.getRemotePath());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, currentFile.getRemotePath());
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
- mWaitingForOpId = mFileActivity.getOperationsServiceBinder().newOperation(service);
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
mFileActivity.showLoadingDialog();
}
/* ownCloud Android client application
* Copyright (C) 2012 Bartek Przybylski
- * Copyright (C) 2012-2013 ownCloud Inc.
+ * Copyright (C) 2012-2015 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AuthenticatorActivity;
import android.os.Message;
import android.os.Process;
import android.support.v4.app.NotificationCompat;
+import android.util.Pair;
public class FileDownloader extends Service implements OnDatatransferProgressListener {
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public static final String EXTRA_FILE = "FILE";
-
+
private static final String DOWNLOAD_ADDED_MESSAGE = "DOWNLOAD_ADDED";
private static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH";
public static final String EXTRA_DOWNLOAD_RESULT = "RESULT";
public static final String EXTRA_FILE_PATH = "FILE_PATH";
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
+ public static final String EXTRA_LINKED_TO_PATH = "LINKED_TO";
public static final String ACCOUNT_NAME = "ACCOUNT_NAME";
private static final String TAG = "FileDownloader";
private ServiceHandler mServiceHandler;
private IBinder mBinder;
private OwnCloudClient mDownloadClient = null;
- private Account mLastAccount = null;
+ private Account mCurrentAccount = null;
private FileDataStorageManager mStorageManager;
- private ConcurrentMap<String, DownloadFileOperation> mPendingDownloads = new ConcurrentHashMap<String, DownloadFileOperation>();
+ private IndexedForest<DownloadFileOperation> mPendingDownloads = new IndexedForest<DownloadFileOperation>();
+
private DownloadFileOperation mCurrentDownload = null;
private NotificationManager mNotificationManager;
private NotificationCompat.Builder mNotificationBuilder;
private int mLastPercent;
-
+
public static String getDownloadAddedMessage() {
- return FileDownloader.class.getName().toString() + DOWNLOAD_ADDED_MESSAGE;
+ return FileDownloader.class.getName() + DOWNLOAD_ADDED_MESSAGE;
}
public static String getDownloadFinishMessage() {
- return FileDownloader.class.getName().toString() + DOWNLOAD_FINISH_MESSAGE;
- }
-
- /**
- * Builds a key for mPendingDownloads from the account and file to download
- *
- * @param account Account where the file to download is stored
- * @param file File to download
- */
- private String buildRemoteName(Account account, OCFile file) {
- return account.name + file.getRemotePath();
+ return FileDownloader.class.getName() + DOWNLOAD_FINISH_MESSAGE;
}
-
/**
* Service initialization
/**
* Entry point to add one or several files to the queue of downloads.
- *
- * New downloads are added calling to startService(), resulting in a call to this method. This ensures the service will keep on working
- * although the caller activity goes away.
+ *
+ * New downloads are added calling to startService(), resulting in a call to this method.
+ * This ensures the service will keep on working although the caller activity goes away.
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if ( !intent.hasExtra(EXTRA_ACCOUNT) ||
!intent.hasExtra(EXTRA_FILE)
- /*!intent.hasExtra(EXTRA_FILE_PATH) ||
- !intent.hasExtra(EXTRA_REMOTE_PATH)*/
) {
Log_OC.e(TAG, "Not enough information provided in intent");
return START_NOT_STICKY;
- }
- Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
- OCFile file = intent.getParcelableExtra(EXTRA_FILE);
-
- AbstractList<String> requestedDownloads = new Vector<String>(); // dvelasco: now this always contains just one element, but that can change in a near future (download of multiple selection)
- String downloadKey = buildRemoteName(account, file);
- try {
- DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
- mPendingDownloads.putIfAbsent(downloadKey, newDownload);
- newDownload.addDatatransferProgressListener(this);
- newDownload.addDatatransferProgressListener((FileDownloaderBinder)mBinder);
- requestedDownloads.add(downloadKey);
- sendBroadcastNewDownload(newDownload);
-
- } catch (IllegalArgumentException e) {
- Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
- return START_NOT_STICKY;
- }
-
- if (requestedDownloads.size() > 0) {
- Message msg = mServiceHandler.obtainMessage();
- msg.arg1 = startId;
- msg.obj = requestedDownloads;
- mServiceHandler.sendMessage(msg);
+ } else {
+ final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
+ final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
+
+ /*Log_OC.v(
+ "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Received request to download file"
+ );*/
+
+ AbstractList<String> requestedDownloads = new Vector<String>();
+ try {
+ DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
+ newDownload.addDatatransferProgressListener(this);
+ newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
+ Pair<String, String> putResult = mPendingDownloads.putIfAbsent(
+ account, file.getRemotePath(), newDownload
+ );
+ String downloadKey = putResult.first;
+ requestedDownloads.add(downloadKey);
+ /*Log_OC.v(
+ "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Download on " + file.getRemotePath() + " added to queue"
+ );*/
+
+ // Store file on db with state 'downloading'
+ /*
+ TODO - check if helps with UI responsiveness, letting only folders use FileDownloaderBinder to check
+ FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());
+ file.setDownloading(true);
+ storageManager.saveFile(file);
+ */
+
+ sendBroadcastNewDownload(newDownload, putResult.second);
+
+ } catch (IllegalArgumentException e) {
+ Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
+ return START_NOT_STICKY;
+ }
+
+ if (requestedDownloads.size() > 0) {
+ Message msg = mServiceHandler.obtainMessage();
+ msg.arg1 = startId;
+ msg.obj = requestedDownloads;
+ mServiceHandler.sendMessage(msg);
+ }
+ //}
}
return START_NOT_STICKY;
}
-
-
+
+
/**
- * Provides a binder object that clients can use to perform operations on the queue of downloads, excepting the addition of new files.
- *
+ * Provides a binder object that clients can use to perform operations on the queue of downloads,
+ * excepting the addition of new files.
+ *
* Implemented to perform cancellation, pause and resume of existing downloads.
*/
@Override
return false; // not accepting rebinding (default behaviour)
}
-
+
/**
* Binder to let client components to perform operations on the queue of downloads.
- *
+ *
* It provides by itself the available operations.
*/
public class FileDownloaderBinder extends Binder implements OnDatatransferProgressListener {
/**
- * Map of listeners that will be reported about progress of downloads from a {@link FileDownloaderBinder} instance
+ * Map of listeners that will be reported about progress of downloads from a {@link FileDownloaderBinder}
+ * instance.
*/
- private Map<String, OnDatatransferProgressListener> mBoundListeners = new HashMap<String, OnDatatransferProgressListener>();
-
-
+ private Map<Long, OnDatatransferProgressListener> mBoundListeners =
+ new HashMap<Long, OnDatatransferProgressListener>();
+
+
/**
* Cancels a pending or current download of a remote file.
- *
- * @param account Owncloud account where the remote file is stored.
+ *
+ * @param account ownCloud account where the remote file is stored.
* @param file A file in the queue of pending downloads
*/
public void cancel(Account account, OCFile file) {
- DownloadFileOperation download = null;
- synchronized (mPendingDownloads) {
- download = mPendingDownloads.remove(buildRemoteName(account, file));
- }
+ /*Log_OC.v(
+ "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Received request to cancel download of " + file.getRemotePath()
+ );
+ Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Removing download of " + file.getRemotePath());*/
+ Pair<DownloadFileOperation, String> removeResult = mPendingDownloads.remove(account, file.getRemotePath());
+ DownloadFileOperation download = removeResult.first;
if (download != null) {
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Canceling returned download of " + file.getRemotePath());*/
download.cancel();
+ } else {
+ if (mCurrentDownload != null && mCurrentAccount != null &&
+ mCurrentDownload.getRemotePath().startsWith(file.getRemotePath()) &&
+ account.name.equals(mCurrentAccount.name)) {
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Canceling current sync as descendant: " + mCurrentDownload.getRemotePath());*/
+ mCurrentDownload.cancel();
+ }
}
}
/**
- * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting to download.
+ * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or
+ * waiting to download.
*
- * If 'file' is a directory, returns 'true' if some of its descendant files is downloading or waiting to download.
+ * If 'file' is a directory, returns 'true' if any of its descendant files is downloading or
+ * waiting to download.
*
- * @param account Owncloud account where the remote file is stored.
+ * @param account ownCloud account where the remote file is stored.
* @param file A file that could be in the queue of downloads.
*/
public boolean isDownloading(Account account, OCFile file) {
if (account == null || file == null) return false;
- String targetKey = buildRemoteName(account, file);
- synchronized (mPendingDownloads) {
- if (file.isFolder()) {
- // this can be slow if there are many downloads :(
- Iterator<String> it = mPendingDownloads.keySet().iterator();
- boolean found = false;
- while (it.hasNext() && !found) {
- found = it.next().startsWith(targetKey);
- }
- return found;
- } else {
- return (mPendingDownloads.containsKey(targetKey));
- }
- }
+ return (mPendingDownloads.contains(account, file.getRemotePath()));
}
*
* @param listener Object to notify about progress of transfer.
* @param account ownCloud account holding the file of interest.
- * @param file {@link OCfile} of interest for listener.
+ * @param file {@link OCFile} of interest for listener.
*/
- public void addDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {
+ public void addDatatransferProgressListener (
+ OnDatatransferProgressListener listener, Account account, OCFile file
+ ) {
if (account == null || file == null || listener == null) return;
- String targetKey = buildRemoteName(account, file);
- mBoundListeners.put(targetKey, listener);
+ //String targetKey = buildKey(account, file.getRemotePath());
+ mBoundListeners.put(file.getFileId(), listener);
}
*
* @param listener Object to notify about progress of transfer.
* @param account ownCloud account holding the file of interest.
- * @param file {@link OCfile} of interest for listener.
+ * @param file {@link OCFile} of interest for listener.
*/
- public void removeDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {
+ public void removeDatatransferProgressListener (
+ OnDatatransferProgressListener listener, Account account, OCFile file
+ ) {
if (account == null || file == null || listener == null) return;
- String targetKey = buildRemoteName(account, file);
- if (mBoundListeners.get(targetKey) == listener) {
- mBoundListeners.remove(targetKey);
+ //String targetKey = buildKey(account, file.getRemotePath());
+ Long fileId = file.getFileId();
+ if (mBoundListeners.get(fileId) == listener) {
+ mBoundListeners.remove(fileId);
}
}
@Override
public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer,
String fileName) {
- String key = buildRemoteName(mCurrentDownload.getAccount(), mCurrentDownload.getFile());
- OnDatatransferProgressListener boundListener = mBoundListeners.get(key);
+ //String key = buildKey(mCurrentDownload.getAccount(), mCurrentDownload.getFile().getRemotePath());
+ OnDatatransferProgressListener boundListener = mBoundListeners.get(mCurrentDownload.getFile().getFileId());
if (boundListener != null) {
boundListener.onTransferProgress(progressRate, totalTransferredSoFar, totalToTransfer, fileName);
}
if (msg.obj != null) {
Iterator<String> it = requestedDownloads.iterator();
while (it.hasNext()) {
- mService.downloadFile(it.next());
+ String next = it.next();
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Handling download file " + next);*/
+ mService.downloadFile(next);
}
}
mService.stopSelf(msg.arg1);
* @param downloadKey Key to access the download to perform, contained in mPendingDownloads
*/
private void downloadFile(String downloadKey) {
-
- synchronized(mPendingDownloads) {
- mCurrentDownload = mPendingDownloads.get(downloadKey);
- }
-
+
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Getting download of " + downloadKey);*/
+ mCurrentDownload = mPendingDownloads.get(downloadKey);
+
if (mCurrentDownload != null) {
notifyDownloadStart(mCurrentDownload);
RemoteOperationResult downloadResult = null;
try {
/// prepare client object to send the request to the ownCloud server
- if (mDownloadClient == null || !mLastAccount.equals(mCurrentDownload.getAccount())) {
- mLastAccount = mCurrentDownload.getAccount();
- mStorageManager =
- new FileDataStorageManager(mLastAccount, getContentResolver());
- OwnCloudAccount ocAccount = new OwnCloudAccount(mLastAccount, this);
- mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
- getClientFor(ocAccount, this);
- }
+ if (mCurrentAccount == null || !mCurrentAccount.equals(mCurrentDownload.getAccount())) {
+ mCurrentAccount = mCurrentDownload.getAccount();
+ mStorageManager = new FileDataStorageManager(
+ mCurrentAccount,
+ getContentResolver()
+ );
+ } // else, reuse storage manager from previous operation
+
+ // always get client from client manager, to get fresh credentials in case of update
+ OwnCloudAccount ocAccount = new OwnCloudAccount(mCurrentAccount, this);
+ mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, this);
+
/// perform the download
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Executing download of " + mCurrentDownload.getRemotePath());*/
downloadResult = mCurrentDownload.execute(mDownloadClient);
if (downloadResult.isSuccess()) {
saveDownloadedFile();
}
} catch (AccountsException e) {
- Log_OC.e(TAG, "Error while trying to get autorization for " + mLastAccount.name, e);
+ Log_OC.e(TAG, "Error while trying to get authorization for " + mCurrentAccount.name, e);
downloadResult = new RemoteOperationResult(e);
} catch (IOException e) {
- Log_OC.e(TAG, "Error while trying to get autorization for " + mLastAccount.name, e);
+ Log_OC.e(TAG, "Error while trying to get authorization for " + mCurrentAccount.name, e);
downloadResult = new RemoteOperationResult(e);
} finally {
- synchronized(mPendingDownloads) {
- mPendingDownloads.remove(downloadKey);
- }
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Removing payload " + mCurrentDownload.getRemotePath());*/
+
+ Pair<DownloadFileOperation, String> removeResult =
+ mPendingDownloads.removePayload(mCurrentAccount, mCurrentDownload.getRemotePath());
+
+ /// notify result
+ notifyDownloadResult(mCurrentDownload, downloadResult);
+
+ sendBroadcastDownloadFinished(mCurrentDownload, downloadResult, removeResult.second);
}
-
- /// notify result
- notifyDownloadResult(mCurrentDownload, downloadResult);
-
- sendBroadcastDownloadFinished(mCurrentDownload, downloadResult);
}
}
mStorageManager.triggerMediaScan(file.getStoragePath());
}
+ /**
+ * Update the OC File after a unsuccessful download
+ */
+ private void updateUnsuccessfulDownloadedFile() {
+ OCFile file = mStorageManager.getFileById(mCurrentDownload.getFile().getFileId());
+ file.setDownloading(false);
+ mStorageManager.saveFile(file);
+ }
+
/**
* Creates a status notification to show the download progress
* Callback method to update the progress bar in the status notification.
*/
@Override
- public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String filePath) {
+ public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String filePath)
+ {
int percent = (int)(100.0*((double)totalTransferredSoFar)/((double)totalToTransfer));
if (percent != mLastPercent) {
mNotificationBuilder.setProgress(100, percent, totalToTransfer < 0);
// let the user update credentials with one click
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, download.getAccount());
- updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
+ updateAccountCredentials.putExtra(
+ AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN
+ );
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
.setContentIntent(PendingIntent.getActivity(
this, (int) System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT));
- mDownloadClient = null; // grant that future retries on the same account will get the fresh credentials
-
} else {
// TODO put something smart in showDetailsIntent
Intent showDetailsIntent = new Intent();
this, (int) System.currentTimeMillis(), showDetailsIntent, 0));
}
- mNotificationBuilder.setContentText(ErrorMessageAdapter.getErrorCauseMessage(downloadResult, download, getResources()));
+ mNotificationBuilder.setContentText(
+ ErrorMessageAdapter.getErrorCauseMessage(downloadResult, download, getResources())
+ );
mNotificationManager.notify(tickerId, mNotificationBuilder.build());
// Remove success notification
/**
* Sends a broadcast when a download finishes in order to the interested activities can update their view
*
- * @param download Finished download operation
- * @param downloadResult Result of the download operation
+ * @param download Finished download operation
+ * @param downloadResult Result of the download operation
+ * @param unlinkedFromRemotePath Path in the downloads tree where the download was unlinked from
*/
- private void sendBroadcastDownloadFinished(DownloadFileOperation download, RemoteOperationResult downloadResult) {
+ private void sendBroadcastDownloadFinished(
+ DownloadFileOperation download,
+ RemoteOperationResult downloadResult,
+ String unlinkedFromRemotePath) {
Intent end = new Intent(getDownloadFinishMessage());
end.putExtra(EXTRA_DOWNLOAD_RESULT, downloadResult.isSuccess());
end.putExtra(ACCOUNT_NAME, download.getAccount().name);
end.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());
end.putExtra(EXTRA_FILE_PATH, download.getSavePath());
+ if (unlinkedFromRemotePath != null) {
+ end.putExtra(EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath);
+ }
sendStickyBroadcast(end);
}
/**
* Sends a broadcast when a new download is added to the queue.
*
- * @param download Added download operation
+ * @param download Added download operation
+ * @param linkedToRemotePath Path in the downloads tree where the download was linked to
*/
- private void sendBroadcastNewDownload(DownloadFileOperation download) {
+ private void sendBroadcastNewDownload(DownloadFileOperation download, String linkedToRemotePath) {
Intent added = new Intent(getDownloadAddedMessage());
added.putExtra(ACCOUNT_NAME, download.getAccount().name);
added.putExtra(EXTRA_REMOTE_PATH, download.getRemotePath());
added.putExtra(EXTRA_FILE_PATH, download.getSavePath());
+ added.putExtra(EXTRA_LINKED_TO_PATH, linkedToRemotePath);
sendStickyBroadcast(added);
}
if (uploadType == UPLOAD_SINGLE_FILE) {
if (intent.hasExtra(KEY_FILE)) {
- files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };
+ files = new OCFile[] { (OCFile) intent.getParcelableExtra(KEY_FILE) };
} else {
localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
*
* If 'file' is a directory, returns 'true' if some of its descendant files is uploading or waiting to upload.
*
- * @param account Owncloud account where the remote file will be stored.
- * @param file A file that could be in the queue of pending uploads
+ * @param account ownCloud account where the remote file will be stored.
+ * @param file A file that could be in the queue of pending uploads
*/
public boolean isUploading(Account account, OCFile file) {
if (account == null || file == null)
*
* @param listener Object to notify about progress of transfer.
* @param account ownCloud account holding the file of interest.
- * @param file {@link OCfile} of interest for listener.
+ * @param file {@link OCFile} of interest for listener.
*/
public void addDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {
if (account == null || file == null || listener == null) return;
*
* @param listener Object to notify about progress of transfer.
* @param account ownCloud account holding the file of interest.
- * @param file {@link OCfile} of interest for listener.
+ * @param file {@link OCFile} of interest for listener.
*/
public void removeDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {
if (account == null || file == null || listener == null) return;
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2015 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.files.services;
+
+import android.accounts.Account;
+import android.util.Pair;
+
+import com.owncloud.android.datamodel.OCFile;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * Helper structure to keep the trees of folders containing any file downloading or synchronizing.
+ *
+ * A map provides the indexation based in hashing.
+ *
+ * A tree is created per account.
+ *
+ * @author David A. Velasco
+ */
+public class IndexedForest<V> {
+
+ private ConcurrentMap<String, Node<V>> mMap = new ConcurrentHashMap<String, Node<V>>();
+
+ private class Node<V> {
+ String mKey = null;
+ Node<V> mParent = null;
+ Set<Node<V>> mChildren = new HashSet<Node<V>>(); // TODO be careful with hash()
+ V mPayload = null;
+
+ // payload is optional
+ public Node(String key, V payload) {
+ if (key == null) {
+ throw new IllegalArgumentException("Argument key MUST NOT be null");
+ }
+ mKey = key;
+ mPayload = payload;
+ }
+
+ public Node<V> getParent() {
+ return mParent;
+ };
+
+ public Set<Node<V>> getChildren() {
+ return mChildren;
+ }
+
+ public String getKey() {
+ return mKey;
+ }
+
+ public V getPayload() {
+ return mPayload;
+ }
+
+ public void addChild(Node<V> child) {
+ mChildren.add(child);
+ child.setParent(this);
+ }
+
+ private void setParent(Node<V> parent) {
+ mParent = parent;
+ }
+
+ public boolean hasChildren() {
+ return mChildren.size() > 0;
+ }
+
+ public void removeChild(Node<V> removed) {
+ mChildren.remove(removed);
+ }
+
+ public void clearPayload() {
+ mPayload = null;
+ }
+ }
+
+
+ public /* synchronized */ Pair<String, String> putIfAbsent(Account account, String remotePath, V value) {
+ String targetKey = buildKey(account, remotePath);
+ Node<V> valuedNode = new Node(targetKey, value);
+ mMap.putIfAbsent(
+ targetKey,
+ valuedNode
+ );
+
+ String currentPath = remotePath, parentPath = null, parentKey = null;
+ Node<V> currentNode = valuedNode, parentNode = null;
+ boolean linked = false;
+ while (!OCFile.ROOT_PATH.equals(currentPath) && !linked) {
+ parentPath = new File(currentPath).getParent();
+ if (!parentPath.endsWith(OCFile.PATH_SEPARATOR)) {
+ parentPath += OCFile.PATH_SEPARATOR;
+ }
+ parentKey = buildKey(account, parentPath);
+ parentNode = mMap.get(parentKey);
+ if (parentNode == null) {
+ parentNode = new Node(parentKey, null);
+ parentNode.addChild(currentNode);
+ mMap.put(parentKey, parentNode);
+ } else {
+ parentNode.addChild(currentNode);
+ linked = true;
+ }
+ currentPath = parentPath;
+ currentNode = parentNode;
+ }
+
+ String linkedTo = OCFile.ROOT_PATH;
+ if (linked) {
+ linkedTo = parentNode.getKey().substring(account.name.length());
+ }
+ return new Pair<String, String>(targetKey, linkedTo);
+ };
+
+
+ public Pair<V, String> removePayload(Account account, String remotePath) {
+ String targetKey = buildKey(account, remotePath);
+ Node<V> target = mMap.get(targetKey);
+ if (target != null) {
+ target.clearPayload();
+ if (!target.hasChildren()) {
+ return remove(account, remotePath);
+ }
+ }
+ return new Pair<V, String>(null, null);
+ }
+
+
+ public /* synchronized */ Pair<V, String> remove(Account account, String remotePath) {
+ String targetKey = buildKey(account, remotePath);
+ Node<V> firstRemoved = mMap.remove(targetKey);
+ String unlinkedFrom = null;
+
+ if (firstRemoved != null) {
+ /// remove children
+ removeDescendants(firstRemoved);
+
+ /// remove ancestors if only here due to firstRemoved
+ Node<V> removed = firstRemoved;
+ Node<V> parent = removed.getParent();
+ boolean unlinked = false;
+ while (parent != null) {
+ parent.removeChild(removed);
+ if (!parent.hasChildren()) {
+ removed = mMap.remove(parent.getKey());
+ parent = removed.getParent();
+ } else {
+ break;
+ }
+ }
+
+ if (parent != null) {
+ unlinkedFrom = parent.getKey().substring(account.name.length());
+ }
+
+ return new Pair<V, String>(firstRemoved.getPayload(), unlinkedFrom);
+ }
+
+ return new Pair<V, String>(null, null);
+ }
+
+ private void removeDescendants(Node<V> removed) {
+ Iterator<Node<V>> childrenIt = removed.getChildren().iterator();
+ Node<V> child = null;
+ while (childrenIt.hasNext()) {
+ child = childrenIt.next();
+ mMap.remove(child.getKey());
+ removeDescendants(child);
+ }
+ }
+
+ public boolean contains(Account account, String remotePath) {
+ String targetKey = buildKey(account, remotePath);
+ return mMap.containsKey(targetKey);
+ }
+
+ public /* synchronized */ V get(String key) {
+ Node<V> node = mMap.get(key);
+ if (node != null) {
+ return node.getPayload();
+ } else {
+ return null;
+ }
+ }
+
+ public V get(Account account, String remotePath) {
+ String key = buildKey(account, remotePath);
+ return get(key);
+ }
+
+
+ /**
+ * Builds a key to index files
+ *
+ * @param account Account where the file to download is stored
+ * @param remotePath Path of the file in the server
+ */
+ private String buildKey(Account account, String remotePath) {
+ return account.name + remotePath;
+ }
+
+
+
+}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012-2014 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.operations;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.apache.http.HttpStatus;
+import android.accounts.Account;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+//import android.support.v4.content.LocalBroadcastManager;
+
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.resources.shares.OCShare;
+import com.owncloud.android.lib.common.operations.RemoteOperation;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation;
+import com.owncloud.android.lib.resources.files.FileUtils;
+import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
+import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
+import com.owncloud.android.lib.resources.files.RemoteFile;
+
+import com.owncloud.android.syncadapter.FileSyncAdapter;
+import com.owncloud.android.utils.FileStorageUtils;
+
+
+
+/**
+ * Remote operation performing the synchronization of the list of files contained
+ * in a folder identified with its remote path.
+ *
+ * Fetches the list and properties of the files contained in the given folder, including their
+ * properties, and updates the local database with them.
+ *
+ * Does NOT enter in the child folders to synchronize their contents also.
+ *
+ * @author David A. Velasco
+ */
+public class RefreshFolderOperation extends RemoteOperation {
+
+ private static final String TAG = RefreshFolderOperation.class.getSimpleName();
+
+ public static final String EVENT_SINGLE_FOLDER_CONTENTS_SYNCED =
+ RefreshFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_CONTENTS_SYNCED";
+ public static final String EVENT_SINGLE_FOLDER_SHARES_SYNCED =
+ RefreshFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_SHARES_SYNCED";
+
+ /** Time stamp for the synchronization process in progress */
+ private long mCurrentSyncTime;
+
+ /** Remote folder to synchronize */
+ private OCFile mLocalFolder;
+
+ /** Access to the local database */
+ private FileDataStorageManager mStorageManager;
+
+ /** Account where the file to synchronize belongs */
+ private Account mAccount;
+
+ /** Android context; necessary to send requests to the download service */
+ private Context mContext;
+
+ /** Files and folders contained in the synchronized folder after a successful operation */
+ private List<OCFile> mChildren;
+
+ /** Counter of conflicts found between local and remote files */
+ private int mConflictsFound;
+
+ /** Counter of failed operations in synchronization of kept-in-sync files */
+ private int mFailsInFavouritesFound;
+
+ /**
+ * Map of remote and local paths to files that where locally stored in a location
+ * out of the ownCloud folder and couldn't be copied automatically into it
+ **/
+ private Map<String, String> mForgottenLocalFiles;
+
+ /** 'True' means that this operation is part of a full account synchronization */
+ private boolean mSyncFullAccount;
+
+ /** 'True' means that Share resources bound to the files into should be refreshed also */
+ private boolean mIsShareSupported;
+
+ /** 'True' means that the remote folder changed and should be fetched */
+ private boolean mRemoteFolderChanged;
+
+ /** 'True' means that Etag will be ignored */
+ private boolean mIgnoreETag;
+
+
+ /**
+ * Creates a new instance of {@link RefreshFolderOperation}.
+ *
+ * @param folder Folder to synchronize.
+ * @param currentSyncTime Time stamp for the synchronization process in progress.
+ * @param syncFullAccount 'True' means that this operation is part of a full account
+ * synchronization.
+ * @param isShareSupported 'True' means that the server supports the sharing API.
+ * @param ignoreEtag 'True' means that the content of the remote folder should
+ * be fetched and updated even though the 'eTag' did not
+ * change.
+ * @param dataStorageManager Interface with the local database.
+ * @param account ownCloud account where the folder is located.
+ * @param context Application context.
+ */
+ public RefreshFolderOperation(OCFile folder,
+ long currentSyncTime,
+ boolean syncFullAccount,
+ boolean isShareSupported,
+ boolean ignoreETag,
+ FileDataStorageManager dataStorageManager,
+ Account account,
+ Context context) {
+ mLocalFolder = folder;
+ mCurrentSyncTime = currentSyncTime;
+ mSyncFullAccount = syncFullAccount;
+ mIsShareSupported = isShareSupported;
+ mStorageManager = dataStorageManager;
+ mAccount = account;
+ mContext = context;
+ mForgottenLocalFiles = new HashMap<String, String>();
+ mRemoteFolderChanged = false;
+ mIgnoreETag = ignoreETag;
+ }
+
+
+ public int getConflictsFound() {
+ return mConflictsFound;
+ }
+
+ public int getFailsInFavouritesFound() {
+ return mFailsInFavouritesFound;
+ }
+
+ public Map<String, String> getForgottenLocalFiles() {
+ return mForgottenLocalFiles;
+ }
+
+ /**
+ * Returns the list of files and folders contained in the synchronized folder,
+ * if called after synchronization is complete.
+ *
+ * @return List of files and folders contained in the synchronized folder.
+ */
+ public List<OCFile> getChildren() {
+ return mChildren;
+ }
+
+ /**
+ * Performs the synchronization.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ protected RemoteOperationResult run(OwnCloudClient client) {
+ RemoteOperationResult result = null;
+ mFailsInFavouritesFound = 0;
+ mConflictsFound = 0;
+ mForgottenLocalFiles.clear();
+
+ if (FileUtils.PATH_SEPARATOR.equals(mLocalFolder.getRemotePath()) && !mSyncFullAccount) {
+ updateOCVersion(client);
+ }
+
+ result = checkForChanges(client);
+
+ if (result.isSuccess()) {
+ if (mRemoteFolderChanged) {
+ result = fetchAndSyncRemoteFolder(client);
+ } else {
+ mChildren = mStorageManager.getFolderContent(mLocalFolder);
+ }
+ }
+
+ if (!mSyncFullAccount) {
+ sendLocalBroadcast(
+ EVENT_SINGLE_FOLDER_CONTENTS_SYNCED, mLocalFolder.getRemotePath(), result
+ );
+ }
+
+ if (result.isSuccess() && mIsShareSupported && !mSyncFullAccount) {
+ refreshSharesForFolder(client); // share result is ignored
+ }
+
+ if (!mSyncFullAccount) {
+ sendLocalBroadcast(
+ EVENT_SINGLE_FOLDER_SHARES_SYNCED, mLocalFolder.getRemotePath(), result
+ );
+ }
+
+ return result;
+
+ }
+
+
+ private void updateOCVersion(OwnCloudClient client) {
+ UpdateOCVersionOperation update = new UpdateOCVersionOperation(mAccount, mContext);
+ RemoteOperationResult result = update.execute(client);
+ if (result.isSuccess()) {
+ mIsShareSupported = update.getOCVersion().isSharedSupported();
+ }
+ }
+
+
+ private RemoteOperationResult checkForChanges(OwnCloudClient client) {
+ mRemoteFolderChanged = true;
+ RemoteOperationResult result = null;
+ String remotePath = null;
+
+ remotePath = mLocalFolder.getRemotePath();
+ Log_OC.d(TAG, "Checking changes in " + mAccount.name + remotePath);
+
+ // remote request
+ ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath);
+ result = operation.execute(client);
+ if (result.isSuccess()){
+ OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
+
+ if (!mIgnoreETag) {
+ // check if remote and local folder are different
+ mRemoteFolderChanged =
+ !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag()));
+ }
+
+ result = new RemoteOperationResult(ResultCode.OK);
+
+ Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " +
+ (mRemoteFolderChanged ? "changed" : "not changed"));
+
+ } else {
+ // check failed
+ if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
+ removeLocalFolder();
+ }
+ if (result.isException()) {
+ Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
+ result.getLogMessage(), result.getException());
+ } else {
+ Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
+ result.getLogMessage());
+ }
+ }
+
+ return result;
+ }
+
+
+ private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) {
+ String remotePath = mLocalFolder.getRemotePath();
+ ReadRemoteFolderOperation operation = new ReadRemoteFolderOperation(remotePath);
+ RemoteOperationResult result = operation.execute(client);
+ Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath);
+
+ if (result.isSuccess()) {
+ synchronizeData(result.getData(), client);
+ if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {
+ result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
+ // should be a different result code, but will do the job
+ }
+ } else {
+ if (result.getCode() == ResultCode.FILE_NOT_FOUND)
+ removeLocalFolder();
+ }
+
+ return result;
+ }
+
+
+ private void removeLocalFolder() {
+ if (mStorageManager.fileExists(mLocalFolder.getFileId())) {
+ String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
+ mStorageManager.removeFolder(
+ mLocalFolder,
+ true,
+ ( mLocalFolder.isDown() &&
+ mLocalFolder.getStoragePath().startsWith(currentSavePath)
+ )
+ );
+ }
+ }
+
+
+ /**
+ * Synchronizes the data retrieved from the server about the contents of the target folder
+ * with the current data in the local database.
+ *
+ * Grants that mChildren is updated with fresh data after execution.
+ *
+ * @param folderAndFiles Remote folder and children files in Folder
+ *
+ * @param client Client instance to the remote server where the data were
+ * retrieved.
+ * @return 'True' when any change was made in the local data, 'false' otherwise
+ */
+ private void synchronizeData(ArrayList<Object> folderAndFiles, OwnCloudClient client) {
+ // get 'fresh data' from the database
+ mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath());
+
+ // parse data from remote folder
+ OCFile remoteFolder = fillOCFile((RemoteFile)folderAndFiles.get(0));
+ remoteFolder.setParentId(mLocalFolder.getParentId());
+ remoteFolder.setFileId(mLocalFolder.getFileId());
+
+ Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath()
+ + " changed - starting update of local data ");
+
+ List<OCFile> updatedFiles = new Vector<OCFile>(folderAndFiles.size() - 1);
+ List<SynchronizeFileOperation> filesToSyncContents = new Vector<SynchronizeFileOperation>();
+
+ // get current data about local contents of the folder to synchronize
+ List<OCFile> localFiles = mStorageManager.getFolderContent(mLocalFolder);
+ Map<String, OCFile> localFilesMap = new HashMap<String, OCFile>(localFiles.size());
+ for (OCFile file : localFiles) {
+ localFilesMap.put(file.getRemotePath(), file);
+ }
+
+ // loop to update every child
+ OCFile remoteFile = null, localFile = null;
+ for (int i=1; i<folderAndFiles.size(); i++) {
+ /// new OCFile instance with the data from the server
+ remoteFile = fillOCFile((RemoteFile)folderAndFiles.get(i));
+ remoteFile.setParentId(mLocalFolder.getFileId());
+
+ /// retrieve local data for the read file
+ // localFile = mStorageManager.getFileByPath(remoteFile.getRemotePath());
+ localFile = localFilesMap.remove(remoteFile.getRemotePath());
+
+ /// add to the remoteFile (the new one) data about LOCAL STATE (not existing in server)
+ remoteFile.setLastSyncDateForProperties(mCurrentSyncTime);
+ if (localFile != null) {
+ // some properties of local state are kept unmodified
+ remoteFile.setFileId(localFile.getFileId());
+ remoteFile.setKeepInSync(localFile.keepInSync());
+ remoteFile.setLastSyncDateForData(localFile.getLastSyncDateForData());
+ remoteFile.setModificationTimestampAtLastSyncForData(
+ localFile.getModificationTimestampAtLastSyncForData()
+ );
+ remoteFile.setStoragePath(localFile.getStoragePath());
+ // eTag will not be updated unless contents are synchronized
+ // (Synchronize[File|Folder]Operation with remoteFile as parameter)
+ remoteFile.setEtag(localFile.getEtag());
+ if (remoteFile.isFolder()) {
+ remoteFile.setFileLength(localFile.getFileLength());
+ // TODO move operations about size of folders to FileContentProvider
+ } else if (mRemoteFolderChanged && remoteFile.isImage() &&
+ remoteFile.getModificationTimestamp() != localFile.getModificationTimestamp()) {
+ remoteFile.setNeedsUpdateThumbnail(true);
+ Log.d(TAG, "Image " + remoteFile.getFileName() + " updated on the server");
+ }
+ remoteFile.setPublicLink(localFile.getPublicLink());
+ remoteFile.setShareByLink(localFile.isShareByLink());
+ } else {
+ // remote eTag will not be updated unless contents are synchronized
+ // (Synchronize[File|Folder]Operation with remoteFile as parameter)
+ remoteFile.setEtag("");
+ }
+
+ /// check and fix, if needed, local storage path
+ checkAndFixForeignStoragePath(remoteFile); // policy - local files are COPIED
+ // into the ownCloud local folder;
+ searchForLocalFileInDefaultPath(remoteFile); // legacy
+
+ /// prepare content synchronization for kept-in-sync files
+ if (remoteFile.keepInSync()) {
+ SynchronizeFileOperation operation = new SynchronizeFileOperation( localFile,
+ remoteFile,
+ mAccount,
+ true,
+ mContext
+ );
+
+ filesToSyncContents.add(operation);
+ }
+
+ updatedFiles.add(remoteFile);
+ }
+
+ // save updated contents in local database
+ mStorageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());
+
+ // request for the synchronization of file contents AFTER saving current remote properties
+ startContentSynchronizations(filesToSyncContents, client);
+
+ mChildren = updatedFiles;
+ }
+
+ /**
+ * Performs a list of synchronization operations, determining if a download or upload is needed
+ * or if exists conflict due to changes both in local and remote contents of the each file.
+ *
+ * If download or upload is needed, request the operation to the corresponding service and goes
+ * on.
+ *
+ * @param filesToSyncContents Synchronization operations to execute.
+ * @param client Interface to the remote ownCloud server.
+ */
+ private void startContentSynchronizations(
+ List<SynchronizeFileOperation> filesToSyncContents, OwnCloudClient client
+ ) {
+ RemoteOperationResult contentsResult = null;
+ for (SynchronizeFileOperation op: filesToSyncContents) {
+ contentsResult = op.execute(mStorageManager, mContext); // async
+ if (!contentsResult.isSuccess()) {
+ if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
+ mConflictsFound++;
+ } else {
+ mFailsInFavouritesFound++;
+ if (contentsResult.getException() != null) {
+ Log_OC.e(TAG, "Error while synchronizing favourites : "
+ + contentsResult.getLogMessage(), contentsResult.getException());
+ } else {
+ Log_OC.e(TAG, "Error while synchronizing favourites : "
+ + contentsResult.getLogMessage());
+ }
+ }
+ } // won't let these fails break the synchronization process
+ }
+ }
+
+
+ public boolean isMultiStatus(int status) {
+ return (status == HttpStatus.SC_MULTI_STATUS);
+ }
+
+ /**
+ * Creates and populates a new {@link OCFile} object with the data read from the server.
+ *
+ * @param remote remote file read from the server (remote file or folder).
+ * @return New OCFile instance representing the remote resource described by we.
+ */
+ private OCFile fillOCFile(RemoteFile remote) {
+ OCFile file = new OCFile(remote.getRemotePath());
+ file.setCreationTimestamp(remote.getCreationTimestamp());
+ file.setFileLength(remote.getLength());
+ file.setMimetype(remote.getMimeType());
+ file.setModificationTimestamp(remote.getModifiedTimestamp());
+ file.setEtag(remote.getEtag());
+ file.setPermissions(remote.getPermissions());
+ file.setRemoteId(remote.getRemoteId());
+ return file;
+ }
+
+
+ /**
+ * Checks the storage path of the OCFile received as parameter.
+ * If it's out of the local ownCloud folder, tries to copy the file inside it.
+ *
+ * If the copy fails, the link to the local file is nullified. The account of forgotten
+ * files is kept in {@link #mForgottenLocalFiles}
+ *)
+ * @param file File to check and fix.
+ */
+ private void checkAndFixForeignStoragePath(OCFile file) {
+ String storagePath = file.getStoragePath();
+ String expectedPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
+ if (storagePath != null && !storagePath.equals(expectedPath)) {
+ /// fix storagePaths out of the local ownCloud folder
+ File originalFile = new File(storagePath);
+ if (FileStorageUtils.getUsableSpace(mAccount.name) < originalFile.length()) {
+ mForgottenLocalFiles.put(file.getRemotePath(), storagePath);
+ file.setStoragePath(null);
+
+ } else {
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ File expectedFile = new File(expectedPath);
+ File expectedParent = expectedFile.getParentFile();
+ expectedParent.mkdirs();
+ if (!expectedParent.isDirectory()) {
+ throw new IOException(
+ "Unexpected error: parent directory could not be created"
+ );
+ }
+ expectedFile.createNewFile();
+ if (!expectedFile.isFile()) {
+ throw new IOException("Unexpected error: target file could not be created");
+ }
+ in = new FileInputStream(originalFile);
+ out = new FileOutputStream(expectedFile);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0){
+ out.write(buf, 0, len);
+ }
+ file.setStoragePath(expectedPath);
+
+ } catch (Exception e) {
+ Log_OC.e(TAG, "Exception while copying foreign file " + expectedPath, e);
+ mForgottenLocalFiles.put(file.getRemotePath(), storagePath);
+ file.setStoragePath(null);
+
+ } finally {
+ try {
+ if (in != null) in.close();
+ } catch (Exception e) {
+ Log_OC.d(TAG, "Weird exception while closing input stream for "
+ + storagePath + " (ignoring)", e);
+ }
+ try {
+ if (out != null) out.close();
+ } catch (Exception e) {
+ Log_OC.d(TAG, "Weird exception while closing output stream for "
+ + expectedPath + " (ignoring)", e);
+ }
+ }
+ }
+ }
+ }
+
+
+ private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) {
+ RemoteOperationResult result = null;
+
+ // remote request
+ GetRemoteSharesForFileOperation operation =
+ new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), false, true);
+ result = operation.execute(client);
+
+ if (result.isSuccess()) {
+ // update local database
+ ArrayList<OCShare> shares = new ArrayList<OCShare>();
+ for(Object obj: result.getData()) {
+ shares.add((OCShare) obj);
+ }
+ mStorageManager.saveSharesInFolder(shares, mLocalFolder);
+ }
+
+ return result;
+ }
+
+
+ /**
+ * Scans the default location for saving local copies of files searching for
+ * a 'lost' file with the same full name as the {@link OCFile} received as
+ * parameter.
+ *
+ * @param file File to associate a possible 'lost' local file.
+ */
+ private void searchForLocalFileInDefaultPath(OCFile file) {
+ if (file.getStoragePath() == null && !file.isFolder()) {
+ File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
+ if (f.exists()) {
+ file.setStoragePath(f.getAbsolutePath());
+ file.setLastSyncDateForData(f.lastModified());
+ }
+ }
+ }
+
+
+ /**
+ * Sends a message to any application component interested in the progress
+ * of the synchronization.
+ *
+ * @param event
+ * @param dirRemotePath Remote path of a folder that was just synchronized
+ * (with or without success)
+ * @param result
+ */
+ private void sendLocalBroadcast(
+ String event, String dirRemotePath, RemoteOperationResult result
+ ) {
+ Log_OC.d(TAG, "Send broadcast " + event);
+ Intent intent = new Intent(event);
+ intent.putExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME, mAccount.name);
+ if (dirRemotePath != null) {
+ intent.putExtra(FileSyncAdapter.EXTRA_FOLDER_PATH, dirRemotePath);
+ }
+ intent.putExtra(FileSyncAdapter.EXTRA_RESULT, result);
+ mContext.sendStickyBroadcast(intent);
+ //LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
+ }
+
+
+ public boolean getRemoteFolderChanged() {
+ return mRemoteFolderChanged;
+ }
+
+}
private boolean mTransferWasRequested = false;
+ /**
+ * When 'false', uploads to the server are not done; only downloads or conflict detection.
+ * This is a temporal field.
+ * TODO Remove when 'folder synchronization' replaces 'folder download'.
+ */
+ private boolean mAllowUploads;
+
/**
- * Constructor.
+ * Constructor for "full synchronization mode".
*
- * Uses remotePath to retrieve all the data in local cache and remote server when the operation
+ * Uses remotePath to retrieve all the data both in local cache and in the remote OC server when the operation
* is executed, instead of reusing {@link OCFile} instances.
*
+ * Useful for direct synchronization of a single file.
+ *
* @param
* @param account ownCloud account holding the file.
* @param syncFileContents When 'true', transference of data will be started by the
mAccount = account;
mSyncFileContents = syncFileContents;
mContext = context;
+ mAllowUploads = true;
}
/**
- * Constructor allowing to reuse {@link OCFile} instances just queried from cache or network.
+ * Constructor allowing to reuse {@link OCFile} instances just queried from local cache or from remote OC server.
*
- * Useful for folder / account synchronizations.
+ * Useful to include this operation as part of the synchronization of a folder (or a full account), avoiding the
+ * repetition of fetch operations (both in local database or remote server).
*
- * @param localFile Data of file currently hold in device cache. MUSTN't be null.
- * @param serverFile Data of file just retrieved from network. If null, will be
+ * At least one of localFile or serverFile MUST NOT BE NULL. If you don't have none of them, use the other
+ * constructor.
+ *
+ * @param localFile Data of file (just) retrieved from local cache/database.
+ * @param serverFile Data of file (just) retrieved from a remote server. If null, will be
* retrieved from network by the operation when executed.
* @param account ownCloud account holding the file.
* @param syncFileContents When 'true', transference of data will be started by the
mLocalFile = localFile;
mServerFile = serverFile;
- mRemotePath = localFile.getRemotePath();
+ if (mLocalFile != null) {
+ mRemotePath = mLocalFile.getRemotePath();
+ if (mServerFile != null && !mServerFile.getRemotePath().equals(mRemotePath)) {
+ throw new IllegalArgumentException("serverFile and localFile do not correspond to the same OC file");
+ }
+ } else if (mServerFile != null) {
+ mRemotePath = mServerFile.getRemotePath();
+ } else {
+ throw new IllegalArgumentException("Both serverFile and localFile are NULL");
+ }
mAccount = account;
mSyncFileContents = syncFileContents;
mContext = context;
+ mAllowUploads = true;
+ }
+
+
+ /**
+ * Temporal constructor.
+ *
+ * Extends the previous one to allow constrained synchronizations where uploads are never performed - only
+ * downloads or conflict detection.
+ *
+ * Do not use unless you are involved in 'folder synchronization' or 'folder download' work in progress.
+ *
+ * TODO Remove when 'folder synchronization' replaces 'folder download'.
+ *
+ * @param localFile Data of file (just) retrieved from local cache/database. MUSTN't be null.
+ * @param serverFile Data of file (just) retrieved from a remote server. If null, will be
+ * retrieved from network by the operation when executed.
+ * @param account ownCloud account holding the file.
+ * @param syncFileContents When 'true', transference of data will be started by the
+ * operation if needed and no conflict is detected.
+ * @param allowUploads When 'false', uploads to the server are not done; only downloads or conflict
+ * detection.
+ * @param context Android context; needed to start transfers.
+ */
+ public SynchronizeFileOperation(
+ OCFile localFile,
+ OCFile serverFile,
+ Account account,
+ boolean syncFileContents,
+ boolean allowUploads,
+ Context context) {
+
+ this(localFile, serverFile, account, syncFileContents, context);
+ mAllowUploads = allowUploads;
}
boolean serverChanged = false;
/* time for eTag is coming, but not yet
if (mServerFile.getEtag() != null) {
- serverChanged = (!mServerFile.getEtag().equals(mLocalFile.getEtag())); // TODO could this be dangerous when the user upgrades the server from non-tagged to tagged?
+ serverChanged = (!mServerFile.getEtag().equals(mLocalFile.getEtag()));
} else { */
- // server without etags
- serverChanged = (mServerFile.getModificationTimestamp() != mLocalFile.getModificationTimestampAtLastSyncForData());
+ serverChanged = (
+ mServerFile.getModificationTimestamp() != mLocalFile.getModificationTimestampAtLastSyncForData()
+ );
//}
- boolean localChanged = (mLocalFile.getLocalModificationTimestamp() > mLocalFile.getLastSyncDateForData());
- // TODO this will be always true after the app is upgraded to database version 2; will result in unnecessary uploads
+ boolean localChanged = (
+ mLocalFile.getLocalModificationTimestamp() > mLocalFile.getLastSyncDateForData()
+ );
/// decide action to perform depending upon changes
//if (!mLocalFile.getEtag().isEmpty() && localChanged && serverChanged) {
result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
} else if (localChanged) {
- if (mSyncFileContents) {
+ if (mSyncFileContents && mAllowUploads) {
requestForUpload(mLocalFile);
// the local update of file properties will be done by the FileUploader service when the upload finishes
} else {
}
- Log_OC.i(TAG, "Synchronizing " + mAccount.name + ", file " + mLocalFile.getRemotePath() + ": " + result.getLogMessage());
+ Log_OC.i(TAG, "Synchronizing " + mAccount.name + ", file " + mLocalFile.getRemotePath() + ": "
+ + result.getLogMessage());
return result;
}
package com.owncloud.android.operations;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
-import org.apache.http.HttpStatus;
import android.accounts.Account;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
-//import android.support.v4.content.LocalBroadcastManager;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
-
+import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.resources.shares.OCShare;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
+import com.owncloud.android.lib.common.operations.OperationCancelledException;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation;
-import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.RemoteFile;
-
-import com.owncloud.android.syncadapter.FileSyncAdapter;
+import com.owncloud.android.operations.common.SyncOperation;
+import com.owncloud.android.services.OperationsService;
import com.owncloud.android.utils.FileStorageUtils;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+//import android.support.v4.content.LocalBroadcastManager;
/**
*
* @author David A. Velasco
*/
-public class SynchronizeFolderOperation extends RemoteOperation {
+public class SynchronizeFolderOperation extends SyncOperation {
private static final String TAG = SynchronizeFolderOperation.class.getSimpleName();
- public static final String EVENT_SINGLE_FOLDER_CONTENTS_SYNCED =
- SynchronizeFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_CONTENTS_SYNCED";
- public static final String EVENT_SINGLE_FOLDER_SHARES_SYNCED =
- SynchronizeFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_SHARES_SYNCED";
-
/** Time stamp for the synchronization process in progress */
private long mCurrentSyncTime;
-
- /** Remote folder to synchronize */
- private OCFile mLocalFolder;
-
- /** Access to the local database */
- private FileDataStorageManager mStorageManager;
+
+ /** Remote path of the folder to synchronize */
+ private String mRemotePath;
/** Account where the file to synchronize belongs */
private Account mAccount;
-
+
/** Android context; necessary to send requests to the download service */
private Context mContext;
-
+
+ /** Locally cached information about folder to synchronize */
+ private OCFile mLocalFolder;
+
/** Files and folders contained in the synchronized folder after a successful operation */
- private List<OCFile> mChildren;
+ //private List<OCFile> mChildren;
/** Counter of conflicts found between local and remote files */
private int mConflictsFound;
/** Counter of failed operations in synchronization of kept-in-sync files */
- private int mFailsInFavouritesFound;
+ private int mFailsInFileSyncsFound;
- /**
- * Map of remote and local paths to files that where locally stored in a location
- * out of the ownCloud folder and couldn't be copied automatically into it
- **/
- private Map<String, String> mForgottenLocalFiles;
-
- /** 'True' means that this operation is part of a full account synchronization */
- private boolean mSyncFullAccount;
-
- /** 'True' means that Share resources bound to the files into should be refreshed also */
- private boolean mIsShareSupported;
-
/** 'True' means that the remote folder changed and should be fetched */
private boolean mRemoteFolderChanged;
- /** 'True' means that Etag will be ignored */
- private boolean mIgnoreETag;
-
+ private List<OCFile> mFilesForDirectDownload;
+ // to avoid extra PROPFINDs when there was no change in the folder
+ private List<SyncOperation> mFilesToSyncContentsWithoutUpload;
+ // this will go out when 'folder synchronization' replaces 'folder download'; step by step
+
+ private List<SyncOperation> mFavouriteFilesToSyncContents;
+ // this will be used for every file when 'folder synchronization' replaces 'folder download'
+
+ private final AtomicBoolean mCancellationRequested;
+
/**
* Creates a new instance of {@link SynchronizeFolderOperation}.
- *
- * @param folder Folder to synchronize.
- * @param currentSyncTime Time stamp for the synchronization process in progress.
- * @param syncFullAccount 'True' means that this operation is part of a full account
- * synchronization.
- * @param isShareSupported 'True' means that the server supports the sharing API.
- * @param ignoreEtag 'True' means that the content of the remote folder should
- * be fetched and updated even though the 'eTag' did not
- * change.
- * @param dataStorageManager Interface with the local database.
- * @param account ownCloud account where the folder is located.
+ *
* @param context Application context.
+ * @param remotePath Path to synchronize.
+ * @param account ownCloud account where the folder is located.
+ * @param currentSyncTime Time stamp for the synchronization process in progress.
*/
- public SynchronizeFolderOperation( OCFile folder,
- long currentSyncTime,
- boolean syncFullAccount,
- boolean isShareSupported,
- boolean ignoreETag,
- FileDataStorageManager dataStorageManager,
- Account account,
- Context context ) {
- mLocalFolder = folder;
+ public SynchronizeFolderOperation(Context context, String remotePath, Account account, long currentSyncTime){
+ mRemotePath = remotePath;
mCurrentSyncTime = currentSyncTime;
- mSyncFullAccount = syncFullAccount;
- mIsShareSupported = isShareSupported;
- mStorageManager = dataStorageManager;
mAccount = account;
mContext = context;
- mForgottenLocalFiles = new HashMap<String, String>();
mRemoteFolderChanged = false;
- mIgnoreETag = ignoreETag;
+ mFilesForDirectDownload = new Vector<OCFile>();
+ mFilesToSyncContentsWithoutUpload = new Vector<SyncOperation>();
+ mFavouriteFilesToSyncContents = new Vector<SyncOperation>();
+ mCancellationRequested = new AtomicBoolean(false);
}
-
-
+
+
public int getConflictsFound() {
return mConflictsFound;
}
-
- public int getFailsInFavouritesFound() {
- return mFailsInFavouritesFound;
- }
-
- public Map<String, String> getForgottenLocalFiles() {
- return mForgottenLocalFiles;
- }
-
- /**
- * Returns the list of files and folders contained in the synchronized folder,
- * if called after synchronization is complete.
- *
- * @return List of files and folders contained in the synchronized folder.
- */
- public List<OCFile> getChildren() {
- return mChildren;
+
+ public int getFailsInFileSyncsFound() {
+ return mFailsInFileSyncsFound;
}
-
+
/**
* Performs the synchronization.
- *
+ *
* {@inheritDoc}
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
- mFailsInFavouritesFound = 0;
+ mFailsInFileSyncsFound = 0;
mConflictsFound = 0;
- mForgottenLocalFiles.clear();
-
- if (FileUtils.PATH_SEPARATOR.equals(mLocalFolder.getRemotePath()) && !mSyncFullAccount) {
- updateOCVersion(client);
- }
- result = checkForChanges(client);
-
- if (result.isSuccess()) {
- if (mRemoteFolderChanged) {
- result = fetchAndSyncRemoteFolder(client);
- } else {
- mChildren = mStorageManager.getFolderContent(mLocalFolder);
+ try {
+ // get locally cached information about folder
+ mLocalFolder = getStorageManager().getFileByPath(mRemotePath);
+
+ result = checkForChanges(client);
+
+ if (result.isSuccess()) {
+ if (mRemoteFolderChanged) {
+ result = fetchAndSyncRemoteFolder(client);
+
+ } else {
+ prepareOpsFromLocalKnowledge();
+ }
+
+ if (result.isSuccess()) {
+ syncContents(client);
+ }
+
}
+
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();
+ }
+
+ } catch (OperationCancelledException e) {
+ result = new RemoteOperationResult(e);
}
-
- if (!mSyncFullAccount) {
- sendLocalBroadcast(
- EVENT_SINGLE_FOLDER_CONTENTS_SYNCED, mLocalFolder.getRemotePath(), result
- );
- }
-
- if (result.isSuccess() && mIsShareSupported && !mSyncFullAccount) {
- refreshSharesForFolder(client); // share result is ignored
- }
-
- if (!mSyncFullAccount) {
- sendLocalBroadcast(
- EVENT_SINGLE_FOLDER_SHARES_SYNCED, mLocalFolder.getRemotePath(), result
- );
- }
-
- return result;
-
- }
+ return result;
- private void updateOCVersion(OwnCloudClient client) {
- UpdateOCVersionOperation update = new UpdateOCVersionOperation(mAccount, mContext);
- RemoteOperationResult result = update.execute(client);
- if (result.isSuccess()) {
- mIsShareSupported = update.getOCVersion().isSharedSupported();
- }
}
-
- private RemoteOperationResult checkForChanges(OwnCloudClient client) {
+ private RemoteOperationResult checkForChanges(OwnCloudClient client) throws OperationCancelledException {
+ Log_OC.d(TAG, "Checking changes in " + mAccount.name + mRemotePath);
+
mRemoteFolderChanged = true;
RemoteOperationResult result = null;
- String remotePath = null;
-
- remotePath = mLocalFolder.getRemotePath();
- Log_OC.d(TAG, "Checking changes in " + mAccount.name + remotePath);
- // remote request
- ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath);
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();
+ }
+
+ // remote request
+ ReadRemoteFileOperation operation = new ReadRemoteFileOperation(mRemotePath);
result = operation.execute(client);
if (result.isSuccess()){
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
- if (!mIgnoreETag) {
- // check if remote and local folder are different
- mRemoteFolderChanged =
+ // check if remote and local folder are different
+ mRemoteFolderChanged =
!(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag()));
- }
result = new RemoteOperationResult(ResultCode.OK);
-
- Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " +
+
+ Log_OC.i(TAG, "Checked " + mAccount.name + mRemotePath + " : " +
(mRemoteFolderChanged ? "changed" : "not changed"));
-
+
} else {
// check failed
if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
removeLocalFolder();
}
if (result.isException()) {
- Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
+ Log_OC.e(TAG, "Checked " + mAccount.name + mRemotePath + " : " +
result.getLogMessage(), result.getException());
} else {
- Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
+ Log_OC.e(TAG, "Checked " + mAccount.name + mRemotePath + " : " +
result.getLogMessage());
}
+
}
-
+
return result;
}
- private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) {
- String remotePath = mLocalFolder.getRemotePath();
- ReadRemoteFolderOperation operation = new ReadRemoteFolderOperation(remotePath);
- RemoteOperationResult result = operation.execute(client);
- Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath);
+ private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) throws OperationCancelledException {
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();
+ }
+ ReadRemoteFolderOperation operation = new ReadRemoteFolderOperation(mRemotePath);
+ RemoteOperationResult result = operation.execute(client);
+ Log_OC.d(TAG, "Synchronizing " + mAccount.name + mRemotePath);
+
if (result.isSuccess()) {
synchronizeData(result.getData(), client);
- if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {
- result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
+ if (mConflictsFound > 0 || mFailsInFileSyncsFound > 0) {
+ result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
// should be a different result code, but will do the job
}
} else {
removeLocalFolder();
}
+
return result;
}
-
+
private void removeLocalFolder() {
- if (mStorageManager.fileExists(mLocalFolder.getFileId())) {
+ FileDataStorageManager storageManager = getStorageManager();
+ if (storageManager.fileExists(mLocalFolder.getFileId())) {
String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
- mStorageManager.removeFolder(
- mLocalFolder,
- true,
- ( mLocalFolder.isDown() &&
+ storageManager.removeFolder(
+ mLocalFolder,
+ true,
+ ( mLocalFolder.isDown() && // TODO: debug, I think this is always false for folders
mLocalFolder.getStoragePath().startsWith(currentSavePath)
)
);
/**
- * Synchronizes the data retrieved from the server about the contents of the target folder
+ * Synchronizes the data retrieved from the server about the contents of the target folder
* with the current data in the local database.
- *
+ *
* Grants that mChildren is updated with fresh data after execution.
- *
- * @param folderAndFiles Remote folder and children files in Folder
- *
- * @param client Client instance to the remote server where the data were
- * retrieved.
+ *
+ * @param folderAndFiles Remote folder and children files in Folder
+ *
+ * @param client Client instance to the remote server where the data were
+ * retrieved.
* @return 'True' when any change was made in the local data, 'false' otherwise
*/
- private void synchronizeData(ArrayList<Object> folderAndFiles, OwnCloudClient client) {
- // get 'fresh data' from the database
- mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath());
-
- // parse data from remote folder
+ private void synchronizeData(ArrayList<Object> folderAndFiles, OwnCloudClient client)
+ throws OperationCancelledException {
+ FileDataStorageManager storageManager = getStorageManager();
+
+ // parse data from remote folder
OCFile remoteFolder = fillOCFile((RemoteFile)folderAndFiles.get(0));
remoteFolder.setParentId(mLocalFolder.getParentId());
remoteFolder.setFileId(mLocalFolder.getFileId());
-
- Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath()
+
+ Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath()
+ " changed - starting update of local data ");
-
+
List<OCFile> updatedFiles = new Vector<OCFile>(folderAndFiles.size() - 1);
- List<SynchronizeFileOperation> filesToSyncContents = new Vector<SynchronizeFileOperation>();
+ mFilesForDirectDownload.clear();
+ mFilesToSyncContentsWithoutUpload.clear();
+ mFavouriteFilesToSyncContents.clear();
+
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();
+ }
// get current data about local contents of the folder to synchronize
- List<OCFile> localFiles = mStorageManager.getFolderContent(mLocalFolder);
+ List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder);
Map<String, OCFile> localFilesMap = new HashMap<String, OCFile>(localFiles.size());
for (OCFile file : localFiles) {
localFilesMap.put(file.getRemotePath(), file);
}
-
- // loop to update every child
+
+ // loop to synchronize every child
OCFile remoteFile = null, localFile = null;
for (int i=1; i<folderAndFiles.size(); i++) {
/// new OCFile instance with the data from the server
remoteFile = fillOCFile((RemoteFile)folderAndFiles.get(i));
remoteFile.setParentId(mLocalFolder.getFileId());
- /// retrieve local data for the read file
+ /// retrieve local data for the read file
// localFile = mStorageManager.getFileByPath(remoteFile.getRemotePath());
localFile = localFilesMap.remove(remoteFile.getRemotePath());
-
+
/// add to the remoteFile (the new one) data about LOCAL STATE (not existing in server)
remoteFile.setLastSyncDateForProperties(mCurrentSyncTime);
if (localFile != null) {
localFile.getModificationTimestampAtLastSyncForData()
);
remoteFile.setStoragePath(localFile.getStoragePath());
- // eTag will not be updated unless contents are synchronized
+ // eTag will not be updated unless contents are synchronized
// (Synchronize[File|Folder]Operation with remoteFile as parameter)
- remoteFile.setEtag(localFile.getEtag());
+ remoteFile.setEtag(localFile.getEtag());
if (remoteFile.isFolder()) {
- remoteFile.setFileLength(localFile.getFileLength());
+ remoteFile.setFileLength(localFile.getFileLength());
// TODO move operations about size of folders to FileContentProvider
} else if (mRemoteFolderChanged && remoteFile.isImage() &&
remoteFile.getModificationTimestamp() != localFile.getModificationTimestamp()) {
remoteFile.setPublicLink(localFile.getPublicLink());
remoteFile.setShareByLink(localFile.isShareByLink());
} else {
- // remote eTag will not be updated unless contents are synchronized
+ // remote eTag will not be updated unless contents are synchronized
// (Synchronize[File|Folder]Operation with remoteFile as parameter)
- remoteFile.setEtag("");
+ remoteFile.setEtag("");
}
/// check and fix, if needed, local storage path
- checkAndFixForeignStoragePath(remoteFile); // policy - local files are COPIED
- // into the ownCloud local folder;
- searchForLocalFileInDefaultPath(remoteFile); // legacy
-
- /// prepare content synchronization for kept-in-sync files
- if (remoteFile.keepInSync()) {
- SynchronizeFileOperation operation = new SynchronizeFileOperation( localFile,
- remoteFile,
- mAccount,
- true,
- mContext
- );
+ searchForLocalFileInDefaultPath(remoteFile);
+
+ /// classify file to sync/download contents later
+ if (remoteFile.isFolder()) {
+ /// to download children files recursively
+ synchronized(mCancellationRequested) {
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();
+ }
+ startSyncFolderOperation(remoteFile.getRemotePath());
+ }
+
+ } else if (remoteFile.keepInSync()) {
+ /// prepare content synchronization for kept-in-sync files
+ SynchronizeFileOperation operation = new SynchronizeFileOperation(
+ localFile,
+ remoteFile,
+ mAccount,
+ true,
+ mContext
+ );
+ mFavouriteFilesToSyncContents.add(operation);
- filesToSyncContents.add(operation);
+ } else {
+ /// prepare limited synchronization for regular files
+ SynchronizeFileOperation operation = new SynchronizeFileOperation(
+ localFile,
+ remoteFile,
+ mAccount,
+ true,
+ false,
+ mContext
+ );
+ mFilesToSyncContentsWithoutUpload.add(operation);
}
-
+
updatedFiles.add(remoteFile);
}
// save updated contents in local database
- mStorageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());
+ storageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());
- // request for the synchronization of file contents AFTER saving current remote properties
- startContentSynchronizations(filesToSyncContents, client);
+ }
+
+
+ private void prepareOpsFromLocalKnowledge() throws OperationCancelledException {
+ List<OCFile> children = getStorageManager().getFolderContent(mLocalFolder);
+ for (OCFile child : children) {
+ /// classify file to sync/download contents later
+ if (child.isFolder()) {
+ /// to download children files recursively
+ synchronized(mCancellationRequested) {
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();
+ }
+ startSyncFolderOperation(child.getRemotePath());
+ }
- mChildren = updatedFiles;
+ } else {
+ /// prepare limited synchronization for regular files
+ if (!child.isDown()) {
+ mFilesForDirectDownload.add(child);
+ }
+ }
+ }
+ }
+
+
+ private void syncContents(OwnCloudClient client) throws OperationCancelledException {
+ startDirectDownloads();
+ startContentSynchronizations(mFilesToSyncContentsWithoutUpload, client);
+ startContentSynchronizations(mFavouriteFilesToSyncContents, client);
+ }
+
+
+ private void startDirectDownloads() throws OperationCancelledException {
+ for (OCFile file : mFilesForDirectDownload) {
+ synchronized(mCancellationRequested) {
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();
+ }
+ Intent i = new Intent(mContext, FileDownloader.class);
+ i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
+ i.putExtra(FileDownloader.EXTRA_FILE, file);
+ mContext.startService(i);
+ }
+ }
}
/**
* Performs a list of synchronization operations, determining if a download or upload is needed
* or if exists conflict due to changes both in local and remote contents of the each file.
- *
- * If download or upload is needed, request the operation to the corresponding service and goes
+ *
+ * If download or upload is needed, request the operation to the corresponding service and goes
* on.
- *
+ *
* @param filesToSyncContents Synchronization operations to execute.
* @param client Interface to the remote ownCloud server.
*/
- private void startContentSynchronizations(
- List<SynchronizeFileOperation> filesToSyncContents, OwnCloudClient client
- ) {
+ private void startContentSynchronizations(List<SyncOperation> filesToSyncContents, OwnCloudClient client)
+ throws OperationCancelledException {
+
RemoteOperationResult contentsResult = null;
- for (SynchronizeFileOperation op: filesToSyncContents) {
- contentsResult = op.execute(mStorageManager, mContext); // async
+ for (SyncOperation op: filesToSyncContents) {
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();
+ }
+ contentsResult = op.execute(getStorageManager(), mContext);
if (!contentsResult.isSuccess()) {
if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
mConflictsFound++;
} else {
- mFailsInFavouritesFound++;
+ mFailsInFileSyncsFound++;
if (contentsResult.getException() != null) {
- Log_OC.e(TAG, "Error while synchronizing favourites : "
+ Log_OC.e(TAG, "Error while synchronizing file : "
+ contentsResult.getLogMessage(), contentsResult.getException());
} else {
- Log_OC.e(TAG, "Error while synchronizing favourites : "
+ Log_OC.e(TAG, "Error while synchronizing file : "
+ contentsResult.getLogMessage());
}
}
+ // TODO - use the errors count in notifications
} // won't let these fails break the synchronization process
}
}
-
- public boolean isMultiStatus(int status) {
- return (status == HttpStatus.SC_MULTI_STATUS);
- }
-
+
/**
- * Creates and populates a new {@link OCFile} object with the data read from the server.
- *
+ * Creates and populates a new {@link com.owncloud.android.datamodel.OCFile} object with the data read from the server.
+ *
* @param remote remote file read from the server (remote file or folder).
* @return New OCFile instance representing the remote resource described by we.
*/
file.setRemoteId(remote.getRemoteId());
return file;
}
-
- /**
- * Checks the storage path of the OCFile received as parameter.
- * If it's out of the local ownCloud folder, tries to copy the file inside it.
- *
- * If the copy fails, the link to the local file is nullified. The account of forgotten
- * files is kept in {@link #mForgottenLocalFiles}
- *)
- * @param file File to check and fix.
- */
- private void checkAndFixForeignStoragePath(OCFile file) {
- String storagePath = file.getStoragePath();
- String expectedPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
- if (storagePath != null && !storagePath.equals(expectedPath)) {
- /// fix storagePaths out of the local ownCloud folder
- File originalFile = new File(storagePath);
- if (FileStorageUtils.getUsableSpace(mAccount.name) < originalFile.length()) {
- mForgottenLocalFiles.put(file.getRemotePath(), storagePath);
- file.setStoragePath(null);
-
- } else {
- InputStream in = null;
- OutputStream out = null;
- try {
- File expectedFile = new File(expectedPath);
- File expectedParent = expectedFile.getParentFile();
- expectedParent.mkdirs();
- if (!expectedParent.isDirectory()) {
- throw new IOException(
- "Unexpected error: parent directory could not be created"
- );
- }
- expectedFile.createNewFile();
- if (!expectedFile.isFile()) {
- throw new IOException("Unexpected error: target file could not be created");
- }
- in = new FileInputStream(originalFile);
- out = new FileOutputStream(expectedFile);
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0){
- out.write(buf, 0, len);
- }
- file.setStoragePath(expectedPath);
-
- } catch (Exception e) {
- Log_OC.e(TAG, "Exception while copying foreign file " + expectedPath, e);
- mForgottenLocalFiles.put(file.getRemotePath(), storagePath);
- file.setStoragePath(null);
-
- } finally {
- try {
- if (in != null) in.close();
- } catch (Exception e) {
- Log_OC.d(TAG, "Weird exception while closing input stream for "
- + storagePath + " (ignoring)", e);
- }
- try {
- if (out != null) out.close();
- } catch (Exception e) {
- Log_OC.d(TAG, "Weird exception while closing output stream for "
- + expectedPath + " (ignoring)", e);
- }
- }
- }
- }
- }
-
-
- private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) {
- RemoteOperationResult result = null;
-
- // remote request
- GetRemoteSharesForFileOperation operation =
- new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), false, true);
- result = operation.execute(client);
-
- if (result.isSuccess()) {
- // update local database
- ArrayList<OCShare> shares = new ArrayList<OCShare>();
- for(Object obj: result.getData()) {
- shares.add((OCShare) obj);
- }
- mStorageManager.saveSharesInFolder(shares, mLocalFolder);
- }
-
- return result;
- }
-
/**
* Scans the default location for saving local copies of files searching for
- * a 'lost' file with the same full name as the {@link OCFile} received as
+ * a 'lost' file with the same full name as the {@link com.owncloud.android.datamodel.OCFile} received as
* parameter.
*
* @param file File to associate a possible 'lost' local file.
/**
- * Sends a message to any application component interested in the progress
- * of the synchronization.
- *
- * @param event
- * @param dirRemotePath Remote path of a folder that was just synchronized
- * (with or without success)
- * @param result
+ * Cancel operation
*/
- private void sendLocalBroadcast(
- String event, String dirRemotePath, RemoteOperationResult result
- ) {
- Log_OC.d(TAG, "Send broadcast " + event);
- Intent intent = new Intent(event);
- intent.putExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME, mAccount.name);
- if (dirRemotePath != null) {
- intent.putExtra(FileSyncAdapter.EXTRA_FOLDER_PATH, dirRemotePath);
- }
- intent.putExtra(FileSyncAdapter.EXTRA_RESULT, result);
- mContext.sendStickyBroadcast(intent);
- //LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
+ public void cancel() {
+ mCancellationRequested.set(true);
}
+ public String getFolderPath() {
+ String path = mLocalFolder.getStoragePath();
+ if (path != null && path.length() > 0) {
+ return path;
+ }
+ return FileStorageUtils.getDefaultSavePathFor(mAccount.name, mLocalFolder);
+ }
- public boolean getRemoteFolderChanged() {
- return mRemoteFolderChanged;
+ private void startSyncFolderOperation(String path){
+ Intent intent = new Intent(mContext, OperationsService.class);
+ intent.setAction(OperationsService.ACTION_SYNC_FOLDER);
+ intent.putExtra(OperationsService.EXTRA_ACCOUNT, mAccount);
+ intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, path);
+ mContext.startService(intent);
}
+ public String getRemotePath() {
+ return mRemotePath;
+ }
}
ProviderTableMeta.FILE_REMOTE_ID);
mFileProjectionMap.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL,
ProviderTableMeta.FILE_UPDATE_THUMBNAIL);
+ mFileProjectionMap.put(ProviderTableMeta.FILE_IS_DOWNLOADING,
+ ProviderTableMeta.FILE_IS_DOWNLOADING);
}
private static final int SINGLE_FILE = 1;
+ ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, "
+ ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
+ ProviderTableMeta.FILE_REMOTE_ID + " TEXT null,"
- + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER);" //boolean
+ + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER," //boolean
+ + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER);" //boolean
);
// Create table ocshares
}
}
if (!upgraded)
- Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
+ Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
+ ", newVersion == " + newVersion);
+
+ if (oldVersion < 9 && newVersion >= 9) {
+ Log_OC.i("SQL", "Entering in the #9 ADD in onUpgrade");
+ db.beginTransaction();
+ try {
+ db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
+ " ADD COLUMN " + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER " +
+ " DEFAULT 0");
+
+ upgraded = true;
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ }
+ if (!upgraded)
+ Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
", newVersion == " + newVersion);
}
}
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
+import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareLinkOperation;
import android.accounts.Account;
public static final String EXTRA_SYNC_FILE_CONTENTS = "SYNC_FILE_CONTENTS";
public static final String EXTRA_RESULT = "RESULT";
public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH";
-
+ public static final String EXTRA_FILE = "FILE";
+
// TODO review if ALL OF THEM are necessary
public static final String EXTRA_SUCCESS_IF_ABSENT = "SUCCESS_IF_ABSENT";
public static final String EXTRA_USERNAME = "USERNAME";
public static final String ACTION_REMOVE = "REMOVE";
public static final String ACTION_CREATE_FOLDER = "CREATE_FOLDER";
public static final String ACTION_SYNC_FILE = "SYNC_FILE";
+ public static final String ACTION_SYNC_FOLDER = "SYNC_FOLDER"; // for the moment, just to download
+ //public static final String ACTION_CANCEL_SYNC_FOLDER = "CANCEL_SYNC_FOLDER"; // for the moment, just to download
public static final String ACTION_MOVE_FILE = "MOVE_FILE";
public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
- private ConcurrentLinkedQueue<Pair<Target, RemoteOperation>> mPendingOperations =
- new ConcurrentLinkedQueue<Pair<Target, RemoteOperation>>();
private ConcurrentMap<Integer, Pair<RemoteOperation, RemoteOperationResult>>
mUndispatchedFinishedOperations =
}
}
- private Looper mServiceLooper;
- private ServiceHandler mServiceHandler;
- private OperationsServiceBinder mBinder;
- private OwnCloudClient mOwnCloudClient = null;
- private Target mLastTarget = null;
- private FileDataStorageManager mStorageManager;
- private RemoteOperation mCurrentOperation = null;
+ private ServiceHandler mOperationsHandler;
+ private OperationsServiceBinder mOperationsBinder;
+ private SyncFolderHandler mSyncFolderHandler;
/**
* Service initialization
@Override
public void onCreate() {
super.onCreate();
- HandlerThread thread = new HandlerThread("Operations service thread", Process.THREAD_PRIORITY_BACKGROUND);
+ /// First worker thread for most of operations
+ HandlerThread thread = new HandlerThread("Operations thread", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
- mServiceLooper = thread.getLooper();
- mServiceHandler = new ServiceHandler(mServiceLooper, this);
- mBinder = new OperationsServiceBinder();
+ mOperationsHandler = new ServiceHandler(thread.getLooper(), this);
+ mOperationsBinder = new OperationsServiceBinder(mOperationsHandler);
+
+ /// Separated worker thread for download of folders (WIP)
+ thread = new HandlerThread("Syncfolder thread", Process.THREAD_PRIORITY_BACKGROUND);
+ thread.start();
+ mSyncFolderHandler = new SyncFolderHandler(thread.getLooper(), this);
}
*
* New operations are added calling to startService(), resulting in a call to this method.
* This ensures the service will keep on working although the caller activity goes away.
- *
- * IMPORTANT: the only operations performed here right now is {@link GetSharedFilesOperation}. The class
- * is taking advantage of it due to time constraints.
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- //Log_OC.wtf(TAG, "onStartCommand init" );
- Message msg = mServiceHandler.obtainMessage();
- msg.arg1 = startId;
- mServiceHandler.sendMessage(msg);
- //Log_OC.wtf(TAG, "onStartCommand end" );
+ // WIP: for the moment, only SYNC_FOLDER and CANCEL_SYNC_FOLDER is expected here;
+ // the rest of the operations are requested through the Binder
+ if (ACTION_SYNC_FOLDER.equals(intent.getAction())) {
+
+ /*Log_OC.v("NOW " + TAG + ", thread " + Thread.currentThread().getName(), "Received request to sync folder");*/
+
+ if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) {
+ Log_OC.e(TAG, "Not enough information provided in intent");
+ return START_NOT_STICKY;
+ }
+ Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
+ String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);
+
+ Pair<Account, String> itemSyncKey = new Pair<Account , String>(account, remotePath);
+
+ Pair<Target, RemoteOperation> itemToQueue = newOperation(intent);
+ if (itemToQueue != null) {
+ mSyncFolderHandler.add(account, remotePath, (SynchronizeFolderOperation)itemToQueue.second);
+ Message msg = mSyncFolderHandler.obtainMessage();
+ msg.arg1 = startId;
+ msg.obj = itemSyncKey;
+ /*Log_OC.v(
+ "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Sync folder " + remotePath + " added to queue"
+ );*/
+ mSyncFolderHandler.sendMessage(msg);
+ }
+
+ } else {
+ Message msg = mOperationsHandler.obtainMessage();
+ msg.arg1 = startId;
+ mOperationsHandler.sendMessage(msg);
+ }
+
return START_NOT_STICKY;
}
e.printStackTrace();
}
- //Log_OC.wtf(TAG, "Clear mUndispatchedFinisiedOperations" );
+ //Log_OC.wtf(TAG, "Clear mUndispatchedFinishedOperations" );
mUndispatchedFinishedOperations.clear();
//Log_OC.wtf(TAG, "onDestroy end" );
super.onDestroy();
}
-
/**
* Provides a binder object that clients can use to perform actions on the queue of operations,
* except the addition of new operations.
@Override
public IBinder onBind(Intent intent) {
//Log_OC.wtf(TAG, "onBind" );
- return mBinder;
+ return mOperationsBinder;
}
*/
@Override
public boolean onUnbind(Intent intent) {
- ((OperationsServiceBinder)mBinder).clearListeners();
+ ((OperationsServiceBinder)mOperationsBinder).clearListeners();
return false; // not accepting rebinding (default behaviour)
}
-
+
/**
* Binder to let client components to perform actions on the queue of operations.
*
private ConcurrentMap<OnRemoteOperationListener, Handler> mBoundListeners =
new ConcurrentHashMap<OnRemoteOperationListener, Handler>();
+ private ServiceHandler mServiceHandler = null;
+
+ public OperationsServiceBinder(ServiceHandler serviceHandler) {
+ mServiceHandler = serviceHandler;
+ }
+
+
/**
- * Cancels an operation
+ * Cancels a pending or current synchronization.
*
- * TODO
+ * @param account ownCloud account where the remote folder is stored.
+ * @param file A folder in the queue of pending synchronizations
*/
- public void cancel() {
- // TODO
+ public void cancel(Account account, OCFile file) {
+ /*Log_OC.v(
+ "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Received request to cancel folder " + file.getRemotePath()
+ );*/
+ mSyncFolderHandler.cancel(account, file);
}
-
-
+
+
public void clearListeners() {
mBoundListeners.clear();
* @return 'True' when an operation that enforces the user to wait for completion is in process.
*/
public boolean isPerformingBlockingOperation() {
- return (!mPendingOperations.isEmpty());
+ return (!mServiceHandler.mPendingOperations.isEmpty());
}
/**
- * Creates and adds to the queue a new operation, as described by operationIntent
+ * Creates and adds to the queue a new operation, as described by operationIntent.
+ *
+ * Calls startService to make the operation is processed by the ServiceHandler.
*
* @param operationIntent Intent describing a new operation to queue and execute.
* @return Identifier of the operation created, or null if failed.
*/
- public long newOperation(Intent operationIntent) {
- RemoteOperation operation = null;
- Target target = null;
- try {
- if (!operationIntent.hasExtra(EXTRA_ACCOUNT) &&
- !operationIntent.hasExtra(EXTRA_SERVER_URL)) {
- Log_OC.e(TAG, "Not enough information provided in intent");
-
- } else {
- Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
- String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
- String username = operationIntent.getStringExtra(EXTRA_USERNAME);
- String password = operationIntent.getStringExtra(EXTRA_PASSWORD);
- String authToken = operationIntent.getStringExtra(EXTRA_AUTH_TOKEN);
- String cookie = operationIntent.getStringExtra(EXTRA_COOKIE);
- target = new Target(
- account,
- (serverUrl == null) ? null : Uri.parse(serverUrl),
- username,
- password,
- authToken,
- cookie
- );
-
- String action = operationIntent.getAction();
- if (action.equals(ACTION_CREATE_SHARE)) { // Create Share
- String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- Intent sendIntent = operationIntent.getParcelableExtra(EXTRA_SEND_INTENT);
- if (remotePath.length() > 0) {
- operation = new CreateShareOperation(OperationsService.this, remotePath, ShareType.PUBLIC_LINK,
- "", false, "", 1, sendIntent);
- }
-
- } else if (action.equals(ACTION_UNSHARE)) { // Unshare file
- String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- if (remotePath.length() > 0) {
- operation = new UnshareLinkOperation(
- remotePath,
- OperationsService.this);
- }
-
- } else if (action.equals(ACTION_GET_SERVER_INFO)) {
- // check OC server and get basic information from it
- operation = new GetServerInfoOperation(serverUrl, OperationsService.this);
-
- } else if (action.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN)) {
- /// GET ACCESS TOKEN to the OAuth server
- String oauth2QueryParameters =
- operationIntent.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS);
- operation = new OAuth2GetAccessToken(
- getString(R.string.oauth2_client_id),
- getString(R.string.oauth2_redirect_uri),
- getString(R.string.oauth2_grant_type),
- oauth2QueryParameters);
-
- } else if (action.equals(ACTION_EXISTENCE_CHECK)) {
- // Existence Check
- String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- boolean successIfAbsent = operationIntent.getBooleanExtra(EXTRA_SUCCESS_IF_ABSENT, false);
- operation = new ExistenceCheckRemoteOperation(remotePath, OperationsService.this, successIfAbsent);
-
- } else if (action.equals(ACTION_GET_USER_NAME)) {
- // Get User Name
- operation = new GetRemoteUserNameOperation();
-
- } else if (action.equals(ACTION_RENAME)) {
- // Rename file or folder
- String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
- operation = new RenameFileOperation(remotePath, newName);
-
- } else if (action.equals(ACTION_REMOVE)) {
- // Remove file or folder
- String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
- operation = new RemoveFileOperation(remotePath, onlyLocalCopy);
-
- } else if (action.equals(ACTION_CREATE_FOLDER)) {
- // Create Folder
- String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true);
- operation = new CreateFolderOperation(remotePath, createFullPath);
-
- } else if (action.equals(ACTION_SYNC_FILE)) {
- // Sync file
- String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- boolean syncFileContents = operationIntent.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS, true);
- operation = new SynchronizeFileOperation(remotePath, account, syncFileContents, getApplicationContext());
- } else if (action.equals(ACTION_MOVE_FILE)) {
- // Move file/folder
- String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
- operation = new MoveFileOperation(remotePath,newParentPath,account);
- }
-
- }
-
- } catch (IllegalArgumentException e) {
- Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
- operation = null;
- }
-
- if (operation != null) {
- mPendingOperations.add(new Pair<Target , RemoteOperation>(target, operation));
+ public long queueNewOperation(Intent operationIntent) {
+ Pair<Target, RemoteOperation> itemToQueue = newOperation(operationIntent);
+ if (itemToQueue != null) {
+ mServiceHandler.mPendingOperations.add(itemToQueue);
startService(new Intent(OperationsService.this, OperationsService.class));
- //Log_OC.wtf(TAG, "New operation added, opId: " + operation.hashCode());
- // better id than hash? ; should be good enough by the time being
- return operation.hashCode();
+ return itemToQueue.second.hashCode();
} else {
- //Log_OC.wtf(TAG, "New operation failed, returned Long.MAX_VALUE");
return Long.MAX_VALUE;
}
}
-
+
+
public boolean dispatchResultIfFinished(int operationId, OnRemoteOperationListener listener) {
Pair<RemoteOperation, RemoteOperationResult> undispatched =
mUndispatchedFinishedOperations.remove(operationId);
return true;
//Log_OC.wtf(TAG, "Sending callback later");
} else {
- if (!mPendingOperations.isEmpty()) {
+ if (!mServiceHandler.mPendingOperations.isEmpty()) {
return true;
} else {
return false;
//Log_OC.wtf(TAG, "Not finished yet");
}
}
+
+
+ /**
+ * Returns True when the file described by 'file' in the ownCloud account 'account' is downloading or waiting
+ * to download.
+ *
+ * If 'file' is a directory, returns 'true' if some of its descendant files is downloading or waiting
+ * to download.
+ *
+ * @param account ownCloud account where the remote file is stored.
+ * @param remotePath Path of the folder to check if something is synchronizing / downloading / uploading
+ * inside.
+ */
+ public boolean isSynchronizing(Account account, String remotePath) {
+ return mSyncFolderHandler.isSynchronizing(account, remotePath);
+ }
}
-
-
- /**
+
+
+ /**
* Operations worker. Performs the pending operations in the order they were requested.
*
* Created with the Looper of a new thread, started in {@link OperationsService#onCreate()}.
*/
private static class ServiceHandler extends Handler {
// don't make it a final class, and don't remove the static ; lint will warn about a possible memory leak
+
+
OperationsService mService;
+
+
+ private ConcurrentLinkedQueue<Pair<Target, RemoteOperation>> mPendingOperations =
+ new ConcurrentLinkedQueue<Pair<Target, RemoteOperation>>();
+ private RemoteOperation mCurrentOperation = null;
+ private Target mLastTarget = null;
+ private OwnCloudClient mOwnCloudClient = null;
+ private FileDataStorageManager mStorageManager;
+
+
public ServiceHandler(Looper looper, OperationsService service) {
super(looper);
if (service == null) {
@Override
public void handleMessage(Message msg) {
- mService.nextOperation();
+ nextOperation();
mService.stopSelf(msg.arg1);
}
- }
-
-
- /**
- * Performs the next operation in the queue
- */
- private void nextOperation() {
- //Log_OC.wtf(TAG, "nextOperation init" );
- Pair<Target, RemoteOperation> next = null;
- synchronized(mPendingOperations) {
- next = mPendingOperations.peek();
- }
-
- if (next != null) {
+ /**
+ * Performs the next operation in the queue
+ */
+ private void nextOperation() {
- mCurrentOperation = next.second;
- RemoteOperationResult result = null;
- try {
- /// prepare client object to send the request to the ownCloud server
- if (mLastTarget == null || !mLastTarget.equals(next.first)) {
- mLastTarget = next.first;
- if (mLastTarget.mAccount != null) {
- OwnCloudAccount ocAccount = new OwnCloudAccount(mLastTarget.mAccount, this);
- mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
- getClientFor(ocAccount, this);
- mStorageManager =
- new FileDataStorageManager(
- mLastTarget.mAccount,
- getContentResolver());
- } else {
- OwnCloudCredentials credentials = null;
- if (mLastTarget.mUsername != null &&
- mLastTarget.mUsername.length() > 0) {
- credentials = OwnCloudCredentialsFactory.newBasicCredentials(
- mLastTarget.mUsername,
- mLastTarget.mPassword); // basic
-
- } else if (mLastTarget.mAuthToken != null &&
- mLastTarget.mAuthToken.length() > 0) {
- credentials = OwnCloudCredentialsFactory.newBearerCredentials(
- mLastTarget.mAuthToken); // bearer token
-
- } else if (mLastTarget.mCookie != null &&
- mLastTarget.mCookie.length() > 0) {
- credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(
- mLastTarget.mCookie); // SAML SSO
+ //Log_OC.wtf(TAG, "nextOperation init" );
+
+ Pair<Target, RemoteOperation> next = null;
+ synchronized(mPendingOperations) {
+ next = mPendingOperations.peek();
+ }
+
+ if (next != null) {
+
+ mCurrentOperation = next.second;
+ RemoteOperationResult result = null;
+ try {
+ /// prepare client object to send the request to the ownCloud server
+ if (mLastTarget == null || !mLastTarget.equals(next.first)) {
+ mLastTarget = next.first;
+ if (mLastTarget.mAccount != null) {
+ OwnCloudAccount ocAccount = new OwnCloudAccount(mLastTarget.mAccount, mService);
+ mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, mService);
+ mStorageManager = new FileDataStorageManager(
+ mLastTarget.mAccount,
+ mService.getContentResolver()
+ );
+ } else {
+ OwnCloudCredentials credentials = null;
+ if (mLastTarget.mUsername != null &&
+ mLastTarget.mUsername.length() > 0) {
+ credentials = OwnCloudCredentialsFactory.newBasicCredentials(
+ mLastTarget.mUsername,
+ mLastTarget.mPassword); // basic
+
+ } else if (mLastTarget.mAuthToken != null &&
+ mLastTarget.mAuthToken.length() > 0) {
+ credentials = OwnCloudCredentialsFactory.newBearerCredentials(
+ mLastTarget.mAuthToken); // bearer token
+
+ } else if (mLastTarget.mCookie != null &&
+ mLastTarget.mCookie.length() > 0) {
+ credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(
+ mLastTarget.mCookie); // SAML SSO
+ }
+ OwnCloudAccount ocAccount = new OwnCloudAccount(
+ mLastTarget.mServerUrl, credentials);
+ mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, mService);
+ mStorageManager = null;
}
- OwnCloudAccount ocAccount = new OwnCloudAccount(
- mLastTarget.mServerUrl, credentials);
- mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
- getClientFor(ocAccount, this);
- mStorageManager = null;
}
- }
- /// perform the operation
- if (mCurrentOperation instanceof SyncOperation) {
- result = ((SyncOperation)mCurrentOperation).execute(mOwnCloudClient, mStorageManager);
- } else {
- result = mCurrentOperation.execute(mOwnCloudClient);
- }
+ /// perform the operation
+ if (mCurrentOperation instanceof SyncOperation) {
+ result = ((SyncOperation)mCurrentOperation).execute(mOwnCloudClient, mStorageManager);
+ } else {
+ result = mCurrentOperation.execute(mOwnCloudClient);
+ }
+
+ } catch (AccountsException e) {
+ if (mLastTarget.mAccount == null) {
+ Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", e);
+ } else {
+ Log_OC.e(TAG, "Error while trying to get authorization for " + mLastTarget.mAccount.name, e);
+ }
+ result = new RemoteOperationResult(e);
+
+ } catch (IOException e) {
+ if (mLastTarget.mAccount == null) {
+ Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", e);
+ } else {
+ Log_OC.e(TAG, "Error while trying to get authorization for " + mLastTarget.mAccount.name, e);
+ }
+ result = new RemoteOperationResult(e);
+ } catch (Exception e) {
+ if (mLastTarget.mAccount == null) {
+ Log_OC.e(TAG, "Unexpected error for a NULL account", e);
+ } else {
+ Log_OC.e(TAG, "Unexpected error for " + mLastTarget.mAccount.name, e);
+ }
+ result = new RemoteOperationResult(e);
- } catch (AccountsException e) {
- if (mLastTarget.mAccount == null) {
- Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", e);
- } else {
- Log_OC.e(TAG, "Error while trying to get authorization for " + mLastTarget.mAccount.name, e);
+ } finally {
+ synchronized(mPendingOperations) {
+ mPendingOperations.poll();
+ }
}
- result = new RemoteOperationResult(e);
- } catch (IOException e) {
- if (mLastTarget.mAccount == null) {
- Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", e);
- } else {
- Log_OC.e(TAG, "Error while trying to get authorization for " + mLastTarget.mAccount.name, e);
- }
- result = new RemoteOperationResult(e);
- } catch (Exception e) {
- if (mLastTarget.mAccount == null) {
- Log_OC.e(TAG, "Unexpected error for a NULL account", e);
- } else {
- Log_OC.e(TAG, "Unexpected error for " + mLastTarget.mAccount.name, e);
- }
- result = new RemoteOperationResult(e);
-
- } finally {
- synchronized(mPendingOperations) {
- mPendingOperations.poll();
- }
+ //sendBroadcastOperationFinished(mLastTarget, mCurrentOperation, result);
+ mService.dispatchResultToOperationListeners(mLastTarget, mCurrentOperation, result);
}
-
- //sendBroadcastOperationFinished(mLastTarget, mCurrentOperation, result);
- dispatchResultToOperationListeners(mLastTarget, mCurrentOperation, result);
}
+
+
+
}
+
+ /**
+ * Creates a new operation, as described by operationIntent.
+ *
+ * TODO - move to ServiceHandler (probably)
+ *
+ * @param operationIntent Intent describing a new operation to queue and execute.
+ * @return Pair with the new operation object and the information about its target server.
+ */
+ private Pair<Target , RemoteOperation> newOperation(Intent operationIntent) {
+ RemoteOperation operation = null;
+ Target target = null;
+ try {
+ if (!operationIntent.hasExtra(EXTRA_ACCOUNT) &&
+ !operationIntent.hasExtra(EXTRA_SERVER_URL)) {
+ Log_OC.e(TAG, "Not enough information provided in intent");
+
+ } else {
+ Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
+ String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
+ String username = operationIntent.getStringExtra(EXTRA_USERNAME);
+ String password = operationIntent.getStringExtra(EXTRA_PASSWORD);
+ String authToken = operationIntent.getStringExtra(EXTRA_AUTH_TOKEN);
+ String cookie = operationIntent.getStringExtra(EXTRA_COOKIE);
+ target = new Target(
+ account,
+ (serverUrl == null) ? null : Uri.parse(serverUrl),
+ username,
+ password,
+ authToken,
+ cookie
+ );
+
+ String action = operationIntent.getAction();
+ if (action.equals(ACTION_CREATE_SHARE)) { // Create Share
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ Intent sendIntent = operationIntent.getParcelableExtra(EXTRA_SEND_INTENT);
+ if (remotePath.length() > 0) {
+ operation = new CreateShareOperation(OperationsService.this, remotePath, ShareType.PUBLIC_LINK,
+ "", false, "", 1, sendIntent);
+ }
+
+ } else if (action.equals(ACTION_UNSHARE)) { // Unshare file
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ if (remotePath.length() > 0) {
+ operation = new UnshareLinkOperation(
+ remotePath,
+ OperationsService.this);
+ }
+
+ } else if (action.equals(ACTION_GET_SERVER_INFO)) {
+ // check OC server and get basic information from it
+ operation = new GetServerInfoOperation(serverUrl, OperationsService.this);
+
+ } else if (action.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN)) {
+ /// GET ACCESS TOKEN to the OAuth server
+ String oauth2QueryParameters =
+ operationIntent.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS);
+ operation = new OAuth2GetAccessToken(
+ getString(R.string.oauth2_client_id),
+ getString(R.string.oauth2_redirect_uri),
+ getString(R.string.oauth2_grant_type),
+ oauth2QueryParameters);
+
+ } else if (action.equals(ACTION_EXISTENCE_CHECK)) {
+ // Existence Check
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ boolean successIfAbsent = operationIntent.getBooleanExtra(EXTRA_SUCCESS_IF_ABSENT, false);
+ operation = new ExistenceCheckRemoteOperation(remotePath, OperationsService.this, successIfAbsent);
+
+ } else if (action.equals(ACTION_GET_USER_NAME)) {
+ // Get User Name
+ operation = new GetRemoteUserNameOperation();
+
+ } else if (action.equals(ACTION_RENAME)) {
+ // Rename file or folder
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
+ operation = new RenameFileOperation(remotePath, newName);
+
+ } else if (action.equals(ACTION_REMOVE)) {
+ // Remove file or folder
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
+ operation = new RemoveFileOperation(remotePath, onlyLocalCopy);
+
+ } else if (action.equals(ACTION_CREATE_FOLDER)) {
+ // Create Folder
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true);
+ operation = new CreateFolderOperation(remotePath, createFullPath);
+
+ } else if (action.equals(ACTION_SYNC_FILE)) {
+ // Sync file
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ boolean syncFileContents = operationIntent.getBooleanExtra(EXTRA_SYNC_FILE_CONTENTS, true);
+ operation = new SynchronizeFileOperation(
+ remotePath, account, syncFileContents, getApplicationContext()
+ );
+
+ } else if (action.equals(ACTION_SYNC_FOLDER)) {
+ // Sync file
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ operation = new SynchronizeFolderOperation(
+ this, // TODO remove this dependency from construction time
+ remotePath,
+ account,
+ System.currentTimeMillis() // TODO remove this dependency from construction time
+ );
+
+ } else if (action.equals(ACTION_MOVE_FILE)) {
+ // Move file/folder
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
+ operation = new MoveFileOperation(remotePath,newParentPath,account);
+ }
+
+ }
+
+ } catch (IllegalArgumentException e) {
+ Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
+ operation = null;
+ }
+
+ if (operation != null) {
+ return new Pair<Target , RemoteOperation>(target, operation);
+ } else {
+ return null;
+ }
+ }
+
/**
* Sends a broadcast when a new operation is added to the queue.
/**
* Notifies the currently subscribed listeners about the end of an operation.
- *
+ *
* @param target Account or URL pointing to an OC server.
* @param operation Finished operation.
* @param result Result of the operation.
*/
- private void dispatchResultToOperationListeners(
+ protected void dispatchResultToOperationListeners(
Target target, final RemoteOperation operation, final RemoteOperationResult result) {
int count = 0;
- Iterator<OnRemoteOperationListener> listeners = mBinder.mBoundListeners.keySet().iterator();
+ Iterator<OnRemoteOperationListener> listeners = mOperationsBinder.mBoundListeners.keySet().iterator();
while (listeners.hasNext()) {
final OnRemoteOperationListener listener = listeners.next();
- final Handler handler = mBinder.mBoundListeners.get(listener);
+ final Handler handler = mOperationsBinder.mBoundListeners.get(listener);
if (handler != null) {
handler.post(new Runnable() {
@Override
}
Log_OC.d(TAG, "Called " + count + " listeners");
}
-
-
}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2015 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.services;
+
+import android.accounts.Account;
+import android.accounts.AccountsException;
+import android.content.Intent;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.util.Pair;
+
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.services.FileDownloader;
+import com.owncloud.android.files.services.IndexedForest;
+import com.owncloud.android.lib.common.OwnCloudAccount;
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.operations.SynchronizeFolderOperation;
+import com.owncloud.android.utils.FileStorageUtils;
+
+import java.io.IOException;
+
+/**
+ * SyncFolder worker. Performs the pending operations in the order they were requested.
+ *
+ * Created with the Looper of a new thread, started in
+ * {@link com.owncloud.android.services.OperationsService#onCreate()}.
+ */
+class SyncFolderHandler extends Handler {
+
+ private static final String TAG = SyncFolderHandler.class.getSimpleName();
+
+
+ OperationsService mService;
+
+ private IndexedForest<SynchronizeFolderOperation> mPendingOperations =
+ new IndexedForest<SynchronizeFolderOperation>();
+
+ private OwnCloudClient mOwnCloudClient = null;
+ private Account mCurrentAccount = null;
+ private FileDataStorageManager mStorageManager;
+ private SynchronizeFolderOperation mCurrentSyncOperation;
+
+
+ public SyncFolderHandler(Looper looper, OperationsService service) {
+ super(looper);
+ if (service == null) {
+ throw new IllegalArgumentException("Received invalid NULL in parameter 'service'");
+ }
+ mService = service;
+ }
+
+
+ /**
+ * Returns True when the folder located in 'remotePath' in the ownCloud account 'account', or any of its
+ * descendants, is being synchronized (or waiting for it).
+ *
+ * @param account ownCloud account where the remote folder is stored.
+ * @param remotePath The path to a folder that could be in the queue of synchronizations.
+ */
+ public boolean isSynchronizing(Account account, String remotePath) {
+ if (account == null || remotePath == null) return false;
+ return (mPendingOperations.contains(account, remotePath));
+ }
+
+
+ @Override
+ public void handleMessage(Message msg) {
+ Pair<Account, String> itemSyncKey = (Pair<Account, String>) msg.obj;
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Handling sync folder " + itemSyncKey.second);*/
+ doOperation(itemSyncKey.first, itemSyncKey.second);
+ mService.stopSelf(msg.arg1);
+ }
+
+
+ /**
+ * Performs the next operation in the queue
+ */
+ private void doOperation(Account account, String remotePath) {
+
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Getting sync folder " + remotePath);*/
+ mCurrentSyncOperation = mPendingOperations.get(account, remotePath);
+
+ if (mCurrentSyncOperation != null) {
+ RemoteOperationResult result = null;
+
+ try {
+
+ if (mCurrentAccount == null || !mCurrentAccount.equals(account)) {
+ mCurrentAccount = account;
+ mStorageManager = new FileDataStorageManager(
+ account,
+ mService.getContentResolver()
+ );
+ } // else, reuse storage manager from previous operation
+
+ // always get client from client manager, to get fresh credentials in case of update
+ OwnCloudAccount ocAccount = new OwnCloudAccount(account, mService);
+ mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, mService);
+
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Executing sync folder " + remotePath);*/
+ result = mCurrentSyncOperation.execute(mOwnCloudClient, mStorageManager);
+
+ } catch (AccountsException e) {
+ Log_OC.e(TAG, "Error while trying to get authorization", e);
+ } catch (IOException e) {
+ Log_OC.e(TAG, "Error while trying to get authorization", e);
+ } finally {
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Removing payload " + remotePath);*/
+
+ mPendingOperations.removePayload(account, remotePath);
+
+ mService.dispatchResultToOperationListeners(null, mCurrentSyncOperation, result);
+
+ sendBroadcastFinishedSyncFolder(account, remotePath, result.isSuccess());
+ }
+ }
+ }
+
+ public void add(Account account, String remotePath, SynchronizeFolderOperation syncFolderOperation){
+ mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation);
+ sendBroadcastNewSyncFolder(account, remotePath); // TODO upgrade!
+ }
+
+
+ /**
+ * Cancels a pending or current sync' operation.
+ *
+ * @param account ownCloud account where the remote file is stored.
+ * @param file A file in the queue of pending synchronizations
+ */
+ public void cancel(Account account, OCFile file){
+ if (account == null || file == null) {
+ Log_OC.e(TAG, "Cannot cancel with NULL parameters");
+ return;
+ }
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Removing sync folder " + file.getRemotePath());*/
+ Pair<SynchronizeFolderOperation, String> removeResult =
+ mPendingOperations.remove(account, file.getRemotePath());
+ SynchronizeFolderOperation synchronization = removeResult.first;
+ if (synchronization != null) {
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Canceling returned sync of " + file.getRemotePath());*/
+ synchronization.cancel();
+ } else {
+ // TODO synchronize?
+ if (mCurrentSyncOperation != null && mCurrentAccount != null &&
+ mCurrentSyncOperation.getRemotePath().startsWith(file.getRemotePath()) &&
+ account.name.equals(mCurrentAccount.name)) {
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Canceling current sync as descendant: " + mCurrentSyncOperation.getRemotePath());*/
+ mCurrentSyncOperation.cancel();
+ } else {
+ /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
+ "Nothing else in cancelation of " + file.getRemotePath());*/
+ }
+ }
+
+ //sendBroadcastFinishedSyncFolder(account, file.getRemotePath());
+ }
+
+ /**
+ * TODO review this method when "folder synchronization" replaces "folder download"; this is a fast and ugly
+ * patch.
+ */
+ private void sendBroadcastNewSyncFolder(Account account, String remotePath) {
+ Intent added = new Intent(FileDownloader.getDownloadAddedMessage());
+ added.putExtra(FileDownloader.ACCOUNT_NAME, account.name);
+ added.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath);
+ added.putExtra(FileDownloader.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name) + remotePath);
+ mService.sendStickyBroadcast(added);
+ }
+
+ /**
+ * TODO review this method when "folder synchronization" replaces "folder download"; this is a fast and ugly
+ * patch.
+ */
+ private void sendBroadcastFinishedSyncFolder(Account account, String remotePath, boolean success) {
+ Intent finished = new Intent(FileDownloader.getDownloadFinishMessage());
+ finished.putExtra(FileDownloader.ACCOUNT_NAME, account.name);
+ finished.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath);
+ finished.putExtra(FileDownloader.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name) + remotePath);
+ finished.putExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, success);
+ mService.sendStickyBroadcast(finished);
+ }
+
+
+}
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.operations.SynchronizeFolderOperation;
+import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.operations.UpdateOCVersionOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
}
*/
// folder synchronization
- SynchronizeFolderOperation synchFolderOp = new SynchronizeFolderOperation( folder,
+ RefreshFolderOperation synchFolderOp = new RefreshFolderOperation( folder,
mCurrentSyncTime,
true,
mIsShareSupported,
import com.owncloud.android.files.FileOperationsHelper;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
+import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
public interface ComponentsGetter {
/**
- * Callback method invoked when the parent activity is fully created to get a reference to the FileDownloader service API.
- *
- * @return Directory to list firstly. Can be NULL.
+ * To be invoked when the parent activity is fully created to get a reference to the FileDownloader service API.
*/
public FileDownloaderBinder getFileDownloaderBinder();
/**
- * Callback method invoked when the parent activity is fully created to get a reference to the FileUploader service API.
- *
- * @return Directory to list firstly. Can be NULL.
+ * To be invoked when the parent activity is fully created to get a reference to the FileUploader service API.
*/
public FileUploaderBinder getFileUploaderBinder();
+ /**
+ * To be invoked when the parent activity is fully created to get a reference to the OperationsSerivce service API.
+ */
+ public OperationsServiceBinder getOperationsServiceBinder();
+
public FileDataStorageManager getStorageManager();
public FileOperationsHelper getFileOperationsHelper();
+
}
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.CreateShareOperation;
+import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.services.OperationsService;
} else if (operation instanceof UnshareLinkOperation) {
onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
- }
+ } else if (operation instanceof SynchronizeFolderOperation) {
+ onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result);
+
+ }
}
protected void requestCredentialsUpdate() {
t.show();
}
}
-
+
+ private void onSynchronizeFolderOperationFinish(SynchronizeFolderOperation operation, RemoteOperationResult result) {
+ if (!result.isSuccess() && result.getCode() != ResultCode.CANCELLED){
+ Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
+ Toast.LENGTH_LONG);
+ t.show();
+ }
+ }
protected void updateFileFromDB(){
OCFile file = getFile();
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.operations.SynchronizeFolderOperation;
+import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.syncadapter.FileSyncAdapter;
IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED);
- syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
- syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
+ syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
+ syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
mSyncBroadcastReceiver = new SyncBroadcastReceiver();
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
//LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
setFile(currentFile);
}
- mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
+ mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
- if (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
+ if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
equals(event) &&
/// TODO refactor and make common
synchResult != null && !synchResult.isSuccess() &&
/**
- * Class waiting for broadcast events from the {@link FielDownloader} service.
+ * Class waiting for broadcast events from the {@link FileDownloader} service.
*
* Updates the UI when a download is started or finished, provided that it is relevant for the
* current folder.
*/
private class DownloadFinishReceiver extends BroadcastReceiver {
+
+ //int refreshCounter = 0;
@Override
public void onReceive(Context context, Intent intent) {
try {
boolean sameAccount = isSameAccount(context, intent);
String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
boolean isDescendant = isDescendant(downloadedRemotePath);
-
+
if (sameAccount && isDescendant) {
- refreshListOfFilesFragment();
- refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
+ String linkedToRemotePath = intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
+ if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
+ //Log_OC.v(TAG, "refresh #" + ++refreshCounter);
+ refreshListOfFilesFragment();
+ }
+ refreshSecondFragment(
+ intent.getAction(),
+ downloadedRemotePath,
+ intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false)
+ );
}
if (mWaitingToSend != null) {
- mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath()); // Update the file to send
+ mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath());
if (mWaitingToSend.isDown()) {
sendDownloadedFile();
}
private boolean isDescendant(String downloadedRemotePath) {
OCFile currentDir = getCurrentDir();
- return (currentDir != null && downloadedRemotePath != null && downloadedRemotePath.startsWith(currentDir.getRemotePath()));
+ return (
+ currentDir != null &&
+ downloadedRemotePath != null &&
+ downloadedRemotePath.startsWith(currentDir.getRemotePath())
+ );
+ }
+
+ private boolean isAscendant(String linkedToRemotePath) {
+ OCFile currentDir = getCurrentDir();
+ return (
+ currentDir != null &&
+ currentDir.getRemotePath().startsWith(linkedToRemotePath)
+ );
}
private boolean isSameAccount(Context context, Intent intent) {
private void requestForDownload() {
Account account = getAccount();
+ //if (!mWaitingToPreview.isDownloading()) {
if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
Intent i = new Intent(this, FileDownloader.class);
i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
mSyncInProgress = true;
// perform folder synchronization
- RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder,
+ RemoteOperation synchFolderOp = new RefreshFolderOperation( folder,
currentSyncTime,
false,
getFileOperationsHelper().isSharedSupported(),
private void requestForDownload(OCFile file) {
Account account = getAccount();
- if (!mDownloaderBinder.isDownloading(account, file)) {
+ if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
Intent i = new Intent(this, FileDownloader.class);
i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
i.putExtra(FileDownloader.EXTRA_FILE, file);
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.CreateFolderOperation;
-import com.owncloud.android.operations.SynchronizeFolderOperation;
+import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
import com.owncloud.android.ui.fragment.FileFragment;
mSyncInProgress = true;
// perform folder synchronization
- RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder,
+ RemoteOperation synchFolderOp = new RefreshFolderOperation( folder,
currentSyncTime,
false,
getFileOperationsHelper().isSharedSupported(),
IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED);
- syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
- syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
+ syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
+ syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
mSyncBroadcastReceiver = new SyncBroadcastReceiver();
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
}
mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&
- !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
+ !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
- if (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
+ if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
equals(event) &&
/// TODO refactor and make common
synchResult != null && !synchResult.isSuccess() &&
private String mAccountName;
private boolean mShowContextMenu = false;
private String mUploadPath;
+ private PreferenceCategory mPrefInstantUploadCategory;
+ private Preference mPrefInstantUpload;
private Preference mPrefInstantUploadPath;
+ private Preference mPrefInstantUploadPathWiFi;
+ private Preference mPrefInstantVideoUpload;
private Preference mPrefInstantVideoUploadPath;
+ private Preference mPrefInstantVideoUploadPathWiFi;
private String mUploadVideoPath;
}
});
}
-
+
+ mPrefInstantUploadCategory = (PreferenceCategory) findPreference("instant_uploading_category");
+
+ mPrefInstantUploadPathWiFi = findPreference("instant_upload_on_wifi");
+ mPrefInstantUpload = findPreference("instant_uploading");
+
+ toggleInstantPictureOptions(((CheckBoxPreference) mPrefInstantUpload).isChecked());
+
+ mPrefInstantUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ toggleInstantPictureOptions((Boolean) newValue);
+ return true;
+ }
+ });
+
mPrefInstantVideoUploadPath = findPreference("instant_video_upload_path");
if (mPrefInstantVideoUploadPath != null){
}
});
}
+
+ mPrefInstantVideoUploadPathWiFi = findPreference("instant_video_upload_on_wifi");
+ mPrefInstantVideoUpload = findPreference("instant_video_uploading");
+ toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked());
+
+ mPrefInstantVideoUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ toggleInstantVideoOptions((Boolean) newValue);
+ return true;
+ }
+ });
/* About App */
pAboutApp = (Preference) findPreference("about_app");
loadInstantUploadVideoPath();
}
+
+ private void toggleInstantPictureOptions(Boolean value){
+ if (value){
+ mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPathWiFi);
+ mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPath);
+ } else {
+ mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi);
+ mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath);
+ }
+ }
+
+ private void toggleInstantVideoOptions(Boolean value){
+ if (value){
+ mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPathWiFi);
+ mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPath);
+ } else {
+ mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi);
+ mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath);
+ }
+ }
@Override
protected void onPause() {
\r
\r
import java.io.File;\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
import java.util.Vector;\r
\r
-import third_parties.daveKoeller.AlphanumComparator;\r
import android.accounts.Account;\r
import android.content.Context;\r
import android.content.SharedPreferences;\r
import com.owncloud.android.datamodel.ThumbnailsCacheManager;\r
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
+import com.owncloud.android.services.OperationsService.OperationsServiceBinder;\r
import com.owncloud.android.ui.activity.ComponentsGetter;\r
import com.owncloud.android.utils.DisplayUtils;\r
import com.owncloud.android.utils.FileStorageUtils;\r
private FileDataStorageManager mStorageManager;\r
private Account mAccount;\r
private ComponentsGetter mTransferServiceGetter;\r
- \r
+\r
private SharedPreferences mAppPreferences;\r
\r
public FileListListAdapter(\r
boolean justFolders, \r
- Context context, \r
+ Context context,\r
ComponentsGetter transferServiceGetter\r
) {\r
\r
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);\r
\r
mTransferServiceGetter = transferServiceGetter;\r
- \r
+\r
mAppPreferences = PreferenceManager\r
.getDefaultSharedPreferences(mContext);\r
\r
\r
ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);\r
localStateView.bringToFront();\r
- FileDownloaderBinder downloaderBinder = \r
- mTransferServiceGetter.getFileDownloaderBinder();\r
+ FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();\r
FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();\r
- if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {\r
+ boolean downloading = (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file));\r
+ OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder();\r
+ downloading |= (opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath()));\r
+ if (downloading) {\r
localStateView.setImageResource(R.drawable.downloading_file_indicator);\r
localStateView.setVisibility(View.VISIBLE);\r
} else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {\r
// configure UI for depending upon local state of the file
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
- if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file))) {
+ if (transferring ||
+ (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) ||
+ (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file))
+ ) {
setButtonsForTransferring();
} else if (file.isDown()) {
progressText.setVisibility(View.VISIBLE);
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
+ //if (getFile().isDownloading()) {
if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) {
progressText.setText(R.string.downloader_download_in_progress_ticker);
} else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile())) {
boolean justFolders = (args == null) ? false : args.getBoolean(ARG_JUST_FOLDERS, false);
mAdapter = new FileListListAdapter(
justFolders,
- getSherlockActivity(),
+ getSherlockActivity(),
mContainerActivity
);
setListAdapter(mAdapter);
* @param transferring When true, the view must be updated assuming that the holded file is
* downloading, no matter what the downloaderBinder says.
*/
+ /*
public void updateView(boolean transferring) {
// configure UI for depending upon local state of the file
- FileDownloaderBinder downloaderBinder = (mContainerActivity == null) ? null : mContainerActivity.getFileDownloaderBinder();
- if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile()))) {
+ // TODO remove
+ if (transferring || getFile().isDownloading()) {
setButtonsForTransferring();
} else if (getFile().isDown()) {
getView().invalidate();
}
-
+ */
/**
* Enables or disables buttons for a file being downloaded
/**
- * Class waiting for broadcast events from the {@link FielDownloader} service.
+ * Class waiting for broadcast events from the {@link FileDownloader} service.
*
* Updates the UI when a download is started or finished, provided that it is relevant for the
* folder displayed in the gallery.
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
+import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.operations.UploadFileOperation;
// Show a Message, operation finished without success
message = res.getString(R.string.move_file_error);
}
+ } else if (operation instanceof SynchronizeFolderOperation) {
+
+ if (!result.isSuccess()) {
+ String folderPathName = new File(
+ ((SynchronizeFolderOperation) operation).getFolderPath()).getName();
+ if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
+ message = String.format(res.getString(R.string.sync_current_folder_was_removed),
+ folderPathName);
+
+ } else { // Generic error
+ // Show a Message, operation finished without success
+ message = String.format(res.getString(R.string.download_folder_failed_content),
+ folderPathName);
+ }
+ }
}
return message;
--- /dev/null
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " pdf to make PDF files"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " texinfo to make Texinfo files"
+ @echo " info to make Texinfo files and run them through makeinfo"
+ @echo " gettext to make PO message catalogs"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+ -rm -rf $(BUILDDIR)/*
+
+html: html-org
+
+html-all: html-release html-org html-com
+
+html-release:
+ $(SPHINXBUILD) -b html -D html_theme='owncloud_release' $(ALLSPHINXOPTS) $(BUILDDIR)/html/release
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html/release."
+
+html-org:
+ $(SPHINXBUILD) -b html -D html_theme='owncloud_org' $(ALLSPHINXOPTS) $(BUILDDIR)/html/org
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html/org."
+
+html-com:
+ $(SPHINXBUILD) -b html -D html_theme='owncloud_com' $(ALLSPHINXOPTS) $(BUILDDIR)/html/com
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html/com."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/OwncloudDocumentation.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/OwncloudDocumentation.qhc"
+
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/OwncloudDocumentation"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/OwncloudDocumentation"
+ @echo "# devhelp"
+
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+pdf:
+ $(SPHINXBUILD) -b pdf $(ALLSPHINXOPTS) $(BUILDDIR)/pdf
+ @echo
+ @echo "build finished. the text files are in $(BUILDDIR)/pdf."
+
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "build finished. the text files are in $(BUILDDIR)/text."
+
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo
+ @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+ @echo "Run \`make' in that directory to run these through makeinfo" \
+ "(use \`make info' here to do that automatically)."
+
+info:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo "Running Texinfo files through makeinfo..."
+ make -C $(BUILDDIR)/texinfo info
+ @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+ @echo
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
--- /dev/null
+==============================
+Using the ownCloud Android App
+==============================
+
+Accessing your files on your ownCloud server via the Web interface is easy and
+convenient, as you can use any Web browser on any operating system without
+installing special client software. However, the ownCloud Android app offers
+some advantages over the Web interface:
+
+* A simplified interface that fits nicely on a tablet or smartphone
+* Automatic synchronization of your files
+* Instant uploads of photos or videos recorded on your Android device
+* Easily add files from your device to ownCloud
+* Two-factor authentication
+
+Getting the ownCloud Android App
+--------------------------------
+
+One way to get your ownCloud Android app is to log into your ownCloud server
+from your Android device using a Web browser such as Chrome, Firefox, or
+Dolphin. The first time you log in to a new ownCloud account you'll see a screen
+with a download link to the ownCloud app in the `Google Play store
+<https://play.google.com/store/apps/details?id=com.owncloud.android>`_.
+
+.. figure:: images/android-first-screen.jpg
+
+You will also find these links on your Personal page in the Web interface,
+
+You can also get it from the `Amazon App store
+<http://www.amazon.com/ownCloud-Inc/dp/B00944PQMK/>`_, and get source code and
+more information from the `ownCloud download page
+<http://owncloud.org/install/#mobile>`_.
+
+Connecting to Your ownCloud Server
+----------------------------------
+
+The first time you run your ownCloud Android app it opens to a configuration
+screen. Enter your server URL, login name, password, and click the Connect
+button. (Click the eyeball to the right of your password to expose your
+password.)
+
+.. figure:: images/android-new-account.png
+
+For best security your ownCloud server should be SSL-enabled, so that you can
+connect via ``https``. The ownCloud app will test your connection as soon as
+you enter it and tell you if you entered it correctly. If your server has a
+self-signed SSL certificate you'll get a scary warning how it is not to be
+trusted. Click the OK button to accept the certificate and complete your account
+setup.
+
+.. figure:: images/android-ssl-cert.png
+
+Managing Files
+--------------
+
+Now you should see the Files page of your ownCloud account. Click the overflow
+button at the top right (that's the one with three vertical dots, and that is
+really what it is called) to open a user menu. ``Refresh account`` refreshes the
+page view. ``Settings`` take you to your settings menu. ``Sort`` gives you the
+option to sort your files by date, or alphabetically.
+
+.. figure:: images/android-files-page.png
+
+The little file folder icon to the left of the overflow button opens a dialog to
+create a new folder. The arrow button opens a file upload dialog, and you can
+either upload content from other Android apps such as Google Drive, the Gallery,
+your music player, or from your Android filesystem. When you add a new file
+you will see a confirmation on the top left when it has uploaded successfully,
+and it is immediately synchronized with the server.
+
+.. figure:: images/android-upload.png
+
+All files (that you have permission to access) on your ownCloud server are
+displayed in your Android app, but are not downloaded until you download them.
+Downloaded files are marked with a green arrow.
+
+.. figure:: images/android-file-list.png
+
+Download and preview a file with a short press on the filename. When the file
+is in preview mode, a short press on the overflow button opens a menu with
+options for sharing, opening with an app, removing, sending, and displaying file
+details.
+
+.. figure:: images/android-file.png
+
+
+A long press on the filename does not download it, but opens a dialog with
+options for sharing, downloading, renaming, moving, removing, sending, and
+viewing file details.
+
+
+.. figure:: images/android-file-options.png
+
+
+Settings
+--------
+
+The Settings screen offers a number of useful options. In the Accounts
+section you can configure multiple ownCloud accounts.
+
+The Security section sets up strong two-factor authentication by allowing you
+to add a PIN (personal identification number) to access your account.
+
+The Instant Uploads section creates a directory, :file:`/InstantUpload`, and
+any photos or videos created with your Android device's camera are instantly
+uploaded to this directory. You also have the option to choose any other
+existing directory. Another nice option is Upload Pictures/Video via WiFi Only,
+to conserve your Internet data usage.
+
+.. figure:: images/android-settings.png
+
+The bottom section of the Settings screen has links to help and the
+app's version number.
+
+.. figure:: images/android-help.png
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# ownCloud Documentation documentation build configuration file, created by
+# sphinx-quickstart on Mon Oct 22 23:16:40 2012.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os, inspect
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#sys.path.insert(0, os.path.abspath('.'))
+
+#path to this script
+scriptpath = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
+
+# -- General configuration -----------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.todo']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = [scriptpath+'/ocdoc/_shared_assets/templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'ownCloud Android App Manual'
+copyright = u'2013-2015, The ownCloud developers'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '1.6.2'
+# The full version, including alpha/beta/rc tags.
+release = version
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['_build','scripts/*', 'ocdoc/*']
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+2
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+html_theme_path = [scriptpath+'/ocdoc/_shared_assets/themes']
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+#html_theme = 'bootstrap'
+html_theme = 'default'
+# The name for this set of Sphinx documents. If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar. Default is the same as html_title.
+html_short_title = "Android App Manual"
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = [scriptpath+'/ocdoc/_shared_assets/static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+html_show_sphinx = False
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it. The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'ownCloudAndroidAppManual'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+latex_elements = {
+# The paper size ('letterpaper' or 'a4paper').
+#'papersize': 'letterpaper',
+
+# The font size ('10pt', '11pt' or '12pt').
+#'pointsize': '10pt',
+
+# Additional stuff for the LaTeX preamble.
+#'preamble': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+ ('index', 'ownCloudAndroidAppManual.tex', u'ownCloud Android App Manual',
+ u'The ownCloud developers', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ ('owncloud.1', 'owncloud', u'Android synchronisation and file management utility.',
+ [u'The ownCloud developers'], 1),
+ ('owncloudcmd.1', 'owncloudcmd', u'ownCloud Android app.',
+ [u'The ownCloud developers'], 1),
+]
+
+# If true, show URL addresses after external links.
+man_show_urls = True
+
+
+# -- Options for Texinfo output ------------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+# dir menu entry, description, category)
+texinfo_documents = [
+ ('index', 'ownCloudClientManual', u'ownCloud Android App Manual',
+ u'The ownCloud developers', 'ownCloud', 'The ownCloud Android App Manual.',
+ 'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
+
+
+# -- Options for Epub output ---------------------------------------------------
+
+# Bibliographic Dublin Core info.
+epub_title = u'ownCloud Android App Manual'
+epub_author = u'The ownCloud developers'
+epub_publisher = u'The ownCloud developers'
+epub_copyright = u'2013-2015, The ownCloud developers'
+
+# The language of the text. It defaults to the language option
+# or en if the language is not set.
+#epub_language = ''
+
+# The scheme of the identifier. Typical schemes are ISBN or URL.
+#epub_scheme = ''
+
+# The unique identifier of the text. This can be a ISBN number
+# or the project homepage.
+#epub_identifier = ''
+
+# A unique identification for the text.
+#epub_uid = ''
+
+# A tuple containing the cover image and cover page html template filenames.
+#epub_cover = ()
+
+# HTML files that should be inserted before the pages created by sphinx.
+# The format is a list of tuples containing the path and title.
+#epub_pre_files = []
+
+# HTML files shat should be inserted after the pages created by sphinx.
+# The format is a list of tuples containing the path and title.
+#epub_post_files = []
+
+# A list of files that should not be packed into the epub file.
+#epub_exclude_files = []
+
+# The depth of the table of contents in toc.ncx.
+#epub_tocdepth = 3
+
+# Allow duplicate toc entries.
+#epub_tocdup = True
+
+# Include todos?
+todo_include_todos = True
--- /dev/null
+.. _contents:
+
+ownCloud Android App Manual
+==============================
+
+.. toctree::
+ :maxdepth: 2
+
+ android_app
--- /dev/null
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=_build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
+set I18NSPHINXOPTS=%SPHINXOPTS% .
+if NOT "%PAPER%" == "" (
+ set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+ set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+ :help
+ echo.Please use `make ^<target^>` where ^<target^> is one of
+ echo. html to make standalone HTML files
+ echo. dirhtml to make HTML files named index.html in directories
+ echo. singlehtml to make a single large HTML file
+ echo. pdf to make a PDF file with rst2pdf
+ echo. pickle to make pickle files
+ echo. json to make JSON files
+ echo. htmlhelp to make HTML files and a HTML help project
+ echo. qthelp to make HTML files and a qthelp project
+ echo. devhelp to make HTML files and a Devhelp project
+ echo. epub to make an epub
+ echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+ echo. text to make text files
+ echo. man to make manual pages
+ echo. texinfo to make Texinfo files
+ echo. gettext to make PO message catalogs
+ echo. changes to make an overview over all changed/added/deprecated items
+ echo. linkcheck to check all external links for integrity
+ echo. doctest to run all doctests embedded in the documentation if enabled
+ goto end
+)
+
+if "%1" == "clean" (
+ for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+ del /q /s %BUILDDIR%\*
+ goto end
+)
+
+if "%1" == "html" (
+ %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+ goto end
+)
+
+if "%1" == "dirhtml" (
+ %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+ goto end
+)
+
+if "%1" == "singlehtml" (
+ %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+ goto end
+)
+
+if "%1" == "pdf" (
+ %SPHINXBUILD% -b pdf %ALLSPHINXOPTS% %BUILDDIR%/pdf
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The PDF file is in %BUILDDIR%/pdf.
+ goto end
+)
+
+if "%1" == "pickle" (
+ %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can process the pickle files.
+ goto end
+)
+
+if "%1" == "json" (
+ %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can process the JSON files.
+ goto end
+)
+
+if "%1" == "htmlhelp" (
+ %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+ goto end
+)
+
+if "%1" == "qthelp" (
+ %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+ echo.^> qcollectiongenerator %BUILDDIR%\qthelp\OwncloudDocumentation.qhcp
+ echo.To view the help file:
+ echo.^> assistant -collectionFile %BUILDDIR%\qthelp\OwncloudDocumentation.ghc
+ goto end
+)
+
+if "%1" == "devhelp" (
+ %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished.
+ goto end
+)
+
+if "%1" == "epub" (
+ %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The epub file is in %BUILDDIR%/epub.
+ goto end
+)
+
+if "%1" == "latex" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "text" (
+ %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The text files are in %BUILDDIR%/text.
+ goto end
+)
+
+if "%1" == "man" (
+ %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The manual pages are in %BUILDDIR%/man.
+ goto end
+)
+
+if "%1" == "texinfo" (
+ %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
+ goto end
+)
+
+if "%1" == "gettext" (
+ %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
+ goto end
+)
+
+if "%1" == "changes" (
+ %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.The overview file is in %BUILDDIR%/changes.
+ goto end
+)
+
+if "%1" == "linkcheck" (
+ %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+ goto end
+)
+
+if "%1" == "doctest" (
+ %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+ if errorlevel 1 exit /b 1
+ echo.
+ echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+ goto end
+)
+
+:end
--- /dev/null
+Subproject commit 343496c792616459e8204b6614fd42a1b16a6d68