Browse Source

auto select web preview port

cl-refactor
arkpar 10 years ago
parent
commit
0d45dfabe1
  1. 13
      mix/HttpServer.cpp
  2. 2
      mix/HttpServer.h
  3. 2
      mix/qml/WebPreview.qml

13
mix/HttpServer.cpp

@ -21,6 +21,7 @@
*/ */
#include <memory> #include <memory>
#include <random>
#include <QTcpSocket> #include <QTcpSocket>
#include "HttpServer.h" #include "HttpServer.h"
@ -106,8 +107,18 @@ void HttpServer::updateListening()
if (this->isListening()) if (this->isListening())
this->close(); this->close();
if (!m_listen || QTcpServer::listen(QHostAddress::LocalHost, m_port)) if (!m_listen)
return; return;
if (!QTcpServer::listen(QHostAddress::LocalHost, m_port))
errorStringChanged();
if (m_port != QTcpServer::serverPort())
{
m_port = QTcpServer::serverPort();
emit portChanged(m_port);
emit urlChanged(url());
}
} }
void HttpServer::incomingConnection(qintptr _socket) void HttpServer::incomingConnection(qintptr _socket)

2
mix/HttpServer.h

@ -100,7 +100,7 @@ protected:
signals: signals:
void clientConnected(HttpRequest* _request); void clientConnected(HttpRequest* _request);
void errorStringChanged(QString const& _errorString); void errorStringChanged();
void urlChanged(QUrl const& _url); void urlChanged(QUrl const& _url);
void portChanged(int _port); void portChanged(int _port);
void listenChanged(bool _listen); void listenChanged(bool _listen);

2
mix/qml/WebPreview.qml

@ -150,7 +150,7 @@ Item {
id: httpServer id: httpServer
listen: true listen: true
accept: true accept: true
port: 8893 //port: 8893
onClientConnected: { onClientConnected: {
var urlPath = _request.url.toString(); var urlPath = _request.url.toString();
if (urlPath.indexOf("/rpc/") === 0) if (urlPath.indexOf("/rpc/") === 0)

Loading…
Cancel
Save