comparison src/mainwindow.cpp @ 526:b80d28f2f456

Grab server port from hgrc if present
author Chris Cannam
date Thu, 17 Nov 2011 17:35:02 +0000
parents b5a342a71218
children 49bddabad719
comparison
equal deleted inserted replaced
525:721a8e30822b 526:b80d28f2f456
1322 QMessageBox::critical 1322 QMessageBox::critical
1323 (this, tr("Serve"), tr("Failed to identify an active IPv4 address")); 1323 (this, tr("Serve"), tr("Failed to identify an active IPv4 address"));
1324 return; 1324 return;
1325 } 1325 }
1326 1326
1327 //!!! should find available port as well 1327 // See #202. We really want to display the port that the server
1328 // ends up using -- but we don't get that information until after
1329 // it has exited! However, we can improve the likelihood of
1330 // showing the right port by at least checking whether a port is
1331 // defined in the hgrc file.
1332
1333 QFileInfo hgrc(QDir::homePath() + "/.hgrc");
1334 QString path;
1335 int port = 8000; // the default
1336 if (hgrc.exists()) {
1337 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
1338 s.beginGroup("web");
1339 if (s.contains("port")) {
1340 port = s.value("port").toInt();
1341 }
1342 }
1328 1343
1329 QTextStream ts(&msg); 1344 QTextStream ts(&msg);
1330 ts << QString("<qt><h3>%1</h3><p>%2</p>") 1345 ts << QString("<qt><h3>%1</h3><p>%2</p>")
1331 .arg(tr("Sharing Repository")) 1346 .arg(tr("Sharing Repository"))
1332 .arg(tr("Your local repository is now being made temporarily available via HTTP for workgroup access.")); 1347 .arg(tr("Your local repository is now being made temporarily available via HTTP for workgroup access."));
1336 } else { 1351 } else {
1337 ts << QString("<p>%3</p>") 1352 ts << QString("<p>%3</p>")
1338 .arg(tr("Users who have network access to your computer can now clone your repository, by using the following URL as a remote location:")); 1353 .arg(tr("Users who have network access to your computer can now clone your repository, by using the following URL as a remote location:"));
1339 } 1354 }
1340 foreach (QString addr, addrs) { 1355 foreach (QString addr, addrs) {
1341 ts << QString("<pre>&nbsp;&nbsp;http://%1:8000</pre>").arg(xmlEncode(addr)); 1356 ts << QString("<pre>&nbsp;&nbsp;http://%1:%2</pre>").arg(xmlEncode(addr)).arg(port);
1342 } 1357 }
1343 ts << tr("<p>Press Close to terminate this server, end remote access, and return.</p>"); 1358 ts << tr("<p>Press Close to terminate this server, end remote access, and return.</p>");
1344 ts.flush(); 1359 ts.flush();
1345 1360
1346 params << "serve"; 1361 params << "serve";