This could / should / oh well you know the drill... just test if minimize to tray...
[quassel.git] / src / qtui / mainwin.cpp
index dda747d..4c39b12 100644 (file)
@@ -464,7 +464,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();
@@ -510,10 +509,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 +518,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();
       }
     }
   }
@@ -553,8 +550,11 @@ void MainWin::setConnectedState() {
   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 +582,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 +681,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()) {
+    hideToTray();
     event->ignore();
   } else {
     event->accept();
@@ -696,37 +692,27 @@ void MainWin::closeEvent(QCloseEvent *event) {
   }
 }
 
-void MainWin::systrayActivated( QSystemTrayIcon::ActivationReason activationReason) {
+void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) {
   if(activationReason == QSystemTrayIcon::Trigger) {
-    toggleVisibility();
+    restoreFromTray();
   }
 }
 
-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();
+}
 
-  } else {
-    if(systemTrayIcon()->isSystemTrayAvailable ()) {
-      clearFocus();
-      hide();
-      if(!systemTrayIcon()->isVisible()) {
-        systemTrayIcon()->show();
-      }
-    } else {
-      lower();
-    }
-  }
+void MainWin::restoreFromTray() {
+  setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
+  show();
+  raise();
 }
 
 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {