Display correct core timezone in core connection dialog
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 11 Sep 2009 15:41:37 +0000 (17:41 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 11 Sep 2009 15:41:37 +0000 (17:41 +0200)
For this to work, the CoreInfo string is generated client-side for now, from
the information new enough cores send. Older cores and/or clients will continue to
use the core-side generated string.

src/client/clientsyncer.cpp
src/client/clientsyncer.h
src/core/core.cpp
src/qtui/ui/coreconnectdlg.ui

index 64d909f..1af95b8 100644 (file)
@@ -197,7 +197,7 @@ void ClientSyncer::clientInitAck(const QVariantMap &msg) {
     disconnectFromCore();
     return;
   }
-  emit connectionMsg(msg["CoreInfo"].toString());
+  emit connectionMsg(coreInfoString(msg));
 
 #ifndef QT_NO_COMPRESS
   if(msg["SupportsCompression"].toBool()) {
@@ -345,6 +345,28 @@ void ClientSyncer::resetConnection() {
   numNetsToSync = 0;
 }
 
+QString ClientSyncer::coreInfoString(const QVariantMap &coreData) {
+  // check if we use a new enough core
+  // FIXME: this can go away after v11 protocol bump
+  if(!coreData.contains("CoreStartTime"))
+    return coreData.value("CoreInfo").toString();
+
+  QDateTime startTime = coreData.value("CoreStartTime").toDateTime().toLocalTime();
+  int uptime = startTime.secsTo(QDateTime::currentDateTime());
+  int updays = uptime / 86400; uptime %= 86400;
+  int uphours = uptime / 3600; uptime %= 3600;
+  int upmins = uptime / 60; uptime %= 60;
+
+  QString reply = tr("<b>Quassel Core Version %1</b><br>"
+                        "Built: %2<br>"
+                        "Up %3d%4h%5m (since %6)")
+  .arg(coreData.value("CoreVersion").toString())
+  .arg(coreData.value("CoreDate").toString())
+  .arg(updays).arg(uphours,2,10,QChar('0')).arg(upmins,2,10,QChar('0')).arg(startTime.toString(Qt::TextDate));
+
+  return reply;
+}
+
 #ifdef HAVE_SSL
 void ClientSyncer::ignoreSslWarnings(bool permanently) {
   QSslSocket *sock = qobject_cast<QSslSocket *>(_socket);
@@ -358,7 +380,7 @@ void ClientSyncer::ignoreSslWarnings(bool permanently) {
     else
       KnownHostsSettings().saveKnownHost(sock);
   }
-  emit connectionMsg(_coreMsgBuffer["CoreInfo"].toString());
+  emit connectionMsg(coreInfoString(_coreMsgBuffer));
   connectionReady();
 }
 
index aa8d786..8689279 100644 (file)
@@ -117,6 +117,8 @@ private:
 
   QSet<QObject *> netsToSync;
   int numNetsToSync;
+
+  QString coreInfoString(const QVariantMap &);
 };
 
 #endif
index b2e3ee4..ebe1b08 100644 (file)
@@ -509,10 +509,15 @@ void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) {
       socket->close(); return;
     }
 
+    reply["ProtocolVersion"] = Quassel::buildInfo().protocolVersion;
     reply["CoreVersion"] = Quassel::buildInfo().fancyVersionString;
     reply["CoreDate"] = Quassel::buildInfo().buildDate;
-    reply["ProtocolVersion"] = Quassel::buildInfo().protocolVersion;
-    // TODO: Make the core info configurable
+    reply["CoreStartTime"] = startTime(); // v10 clients don't necessarily parse this, see below
+
+    // FIXME: newer clients no longer use the hardcoded CoreInfo (for now), since it gets the
+    //        time zone wrong. With the next protocol bump (10 -> 11), we should remove this
+    //        or make it properly configurable.
+
     int uptime = startTime().secsTo(QDateTime::currentDateTime().toUTC());
     int updays = uptime / 86400; uptime %= 86400;
     int uphours = uptime / 3600; uptime %= 3600;
index 395c95a..f876bb7 100644 (file)
@@ -36,7 +36,7 @@
       </sizepolicy>
      </property>
      <property name="currentIndex">
-      <number>1</number>
+      <number>0</number>
      </property>
      <widget class="QWidget" name="accountPage">
       <layout class="QVBoxLayout">