comparison mainwindow.cpp @ 22:465fbf9ad5a9

Tries to show hg serve ipv6 address correctly (at least for browser, dont know about hg itself).
author Jari Korhonen <jtkorhonen@gmail.com>
date Tue, 18 May 2010 23:56:20 +0300
parents 36e03b1f719e
children bb93f0593aeb
comparison
equal deleted inserted replaced
21:799cfade2cb3 22:465fbf9ad5a9
544 runningAction = ACT_PUSH; 544 runningAction = ACT_PUSH;
545 } 545 }
546 } 546 }
547 547
548 548
549 QString MainWindow::findMyIps() 549 QString MainWindow::findMyIp(bool& isAddrIpV6)
550 { 550 {
551 QString ret; 551 QString ret;
552 QHostInfo info = QHostInfo::fromName(QHostInfo::localHostName()); 552 QHostInfo info = QHostInfo::fromName(QHostInfo::localHostName());
553 QList <QHostAddress> ipList = info.addresses(); 553 QList <QHostAddress> ipList = info.addresses();
554 554
555
555 if (!ipList.isEmpty()) 556 if (!ipList.isEmpty())
556 { 557 {
557 QHostAddress addr = ipList.at(0); 558 QHostAddress addr = ipList.at(0);
559
560 if (QAbstractSocket::IPv6Protocol == addr.protocol())
561 {
562 isAddrIpV6 = true;
563 }
564 else
565 {
566 isAddrIpV6 = false;
567 }
568
558 ret = addr.toString(); 569 ret = addr.toString();
559 } 570 }
560 else 571 else
561 { 572 {
562 ret = "unknown"; 573 //This won't help your teammate much, but is funny ;-)
574 ret = "127.0.0.1";
575 isAddrIpV6 = false;
563 } 576 }
564 577
565 return ret; 578 return ret;
566 } 579 }
567 580
568 void MainWindow::hgServe() 581 void MainWindow::hgServe()
569 { 582 {
570 if (runningAction == ACT_NONE) 583 if (runningAction == ACT_NONE)
571 { 584 {
572 QStringList params; 585 QStringList params;
573 586 QString msg;
574 params << "serve"; 587 bool isIpv6;
588
589 QString addr = findMyIp(isIpv6);
590 if (isIpv6)
591 {
592 QTextStream(&msg) << "Server running on http://[" << addr << "]:8000/";
593 params << "serve" << "--ipv6";
594 }
595 else
596 {
597 QTextStream(&msg) << "Server running on http://" << addr << ":8000/";
598 params << "serve";
599 }
575 600
576 runner -> startProc(getHgBinaryName(), workFolderPath, params, false); 601 runner -> startProc(getHgBinaryName(), workFolderPath, params, false);
577 runningAction = ACT_SERVE; 602 runningAction = ACT_SERVE;
578 603
579 QString msg;
580
581 QTextStream(&msg) << "Server running on http://" << findMyIps() << ":8000/";
582 QMessageBox::information(this, "Serve", msg, QMessageBox::Close); 604 QMessageBox::information(this, "Serve", msg, QMessageBox::Close);
583 runner -> killProc(); 605 runner -> killProc();
584 } 606 }
585 } 607 }
586 608