diff --git a/kdecore/kernel/kglobal.cpp b/kdecore/kernel/kglobal.cpp
index 2ce71a4..00d4265 100644
--- a/kdecore/kernel/kglobal.cpp
+++ b/kdecore/kernel/kglobal.cpp
@@ -176,6 +176,15 @@ KComponentData KGlobal::activeComponent()
     return d->activeComponent;
 }
 
+bool KGlobal::hasActiveComponent()
+{
+    if (globalData.isDestroyed()) {
+        return false;
+    }
+    PRIVATE_DATA;
+    return d->activeComponent.isValid();
+}
+
 void KGlobal::setActiveComponent(const KComponentData &c)
 {
     PRIVATE_DATA;
diff --git a/kdecore/kernel/kglobal.h b/kdecore/kernel/kglobal.h
index e2f8cce..340c87b 100644
--- a/kdecore/kernel/kglobal.h
+++ b/kdecore/kernel/kglobal.h
@@ -446,6 +446,13 @@ namespace KGlobal
     KDECORE_EXPORT KComponentData activeComponent();
 
     /**
+     * @internal
+     * Returns whether an active KComponentData is available.
+     * @since 4.2
+     */
+    KDECORE_EXPORT bool hasActiveComponent();
+
+    /**
      * Set the active component for use by KAboutDialog and KBugReport.
      * To be used only by a multi-component (KParts) application.
      *
diff --git a/kdeui/widgets/kmainwindow.cpp b/kdeui/widgets/kmainwindow.cpp
index 3c0ca78..cdeb091 100644
--- a/kdeui/widgets/kmainwindow.cpp
+++ b/kdeui/widgets/kmainwindow.cpp
@@ -117,11 +117,11 @@ bool DockResizeListener::eventFilter(QObject *watched, QEvent *event)
     if (event->type() == QEvent::Resize) {
         m_win->setSettingsDirty();
     }
-#ifdef Q_WS_WIN
+
     if (event->type() == QEvent::Move) {
         m_win->setSettingsDirty();
     }
-#endif
+
     return QObject::eventFilter(watched, event);
 }
 
@@ -631,10 +631,19 @@ void KMainWindow::saveMainWindowSettings(const KConfigGroup &_cg)
            cg.writeEntry("MenuBar", mb->isHidden() ? "Disabled" : "Enabled");
     }
 
-    // Utilise the QMainWindow::saveState() functionality
-    QByteArray state = saveState();
-    cg.writeEntry("State", state.toBase64());
     // One day will need to save the version number, but for now, assume 0
+    // Utilise the QMainWindow::saveState() functionality.
+    // In case we are switching between parts (and have different main toolbars), we need to save
+    // the different states of the window (taking in count some toolbars could have the same name,
+    // as "mainToolbar", for instance). This way we always load the state of the correct window. (ereslibre)
+    QString componentDataName;
+    if (KGlobal::hasActiveComponent()) {
+        componentDataName = KGlobal::activeComponent().componentName();
+    } else if (KGlobal::hasMainComponent()) {
+        componentDataName = KGlobal::mainComponent().componentName();
+    }
+    QByteArray state = saveState();
+    cg.writeEntry(QString("State%1").arg(componentDataName), state.toBase64());
 
     if ( !autoSaveSettings() || cg.name() == autoSaveGroup() ) { // TODO should be cg == d->autoSaveGroup, to compare both kconfig and group name
         if(!cg.hasDefault("ToolBarsMovable") && !KToolBar::toolBarsLocked())
@@ -705,10 +714,20 @@ void KMainWindow::applyMainWindowSettings(const KConfigGroup &cg, bool force)
            mb->show();
     }
 
-    // Utilise the QMainWindow::restoreState() functionality
-    if (cg.hasKey("State")) {
+    // Utilise the QMainWindow::restoreState() functionality.
+    // In case we are switching between parts (and have different main toolbars), we need to save
+    // the different states of the window (taking in count some toolbars could have the same name,
+    // as "mainToolbar", for instance). This way we always load the state of the correct window. (ereslibre)
+    QString componentDataName;
+    if (KGlobal::hasActiveComponent()) {
+        componentDataName = KGlobal::activeComponent().componentName();
+    } else if (KGlobal::hasMainComponent()) {
+        componentDataName = KGlobal::mainComponent().componentName();
+    }
+    QString entry = QString("State%1").arg(componentDataName);
+    if (cg.hasKey(entry)) {
         QByteArray state;
-        state = cg.readEntry("State", state);
+        state = cg.readEntry(entry, state);
         state = QByteArray::fromBase64(state);
         // One day will need to load the version number, but for now, assume 0
         restoreState(state);
@@ -900,7 +919,7 @@ void KMainWindow::setSettingsDirty()
            d->settingsTimer = new QTimer( this );
            connect( d->settingsTimer, SIGNAL( timeout() ), SLOT( saveAutoSaveSettings() ) );
         }
-        d->settingsTimer->setInterval(5000);
+        d->settingsTimer->setInterval(500);
         d->settingsTimer->setSingleShot(true);
         d->settingsTimer->start();
     }
@@ -985,6 +1004,7 @@ bool KMainWindow::event( QEvent* ev )
         {
             QChildEvent *event = static_cast<QChildEvent*>(ev);
             QDockWidget *dock = qobject_cast<QDockWidget*>(event->child());
+            KToolBar *toolbar = qobject_cast<KToolBar*>(event->child());
             if (dock) {
                 connect(dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
                         this, SLOT(setSettingsDirty()));
@@ -996,6 +1016,10 @@ bool KMainWindow::event( QEvent* ev )
                 // there is no signal emitted if the size of the dock changes,
                 // hence install an event filter instead
                 dock->installEventFilter(k_ptr->dockResizeListener);
+            } else if (toolbar) {
+                // there is no signal emitted if the size of the dock changes,
+                // hence install an event filter instead
+                toolbar->installEventFilter(k_ptr->dockResizeListener);
             }
         }
         break;
