[prev in list] [next in list] [prev in thread] [next in thread]
List: kopete-devel
Subject: [Kopete-devel] MSN SwitchBoard Socket issues
From: Richard Stellingwerff <mortallic () multiweb ! nl>
Date: 2002-06-20 10:18:06
[Download RAW message or body]
Hey spaze,
I updated the MSNSwitchBoardSocket so that it emits a signal
switchBoardClosed() when the socket gets closed (either by will, or
unexpectedly).
MSNProtocol will catch this event, and remove the switchboard from the list
and call deleteLater() on the object. All this works fine.
Whenever we want to send a new message, we check if there's a switchboard
available (in MSNProtocol::slotMessageSent()). If there isn't, we create one.
since slotStartChatSession(string handle) wants a handle, I extract this from
the first KopeteContact (msg.to().first()). Then I dynamically cast that to
MSNContact*, and extract the handle.
This works fine too (with 1 on 1 chats).
However, we can't send the message right away, because creating the
switchboard takes a little while... The only solution I can think of, is
using a queue (which I would dislike, but if it's the only option, so be
it...). Also, since the chat window doesn't block when sending a message, the
user should know that some messages are still pending. Perhaps we could
implement a statusbar inside the chat window, which tells the user how many
messages are pending?
If you've got any better ideas, please let me know...
I attached a patch with all the changed so far (I changed some more stuff
too). If need it, i uploaded the full msnprotocol.cpp to
http://www.linuxfromscratch.org/~remenic/kopete/msnprotocol.cpp.
Cheers,
Richard.
["diffs" (text/x-diff)]
? diffs
? ui/msndebugrawcommand_base.cpp
? ui/msndebugrawcommand_base.h
Index: msnnotifysocket.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/protocols/msn/msnnotifysocket.cpp,v
retrieving revision 1.30
diff -b -u -r1.30 msnnotifysocket.cpp
--- msnnotifysocket.cpp 2002/06/17 19:32:40 1.30
+++ msnnotifysocket.cpp 2002/06/20 10:09:26
@@ -36,6 +36,7 @@
KMSNServiceSocket::~KMSNServiceSocket()
{
+ kdDebug() << "KMSNServiceSocket::~KMSNServiceSocket" << endl;
}
void KMSNServiceSocket::connect( const QString &pwd )
@@ -106,6 +107,8 @@
void KMSNServiceSocket::parseCommand( const QString &cmd, uint id,
const QString &data )
{
+ kdDebug() << "KMSNServiceSocket::parseCommand: Command: " << cmd << endl;
+
if( cmd == "USR" )
{
if( data.section( ' ', 1, 1 ) == "S" )
Index: msnprotocol.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/protocols/msn/msnprotocol.cpp,v
retrieving revision 1.90
diff -b -u -r1.90 msnprotocol.cpp
--- msnprotocol.cpp 2002/06/17 19:32:40 1.90
+++ msnprotocol.cpp 2002/06/20 10:09:30
@@ -201,6 +201,9 @@
connect( m_serviceSocket, SIGNAL( startChat( QString, QString ) ),
this, SLOT( slotCreateChat( QString, QString ) ) );
+ connect( m_serviceSocket, SIGNAL( socketClosed( int ) ),
+ this, SLOT( slotNotifySocketClosed( int ) ) );
+
m_serviceSocket->connect( m_password );
statusBarIcon->setMovie( connectingIcon );
}
@@ -210,7 +213,8 @@
if (m_serviceSocket)
m_serviceSocket->disconnect();
- delete m_serviceSocket;
+ //delete m_serviceSocket;
+ m_serviceSocket->deleteLater();
m_serviceSocket = 0L;
m_chatServices.setAutoDelete( true );
@@ -1021,14 +1025,34 @@
KopeteMessageManager *manager = kopeteapp->sessionFactory()->create(
m_myself, msg.to(), this );
+
MSNSwitchBoardSocket *service = m_chatServices[ manager ];
if( service )
service->slotSendMsg( msg );
- else
+ else // There's no switchboard available, so we must create a new one!
+ {
+ MSNContact *contact = dynamic_cast<MSNContact*>( msg.to().first() );
+
+ if ( !contact )
{
- kdDebug() << "WARNING: No chat service active for these recipients!"
- << endl;
+ kdDebug() <<
+ "MSNProtocol::slotMessageSent:Unable to create a " <<
+ "new switchboard!" << endl;
+ return;
}
+
+ kdDebug() << "MSNProtocol::slotMessageSent: Creating new "
+ << "SwitchBoardSocket for " << contact->msnId() << "!" << endl;
+
+ slotStartChatSession( contact->msnId() );
+
+ // *********** NOW WHAT DO WE DO?! ************** //
+ //MSNSwitchBoardSocket *service = m_chatServices[ manager ];
+
+ //if( service )
+ // service->slotSendMsg( msg );
+
+ }
}
void MSNProtocol::slotCreateChat( QString ID, QString address, QString auth,
@@ -1055,6 +1079,9 @@
connect( chatService, SIGNAL( msgReceived( const KopeteMessage & ) ),
this, SLOT( slotMessageReceived( const KopeteMessage & ) ) );
+ connect( chatService,
+ SIGNAL( switchBoardClosed(MSNSwitchBoardSocket *) ),
+ this, SLOT( slotSwitchBoardClosed(MSNSwitchBoardSocket * ) ) );
// We may have a new KMM here, but it could just as well be an
// existing instance. To avoid connecting multiple times, try to
@@ -1151,6 +1178,33 @@
}
delete dlg;
}
+
+void MSNProtocol::slotNotifySocketClosed( int state )
+{
+ if ( state == 0x10 ) // connection died unexpectedly
+ {
+ //KMessageBox::error( 0, i18n( "Connection with the MSN server was lost \
unexpectedly.\nIf you are unable to reconnect, please try again later." ), i18n( \
"Connection lost - MSN Plugin - Kopete" ) ); + Disconnect();
+ kdDebug() << "MSNProtocol::slotNotifySocketClosed: Done." << endl;
+ }
+}
+
+void MSNProtocol::slotSwitchBoardClosed( MSNSwitchBoardSocket *switchboard)
+{
+ QPtrDictIterator<MSNSwitchBoardSocket> it( m_chatServices );
+ for( ; m_chatServices.count() && it.current(); ++it )
+ {
+ if( it == switchboard )
+ {
+ kdDebug() << "MSNProtocol::slotSwitchBoardClosed" << endl;
+
+ // remove from the list, then make it kill itself
+ m_chatServices.take( it.currentKey() )->deleteLater();
+ break;
+ }
+ }
+}
+
#include "msnprotocol.moc"
Index: msnprotocol.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/protocols/msn/msnprotocol.h,v
retrieving revision 1.54
diff -b -u -r1.54 msnprotocol.h
--- msnprotocol.h 2002/06/17 19:10:02 1.54
+++ msnprotocol.h 2002/06/20 10:09:31
@@ -272,6 +272,15 @@
* Show simple debugging aid
*/
void slotDebugRawCommand();
+
+ /**
+ * The Notify socket might have closed unexpectedly...
+ */
+ void slotNotifySocketClosed( int state );
+ /**
+ * The SwitchBoard socket was closed, so we remove it from the list.
+ */
+ void slotSwitchBoardClosed( MSNSwitchBoardSocket *switchboard);
private:
/**
Index: msnsocket.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/protocols/msn/msnsocket.cpp,v
retrieving revision 1.14
diff -b -u -r1.14 msnsocket.cpp
--- msnsocket.cpp 2002/06/17 19:10:02 1.14
+++ msnsocket.cpp 2002/06/20 10:09:33
@@ -397,9 +397,9 @@
kdDebug() << "MSNSocket::slotSocketClosed: socket closed. State: 0x" <<
QString::number( state, 16 ) << endl;
- if ( state == 0x40 )
setOnlineStatus( Disconnected );
+ emit( socketClosed( state ) );
}
#include "msnsocket.moc"
Index: msnsocket.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/protocols/msn/msnsocket.h,v
retrieving revision 1.8
diff -b -u -r1.8 msnsocket.h
--- msnsocket.h 2002/06/17 19:10:02 1.8
+++ msnsocket.h 2002/06/20 10:09:33
@@ -94,6 +94,12 @@
* The connection failed
*/
void connectionFailed();
+
+
+ /**
+ * The connection was closed
+ */
+ void socketClosed( int );
protected:
/**
Index: msnswitchboardsocket.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/protocols/msn/msnswitchboardsocket.cpp,v
retrieving revision 1.22
diff -b -u -r1.22 msnswitchboardsocket.cpp
--- msnswitchboardsocket.cpp 2002/06/17 19:32:40 1.22
+++ msnswitchboardsocket.cpp 2002/06/20 10:09:36
@@ -49,13 +49,15 @@
QObject::connect( this, SIGNAL( onlineStatusChanged( MSNSocket::OnlineStatus ) ),
this, SLOT( slotOnlineStatusChanged( MSNSocket::OnlineStatus ) ) );
+ QObject::connect( this, SIGNAL( socketClosed( int ) ),
+ this, SLOT( slotSocketClosed( int ) ) );
+
connect( server, port );
// we need these for the handshake later on (when we're connected)
m_ID = ID;
m_auth = auth;
- // FIXME : we have no socketClosed signal
}
void MSNSwitchBoardSocket::parseCommand( const QString &cmd, uint id,
@@ -128,7 +130,7 @@
QString len = data.section( ' ', 2, 2 );
// we need to know who's sending is the block...
- m_msgHandle = data.section( ' ', 0, 0 ); // MUAHAHAHAH
+ m_msgHandle = data.section( ' ', 0, 0 );
readBlock(len.toUInt());
}
@@ -182,14 +184,14 @@
endl;
kdDebug() << "MSNSwitchBoardService::slotReadMessage: User handle: "
- << m_msgHandle << endl; // MUAH
+ << m_msgHandle << endl;
// FIXME: THIS IS UGLY!!!!!!!!!!!!!!!!!!!!!!
KopeteContactList others;
others.append( MSNProtocol::protocol()->myself() );
KopeteMessage kmsg(
- MSNProtocol::protocol()->contacts()[ m_msgHandle ] , others, // MUAH
+ MSNProtocol::protocol()->contacts()[ m_msgHandle ] , others,
msg.right( msg.length() - msg.findRev("\r\n\r\n") - 4 ),
KopeteMessage::Inbound );
@@ -233,7 +235,7 @@
sendCommand( command + message, args + message, false );
}*/
- QString contact = MSNProtocol::protocol()->contacts()[ m_msgHandle ]->nickname(); \
// MUAH + QString contact = MSNProtocol::protocol()->contacts()[ m_msgHandle \
]->nickname(); QString message = i18n("%1 tried to send you a file.\nUnfortunately,"
" file tranfer is currently not supported.\n").arg( contact );
@@ -301,11 +303,11 @@
emit msgReceived( msg ); // send the own msg to chat window
}
-void MSNSwitchBoardSocket::slotSocketClosed()
+void MSNSwitchBoardSocket::slotSocketClosed( int /*state */)
{
// we have lost the connection, send a message to chatwindow (this will not \
displayed) emit switchBoardIsActive(false);
- delete this;
+ emit switchBoardClosed( this );
}
void MSNSwitchBoardSocket::slotCloseSession()
Index: msnswitchboardsocket.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/protocols/msn/msnswitchboardsocket.h,v
retrieving revision 1.7
diff -b -u -r1.7 msnswitchboardsocket.h
--- msnswitchboardsocket.h 2002/06/17 19:10:02 1.7
+++ msnswitchboardsocket.h 2002/06/20 10:09:36
@@ -38,7 +38,6 @@
MSNSwitchBoardSocket();
~MSNSwitchBoardSocket();
-
protected:
QString m_myHandle; // our handle
QString m_msgHandle; // the other side's handle
@@ -69,13 +68,13 @@
public slots:
void slotReadMessage( const QString &msg );
void slotSendMsg( const KopeteMessage &msg );
- void slotSocketClosed();
void slotCloseSession();
void slotInviteContact(QString handle);
void slotTypingMsg();
private slots:
void slotOnlineStatusChanged( MSNSocket::OnlineStatus status );
+ void slotSocketClosed( int /* state */ );
signals:
void msgReceived( const KopeteMessage &msg );
@@ -87,6 +86,7 @@
void switchBoardIsActive(bool);
void updateChatMember(QString,QString,bool);
void userLeftChat( QString );
+ void switchBoardClosed(MSNSwitchBoardSocket * /*switchboard*/);
private:
QStringList m_chatMembers;
_______________________________________________
Kopete-devel mailing list
Kopete-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kopete-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic