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

List:       kopete-devel
Subject:    Re: [Kopete-devel] patch, and other stuff
From:       Andres Krapf <dae () chez ! com>
Date:       2002-05-05 19:17:43
[Download RAW message or body]

>I'm working on several MSN related issues outside the branch in HEAD, so I
> can't commit. Could you add the callback and ditch the whole
> QObject/signal/slot mess we created in KopeteMessage and repost the patch?
>
> Means you can revert quite some of your code, like QValueList can return,
> mocs no longer need inclusion, etc. Also means the code hopefully will be
> more readable and maintainable. Sorry for the extra work... :/

yep... warning, not fully tested :P

last patch of the day... i'm leaving.
btw, this will break protocols using the messageSent() signal emitted by kmm. 
that's to force them to use the newer (and saner) scheme (aka 
protocol::sendMessage())

cheers,

-- 
Andres
["kmmbranchv6.patch" (text/x-diff)]

Index: libkopete/kopetemessage.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopetemessage.cpp,v
retrieving revision 1.4.2.3
diff -u -r1.4.2.3 kopetemessage.cpp
--- libkopete/kopetemessage.cpp	1 May 2002 02:40:48 -0000	1.4.2.3
+++ libkopete/kopetemessage.cpp	5 May 2002 19:07:08 -0000
@@ -27,28 +27,64 @@
 }
 
 
-KopeteMessage::KopeteMessage(const KopeteContact *fromKC, KopeteContactList toKC, \
QString body, MessageDirection direction, QColor fg, QColor bg, QFont fnt) \
+KopeteMessage::KopeteMessage(const KopeteContact *fromKC, +		KopeteContactList toKC, \
QString body, MessageDirection direction)  {
-	mTimestamp = QDateTime::currentDateTime();
-	mFrom = fromKC;
-	mTo = toKC;
-	mBody = body;
-	mDirection = direction;
-	mBg = bg;
-	mFg = fg;
-	mFont = fnt;
+	init(QDateTime::currentDateTime(), fromKC, toKC, body, direction);
+}
+
+KopeteMessage::KopeteMessage(const KopeteContact *fromKC,
+		KopeteContact* toKC, QString body, MessageDirection direction)
+{
+	KopeteContactList kcl;
+	kcl.append(toKC);
+	init(QDateTime::currentDateTime(), fromKC, kcl, body, direction);
 }
 
-KopeteMessage::KopeteMessage(QDateTime timestamp, const KopeteContact *fromKC, \
KopeteContactList toKC, QString body, MessageDirection direction, QColor fg, QColor \
bg, QFont fnt) +KopeteMessage::KopeteMessage(QDateTime timeStamp,
+		const KopeteContact *fromKC, KopeteContactList toKC, QString body,
+		MessageDirection direction)
 {
-	mTimestamp = timestamp;
-	mFrom = fromKC;
-	mTo = toKC;
+	init(timeStamp, fromKC, toKC, body, direction);
+}
+
+KopeteMessage::KopeteMessage(QDateTime timeStamp,
+		const KopeteContact *fromKC, KopeteContact* toKC, QString body,
+		MessageDirection direction)
+{
+	KopeteContactList kcl;
+	kcl.append(toKC);
+	init(timeStamp, fromKC, kcl, body, direction);
+}
+
+void KopeteMessage::setFg(QColor color) {
+	mFg = color;
+}
+
+void KopeteMessage::setBg(QColor color) {
+	mBg = color;
+}
+
+void KopeteMessage::setFont(QFont font) {
+	mFont = font;
+}
+
+void KopeteMessage::init(
+		QDateTime timeStamp,
+		const KopeteContact * from,
+		KopeteContactList to,
+		QString body,
+		MessageDirection direction) {
+
+	mTimestamp = timeStamp;
+	mFrom = from;
+	mTo = to;
 	mBody = body;
 	mDirection = direction;
-	mBg = bg;
-	mFg = fg;
-	mFont = fnt;
+	mFg = QColor();
+	mBg = QColor();
+	mFont = QFont();
+
 }
 
 // vim: set noet ts=4 sts=4 sw=4:
