#2 Show a "not connected" message in the DCC Chat window if there is no connection while typing a message.

master
Tomatix 3 years ago
parent 523e21d3db
commit 60768be2ce
  1. 6
      IRCClient/DCC.cpp
  2. 2
      IRCClient/DCC.h
  3. 19
      IWin/IWinDCCChat.cpp

@ -59,6 +59,7 @@ struct DCCPriv
void disconnected(const asio::error_code& ec)
{
socket.close();
super.onDisconnected(SystemErrorToIRCError(ec));
}
@ -176,6 +177,11 @@ const IRCBase& DCC::context() const
return mp->ircctx;
}
bool DCC::isConnected() const
{
return mp->socket.is_open();
}
void DCC::setCallbackRead(DCC::CallbackRead&& cb)
{
mp->cbRead = std::move(cb);

@ -58,6 +58,8 @@ public:
IRCBase& context();
const IRCBase& context() const;
bool isConnected() const;
/*
* Callbacks used by 'users' of this class.
*/

@ -80,13 +80,18 @@ void IWinDCCChat::onDisconnected(IRCError e)
void IWinDCCChat::newLine(const QString& line)
{
const auto nickname{ QString::fromStdString(dcc->context().getNickname()) };
print(PrintType::OwnText, tr("<%1> %2").arg(nickname, line));
auto data = DCC::stringToByteString(line.toStdString());
data.push_back(std::byte('\r'));
data.push_back(std::byte('\n'));
dcc->write(data);
if (dcc->isConnected()) {
const auto nickname{ QString::fromStdString(dcc->context().getNickname()) };
print(PrintType::OwnText, tr("<%1> %2").arg(nickname, line));
auto data = DCC::stringToByteString(line.toStdString());
data.push_back(std::byte('\r'));
data.push_back(std::byte('\n'));
dcc->write(data);
}
else {
print(PrintType::ProgramInfo, tr("Not connected with remote peer"));
}
}
void IWinDCCChat::onRead(const DCC::ByteString& data, std::size_t length)

Loading…
Cancel
Save