Reconnect on unexpected disconnection

master
Tomatix 5 years ago
parent c98844fd30
commit ee13cb15dc
  1. 2
      IConfig/IConfig.cpp
  2. 15
      IdealIRC/IRC.cpp
  3. 20
      IdealIRC/IRC.h
  4. 7
      IdealIRC/IdealIRC.cpp

@ -138,6 +138,8 @@ void IConfig::on_btnSaveConnect_clicked()
return;
}
if (!servers->connectToNewStatus())
emit disconnectFromServer();
emit connectToServer(servers->connectToNewStatus());
servers->unsetConnectToNewStatus();
close();

@ -97,11 +97,10 @@ void IRC::rejoinChannels()
void IRC::onRegistered()
{
const auto& config = ConfigMgr::instance();
emit registered();
if (config.common("RejoinChannelsOnConnect") == "1")
m_expectDisconnect = false;
emit registered();
const auto& config = ConfigMgr::instance();
if (config.common("RejoinChannelsOnConnect") == "1")
rejoinChannels();
contextualScriptEvent(&m_status, ScriptEvent::Connected);
@ -128,6 +127,12 @@ void IRC::onDisconnected()
if (m_disconnectForExit)
emit readyForExit();
contextualScriptEvent(&m_status, ScriptEvent::Disconnected);
auto& conf = ConfigMgr::instance();
bool reconnect = conf.common("Reconnect").toInt();
if (reconnect && !m_expectDisconnect)
tryConnect();
m_expectDisconnect = false;
}
void IRC::onConnectionError(IRCError e)

@ -25,23 +25,8 @@ public:
void setIgnoreVerbosity(const QStringList& commandsAndNumerics);
void unsetIgnoreVerbosity(const QStringList& commandsAndNumerics);
void expectDisconnect()
{
/*
m_expectDisconnect = true;
expectDisconnectTimer.singleShot(10000, [this]{
m_expectDisconnect = false;
});
*/
}
void dontExpectDisconnect()
{
/*
m_expectDisconnect = false;
expectDisconnectTimer.stop();
*/
}
void expectDisconnect() { m_expectDisconnect = true; }
void dontExpectDisconnect() { m_expectDisconnect = false; }
signals:
void readyForExit();
@ -58,6 +43,7 @@ signals:
private:
bool m_disconnectForExit{ false };
bool m_expectDisconnect{ false };
IWinStatus& m_status;
int m_id; //! Used mainly for scripts
bool m_receiveWhoisToCurrentWindow{ false };

@ -71,7 +71,7 @@ IdealIRC::IdealIRC(QWidget* parent)
statusw->refreshWindowTitle();
ScriptManager::init(mdiManager, this);
QTimer::singleShot(10, std::bind(&IdealIRC::startup, this));
QTimer::singleShot(10, [this]{ startup(); });
}
IdealIRC::~IdealIRC()
@ -284,7 +284,9 @@ void IdealIRC::connectToServer(bool newStatus)
void IdealIRC::disconnectFromServer()
{
IWinStatus* status = mdiManager->currentStatus();
if (status->getConnection().disconnectFromServer() == IRCError::NotConnected)
auto& connection = status->getConnection();
connection.expectDisconnect();
if (connection.disconnectFromServer() == IRCError::NotConnected)
qWarning() << "Trying to disconnect from an already closed connection.";
}
@ -300,6 +302,7 @@ void IdealIRC::on_actionConnect_triggered()
if (!connection.isOnline())
setConnectButtonState(ConnectButtonState::Connect);
connection.expectDisconnect();
auto e = connection.disconnectFromServer(conf.common("QuitMessage").toStdString());
if (e == IRCError::NotConnected)
qWarning() << "Trying to disconnect from an already closed connection.";

Loading…
Cancel
Save