Save the mainwindow state properly when exiting the client.
[quassel.git] / src / qtui / mainwin.cpp
index cf283e4..d16916d 100644 (file)
@@ -100,6 +100,9 @@ void MainWin::init() {
 
   Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
 
+  // let's hope here that nothing in disconnectedFromCore() needs user interaction/event loop...
+  connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(disconnectedFromCore()));
+
   connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkCreated(NetworkId)));
   connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), this, SLOT(clientNetworkRemoved(NetworkId)));
   //ui.bufferWidget->init();
@@ -131,7 +134,7 @@ void MainWin::init() {
   // restore mainwin state
   restoreState(s.value("MainWinState").toByteArray());
 
-  disconnectedFromCore();  // Disable menus and stuff
+  setDisconnectedState();  // Disable menus and stuff
   showCoreConnectionDlg(true); // autoconnect if appropriate
 
   // attach the BufferWidget to the BufferModel and the default selection
@@ -217,7 +220,7 @@ void MainWin::removeBufferView(int bufferViewConfigId) {
       break;
 
     dock = qobject_cast<BufferViewDock *>(action->parent());
-    if(dock && actionData.toInt() != bufferViewConfigId) {
+    if(dock && actionData.toInt() == bufferViewConfigId) {
       removeAction(action);
       dock->deleteLater();
     }
@@ -399,7 +402,10 @@ void MainWin::connectedToCore() {
   foreach(BufferInfo id, Client::allBufferInfos()) {
     Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1);
   }
+  setConnectedState();
+}
 
+void MainWin::setConnectedState() {
   ui.menuViews->setEnabled(true);
   //ui.menuCore->setEnabled(true);
   ui.actionConnectCore->setEnabled(false);
@@ -447,7 +453,11 @@ void MainWin::disconnectedFromCore() {
       dock->deleteLater();
     }
   }
+  restoreState(s.value("MainWinState").toByteArray());
+  setDisconnectedState();
+}
 
+void MainWin::setDisconnectedState() {
   ui.menuViews->setEnabled(false);
   //ui.menuCore->setEnabled(false);
   ui.actionDisconnectCore->setEnabled(false);