This is a part of refactoring of Kopete4.

Today, protocols can see more than a plain text for a status message. Example 
is in MSN the NowListening thingy. Also in Jabber, the User Tune, User Mood 
exists. Those are extended presence.

So I made a first draft of Kopete::StatusMessage that encapsulate this. 
It can contains the conventional text status message. But metadata can be 
added to the message.

I attached two patches. kopete_statusmessage_v1.patch.gz is the full diff for 
the whole Kopete tree that include refactoring in NowListening plugin and MSN 
plugin.
libkopete_statusmessage_v1.diff is for those that want a quick look on 
Kopete::StatusMessage class and test, and additions to the Kopete API.

Looking for inputs for your needs about this matter.

-- 
Michaël Larouche (Shock The Dark Mage)
KDE developer working on Kopete, Kamefu...on dial-up :P
--------------------------------------
Blog: http://mlarouche.blogspot.com/
MSN/Email: [EMAIL PROTECTED]
IRC: irc.freenode.org/DarkShock on #kopete,#solid,#kamefu,#plasma
Jabber: [EMAIL PROTECTED]
Index: kopetestatusmessage.cpp
===================================================================
--- kopetestatusmessage.cpp	(revision 0)
+++ kopetestatusmessage.cpp	(revision 0)
@@ -0,0 +1,84 @@
+/*
+    kopetestatusmessage.cpp - Describle a status message and it's metadata.
+
+    Copyright (c) 2006  by Michaël Larouche          <[EMAIL PROTECTED]>
+
+    Kopete    (c) 2002-2006 by the Kopete developers <kopete-devel@kde.org>
+
+    *************************************************************************
+    *                                                                       *
+    * This library is free software; you can redistribute it and/or         *
+    * modify it under the terms of the GNU Lesser General Public            *
+    * License as published by the Free Software Foundation; either          *
+    * version 2 of the License, or (at your option) any later version.      *
+    *                                                                       *
+    *************************************************************************
+*/
+#include "kopetestatusmessage.h"
+
+#include <QHash>
+
+namespace Kopete
+{
+
+class StatusMessage::Private : public KShared
+{
+public:
+	Private()
+	{}
+
+	QString statusMessage;
+	QHash<QString, QVariant> metaData;
+};	
+
+StatusMessage::StatusMessage()
+ : d(new Private)
+{}
+
+StatusMessage::StatusMessage(const QString &message)
+ : d(new Private)
+{
+	d->statusMessage = message;
+}
+
+StatusMessage::~StatusMessage()
+{}
+
+StatusMessage::StatusMessage(const StatusMessage &copy)
+ : d(copy.d)
+{}
+
+StatusMessage &StatusMessage::operator=(const StatusMessage &other)
+{
+	d = other.d;
+	return *this;
+}
+
+void StatusMessage::setMessage(const QString &message)
+{
+	//d.detach();
+	d->statusMessage = message;
+}
+
+QString StatusMessage::message() const
+{
+	return d->statusMessage;
+}
+
+void StatusMessage::addMetaData(const QString &key, const QVariant &value)
+{
+	//d.detach();
+	d->metaData.insert(key, value);	
+}
+
+bool StatusMessage::hasMetaData(const QString &key) const
+{
+	return d->metaData.contains(key);
+}
+
+QVariant StatusMessage::metaData(const QString &key) const
+{
+	return d->metaData[key];
+}
+
+}
Index: kopetecontact.h
===================================================================
--- kopetecontact.h	(revision 509668)
+++ kopetecontact.h	(working copy)
@@ -42,6 +42,8 @@
 class Plugin;
 class Protocol;
 class Account;