Index: libkopete/kopetemessage.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopetemessage.h,v
retrieving revision 1.6.2.3
diff -u -r1.6.2.3 kopetemessage.h
--- libkopete/kopetemessage.h	1 May 2002 02:40:48 -0000	1.6.2.3
+++ libkopete/kopetemessage.h	5 May 2002 19:07:09 -0000
@@ -40,9 +40,13 @@
 		characters must be escaped.
 	*/
 	KopeteMessage();
-	KopeteMessage(const KopeteContact *, KopeteContactList, QString, MessageDirection, \
                QColor = QColor(), QColor = QColor(), QFont = QFont() );
-	KopeteMessage(QDateTime, const KopeteContact *, KopeteContactList, QString, \
MessageDirection, QColor = QColor(), QColor = QColor(), QFont = QFont() ); \
+	KopeteMessage(const KopeteContact *, KopeteContactList, QString, MessageDirection \
); +	KopeteMessage(const KopeteContact*, KopeteContact*, QString, MessageDirection );
 
+	KopeteMessage(QDateTime, const KopeteContact *, KopeteContactList, QString, \
MessageDirection ); +	KopeteMessage(QDateTime, const KopeteContact *, KopeteContact \
*, QString, MessageDirection ); +
+	// Accessors
 	QDateTime timestamp() const { return mTimestamp; }
 
 	const KopeteContact *from() const { return mFrom; }
@@ -54,7 +58,21 @@
 
 	MessageDirection direction() const { return mDirection; }
 
+	// Mutators
+	void setFg(QColor color);
+	void setBg(QColor color);
+	void setFont(QFont font);
+
 protected:
+	// Helper for constructors
+	void init(
+			QDateTime timeStamp,
+			const KopeteContact * from,
+			KopeteContactList to,
+			QString body,
+			MessageDirection direction
+	);
+
 	QDateTime mTimestamp;
 
 	const KopeteContact *mFrom;
@@ -64,6 +82,7 @@
 	QColor mFg, mBg;
 
 	MessageDirection mDirection;
+
 };
 
 #endif
Index: libkopete/kopetemessagemanager.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopetemessagemanager.cpp,v
retrieving revision 1.18.2.5
diff -u -r1.18.2.5 kopetemessagemanager.cpp
--- libkopete/kopetemessagemanager.cpp	3 May 2002 05:56:02 -0000	1.18.2.5
+++ libkopete/kopetemessagemanager.cpp	5 May 2002 19:07:09 -0000
@@ -17,26 +17,30 @@
 */
 
 #include "kopetemessagemanager.h"
+
+#include "kopete.h"
 #include "kopetechatwindow.h"
 #include "kopeteevent.h"
-#include "kopete.h"
+#include "kopetemessage.h"
+#include "kopeteprotocol.h"
 
 #include "messagelog.h"
 #include <kdebug.h>
 #include <klocale.h>
 
 KopeteMessageManager::KopeteMessageManager( const KopeteContact *user, \
                KopeteContactList others,
-		QString logFile, QObject *parent, const char *name) : QObject( parent, name)
+		KopeteProtocol* protocol, QString logFile, QObject *parent, const char *name) : \
QObject( parent, name)  {
 
 	mContactList = others;
 	mUser = user;
+	mProtocol = protocol;
 	mChatWindow = 0L;
 	mUnreadMessageEvent = 0L;
 
 	readModeChanged();
 	connect( kopeteapp->appearance(), SIGNAL(queueChanged()), this, \
                SLOT(readModeChanged()) );
-	
+
 	if (!logFile.isEmpty())
 	{
 		QString logFileName = "kopete/" + logFile;
@@ -46,7 +50,7 @@
 	{
 		mLogger = 0L;
 	}
-
+	
 }
 
 KopeteMessageManager::~KopeteMessageManager()
@@ -89,14 +93,16 @@
 		connect ( mChatWindow, SIGNAL(sendMessage(const QString &)), this, \
SLOT(messageSentFromWindow(const QString &)) );  connect ( mChatWindow, \
SIGNAL(closeClicked()), this, SLOT(chatWindowClosing()) );  }
-	
-	for (KopeteMessageList::Iterator it = mMessageQueue.begin(); it != \
mMessageQueue.end(); it++) +
+	for (KopeteMessageList::Iterator it = mMessageQueue.begin(); mMessageQueue.end() != \
it; ++it)  {
 		kdDebug() << "[KopeteMessageManager] Inserting message from " << \
                (*it).from()->name() << endl;
-		mChatWindow->messageReceived((*it));
+		mChatWindow->messageReceived(*it);
 	}
 	mMessageQueue.clear();
