changeset 526:b80d28f2f456

Grab server port from hgrc if present
author Chris Cannam
date Thu, 17 Nov 2011 17:35:02 +0000
parents 721a8e30822b
children 49bddabad719
files src/mainwindow.cpp
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/mainwindow.cpp	Thu Nov 17 17:12:39 2011 +0000
+++ b/src/mainwindow.cpp	Thu Nov 17 17:35:02 2011 +0000
@@ -1324,7 +1324,22 @@
         return;
     }
 
-    //!!! should find available port as well
+    // See #202. We really want to display the port that the server
+    // ends up using -- but we don't get that information until after
+    // it has exited!  However, we can improve the likelihood of
+    // showing the right port by at least checking whether a port is
+    // defined in the hgrc file.
+
+    QFileInfo hgrc(QDir::homePath() + "/.hgrc");
+    QString path;
+    int port = 8000; // the default
+    if (hgrc.exists()) {
+        QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
+        s.beginGroup("web");
+        if (s.contains("port")) {
+            port = s.value("port").toInt();
+        }
+    }
 
     QTextStream ts(&msg);
     ts << QString("<qt><h3>%1</h3><p>%2</p>")
@@ -1338,7 +1353,7 @@
             .arg(tr("Users who have network access to your computer can now clone your repository, by using the following URL as a remote location:"));
     }
     foreach (QString addr, addrs) {
-        ts << QString("<pre>&nbsp;&nbsp;http://%1:8000</pre>").arg(xmlEncode(addr));
+        ts << QString("<pre>&nbsp;&nbsp;http://%1:%2</pre>").arg(xmlEncode(addr)).arg(port);
     }
     ts << tr("<p>Press Close to terminate this server, end remote access, and return.</p>");
     ts.flush();