# HG changeset patch # User Jari Korhonen # Date 1274299025 -10800 # Node ID bb93f0593aeb6a3f0fa1d5f4defdf35256f99f3d # Parent 16be237acf13b9839cf3afaccbf8bdf494102b1a Fixed findMyIp(). diff -r 16be237acf13 -r bb93f0593aeb mainwindow.cpp --- a/mainwindow.cpp Tue May 18 23:56:55 2010 +0300 +++ b/mainwindow.cpp Wed May 19 22:57:05 2010 +0300 @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -546,36 +547,31 @@ } -QString MainWindow::findMyIp(bool& isAddrIpV6) +QString MainWindow::findMyIp() { - QString ret; - QHostInfo info = QHostInfo::fromName(QHostInfo::localHostName()); - QList ipList = info.addresses(); + QString ipAddr; + + QList ipList = QNetworkInterface::allAddresses(); if (!ipList.isEmpty()) { - QHostAddress addr = ipList.at(0); + for(int i = 0; i < ipList.size(); i++) + { + QHostAddress addr = ipList.at(i); - if (QAbstractSocket::IPv6Protocol == addr.protocol()) - { - isAddrIpV6 = true; + if (QAbstractSocket::IPv4Protocol == addr.protocol()) + { + if (addr != QHostAddress::LocalHost) + { + return addr.toString(); + } + } } - else - { - isAddrIpV6 = false; - } - - ret = addr.toString(); - } - else - { - //This won't help your teammate much, but is funny ;-) - ret = "127.0.0.1"; - isAddrIpV6 = false; } - return ret; + //This won't help your teammate much but is funny ;-) + return "127.0.0.1"; } void MainWindow::hgServe() @@ -584,19 +580,10 @@ { QStringList params; QString msg; - bool isIpv6; - 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"; - } + QString addr = findMyIp(); + QTextStream(&msg) << "Server running on http://" << addr << ":8000/"; + params << "serve"; runner -> startProc(getHgBinaryName(), workFolderPath, params, false); runningAction = ACT_SERVE; diff -r 16be237acf13 -r bb93f0593aeb mainwindow.h --- a/mainwindow.h Tue May 18 23:56:55 2010 +0300 +++ b/mainwindow.h Wed May 19 22:57:05 2010 +0300 @@ -152,7 +152,7 @@ bool areAllSelectedUntracked(QListWidget *workList); bool isSelectedDeletable(QListWidget *workList); bool areAllSelectedCommitable(QListWidget *workList); - QString findMyIp(bool& isIpV6); + QString findMyIp(); //Actions enabled flags