-	mChatWindow->show();	// show message window again
+	mChatWindow->setActiveWindow();
+	mChatWindow->show();
+	cancelUnreadMessageEvent();
 }
 
 void KopeteMessageManager::slotReadMessages()
@@ -106,15 +112,20 @@
 
 void KopeteMessageManager::messageSentFromWindow(const QString &message)
 {
+	// Create the kopete message
 	QString body = message;
-	KopeteMessage tmpmessage(mUser, mContactList, body, KopeteMessage::Outbound);
-	emit messageSent ( tmpmessage );
+	KopeteMessage tmpMessage(mUser, mContactList, body, KopeteMessage::Outbound);
+
+	// Send the message
+	mProtocol->sendMessage(tmpMessage);
+
+	// What is this doing here ???? messages should be read when they arrive, not when \
they're sent  readMessages();
 }
 
 void KopeteMessageManager::chatWindowClosing()
 {
-	kdDebug() << "[KopeteMessageManager] Chat Window closed, now 0L" << endl;	
+	kdDebug() << "[KopeteMessageManager] Chat Window closed, now 0L" << endl;
 	mChatWindow = 0L;
 }
 
@@ -130,7 +141,7 @@
 		delete mUnreadMessageEvent;
 		mUnreadMessageEvent = 0L;
 		kdDebug() << "[KopeteMessageManager] cancelUnreadMessageEvent Event Deleted" << \
                endl;
-	}		
+	}
 }
 
 void KopeteMessageManager::slotEventDeleted(KopeteEvent *e)
@@ -140,9 +151,7 @@
 		mUnreadMessageEvent = 0L;
 }
 
-
-
-void KopeteMessageManager::appendMessage( const KopeteMessage &msg )
+void KopeteMessageManager::appendMessage( const KopeteMessage& msg )
 {
 	//mMessageQueue.append( KopeteMessage( msg.timestamp(), msg.from(), msg.to(), \
msg.body(), msg.direction(),msg.fg(), msg.bg(), msg.font()));  \
mMessageQueue.append(msg); @@ -196,4 +205,10 @@
 	{
                 mReadMode = Popup;
 	}
+}
+
+void KopeteMessageManager::messageSent( const KopeteMessage& message ) {
+
+	mChatWindow->messageReceived(message);
+
 }
Index: libkopete/kopetemessagemanager.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopetemessagemanager.h,v
retrieving revision 1.11.2.5
diff -u -r1.11.2.5 kopetemessagemanager.h
--- libkopete/kopetemessagemanager.h	3 May 2002 06:52:57 -0000	1.11.2.5
+++ libkopete/kopetemessagemanager.h	5 May 2002 19:07:09 -0000
@@ -18,19 +18,18 @@
 #define __KOPETEMESSAGEMANAGER_H__
 
 #include <qptrlist.h>
-#include <qvaluelist.h>
 #include <qobject.h>
 
-#include "kopetemessage.h"
 #include "kopetecontact.h"
+#include "kopetemessage.h"
 
 class KopeteContact;
-class KopeteMessage;
 class KopeteMessageManager;
 class QObject;
 class KopeteChatWindow;
 class KopeteEvent;
 class KopeteMessageLog;
+class KopeteProtocol;
 
 
 typedef QPtrList<KopeteContact>        KopeteContactList;
@@ -54,7 +53,7 @@
 	/**
 	 * Append a message to the queue
 	 */
