diff --git a/src/kcmkwin/kwindesktop/desktopsmodel.cpp b/src/kcmkwin/kwindesktop/desktopsmodel.cpp index fc98307148..dde4175039 100644 --- a/src/kcmkwin/kwindesktop/desktopsmodel.cpp +++ b/src/kcmkwin/kwindesktop/desktopsmodel.cpp @@ -37,7 +37,6 @@ DesktopsModel::DesktopsModel(QObject *parent) , m_serverModified(false) , m_serverSideRows(-1) , m_rows(-1) - , m_synchronizing(false) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); @@ -239,8 +238,6 @@ void DesktopsModel::setDesktopName(const QString &id, const QString &name) void DesktopsModel::syncWithServer() { - m_synchronizing = true; - auto callFinished = [this](QDBusPendingCallWatcher *call) { QDBusPendingReply reply = *call; @@ -248,6 +245,8 @@ void DesktopsModel::syncWithServer() handleCallError(); } + --m_pendingCalls; + call->deleteLater(); }; @@ -262,6 +261,7 @@ void DesktopsModel::syncWithServer() call.setArguments({(uint)newIndex, m_names.value(m_desktops.at(newIndex))}); + ++m_pendingCalls; QDBusPendingCall pending = QDBusConnection::sessionBus().asyncCall(call); const auto *watcher = new QDBusPendingCallWatcher(pending, this); @@ -288,6 +288,7 @@ void DesktopsModel::syncWithServer() call.setArguments({previous}); + ++m_pendingCalls; QDBusPendingCall pending = QDBusConnection::sessionBus().asyncCall(call); const QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, this); @@ -325,6 +326,7 @@ void DesktopsModel::syncWithServer() call.setArguments({i.key(), i.value()}); + ++m_pendingCalls; QDBusPendingCall pending = QDBusConnection::sessionBus().asyncCall(call); const QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, this); @@ -349,6 +351,7 @@ void DesktopsModel::syncWithServer() call.setArguments({s_virtualDesktopsInterface, QStringLiteral("rows"), QVariant::fromValue(QDBusVariant(QVariant((uint)m_rows)))}); + ++m_pendingCalls; QDBusPendingCall pending = QDBusConnection::sessionBus().asyncCall(call); const QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, this); @@ -358,8 +361,6 @@ void DesktopsModel::syncWithServer() void DesktopsModel::reset() { - m_synchronizing = false; // Sanity. - auto getAllAndConnectCall = QDBusMessage::createMethodCall( s_serviceName, s_virtDesktopsPath, @@ -638,10 +639,8 @@ void DesktopsModel::updateModifiedState(bool server) m_serverModified = false; emit serverModifiedChanged(); - - m_synchronizing = false; } else { - if (m_synchronizing) { + if (m_pendingCalls > 0) { m_serverModified = false; emit serverModifiedChanged(); @@ -658,8 +657,7 @@ void DesktopsModel::updateModifiedState(bool server) void DesktopsModel::handleCallError() { - if (m_synchronizing) { - m_synchronizing = false; + if (m_pendingCalls > 0) { m_serverModified = false; emit serverModifiedChanged(); diff --git a/src/kcmkwin/kwindesktop/desktopsmodel.h b/src/kcmkwin/kwindesktop/desktopsmodel.h index 50387fa726..623baefcd0 100644 --- a/src/kcmkwin/kwindesktop/desktopsmodel.h +++ b/src/kcmkwin/kwindesktop/desktopsmodel.h @@ -120,7 +120,7 @@ private: QStringList m_desktops; QHash m_names; int m_rows; - bool m_synchronizing; + int m_pendingCalls = 0; }; }