27 const QList<BrowserWindow*> windows =
mApp->windows();
29 windowCreated(window);
37 if (!map.contains(
QSL(
"index"))) {
38 qWarning() <<
"Unable to set current index:" <<
"index not defined";
42 const int index = map.value(
QSL(
"index")).toInt();
44 const auto window = getWindow(map);
48 window->tabWidget()->setCurrentIndex(index);
54 const auto window = getWindow(windowId);
58 window->tabWidget()->nextTab();
64 const auto window = getWindow(windowId);
68 window->tabWidget()->previousTab();
74 if (!map.contains(
QSL(
"from"))) {
75 qWarning() <<
"Unable to move tab:" <<
"from not defined";
78 if (!map.contains(
QSL(
"to"))) {
79 qWarning() <<
"Unable to move tab:" <<
"to not defined";
83 const int from = map.value(
QSL(
"from")).toInt();
84 const int to = map.value(
QSL(
"to")).toInt();
86 const auto window = getWindow(map);
90 window->tabWidget()->moveTab(from, to);
96 if (!map.contains(
QSL(
"index"))) {
97 qWarning() <<
"Unable to pin tab:" <<
"index not defined";
101 const int index = map.value(
QSL(
"index")).toInt();
103 const auto window = getWindow(map);
108 WebTab *webTab = window->tabWidget()->webTab(index);
120 if (!map.contains(
QSL(
"index"))) {
121 qWarning() <<
"Unable to unpin tab:" <<
"index not defined";
125 const int index = map.value(
QSL(
"index")).toInt();
127 const auto window = getWindow(map);
132 WebTab *webTab = window->tabWidget()->webTab(index);
144 if (!map.contains(
QSL(
"index"))) {
145 qWarning() <<
"Unable to detatch tab:" <<
"index not defined";
149 const int index = map.value(
QSL(
"index")).toInt();
151 const auto window = getWindow(map);
155 window->tabWidget()->detachTab(index);
161 if (!map.contains(
QSL(
"index"))) {
162 qWarning() <<
"Unable to duplicate:" <<
"index not defined";
166 const int index = map.value(
QSL(
"index")).toInt();
168 const auto window = getWindow(map);
172 window->tabWidget()->duplicateTab(index);
178 if (!map.contains(
QSL(
"index"))) {
179 qWarning() <<
"Unable to close tab:" <<
"index not defined";
183 const int index = map.value(
QSL(
"index")).toInt();
185 const auto window = getWindow(map);
189 window->tabWidget()->closeTab(index);
195 if (!map.contains(
QSL(
"index"))) {
196 qWarning() <<
"Unable to reload tab:" <<
"index not defined";
200 const int index = map.value(
QSL(
"index")).toInt();
202 const auto window = getWindow(map);
206 window->tabWidget()->reloadTab(index);
212 if (!map.contains(
QSL(
"index"))) {
213 qWarning() <<
"Unable to close tab:" <<
"index not defined";
217 const int index = map.value(
QSL(
"index")).toInt();
219 const auto window = getWindow(map);
223 window->tabWidget()->stopTab(index);
229 if (!map.contains(
QSL(
"index"))) {
230 qWarning() <<
"Unable to set current index:" <<
"index not defined";
234 const int index = map.value(
QSL(
"index")).toInt();
236 const auto window = getWindow(map);
240 const auto webTab = window->tabWidget()->webTab(index);
246 const auto window = getWindow(windowId);
250 return window->tabWidget()->normalTabsCount();
255 const auto window = getWindow(windowId);
259 return window->tabWidget()->pinnedTabsCount();
264 const auto window = getWindow(map);
269 const bool withPinned = map.value(
QSL(
"withPinned")).toBool();
270 const QList<WebTab*> tabList = window->tabWidget()->allTabs(withPinned);
272 QList<QObject*> list;
273 list.reserve(tabList.size());
274 for (
WebTab *tab : tabList) {
283 const QString title = map.value(
QSL(
"title")).toString();
284 const QString url = map.value(
QSL(
"url")).toString();
285 const bool withPinned = map.value(
QSL(
"withPinned")).toBool();
286 QList<QObject*> list;
288 for (
WebTab *webTab : window->tabWidget()->allTabs(withPinned)) {
289 if (webTab->title().contains(title, Qt::CaseInsensitive)
290 || QString::fromUtf8(webTab->url().toEncoded()).contains(url, Qt::CaseInsensitive)) {
300 const QString urlString = map.value(
QSL(
"url")).toString();
301 const auto window = getWindow(map);
303 qDebug() <<
"Unable to add tab:" <<
"window not found";
306 LoadRequest req(QUrl::fromEncoded(urlString.toUtf8()));
307 const int ret = window->tabWidget()->addView(req);
308 return ret != -1 ? true :
false;
311BrowserWindow *QmlTabs::getWindow(
const QVariantMap &map)
const
313 const int windowId = map.value(
QSL(
"windowId"), -1).toInt();
314 return getWindow(windowId);
319 if (windowId == -1) {
320 return mApp->getWindow();
324 for (
auto it = windowIdHash.cbegin(); it != windowIdHash.cend(); it++) {
330 qWarning() <<
"Unable to get window with given windowId";
339 Q_EMIT changed(windowId);
344 map.insert(QSL(
"windowId"), windowId);
345 map.insert(QSL(
"index"), index);
346 Q_EMIT tabInserted(map);
351 map.insert(QSL(
"windowId"), windowId);
352 map.insert(QSL(
"index"), index);
353 Q_EMIT tabRemoved(map);
358 map.insert(QSL(
"windowId"), windowId);
359 map.insert(QSL(
"from"), from);
360 map.insert(QSL(
"to"), to);
361 Q_EMIT tabMoved(map);
TabWidget * tabWidget() const
void mainWindowCreated(BrowserWindow *window)
QHash< BrowserWindow *, int > windowIdHash()
QmlTab * getTab(WebTab *webTab)
static QmlStaticData & instance()
The class exposing a browser tab to QML.
Q_INVOKABLE bool unpinTab(const QVariantMap &map)
Un-pins a tab.
Q_INVOKABLE bool addTab(const QVariantMap &map)
Adds a tab.
Q_INVOKABLE bool closeTab(const QVariantMap &map)
Close a tab.
Q_INVOKABLE bool stopTab(const QVariantMap &map)
Stops a tab.
Q_INVOKABLE bool moveTab(const QVariantMap &map)
Moves a tab.
Q_INVOKABLE bool duplicate(const QVariantMap &map)
Duplicates a tab.
Q_INVOKABLE QList< QObject * > getAll(const QVariantMap &map=QVariantMap()) const
Gets all the tabs of a window.
Q_INVOKABLE int pinnedTabsCount(int windowId=-1) const
Get the pinned tabs count in a window.
QmlTabs(QObject *parent=nullptr)
Q_INVOKABLE bool setCurrentIndex(const QVariantMap &map)
Sets the current tab in a window.
Q_INVOKABLE bool nextTab(int windowId=-1)
Sets the next tab as current tab.
Q_INVOKABLE bool detachTab(const QVariantMap &map)
Detaches a tab.
Q_INVOKABLE bool previousTab(int windowId=-1)
Sets the previous tab as current tab.
Q_INVOKABLE bool reloadTab(const QVariantMap &map)
Reloads a tab.
Q_INVOKABLE QmlTab * get(const QVariantMap &map) const
Gets a tab.
Q_INVOKABLE bool pinTab(const QVariantMap &map)
Pins a tab.
Q_INVOKABLE int normalTabsCount(int windowId=-1) const
Get the normal tabs count in a window.
Q_INVOKABLE QList< QObject * > search(const QVariantMap &map)
Searches tabs against a criteria.
int value(const QColor &c)