The following eleventh hour patch adds a much-requested feature: a way for 
protocols to give a hint to Kopete which form a chat should take.  This 
allows Kopete to give a chatwindow a size and members list visibility 
appropriate to the chat.

We've previously told users who requested this feature that it was not 
possible for consistency's sake, but I feel that this has handicapped our use 
of chatrooms/IRC in kopete.  This patch aims to solve this dilemma(!) 
elegantly.

* Form is an attribute of Kopete::ChatSession
* 2 forms of chat: Small and Chatroom
* this affects the initial format of the chatwindow
* subsequently, following the window's initial form, user changes to the 
window layout are persisted separately so that Small windows and Chatroom 
windows layout and members list visibility are sticky

Additionally, the features allows (optionally) an compact variant of the chat 
view style to be selected dependent on chat session form.  This is 
implemented by munging the relative path to the variant css.  
FunkyStyle.css -> FunkyStyle_compact.css.  The rationale for this is that a 
large style with avatars is not appropriate to a high traffic channel.  This 
allows a compact variant to the main style, but that keeps has consistent 
theming, and works within the Adium chat spec

Notes on the patch:
* alternate chat view styles are not implemented - the methods are there, but 
the path munging, compact variant css file detection does not happen. the 
munge is a no-op
* UI for enabling the compact variant is missing and would go in the 
ChatWindow->style widget
* Everything defaults to the current Small behaviour! Even if applied as is, 
the patch is fail-safe!
* ...Except testbed, for testing and demonstration.  This requests Chatroom 
style windows.

I'd like to get this in and tested so that in KDE 4.1 we can have rockin' IRC 
and AIM chatroom support, and to support Groupwise chatrooms, that I will be 
completing for 4.1.

Will (who finds there is nothing like a deadline for a burst of productivity)
-- 
Will Stephenson
IRC: Bille
Index: protocols/testbed/testbedcontact.cpp
===================================================================
--- protocols/testbed/testbedcontact.cpp	(revision 736275)
+++ protocols/testbed/testbedcontact.cpp	(working copy)
@@ -75,7 +75,7 @@
 	{
 		QList<Kopete::Contact*> contacts;
 		contacts.append(this);
-		m_msgManager = Kopete::ChatSessionManager::self()->create(account()->myself(), contacts, protocol());
+		m_msgManager = Kopete::ChatSessionManager::self()->create(account()->myself(), contacts, protocol(), Kopete::ChatSession::Chatroom);
 		connect(m_msgManager, SIGNAL(messageSent(Kopete::Message&, Kopete::ChatSession*)),
 				this, SLOT( sendMessage( Kopete::Message& ) ) );
 		connect(m_msgManager, SIGNAL(destroyed()), this, SLOT(slotChatSessionDestroyed()));
Index: kopete/chatwindow/chatmessagepart.cpp
===================================================================
--- kopete/chatwindow/chatmessagepart.cpp	(revision 736315)
+++ kopete/chatwindow/chatmessagepart.cpp	(working copy)
@@ -369,7 +369,7 @@
 {
 	DOM::HTMLElement variantNode = document().getElementById( QString("mainStyle") );
 	if( !variantNode.isNull() )
-		variantNode.setInnerText( QString("@import url(\"%1\");").arg(variantPath) );
+		variantNode.setInnerText( QString("@import url(\"%1\");").arg( adjustStyleVariantForChatSession( variantPath) ) );
 }
 
 void ChatMessagePart::slotAppearanceChanged()
@@ -1176,7 +1176,7 @@
 		).arg( d->currentChatStyle->getStyleBaseHref() )
 		.arg( formatStyleKeywords(d->currentChatStyle->getHeaderHtml()) )
 		.arg( formatStyleKeywords(d->currentChatStyle->getFooterHtml()) )
-		.arg( KopeteChatWindowSettings::self()->styleVariant() )
+		.arg( adjustStyleVariantForChatSession( KopeteChatWindowSettings::self()->styleVariant() ) )
 		.arg( styleHTML() );
 	write(xhtmlBase);
 	end();
@@ -1185,6 +1185,15 @@
 #endif
 }
 
+QString ChatMessagePart::adjustStyleVariantForChatSession( const QString & styleVariant ) const
+{
+	kDebug() << styleVariant;
+	if ( d->manager->form() == Kopete::ChatSession::Chatroom
+			&& KopeteChatWindowSettings::self()->useCompact() ) {
+		kDebug() << "adjusting style to compact!";
+	}
+	return styleVariant;
+}
 #include "chatmessagepart.moc"
 
 // vim: set noet ts=4 sts=4 sw=4:
