summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2021-03-30 15:01:31 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2021-03-31 07:03:39 +0200
commit1b2f2b730b24103ca231fe3123172bb4503dedb9 (patch)
treefb34b6da16c3e488342f56a0b930c669d641b23d
parent76114ef23c02c21de31b3c9b9be4255772b279f3 (diff)
tdf#139350 android: Add param to allow a "real" "Save As"
So far, LOKitTileProvider's 'saveDocumentAs' method was always saving a copy of the current document (or doing an export), but was not continuing to use the newly saved doc afterwards. Add an additional parameter 'takeOwnership' to the method to specify whether to do so. In other words, * the 'takeOwnership=false' case continues to do what was done previously, it basically does what "File" -> "Save a Copy" or "File" -> "Export" does in the desktop version * the 'takeOwnership=true' case now basically does the same as "File" -> "Save As" in the desktop version (except that the path is already known in the Android case) This essentially forwards the "TakeOwnership" param to LibreOfficeKit, which was originally added there in commit a121074cbd07939713e169586469b934aedbe594 Date: Wed Feb 10 13:26:50 2016 +0100 lok: Introduce a "TakeOwnership" filter option for saveAs(). It is consumed by the saveAs() itself, and when provided, the document identity changes to the provided pUrl - meaning that '.uno:ModifiedStatus' is triggered as with the "Save As..." in the UI. This mode must not be used when saving to PNG or PDF. Change-Id: I11b5aa814476a8dcab9eac5202bd052828ebbd96 This also adds a new 'SAVE_COPY_AS' event type to save a copy without taking ownership, and switches all uses of the 'SAVE_AS' event to that new one for now. (So the behavior remains unchanged, but the terminology is hopefully clearer.) Except for one instance in LOKitTileProver::saveDocument (where the cached version of the document is written to the original URI, if present), all other places are left with the previous behaviour in this commit. Further changes will be done in follow-up commits. Change-Id: I11996cd7276a6c6f2774535cd3e53cb997c8cd4e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113375 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> (cherry picked from commit a1abf2c865228e6ed33e99ab73b94357ddbc590f)
-rw-r--r--android/source/src/java/org/libreoffice/LOEvent.java1
-rw-r--r--android/source/src/java/org/libreoffice/LOKitShell.java4
-rw-r--r--android/source/src/java/org/libreoffice/LOKitThread.java11
-rw-r--r--android/source/src/java/org/libreoffice/LOKitTileProvider.java26
-rw-r--r--android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java4
-rw-r--r--android/source/src/java/org/libreoffice/TileProvider.java12
6 files changed, 40 insertions, 18 deletions
diff --git a/android/source/src/java/org/libreoffice/LOEvent.java b/android/source/src/java/org/libreoffice/LOEvent.java
index 4db48a5bbd6d..74a09c92cc1d 100644
--- a/android/source/src/java/org/libreoffice/LOEvent.java
+++ b/android/source/src/java/org/libreoffice/LOEvent.java
@@ -42,6 +42,7 @@ public class LOEvent implements Comparable<LOEvent> {
public static final int REFRESH = 21;
public static final int PAGE_SIZE_CHANGED = 22;
public static final int UNO_COMMAND_NOTIFY = 23;
+ public static final int SAVE_COPY_AS = 24;
public final int mType;
diff --git a/android/source/src/java/org/libreoffice/LOKitShell.java b/android/source/src/java/org/libreoffice/LOKitShell.java
index 46ca256c7993..75b2fb09b260 100644
--- a/android/source/src/java/org/libreoffice/LOKitShell.java
+++ b/android/source/src/java/org/libreoffice/LOKitShell.java
@@ -119,6 +119,10 @@ public class LOKitShell {
LOKitShell.sendEvent(new LOEvent(filePath, fileFormat, LOEvent.SAVE_AS));
}
+ public static void sendSaveCopyAsEvent(String filePath, String fileFormat) {
+ LOKitShell.sendEvent(new LOEvent(filePath, fileFormat, LOEvent.SAVE_COPY_AS));
+ }
+
public static void sendResumeEvent(String inputFile, int partIndex) {
LOKitShell.sendEvent(new LOEvent(LOEvent.RESUME, inputFile, partIndex));
}
diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java b/android/source/src/java/org/libreoffice/LOKitThread.java
index e80e5af6c990..c20365d58fad 100644
--- a/android/source/src/java/org/libreoffice/LOKitThread.java
+++ b/android/source/src/java/org/libreoffice/LOKitThread.java
@@ -265,7 +265,7 @@ class LOKitThread extends Thread {
refresh();
LOKitShell.hideProgressSpinner(mContext);
- mTileProvider.saveDocumentAs(filePath);
+ mTileProvider.saveDocumentAs(filePath, false);
} else {
closeDocument();
}
@@ -274,11 +274,11 @@ class LOKitThread extends Thread {
/**
* Save the currently loaded document.
*/
- private void saveDocumentAs(String filePath, String fileType) {
+ private void saveDocumentAs(String filePath, String fileType, boolean bTakeOwnership) {
if (mTileProvider == null) {
Log.e(LOGTAG, "Error in saving, Tile Provider instance is null");
} else {
- mTileProvider.saveDocumentAs(filePath, fileType);
+ mTileProvider.saveDocumentAs(filePath, fileType, bTakeOwnership);
}
}
@@ -305,7 +305,10 @@ class LOKitThread extends Thread {
loadNewDocument(event.filePath, event.fileType);
break;
case LOEvent.SAVE_AS:
- saveDocumentAs(event.filePath, event.fileType);
+ saveDocumentAs(event.filePath, event.fileType, true);
+ break;
+ case LOEvent.SAVE_COPY_AS:
+ saveDocumentAs(event.filePath, event.fileType, false);
break;
case LOEvent.RESUME:
resumeDocument(event.mString, event.mPartIndex);
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index a887118c6aaa..0a9ad6a90685 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -42,7 +42,7 @@ class LOKitTileProvider implements TileProvider {
private static int TILE_SIZE = 256;
private final float mTileWidth;
private final float mTileHeight;
- private final String mInputFile;
+ private String mInputFile;
private Office mOffice;
private Document mDocument;
private boolean mIsReady = false;
@@ -298,11 +298,16 @@ class LOKitTileProvider implements TileProvider {
@Override
- public void saveDocumentAs(final String filePath, String format) {
+ public void saveDocumentAs(final String filePath, String format, boolean takeOwnership) {
+ String options = "";
+ if (takeOwnership) {
+ options = "TakeOwnership";
+ }
+
final String newFilePath = "file://" + filePath;
Log.d("saveFilePathURL", newFilePath);
LOKitShell.showProgressSpinner(mContext);
- mDocument.saveAs(newFilePath, format, "");
+ mDocument.saveAs(newFilePath, format, options);
if (!mOffice.getError().isEmpty()){
Log.e("Save Error", mOffice.getError());
if (format.equals("svg")) {
@@ -344,6 +349,7 @@ class LOKitTileProvider implements TileProvider {
}
});
} else {
+ mInputFile = filePath;
LOKitShell.getMainHandler().post(new Runnable() {
@Override
public void run() {
@@ -357,16 +363,16 @@ class LOKitTileProvider implements TileProvider {
}
@Override
- public void saveDocumentAs(final String filePath) {
+ public void saveDocumentAs(final String filePath, boolean takeOwnership) {
final int docType = mDocument.getDocumentType();
if (docType == Document.DOCTYPE_TEXT)
- saveDocumentAs(filePath, "odt");
+ saveDocumentAs(filePath, "odt", takeOwnership);
else if (docType == Document.DOCTYPE_SPREADSHEET)
- saveDocumentAs(filePath, "ods");
+ saveDocumentAs(filePath, "ods", takeOwnership);
else if (docType == Document.DOCTYPE_PRESENTATION)
- saveDocumentAs(filePath, "odp");
+ saveDocumentAs(filePath, "odp", takeOwnership);
else if (docType == Document.DOCTYPE_DRAWING)
- saveDocumentAs(filePath, "odg");
+ saveDocumentAs(filePath, "odg", takeOwnership);
else
Log.w(LOGTAG, "Cannot determine file format from document. Not saving.");
}
@@ -385,7 +391,7 @@ class LOKitTileProvider implements TileProvider {
mDocument.saveAs("file://"+cacheFile,"pdf","");
printDocument(cacheFile);
}else{
- saveDocumentAs(dir+"/"+file,"pdf");
+ saveDocumentAs(dir+"/"+file,"pdf", false);
}
}
@@ -435,7 +441,7 @@ class LOKitTileProvider implements TileProvider {
File input = new File(mInputFile);
final String cacheFile = cacheDir + "/lo_cached_" + input.getName();
String path = input.getAbsolutePath();
- saveDocumentAs(path, format);
+ saveDocumentAs(path, format, true);
(new File(cacheFile)).delete();
}else{
mContext.saveDocument();
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 368d19af1375..210b2bf2ffd5 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -365,7 +365,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
* Save a new document
* */
public void saveAs(){
- LOKitShell.sendSaveAsEvent(mInputFile.getPath(), FileUtilities.getExtension(mInputFile.getPath()).substring(1));
+ LOKitShell.sendSaveCopyAsEvent(mInputFile.getPath(), FileUtilities.getExtension(mInputFile.getPath()).substring(1));
}
/**
@@ -1057,7 +1057,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
if (mTempSlideShowFile.exists() && !isDocumentChanged) {
startPresentation("file://" + tempPath);
} else {
- LOKitShell.sendSaveAsEvent(tempPath, "svg");
+ LOKitShell.sendSaveCopyAsEvent(tempPath, "svg");
}
}
}
diff --git a/android/source/src/java/org/libreoffice/TileProvider.java b/android/source/src/java/org/libreoffice/TileProvider.java
index a848b4ae98d0..1a20c8b080d0 100644
--- a/android/source/src/java/org/libreoffice/TileProvider.java
+++ b/android/source/src/java/org/libreoffice/TileProvider.java
@@ -23,14 +23,22 @@ public interface TileProvider {
/**
* Save the current document under the given path.
+ * @param takeOwnership Whether to take ownership of the new file,
+ * i.e. whether the current document is changed to the
+ * newly saved document (takeOwnership = true),
+ * as compared to just saving a copy of the current document
+ * or exporting to a different file format.
+ * Must be 'false' when using this method for export to e.g. PNG or PDF.
*/
- void saveDocumentAs(String filePath, String format);
+ void saveDocumentAs(String filePath, String format, boolean takeOwnership);
/**
* Saves the current document under the given path,
* using the default file format.
+ * @param takeOwnership (s. documentation for
+ * 'saveDocumentAs(String filePath, String format, boolean takeOwnership)')
*/
- void saveDocumentAs(String filePath);
+ void saveDocumentAs(String filePath, boolean takeOwnership);
/**
* Returns the page width in pixels.