Falkon Develop
Cross-platform Qt-based web browser
qmlfileutils.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "qmlfileutils.h"
19#include "datapaths.h"
20#include "qztools.h"
21#include <QFile>
22#include <QDebug>
23#include <QQmlEngine>
24
25QmlFileUtils::QmlFileUtils(const QString &filePath, QObject *parent)
26 : QObject(parent)
27{
28 m_path = filePath;
29}
30
31QString QmlFileUtils::resolve(const QString &filePath)
32{
33 QString resolvedPath = m_path + QL1C('/') + filePath;
34 resolvedPath = QDir::cleanPath(resolvedPath);
35 if (resolvedPath.contains(m_path)) {
36 return resolvedPath;
37 }
38 return {};
39}
40
41QByteArray QmlFileUtils::readAllFileContents(const QString &fileName)
42{
43 const QString path = resolve(fileName);
45}
46
47bool QmlFileUtils::exists(const QString &filePath)
48{
49 const QString path = resolve(filePath);
50 return QFile(path).exists();
51}
QmlFileUtils(const QString &filePath, QObject *parent=nullptr)
Q_INVOKABLE QString resolve(const QString &filePath)
Get the path of the file within the plugin directory. If the filePath provided is resolved to be outs...
Q_INVOKABLE QByteArray readAllFileContents(const QString &fileName)
Read the contents of the file within the plugin directory.
Q_INVOKABLE bool exists(const QString &filePath)
Checks if the file exists within the plugin directory.
static QByteArray readAllFileByteContents(const QString &filename)
Definition: qztools.cpp:103
#define QL1C(x)
Definition: qzcommon.h:48