changeset 28:90ffef5f0494

Another attempt to list hg serve ip addresses ;-)
author Jari Korhonen <jtkorhonen@gmail.com>
date Fri, 28 May 2010 22:34:44 +0300
parents 6e8cd5ffa4df
children fad897ed9894
files common.h mainwindow.cpp mainwindow.h
diffstat 3 files changed, 16 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/common.h	Thu May 20 23:03:49 2010 +0300
+++ b/common.h	Fri May 28 22:34:44 2010 +0300
@@ -6,7 +6,7 @@
 #include <QtCore>
 
 #define APPNAME                         "HgExplorer"
-#define APPVERSION                      "0.4.4"
+#define APPVERSION                      "0.4.5"
 #define MY_ICON_SIZE                    32
 #define REPOMENU_TITLE                  "Repository actions"
 #define WORKFOLDERMENU_TITLE            "Workfolder actions"
--- a/mainwindow.cpp	Thu May 20 23:03:49 2010 +0300
+++ b/mainwindow.cpp	Fri May 28 22:34:44 2010 +0300
@@ -548,57 +548,34 @@
 
 
 
-void MainWindow::listAllUpAddresses()
+QString MainWindow::listAllUpIpV4Addresses()
 {
+    QString ret;
     QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
 
     for (int i = 0; i < ifaces.count(); i++)
     {
         QNetworkInterface iface = ifaces.at(i);
 
-        QString msg;
-
-        QTextStream(&msg) <<  "name: " << iface.name() << endl << "mac: " << iface.hardwareAddress() << endl;
-        QMessageBox::information(this,  "interface", msg);
-
         if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack))
         {
-            // this loop is important
             for (int j=0; j<iface.addressEntries().count(); j++)
             {
-                QMessageBox::information(this, iface.name(), iface.addressEntries().at(j).ip().toString());
-            }
-        }
-    }
-}
-
-
-QString MainWindow::findMyIp()
-{
-    listAllUpAddresses();
-
-    QList <QHostAddress> ipList = QNetworkInterface::allAddresses();
-
-
-    if (!ipList.isEmpty())
-    {
-        for(int i = 0; i < ipList.size(); i++)
-        {
-            QHostAddress addr = ipList.at(i);
-
-            if (QAbstractSocket::IPv4Protocol == addr.protocol())
-            {
-                if (addr != QHostAddress::LocalHost)
+                QHostAddress tmp = iface.addressEntries().at(j).ip();
+                if (QAbstractSocket::IPv4Protocol == tmp.protocol())
                 {
-                    return addr.toString();
+                    if (!ret.isEmpty())
+                    {
+                        ret += " ";
+                    }
+                    ret += tmp.toString();
                 }
             }
         }
     }
+    return ret;
+}
 
-    //This won't help your teammate much but is funny ;-)
-    return "127.0.0.1";
-}
 
 void MainWindow::hgServe()
 {
@@ -607,9 +584,9 @@
         QStringList params;
         QString msg;
 
-        QString addr = findMyIp();
-        QTextStream(&msg) << "Server running on http://" << addr << ":8000/";
-        params << "serve" << "--address" << addr << "--port" << "8000";
+        QString addrs = listAllUpIpV4Addresses();
+        QTextStream(&msg) << "Server running on address(es) (" << addrs << "), port 8000";
+        params << "serve";
 
         runner -> startProc(getHgBinaryName(), workFolderPath, params, false);
         runningAction = ACT_SERVE;
--- a/mainwindow.h	Thu May 20 23:03:49 2010 +0300
+++ b/mainwindow.h	Fri May 28 22:34:44 2010 +0300
@@ -152,8 +152,7 @@
     bool areAllSelectedUntracked(QListWidget *workList);
     bool isSelectedDeletable(QListWidget *workList);
     bool areAllSelectedCommitable(QListWidget *workList);
-    QString findMyIp();
-    void listAllUpAddresses();
+    QString listAllUpIpV4Addresses();
 
 
     //Actions enabled flags