From: Manuel Nickschas Date: Wed, 20 Feb 2008 21:08:20 +0000 (+0000) Subject: Pressing enter in the topic line now sets the channel topic. X-Git-Tag: 0.2.0-alpha1~15 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=dcba0652ac1275877b98b06d6482924ee6df0cd1 Pressing enter in the topic line now sets the channel topic. Also fixed a core crash resulting from receiving an empty topic message. --- diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp index 335bd3a5..0499c859 100644 --- a/src/core/ircserverhandler.cpp +++ b/src/core/ircserverhandler.cpp @@ -312,7 +312,7 @@ void IrcServerHandler::handlePrivmsg(const QString &prefix, const QList ¶ms) { IrcUser *ircuser = network()->updateNickFromMask(prefix); - Q_ASSERT(ircuser); + if(!ircuser) return; QString msg; if(params.count()) @@ -326,9 +326,10 @@ void IrcServerHandler::handleQuit(const QString &prefix, const QList void IrcServerHandler::handleTopic(const QString &prefix, const QList ¶ms) { IrcUser *ircuser = network()->updateNickFromMask(prefix); + if(!ircuser) return; QString channel = serverDecode(params[0]); - QString topic = channelDecode(channel, params[1]); - Q_ASSERT(ircuser); + QString topic; + if(params.count() >= 2) topic = channelDecode(channel, params[1]); network()->ircChannel(channel)->setTopic(topic); diff --git a/src/core/userinputhandler.cpp b/src/core/userinputhandler.cpp index 08561341..d7b827ec 100644 --- a/src/core/userinputhandler.cpp +++ b/src/core/userinputhandler.cpp @@ -222,9 +222,13 @@ void UserInputHandler::handleSay(const BufferInfo &bufferInfo, const QString &ms void UserInputHandler::handleTopic(const BufferInfo &bufferInfo, const QString &msg) { if(bufferInfo.bufferName().isEmpty()) return; - QList params; - params << serverEncode(bufferInfo.bufferName()) << channelEncode(bufferInfo.bufferName(), msg); - emit putCmd("TOPIC", params); + if(!msg.isEmpty()) { + QList params; + params << serverEncode(bufferInfo.bufferName()) << channelEncode(bufferInfo.bufferName(), msg); + emit putCmd("TOPIC", params); + } else { + emit networkConnection()->putRawLine("TOPIC " + serverEncode(bufferInfo.bufferName()) + " :"); + } } void UserInputHandler::handleVoice(const BufferInfo &bufferInfo, const QString &msg) { diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index b44f7dde..e6f3a54a 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -254,6 +254,8 @@ void MainWin::setupTopicWidget() { VerticalDock *dock = new VerticalDock(tr("Topic"), this); dock->setObjectName("TopicDock"); TopicWidget *topicwidget = new TopicWidget(dock); + connect(topicwidget, SIGNAL(topicChanged(const QString &)), this, SLOT(changeTopic(const QString &))); + dock->setWidget(topicwidget); Client::bufferModel()->mapProperty(1, Qt::DisplayRole, topicwidget, "topic"); @@ -303,6 +305,14 @@ void MainWin::changeEvent(QEvent *event) { } } +// FIXME this should be made prettier... +void MainWin::changeTopic(const QString &topic) { + BufferId id = ui.bufferWidget->currentBuffer(); + if(!id.isValid()) return; + Buffer *buffer = Client::buffer(id); + if(buffer) Client::userInput(buffer->bufferInfo(), QString("/topic %1").arg(topic)); +} + void MainWin::connectedToCore() { foreach(BufferInfo id, Client::allBufferInfos()) { emit requestBacklog(id, 1000, -1); diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 40764f31..57c8bb3d 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -73,6 +73,8 @@ class MainWin : public QMainWindow { void clientNetworkUpdated(); void connectOrDisconnectFromNet(); + void changeTopic(const QString &topic); + signals: void connectToCore(const QVariantMap &connInfo); void disconnectFromCore(); diff --git a/src/qtui/topicwidget.cpp b/src/qtui/topicwidget.cpp index 06303c83..40e7ae8e 100644 --- a/src/qtui/topicwidget.cpp +++ b/src/qtui/topicwidget.cpp @@ -28,13 +28,12 @@ TopicWidget::TopicWidget(QWidget *parent) ui.setupUi(this); } -QString TopicWidget::topic() const { - return ui.topicLineEdit->text(); -} - void TopicWidget::setTopic(const QString &newtopic) { ui.topicLineEdit->setText(newtopic); + ui.topicLineEdit->setCursorPosition(0); } -TopicWidget::~TopicWidget() { +void TopicWidget::on_topicLineEdit_returnPressed() { + ui.topicLineEdit->setCursorPosition(0); + emit topicChanged(topic()); } diff --git a/src/qtui/topicwidget.h b/src/qtui/topicwidget.h index c28a2eb4..f899a2ba 100644 --- a/src/qtui/topicwidget.h +++ b/src/qtui/topicwidget.h @@ -29,15 +29,20 @@ class TopicWidget : public QWidget { Q_OBJECT Q_PROPERTY(QString topic READ topic WRITE setTopic STORED false) -public: - TopicWidget(QWidget *parent = 0); - virtual ~TopicWidget(); + public: + TopicWidget(QWidget *parent = 0); - QString topic() const; - void setTopic(const QString &newtopic); + inline QString topic() const { return ui.topicLineEdit->text(); } + void setTopic(const QString &newtopic); + + signals: + void topicChanged(const QString &text); + + private slots: + void on_topicLineEdit_returnPressed(); -private: - Ui::TopicWidget ui; + private: + Ui::TopicWidget ui; };