+class StatusMessage;
+
 typedef QList<Group *> GroupList;
 
 /**
@@ -212,6 +214,16 @@
 	void setOnlineStatus(const OnlineStatus &status);
 
 	/**
+	 * @brief Get the current status message of the contact.
+	 * @return the status in a Kopete::StatusMessage.
+	 */
+	Kopete::StatusMessage statusMessage() const;
+	/**
+	 * @brief Set the contact's status message.
+	 */
+	void setStatusMessage(const Kopete::StatusMessage &statusMessage);
+	 
+	/**
 	 * \brief Get the set of custom menu items for this contact
 	 *
 	 * Returns a set of custom menu items for the context menu
Index: kopetecontact.cpp
===================================================================
--- kopetecontact.cpp	(revision 509668)
+++ kopetecontact.cpp	(working copy)
@@ -47,6 +47,7 @@
 #include "kopetebehaviorsettings.h"
 #include "metacontactselectorwidget.h"
 #include "kopeteemoticons.h"
+#include "kopetestatusmessage.h"
 
 //For the moving to another metacontact dialog
 #include <qlabel.h>
@@ -76,7 +77,7 @@
 	unsigned long int idleTime;
 
 	Kopete::ContactProperty::Map properties;
-
+	Kopete::StatusMessage statusMessage;
 };
 
 Contact::Contact( Account *account, const QString &contactId,
@@ -166,6 +167,17 @@
 		emit onlineStatusChanged( this, status, oldStatus );
 }
 
+Kopete::StatusMessage Contact::statusMessage() const
+{
+	return d->statusMessage;
+}
+
+void Contact::setStatusMessage( const Kopete::StatusMessage &statusMessage )
+{
+	// TODO: Maybe set awayMessage property here.
+	d->statusMessage = statusMessage;
+}
+
 void Contact::slotAccountIsConnectedChanged()
 {
 	if ( this == account()->myself() )
Index: kopeteaccount.cpp
===================================================================
--- kopeteaccount.cpp	(revision 509668)
+++ kopeteaccount.cpp	(working copy)
@@ -48,6 +48,7 @@
 #include "kopeteuiglobal.h"
 #include "kopeteblacklister.h"
 #include "kopeteonlinestatusmanager.h"
+#include "kopetestatusmessage.h"
 #include "editaccountwidget.h"
 
 namespace Kopete
Index: kopetestatusmessage.h
===================================================================
--- kopetestatusmessage.h	(revision 0)
+++ kopetestatusmessage.h	(revision 0)
@@ -0,0 +1,113 @@
+/*
+    kopetestatusmessage.h - Describle a status message and it's metadata.
+
+    Copyright (c) 2006  by Michaël Larouche          <[EMAIL PROTECTED]>
+
+    Kopete    (c) 2002-2006 by the Kopete developers <kopete-devel@kde.org>
+
+    *************************************************************************
+    *                                                                       *
+    * This library is free software; you can redistribute it and/or         *
+    * modify it under the terms of the GNU Lesser General Public            *
+    * License as published by the Free Software Foundation; either          *
+    * version 2 of the License, or (at your option) any later version.      *
+    *                                                                       *
+    *************************************************************************
+*/
+#ifndef KOPETESTATUSMESSAGE_H
+#define KOPETESTATUSMESSAGE_H
+
+#include <QVariant>
+#include <QString>
+
+#include <ksharedptr.h>
+#include "kopete_export.h"
+
+namespace Kopete
+{
+
+/**
+ * @brief This class encapsulate a status message.
+ * A status message to today(as 2006) standards is more than a simple text. 
+ * It can be used to show the current listening song, current playing game, show our mood etc..
+ * So this class allows to add metadata to the status message where protocols will be able to use properly.
+ * 
+ * @code
+ * // Create a new status message.
+ * Kopete::StatusMessage message;
+ * message.setMessage( QString("Writing APIDOX") );
+ * message.addMetaData( "musicPlayer", "amaroK" );
+ * message.addMetaData( "artist", "Liquid Tension Experiment" );
+ * message.addMetaData( "title", "Acid Rain" );
+ * message.addMetaData( "album", "Liquid Tension Experiment 2" );
+ * 
+ * account->setStatusMessage(message);
+ * @endcode
+ * This class is implicit shared.
+ * @author Michaël Larouche
+ */
+class KOPETE_EXPORT StatusMessage
+{
+public:
+	/**
+	 * Create a empty status message.
+	 */
+	StatusMessage();
+	/**
+	 * Create a new status message with the specified status message.
+	 * @param statusMessage the status message.
+	 */
+	explicit StatusMessage(const QString &statusMessage);
+	/**
+	 * StatusMessage copy constructor. 
+	 * Very cheap because the class is implicit shared.
+	 */
+	StatusMessage(const StatusMessage &copy);
+	/**
+	 * StatusMessage destructor
+	 */
+	~StatusMessage();
+	/**
+	 * StatusMessage copy-assignment operator.
+	 * Very cheap because the class is implicit shared.
+	 */
+	StatusMessage &operator=(const StatusMessage &other);
+
+	/**
+	 * Add a metadata to the status message.
+	 * @param key Key to identity the metadata.
+	 * @param value Value for the metadata.
+	 */
+	void addMetaData(const QString &key, const QVariant &value);
+	/**
+	 * Check if the status message has the specified metadata.
+	 * @param key Key of the metadata.
+	 * @return true if the metadata is present.
+	 */
+	bool hasMetaData(const QString &key) const;
+	/**
+	 * Retrieve the specified metadata.
+	 * @param key Key of the metadata
+	 * @return The medata value
+	 */
+	QVariant metaData(const QString &key) const;
+
+	/**
+	 * Set a new status message.
+	 * @param message New status message.
+	 */ 
+	void setMessage(const QString &message);
+	/**
+	 * Return the current status message.
+	 * @return The current status message.
+	 */
+	QString message() const;
+
+private:
+	class Private;
+	KSharedPtr<Private> d;
+};
+
+}
+
+#endif
Index: tests/mock/kopeteaccount_mock.h
===================================================================
--- tests/mock/kopeteaccount_mock.h	(revision 509668)
+++ tests/mock/kopeteaccount_mock.h	(working copy)
@@ -23,6 +23,7 @@
 class Kopete::Protocol;
 class Kopete::OnlineStatus;
 class Kopete::MetaContact;
