Display lag and SSL status in CoreConnectionStatusWidget
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2009 21:34:50 +0000 (22:34 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2009 23:39:42 +0000 (00:39 +0100)
Removing the legacy widgets too.

src/client/coreconnection.cpp
src/qtui/CMakeLists.txt
src/qtui/coreconnectionstatuswidget.cpp
src/qtui/coreconnectionstatuswidget.h
src/qtui/mainwin.cpp
src/qtui/mainwin.h
src/qtui/ui/coreconnectionstatuswidget.ui

index a60fae3..a982f62 100644 (file)
@@ -155,9 +155,6 @@ void CoreConnection::setState(QAbstractSocket::SocketState socketState) {
   case QAbstractSocket::ConnectingState:
     state = Connecting;
     break;
-  case QAbstractSocket::ConnectedState:
-    state = Connected;
-    break;
   default:
     state = Disconnected;
   }
@@ -220,7 +217,7 @@ void CoreConnection::coreHasData() {
       sessionStateReceived(msg["SessionState"].toMap());
       break; // this is definitively the last message we process here!
     } else {
-      emit connectionError(tr("<b>Invalid data received from core!</b><br>Disconnecting."));
+      emit connectionError(tr("Invalid data received from core, disconnecting."));
       disconnectFromCore();
       return;
     }
@@ -448,6 +445,9 @@ void CoreConnection::sslErrors() {
 #endif /* HAVE_SSL */
 
 void CoreConnection::connectionReady() {
+  setState(Connected);
+  emit connectionMsg(tr("Connected to %1").arg(currentAccount().accountName()));
+
   if(!_coreMsgBuffer["Configured"].toBool()) {
     // start wizard
     emit startCoreSetup(_coreMsgBuffer["StorageBackends"].toList());
@@ -559,7 +559,7 @@ void CoreConnection::networkInitDone() {
 void CoreConnection::checkSyncState() {
   if(_netsToSync.isEmpty()) {
     setState(Synchronized);
-    setProgressText(QString());
+    setProgressText(tr("Synchronized to %1").arg(currentAccount().accountName()));
     setProgressMaximum(-1);
     emit synchronized();
   }
index 3e7e067..0a87377 100644 (file)
@@ -120,6 +120,7 @@ set(FORMS
     coreconfigwizardstorageselectionpage.ui
     coreconfigwizardsyncpage.ui
     coreconnectauthdlg.ui
+    coreconnectionstatuswidget.ui
     coreinfodlg.ui
     debugbufferviewoverlay.ui
     debugconsole.ui
index bc78fc6..34cdc66 100644 (file)
 #include "coreconnectionstatuswidget.h"
 
 #include "client.h"
-#include "coreconnection.h"
 #include "iconloader.h"
+#include "signalproxy.h"
 
 CoreConnectionStatusWidget::CoreConnectionStatusWidget(CoreConnection *connection, QWidget *parent)
   : QWidget(parent),
   _coreConnection(connection)
 {
   ui.setupUi(this);
+  ui.lagLabel->hide();
+  ui.sslLabel->hide();
   update();
 
   connect(coreConnection(), SIGNAL(progressTextChanged(QString)), ui.messageLabel, SLOT(setText(QString)));
@@ -36,7 +38,9 @@ CoreConnectionStatusWidget::CoreConnectionStatusWidget(CoreConnection *connectio
   connect(coreConnection(), SIGNAL(progressRangeChanged(int, int)), ui.progressBar, SLOT(setRange(int, int)));
   connect(coreConnection(), SIGNAL(progressRangeChanged(int, int)), this, SLOT(progressRangeChanged(int, int)));
 
+  connect(coreConnection(), SIGNAL(stateChanged(CoreConnection::ConnectionState)), SLOT(connectionStateChanged(CoreConnection::ConnectionState)));
   connect(coreConnection(), SIGNAL(connectionError(QString)), ui.messageLabel, SLOT(setText(QString)));
+  connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), SLOT(updateLag(int)));
 }
 
 void CoreConnectionStatusWidget::update() {
@@ -50,7 +54,31 @@ void CoreConnectionStatusWidget::update() {
     ui.progressBar->hide();
 
   ui.messageLabel->setText(conn->progressText());
+}
+
+void CoreConnectionStatusWidget::updateLag(int msecs) {
+  if(msecs >= 0) {
+    ui.lagLabel->setText(tr("(Lag: %1 ms)").arg(msecs));
+    if(!ui.lagLabel->isVisible())
+      ui.lagLabel->show();
+  } else {
+    if(ui.lagLabel->isVisible())
+      ui.lagLabel->hide();
+  }
+}
 
+void CoreConnectionStatusWidget::connectionStateChanged(CoreConnection::ConnectionState state) {
+  if(state >= CoreConnection::Connected) {
+    if(coreConnection()->isEncrypted()) {
+      ui.sslLabel->setPixmap(SmallIcon("security-high"));
+      ui.sslLabel->setToolTip(tr("The connection to your core is encrypted with SSL."));
+    } else {
+      ui.sslLabel->setPixmap(SmallIcon("security-low"));
+      ui.sslLabel->setToolTip(tr("The connection to your core is not encrypted."));
+    }
+    ui.sslLabel->show();
+  } else
+    ui.sslLabel->hide();
 }
 
 void CoreConnectionStatusWidget::progressRangeChanged(int min, int max) {
index fd2c10a..f07926e 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "ui_coreconnectionstatuswidget.h"
 
-class CoreConnection;
+#include "coreconnection.h"
 
 class CoreConnectionStatusWidget : public QWidget {
   Q_OBJECT
@@ -37,7 +37,10 @@ public:
 
 public slots:
   void update();
+  void updateLag(int msecs);
+
 private slots:
+  void connectionStateChanged(CoreConnection::ConnectionState);
   void progressRangeChanged(int min, int max);
 
 private:
index c779210..0b5fe85 100644 (file)
@@ -128,8 +128,6 @@ MainWin::MainWin(QWidget *parent)
 #else
   : QMainWindow(parent),
 #endif
-    coreLagLabel(new QLabel()),
-    sslLabel(new QLabel()),
     _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
     _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
     _titleSetter(this),
@@ -642,17 +640,6 @@ void MainWin::setupStatusBar() {
   _coreConnectionStatusWidget->update();
   statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
 
-  // Core Lag:
-  updateLagIndicator();
-  statusBar()->addPermanentWidget(coreLagLabel);
-  coreLagLabel->hide();
-  connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
-
-  // SSL indicator
-  sslLabel->setPixmap(QPixmap());
-  statusBar()->addPermanentWidget(sslLabel);
-  sslLabel->hide();
-
   QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
 
   QtUiSettings uiSettings;
@@ -746,14 +733,7 @@ void MainWin::setConnectedState() {
   else
     statusBar()->clearMessage();
 
-  if(Client::signalProxy()->isSecure()) {
-    sslLabel->setPixmap(SmallIcon("security-high"));
-  } else {
-    sslLabel->setPixmap(SmallIcon("security-low"));
-  }
-
-  sslLabel->setVisible(!Client::internalCore());
-  coreLagLabel->setVisible(!Client::internalCore());
+  _coreConnectionStatusWidget->setVisible(!Client::internalCore());
   updateIcon();
   systemTray()->setState(SystemTray::Active);
 
@@ -784,15 +764,6 @@ void MainWin::saveLayout() {
   if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
 }
 
-void MainWin::updateLagIndicator(int lag) {
-  QString text = tr("Core Lag: %1");
-  if(lag == -1)
-    text = text.arg('-');
-  else
-    text = text.arg("%1 msec").arg(lag);
-  coreLagLabel->setText(text);
-}
-
 void MainWin::disconnectedFromCore() {
   // save core specific layout and remove bufferviews;
   saveLayout();
@@ -827,10 +798,6 @@ void MainWin::setDisconnectedState() {
   coll->action("CoreInfo")->setEnabled(false);
   //_viewMenu->setEnabled(false);
   statusBar()->showMessage(tr("Not connected to core."));
-  sslLabel->setPixmap(QPixmap());
-  sslLabel->hide();
-  updateLagIndicator();
-  coreLagLabel->hide();
   if(_msgProcessorStatusWidget)
     _msgProcessorStatusWidget->setProgress(0, 0);
   updateIcon();
index 5f15fa5..8c9c1ec 100644 (file)
@@ -107,7 +107,6 @@ class MainWin
   protected slots:
     void connectedToCore();
     void setConnectedState();
-    void updateLagIndicator(int lag = -1);
     void disconnectedFromCore();
     void setDisconnectedState();
 
@@ -168,8 +167,6 @@ class MainWin
     KHelpMenu *_kHelpMenu;
 #endif
 
-    QLabel *coreLagLabel;
-    QLabel *sslLabel;
     MsgProcessorStatusWidget *_msgProcessorStatusWidget;
     CoreConnectionStatusWidget *_coreConnectionStatusWidget;
 
index f9e72e0..0d05ef8 100644 (file)
    <string>Form</string>
   </property>
   <layout class="QHBoxLayout" name="horizontalLayout">
-   <property name="margin">
+   <property name="leftMargin">
+    <number>4</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>4</number>
+   </property>
+   <property name="bottomMargin">
     <number>0</number>
    </property>
    <item>
      </property>
     </widget>
    </item>
+   <item>
+    <widget class="QLabel" name="lagLabel">
+     <property name="text">
+      <string notr="true">Lag: n/a</string>
+     </property>
+    </widget>
+   </item>
    <item>
     <widget class="QLabel" name="sslLabel">
      <property name="text">