Improve error message display
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2009 21:53:23 +0000 (22:53 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2009 23:39:42 +0000 (00:39 +0100)
src/client/coreconnection.cpp
src/client/coreconnection.h
src/qtui/mainwin.cpp
src/qtui/mainwin.h

index a982f62..3d769cc 100644 (file)
@@ -120,7 +120,7 @@ void CoreConnection::socketStateChanged(QAbstractSocket::SocketState socketState
 
   switch(socketState) {
   case QAbstractSocket::UnconnectedState:
-    text = tr("Disconnected.");
+    text = tr("Disconnected");
     break;
   case QAbstractSocket::HostLookupState:
     text = tr("Looking up %1...").arg(currentAccount().hostName());
@@ -129,7 +129,7 @@ void CoreConnection::socketStateChanged(QAbstractSocket::SocketState socketState
     text = tr("Connecting to %1...").arg(currentAccount().hostName());
     break;
   case QAbstractSocket::ConnectedState:
-    text = tr("Connected to %1.").arg(currentAccount().hostName());
+    text = tr("Connected to %1").arg(currentAccount().hostName());
     break;
   case QAbstractSocket::ClosingState:
     text = tr("Disconnecting from %1...").arg(currentAccount().hostName());
@@ -189,14 +189,14 @@ void CoreConnection::coreHasData() {
     QVariantMap msg = item.toMap();
     if(!msg.contains("MsgType")) {
       // This core is way too old and does not even speak our init protocol...
-      emit connectionError(tr("The Quassel Core you try to connect to is too old! Please consider upgrading."));
+      emit connectionErrorPopup(tr("The Quassel Core you try to connect to is too old! Please consider upgrading."));
       disconnectFromCore();
       return;
     }
     if(msg["MsgType"] == "ClientInitAck") {
       clientInitAck(msg);
     } else if(msg["MsgType"] == "ClientInitReject") {
-      emit connectionError(msg["Error"].toString());
+      emit connectionErrorPopup(msg["Error"].toString());
       disconnectFromCore();
       return;
     } else if(msg["MsgType"] == "CoreSetupAck") {
@@ -217,8 +217,7 @@ void CoreConnection::coreHasData() {
       sessionStateReceived(msg["SessionState"].toMap());
       break; // this is definitively the last message we process here!
     } else {
-      emit connectionError(tr("Invalid data received from core, disconnecting."));
-      disconnectFromCore();
+      disconnectFromCore(tr("Invalid data received from core"));
       return;
     }
   }
@@ -227,7 +226,12 @@ void CoreConnection::coreHasData() {
   }
 }
 
-void CoreConnection::disconnectFromCore() {
+void CoreConnection::disconnectFromCore(const QString &errorString) {
+  if(errorString.isEmpty())
+    emit connectionError(tr("Disconnected"));
+  else
+    emit connectionError(errorString);
+
   Client::signalProxy()->removeAllPeers();
   resetConnection();
 }
@@ -351,7 +355,7 @@ void CoreConnection::clientInitAck(const QVariantMap &msg) {
   // Core has accepted our version info and sent its own. Let's see if we accept it as well...
   uint ver = msg["ProtocolVersion"].toUInt();
   if(ver < Quassel::buildInfo().clientNeedsProtocol) {
-    emit connectionError(tr("<b>The Quassel Core you are trying to connect to is too old!</b><br>"
+    emit connectionErrorPopup(tr("<b>The Quassel Core you are trying to connect to is too old!</b><br>"
         "Need at least core/client protocol v%1 to connect.").arg(Quassel::buildInfo().clientNeedsProtocol));
     disconnectFromCore();
     return;
@@ -382,8 +386,7 @@ void CoreConnection::clientInitAck(const QVariantMap &msg) {
         bool accepted = false;
         emit handleNoSslInCore(&accepted);
         if(!accepted) {
-          emit connectionError(tr("Unencrypted connection canceled"));
-          disconnectFromCore();
+          disconnectFromCore(tr("Unencrypted connection canceled"));
           return;
         }
         s.setAccountValue("ShowNoCoreSslWarning", false);
@@ -428,8 +431,7 @@ void CoreConnection::sslErrors() {
     emit handleSslErrors(socket, &accepted, &permanently);
 
     if(!accepted) {
-      emit connectionError(tr("Unencrypted connection canceled"));
-      disconnectFromCore();
+      disconnectFromCore(tr("Unencrypted connection canceled"));
       return;
     }
 
@@ -463,8 +465,7 @@ void CoreConnection::loginToCore(const QString &prevError) {
     bool valid = false;
     emit userAuthenticationRequired(&_account, &valid, prevError);  // *must* be a synchronous call
     if(!valid || currentAccount().user().isEmpty() || currentAccount().password().isEmpty()) {
-      disconnectFromCore();
-      emit connectionError(tr("Login canceled"));
+      disconnectFromCore(tr("Login canceled"));
       return;
     }
   }
index 2ef7d1a..5342636 100644 (file)
@@ -72,7 +72,7 @@ public:
 public slots:
   bool connectToCore(AccountId = 0);
   void reconnectToCore();
-  void disconnectFromCore();
+  void disconnectFromCore(const QString &errorString = QString());
 
 signals:
   void stateChanged(CoreConnection::ConnectionState);
@@ -80,6 +80,7 @@ signals:
   void synchronized();
 
   void connectionError(const QString &errorMsg);
+  void connectionErrorPopup(const QString &errorMsg);
   void connectionWarnings(const QStringList &warnings);
   void connectionMsg(const QString &msg);
   void disconnected();
index 0b5fe85..6312749 100644 (file)
@@ -160,6 +160,7 @@ void MainWin::init() {
            SLOT(messagesInserted(const QModelIndex &, int, int)));
   connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
   connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
+  connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
   connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
   connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool*)), SLOT(handleNoSslInClient(bool *)));
   connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool*)), SLOT(handleNoSslInCore(bool *)));
@@ -804,10 +805,6 @@ void MainWin::setDisconnectedState() {
   systemTray()->setState(SystemTray::Inactive);
 }
 
-void MainWin::startInternalCore() {
-
-}
-
 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
   Q_UNUSED(errorMessage)
   CoreConnectAuthDlg dlg(account, this);
@@ -872,6 +869,10 @@ void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *pe
 
 #endif /* HAVE_SSL */
 
+void MainWin::handleCoreConnectionError(const QString &error) {
+  QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
+}
+
 void MainWin::showCoreConnectionDlg() {
   CoreConnectDlg dlg(this);
   if(dlg.exec() == QDialog::Accepted) {
index 8c9c1ec..8caa8b3 100644 (file)
@@ -127,7 +127,7 @@ class MainWin
 #ifdef HAVE_KDE
     void showShortcutsDlg();
 #endif
-    void startInternalCore();
+    void handleCoreConnectionError(const QString &errorMsg);
     void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage);
     void handleNoSslInClient(bool *accepted);
     void handleNoSslInCore(bool *accepted);