+class Kopete::StatusMessage;
 
 class QString;
 
@@ -43,6 +44,7 @@
 	virtual void connect( const Kopete::OnlineStatus& initialStatus = OnlineStatus() );
 	virtual void disconnect();
 	virtual void setOnlineStatus( const Kopete::OnlineStatus& status , const QString &reason = QString::null );
+	virtual void setOnlineStatus( const Kopete::OnlineStatus& status, const Kopete::StatusMessage &statusMessage );
 };
 
 } // end ns Kopete::Test::Mock
Index: tests/mock/kopeteaccount_mock.cpp
===================================================================
--- tests/mock/kopeteaccount_mock.cpp	(revision 509668)
+++ tests/mock/kopeteaccount_mock.cpp	(working copy)
@@ -18,6 +18,7 @@
 #include "kopeteaccount_mock.h"
 #include "kopetemetacontact.h"
 #include "kopeteaccount_mock.h"
+#include "kopetestatusmessage.h"
 
 namespace Kopete
 {
@@ -56,6 +57,11 @@
 	// do nothing
 }
 
+void Account::setOnlineStatus( const Kopete::OnlineStatus& status, const Kopete::StatusMessage& statusMessage)
+{
+	// do nothing
+}
+
 } // end ns Kopete::Test::Mock
 } // end ns Kopete::Test
 } // end ns Kopete
