aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrigorii Zimin <gzimin@luxoft.com>2020-08-04 17:42:36 +0300
committerGrigorii Zimin <gzimin@luxoft.com>2020-08-05 15:47:44 +0000
commitbdb753ea00083e8a1d9f77ca1daf3b08be13c551 (patch)
treec5671275b1e496b0eab973f6fd5033f0995d039d
parentbcb4307121c01c820bd41f8c97b64556d446d55d (diff)
[plugins] add initial implementation of the FileUtils
1) Only one function is added for now Fixes: AUTOSUITE-1599 Change-Id: I3558e42c3aa37df927de85ee2f3c3eae80d9aa2a Reviewed-by: Egor Nemtsev <enemtsev@luxoft.com>
-rw-r--r--apps/com.luxoft.vehicle/helpers/pathsProvider.js11
-rw-r--r--plugins/fileutils/fileUtils.cpp45
-rw-r--r--plugins/fileutils/fileUtils.h43
-rw-r--r--plugins/fileutils/fileUtilsPlugin.cpp55
-rw-r--r--plugins/fileutils/fileutils.pro14
-rw-r--r--plugins/fileutils/qmldir2
-rw-r--r--plugins/plugins.pro1
7 files changed, 162 insertions, 9 deletions
diff --git a/apps/com.luxoft.vehicle/helpers/pathsProvider.js b/apps/com.luxoft.vehicle/helpers/pathsProvider.js
index 36d7aa4c..4964dd16 100644
--- a/apps/com.luxoft.vehicle/helpers/pathsProvider.js
+++ b/apps/com.luxoft.vehicle/helpers/pathsProvider.js
@@ -31,14 +31,7 @@
****************************************************************************/
.pragma library
-
-function doesFileExist(url) {
- var req = new XMLHttpRequest();
- req.open('HEAD', url, false);
- req.send();
- return req.status == 200;
-}
-
+.import shared.FileUtils 1.0 as FU
// see vehicle app info.yaml for description
function getModelPath(name, version) {
@@ -51,7 +44,7 @@ function getModelPath(name, version) {
if (version === "mixedFormats") {
var pathObj = Qt.resolvedUrl("../assets/models/" + version + "/" + name + ".obj")
var pathStl = Qt.resolvedUrl("../assets/models/" + version + "/" + name + ".stl")
- return doesFileExist(pathObj) ? pathObj : pathStl
+ return FU.FileUtils.existsFileFromUrl(pathObj) ? pathObj : pathStl
}
}
diff --git a/plugins/fileutils/fileUtils.cpp b/plugins/fileutils/fileUtils.cpp
new file mode 100644
index 00000000..204946a7
--- /dev/null
+++ b/plugins/fileutils/fileUtils.cpp
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 Luxoft Sweden AB
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Neptune IVI UI.
+**
+** $QT_BEGIN_LICENSE:GPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+****************************************************************************/
+
+#include "fileUtils.h"
+
+#include <QUrl>
+#include <QFile>
+
+FileUtils::FileUtils(QObject *parent) : QObject(parent)
+{
+}
+
+bool FileUtils::existsFileFromUrl(const QString &fileUrl)
+{
+ QUrl url(fileUrl);
+ return QFile::exists(url.path());
+}
diff --git a/plugins/fileutils/fileUtils.h b/plugins/fileutils/fileUtils.h
new file mode 100644
index 00000000..0134abe8
--- /dev/null
+++ b/plugins/fileutils/fileUtils.h
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 Luxoft Sweden AB
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Neptune 3 IVI UI.
+**
+** $QT_BEGIN_LICENSE:GPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+****************************************************************************/
+
+#pragma once
+#include <QObject>
+
+class FileUtils : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit FileUtils(QObject *parent = nullptr);
+
+ Q_INVOKABLE bool existsFileFromUrl(const QString &fileUrl);
+};
diff --git a/plugins/fileutils/fileUtilsPlugin.cpp b/plugins/fileutils/fileUtilsPlugin.cpp
new file mode 100644
index 00000000..810763ee
--- /dev/null
+++ b/plugins/fileutils/fileUtilsPlugin.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 Luxoft Sweden AB
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Neptune 3 UI.
+**
+** $QT_BEGIN_LICENSE:GPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+****************************************************************************/
+#include <QQmlExtensionPlugin>
+#include <QQmlEngine>
+
+#include "fileUtils.h"
+
+class FileUtilsPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
+
+public:
+ void registerTypes(const char *uri) override
+ {
+ Q_ASSERT(uri == QLatin1String("shared.FileUtils"));
+ qmlRegisterSingletonType<FileUtils>(uri, 1, 0, "FileUtils",
+ [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject *{
+ Q_UNUSED(engine)
+ Q_UNUSED(scriptEngine)
+ auto fileUtils = new FileUtils;
+ return fileUtils;
+ });
+ }
+};
+
+#include "fileUtilsPlugin.moc"
diff --git a/plugins/fileutils/fileutils.pro b/plugins/fileutils/fileutils.pro
new file mode 100644
index 00000000..6ffebf26
--- /dev/null
+++ b/plugins/fileutils/fileutils.pro
@@ -0,0 +1,14 @@
+TEMPLATE = lib
+TARGET = fileutilsplugin
+QT += core qml
+CONFIG += qt plugin c++11
+
+SOURCES += \
+ fileUtils.cpp \
+ fileUtilsPlugin.cpp \
+
+HEADERS += \
+ fileUtils.h \
+
+uri = FileUtils
+load(qmlplugin)
diff --git a/plugins/fileutils/qmldir b/plugins/fileutils/qmldir
new file mode 100644
index 00000000..ecf1e579
--- /dev/null
+++ b/plugins/fileutils/qmldir
@@ -0,0 +1,2 @@
+module shared.FileUtils
+plugin fileutilsplugin
diff --git a/plugins/plugins.pro b/plugins/plugins.pro
index 7a8a126b..e3bb5b32 100644
--- a/plugins/plugins.pro
+++ b/plugins/plugins.pro
@@ -9,6 +9,7 @@ SUBDIRS = \
systeminfo \
eventslisteners \
com.pelagicore.map \
+ fileutils \
!isEmpty(SQUISH_PREFIX) {
SUBDIRS += squishhook