diff mainwindow.cpp @ 22:465fbf9ad5a9

Tries to show hg serve ipv6 address correctly (at least for browser, dont know about hg itself).
author Jari Korhonen <jtkorhonen@gmail.com>
date Tue, 18 May 2010 23:56:20 +0300
parents 36e03b1f719e
children bb93f0593aeb
line wrap: on
line diff
--- a/mainwindow.cpp	Tue May 18 01:56:40 2010 +0300
+++ b/mainwindow.cpp	Tue May 18 23:56:20 2010 +0300
@@ -546,20 +546,33 @@
 }
 
 
-QString MainWindow::findMyIps()
+QString MainWindow::findMyIp(bool& isAddrIpV6)
 {
     QString ret;
     QHostInfo info = QHostInfo::fromName(QHostInfo::localHostName());
     QList <QHostAddress> ipList = info.addresses();
 
+
     if (!ipList.isEmpty())
     {
         QHostAddress addr = ipList.at(0);
+
+        if (QAbstractSocket::IPv6Protocol == addr.protocol())
+        {
+            isAddrIpV6 = true;
+        }
+        else
+        {
+            isAddrIpV6 = false;
+        }
+
         ret = addr.toString();
     }
     else
     {
-        ret = "unknown";
+        //This won't help your teammate much, but is funny ;-)
+        ret = "127.0.0.1";
+        isAddrIpV6 = false;
     }
 
     return ret;
@@ -570,15 +583,24 @@
     if (runningAction == ACT_NONE)
     {
         QStringList params;
+        QString msg;
+        bool isIpv6;
 
-        params << "serve";
+        QString addr = findMyIp(isIpv6);
+        if (isIpv6)
+        {
+            QTextStream(&msg) << "Server running on http://[" << addr << "]:8000/";
+            params << "serve" << "--ipv6";
+        }
+        else
+        {
+            QTextStream(&msg) << "Server running on http://" << addr << ":8000/";
+            params << "serve";
+        }
 
         runner -> startProc(getHgBinaryName(), workFolderPath, params, false);
         runningAction = ACT_SERVE;
 
-        QString msg;
-
-        QTextStream(&msg) << "Server running on http://" << findMyIps() << ":8000/";
         QMessageBox::information(this, "Serve", msg, QMessageBox::Close);
         runner -> killProc();
     }