4 * This file is part of CameraPlus.
6 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "qmlfileengine.h"
27 // TODO: support mmap extension
29 QmlFileEngine::QmlFileEngine(const QString& fileName) :
30 QFSFileEngine(fileName),
31 m_res(new QResource(fileName)),
36 void QmlFileEngine::setFileName(const QString& file) {
37 m_res->setFileName(file);
40 bool QmlFileEngine::open(QIODevice::OpenMode flags) {
41 if (!m_res->isValid() || m_res->fileName().isEmpty()) {
45 if (flags & QIODevice::WriteOnly) {
51 if (m_res->isCompressed()) {
52 m_data = qUncompress(m_res->data(), m_res->size());
55 m_data = QByteArray::fromRawData((const char *)m_res->data(), m_res->size());
58 m_data.replace("import QtQuick 2.0", "import QtQuick 1.1");
63 bool QmlFileEngine::close() {
70 bool QmlFileEngine::flush() {
74 qint64 QmlFileEngine::size() const {
78 qint64 QmlFileEngine::pos() const {
82 bool QmlFileEngine::atEnd() const {
83 return m_off == m_data.size();
86 bool QmlFileEngine::seek(qint64 pos) {
87 if (pos > m_data.size()) {
94 qint64 QmlFileEngine::read(char *data, qint64 len) {
95 if (len > m_data.size() - m_off) {
96 len = m_data.size() - m_off;
103 memcpy(data, m_data.data() + m_off, len);
110 qint64 QmlFileEngine::write(const char *data, qint64 len) {
117 bool QmlFileEngine::remove() {
121 bool QmlFileEngine::copy(const QString& newName) {
127 bool QmlFileEngine::rename(const QString& newName) {
133 bool QmlFileEngine::link(const QString& newName) {
139 bool QmlFileEngine::isSequential() const {
143 bool QmlFileEngine::isRelativePath() const {
147 bool QmlFileEngine::mkdir(const QString& dirName, bool createParentDirectories) const {
149 Q_UNUSED(createParentDirectories);
154 bool QmlFileEngine::rmdir(const QString& dirName, bool recurseParentDirectories) const {
156 Q_UNUSED(recurseParentDirectories);
161 bool QmlFileEngine::setSize(qint64 size) {
167 QStringList QmlFileEngine::entryList(QDir::Filters filters, const QStringList& filterNames) const {
169 Q_UNUSED(filterNames);
171 return QStringList();
174 bool QmlFileEngine::caseSensitive() const {
178 QFSFileEngine::FileFlags QmlFileEngine::fileFlags(FileFlags type) const {
179 QFSFileEngine::FileFlags flags = 0;
181 if (!m_res->isValid()) {
185 if (type & TypesMask) {
189 if (type & FlagsMask) {
196 bool QmlFileEngine::setPermissions(uint perms) {
202 QString QmlFileEngine::fileName(QAbstractFileEngine::FileName file) const {
204 case QAbstractFileEngine::AbsoluteName:
205 return m_res->fileName();
214 uint QmlFileEngine::ownerId(FileOwner owner) const {
220 QString QmlFileEngine::owner(FileOwner owner) const {
226 QDateTime QmlFileEngine::fileTime(FileTime time) const {