Пример #1
0
void PrivateChat::sendMessage()
{
	gloox::Message m( gloox::Message::Chat, target(), inputLine->text().toUtf8().data() );
	send( m );
	emit reciveMessage(inputLine->text(), "pichi");
	inputLine->clear();
}
Пример #2
0
void PrivateChat::handleMessage(const gloox::Message& msg, gloox::MessageSession* session)
{
	if(msg.subtype() == gloox::Message::Chat)
		emit reciveMessage(QString().fromUtf8(msg.body().c_str()), QString().fromUtf8((msg.from().full().c_str())));
	else
		emit reciveNotPrivateMessage(QString().fromUtf8(msg.body().c_str()), QString().fromUtf8((msg.from().full().c_str())), QString().fromUtf8((msg.from().resource().c_str())));
}
Пример #3
0
void NetWorkClient::onReadyRead()
{
    QDataStream in ( this );
    in.setVersion(QDataStream::Qt_4_0); // Для совместимости с серверной частью

    while (this->bytesAvailable() > 0){
        if (packetSize == -1) {
            //Определим количество байт доступных для чтения min >= 8 byte
            if( (PACKET_SIZE) this->bytesAvailable() < (PACKET_SIZE) sizeof(packetSize) ){
                return;
            }            
            in >> packetSize;//Читаем размер пакета
        }
        //Проверим что в сокет пришел весь пакет а не его огрызки
        if (this->bytesAvailable() < packetSize){
            return;
        }
        //Сбросим размер пакета, для обработки следующего
        packetSize = -1;
        // Прочтем тип сообщения
        int m_Type;
        in >> m_Type;

        //Прочтем само сообщение
        QByteArray data;
        in >> data;
        Message message( this );
        message.setType((MessageType) m_Type);
        message.setMessageData( data );
        // Отправка сообщения
        emit reciveMessage( message );
    }
}
Пример #4
0
void PrivateChat::createChatBox()
{
	QVBoxLayout* main = new QVBoxLayout;
	inputLine = new QLineEdit;
	chatBox = new QTextBrowser;
	main->addWidget(chatBox);
	main->addWidget(inputLine);
	setLayout(main);
	
	connect(this, SIGNAL(reciveMessage(QString,QString)), SLOT(addToMessageBox(QString,QString)));
	connect(this, SIGNAL(reciveNotPrivateMessage(QString,QString,QString)), ((ChatDialog*)parent()), SLOT(addToMessageBox(QString,QString,QString)));
	connect(inputLine, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
	connect(this, SIGNAL(setTrayBlink(bool)), ((ChatDialog*)parent())->mainWindow, SLOT(setTrayBlink(bool)));
	
	registerMessageHandler(this);
}