From bb079e0dff5557e811af63194a86a5d6548b4cfd Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Mon, 22 Jul 2013 20:35:11 +0300 Subject: [PATCH] First attempt at removing QtQuick 1.1 hardcoding from qml files. We replace QtQuick import with a macro which will get replaced during runtime with the correct version via a custom QFileSystemEngine subclass --- qml/CameraOverlay.qml | 2 +- qml/CameraSettings.qml | 2 +- qml/CameraToolBar.qml | 2 +- qml/CameraView.qml | 2 +- qml/CaptureButton.qml | 2 +- qml/CheckButton.qml | 2 +- qml/FlashButton.qml | 2 +- qml/FocusReticle.qml | 2 +- qml/ImageColorFilterButton.qml | 2 +- qml/ImageEvCompButton.qml | 2 +- qml/ImageIsoButton.qml | 2 +- qml/ImageOverlay.qml | 2 +- qml/ImageResolutionSettings.qml | 2 +- qml/ImageSceneButton.qml | 2 +- qml/ImageSettings.qml | 2 +- qml/ImageWhiteBalanceButton.qml | 2 +- qml/Indicator.qml | 2 +- qml/ModeButton.qml | 2 +- qml/ModeController.qml | 2 +- qml/PipelineManager.qml | 2 +- qml/PostCaptureItem.qml | 2 +- qml/PostCaptureView.qml | 2 +- qml/PreviewImage.qml | 2 +- qml/RecordingDurationLabel.qml | 2 +- qml/SectionHeader.qml | 2 +- qml/SettingsView.qml | 2 +- qml/Standby.qml | 2 +- qml/TextSwitch.qml | 2 +- qml/VideoColorFilterButton.qml | 2 +- qml/VideoEvCompButton.qml | 2 +- qml/VideoMuteButton.qml | 2 +- qml/VideoOverlay.qml | 2 +- qml/VideoPlayerPage.qml | 2 +- qml/VideoResolutionSettings.qml | 2 +- qml/VideoSceneButton.qml | 2 +- qml/VideoSettings.qml | 2 +- qml/VideoTorchButton.qml | 2 +- qml/VideoWhiteBalanceButton.qml | 2 +- qml/ZoomCaptureButton.qml | 2 +- qml/ZoomCaptureCancel.qml | 2 +- qml/ZoomSlider.qml | 2 +- qml/main.qml | 2 +- src/main.cpp | 17 +++ src/qmlfileengine.cpp | 225 ++++++++++++++++++++++++++++++++ src/qmlfileengine.h | 73 +++++++++++ src/src.pro | 4 +- 46 files changed, 359 insertions(+), 44 deletions(-) create mode 100644 src/qmlfileengine.cpp create mode 100644 src/qmlfileengine.h diff --git a/qml/CameraOverlay.qml b/qml/CameraOverlay.qml index 88b0849..9f10d41 100644 --- a/qml/CameraOverlay.qml +++ b/qml/CameraOverlay.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import CameraPlus 1.0 diff --git a/qml/CameraSettings.qml b/qml/CameraSettings.qml index e2bf74d..9a67ba1 100644 --- a/qml/CameraSettings.qml +++ b/qml/CameraSettings.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 Column { diff --git a/qml/CameraToolBar.qml b/qml/CameraToolBar.qml index b5f61b9..c0e5366 100644 --- a/qml/CameraToolBar.qml +++ b/qml/CameraToolBar.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import "CameraToolBar.js" as Layout diff --git a/qml/CameraView.qml b/qml/CameraView.qml index 8ce012e..d68c4e2 100644 --- a/qml/CameraView.qml +++ b/qml/CameraView.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import QtCamera 1.0 import CameraPlus 1.0 diff --git a/qml/CaptureButton.qml b/qml/CaptureButton.qml index 38e1f0e..6dc99a3 100644 --- a/qml/CaptureButton.qml +++ b/qml/CaptureButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 Item { diff --git a/qml/CheckButton.qml b/qml/CheckButton.qml index 573a301..8aa8eb0 100644 --- a/qml/CheckButton.qml +++ b/qml/CheckButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 ToolIcon { diff --git a/qml/FlashButton.qml b/qml/FlashButton.qml index 2f5497b..bf6cc51 100644 --- a/qml/FlashButton.qml +++ b/qml/FlashButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import "data.js" as Data diff --git a/qml/FocusReticle.qml b/qml/FocusReticle.qml index 82d267b..c086ec7 100644 --- a/qml/FocusReticle.qml +++ b/qml/FocusReticle.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import QtCamera 1.0 import CameraPlus 1.0 diff --git a/qml/ImageColorFilterButton.qml b/qml/ImageColorFilterButton.qml index 75680dd..c28a54e 100644 --- a/qml/ImageColorFilterButton.qml +++ b/qml/ImageColorFilterButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import "data.js" as Data diff --git a/qml/ImageEvCompButton.qml b/qml/ImageEvCompButton.qml index 1abcb82..0a12cf7 100644 --- a/qml/ImageEvCompButton.qml +++ b/qml/ImageEvCompButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 diff --git a/qml/ImageIsoButton.qml b/qml/ImageIsoButton.qml index b916be0..7cccff7 100644 --- a/qml/ImageIsoButton.qml +++ b/qml/ImageIsoButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import "data.js" as Data diff --git a/qml/ImageOverlay.qml b/qml/ImageOverlay.qml index 842768d..9875ab4 100644 --- a/qml/ImageOverlay.qml +++ b/qml/ImageOverlay.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import CameraPlus 1.0 diff --git a/qml/ImageResolutionSettings.qml b/qml/ImageResolutionSettings.qml index bfd1309..3c78458 100644 --- a/qml/ImageResolutionSettings.qml +++ b/qml/ImageResolutionSettings.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 Column { diff --git a/qml/ImageSceneButton.qml b/qml/ImageSceneButton.qml index 5cae56c..226be62 100644 --- a/qml/ImageSceneButton.qml +++ b/qml/ImageSceneButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import "data.js" as Data diff --git a/qml/ImageSettings.qml b/qml/ImageSettings.qml index bfd862a..220f226 100644 --- a/qml/ImageSettings.qml +++ b/qml/ImageSettings.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 diff --git a/qml/ImageWhiteBalanceButton.qml b/qml/ImageWhiteBalanceButton.qml index 6d60392..55290e9 100644 --- a/qml/ImageWhiteBalanceButton.qml +++ b/qml/ImageWhiteBalanceButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import "data.js" as Data diff --git a/qml/Indicator.qml b/qml/Indicator.qml index 873ac22..da59619 100644 --- a/qml/Indicator.qml +++ b/qml/Indicator.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ Image { anchors.left: parent.left diff --git a/qml/ModeButton.qml b/qml/ModeButton.qml index 31a19cf..0063e7e 100644 --- a/qml/ModeButton.qml +++ b/qml/ModeButton.qml @@ -21,7 +21,7 @@ */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import QtCamera 1.0 CaptureButton { diff --git a/qml/ModeController.qml b/qml/ModeController.qml index a986dd7..b9c8b8a 100644 --- a/qml/ModeController.qml +++ b/qml/ModeController.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 diff --git a/qml/PipelineManager.qml b/qml/PipelineManager.qml index d328711..04294ba 100644 --- a/qml/PipelineManager.qml +++ b/qml/PipelineManager.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import QtCamera 1.0 import CameraPlus 1.0 diff --git a/qml/PostCaptureItem.qml b/qml/PostCaptureItem.qml index 5e5b79e..f9c4a85 100644 --- a/qml/PostCaptureItem.qml +++ b/qml/PostCaptureItem.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import CameraPlus 1.0 diff --git a/qml/PostCaptureView.qml b/qml/PostCaptureView.qml index 7130f5b..a1c0e06 100644 --- a/qml/PostCaptureView.qml +++ b/qml/PostCaptureView.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import CameraPlus 1.0 import com.nokia.meego 1.1 import QtCamera 1.0 diff --git a/qml/PreviewImage.qml b/qml/PreviewImage.qml index e70509e..52a32f3 100644 --- a/qml/PreviewImage.qml +++ b/qml/PreviewImage.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 diff --git a/qml/RecordingDurationLabel.qml b/qml/RecordingDurationLabel.qml index ffac09a..8ab644c 100644 --- a/qml/RecordingDurationLabel.qml +++ b/qml/RecordingDurationLabel.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 Rectangle { diff --git a/qml/SectionHeader.qml b/qml/SectionHeader.qml index ae39e4d..51f6ee3 100644 --- a/qml/SectionHeader.qml +++ b/qml/SectionHeader.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 Row { diff --git a/qml/SettingsView.qml b/qml/SettingsView.qml index 41b8773..40ac8fd 100644 --- a/qml/SettingsView.qml +++ b/qml/SettingsView.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import QtCamera 1.0 import CameraPlus 1.0 diff --git a/qml/Standby.qml b/qml/Standby.qml index ed5eb92..471a099 100644 --- a/qml/Standby.qml +++ b/qml/Standby.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.0 Rectangle { diff --git a/qml/TextSwitch.qml b/qml/TextSwitch.qml index 2744d17..74e042b 100644 --- a/qml/TextSwitch.qml +++ b/qml/TextSwitch.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 Item { diff --git a/qml/VideoColorFilterButton.qml b/qml/VideoColorFilterButton.qml index 886d2ab..cf864d6 100644 --- a/qml/VideoColorFilterButton.qml +++ b/qml/VideoColorFilterButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import "data.js" as Data diff --git a/qml/VideoEvCompButton.qml b/qml/VideoEvCompButton.qml index c46f24b..b012c17 100644 --- a/qml/VideoEvCompButton.qml +++ b/qml/VideoEvCompButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 diff --git a/qml/VideoMuteButton.qml b/qml/VideoMuteButton.qml index 7df6aa6..ada6812 100644 --- a/qml/VideoMuteButton.qml +++ b/qml/VideoMuteButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 ToolIcon { diff --git a/qml/VideoOverlay.qml b/qml/VideoOverlay.qml index 91f9e1a..735833d 100644 --- a/qml/VideoOverlay.qml +++ b/qml/VideoOverlay.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import CameraPlus 1.0 diff --git a/qml/VideoPlayerPage.qml b/qml/VideoPlayerPage.qml index 6820030..dbe7274 100644 --- a/qml/VideoPlayerPage.qml +++ b/qml/VideoPlayerPage.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import CameraPlus 1.0 import QtCamera 1.0 diff --git a/qml/VideoResolutionSettings.qml b/qml/VideoResolutionSettings.qml index e80be20..718ee7d 100644 --- a/qml/VideoResolutionSettings.qml +++ b/qml/VideoResolutionSettings.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 Column { diff --git a/qml/VideoSceneButton.qml b/qml/VideoSceneButton.qml index d87d483..96e6fd1 100644 --- a/qml/VideoSceneButton.qml +++ b/qml/VideoSceneButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import "data.js" as Data diff --git a/qml/VideoSettings.qml b/qml/VideoSettings.qml index c7a554a..e0f90fd 100644 --- a/qml/VideoSettings.qml +++ b/qml/VideoSettings.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 diff --git a/qml/VideoTorchButton.qml b/qml/VideoTorchButton.qml index 34f42d2..e813ac6 100644 --- a/qml/VideoTorchButton.qml +++ b/qml/VideoTorchButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 diff --git a/qml/VideoWhiteBalanceButton.qml b/qml/VideoWhiteBalanceButton.qml index 33ab5eb..353619b 100644 --- a/qml/VideoWhiteBalanceButton.qml +++ b/qml/VideoWhiteBalanceButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 import "data.js" as Data diff --git a/qml/ZoomCaptureButton.qml b/qml/ZoomCaptureButton.qml index 7b2763e..ed10da3 100644 --- a/qml/ZoomCaptureButton.qml +++ b/qml/ZoomCaptureButton.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import CameraPlus 1.0 diff --git a/qml/ZoomCaptureCancel.qml b/qml/ZoomCaptureCancel.qml index d89ee04..b85966a 100644 --- a/qml/ZoomCaptureCancel.qml +++ b/qml/ZoomCaptureCancel.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import CameraPlus 1.0 diff --git a/qml/ZoomSlider.qml b/qml/ZoomSlider.qml index dc5dbc8..13609f0 100644 --- a/qml/ZoomSlider.qml +++ b/qml/ZoomSlider.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import QtCamera 1.0 diff --git a/qml/main.qml b/qml/main.qml index e04dadc..6676ff6 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import QtQuick 1.1 +@IMPORT_QT_QUICK@ import com.nokia.meego 1.1 import com.nokia.extras 1.1 import QtCamera 1.0 diff --git a/src/main.cpp b/src/main.cpp index 9f83baa..7f9758b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,10 +52,27 @@ #include "qt_private/qdeclarativedebughelper_p.h" #endif /* QMLJSDEBUGGER */ +#include +#include "qmlfileengine.h" + +class QmlFileEngineHandler : public QAbstractFileEngineHandler { + QAbstractFileEngine *create(const QString& fileName) const { + QString fn = fileName.toLower(); + if (fn.startsWith(':') && fn.endsWith(".qml")) { + return new QmlFileEngine(fileName); + } + + return 0; + } +}; + Q_DECL_EXPORT int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_X11InitThreads, true); QApplication app(argc, argv); + QmlFileEngineHandler handler; + Q_UNUSED(handler); + #ifdef QMLJSDEBUGGER QDeclarativeDebugHelper::enableDebugging(); #endif /* QMLJSDEBUGGER */ diff --git a/src/qmlfileengine.cpp b/src/qmlfileengine.cpp new file mode 100644 index 0000000..e9262b7 --- /dev/null +++ b/src/qmlfileengine.cpp @@ -0,0 +1,225 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "qmlfileengine.h" +#include +#include + +// TODO: support mmap extension + +QmlFileEngine::QmlFileEngine(const QString& fileName) : + QFSFileEngine(fileName), + m_res(new QResource(fileName)), + m_off(0) { + +} + +void QmlFileEngine::setFileName(const QString& file) { + m_res->setFileName(file); +} + +bool QmlFileEngine::open(QIODevice::OpenMode flags) { + if (!m_res->isValid() || m_res->fileName().isEmpty()) { + return false; + } + + if (flags & QIODevice::WriteOnly) { + return false; + } + + m_off = 0; + + if (m_res->isCompressed()) { + m_data = qUncompress(m_res->data(), m_res->size()); + } + else { + m_data = QByteArray::fromRawData((const char *)m_res->data(), m_res->size()); + } + + m_data.replace("@IMPORT_QT_QUICK@", "import QtQuick 1.1"); + + return true; +} + +bool QmlFileEngine::close() { + m_data.clear(); + m_off = 0; + + return true; +} + +bool QmlFileEngine::flush() { + return true; +} + +qint64 QmlFileEngine::size() const { + return m_data.size(); +} + +qint64 QmlFileEngine::pos() const { + return m_off; +} + +bool QmlFileEngine::atEnd() const { + return m_off == m_data.size(); +} + +bool QmlFileEngine::seek(qint64 pos) { + if (pos > m_data.size()) { + return false; + } + + return true; +} + +qint64 QmlFileEngine::read(char *data, qint64 len) { + if (len > m_data.size() - m_off) { + len = m_data.size() - m_off; + } + + if (len <= 0) { + return 0; + } + + memcpy(data, m_data.data() + m_off, len); + + m_off += len; + + return len; +} + +qint64 QmlFileEngine::write(const char *data, qint64 len) { + Q_UNUSED(data); + Q_UNUSED(len); + + return false; +} + +bool QmlFileEngine::remove() { + return false; +} + +bool QmlFileEngine::copy(const QString& newName) { + Q_UNUSED(newName); + + return false; +} + +bool QmlFileEngine::rename(const QString& newName) { + Q_UNUSED(newName); + + return false; +} + +bool QmlFileEngine::link(const QString& newName) { + Q_UNUSED(newName); + + return false; +} + +bool QmlFileEngine::isSequential() const { + return false; +} + +bool QmlFileEngine::isRelativePath() const { + return false; +} + +bool QmlFileEngine::mkdir(const QString& dirName, bool createParentDirectories) const { + Q_UNUSED(dirName); + Q_UNUSED(createParentDirectories); + + return false; +} + +bool QmlFileEngine::rmdir(const QString& dirName, bool recurseParentDirectories) const { + Q_UNUSED(dirName); + Q_UNUSED(recurseParentDirectories); + + return false; +} + +bool QmlFileEngine::setSize(qint64 size) { + Q_UNUSED(size); + + return false; +} + +QStringList QmlFileEngine::entryList(QDir::Filters filters, const QStringList& filterNames) const { + Q_UNUSED(filters); + Q_UNUSED(filterNames); + + return QStringList(); +} + +bool QmlFileEngine::caseSensitive() const { + return true; +} + +QFSFileEngine::FileFlags QmlFileEngine::fileFlags(FileFlags type) const { + QFSFileEngine::FileFlags flags = 0; + + if (!m_res->isValid()) { + return flags; + } + + if (type & TypesMask) { + flags |= FileType; + } + + if (type & FlagsMask) { + flags |= ExistsFlag; + } + + return flags; +} + +bool QmlFileEngine::setPermissions(uint perms) { + Q_UNUSED(perms); + + return false; +} + +QString QmlFileEngine::fileName(QAbstractFileEngine::FileName file) const { + Q_UNUSED(file); + + // TODO: + return QString(); +} + +uint QmlFileEngine::ownerId(FileOwner owner) const { + Q_UNUSED(owner); + + return -2; +} + +QString QmlFileEngine::owner(FileOwner owner) const { + Q_UNUSED(owner); + + return QString(); +} + +QDateTime QmlFileEngine::fileTime(FileTime time) const { + Q_UNUSED(time); + + return QDateTime(); +} diff --git a/src/qmlfileengine.h b/src/qmlfileengine.h new file mode 100644 index 0000000..fc7e463 --- /dev/null +++ b/src/qmlfileengine.h @@ -0,0 +1,73 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef QML_FILE_ENGINE_H +#define QML_FILE_ENGINE_H + +#include + +class QResource; + +class QmlFileEngine : public QFSFileEngine { +public: + QmlFileEngine(const QString& fileName); + + virtual void setFileName(const QString& file); + virtual bool open(QIODevice::OpenMode flags); + virtual bool close(); + virtual bool flush(); + virtual qint64 size() const; + virtual qint64 pos() const; + virtual bool atEnd() const; + virtual bool seek(qint64 pos); + virtual qint64 read(char *data, qint64 len); + virtual qint64 write(const char *data, qint64 len); + virtual bool remove(); + virtual bool copy(const QString& newName); + virtual bool rename(const QString& newName); + virtual bool link(const QString& newName); + virtual bool isSequential() const; + virtual bool isRelativePath() const; + virtual bool mkdir(const QString& dirName, bool createParentDirectories) const; + virtual bool rmdir(const QString& dirName, bool recurseParentDirectories) const; + virtual bool setSize(qint64 size); + virtual QStringList entryList(QDir::Filters filters, const QStringList& filterNames) const; + virtual bool caseSensitive() const; + virtual FileFlags fileFlags(FileFlags type) const; + virtual bool setPermissions(uint perms); + virtual QString fileName(QAbstractFileEngine::FileName file) const; + virtual uint ownerId(FileOwner owner) const; + virtual QString owner(FileOwner owner) const; + virtual QDateTime fileTime(FileTime time) const; + // TODO: + // virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames); + // virtual Iterator *endEntryList(); + // bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0); + // bool supportsExtension(Extension extension) const; + +private: + QResource *m_res; + QByteArray m_data; + qint64 m_off; +}; + +#endif /* QML_FILE_ENGINE_H */ diff --git a/src/src.pro b/src/src.pro index ababc84..036e8d8 100644 --- a/src/src.pro +++ b/src/src.pro @@ -15,13 +15,13 @@ SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp displaystate.cpp f cameraresources.cpp compass.cpp orientation.cpp geocode.cpp mountprotector.cpp \ trackerstore.cpp focusrectangle.cpp sharehelper.cpp deletehelper.cpp galleryhelper.cpp \ postcapturemodel.cpp batteryinfo.cpp gridlines.cpp deviceinfo.cpp devicekeys.cpp \ - platformsettings.cpp dbusservice.cpp + platformsettings.cpp dbusservice.cpp qmlfileengine.cpp HEADERS += settings.h filenaming.h quillitem.h displaystate.h fsmonitor.h \ cameraresources.h compass.h orientation.h geocode.h mountprotector.h \ trackerstore.h focusrectangle.h sharehelper.h deletehelper.h galleryhelper.h \ postcapturemodel.h batteryinfo.h gridlines.h deviceinfo.h devicekeys.h \ - platformsettings.h dbusservice.h + platformsettings.h dbusservice.h qmlfileengine.h RESOURCES += ../qml/qml.qrc -- 2.25.1