-	void appendMessage( const KopeteMessage &msg );
+	void appendMessage( const KopeteMessage& msg );
 
 	/**
 	 * Add a contact to the session
@@ -86,35 +85,41 @@
 	 * Get a list of all contacts in the session
 	 */
 	const KopeteContactList& members() const { return mContactList; }; /* Sorry, had to \
                change this to members(), it was conflicting with kxContact */
-    /**
+	/**
 	 * Get athe local user in the session
 	 */
 	const KopeteContact* user() const { return mUser; };
 
+	/**
+	 * Call when a message is actually sent over the wire
+	 */
+	void messageSent( const KopeteMessage& message );
+
+
 signals:
 	/**
 	 * A message has been sent by the user or a plugin. The protocol should
 	 * connect to this signal to actually send the message over the wire.
 	 */
-	void messageSent( const KopeteMessage msg );
 	void dying( KopeteMessageManager *);
 
 public slots:
 	void readModeChanged();
-	
+
 protected slots:
 	void cancelUnreadMessageEvent();
 	void slotEventDeleted(KopeteEvent *);
-    void chatWindowClosing();
+	void chatWindowClosing();
 	void messageSentFromWindow( const QString &message);
 	void slotReadMessages();
+
 private:
 	/**
 	 * Create a message manager. This constructor is private, because the
 	 * static factory method createSession() creates the object. You may
 	 * not create instances yourself directly!
 	 */
-	KopeteMessageManager( const KopeteContact *user, KopeteContactList others,
+	KopeteMessageManager( const KopeteContact *user, KopeteContactList others, \
KopeteProtocol* protocol,  QString logFile = QString::null, QObject *parent = 0, \
const char *name = 0 );  
 	KopeteContactList mContactList;
@@ -123,6 +128,7 @@
 	KopeteEvent *mUnreadMessageEvent;
 	KopeteMessageList mMessageQueue;
 	KopeteMessageLog *mLogger;
+	KopeteProtocol* mProtocol;
 	int mReadMode;
 };
 
Index: libkopete/kopetemessagemanagerfactory.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopetemessagemanagerfactory.cpp,v
retrieving revision 1.7.2.2
diff -u -r1.7.2.2 kopetemessagemanagerfactory.cpp
--- libkopete/kopetemessagemanagerfactory.cpp	3 May 2002 06:52:57 -0000	1.7.2.2
+++ libkopete/kopetemessagemanagerfactory.cpp	5 May 2002 19:07:09 -0000
@@ -29,9 +29,18 @@
 {
 }
 
+KopeteMessageManager* KopeteMessageManagerFactory::create(
+	const KopeteContact *user, KopeteContact* other, KopeteProtocol* protocol,
+	QString logFile)
+{
+	KopeteContactList tempKcl;
+	tempKcl.append(other);
+	return (create(user, tempKcl, protocol, logFile));
+}
+
 KopeteMessageManager *KopeteMessageManagerFactory::create(
 	const KopeteContact *user, KopeteContactList _contacts, /* Touch that underscore \
                and you die, along with ICQ not compiling */
-	QString logFile )
+	KopeteProtocol* protocol, QString logFile )
 {
 	bool createNewSession = false;
 	KopeteMessageManager *tmp;
@@ -39,14 +48,14 @@
 	{
     	if ( user == tmp->user() )
 		{
-			kdDebug() << "[KopeteMessageManagerFactory] User match, looking session members" \
<< endl;	 +			kdDebug() << "[KopeteMessageManagerFactory] User match, looking session \
members" << endl;  KopeteContact *tmp_contact;
 			KopeteContactList contactlist = tmp->members();
             for (  tmp_contact = contactlist.first(); tmp_contact ; tmp_contact = \
contactlist.next() )  {
 				if ( !_contacts.containsRef( tmp_contact ) )
 				{
-					kdDebug() << "[KopeteMessageManagerFactory] create() Oops, contact not found! \
new session needed!" << endl;	 +					kdDebug() << "[KopeteMessageManagerFactory] \
create() Oops, contact not found! new session needed!" << endl;  createNewSession = \
true;  break;
 				}
@@ -55,15 +64,15 @@
 			{
 				/* current session (tmp) is the same session the user is requesting */
 				return tmp;
-			}		
+			}
 		}
 		else
 		{
-			kdDebug() << "[KopeteMessageManagerFactory] User doesnt match, trying next \
session" << endl;	 +			kdDebug() << "[KopeteMessageManagerFactory] User doesnt match, \
trying next session" << endl;  }
 	}
-	
-	KopeteMessageManager *session = new KopeteMessageManager ( user, _contacts , \
logFile); +
+	KopeteMessageManager *session = new KopeteMessageManager ( user, _contacts, \
protocol, logFile);  connect( session, SIGNAL(dying(KopeteMessageManager*)), this, \
SLOT(slotRemoveSession(KopeteMessageManager*)));  (mSessionList).append(session);
 	return (session);
@@ -77,4 +86,3 @@
 }
 
 // vim: set noet ts=4 sts=4 sw=4:
