1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

corrected windowId(s) for qml plugins

This commit is contained in:
Anmol Gautam 2018-06-03 18:24:03 +05:30
parent a9a65be17a
commit 7f5f3a8bfc
4 changed files with 25 additions and 40 deletions

View File

@ -103,6 +103,7 @@ MainApplication::MainApplication(int &argc, char** argv)
, m_desktopNotifications(0) , m_desktopNotifications(0)
, m_webProfile(0) , m_webProfile(0)
, m_autoSaver(0) , m_autoSaver(0)
, m_newWindowId(0)
#if defined(Q_OS_WIN) && !defined(Q_OS_OS2) #if defined(Q_OS_WIN) && !defined(Q_OS_OS2)
, m_registerQAppAssociation(0) , m_registerQAppAssociation(0)
#endif #endif
@ -406,6 +407,11 @@ QList<BrowserWindow*> MainApplication::windows() const
return m_windows; return m_windows;
} }
QHash<BrowserWindow*, int> MainApplication::windowIdHash() const
{
return m_windowIdHash;
}
BrowserWindow* MainApplication::getWindow() const BrowserWindow* MainApplication::getWindow() const
{ {
if (m_lastActiveWindow) { if (m_lastActiveWindow) {
@ -425,6 +431,7 @@ BrowserWindow* MainApplication::createWindow(Qz::BrowserWindowType type, const Q
connect(window, SIGNAL(destroyed(QObject*)), this, SLOT(windowDestroyed(QObject*))); connect(window, SIGNAL(destroyed(QObject*)), this, SLOT(windowDestroyed(QObject*)));
m_windows.prepend(window); m_windows.prepend(window);
m_windowIdHash.insert(window, m_newWindowId++);
return window; return window;
} }
@ -868,6 +875,7 @@ void MainApplication::windowDestroyed(QObject* window)
Q_ASSERT(m_windows.contains(static_cast<BrowserWindow*>(window))); Q_ASSERT(m_windows.contains(static_cast<BrowserWindow*>(window)));
m_windows.removeOne(static_cast<BrowserWindow*>(window)); m_windows.removeOne(static_cast<BrowserWindow*>(window));
m_windowIdHash.remove(static_cast<BrowserWindow*>(window));
} }
void MainApplication::onFocusChanged() void MainApplication::onFocusChanged()

View File

@ -76,6 +76,7 @@ public:
int windowCount() const; int windowCount() const;
QList<BrowserWindow*> windows() const; QList<BrowserWindow*> windows() const;
QHash<BrowserWindow*, int> windowIdHash() const;
BrowserWindow* getWindow() const; BrowserWindow* getWindow() const;
BrowserWindow* createWindow(Qz::BrowserWindowType type, const QUrl &startUrl = QUrl()); BrowserWindow* createWindow(Qz::BrowserWindowType type, const QUrl &startUrl = QUrl());
@ -188,6 +189,8 @@ private:
ProxyStyle *m_proxyStyle = nullptr; ProxyStyle *m_proxyStyle = nullptr;
QList<BrowserWindow*> m_windows; QList<BrowserWindow*> m_windows;
int m_newWindowId;
QHash<BrowserWindow*, int> m_windowIdHash;
QPointer<BrowserWindow> m_lastActiveWindow; QPointer<BrowserWindow> m_lastActiveWindow;
QList<PostLaunchAction> m_postLaunchActions; QList<PostLaunchAction> m_postLaunchActions;

View File

@ -27,23 +27,6 @@ QmlTabs::QmlTabs(QObject *parent)
} }
connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, &QmlTabs::windowCreated); connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, &QmlTabs::windowCreated);
connect(mApp->plugins(), &PluginProxy::mainWindowDeleted, this, [this](BrowserWindow *window){
// FIXME: make it more efficient
windowIdHash.remove(window);
// If the window is not destroyed (which is almost always),
// then remove bias(= 1) from the index of window in the list
// for the correct index
int bias = 0;
for (int i = 0; i < mApp->windowCount(); i++) {
BrowserWindow *windowAtI = mApp->windows().at(i);
if (windowAtI == window) {
bias = 1;
continue;
}
windowIdHash[windowAtI] = i - bias;
}
});
} }
bool QmlTabs::setCurrentIndex(const QVariantMap &map) bool QmlTabs::setCurrentIndex(const QVariantMap &map)
@ -326,54 +309,46 @@ BrowserWindow *QmlTabs::getWindow(const QVariantMap &map) const
{ {
int windowId = map.value(QSL("windowId"), -1).toInt(); int windowId = map.value(QSL("windowId"), -1).toInt();
if (windowId < -1 || windowId >= mApp->windowCount()) {
qWarning() << "Unable to get window" << "windowId is out of bounds";
return nullptr;
}
BrowserWindow *window;
if (windowId == -1) { if (windowId == -1) {
window = mApp->getWindow(); return mApp->getWindow();
} else {
window = mApp->windows().at(windowId);
} }
for(BrowserWindow *window : mApp->windowIdHash().keys()) {
if (mApp->windowIdHash().value(window) == windowId) {
return window; return window;
} }
}
qWarning() << "Unable to get window with given windowId";
return nullptr;
}
void QmlTabs::windowCreated(BrowserWindow *window) void QmlTabs::windowCreated(BrowserWindow *window)
{ {
// FIXME: make it more efficient int windowId = mApp->windowIdHash().value(window);
for (int i = 0; i < mApp->windowCount(); i++) {
windowIdHash[mApp->windows().at(i)] = i;
}
connect(window->tabWidget(), &TabWidget::changed, this, [this, window]{ connect(window->tabWidget(), &TabWidget::changed, this, [this, windowId]{
QVariantMap map; QVariantMap map;
int windowId = windowIdHash.value(window);
map.insert(QSL("windowId"), windowId); map.insert(QSL("windowId"), windowId);
emit changed(map); emit changed(map);
}); });
connect(window->tabWidget(), &TabWidget::tabInserted, this, [this, window](int index){ connect(window->tabWidget(), &TabWidget::tabInserted, this, [this, windowId](int index){
QVariantMap map; QVariantMap map;
int windowId = windowIdHash.value(window);
map.insert(QSL("windowId"), windowId); map.insert(QSL("windowId"), windowId);
map.insert(QSL("index"), index); map.insert(QSL("index"), index);
emit tabInserted(map); emit tabInserted(map);
}); });
connect(window->tabWidget(), &TabWidget::tabRemoved, this, [this, window](int index){ connect(window->tabWidget(), &TabWidget::tabRemoved, this, [this, windowId](int index){
QVariantMap map; QVariantMap map;
int windowId = windowIdHash.value(window);
map.insert(QSL("windowId"), windowId); map.insert(QSL("windowId"), windowId);
map.insert(QSL("index"), index); map.insert(QSL("index"), index);
emit tabRemoved(map); emit tabRemoved(map);
}); });
connect(window->tabWidget(), &TabWidget::tabMoved, this, [this, window](int from, int to){ connect(window->tabWidget(), &TabWidget::tabMoved, this, [this, windowId](int from, int to){
QVariantMap map; QVariantMap map;
int windowId = windowIdHash.value(window);
map.insert(QSL("windowId"), windowId); map.insert(QSL("windowId"), windowId);
map.insert(QSL("from"), from); map.insert(QSL("from"), from);
map.insert(QSL("to"), to); map.insert(QSL("to"), to);

View File

@ -51,5 +51,4 @@ Q_SIGNALS:
private: private:
BrowserWindow *getWindow(const QVariantMap &map) const; BrowserWindow *getWindow(const QVariantMap &map) const;
void windowCreated(BrowserWindow *window); void windowCreated(BrowserWindow *window);
QHash<BrowserWindow*, int> windowIdHash;
}; };