示例#1
0
 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
 {
     IrcUser* user = index.data(Irc::UserRole).value<IrcUser*>();
     if (user && user->isAway())
         const_cast<QStyleOptionViewItem&>(option).state |= QStyle::State_Off;
     QStyledItemDelegate::paint(painter, option, index);
 }
示例#2
0
/*!
    Returns the data for specified \a role referred to by the \a index.

    \sa Irc::DataRole, roleNames()
 */
QVariant IrcUserModel::data(const QModelIndex& index, int role) const
{
    Q_D(const IrcUserModel);
    if (!d->channel || !hasIndex(index.row(), index.column(), index.parent()))
        return QVariant();

    IrcUser* user = static_cast<IrcUser*>(index.internalPointer());
    Q_ASSERT(user);

    switch (role) {
    case Qt::DisplayRole:
        return data(index, d->role);
    case Irc::UserRole:
        return QVariant::fromValue(user);
    case Irc::NameRole:
        return user->name();
    case Irc::PrefixRole:
        return user->prefix().left(1);
    case Irc::ModeRole:
        return user->mode().left(1);
    case Irc::TitleRole:
        return user->title();
    }

    return QVariant();
}
示例#3
0
void AliasManager::expand(const QString &alias, const BufferInfo &bufferInfo, const QString &msg, CommandList &list) {
  const Network *net = network(bufferInfo.networkId());
  if(!net) {
    // FIXME send error as soon as we have a method for that!
    return;
  }

  QRegExp paramRangeR("\\$(\\d+)\\.\\.(\\d*)");
  QStringList commands = alias.split(QRegExp("; ?"));
  QStringList params = msg.split(' ');
  QStringList expandedCommands;
  for(int i = 0; i < commands.count(); i++) {
    QString command = commands[i];

    // replace ranges like $1..3
    if(!params.isEmpty()) {
      int pos;
      while((pos = paramRangeR.indexIn(command)) != -1) {
        int start = paramRangeR.cap(1).toInt();
        bool ok;
        int end = paramRangeR.cap(2).toInt(&ok);
        if(!ok) {
          end = params.count();
        }
        if(end < start)
          command = command.replace(pos, paramRangeR.matchedLength(), QString());
        else {
          command = command.replace(pos, paramRangeR.matchedLength(), QStringList(params.mid(start - 1, end - start + 1)).join(" "));
        }
      }
    }

    for(int j = params.count(); j > 0; j--) {
      IrcUser *ircUser = net->ircUser(params[j - 1]);
      command = command.replace(QString("$%1:hostname").arg(j), ircUser ? ircUser->host() : QString("*"));
      command = command.replace(QString("$%1").arg(j), params[j - 1]);
    }
    command = command.replace("$0", msg);
    command = command.replace("$channelname", bufferInfo.bufferName()); // legacy
    command = command.replace("$channel", bufferInfo.bufferName());
    command = command.replace("$currentnick", net->myNick()); // legacy
    command = command.replace("$nick", net->myNick());
    expandedCommands << command;
  }

  while(!expandedCommands.isEmpty()) {
    QString command;
    if(expandedCommands[0].trimmed().toLower().startsWith("/wait")) {
      command = expandedCommands.join("; ");
      expandedCommands.clear();
    } else {
      command = expandedCommands.takeFirst();
    }
    list.append(qMakePair(bufferInfo, command));
  }
}
示例#4
0
QVariant IrcUserListModel::data( const QModelIndex& index, int role ) const
{
	if ( !channel() || !hasIndex( index.row(), index.column(), index.parent() ) )
	{
		return QVariant();
	}

	IrcUser* user = static_cast<IrcUser*>( index.internalPointer() );
	Q_ASSERT( user );

	switch ( role )
	{
	case Qt::DisplayRole:
		return user->name();
	case Qt::DecorationRole:
		return modeToIcon( user->mode().left( 1 ) );
	case Qt::ForegroundRole:
		if ( user->isServOp() )
		{
			if ( user->isAway() )
			{
				return QColor( "red" );
			}
			else
			{
				return QColor( "#9A2A2A" );
			}
		}
		else
		{
			if ( user->isAway() )
			{
				return QColor( quazaaSettings.Chat.Colors[IrcColorType::Inactive] );
			}
			else
			{
				return QColor( quazaaSettings.Chat.Colors[IrcColorType::Default] );
			}
		}
	case Irc::UserRole:
		return QVariant::fromValue( user );
	case Irc::NameRole:
		return user->name();
	case Irc::PrefixRole:
		return user->prefix().left( 1 );
	case Irc::ModeRole:
		return user->mode().left( 1 );
	case Irc::TitleRole:
		return user->title();
	}

	return QVariant();
}
示例#5
0
文件: nickview.cpp 项目: AlD/quassel
void NickView::startQuery(const QModelIndex &index)
{
    if (index.data(NetworkModel::ItemTypeRole) != NetworkModel::IrcUserItemType)
        return;

    IrcUser *ircUser = qobject_cast<IrcUser *>(index.data(NetworkModel::IrcUserRole).value<QObject *>());
    NetworkId networkId = index.data(NetworkModel::NetworkIdRole).value<NetworkId>();
    if (!ircUser || !networkId.isValid())
        return;

    Client::bufferModel()->switchToOrStartQuery(networkId, ircUser->nick());
}
示例#6
0
void IrcClient::onUserActivated(const QModelIndex& index)
{
    IrcUser* user = index.data(Irc::UserRole).value<IrcUser*>();

    if (user) {
        IrcBuffer* buffer = bufferModel->add(user->name());

        // activate the new query
        int idx = bufferModel->buffers().indexOf(buffer);
        if (idx != -1)
            bufferList->setCurrentIndex(bufferModel->index(idx));
    }
}
QString NetworkModelController::nickName(const QModelIndex &index) const
{
    IrcUser *ircUser = qobject_cast<IrcUser *>(index.data(NetworkModel::IrcUserRole).value<QObject *>());
    if (ircUser)
        return ircUser->nick();

    BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
    if (!bufferInfo.isValid())
        return QString();
    if (bufferInfo.type() != BufferInfo::QueryBuffer)
        return QString();

    return bufferInfo.bufferName(); // FIXME this might break with merged queries maybe
}
void ContextMenuActionProvider::addIrcUserActions(QMenu *menu, const QModelIndex &index)
{
    // this can be called: a) as a nicklist context menu (index has IrcUserItemType)
    //                     b) as a query buffer context menu (index has BufferItemType and is a QueryBufferItem)
    //                     c) right-click in a query chatview (same as b), index will be the corresponding QueryBufferItem)
    //                     d) right-click on some nickname (_contextItem will be non-null, _filter -> chatview, index -> message buffer)

    if (contextItem().isNull()) {
        // cases a, b, c
        bool haveQuery = indexList().count() == 1 && findQueryBuffer(index).isValid();
        NetworkModel::ItemType itemType = static_cast<NetworkModel::ItemType>(index.data(NetworkModel::ItemTypeRole).toInt());
        addAction(_nickModeMenuAction, menu, itemType == NetworkModel::IrcUserItemType);
        addAction(_nickCtcpMenuAction, menu);

        IrcUser *ircUser = qobject_cast<IrcUser *>(index.data(NetworkModel::IrcUserRole).value<QObject *>());
        if (ircUser) {
            Network *network = ircUser->network();
            // only show entries for usermode +h if server supports it
            if (network && network->prefixModes().contains('h')) {
                action(NickHalfop)->setVisible(true);
                action(NickDehalfop)->setVisible(true);
            }
            else {
                action(NickHalfop)->setVisible(false);
                action(NickDehalfop)->setVisible(false);
            }
            // ignoreliststuff
            QString bufferName;
            BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
            if (bufferInfo.type() == BufferInfo::ChannelBuffer)
                bufferName = bufferInfo.bufferName();
            QMap<QString, bool> ignoreMap = Client::ignoreListManager()->matchingRulesForHostmask(ircUser->hostmask(), ircUser->network()->networkName(), bufferName);
            addIgnoreMenu(menu, ircUser->hostmask(), ignoreMap);
            // end of ignoreliststuff
        }
        menu->addSeparator();
        addAction(NickQuery, menu, itemType == NetworkModel::IrcUserItemType && !haveQuery && indexList().count() == 1);
        addAction(NickSwitchTo, menu, itemType == NetworkModel::IrcUserItemType && haveQuery);
        menu->addSeparator();
        addAction(NickWhois, menu, true);
    }
    else if (!contextItem().isEmpty() && messageFilter()) {
        // case d
        // TODO
    }
}
示例#9
0
void IrcChannelPrivate::addUser(const QString& name)
{
    Q_Q(IrcChannel);
    const QStringList prefixes = q->network()->prefixes();

    IrcUser* user = new IrcUser(q);
    IrcUserPrivate* priv = IrcUserPrivate::get(user);
    priv->channel = q;
    priv->setName(userName(name, prefixes));
    priv->setPrefix(getPrefix(name, prefixes));
    priv->setMode(getMode(q->network(), user->prefix()));
    activeUsers.prepend(user);
    userList.append(user);
    userMap.insert(user->name(), user);
    names = userMap.keys();

    foreach (IrcUserModel* model, userModels)
        IrcUserModelPrivate::get(model)->addUser(user);
}
示例#10
0
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);
}
// this would be the place for a client-side hook
void ClientUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QString &msg)
{
    if (msg.isEmpty())
        return;

    if (!msg.startsWith('/')) {
        if (_nickRx.indexIn(msg) == 0) {
            const Network *net = Client::network(bufferInfo.networkId());
            IrcUser *user = net ? net->ircUser(_nickRx.cap(1)) : 0;
            if (user)
                user->setLastSpokenTo(bufferInfo.bufferId(), QDateTime::currentDateTime().toUTC());
        }
    }

    AliasManager::CommandList clist = Client::aliasManager()->processInput(bufferInfo, msg);

    for (int i = 0; i < clist.count(); i++) {
        QString cmd = clist.at(i).second.section(' ', 0, 0).remove(0, 1).toUpper();
        QString payload = clist.at(i).second.section(' ', 1);
        handle(cmd, Q_ARG(BufferInfo, clist.at(i).first), Q_ARG(QString, payload));
    }
}
示例#12
0
void InputWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
    QItemSelectionRange changedArea(topLeft, bottomRight);
    if (changedArea.contains(selectionModel()->currentIndex())) {
        updateEnabledState();

        bool encrypted = false;

        IrcChannel *chan = qobject_cast<IrcChannel *>(Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcChannelRole).value<QObject *>());
        if (chan)
            encrypted = chan->encrypted();

        IrcUser *user = qobject_cast<IrcUser *>(Client::bufferModel()->data(selectionModel()->currentIndex(), NetworkModel::IrcUserRole).value<QObject *>());
        if (user)
            encrypted = user->encrypted();

        if (encrypted)
            ui.encryptionIconLabel->show();
        else
            ui.encryptionIconLabel->hide();
    }
}
示例#13
0
void BnxChannel::AddMember(const IrcUser &clUser) {
	if (GetMember(clUser.GetNickname()) != MemberEnd())
		return;

	m_vMembers.push_back(Member(clUser));
}