this should fix crashes in the nick/bufer view delegates when receiving an invalid...
[quassel.git] / src / qtui / mainwin.cpp
index dda747d..10aedfa 100644 (file)
@@ -455,7 +455,6 @@ void MainWin::setupTitleSetter() {
 void MainWin::setupStatusBar() {
   // MessageProcessor progress
   statusBar()->addPermanentWidget(msgProcessorStatusWidget);
-  connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
 
   // Core Lag:
   updateLagIndicator();
@@ -464,7 +463,6 @@ void MainWin::setupStatusBar() {
   connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
 
   // SSL indicator
-  connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection()));
   sslLabel->setPixmap(QPixmap());
   statusBar()->addPermanentWidget(sslLabel);
   sslLabel->hide();
@@ -480,9 +478,6 @@ void MainWin::setupStatusBar() {
 
   connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
   connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
-
-  connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
-  connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
 }
 
 void MainWin::saveStatusBarStatus(bool enabled) {
@@ -510,10 +505,8 @@ void MainWin::setupSystray() {
   }
 
 #ifndef Q_WS_MAC
-  connect(systemTrayIcon(), SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
-          this, SLOT(systrayActivated( QSystemTrayIcon::ActivationReason )));
+  connect(systemTrayIcon(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayActivated(QSystemTrayIcon::ActivationReason)));
 #endif
-
 }
 
 void MainWin::changeEvent(QEvent *event) {
@@ -521,8 +514,8 @@ void MainWin::changeEvent(QEvent *event) {
     if(windowState() & Qt::WindowMinimized) {
       QtUiSettings s;
       if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
-        toggleVisibility();
-        event->ignore();
+       hideToTray();
+       event->accept();
       }
     }
   }
@@ -549,12 +542,24 @@ void MainWin::setConnectedState() {
       action->setVisible(!Client::internalCore());
   }
 
+  disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
+  disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
+  disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
+  if(!Client::internalCore()) {
+    connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
+    connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
+    connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
+  }
+
   // _viewMenu->setEnabled(true);
   if(!Client::internalCore())
     statusBar()->showMessage(tr("Connected to core."));
 
-  if(sslLabel->width() == 0)
+  if(Client::signalProxy()->isSecure()) {
+    sslLabel->setPixmap(SmallIcon("security-high"));
+  } else {
     sslLabel->setPixmap(SmallIcon("security-low"));
+  }
 
   sslLabel->setVisible(!Client::internalCore());
   coreLagLabel->setVisible(!Client::internalCore());
@@ -582,12 +587,6 @@ void MainWin::updateLagIndicator(int lag) {
   coreLagLabel->setText(text);
 }
 
-
-void MainWin::securedConnection() {
-  // todo: make status bar entry
-  sslLabel->setPixmap(SmallIcon("security-high"));
-}
-
 void MainWin::disconnectedFromCore() {
   // save core specific layout and remove bufferviews;
   saveLayout();
@@ -687,8 +686,10 @@ void MainWin::showShortcutsDlg() {
 
 void MainWin::closeEvent(QCloseEvent *event) {
   QtUiSettings s;
-  if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
-    toggleVisibility();
+  QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
+  Q_ASSERT(app);
+  if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
+    toggleMinimizedToTray();
     event->ignore();
   } else {
     event->accept();
@@ -696,36 +697,32 @@ void MainWin::closeEvent(QCloseEvent *event) {
   }
 }
 
-void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
+void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) {
   if(activationReason == QSystemTrayIcon::Trigger) {
-    toggleVisibility();
+    toggleMinimizedToTray();
   }
 }
 
-void MainWin::toggleVisibility() {
-  if(isHidden() /*|| !isActiveWindow()*/) {
-    show();
-    if(isMinimized()) {
-      if(isMaximized())
-        showMaximized();
-      else
-        showNormal();
-    }
+void MainWin::hideToTray() {
+  if(!systemTrayIcon()->isSystemTrayAvailable()) {
+    qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
+    return;
+  }
 
-    raise();
-    activateWindow();
-    // setFocus(); //Qt::ActiveWindowFocusReason
+  clearFocus();
+  hide();
+  systemTrayIcon()->show();
+}
 
+void MainWin::toggleMinimizedToTray() {
+  if(windowState() & Qt::WindowMinimized) {
+    // restore
+    setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
+    show();
+    raise();
   } else {
-    if(systemTrayIcon()->isSystemTrayAvailable ()) {
-      clearFocus();
-      hide();
-      if(!systemTrayIcon()->isVisible()) {
-        systemTrayIcon()->show();
-      }
-    } else {
-      lower();
-    }
+    setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized);
+    hideToTray();
   }
 }