[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 15:30:24
[Download RAW message or body]

> as soon as it's ready, i'll send a new patch with 2/ 3/ 4/ included.
> i'll leave 1/ to your judgment (aka, feel free to apply the patch and get
> rid of those  convenience ctors if you like)

hear, hear!

-- 
Andres
["kmmbranchv4.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 15:21:42 -0000
@@ -21,35 +21,67 @@
 	mTimestamp = QDateTime::currentDateTime();
 	mBody = "Body not set";
 	mDirection = Outbound;
-	mBg = QColor();
-	mFg = QColor();
+	mBg = QColor(255,255,255);
+	mFg = QColor(0,0,0);
 	mFont = QFont();
 }
 
 
-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;
+	mBg = QColor(255,255,255);
+	mFg = QColor(0,0,0);
+	mFont = QFont();
+}
+
+KopeteMessage::KopeteMessage(const KopeteContact *fromKC,
+		KopeteContact* toKC, QString body, MessageDirection direction)
+{
+	mTimestamp = QDateTime::currentDateTime();
+	mFrom = fromKC;
+	mTo.append(toKC);
+	mBody = body;
+	mDirection = direction;
+	mBg = QColor(255,255,255);
+	mFg = QColor(0,0,0);
+	mFont = QFont();
 }
 
-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;
 	mBody = body;
 	mDirection = direction;
-	mBg = bg;
-	mFg = fg;
-	mFont = fnt;
+	mBg = QColor(255,255,255);
+	mFg = QColor(0,0,0);
+	mFont = QFont();
 }
+
+KopeteMessage::KopeteMessage(QDateTime timestamp,
+		const KopeteContact *fromKC, KopeteContact* toKC, QString body,
+		MessageDirection direction)
+{
+	mTimestamp = timestamp;
+	mFrom = fromKC;
+	mTo.append(toKC);
+	mBody = body;
+	mDirection = direction;
+	mBg = QColor(255,255,255);
+	mFg = QColor(0,0,0);
+	mFont = QFont();
+}
+
+#include "kopetemessage.moc"
 
 // 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 15:21:43 -0000
@@ -17,6 +17,7 @@
 #ifndef _KOPETE_MESSAGE_H
 #define _KOPETE_MESSAGE_H
 
+#include <qobject.h>
 #include <qdatetime.h>
 #include <qstring.h>
 #include <qfont.h>
@@ -25,8 +26,9 @@
 
 typedef QPtrList<KopeteContact> KopeteContactList;
 
-class KopeteMessage
+class KopeteMessage : public QObject
 {
+Q_OBJECT
 public:
 	/**
 		Direction of a message. Inbound is from the chat partner, Outbound is
@@ -40,9 +42,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,6 +60,17 @@
 
 	MessageDirection direction() const { return mDirection; }
 
+	// Mutators
+	void setFg(QColor color) { mFg = color; };
+	void setBg(QColor color) { mBg = color; };
+	void setFont(QFont font) { mFont = font; };
+
+	// Call when a message is successfully sent
+	void sent() { emit sent(*this); delete this; };
+
+signals:
+	void sent(const KopeteMessage&);
+
 protected:
 	QDateTime mTimestamp;
 
@@ -64,6 +81,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 15:21:43 -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,6 +50,8 @@
 	{
 		mLogger = 0L;
 	}
+	
+	mMessageQueue.setAutoDelete(true);
 
 }
 
@@ -89,14 +95,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 (QPtrListIterator<KopeteMessage> it(mMessageQueue); 0 != *it; ++it)
 	{
-		kdDebug() << "[KopeteMessageManager] Inserting message from " << \
                (*it).from()->name() << endl;
-		mChatWindow->messageReceived((*it));
+		kdDebug() << "[KopeteMessageManager] Inserting message from " << \
(*it)->from()->name() << endl; +		mChatWindow->messageReceived(**it);
 	}
 	mMessageQueue.clear();
-	mChatWindow->show();	// show message window again
+	mChatWindow->setActiveWindow();
+	mChatWindow->show();
+	cancelUnreadMessageEvent();
 }
 
 void KopeteMessageManager::slotReadMessages()
@@ -106,15 +114,26 @@
 
 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 = *(new KopeteMessage(mUser, mContactList, body, \
KopeteMessage::Outbound)); +
+	// Get to know when the message is sent so we can print it in the chatwindow
+	connect(&tmpMessage, SIGNAL(sent(const KopeteMessage&)), this, \
SLOT(printMessage(const KopeteMessage&))); +
+	// Send the message
+	mProtocol->sendMessage(tmpMessage);
+
+	// This should go away soon... kept until all plugins migrate to \
"Protocol::sendMessage" +	emit messageSent ( 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 +149,7 @@
 		delete mUnreadMessageEvent;
 		mUnreadMessageEvent = 0L;
 		kdDebug() << "[KopeteMessageManager] cancelUnreadMessageEvent Event Deleted" << \
                endl;
-	}		
+	}
 }
 
 void KopeteMessageManager::slotEventDeleted(KopeteEvent *e)
@@ -145,7 +164,7 @@
 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);
+	mMessageQueue.append(&msg);
 	if( mLogger )
 	{
 		mLogger->append( msg );
@@ -196,4 +215,10 @@
 	{
                 mReadMode = Popup;
 	}
+}
+
+void KopeteMessageManager::printMessage( 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 15:21:43 -0000
@@ -18,10 +18,8 @@
 #define __KOPETEMESSAGEMANAGER_H__
 
 #include <qptrlist.h>
-#include <qvaluelist.h>
 #include <qobject.h>
 
-#include "kopetemessage.h"
 #include "kopetecontact.h"
 
 class KopeteContact;
@@ -31,10 +29,11 @@
 class KopeteChatWindow;
 class KopeteEvent;
 class KopeteMessageLog;
+class KopeteProtocol;
 
 
 typedef QPtrList<KopeteContact>        KopeteContactList;
-typedef QValueList<KopeteMessage>        KopeteMessageList;
+typedef QPtrList<KopeteMessage>        KopeteMessageList;
 typedef QPtrList<KopeteMessageManager> KopeteMessageManagerList;
 
 class KopeteMessageManager : public QObject
@@ -86,35 +85,38 @@
 	 * 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; };
 
+
 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 messageSent( 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 printMessage( const KopeteMessage& 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 +125,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 15:21:43 -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 15:21:43 -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 15:21:43 -0000
@@ -24,6 +24,7 @@
 
 class AddContactPage;
 class QString;
+class KopeteMessage;
 
 /**
  * @author duncan
@@ -52,7 +53,9 @@
 	// 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;
+
+	virtual void sendMessage(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 15:21:43 -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