Filter some unicode control codes out of IRC messages
[quassel.git] / src / core / coresession.cpp
index 344f6a7..13e8462 100644 (file)
@@ -68,7 +68,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
 
   p->attachSignal(this, SIGNAL(networkCreated(NetworkId)));
   p->attachSignal(this, SIGNAL(networkRemoved(NetworkId)));
-  p->attachSlot(SIGNAL(createNetwork(const NetworkInfo &)), this, SLOT(createNetwork(const NetworkInfo &)));
+  p->attachSlot(SIGNAL(createNetwork(const NetworkInfo &, const QStringList &)), this, SLOT(createNetwork(const NetworkInfo &, const QStringList &)));
   p->attachSlot(SIGNAL(removeNetwork(NetworkId)), this, SLOT(removeNetwork(NetworkId)));
 
   loadSettings();
@@ -182,7 +182,6 @@ void CoreSession::removeClient(QIODevice *iodev) {
 
 QHash<QString, QString> CoreSession::persistentChannels(NetworkId id) const {
   return Core::persistentChannels(user(), id);
-  return QHash<QString, QString>();
 }
 
 // FIXME switch to BufferId
@@ -202,6 +201,11 @@ void CoreSession::recvMessageFromServer(Message::Type type, BufferInfo::Type buf
   CoreNetwork *net = qobject_cast<CoreNetwork*>(this->sender());
   Q_ASSERT(net);
 
+  // U+FDD0 and U+FDD1 are special characters for Qt's text engine, specifically they mark the boundaries of
+  // text frames in a QTextDocument. This might lead to problems in widgets displaying QTextDocuments (such as
+  // KDE's notifications), hence we remove those just to be safe.
+  text.remove(QChar(0xfdd0)).remove(QChar(0xfdd1));
+
   BufferInfo bufferInfo = Core::bufferInfo(user(), net->networkId(), bufferType, target);
   Message msg(bufferInfo, type, text, sender, flags);
   msg.setMsgId(Core::storeMessage(msg));
@@ -307,7 +311,7 @@ void CoreSession::removeIdentity(IdentityId id) {
 
 /*** Network Handling ***/
 
-void CoreSession::createNetwork(const NetworkInfo &info_) {
+void CoreSession::createNetwork(const NetworkInfo &info_, const QStringList &persistentChans) {
   NetworkInfo info = info_;
   int id;
 
@@ -321,6 +325,20 @@ void CoreSession::createNetwork(const NetworkInfo &info_) {
 
   id = info.networkId.toInt();
   if(!_networks.contains(id)) {
+
+    // create persistent chans
+    QRegExp rx("\\s*(\\S+)(?:\\s*(\\S+))?\\s*");
+    foreach(QString channel, persistentChans) {
+      if(!rx.exactMatch(channel)) {
+        qWarning() << QString("Invalid persistent channel declaration: %1").arg(channel);
+        continue;
+      }
+      Core::bufferInfo(user(), info.networkId, BufferInfo::ChannelBuffer, rx.cap(1), true);
+      Core::setChannelPersistent(user(), info.networkId, rx.cap(1), true);
+      if(!rx.cap(2).isEmpty())
+        Core::setPersistentChannelKey(user(), info.networkId, rx.cap(1), rx.cap(2));
+    }
+
     CoreNetwork *net = new CoreNetwork(id, this);
     connect(net, SIGNAL(displayMsg(Message::Type, BufferInfo::Type, QString, QString, QString, Message::Flags)),
            this, SLOT(recvMessageFromServer(Message::Type, BufferInfo::Type, QString, QString, QString, Message::Flags)));
@@ -375,7 +393,6 @@ void CoreSession::clientsConnected() {
   Identity *identity = 0;
   CoreNetwork *net = 0;
   IrcUser *me = 0;
-  QString awayReason;
   while(netIter != _networks.end()) {
     net = *netIter;
     netIter++;
@@ -415,10 +432,8 @@ void CoreSession::clientsDisconnected() {
       continue;
 
     if(identity->detachAwayEnabled() && !me->isAway()) {
-      if(identity->detachAwayReasonEnabled())
+      if(!identity->detachAwayReason().isEmpty())
        awayReason = identity->detachAwayReason();
-      else
-       awayReason = identity->awayReason();
       net->setAutoAwayActive(true);
       net->userInputHandler()->handleAway(BufferInfo(), awayReason);
     }