File indexing completed on 2024-12-22 04:41:13

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #pragma once
0019 
0020 #include <QObject>
0021 
0022 /**
0023  * @brief The QmlFileUtils class, exposed to QML as FileUtils
0024  */
0025 class QmlFileUtils : public QObject
0026 {
0027     Q_OBJECT
0028 public:
0029     explicit QmlFileUtils(const QString &filePath, QObject *parent = nullptr);
0030     /**
0031      * @brief Get the path of the file within the plugin directory.
0032      *        If the filePath provided is resolved to be outside the plugin
0033      *        directory then empty string is returned
0034      * @param file path within the plugin directory
0035      * @return resolved path
0036      */
0037     Q_INVOKABLE QString resolve(const QString &filePath);
0038     /**
0039      * @brief Read the contents of the file within the plugin directory
0040      * @param file path within the plugin directory
0041      * @return contents of the file
0042      */
0043     Q_INVOKABLE QByteArray readAllFileContents(const QString &fileName);
0044     /**
0045      * @brief Checks if the file exists within the plugin directory
0046      * @param file path within the plugin directory
0047      * @return true if file exists, otherwise false
0048      */
0049     Q_INVOKABLE bool exists(const QString &filePath);
0050 private:
0051     QString m_path;
0052 };