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

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 "qmluserscript.h"
0021 #include <QObject>
0022 
0023 /**
0024  * @brief The class exposing QWebEngineScriptCollection to QML
0025  */
0026 class FALKON_EXPORT QmlUserScripts : public QObject
0027 {
0028     Q_OBJECT
0029     /**
0030      * @brief Number of elements in the collection
0031      */
0032     Q_PROPERTY(int count READ count CONSTANT)
0033     /**
0034      * @brief Size of the collection
0035      */
0036     Q_PROPERTY(int size READ size CONSTANT)
0037     /**
0038      * @brief Checks if the collection is empty
0039      */
0040     Q_PROPERTY(bool empty READ empty CONSTANT)
0041 public:
0042     explicit QmlUserScripts(QObject *parent = nullptr);
0043     /**
0044      * @brief Checks if the script is in collection
0045      * @param object of type QmlUserScript
0046      * @return true if the script is in collection, else false
0047      */
0048     Q_INVOKABLE bool contains(QObject *object) const;
0049     /**
0050      * @brief Finds a script in collection by name
0051      * @param name of the script
0052      * @return object of type QmlUserScript, representing the script of given name
0053      */
0054     Q_INVOKABLE QObject *findScript(const QString &name) const;
0055     /**
0056      * @brief Finds all scripts in collection by a given name
0057      * @return list of objects, each of type QmlUserScript, representing the script of given name
0058      */
0059     Q_INVOKABLE QList<QObject*> findScripts(const QString &name) const;
0060     /**
0061      * @brief Removes a script from collection
0062      * @param object of type QmlUserScript
0063      */
0064     Q_INVOKABLE void remove(QObject *object) const;
0065     /**
0066      * @brief Gets all the scripts of the collection
0067      * @return list of objects, each of type QmlUserScript
0068      */
0069     Q_INVOKABLE QList<QObject*> toList() const;
0070 
0071     void insert(QObject *object);
0072 private:
0073     int count() const;
0074     int size() const;
0075     bool empty() const;
0076 
0077     QList<QObject*> toQObjectList(const QList<QWebEngineScript> &list) const;
0078 };