QVariant BufferItem::data(int column, int role) const { switch (role) { case NetworkModel::ItemTypeRole: return NetworkModel::BufferItemType; case NetworkModel::BufferIdRole: return qVariantFromValue(bufferInfo().bufferId()); case NetworkModel::NetworkIdRole: return qVariantFromValue(bufferInfo().networkId()); case NetworkModel::BufferInfoRole: return qVariantFromValue(bufferInfo()); case NetworkModel::BufferTypeRole: return int(bufferType()); case NetworkModel::ItemActiveRole: return isActive(); case NetworkModel::BufferActivityRole: return (int)activityLevel(); case NetworkModel::BufferFirstUnreadMsgIdRole: return qVariantFromValue(firstUnreadMsgId()); case NetworkModel::MarkerLineMsgIdRole: return qVariantFromValue(markerLineMsgId()); default: return PropertyMapItem::data(column, role); } }
void CAbsImgBuffer::abortNewImgBuffer( ) { if ( eInternBuffer == bufferType() ) { Unlock(); } }
unsigned char* CAbsImgBuffer::GetPixelsRW() { MMThreadGuard g( *this ); if ( eInternBuffer == bufferType() ) return __super::GetPixelsRW(); return imagePtr_; }
void MessageEvent::toVariantMap(QVariantMap &map) const { NetworkEvent::toVariantMap(map); map["messageType"] = msgType(); map["messageFlags"] = (int)msgFlags(); map["bufferType"] = bufferType(); map["text"] = text(); map["sender"] = sender(); map["target"] = target(); }
Token Tokenizer::dispense() { ASSERT(ready()); char ch = mBuffer.at(mBuffer.size() - 1); mBuffer.pop_back(); string text = string(mBuffer.begin(), mBuffer.end()); TokenType type = tokenType(text); mState = bufferType(ch); mBuffer.clear(); mBuffer.push_back(ch); mReady = false; return Token(type, text); }
bool CAbsImgBuffer::getNewImgBuffer( u08* & pImg, S_IMAGE_HEADER* & pImgHdr, u32 & dwImgSize ) { MMThreadGuard g( *this ); if ( eInternBuffer == bufferType() ) { Lock(); pImg = GetPixelsRW(); pImgHdr = &imageHeader_; dwImgSize = Width() * Height() * Depth(); } else { pImg = 0; pImgHdr = 0; dwImgSize = 0; } return true; }
void CAbsImgBuffer::releasNewImgBuffer( u08* pImg, S_IMAGE_HEADER* pImgHdr ) { MMThreadGuard g( *this ); addUnsedImgBuffers(); // check if buffers are the same if use internal buffers if ( eInternBuffer == bufferType() ) { Unlock(); assert( pImg == GetPixelsRW() ); assert( pImgHdr == &imageHeader_ ); } // store new buffer pointers imagePtr_ = pImg; imageHeaderPtr_ = pImgHdr; // copy image pointer if (( pImgHdr != &imageHeader_ ) && ( 0 != imageHeaderPtr_ ) ) imageHeader_ = *imageHeaderPtr_; }
bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent); QModelIndex sourceIdx = sourceModel()->index(sourceRow, 2); Message::Type messageType = (Message::Type)sourceIdx.data(MessageModel::TypeRole).toInt(); // apply message type filter if(_messageTypeFilter & messageType) return false; if(_validBuffers.isEmpty()) return true; BufferId bufferId = sourceIdx.data(MessageModel::BufferIdRole).value<BufferId>(); if(!bufferId.isValid()) { return true; } MsgId msgId = sourceIdx.data(MessageModel::MsgIdRole).value<MsgId>(); Message::Flags flags = (Message::Flags)sourceIdx.data(MessageModel::FlagsRole).toInt(); NetworkId myNetworkId = networkId(); NetworkId msgNetworkId = Client::networkModel()->networkId(bufferId); if(myNetworkId != msgNetworkId) return false; // ignorelist handling // only match if message is not flagged as server msg if(!(flags & Message::ServerMsg) && Client::ignoreListManager() && Client::ignoreListManager()->match(sourceIdx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufferId))) return false; if(flags & Message::Redirected) { int redirectionTarget = 0; switch(messageType) { case Message::Notice: if(Client::networkModel()->bufferType(bufferId) != BufferInfo::ChannelBuffer) { if(flags & Message::ServerMsg) { // server notice redirectionTarget = _serverNoticesTarget; } else { redirectionTarget = _userNoticesTarget; } } break; case Message::Error: redirectionTarget = _errorMsgsTarget; break; default: break; } if(redirectionTarget & BufferSettings::DefaultBuffer && _validBuffers.contains(bufferId)) return true; if(redirectionTarget & BufferSettings::CurrentBuffer && !(flags & Message::Backlog)) { BufferId redirectedTo = sourceModel()->data(sourceIdx, MessageModel::RedirectedToRole).value<BufferId>(); if(!redirectedTo.isValid()) { BufferId redirectedTo = Client::bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>(); if(redirectedTo.isValid()) sourceModel()->setData(sourceIdx, QVariant::fromValue<BufferId>(redirectedTo), MessageModel::RedirectedToRole); } if(_validBuffers.contains(redirectedTo)) return true; } if(redirectionTarget & BufferSettings::StatusBuffer) { QSet<BufferId>::const_iterator idIter = _validBuffers.constBegin(); while(idIter != _validBuffers.constEnd()) { if(Client::networkModel()->bufferType(*idIter) == BufferInfo::StatusBuffer) return true; idIter++; } } return false; } if(_validBuffers.contains(bufferId)) { return true; } else { // show Quit messages in Query buffers: if(bufferType() != BufferInfo::QueryBuffer) return false; if(!(messageType & Message::Quit)) return false; if(myNetworkId != msgNetworkId) return false; uint messageTimestamp = sourceModel()->data(sourceIdx, MessageModel::TimestampRole).value<QDateTime>().toTime_t(); QString quiter = sourceModel()->data(sourceIdx, Qt::DisplayRole).toString().section(' ', 0, 0, QString::SectionSkipEmpty).toLower(); if(quiter != bufferName().toLower()) return false; if(_filteredQuitMsgs.contains(quiter, messageTimestamp)) return false; MessageFilter *that = const_cast<MessageFilter *>(this); that->_filteredQuitMsgs.insert(quiter, messageTimestamp); return true; } }
bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { Q_UNUSED(sourceParent); QModelIndex sourceIdx = sourceModel()->index(sourceRow, 2); Message::Type messageType = (Message::Type)sourceIdx.data(MessageModel::TypeRole).toInt(); // apply message type filter if (_messageTypeFilter & messageType) return false; if (_validBuffers.isEmpty()) return true; BufferId bufferId = sourceIdx.data(MessageModel::BufferIdRole).value<BufferId>(); if (!bufferId.isValid()) { return true; } // MsgId msgId = sourceIdx.data(MessageModel::MsgIdRole).value<MsgId>(); Message::Flags flags = (Message::Flags)sourceIdx.data(MessageModel::FlagsRole).toInt(); NetworkId myNetworkId = networkId(); NetworkId msgNetworkId = Client::networkModel()->networkId(bufferId); if (myNetworkId != msgNetworkId) return false; // ignorelist handling // only match if message is not flagged as server msg if (!(flags & Message::ServerMsg) && Client::ignoreListManager() && Client::ignoreListManager()->match(sourceIdx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufferId))) return false; if (flags & Message::Redirected) { int redirectionTarget = 0; switch (messageType) { case Message::Notice: if (Client::networkModel()->bufferType(bufferId) != BufferInfo::ChannelBuffer) { if (flags & Message::ServerMsg) { // server notice redirectionTarget = _serverNoticesTarget; } else { redirectionTarget = _userNoticesTarget; } } break; case Message::Error: redirectionTarget = _errorMsgsTarget; break; default: break; } if (redirectionTarget & BufferSettings::DefaultBuffer && _validBuffers.contains(bufferId)) return true; if (redirectionTarget & BufferSettings::CurrentBuffer && !(flags & Message::Backlog)) { BufferId redirectedTo = sourceModel()->data(sourceIdx, MessageModel::RedirectedToRole).value<BufferId>(); if (!redirectedTo.isValid()) { BufferId redirectedTo = Client::bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>(); if (redirectedTo.isValid()) sourceModel()->setData(sourceIdx, QVariant::fromValue<BufferId>(redirectedTo), MessageModel::RedirectedToRole); } if (_validBuffers.contains(redirectedTo)) return true; } if (redirectionTarget & BufferSettings::StatusBuffer) { QSet<BufferId>::const_iterator idIter = _validBuffers.constBegin(); while (idIter != _validBuffers.constEnd()) { if (Client::networkModel()->bufferType(*idIter) == BufferInfo::StatusBuffer) return true; ++idIter; } } return false; } if (_validBuffers.contains(bufferId)) { return true; } else { // show Quit messages in Query buffers: if (bufferType() != BufferInfo::QueryBuffer) return false; if (!(messageType & Message::Quit)) return false; if (myNetworkId != msgNetworkId) return false; // Extract timestamp and nickname from the new quit message qint64 messageTimestamp = sourceModel()->data(sourceIdx, MessageModel::TimestampRole).value<QDateTime>().toMSecsSinceEpoch(); QString quiter = nickFromMask(sourceModel()->data(sourceIdx, MessageModel::MessageRole).value<Message>().sender()).toLower(); // Check that nickname matches query name if (quiter != bufferName().toLower()) return false; // Check if a quit message was already forwarded within +/- 1000 ms static constexpr qint64 MAX_QUIT_DELTA_MS = 1 * 1000; // No need to check if it's the appropriate buffer, each query has a unique message filter if (std::binary_search(_filteredQuitMsgTime.begin(), _filteredQuitMsgTime.end(), messageTimestamp, [](qint64 a, qint64 b) { return ((a + MAX_QUIT_DELTA_MS) < b); })) { // New element is less than if at least 1000 ms older/newer // Match found, no need to forward another quit message return false; } // Mark query as having a quit message inserted auto* that = const_cast<MessageFilter*>(this); that->_filteredQuitMsgTime.insert(messageTimestamp); return true; } }
void Tokenizer::insert(char ch) { bool insert = true; switch (mState) { case BufferState::ErrorState: { // If we are in an error token, switch to ready to // dispense if we encounter a token that is valid to // start an identifier if (canStartToken(ch)) { mReady = true; } } break; case BufferState::SpecialTokenState: { mReady = true; } break; case BufferState::WhiteSpaceState: { // if we are in a white space token, only something // besides a white space token will end our token if (!isWhitespace(ch)) { mReady = true; } } break; case BufferState::VariableOrKeywordState: { // If we are in an identifier, keyword, or condition, // only something besides a valid identifier // character will end the token if (!isIdentifierCharacter(ch)) { mReady = true; } } break; case BufferState::IntConstantState: { if (ch == '.') { mState = BufferState::FloatConstantState; } else if (!isDigit(ch)) { mReady = true; } } break; case BufferState::FloatConstantState: { if (!isDigit(ch)) { mReady = true; } } break; case BufferState::StringConstantState: { if (mEndOfString) { mReady = true; mEndOfString = false; } else if (mEscapeNextChar) { switch (ch) { case 'n': ch = '\n'; break; case 't': ch = '\t'; break; case 'r': ch = '\r'; break; case 'v': ch = '\v'; break; case 'a': ch = '\a'; break; case 'b': ch = '\b'; break; case 'f': ch = '\f'; break; case '\'': case '\"': case '?': case '\\': // do nothing break; default: abort(); break; } mEscapeNextChar = false; } else if (ch == '\"') { mEndOfString = true; } else if (ch == '\\') { mEscapeNextChar = true; insert = false; } } break; case BufferState::CommentState: { // a comment continues until the new line character if (ch == '\n') { mReady = true; } } break; case BufferState::OperatorState: { if (mBuffer.size() == 1 && mBuffer[0] == '-' && isDigit(ch)) { // Negative number special case mState = BufferState::IntConstantState; break; } string s = string(mBuffer.begin(), mBuffer.end()); int before = isOperatorSubstring(s); s.push_back(ch); int after = isOperatorSubstring(s); if (before && !after) { mReady = true; } } break; case BufferState::EmptyState: { // make the mBuffer mState appropriate for whatever we // are adding. mState = bufferType(ch); } break; } if (insert) { mBuffer.push_back(ch); } }