void BitcoinGUI::incomingMessage(const QModelIndex & parent, int start, int end) { if(!messageModel) return; MessageModel *mm = messageModel; if (mm->index(start, MessageModel::TypeInt, parent).data().toInt() == MessageTableEntry::Received) { QString sent_datetime = mm->index(start, MessageModel::ReceivedDateTime, parent).data().toString(); QString from_address = mm->index(start, MessageModel::FromAddress, parent).data().toString(); QString to_address = mm->index(start, MessageModel::ToAddress, parent).data().toString(); QString message = mm->index(start, MessageModel::Message, parent).data().toString(); QTextDocument html; html.setHtml(message); QString messageText(html.toPlainText()); notificator->notify(Notificator::Information, tr("Incoming Message"), tr("Date: %1\n" "From Address: %2\n" "To Address: %3\n" "Message: %4\n") .arg(sent_datetime) .arg(from_address) .arg(to_address) .arg(messageText)); }; }
void addMessageEntry(const MessageTableEntry & message, const bool & append) { if(append) { cachedMessageTable.append(message); } else { int index = qLowerBound(cachedMessageTable.begin(), cachedMessageTable.end(), message.received_datetime, MessageTableEntryLessThan()) - cachedMessageTable.begin(); parent->beginInsertRows(QModelIndex(), index, index); cachedMessageTable.insert( index, message); parent->endInsertRows(); } }
void setEncryptionStatus(int status) { if (status == WalletModel::Locked) { // -- Wallet is locked, clear secure message display. cachedMessageTable.clear(); #if QT_VERSION <0x050000 parent->reset(); // reload table view #else parent->beginResetModel(); parent->endResetModel(); #endif }; };
void WalletView::processNewMessage(const QModelIndex& parent, int start, int /*end*/) { // Prevent balloon-spam when initial block download is in progress if(!messageModel) return; MessageModel *mm = messageModel; QString sent_datetime = mm->index(start, MessageModel::ReceivedDateTime, parent).data().toString(); QString from_address = mm->index(start, MessageModel::FromAddress, parent).data().toString(); QString to_address = mm->index(start, MessageModel::ToAddress, parent).data().toString(); QString message = mm->index(start, MessageModel::Message, parent).data().toString(); int type = mm->index(start, MessageModel::TypeInt, parent).data().toInt(); emit incomingMessage(sent_datetime, from_address, to_address, message, type); }
void walletUnlocked() { // -- wallet is unlocked, can get at the private keys now refreshMessageTable(); parent->reset(); // reload table view if (parent->proxyModel) { parent->proxyModel->setFilterRole(false); parent->proxyModel->setFilterFixedString(""); parent->resetFilter(); parent->proxyModel->setFilterRole(MessageModel::Ambiguous); parent->proxyModel->setFilterFixedString("true"); } //invalidateFilter() }
void setEncryptionStatus(int status) { if (status == WalletModel::Locked) { // -- Wallet is locked, clear secure message display. cachedMessageTable.clear(); parent->reset(); // reload table view }; };
void walletUnlocked() { // -- wallet is unlocked, can get at the private keys now refreshMessageTable(); #if QT_VERSION <0x050000 parent->reset(); // reload table view #else parent->beginResetModel(); parent->endResetModel(); #endif if (parent->proxyModel) { parent->proxyModel->setFilterRole(false); parent->proxyModel->setFilterFixedString(""); parent->resetFilter(); parent->proxyModel->setFilterRole(MessageModel::Ambiguous); parent->proxyModel->setFilterFixedString("true"); } //invalidateFilter() }
bool BufferFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { if (m_status == 0 && m_filter.isEmpty()) return true; QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); IrcBuffer* buffer = index.data(Irc::BufferRole).value<IrcBuffer*>(); if (buffer && !buffer->isSticky()) { if (!m_filter.isEmpty() && !buffer->title().contains(m_filter, Qt::CaseInsensitive)) return false; if (m_status > 0) { MessageModel* model = m_storage->model(buffer); if (model) { if (m_status == 1 && model->badge() <= 0) return false; if (m_status == 2 && model->activeHighlights() <= 0) return false; } } } return true; }
void MessageSender::sendMessage(MessageCommunication *messageCommunication, ResponseHandler *responseHandler) { // Sending a message is about preparing a handler for the response // that is expected to be received and sending the message information // via the socker to the destination node. // // Check we have a message and a socket to send data. if (messageCommunication == 0 || messageCommunication->message() == 0 || messageCommunication->socket() == 0) { return; } // Get the socket used for the communication rountrip. QTcpSocket *socket = messageCommunication->socket(); // Prepare the response waiter in case a response handler was // provided. if (responseHandler == 0) { responseHandler = new ResponseHandler(this); } // Prepare a new ResponseWaiter to use and throw away. ResponseWaiter * responseWaiter = new ResponseWaiter( this->m_communication_manager, messageCommunication, responseHandler, this); // Connect the receiving of a message in the socket with the // response handler of the response waiter. QObject::connect(socket, SIGNAL(readyRead()), responseWaiter, SLOT(messageReady())); // Prepare the message data to send via the socket. MessageModel *message = messageCommunication->message(); QString *jsonMessage = message->toCommJSON(); QByteArray dataMessage = jsonMessage->toUtf8(); // Send the message via the socket socket->write(dataMessage); // A response is expected to be received soon that will be handled // by the ResponseWaiter once it arrives. // cerr << "[MessageSender] Message sent : " << message->toJSON()->toStdString() << endl; }
void newMessage(const SecMsgStored& inboxHdr) { // we have to copy it, because it doesn't like constants going into Decrypt SecMsgStored smsgStored = inboxHdr; MessageData msg; QString label; QDateTime sent_datetime; QDateTime received_datetime; uint32_t nPayload = smsgStored.vchMessage.size() - SMSG_HDR_LEN; if (SecureMsgDecrypt(false, smsgStored.sAddrTo, &smsgStored.vchMessage[0], &smsgStored.vchMessage[SMSG_HDR_LEN], nPayload, msg) == 0) { label = parent->getWalletModel()->getAddressTableModel()->labelForAddress(QString::fromStdString(msg.sFromAddress)); sent_datetime .setTime_t(msg.timestamp); received_datetime.setTime_t(smsgStored.timeReceived); std::string sPrefix("im"); SecureMessage* psmsg = (SecureMessage*) &smsgStored.vchMessage[0]; std::vector<unsigned char> vchKey; vchKey.resize(18); memcpy(&vchKey[0], sPrefix.data(), 2); memcpy(&vchKey[2], &psmsg->timestamp, 8); memcpy(&vchKey[10], &smsgStored.vchMessage[SMSG_HDR_LEN], 8); // sample addMessageEntry(MessageTableEntry(vchKey, MessageTableEntry::Received, label, QString::fromStdString(smsgStored.sAddrTo), QString::fromStdString(msg.sFromAddress), sent_datetime, received_datetime, !(smsgStored.status & SMSG_MASK_UNREAD), (char*)&msg.vchMessage[0]), false); } }
void newOutboxMessage(const SecMsgStored& outboxHdr) { SecMsgStored smsgStored = outboxHdr; MessageData msg; QString label; QDateTime sent_datetime; QDateTime received_datetime; uint32_t nPayload = smsgStored.vchMessage.size() - SMSG_HDR_LEN; if (SecureMsgDecrypt(false, smsgStored.sAddrOutbox, &smsgStored.vchMessage[0], &smsgStored.vchMessage[SMSG_HDR_LEN], nPayload, msg) == 0) { label = parent->getWalletModel()->getAddressTableModel()->labelForAddress(QString::fromStdString(smsgStored.sAddrTo)); sent_datetime .setTime_t(msg.timestamp); received_datetime.setTime_t(smsgStored.timeReceived); std::string sPrefix("sm"); SecureMessage* psmsg = (SecureMessage*) &smsgStored.vchMessage[0]; std::vector<unsigned char> vchKey; vchKey.resize(18); memcpy(&vchKey[0], sPrefix.data(), 2); memcpy(&vchKey[2], &psmsg->timestamp, 8); memcpy(&vchKey[10], &smsgStored.vchMessage[SMSG_HDR_LEN], 8); // sample addMessageEntry(MessageTableEntry(vchKey, MessageTableEntry::Sent, label, QString::fromStdString(smsgStored.sAddrTo), QString::fromStdString(msg.sFromAddress), sent_datetime, received_datetime, (char*)&msg.vchMessage[0]), false); } }
void refreshMessageTable() { cachedMessageTable.clear(); if (parent->getWalletModel()->getEncryptionStatus() == WalletModel::Locked) { // -- messages are stored encrypted, can't load them without the private keys return; }; { LOCK(cs_smsgDB); SecMsgDB dbSmsg; if (!dbSmsg.Open("cr+")) //throw runtime_error("Could not open DB."); return; unsigned char chKey[18]; std::vector<unsigned char> vchKey; vchKey.resize(18); SecMsgStored smsgStored; MessageData msg; QString label; QDateTime sent_datetime; QDateTime received_datetime; std::string sPrefix("im"); leveldb::Iterator* it = dbSmsg.pdb->NewIterator(leveldb::ReadOptions()); while (dbSmsg.NextSmesg(it, sPrefix, chKey, smsgStored)) { uint32_t nPayload = smsgStored.vchMessage.size() - SMSG_HDR_LEN; if (SecureMsgDecrypt(false, smsgStored.sAddrTo, &smsgStored.vchMessage[0], &smsgStored.vchMessage[SMSG_HDR_LEN], nPayload, msg) == 0) { label = parent->getWalletModel()->getAddressTableModel()->labelForAddress(QString::fromStdString(msg.sFromAddress)); sent_datetime .setTime_t(msg.timestamp); received_datetime.setTime_t(smsgStored.timeReceived); memcpy(&vchKey[0], chKey, 18); addMessageEntry(MessageTableEntry(vchKey, MessageTableEntry::Received, label, QString::fromStdString(smsgStored.sAddrTo), QString::fromStdString(msg.sFromAddress), sent_datetime, received_datetime, (char*)&msg.vchMessage[0]), true); } }; delete it; sPrefix = "sm"; it = dbSmsg.pdb->NewIterator(leveldb::ReadOptions()); while (dbSmsg.NextSmesg(it, sPrefix, chKey, smsgStored)) { uint32_t nPayload = smsgStored.vchMessage.size() - SMSG_HDR_LEN; if (SecureMsgDecrypt(false, smsgStored.sAddrOutbox, &smsgStored.vchMessage[0], &smsgStored.vchMessage[SMSG_HDR_LEN], nPayload, msg) == 0) { label = parent->getWalletModel()->getAddressTableModel()->labelForAddress(QString::fromStdString(smsgStored.sAddrTo)); sent_datetime .setTime_t(msg.timestamp); received_datetime.setTime_t(smsgStored.timeReceived); memcpy(&vchKey[0], chKey, 18); addMessageEntry(MessageTableEntry(vchKey, MessageTableEntry::Sent, label, QString::fromStdString(smsgStored.sAddrTo), QString::fromStdString(msg.sFromAddress), sent_datetime, received_datetime, (char*)&msg.vchMessage[0]), true); } }; delete it; } }