void ChannelBufferItem::attachIrcChannel(IrcChannel *ircChannel)
{
    if (_ircChannel) {
        qWarning() << Q_FUNC_INFO << "IrcChannel already set; cleanup failed!?";
        disconnect(_ircChannel, 0, this, 0);
    }

    _ircChannel = ircChannel;

    connect(ircChannel, SIGNAL(destroyed(QObject*)),
        this, SLOT(ircChannelDestroyed()));
    connect(ircChannel, SIGNAL(topicSet(QString)),
        this, SLOT(setTopic(QString)));
    connect(ircChannel, SIGNAL(encryptedSet(bool)),
        this, SLOT(setEncrypted(bool)));
    connect(ircChannel, SIGNAL(ircUsersJoined(QList<IrcUser *> )),
        this, SLOT(join(QList<IrcUser *> )));
    connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
        this, SLOT(part(IrcUser *)));
    connect(ircChannel, SIGNAL(parted()),
        this, SLOT(ircChannelParted()));
    connect(ircChannel, SIGNAL(ircUserModesSet(IrcUser *, QString)),
        this, SLOT(userModeChanged(IrcUser *)));
    connect(ircChannel, SIGNAL(ircUserModeAdded(IrcUser *, QString)),
        this, SLOT(userModeChanged(IrcUser *)));
    connect(ircChannel, SIGNAL(ircUserModeRemoved(IrcUser *, QString)),
        this, SLOT(userModeChanged(IrcUser *)));

    if (!ircChannel->ircUsers().isEmpty())
        join(ircChannel->ircUsers());

    emit dataChanged();
}
Exemple #2
0
void ChannelBufferItem::attachIrcChannel(IrcChannel *ircChannel)
{
    Q_ASSERT(!_ircChannel && ircChannel);

    _ircChannel = ircChannel;

    connect(ircChannel, SIGNAL(topicSet(QString)),
        this, SLOT(setTopic(QString)));
    connect(ircChannel, SIGNAL(encryptedSet(bool)),
        this, SLOT(setEncrypted(bool)));
    connect(ircChannel, SIGNAL(ircUsersJoined(QList<IrcUser *> )),
        this, SLOT(join(QList<IrcUser *> )));
    connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
        this, SLOT(part(IrcUser *)));
    connect(ircChannel, SIGNAL(parted()),
        this, SLOT(ircChannelParted()));
    connect(ircChannel, SIGNAL(ircUserModesSet(IrcUser *, QString)),
        this, SLOT(userModeChanged(IrcUser *)));
    connect(ircChannel, SIGNAL(ircUserModeAdded(IrcUser *, QString)),
        this, SLOT(userModeChanged(IrcUser *)));
    connect(ircChannel, SIGNAL(ircUserModeRemoved(IrcUser *, QString)),
        this, SLOT(userModeChanged(IrcUser *)));

    if (!ircChannel->ircUsers().isEmpty())
        join(ircChannel->ircUsers());

    emit dataChanged();
}
void IrcChannel::joinIrcUsers(const QList<IrcUser *> &users, const QStringList &modes)
{
    if (users.isEmpty())
        return;

    if (users.count() != modes.count()) {
        qWarning() << "IrcChannel::addUsers(): number of nicks does not match number of modes!";
        return;
    }

    QStringList newNicks;
    QStringList newModes;
    QList<IrcUser *> newUsers;

    IrcUser *ircuser;
    for (int i = 0; i < users.count(); i++) {
        ircuser = users[i];
        if (!ircuser || _userModes.contains(ircuser)) {
            addUserMode(ircuser, modes[i]);
            continue;
        }

        _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

        newNicks << ircuser->nick();
        newModes << modes[i];
        newUsers << ircuser;
    }

    if (newNicks.isEmpty())
        return;

    SYNC_OTHER(joinIrcUsers, ARG(newNicks), ARG(newModes));
    emit ircUsersJoined(newUsers);
}