-
Index: libkopete/kopetemessagemanagerfactory.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopetemessagemanagerfactory.h,v
retrieving revision 1.7.2.1
diff -u -r1.7.2.1 kopetemessagemanagerfactory.h
--- libkopete/kopetemessagemanagerfactory.h	3 May 2002 06:52:57 -0000	1.7.2.1
+++ libkopete/kopetemessagemanagerfactory.h	5 May 2002 19:07:09 -0000
@@ -27,9 +27,9 @@
 class KopeteMessageManager;
 class KopeteMessage;
 class KopeteContact;
+class KopeteProtocol;
 
 typedef QPtrList<KopeteContact>        KopeteContactList;
-typedef QValueList<KopeteMessage>        KopeteMessageList;
 typedef QPtrList<KopeteMessageManager> KopeteMessageManagerList;
 
 class KopeteMessageManagerFactory : public QObject
@@ -46,8 +46,14 @@
 	 * it will be reused. Otherwise a new session is created.
 	 */
 	KopeteMessageManager* create( const KopeteContact *user,
-		KopeteContactList _contacts , QString logFile = QString::null );
-	
+		KopeteContactList _contacts, KopeteProtocol* protocol, QString logFile = \
QString::null ); +
+	/**
+	 * Overloaded function for convenience. Use for one-to-one KMM creation
+	 */
+	KopeteMessageManager* create( const KopeteContact *user,
+		KopeteContact* other, KopeteProtocol* protocol, QString logFile = QString::null );
+
 	/**
 	 * Get a list of all open sessions
 	 */
Index: libkopete/kopeteprotocol.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopeteprotocol.h,v
retrieving revision 1.2
diff -u -r1.2 kopeteprotocol.h
--- libkopete/kopeteprotocol.h	13 Apr 2002 03:45:41 -0000	1.2
+++ libkopete/kopeteprotocol.h	5 May 2002 19:07:09 -0000
@@ -24,6 +24,7 @@
 
 class AddContactPage;
 class QString;
+class KopeteMessage;
 
 /**
  * @author duncan
@@ -52,7 +53,10 @@
 	// plugins should also return TRUE for modes like occupied not-vailable etc.
 	virtual bool isAway(void) const = 0;
 
-	virtual AddContactPage *createAddContactWidget(QWidget *parent)=0;
+	virtual AddContactPage *createAddContactWidget(QWidget *parent) = 0;
+
+	// This method HAS to be reimplemented by subclasses. it will be virtual pure soon.
+	virtual void sendMessage(const KopeteMessage&) {};
 
 	/**
 	 * The icon of the plugin as shown in the status bar
Index: libkopete/ui/kopetechatwindow.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/ui/kopetechatwindow.h,v
retrieving revision 1.8.2.1
diff -u -r1.8.2.1 kopetechatwindow.h
--- libkopete/ui/kopetechatwindow.h	30 Apr 2002 12:34:17 -0000	1.8.2.1
+++ libkopete/ui/kopetechatwindow.h	5 May 2002 19:07:09 -0000
@@ -28,7 +28,6 @@
 class KopeteMessage;
 
 typedef QPtrList<KopeteContact>        KopeteContactList;
-typedef QValueList<KopeteMessage>        KopeteMessageList;
 
 #define WIDGET_OLDSCHOOL	1
 #define WIDGET_EMAIL		2


_______________________________________________
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