Index: tests/statusmessage_test.cpp
===================================================================
--- tests/statusmessage_test.cpp	(revision 0)
+++ tests/statusmessage_test.cpp	(revision 0)
@@ -0,0 +1,55 @@
+/*
+    Unit test for Kopete::StatusMessage class.
+
+    Copyright (c) 2006  by Michaël Larouche          <[EMAIL PROTECTED]>
+
+    Kopete    (c) 2002-2006 by the Kopete developers <kopete-devel@kde.org>
+
+    *************************************************************************
+    *                                                                       *
+    * This library is free software; you can redistribute it and/or         *
+    * modify it under the terms of the GNU Lesser General Public            *
+    * License as published by the Free Software Foundation; either          *
+    * version 2 of the License, or (at your option) any later version.      *
+    *                                                                       *
+    *************************************************************************
+*/
+#include "statusmessage_test.h"
+
+#include <qtest_kde.h>
+#include <QLatin1String>
+
+#include "kopetestatusmessage.h"
+
+QTEST_KDEMAIN( StatusMessage_Test, GUI )
+
+
+void StatusMessage_Test::testNormalStatus()
+{
+	Kopete::StatusMessage status1;
+	status1.setMessage( QLatin1String("http://kopete.kde.org/";) );
+
+	QCOMPARE( status1.message(), QString("http://kopete.kde.org/";) );
+
+	Kopete::StatusMessage status2( QLatin1String("QTestLib rocks !") );
+	
+	QCOMPARE( status2.message(), QString("QTestLib rocks !") );
+}
+
+void StatusMessage_Test::testMusicMetaData()
+{
+	Kopete::StatusMessage status2;
+	status2.setMessage( QLatin1String("Jordan Rudess = keyboard god") );
+
+	status2.addMetaData( QLatin1String("musicPlayer"), QString("amaroK") );
+	status2.addMetaData( QLatin1String("artist"), QString("Dream Theater") );
+	status2.addMetaData( QLatin1String("title"), QString("Beyond This Life") );
+	status2.addMetaData( QLatin1String("album"), QString("Live Scenes From New York") );
+	
+	QCOMPARE( status2.hasMetaData("hjjhadhasdasd"), false );
+	QCOMPARE( status2.hasMetaData("artist"), true );
+	QCOMPARE( status2.metaData("artist").toString(), QString("Dream Theater") );
+	QCOMPARE( status2.message(), QString("Jordan Rudess = keyboard god") );
+}
+
+#include "statusmessage_test.moc"
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision 509668)
+++ tests/Makefile.am	(working copy)
@@ -8,8 +8,8 @@
 
 #check_LTLIBRARIES = kunittest_kopetemessage_test.la kunittest_kopetecontactlist_test.la
 
-check_PROGRAMS = kopeteemoticontest kopetemessage_test kopetetask_test
-TESTS = kopeteemoticontest kopetemessage_test kopetetask_test
+check_PROGRAMS = kopeteemoticontest kopetemessage_test kopetetask_test statusmessage_test
+TESTS = kopeteemoticontest kopetemessage_test kopetetask_test statusmessage_test
 
 kopeteemoticontest_SOURCES = kopeteemoticontest.cpp
 
@@ -17,6 +17,8 @@
 
 kopetetask_test_SOURCES = kopetetask_test.cpp
 
+statusmessage_test_SOURCES = statusmessage_test.cpp
+
 #check_PROGRAMS = kopetewallettest_program kopetepasswordtest_program
 
 #kunittest_kopetepropertiestest_la_SOURCES = kopetepropertiestest.cpp ../kopeteproperties.cpp
Index: tests/statusmessage_test.h
===================================================================
--- tests/statusmessage_test.h	(revision 0)
+++ tests/statusmessage_test.h	(revision 0)
@@ -0,0 +1,29 @@
+/*
+    Unit test for Kopete::StatusMessage class.
+
+    Copyright (c) 2006  by Michaël Larouche          <[EMAIL PROTECTED]>
+
+    Kopete    (c) 2002-2006 by the Kopete developers <kopete-devel@kde.org>
+
+    *************************************************************************
+    *                                                                       *
+    * This library is free software; you can redistribute it and/or         *
+    * modify it under the terms of the GNU Lesser General Public            *
+    * License as published by the Free Software Foundation; either          *
+    * version 2 of the License, or (at your option) any later version.      *
+    *                                                                       *
+    *************************************************************************
+*/
+#ifndef KOPETESTATUSMESSAGE_TEST_H
+#define KOPETESTATUSMESSAGE_TEST_H
+
+#include <QObject>
+
+class StatusMessage_Test : public QObject
+{
+	Q_OBJECT
+private slots:
+	void testNormalStatus();
+	void testMusicMetaData();
+};
+#endif
Index: kopeteaccount.h
===================================================================
--- kopeteaccount.h	(revision 509668)
+++ kopeteaccount.h	(working copy)
@@ -40,6 +40,7 @@
 class Group;
 class OnlineStatus;
 class BlackLister;
