File indexing completed on 2024-05-19 04:59:16

0001 /* ============================================================
0002 * GreaseMonkey plugin for Falkon
0003 * Copyright (C) 2013-2018 David Rosca <nowrep@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 #ifndef GM_MANAGER_H
0019 #define GM_MANAGER_H
0020 
0021 #include <QObject>
0022 #include <QStringList>
0023 #include <QPointer>
0024 #include <QHash>
0025 
0026 class QUrl;
0027 class QWebFrame;
0028 
0029 class BrowserWindow;
0030 class GM_Script;
0031 class GM_JSObject;
0032 class GM_Settings;
0033 class GM_Icon;
0034 
0035 class GM_Manager : public QObject
0036 {
0037     Q_OBJECT
0038 public:
0039     explicit GM_Manager(const QString &sPath, QObject* parent = nullptr);
0040     ~GM_Manager();
0041 
0042     void showSettings(QWidget* parent);
0043     void downloadScript(const QUrl &url);
0044 
0045     QString settingsPath() const;
0046     QString scriptsDirectory() const;
0047     QString requireScripts(const QStringList &urlList) const;
0048     QString bootstrapScript() const;
0049     QString valuesScript() const;
0050 
0051     void unloadPlugin();
0052 
0053     QList<GM_Script*> allScripts() const;
0054     bool containsScript(const QString &fullName) const;
0055 
0056     void enableScript(GM_Script* script);
0057     void disableScript(GM_Script* script);
0058 
0059     bool addScript(GM_Script* script);
0060     bool removeScript(GM_Script* script, bool removeFile = true);
0061 
0062     void showNotification(const QString &message, const QString &title = QString());
0063 
0064     static bool canRunOnScheme(const QString &scheme);
0065 
0066 Q_SIGNALS:
0067     void scriptsChanged();
0068 
0069 public Q_SLOTS:
0070     void mainWindowCreated(BrowserWindow* window);
0071     void mainWindowDeleted(BrowserWindow* window);
0072 
0073 private Q_SLOTS:
0074     void load();
0075     void scriptChanged();
0076 
0077 private:
0078     QString m_settingsPath;
0079     QString m_bootstrapScript;
0080     QString m_valuesScript;
0081     QPointer<GM_Settings> m_settings;
0082 
0083     QStringList m_disabledScripts;
0084     GM_JSObject *m_jsObject;
0085     QList<GM_Script*> m_scripts;
0086 
0087     QHash<BrowserWindow*, GM_Icon*> m_windows;
0088 };
0089 
0090 #endif // GM_MANAGER_H