[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdenetwork/kopete/protocols/qq
From:       Hui Jin <blueangel.jin () gmail ! com>
Date:       2006-08-19 5:11:39
Message-ID: 1155964299.872522.32500.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 574471 by blueangel:

Add basic support for incoming message. 
Still, the message is not added although appendMessage is called.

TODO: consult with mentor with this problem.
clean house.



 M  +25 -0     qqaccount.cpp  
 M  +3 -0      qqaccount.h  
 M  +1 -1      qqchatsession.cpp  
 M  +11 -1     qqnotifysocket.cpp  
 M  +1 -0      qqnotifysocket.h  


--- trunk/KDE/kdenetwork/kopete/protocols/qq/qqaccount.cpp #574470:574471
@@ -18,6 +18,7 @@
 #include "qqaccount.h"
 
 #include <QTextCodec>
+#include <QDateTime>
 
 #include <kaction.h>
 #include <kdebug.h>
@@ -118,6 +119,10 @@
 
 	QObject::connect( m_notifySocket, SIGNAL( contactStatusChanged(const \
Eva::ContactStatus&) ),  SLOT( slotContactStatusChanged(const Eva::ContactStatus &) ) \
); +
+	QObject::connect( m_notifySocket, SIGNAL( messageReceived( const \
Eva::MessageHeader&, const Eva::ByteArray& ) ), +		SLOT( slotMessageReceived( const \
Eva::MessageHeader&, const Eva::ByteArray& ) ) ); +
 	m_notifySocket->connect(host, port);
 }
 
@@ -463,8 +468,28 @@
 		kWarning(14210) << k_funcinfo << "unable to look up contact for delivery" << endl;
 }
 
+void QQAccount::slotMessageReceived( const Eva::MessageHeader& header, const \
Eva::ByteArray& message ) +{
+	QString from = QString::number(header.sender);
+	QString to = QString::number(header.receiver);
+	QString msg ( QByteArray(message.data(), message.size()) );
+	QDateTime timestamp;
+	timestamp.setTime_t(header.timestamp);
 
+	QQContact* sender = static_cast<QQContact*>( contacts()[from] );
+	Kopete::ContactPtrList contactList;
+	contactList.append( sender );
+	QString guid = to +  ":" + from;
 
+	QQChatSession* sess = chatSession( contactList, guid, Kopete::Contact::CanCreate );
+	Q_ASSERT( sess );
+	Kopete::Message * newMessage = 
+			new Kopete::Message( timestamp, sender, contactList, msg,
+								 Kopete::Message::Inbound, Kopete::Message::PlainText );
+	sess->appendMessage( *newMessage );
+}
 
 
+
+
 #include "qqaccount.moc"
--- trunk/KDE/kdenetwork/kopete/protocols/qq/qqaccount.h #574470:574471
@@ -33,6 +33,8 @@
 namespace Eva {
 	struct ContactInfo;
 	struct ContactStatus;
+	struct MessageHeader;
+	struct ByteArray;
 }
 
 class QQContact;
@@ -112,6 +114,7 @@
 	void slotGroupNamesListed(const QStringList& ql );
 	void slotContactInGroup(const int qqId, const char type, const int groupId );
 	void slotContactStatusChanged(const Eva::ContactStatus& cs);
+	void slotMessageReceived( const Eva::MessageHeader& header, const Eva::ByteArray& \
message );  
 protected:
 	/**
--- trunk/KDE/kdenetwork/kopete/protocols/qq/qqchatsession.cpp #574470:574471
@@ -216,10 +216,10 @@
 			else
 			{
 				// we are working for this now.
-				kDebug ( 14140 ) << "sending message" << endl;
 				account()->sendMessage( guid(), message );
 				// we could wait until the server acks our send,
 				// but we'd need a UID for outgoing messages and a list to track them
+				kDebug ( 14140 ) << "sending message: " << message.plainBody() << endl;
 				appendMessage( message );
 				messageSucceeded();
 			}
--- trunk/KDE/kdenetwork/kopete/protocols/qq/qqnotifysocket.cpp #574470:574471
@@ -216,7 +216,14 @@
 						<< " timestamp:" << mh.timestamp << " avatar:" << mh.avatar 
 						<< endl;
 
+					if( mh.receiver != m_qqId )
+					{
+						kDebug(14140) << "receive other(" << mh.receiver <<")'s message" << endl;
+						break;
+					}
+
 					// FIXME: replace the magic number!
+					// FIXME: the code stinks!
 					char* p = body.data()+36;
 					bool hasFontStyle = p[3] != 0;
 					char replyType = p[8];
@@ -228,6 +235,9 @@
 					msg += char(0x0);
 
 					kDebug(14140) << "message received: " << msg.data() << endl;
+					// FIXME: use a function to generate guid!
+					emit messageReceived(mh, msg);
+					
 					break;
 				}
 				default:
@@ -428,7 +438,7 @@
 {
 	// Translate the message to Eva::ByteArray
 	// TODO: color and font
-	kDebug( 14140 ) << "Send the message: " << message << " from " << m_qqId << " to " \
<< toId; +	kDebug( 14140 ) << "Send the message: " << message << " from " << m_qqId \
<< " to " << toId << endl;  // attach the ByteArray to QString:
 	// FIXME: Add an adapter to ByteArray
 	Eva::ByteArray text( (char*)message.data(), message.size() );
--- trunk/KDE/kdenetwork/kopete/protocols/qq/qqnotifysocket.h #574470:574471
@@ -66,6 +66,7 @@
 	void groupNames( const QStringList& ql );
 	void contactInGroup(const int qqId, const char type, const int groupId );
 	void contactStatusChanged( const Eva::ContactStatus& cs);
+	void messageReceived( const Eva::MessageHeader&, const Eva::ByteArray& );
 
 protected:
 	/**


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic