# HG changeset patch # User Chris Cannam # Date 1321551302 0 # Node ID b80d28f2f456ad35223cad4ca1b9279bf8edd720 # Parent 721a8e30822b6b79071d6d47070d6ec113d2e33e Grab server port from hgrc if present diff -r 721a8e30822b -r b80d28f2f456 src/mainwindow.cpp --- 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("

%1

%2

") @@ -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("
  http://%1:8000
").arg(xmlEncode(addr)); + ts << QString("
  http://%1:%2
").arg(xmlEncode(addr)).arg(port); } ts << tr("

Press Close to terminate this server, end remote access, and return.

"); ts.flush();