+class StatusMessage;
 
 /**
  * The Kopete::Account class handles one account.
@@ -469,10 +470,17 @@
 	/**
 	 * Reimplement this function to set the online status
 	 * @param status is the new status
-	 * @param reason is the away message to set.
+	 * @param reason is the status message to set.
 	 * @note If needed, you need to connect.  if the offline status is given, you should disconnect
 	 */
 	virtual void setOnlineStatus( const Kopete::OnlineStatus& status , const QString &reason = QString::null ) = 0;
+	/**
+	 * Reimplement this function to set the online status and the status message(with metadata).
+	 * @param status is the new status.
+	 * @param statusMessage is the status message to set. (Use Kopete::StatusMessage).
+	 * @note If needed, you need to connect.  if the offline status is given, you should disconnect
+	 */
+	virtual void setOnlineStatus( const Kopete::OnlineStatus& status, const Kopete::StatusMessage &statusMessage) = 0;
 
 	/**
 	 * Display the edit account widget for the account
Index: Makefile.am
===================================================================
--- Makefile.am	(revision 509668)
+++ Makefile.am	(working copy)
@@ -13,20 +13,20 @@
 
 lib_LTLIBRARIES = libkopete.la
 
-libkopete_la_SOURCES = connectionmanager.cpp \
-	kopeteonlinestatus.cpp kopeteonlinestatusmanager.cpp kopeteprotocol.cpp kopetecontact.cpp \
-	kopetepluginmanager.cpp kopeteplugin.cpp kopetemessage.cpp kopetechatsession.cpp \
-	kopetechatsessionmanager.cpp kopetecontactlist.cpp kopetemetacontact.cpp \
-	kopetetransfermanager.cpp kopetegroup.cpp kopeteaccountmanager.cpp kopeteaccount.cpp \
-	kopetecontactlistelement.cpp kopetecommand.cpp kopetecommandhandler.cpp kopeteaway.cpp kopeteawayaction.cpp \
-	kopetewalletmanager.cpp kopetecontactproperty.cpp kopetepassword.cpp kopeteglobal.cpp \
-	kopeteuiglobal.cpp kopetepasswordedaccount.cpp kopetemimetypehandler.cpp kopetetask.cpp \
-	kopetemimesourcefactory.cpp \
-	kopeteblacklister.cpp kopetemessageevent.cpp kopetemessagehandler.cpp \
-	kopetemessagehandlerchain.cpp kopetesimplemessagehandler.cpp kopeteproperties.cpp \
-	kabcpersistence.cpp connectionmanager.skel clientiface.stub managedconnectionaccount.cpp \
-	networkstatuscommon.h kopetegeneralsettings.kcfgc kopeteutils.cpp kopeteprefs.cpp kopetepicture.cpp \
-	kopeteappearancesettings.kcfgc kopetebehaviorsettings.kcfgc
+libkopete_la_SOURCES = connectionmanager.cpp 	kopeteonlinestatus.cpp \
+	kopeteonlinestatusmanager.cpp kopeteprotocol.cpp kopetecontact.cpp 	kopetepluginmanager.cpp \
+	kopeteplugin.cpp kopetemessage.cpp kopetechatsession.cpp 	kopetechatsessionmanager.cpp \
+	kopetecontactlist.cpp kopetemetacontact.cpp 	kopetetransfermanager.cpp kopetegroup.cpp \
+	kopeteaccountmanager.cpp kopeteaccount.cpp 	kopetecontactlistelement.cpp kopetecommand.cpp \
+	kopetecommandhandler.cpp kopeteaway.cpp kopeteawayaction.cpp 	kopetewalletmanager.cpp \
+	kopetecontactproperty.cpp kopetepassword.cpp kopeteglobal.cpp 	kopeteuiglobal.cpp \
+	kopetepasswordedaccount.cpp kopetemimetypehandler.cpp kopetetask.cpp 	kopetemimesourcefactory.cpp \
+		kopeteblacklister.cpp kopetemessageevent.cpp kopetemessagehandler.cpp \
+		kopetemessagehandlerchain.cpp kopetesimplemessagehandler.cpp kopeteproperties.cpp \
+		kabcpersistence.cpp connectionmanager.skel clientiface.stub managedconnectionaccount.cpp \
+		networkstatuscommon.h kopetegeneralsettings.kcfgc kopeteutils.cpp kopeteprefs.cpp \
+	kopetepicture.cpp 	kopeteappearancesettings.kcfgc kopetebehaviorsettings.kcfgc \
+	kopetestatusmessage.cpp
 
 libkopete_la_LDFLAGS = -no-undefined -version-info 1:0:0 $(all_libraries)
 libkopete_la_LIBADD = -lkabc ui/libkopeteui.la $(LIB_KIO) $(LIB_XSS)
@@ -49,16 +49,18 @@
 servicetypedir = $(kde_servicetypesdir)
 
 kopeteincludedir = $(includedir)/kopete
-kopeteinclude_HEADERS = kopeteaccount.h kopeteaccountmanager.h kopeteawayaction.h kopeteaway.h \
-	kopeteblacklister.h kopetecommand.h kopetecommandhandler.h kopetecontact.h kopetecontactlistelement.h kopetecontactlist.h \
-	kopetecontactproperty.h kopete_export.h kopeteglobal.h kopetegroup.h \
-	kopetemessageevent.h kopetemessage.h kopetemessagehandlerchain.h kopetemessagehandler.h \
-	kopetechatsession.h kopetechatsessionmanager.h kopetemetacontact.h kopetemimetypehandler.h \
-	kopeteonlinestatus.h kopeteonlinestatusmanager.h kopetepasswordedaccount.h \
-	kopetepassword.h kopeteplugin.h kopeteprotocol.h kopetesimplemessagehandler.h kopetetask.h \
-	kopetetransfermanager.h kopeteuiglobal.h kabcpersistence.h managedconnectionaccount.h \
-	kopeteversion.h kopeteprefs.h kopetepicture.h kopeteappearancesettings.h kopetebehaviorsettings.h kopetegeneralsettings.h
+kopeteinclude_HEADERS = kopeteaccount.h kopeteaccountmanager.h \
+	kopeteawayaction.h kopeteaway.h 	kopeteblacklister.h kopetecommand.h \
+	kopetecommandhandler.h kopetecontact.h kopetecontactlistelement.h kopetecontactlist.h \
+		kopetecontactproperty.h kopete_export.h kopeteglobal.h kopetegroup.h 	kopetemessageevent.h \
+	kopetemessage.h kopetemessagehandlerchain.h kopetemessagehandler.h 	kopetechatsession.h \
+	kopetechatsessionmanager.h kopetemetacontact.h kopetemimetypehandler.h 	kopeteonlinestatus.h \
+	kopeteonlinestatusmanager.h kopetepasswordedaccount.h 	kopetepassword.h kopeteplugin.h \
+	kopeteprotocol.h kopetesimplemessagehandler.h kopetetask.h 	kopetetransfermanager.h \
+	kopeteuiglobal.h kabcpersistence.h managedconnectionaccount.h 	kopeteversion.h \
+	kopeteprefs.h kopetepicture.h kopeteappearancesettings.h kopetebehaviorsettings.h \
+	kopetegeneralsettings.h kopetestatusmessage.h
 
 # vim: set noet:
 
-noinst_HEADERS = kopeteblacklister.h  
+noinst_HEADERS = kopeteblacklister.h

Attachment: kopete_statusmessage_v1.patch.gz
Description: GNU Zip compressed data

_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel

Reply via email to