File indexing completed on 2024-12-22 04:41:14
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 #include "mainapplication.h" 0022 #include "qmltab.h" 0023 0024 /** 0025 * @brief The class exposing Tabs API to QML 0026 */ 0027 class QmlTabs : public QObject 0028 { 0029 Q_OBJECT 0030 public: 0031 explicit QmlTabs(QObject *parent = nullptr); 0032 /** 0033 * @brief Sets the current tab in a window 0034 * @param A JavaScript object containing 0035 * - index: 0036 * Integer representing new current index 0037 * - windowId: 0038 * The id of window containing the tab 0039 * @return True if success, else false 0040 */ 0041 Q_INVOKABLE bool setCurrentIndex(const QVariantMap &map); 0042 /** 0043 * @brief Sets the next tab as current tab 0044 * @param Integer representing the window 0045 * @return True if success, else false 0046 */ 0047 Q_INVOKABLE bool nextTab(int windowId = -1); 0048 /** 0049 * @brief Sets the previous tab as current tab 0050 * @param Integer representing the window 0051 * @return True if success, else false 0052 */ 0053 Q_INVOKABLE bool previousTab(int windowId = -1); 0054 /** 0055 * @brief Moves a tab 0056 * @param A JavaScript object containing 0057 * - from: 0058 * The initial index of the tab 0059 * - to: 0060 * The final index of the tab 0061 * - windowId: 0062 * The id of window containing the tab 0063 * @return True if tab is moved, else false 0064 */ 0065 Q_INVOKABLE bool moveTab(const QVariantMap &map); 0066 /** 0067 * @brief Pins a tab 0068 * @param A JavaScript object containing 0069 * - index: 0070 * Integer representing the tab to be pinned 0071 * - windowId: 0072 * The id of window containing the tab 0073 * @return True if success, else false 0074 */ 0075 Q_INVOKABLE bool pinTab(const QVariantMap &map); 0076 /** 0077 * @brief Un-pins a tab 0078 * @param A JavaScript object containing 0079 * - index: 0080 * Integer representing the tab to be unpinned 0081 * - windowId: 0082 * The id of window containing the tab 0083 * @return True if success, else false 0084 */ 0085 Q_INVOKABLE bool unpinTab(const QVariantMap &map); 0086 /** 0087 * @brief Detaches a tab 0088 * @param A JavaScript object containing 0089 * - index: 0090 * Integer representing the tab to be detached 0091 * - windowId: 0092 * The id of window containing the tab 0093 * @return True if tab is detached, else false 0094 */ 0095 Q_INVOKABLE bool detachTab(const QVariantMap &map); 0096 /** 0097 * @brief Duplicates a tab 0098 * @param A JavaScript object containing 0099 * - index: 0100 * Integer representing the tab to duplicate 0101 * - windowId: 0102 * The id of window containing the tab 0103 * @return True if success, else false 0104 */ 0105 Q_INVOKABLE bool duplicate(const QVariantMap &map); 0106 /** 0107 * @brief Close a tab 0108 * @param A JavaScript object containing 0109 * - index: 0110 * Integer representing the tab to be closed 0111 * - windowId: 0112 * The id of window containing the tab 0113 * @return True if success, else false 0114 */ 0115 Q_INVOKABLE bool closeTab(const QVariantMap &map); 0116 /** 0117 * @brief Reloads a tab 0118 * @param A JavaScript object containing 0119 * - index: 0120 * Integer representing the tab to be reloaded 0121 * - windowId: 0122 * The id of window containing the tab 0123 * @return True if success, else false 0124 */ 0125 Q_INVOKABLE bool reloadTab(const QVariantMap &map); 0126 /** 0127 * @brief Stops a tab 0128 * @param A JavaScript object containing 0129 * - index: 0130 * Integer representing the tab to be stopped 0131 * - windowId: 0132 * The id of window containing the tab 0133 * @return True if success, else false 0134 */ 0135 Q_INVOKABLE bool stopTab(const QVariantMap &map); 0136 /** 0137 * @brief Gets a tab 0138 * @param A JavaScript object containing 0139 * - index: 0140 * Integer representing the index of the tab 0141 * - windowId: 0142 * The id of window containing the tab 0143 * @return Tab of type [QmlTab](@ref QmlTab) if exists, else null 0144 */ 0145 Q_INVOKABLE QmlTab *get(const QVariantMap &map) const; 0146 /** 0147 * @brief Get the normal tabs count in a window 0148 * @param Integer representing the window 0149 * @return Number of normal tabs in the window 0150 */ 0151 Q_INVOKABLE int normalTabsCount(int windowId = -1) const; 0152 /** 0153 * @brief Get the pinned tabs count in a window 0154 * @param Integer representing the window 0155 * @return Number of pinned tabs in the window 0156 */ 0157 Q_INVOKABLE int pinnedTabsCount(int windowId = -1) const; 0158 /** 0159 * @brief Gets all the tabs of a window 0160 * @param A JavaScript object containing 0161 * - windowId: 0162 * The id of window containing the tab 0163 * - withPinned: 0164 * Bool representing if the searched tab can be pinned 0165 * @return List of tabs, each of type [QmlTab](@ref QmlTab) 0166 */ 0167 Q_INVOKABLE QList<QObject*> getAll(const QVariantMap &map = QVariantMap()) const; 0168 /** 0169 * @brief Searches tabs against a criteria 0170 * @param A JavaScript object containing 0171 * - title: 0172 * String representing the title to be searched 0173 * - url: 0174 * String representing the url to be searched 0175 * - withPinned: 0176 * Bool representing if the searched tab can be pinned 0177 * @return List of tabs, each of type [QmlTab](@ref QmlTab), which are 0178 * matched against the criteria 0179 */ 0180 Q_INVOKABLE QList<QObject*> search(const QVariantMap &map); 0181 /** 0182 * @brief Adds a tab 0183 * @param A JavaScript object containing 0184 * - url: 0185 * String representing the url of the tab 0186 * - windowId: 0187 * The id of window containing the tab 0188 * @return True if the tab is added, else false 0189 */ 0190 Q_INVOKABLE bool addTab(const QVariantMap &map); 0191 Q_SIGNALS: 0192 /** 0193 * @brief The signal emitted when tabs in the tab widget are changed 0194 * @param window id representing the window in which the change occurs 0195 */ 0196 void changed(int windowId); 0197 0198 /** 0199 * @brief The signal emitted when a tab is inserted 0200 * @param A JavaScript object containing 0201 * - index: 0202 * The index of the inserted tab 0203 * - windowId: 0204 * The id of window in which the tab is inserted 0205 */ 0206 void tabInserted(const QVariantMap &map); 0207 0208 /** 0209 * @brief The signal emitted when a tab is removed 0210 * @param A JavaScript object containing 0211 * - index: 0212 * The index of the removed tab 0213 * - windowId: 0214 * The id of window in which the tab is removed 0215 */ 0216 void tabRemoved(const QVariantMap &map); 0217 0218 /** 0219 * @brief The signal emitted when a tab is moved 0220 * @param A JavaScript object containing 0221 * - from: 0222 * The initial index of the moved tab 0223 * - to: 0224 * The final index of the moved tab 0225 * - windowId: 0226 * The id of window in which the tab is moved 0227 */ 0228 void tabMoved(const QVariantMap &map); 0229 private: 0230 BrowserWindow *getWindow(const QVariantMap &map) const; 0231 BrowserWindow *getWindow(int windowId) const; 0232 void windowCreated(BrowserWindow *window); 0233 };