diff --git a/debugjob.h b/debugjob.h --- a/debugjob.h +++ b/debugjob.h @@ -79,6 +79,7 @@ protected: bool doKill() override; + void launchBrowser(QUrl &url); private slots: void sessionFinished(); diff --git a/debugjob.cpp b/debugjob.cpp --- a/debugjob.cpp +++ b/debugjob.cpp @@ -207,6 +207,7 @@ setError(-1); setErrorText(err); emitResult(); + m_session->stopDebugger(); return; } @@ -219,6 +220,7 @@ qCWarning(KDEV_PHP_DEBUGGER) << "No process, something went wrong when creating the job"; // No process means we've returned early on from the constructor, some bad error happened emitResult(); + m_session->stopDebugger(); } } @@ -252,10 +254,6 @@ } qCDebug(KDEV_PHP_DEBUGGER) << "Process done"; emitResult(); - - if (m_session && m_session->connection()) { - m_session->connection()->setState(DebugSession::EndedState); - } } void XDebugJob::processError(QProcess::ProcessError error) @@ -265,18 +263,10 @@ QString errmsg = i18n("Could not start program '%1'. Make sure that the " "path is specified correctly.", m_proc->property("executable").toString()); setErrorText(errmsg); + m_session->stopDebugger(); emitResult(); } qCDebug(KDEV_PHP_DEBUGGER) << "Process error"; - - if (m_session && m_session->connection()) { - m_session->connection()->setState(DebugSession::EndedState); - } - else if(m_session) - { - m_session->stateChanged(DebugSession::EndedState); - m_session->stopDebugger(); - } } void XDebugJob::appendLine(const QString& l) @@ -336,25 +326,14 @@ setError(-1); setErrorText(err); emitResult(); + m_session->stopDebugger(); return; } QUrl url = m_url; url.setQuery("XDEBUG_SESSION_START=kdev"); - if (m_browser.isEmpty()) { - if (!QDesktopServices::openUrl(url)) { - qCWarning(KDEV_PHP_DEBUGGER) << "openUrl failed, something went wrong when creating the job"; - emitResult(); - } - } else { - KProcess proc(this); - proc.setProgram(QStringList() << m_browser << url.url()); - if( !proc.startDetached() ) - { - processFailedToStart(); - } - } + launchBrowser(url); } @@ -367,14 +346,26 @@ setErrorText(errmsg); emitResult(); qCDebug(KDEV_PHP_DEBUGGER) << "Process error"; + m_session->stopDebugger(); +} - if (m_session && m_session->connection()) { - m_session->connection()->setState(DebugSession::EndedState); - } - else if(m_session) - { - m_session->stateChanged(DebugSession::EndedState); - m_session->stopDebugger(); + +void XDebugBrowserJob::launchBrowser(QUrl &url) +{ + if (m_browser.isEmpty()) { + if (!QDesktopServices::openUrl(url)) { + qCWarning(KDEV_PHP_DEBUGGER) << "openUrl failed, something went wrong when creating the job"; + emitResult(); + m_session->stopDebugger(); + } + } else { + KProcess proc(this); + + proc.setProgram(QStringList() << m_browser << url.url()); + if( !proc.startDetached() ) + { + processFailedToStart(); + } } } @@ -384,7 +375,7 @@ m_session->stopDebugger(); QUrl url = m_url; url.setQuery("XDEBUG_SESSION_STOP_NO_EXEC=kdev"); - QDesktopServices::openUrl(url); + launchBrowser(url); return true; } diff --git a/debugsession.cpp b/debugsession.cpp --- a/debugsession.cpp +++ b/debugsession.cpp @@ -75,6 +75,8 @@ int remotePortSetting = m_launchConfiguration->config().readEntry("RemotePort", 9000); if (m_server->listen(QHostAddress::Any, remotePortSetting)) { connect(m_server, &QTcpServer::newConnection, this, &DebugSession::incomingConnection); + // avoid 'debug launch' button + stateChanged(ActiveState); } else { error = i18n("Opening port %1 failed: %2.", remotePortSetting, m_server->errorString()); qCWarning(KDEV_PHP_DEBUGGER) << "Error" << m_server->errorString(); @@ -123,9 +125,11 @@ Q_ASSERT(sender() == m_connection); if (m_acceptMultipleConnections && m_server && m_server->isListening() - && m_server->hasPendingConnections() ) { - m_connection->setState(DebugSession::NotStartedState); + // clear variable widget + emit stateChanged(NotStartedState); + // avoid 'debug launch' button + emit stateChanged(ActiveState); } else { m_connection->setState(DebugSession::EndedState); } @@ -207,7 +211,9 @@ void DebugSession::stopDebugger() { closeServer(); - if (!m_connection || m_connection->currentState() == DebugSession::StoppedState || !m_connection->socket()) { + // finish debugger when no connection active + if ( state() == DebugSession::NotStartedState && !m_connection ) { + stateChanged(DebugSession::EndedState); emit finished(); } else { m_connection->sendCommand("stop"); diff --git a/tests/connectiontest.cpp b/tests/connectiontest.cpp --- a/tests/connectiontest.cpp +++ b/tests/connectiontest.cpp @@ -939,18 +939,11 @@ QTest::qWait(1000); - // FIXME: Is this being handled correctly? - QVERIFY(!session); - return; - QVERIFY(session->connection() != firstConnection); //must be a different connection session->connection()->close(); //close second connection QTest::qWait(1000); -// firstConnection->close(); //close first connection _after_ second - - QTest::qWait(1000); QCOMPARE(session->state(), DebugSession::NotStartedState); //well, it should be EndedState in reality, but this works too //job seems to gets deleted automatically