Index: kopete/chatwindow/kopetechatwindow.cpp
===================================================================
--- kopete/chatwindow/kopetechatwindow.cpp	(revision 736316)
+++ kopete/chatwindow/kopetechatwindow.cpp	(working copy)
@@ -179,7 +179,7 @@
 
 	if ( windowCreated )
 	{
-		myWindow = new KopeteChatWindow();
+		myWindow = new KopeteChatWindow( manager->form() );
 
 		if ( !accountMap.contains( manager->account() ) )
 			accountMap.insert( manager->account(), myWindow );
@@ -196,8 +196,8 @@
 	return myWindow;
 }
 
-KopeteChatWindow::KopeteChatWindow( QWidget *parent )
-	: KXmlGuiWindow( parent )
+KopeteChatWindow::KopeteChatWindow( Kopete::ChatSession::Form form, QWidget *parent  )
+	: KXmlGuiWindow( parent ), initialForm( form )
 {
 #ifdef CHRONO
 	QTime chrono;chrono.start();
@@ -230,7 +230,12 @@
 	vBox->setSpacing( 0 );
 	vBox->setFrameStyle( QFrame::NoFrame );
 	// set default window size.  This could be removed by fixing the size hints of the contents
-	resize( 500, 500 );
+	if ( initialForm == Kopete::ChatSession::Chatroom ) {
+		resize( 650, 400 );
+	} else {
+		m_participantsWidget->hide();
+		resize( 400, 400 );
+	}
 	setCentralWidget( vBox );
 
 	mainArea = new QFrame( vBox );
@@ -824,7 +829,7 @@
 
 	if( !action )
 	{
-		newWindow = new KopeteChatWindow();
+		newWindow = new KopeteChatWindow( detachedView->msgManager()->form() );
 		newWindow->setObjectName( QLatin1String("KopeteChatWindow") );
 	}
 	else
@@ -1090,7 +1095,7 @@
 {
 	// load and apply config file settings affecting the appearance of the UI
 //	kDebug(14010) ;
-	applyMainWindowSettings( KGlobal::config()->group( QLatin1String( "KopeteChatWindow" ) ) );
+	applyMainWindowSettings( KGlobal::config()->group( ( initialForm == Kopete::ChatSession::Chatroom ? QLatin1String( "KopeteChatWindowGroupMode" ) : QLatin1String( "KopeteChatWindowIndividualMode" ) ) ) );
 	//config->setGroup( QLatin1String("ChatWindowSettings") );
 }
 
@@ -1098,7 +1103,7 @@
 {
 //	kDebug(14010) ;
 
-	KConfigGroup kopeteChatWindowMainWinSettings( KGlobal::config(), QLatin1String( "KopeteChatWindow" ) );
+	KConfigGroup kopeteChatWindowMainWinSettings( KGlobal::config(), ( initialForm == Kopete::ChatSession::Chatroom ? QLatin1String( "KopeteChatWindowGroupMode" ) : QLatin1String( "KopeteChatWindowIndividualMode" ) ) );
 
 	// saves menubar,toolbar and statusbar setting
 	saveMainWindowSettings( kopeteChatWindowMainWinSettings );
Index: kopete/chatwindow/chatmessagepart.h
===================================================================
--- kopete/chatwindow/chatmessagepart.h	(revision 736315)
+++ kopete/chatwindow/chatmessagepart.h	(working copy)
@@ -240,6 +240,14 @@
 	 */
 	void writeTemplate();
 
+	/**
+	 * Adjust style variant to chat session type.  This allows the chat window to show a compact
+	 * variant of the style for chatrooms and a full-sized version for 1:small chats
+	 * @param styleVariant the chosen style variant as a relative path
+	 * @return the munged path, eg variant_compact.css
+	 */
+	QString adjustStyleVariantForChatSession( const QString & styleVariant ) const;
+
 	class Private;
 	Private *d;
 };
Index: kopete/chatwindow/kopetechatwindow.h
===================================================================
--- kopete/chatwindow/kopetechatwindow.h	(revision 736316)
+++ kopete/chatwindow/kopetechatwindow.h	(working copy)
@@ -30,6 +30,7 @@
 #include <QList>
 #include "kopetecontact.h"
 #include "kdeversion.h"
+#include <kopetechatsession.h>
 
 #include <kopete_export.h>
 
@@ -53,7 +54,6 @@
 namespace Kopete
 {
 class Message;
-class ChatSession;
 class Contact;
 typedef QList<Contact*>  ContactPtrList;
 }
@@ -114,7 +114,7 @@
 
 private:
 	// All KopeteChatWindows are created by the window function
-	KopeteChatWindow( QWidget *parent = 0 );
+	KopeteChatWindow( Kopete::ChatSession::Form form, QWidget *parent = 0 );
 
 	/**
 	 * The window list has changed:
@@ -170,6 +170,7 @@
 	KActionMenu *actionDetachMenu;
 	KActionMenu *actionTabPlacementMenu;
 	QString statusMsg;
+	Kopete::ChatSession::Form initialForm;
 
 signals:
 	void closing( KopeteChatWindow* );
Index: kopete/chatwindow/kopetechatwindowsettings.kcfg
===================================================================
--- kopete/chatwindow/kopetechatwindowsettings.kcfg	(revision 736315)
+++ kopete/chatwindow/kopetechatwindowsettings.kcfg	(working copy)
@@ -38,6 +38,10 @@
 			<label>Group consecutive messages from the same user as one block.</label>
 			<default>true</default>
 		</entry>
+		<entry key="useCompact" type="Bool">
+			<label>Use a compact variant of the chat style for chatrooms.</label>
+			<default>true</default>
+		</entry>
 		
 		<!-- Hightlight preferences -->
 		<entry key="highlightForegroundColor" type="Color">
Index: libkopete/kopetechatsession.h
===================================================================
--- libkopete/kopetechatsession.h	(revision 736275)
+++ libkopete/kopetechatsession.h	(working copy)
@@ -78,6 +78,11 @@
 
 public:
 	/**
+	 * Describes the form of this chat session
+	 */ 
+	enum Form { Small,/**< The chat is a small group or 1:1 chat */
+		Chatroom/** Chat with many members and high traffic */ };
+	/**
 	 * Delete a chat manager instance
 	 * You shouldn't delete the KMM yourself. it will be deleted when the chatwindow is closed
 	 * see also @ref setCanBeDeleted() , @ref deref() 
@@ -171,6 +176,12 @@
 	 */
 	MessageHandlerChain::Ptr chainForDirection( Message::MessageDirection dir );
 
+	/**
+	 * Get the form of this chatsession.  This is a hint to the UI so it can present the chat
+	 * appropriately
+	 */
+	Form form() const;
+
 signals:
 	/**
 	 * @brief the KMM will be deleted
@@ -377,7 +388,7 @@
 	 * static factory method createSession() creates the object. You may
 	 * not create instances yourself directly!
 	 */
-	ChatSession( const Contact *user, ContactPtrList others, Protocol *protocol );
+	ChatSession( const Contact *user, ContactPtrList others, Protocol *protocol, Form form = Small );
 
 	/**
 	 * Set wether or not contact from this account may be invited in this chat.
Index: libkopete/kopetechatsessionmanager.cpp
===================================================================
--- libkopete/kopetechatsessionmanager.cpp	(revision 736275)
+++ libkopete/kopetechatsessionmanager.cpp	(working copy)
@@ -105,12 +105,12 @@
 }
 
 ChatSession *ChatSessionManager::create(
-	const Contact *user, ContactPtrList chatContacts, Protocol *protocol)
+	const Contact *user, ContactPtrList chatContacts, Protocol *protocol, Kopete::ChatSession::Form form )
 {
 	ChatSession *result=findChatSession( user,  chatContacts, protocol);
 	if (!result)
 	{
-		result = new ChatSession(user,  chatContacts, protocol );
+		result = new ChatSession(user,  chatContacts, protocol, form );
 		registerChatSession(result);
 	}
 	return (result);
Index: libkopete/kopetechatsession.cpp
===================================================================
--- libkopete/kopetechatsession.cpp	(revision 736275)
+++ libkopete/kopetechatsession.cpp	(working copy)
@@ -59,10 +59,11 @@
 	KopeteView *view;
 	bool mayInvite;
 	Kopete::MessageHandlerChain::Ptr chains[3];
+	Kopete::ChatSession::Form form;
 };
 
 Kopete::ChatSession::ChatSession( const Kopete::Contact *user,
-	Kopete::ContactPtrList others, Kopete::Protocol *protocol )
+	Kopete::ContactPtrList others, Kopete::Protocol *protocol, Kopete::ChatSession::Form form )
 : QObject( user->account())
 {
 	int i;
@@ -76,6 +77,7 @@
 	d->view = 0L;
 	d->customDisplayName = false;
 	d->mayInvite = false;
+	d->form = form;
 
 	for ( i = 0; others.size() != i; i++ )
 		addContact( others[i], true );
@@ -511,6 +513,11 @@
 		v->raise(true);
 }
 
+Kopete::ChatSession::Form Kopete::ChatSession::form() const
+{
+	return d->form;
+}
+
 #include "kopetechatsession.moc"
 
 
Index: libkopete/kopetechatsessionmanager.h
===================================================================
--- libkopete/kopetechatsessionmanager.h	(revision 736275)
+++ libkopete/kopetechatsessionmanager.h	(working copy)
@@ -63,7 +63,7 @@
 	 * @return A pointer to a new or reused Kopete::ChatSession.
 	 */
 	Kopete::ChatSession* create( const Kopete::Contact *user,
-		Kopete::ContactPtrList chatContacts, Kopete::Protocol *protocol);
+		Kopete::ContactPtrList chatContacts, Kopete::Protocol *protocol, Kopete::ChatSession::Form form = Kopete::ChatSession::Small );
 
 	/**
 	 * Find a chat session, if one exists, that matches the given list of contacts.
_______________________________________________
kopete-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kopete-devel

Reply via email to