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:
parent
a9a65be17a
commit
7f5f3a8bfc
@ -103,6 +103,7 @@ MainApplication::MainApplication(int &argc, char** argv)
|
||||
, m_desktopNotifications(0)
|
||||
, m_webProfile(0)
|
||||
, m_autoSaver(0)
|
||||
, m_newWindowId(0)
|
||||
#if defined(Q_OS_WIN) && !defined(Q_OS_OS2)
|
||||
, m_registerQAppAssociation(0)
|
||||
#endif
|
||||
@ -406,6 +407,11 @@ QList<BrowserWindow*> MainApplication::windows() const
|
||||
return m_windows;
|
||||
}
|
||||
|
||||
QHash<BrowserWindow*, int> MainApplication::windowIdHash() const
|
||||
{
|
||||
return m_windowIdHash;
|
||||
}
|
||||
|
||||
BrowserWindow* MainApplication::getWindow() const
|
||||
{
|
||||
if (m_lastActiveWindow) {
|
||||
@ -425,6 +431,7 @@ BrowserWindow* MainApplication::createWindow(Qz::BrowserWindowType type, const Q
|
||||
connect(window, SIGNAL(destroyed(QObject*)), this, SLOT(windowDestroyed(QObject*)));
|
||||
|
||||
m_windows.prepend(window);
|
||||
m_windowIdHash.insert(window, m_newWindowId++);
|
||||
return window;
|
||||
}
|
||||
|
||||
@ -868,6 +875,7 @@ void MainApplication::windowDestroyed(QObject* window)
|
||||
Q_ASSERT(m_windows.contains(static_cast<BrowserWindow*>(window)));
|
||||
|
||||
m_windows.removeOne(static_cast<BrowserWindow*>(window));
|
||||
m_windowIdHash.remove(static_cast<BrowserWindow*>(window));
|
||||
}
|
||||
|
||||
void MainApplication::onFocusChanged()
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
|
||||
int windowCount() const;
|
||||
QList<BrowserWindow*> windows() const;
|
||||
QHash<BrowserWindow*, int> windowIdHash() const;
|
||||
|
||||
BrowserWindow* getWindow() const;
|
||||
BrowserWindow* createWindow(Qz::BrowserWindowType type, const QUrl &startUrl = QUrl());
|
||||
@ -188,6 +189,8 @@ private:
|
||||
ProxyStyle *m_proxyStyle = nullptr;
|
||||
|
||||
QList<BrowserWindow*> m_windows;
|
||||
int m_newWindowId;
|
||||
QHash<BrowserWindow*, int> m_windowIdHash;
|
||||
QPointer<BrowserWindow> m_lastActiveWindow;
|
||||
|
||||
QList<PostLaunchAction> m_postLaunchActions;
|
||||
|
@ -27,23 +27,6 @@ QmlTabs::QmlTabs(QObject *parent)
|
||||
}
|
||||
|
||||
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)
|
||||
@ -326,54 +309,46 @@ BrowserWindow *QmlTabs::getWindow(const QVariantMap &map) const
|
||||
{
|
||||
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) {
|
||||
window = mApp->getWindow();
|
||||
} else {
|
||||
window = mApp->windows().at(windowId);
|
||||
return mApp->getWindow();
|
||||
}
|
||||
|
||||
return window;
|
||||
for(BrowserWindow *window : mApp->windowIdHash().keys()) {
|
||||
if (mApp->windowIdHash().value(window) == windowId) {
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unable to get window with given windowId";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void QmlTabs::windowCreated(BrowserWindow *window)
|
||||
{
|
||||
// FIXME: make it more efficient
|
||||
for (int i = 0; i < mApp->windowCount(); i++) {
|
||||
windowIdHash[mApp->windows().at(i)] = i;
|
||||
}
|
||||
int windowId = mApp->windowIdHash().value(window);
|
||||
|
||||
connect(window->tabWidget(), &TabWidget::changed, this, [this, window]{
|
||||
connect(window->tabWidget(), &TabWidget::changed, this, [this, windowId]{
|
||||
QVariantMap map;
|
||||
int windowId = windowIdHash.value(window);
|
||||
map.insert(QSL("windowId"), windowId);
|
||||
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;
|
||||
int windowId = windowIdHash.value(window);
|
||||
map.insert(QSL("windowId"), windowId);
|
||||
map.insert(QSL("index"), index);
|
||||
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;
|
||||
int windowId = windowIdHash.value(window);
|
||||
map.insert(QSL("windowId"), windowId);
|
||||
map.insert(QSL("index"), index);
|
||||
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;
|
||||
int windowId = windowIdHash.value(window);
|
||||
map.insert(QSL("windowId"), windowId);
|
||||
map.insert(QSL("from"), from);
|
||||
map.insert(QSL("to"), to);
|
||||
|
@ -51,5 +51,4 @@ Q_SIGNALS:
|
||||
private:
|
||||
BrowserWindow *getWindow(const QVariantMap &map) const;
|
||||
void windowCreated(BrowserWindow *window);
|
||||
QHash<BrowserWindow*, int> windowIdHash;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user