aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Kampas <martin.kampas@jolla.com>2018-10-25 08:46:08 +0200
committerSvetlana Abramenkova <sabramenkova@luxoft.com>2020-02-18 11:56:19 +0300
commit7525cdc6eacc0fc647b5ddbbf35f3f774ae99742 (patch)
tree33acbb7e7f10dcdce7f98a7e7f3d8c9bc19a84be
parentc051f6446f4c80e24254ffa6e3bdf2286b2dc27a (diff)
Only accept updates to existing documents by default
Change-Id: I30f9ea2b1b90bd228317035f6329577143421b6b Reviewed-by: Svetlana Abramenkova <sabramenkova@luxoft.com>
-rw-r--r--src/livenodeengine.cpp25
-rw-r--r--src/livenodeengine.h3
-rw-r--r--src/runtime/main.cpp9
3 files changed, 31 insertions, 6 deletions
diff --git a/src/livenodeengine.cpp b/src/livenodeengine.cpp
index 7ed9fcb..dbbea10 100644
--- a/src/livenodeengine.cpp
+++ b/src/livenodeengine.cpp
@@ -84,6 +84,9 @@
* is read only. Updates will be stored in a writable overlay stacked
* over the original workspace with the help of
* QQmlAbstractUrlInterceptor. Requires \l AllowUpdates.
+ * \value AllowCreateMissing
+ * Without this option enabled, updates are only accepted for existing
+ * workspace documents. Requires \l AllowUpdates.
*
* \sa {QML Live Runtime}
*/
@@ -506,13 +509,20 @@ void LiveNodeEngine::updateDocument(const LiveDocument &document, const QByteArr
return;
}
- QString filePath = (m_workspaceOptions & UpdatesAsOverlay)
+ QString documentPath = document.absoluteFilePathIn(m_workspace);
+
+ if (!(m_workspaceOptions & AllowCreateMissing)) {
+ if (!QFileInfo(documentPath).exists())
+ return;
+ }
+
+ QString writablePath = (m_workspaceOptions & UpdatesAsOverlay)
? m_overlay->reserve(document)
- : document.absoluteFilePathIn(m_workspace);
+ : documentPath;
- QString dirPath = QFileInfo(filePath).absoluteDir().absolutePath();
- QDir().mkpath(dirPath);
- QFile file(filePath);
+ QString writableDirPath = QFileInfo(writablePath).absoluteDir().absolutePath();
+ QDir().mkpath(writableDirPath);
+ QFile file(writablePath);
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << "Unable to save file: " << file.errorString();
return;
@@ -577,6 +587,11 @@ void LiveNodeEngine::setWorkspace(const QString &path, WorkspaceOptions options)
m_workspaceOptions |= AllowUpdates;
}
+ if ((m_workspaceOptions & AllowCreateMissing) && !(m_workspaceOptions & AllowUpdates)) {
+ qWarning() << "Got AllowCreateMissing without AllowUpdates. Enabling AllowUpdates.";
+ m_workspaceOptions |= AllowUpdates;
+ }
+
if (m_workspaceOptions & UpdatesAsOverlay) {
m_overlay = new Overlay(m_workspace.path(), this);
m_overlayUrlInterceptor = new OverlayUrlInterceptor(m_overlay, qmlEngine()->urlInterceptor(), this);
diff --git a/src/livenodeengine.h b/src/livenodeengine.h
index bc73457..8594084 100644
--- a/src/livenodeengine.h
+++ b/src/livenodeengine.h
@@ -53,7 +53,8 @@ public:
NoWorkspaceOption = 0x0,
LoadDummyData = 0x1,
AllowUpdates = 0x2,
- UpdatesAsOverlay = 0x4
+ UpdatesAsOverlay = 0x4,
+ AllowCreateMissing = 0x8
};
Q_DECLARE_FLAGS(WorkspaceOptions, WorkspaceOption)
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
diff --git a/src/runtime/main.cpp b/src/runtime/main.cpp
index aa8ae95..d4eefb5 100644
--- a/src/runtime/main.cpp
+++ b/src/runtime/main.cpp
@@ -46,6 +46,7 @@ struct Options
Options()
: updatesAsOverlay(false)
, updateOnConnect(false)
+ , allowCreateMissing(false)
, fullscreen(false)
, transparent(false)
, frameless(false)
@@ -63,6 +64,7 @@ struct Options
bool frameless;
bool stayontop;
bool hideButtons;
+ bool allowCreateMissing;
QString windowTitle;
QString activeDocument;
QString workspace;
@@ -102,6 +104,10 @@ static void parseArguments(const QStringList &arguments)
QCommandLineOption updateOnConnectOption("update-on-connect", "update all workspace documents initially (blocking).");
parser.addOption(updateOnConnectOption);
+ QCommandLineOption allowCreateMissingOption("allow-create-missing", "without this option updates are only "
+ "accepted for existing workspace documents.");
+ parser.addOption(allowCreateMissingOption);
+
QCommandLineOption fullScreenOption("fullscreen", "shows in fullscreen mode");
parser.addOption(fullScreenOption);
@@ -127,6 +133,7 @@ static void parseArguments(const QStringList &arguments)
options.stayontop = parser.isSet(stayOnTopOption);
options.updatesAsOverlay = parser.isSet(updatesAsOverlayOption);
options.updateOnConnect = parser.isSet(updateOnConnectOption);
+ options.allowCreateMissing = parser.isSet(allowCreateMissingOption);
options.fullscreen = parser.isSet(fullScreenOption);
options.transparent = parser.isSet(transparentOption);
options.frameless = parser.isSet(framelessOption);
@@ -205,6 +212,8 @@ int main(int argc, char** argv)
LiveNodeEngine::WorkspaceOptions workspaceOptions = LiveNodeEngine::LoadDummyData | LiveNodeEngine::AllowUpdates;
if (options.updatesAsOverlay)
workspaceOptions |= LiveNodeEngine::UpdatesAsOverlay;
+ if (options.allowCreateMissing)
+ workspaceOptions |= LiveNodeEngine::AllowCreateMissing;
RemoteReceiver::ConnectionOptions connectionOptions;
if (options.updateOnConnect)