From 72d23cc04e32bfc166720f9b7ecaf4f53e63ec5e Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Thu, 5 Jun 2008 14:49:52 +0200 Subject: [PATCH] Quassel now uses proper default messages for part, quit, kick and away (/away toggles now between away and unaway state) --- src/core/coresession.cpp | 8 +- src/core/networkconnection.cpp | 29 ++- src/core/networkconnection.h | 6 + src/core/userinputhandler.cpp | 41 ++++- .../settingspages/identitiessettingspage.ui | 173 +++++++++--------- src/uisupport/bufferview.cpp | 2 +- 6 files changed, 155 insertions(+), 104 deletions(-) diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 68f31271..4b471213 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -23,6 +23,7 @@ #include "core.h" #include "coresession.h" #include "networkconnection.h" +#include "userinputhandler.h" #include "signalproxy.h" #include "buffersyncer.h" @@ -205,8 +206,11 @@ void CoreSession::attachNetworkConnection(NetworkConnection *conn) { } void CoreSession::disconnectFromNetwork(NetworkId id) { - if(!_connections.contains(id)) return; - _connections[id]->disconnectFromIrc(); + if(!_connections.contains(id)) + return; + + //_connections[id]->disconnectFromIrc(); + _connections[id]->userInputHandler()->handleQuit(BufferInfo(), QString()); } void CoreSession::networkStateRequested() { diff --git a/src/core/networkconnection.cpp b/src/core/networkconnection.cpp index 530ee32b..3d9fcc73 100644 --- a/src/core/networkconnection.cpp +++ b/src/core/networkconnection.cpp @@ -45,6 +45,7 @@ NetworkConnection::NetworkConnection(Network *network, CoreSession *session) _userInputHandler(new UserInputHandler(this)), _ctcpHandler(new CtcpHandler(this)), _autoReconnectCount(0), + _quitRequested(false), _previousConnectionAttemptFailed(false), _lastUsedServerlistIndex(0), @@ -54,7 +55,7 @@ NetworkConnection::NetworkConnection(Network *network, CoreSession *session) _autoWhoInterval(90), _autoWhoNickLimit(0), // unlimited _autoWhoDelay(3), - + // TokenBucket to avaid sending too much at once _messagesPerSecond(1), _burstSize(5), @@ -66,14 +67,13 @@ NetworkConnection::NetworkConnection(Network *network, CoreSession *session) _maxMsgSize(450) { _autoReconnectTimer.setSingleShot(true); - + _socketCloseTimer.setSingleShot(true); + connect(&_socketCloseTimer, SIGNAL(timeout()), this, SLOT(socketCloseTimeout())); + _autoWhoTimer.setInterval(_autoWhoDelay * 1000); - _autoWhoTimer.setSingleShot(false); _autoWhoCycleTimer.setInterval(_autoWhoInterval * 1000); - _autoWhoCycleTimer.setSingleShot(false); - + _tokenBucketTimer.start(_messagesPerSecond * 1000); - _tokenBucketTimer.setSingleShot(false); QHash channels = coreSession()->persistentChannels(networkId()); foreach(QString chan, channels.keys()) { @@ -260,12 +260,13 @@ void NetworkConnection::disconnectFromIrc(bool requested) { setConnectionState(Network::Disconnected); socketDisconnected(); } else { - socket.disconnectFromHost(); + _socketCloseTimer.start(10000); // the irc server has 10 seconds to close the socket } - if(requested) { - emit quitRequested(networkId()); - } + // this flag triggers quitRequested() once the socket is closed + // it is needed to determine whether or not the connection needs to be + // in the automatic session restore. + _quitRequested = requested; } void NetworkConnection::socketHasData() { @@ -369,18 +370,26 @@ void NetworkConnection::socketStateChanged(QAbstractSocket::SocketState socketSt setConnectionState(state); } +void NetworkConnection::socketCloseTimeout() { + socket.disconnectFromHost(); +} + void NetworkConnection::socketDisconnected() { _autoWhoCycleTimer.stop(); _autoWhoTimer.stop(); _autoWhoQueue.clear(); _autoWhoInProgress.clear(); + _socketCloseTimer.stop(); + network()->setConnected(false); emit disconnected(networkId()); if(_autoReconnectCount != 0) { setConnectionState(Network::Reconnecting); if(_autoReconnectCount == network()->autoReconnectRetries()) doAutoReconnect(); // first try is immediate else _autoReconnectTimer.start(); + } else if(_quitRequested) { + emit quitRequested(networkId()); } } diff --git a/src/core/networkconnection.h b/src/core/networkconnection.h index 8654bd85..16bfccc4 100644 --- a/src/core/networkconnection.h +++ b/src/core/networkconnection.h @@ -130,6 +130,7 @@ private slots: void socketError(QAbstractSocket::SocketError); void socketConnected(); void socketInitialized(); + void socketCloseTimeout(); void socketDisconnected(); void socketStateChanged(QAbstractSocket::SocketState); void setConnectionState(Network::ConnectionState); @@ -169,8 +170,13 @@ private: QHash _channelKeys; // stores persistent channels and their passwords, if any QTimer _autoReconnectTimer; + int _autoReconnectCount; + QTimer _socketCloseTimer; + + bool _quitRequested; + bool _previousConnectionAttemptFailed; int _lastUsedServerlistIndex; diff --git a/src/core/userinputhandler.cpp b/src/core/userinputhandler.cpp index 9c7e03ba..550e1682 100644 --- a/src/core/userinputhandler.cpp +++ b/src/core/userinputhandler.cpp @@ -55,7 +55,16 @@ void UserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QStri void UserInputHandler::handleAway(const BufferInfo &bufferInfo, const QString &msg) { Q_UNUSED(bufferInfo) - putCmd("AWAY", serverEncode(msg)); + + QString awayMsg; + // if there is no message supplied we have to check if we are already away or not + if(msg.isEmpty()) { + IrcUser *me = network()->me(); + if(me && !me->isAway()) + awayMsg = networkConnection()->identity()->awayReason(); + } + + putCmd("AWAY", serverEncode(awayMsg)); } void UserInputHandler::handleBan(const BufferInfo &bufferInfo, const QString &msg) { @@ -161,7 +170,9 @@ void UserInputHandler::handleJoin(const BufferInfo &bufferInfo, const QString &m void UserInputHandler::handleKick(const BufferInfo &bufferInfo, const QString &msg) { QString nick = msg.section(' ', 0, 0, QString::SectionSkipEmpty); QString reason = msg.section(' ', 1, -1, QString::SectionSkipEmpty).trimmed(); - if(reason.isEmpty()) reason = networkConnection()->identity()->kickReason(); + if(reason.isEmpty()) + reason = networkConnection()->identity()->kickReason(); + QList params; params << serverEncode(bufferInfo.bufferName()) << serverEncode(nick) << channelEncode(bufferInfo.bufferName(), reason); emit putCmd("KICK", params); @@ -229,7 +240,21 @@ void UserInputHandler::handleOper(const BufferInfo &bufferInfo, const QString &m void UserInputHandler::handlePart(const BufferInfo &bufferInfo, const QString &msg) { QList params; - params << serverEncode(bufferInfo.bufferName()) << channelEncode(bufferInfo.bufferName(), msg); + QString partReason; + + // msg might contain either a channel name and/or a reaon, so we have to check if the first word is a known channel + QString channelName = msg.section(' ', 0, 0); + if(channelName.isEmpty() || !network()->ircChannel(channelName)) { + channelName = bufferInfo.bufferName(); + partReason = msg; + } else { + partReason = msg.mid(channelName.length() + 1); + } + + if(partReason.isEmpty()) + partReason = networkConnection()->identity()->partReason(); + + params << serverEncode(channelName) << channelEncode(bufferInfo.bufferName(), partReason); emit putCmd("PART", params); } @@ -247,7 +272,15 @@ void UserInputHandler::handleQuery(const BufferInfo &bufferInfo, const QString & void UserInputHandler::handleQuit(const BufferInfo &bufferInfo, const QString &msg) { Q_UNUSED(bufferInfo) - emit putCmd("QUIT", serverEncode(msg)); + + QString quitReason; + if(msg.isEmpty()) + quitReason = networkConnection()->identity()->quitReason(); + else + quitReason = msg; + + emit putCmd("QUIT", serverEncode(quitReason)); + networkConnection()->disconnectFromIrc(); } void UserInputHandler::handleQuote(const BufferInfo &bufferInfo, const QString &msg) { diff --git a/src/qtui/settingspages/identitiessettingspage.ui b/src/qtui/settingspages/identitiessettingspage.ui index a5fd9d16..3dfcb645 100644 --- a/src/qtui/settingspages/identitiessettingspage.ui +++ b/src/qtui/settingspages/identitiessettingspage.ui @@ -36,7 +36,8 @@ ... - :/22x22/actions/oxygen/22x22/actions/edit-rename.png + + :/22x22/actions/oxygen/22x22/actions/edit-rename.png:/22x22/actions/oxygen/22x22/actions/edit-rename.png @@ -55,7 +56,8 @@ Add... - :/22x22/actions/oxygen/22x22/actions/list-add-user.png + + :/22x22/actions/oxygen/22x22/actions/list-add-user.png:/22x22/actions/oxygen/22x22/actions/list-add-user.png @@ -77,7 +79,8 @@ ... - :/22x22/actions/oxygen/22x22/actions/list-remove-user.png + + :/22x22/actions/oxygen/22x22/actions/list-remove-user.png:/22x22/actions/oxygen/22x22/actions/list-remove-user.png @@ -92,9 +95,17 @@ - 0 + 2 + + + 0 + 0 + 463 + 314 + + General @@ -162,7 +173,8 @@ &Add... - :/16x16/actions/oxygen/16x16/actions/list-add.png + + :/16x16/actions/oxygen/16x16/actions/list-add.png:/16x16/actions/oxygen/16x16/actions/list-add.png @@ -187,7 +199,8 @@ Remove - :/16x16/actions/oxygen/16x16/actions/edit-delete.png + + :/16x16/actions/oxygen/16x16/actions/edit-delete.png:/16x16/actions/oxygen/16x16/actions/edit-delete.png @@ -206,7 +219,8 @@ Re&name... - :/16x16/actions/oxygen/16x16/actions/edit-rename.png + + :/16x16/actions/oxygen/16x16/actions/edit-rename.png:/16x16/actions/oxygen/16x16/actions/edit-rename.png @@ -215,16 +229,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -232,7 +237,7 @@ Qt::Horizontal - + 0 20 @@ -249,7 +254,8 @@ ... - :/16x16/actions/oxygen/16x16/actions/go-up.png + + :/16x16/actions/oxygen/16x16/actions/go-up.png:/16x16/actions/oxygen/16x16/actions/go-up.png @@ -262,7 +268,8 @@ ... - :/16x16/actions/oxygen/16x16/actions/go-down.png + + :/16x16/actions/oxygen/16x16/actions/go-down.png:/16x16/actions/oxygen/16x16/actions/go-down.png @@ -271,7 +278,7 @@ Qt::Horizontal - + 0 20 @@ -286,7 +293,7 @@ Qt::Vertical - + 124 76 @@ -302,28 +309,24 @@ + + + 0 + 0 + 100 + 30 + + A&way - - 0 - - - 0 - - - 0 - - + 0 - - 6 - - + 6 @@ -385,16 +388,7 @@ 6 - - 8 - - - 8 - - - 8 - - + 8 @@ -402,16 +396,7 @@ 6 - - 0 - - - 0 - - - 0 - - + 0 @@ -436,7 +421,7 @@ Qt::Horizontal - + 40 20 @@ -448,22 +433,10 @@ - - 0 - - + 0 - - 0 - - - 0 - - - 6 - - + 6 @@ -496,7 +469,7 @@ Qt::Vertical - + 20 40 @@ -507,6 +480,14 @@ + + + 0 + 0 + 463 + 314 + + Advanced @@ -537,22 +518,10 @@ - - 0 - - - 0 - - + 0 - - 0 - - - 6 - - + 6 @@ -595,7 +564,7 @@ Qt::Vertical - + 20 40 @@ -611,6 +580,36 @@ + + identityList + renameIdentity + addIdentity + deleteIdentity + tabWidget + realName + nicknameList + addNick + deleteNick + renameNick + nickUp + nickDown + awayNick + awayReasonEnabled + awayReason + returnMessageEnabled + returnMessage + awayNickEnabled + autoAwayEnabled + autoAwayTime + autoReturnMessageEnabled + autoAwayReasonEnabled + autoReturnMessage + autoAwayReason + ident + kickReason + partReason + quitReason + diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index ed530edb..c11c6adf 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -478,7 +478,7 @@ void BufferView::contextMenuEvent(QContextMenuEvent *event) { if(result == &_partBufferAction) { BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value(); - Client::instance()->userInput(bufferInfo, QString("/PART %1").arg(bufferInfo.bufferName())); + Client::instance()->userInput(bufferInfo, QString("/PART")); return; } -- 2.20.1