Mercurial > hg > easyhg
changeset 24:bb93f0593aeb
Fixed findMyIp().
author | Jari Korhonen <jtkorhonen@gmail.com> |
---|---|
date | Wed, 19 May 2010 22:57:05 +0300 |
parents | 16be237acf13 |
children | eba979148fb3 ee34bd26751e |
files | mainwindow.cpp mainwindow.h |
diffstat | 2 files changed, 21 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- 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 <QtGui> #include <QStringList> #include <QDir> +#include <QNetworkInterface> #include <QHostAddress> #include <QHostInfo> @@ -546,36 +547,31 @@ } -QString MainWindow::findMyIp(bool& isAddrIpV6) +QString MainWindow::findMyIp() { - QString ret; - QHostInfo info = QHostInfo::fromName(QHostInfo::localHostName()); - QList <QHostAddress> ipList = info.addresses(); + QString ipAddr; + + QList <QHostAddress> 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;
--- 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