X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircchannel.cpp;h=d16e42df2b3cc6dd9bec6e282cfc46dfe5b5a0ce;hp=04ff1435d678a127854e9b6264ad4e9a14586eb5;hb=e1801627e8e13e7eacbf0c59622a6adf20fcd4cd;hpb=c6fc5ae878a4f92b658c3da2861bcc7da9c2594f diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 04ff1435..d16e42df 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -30,7 +30,7 @@ #include - +INIT_SYNCABLE_OBJECT(IrcChannel) IrcChannel::IrcChannel(const QString &channelname, Network *network) : SyncableObject(network), _initialized(false), @@ -41,6 +41,10 @@ IrcChannel::IrcChannel(const QString &channelname, Network *network) _codecForDecoding(0) { setObjectName(QString::number(network->networkId().toInt()) + "/" + channelname); + + #ifdef HAVE_QCA2 + _cipher = 0; + #endif } IrcChannel::~IrcChannel() { @@ -116,12 +120,13 @@ QByteArray IrcChannel::encodeString(const QString &string) const { // ==================== void IrcChannel::setTopic(const QString &topic) { _topic = topic; + SYNC(ARG(topic)) emit topicSet(topic); } void IrcChannel::setPassword(const QString &password) { _password = password; - emit passwordSet(password); + SYNC(ARG(password)) } void IrcChannel::joinIrcUsers(const QList &users, const QStringList &modes) { @@ -148,6 +153,7 @@ void IrcChannel::joinIrcUsers(const QList &users, const QStringList & _userModes[ircuser] = modes[i]; ircuser->joinChannel(this); connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickSet(QString))); + // connect(ircuser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed())); // if you wonder why there is no counterpart to ircUserJoined: // the joines are propagted by the ircuser. the signal ircUserJoined is only for convenience @@ -159,9 +165,9 @@ void IrcChannel::joinIrcUsers(const QList &users, const QStringList & if(newNicks.isEmpty()) return; - + + SYNC_OTHER(joinIrcUsers, ARG(newNicks), ARG(newModes)); emit ircUsersJoined(newUsers); - emit ircUsersJoined(newNicks, newModes); } void IrcChannel::joinIrcUsers(const QStringList &nicks, const QStringList &modes) { @@ -171,7 +177,7 @@ void IrcChannel::joinIrcUsers(const QStringList &nicks, const QStringList &modes joinIrcUsers(users, modes); } -void IrcChannel::joinIrcUsers(IrcUser *ircuser) { +void IrcChannel::joinIrcUser(IrcUser *ircuser) { QList users; users << ircuser; QStringList modes; @@ -179,10 +185,6 @@ void IrcChannel::joinIrcUsers(IrcUser *ircuser) { joinIrcUsers(users, modes); } -void IrcChannel::joinIrcUsers(const QString &nick) { - joinIrcUsers(network->newIrcUser(nick)); -} - void IrcChannel::part(IrcUser *ircuser) { if(isKnownUser(ircuser)) { _userModes.remove(ircuser); @@ -192,8 +194,9 @@ void IrcChannel::part(IrcUser *ircuser) { disconnect(ircuser, 0, this, 0); emit ircUserParted(ircuser); - if(network->isMe(ircuser)) { - // we left -> clean up the channel and destroy it + if(network->isMe(ircuser) || _userModes.isEmpty()) { + // in either case we're no longer in the channel + // -> clean up the channel and destroy it QList users = _userModes.keys(); _userModes.clear(); foreach(IrcUser *user, users) { @@ -214,7 +217,8 @@ void IrcChannel::part(const QString &nick) { void IrcChannel::setUserModes(IrcUser *ircuser, const QString &modes) { if(isKnownUser(ircuser)) { _userModes[ircuser] = modes; - emit userModesSet(ircuser->nick(), modes); + QString nick = ircuser->nick(); + SYNC_OTHER(setUserModes, ARG(nick), ARG(modes)) emit ircUserModesSet(ircuser, modes); } } @@ -230,7 +234,8 @@ void IrcChannel::addUserMode(IrcUser *ircuser, const QString &mode) { if(!_userModes[ircuser].contains(mode)) { _userModes[ircuser] += mode; - emit userModeAdded(ircuser->nick(), mode); + QString nick = ircuser->nick(); + SYNC_OTHER(addUserMode, ARG(nick), ARG(mode)) emit ircUserModeAdded(ircuser, mode); } @@ -247,7 +252,8 @@ void IrcChannel::removeUserMode(IrcUser *ircuser, const QString &mode) { if(_userModes[ircuser].contains(mode)) { _userModes[ircuser].remove(mode); - emit userModeRemoved(ircuser->nick(), mode); + QString nick = ircuser->nick(); + SYNC_OTHER(removeUserMode, ARG(nick), ARG(mode)); emit ircUserModeRemoved(ircuser, mode); } } @@ -431,7 +437,7 @@ void IrcChannel::addChannelMode(const QChar &mode, const QString &value) { _D_channelModes << mode; break; } - emit channelModeAdded(mode, value); + SYNC(ARG(mode), ARG(value)) } void IrcChannel::removeChannelMode(const QChar &mode, const QString &value) { @@ -457,7 +463,7 @@ void IrcChannel::removeChannelMode(const QChar &mode, const QString &value) { _D_channelModes.remove(mode); break; } - emit channelModeRemoved(mode, value); + SYNC(ARG(mode), ARG(value)) } bool IrcChannel::hasMode(const QChar &mode) const { @@ -539,3 +545,36 @@ QString IrcChannel::channelModeString() const { else return QString("+%1 %2").arg(modeString).arg(params.join(" ")); } + +#ifdef HAVE_QCA2 +Cipher* IrcChannel::cipher() { + if(!_cipher) + _cipher = new Cipher(); + return _cipher; +} +#endif + +void IrcChannel::setEncrypted(bool e) { + if(e) { + #ifdef HAVE_QCA2 + if(topic().isEmpty()) + return; + + QByteArray key = network->bufferKey(name()); + if (key.isEmpty()) + return; + + if(!cipher()->setKey(key)) + return; + + //only send encrypted text to decrypter + int index = topic().indexOf(":",topic().indexOf(":")+1); + + QString backup = topic().mid(0,index+1); + QString decrypted = cipher()->decryptTopic(topic().mid(index+1).toAscii());; + decrypted.prepend(backup); + + setTopic(decodeString(decrypted.toAscii())); + #endif + } +} \ No newline at end of file