On Wednesday 14 November 2007 01:46:43 Will Stephenson wrote:
> 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
The updated version implements these two parts, and supplies 2 compact
variants for Kopete style and its Contact Colors variant - try it out!
Obligatory screenshot: http://www.kdedevelopers.org/node/3098
Will
--
Will Stephenson
IRC: Bille
Index: protocols/testbed/testbedcontact.cpp
===================================================================
--- protocols/testbed/testbedcontact.cpp (revision 736355)
+++ 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/kopetechatwindowstyle.cpp
===================================================================
--- kopete/chatwindow/kopetechatwindowstyle.cpp (revision 736355)
+++ kopete/chatwindow/kopetechatwindowstyle.cpp (working copy)
@@ -20,6 +20,7 @@
// Qt includes
#include <QFile>
#include <QDir>
+#include <QHash>
#include <QStringList>
#include <QTextStream>
@@ -44,6 +45,7 @@
QString statusHtml;
QString actionIncomingHtml;
QString actionOutgoingHtml;
+ QHash<QString, bool> compactVariants;
};
ChatWindowStyle::ChatWindowStyle(const QString &styleName, StyleBuildMode styleBuildMode)
@@ -162,11 +164,23 @@
QStringList variantList = variantDir.entryList( QStringList("*.css") );
QStringList::ConstIterator it, itEnd = variantList.constEnd();
+ QLatin1String compactVersionPrefix("_compact_");
for(it = variantList.constBegin(); it != itEnd; ++it)
{
QString variantName = *it, variantPath;
// Retrieve only the file name.
variantName = variantName.left(variantName.lastIndexOf("."));
+ if ( variantName.startsWith( compactVersionPrefix ) ) {
+ if ( variantName == compactVersionPrefix ) {
+ d->compactVariants.insert( "", true );
+ }
+ continue;
+ }
+ QString compactVersionFilename = *it;
+ QString compactVersionPath = variantDirPath + compactVersionFilename.prepend( compactVersionPrefix );
+ if ( QFile::exists( compactVersionPath )) {
+ d->compactVariants.insert( variantName, true );
+ }
// variantPath is relative to baseHref.
variantPath = QString("Variants/%1").arg(*it);
d->variantsList.insert(variantName, variantPath);
@@ -294,3 +308,21 @@
readStyleFiles();
listVariants();
}
+
+bool ChatWindowStyle::hasCompact( const QString & styleVariant ) const
+{
+ if ( d->compactVariants.contains( styleVariant ) ) {
+ return d->compactVariants.value( styleVariant );
+ }
+ return false;
+}
+
+QString ChatWindowStyle::compact( const QString & styleVariant ) const
+{
+ QString compacted = styleVariant;
+ if ( styleVariant.isEmpty() ) {
+ return QLatin1String( "Variants/_compact_.css" );
+ } else {
+ return compacted.insert( compacted.lastIndexOf('/') + 1, QString("_compact_") );
+ }
+}
Index: kopete/chatwindow/kopetechatwindowstyle.h
===================================================================
--- kopete/chatwindow/kopetechatwindowstyle.h (revision 736355)
+++ kopete/chatwindow/kopetechatwindowstyle.h (working copy)
@@ -103,6 +103,17 @@
bool hasActionTemplate() const;
/**
+ * Check if the supplied variant has a compact form
+ */
+ bool hasCompact( const QString & variant ) const;
+
+ /**
+ * Return the compact version of the given style variant.
+ * For the unmodified style, this returns "Variants/_compact_.css"
+ */
+ QString compact( const QString & variant ) const;
+
+ /**
* Reload style from disk.
*/
void reload();
Index: kopete/chatwindow/kopetechatwindowsettings.kcfg
===================================================================
--- kopete/chatwindow/kopetechatwindowsettings.kcfg (revision 736355)
+++ 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: kopete/chatwindow/chatmessagepart.cpp
===================================================================
--- kopete/chatwindow/chatmessagepart.cpp (revision 736355)
+++ 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,14 @@
#endif
}
+QString ChatMessagePart::adjustStyleVariantForChatSession( const QString & styleVariant ) const
+{
+ if ( d->manager->form() == Kopete::ChatSession::Chatroom
+ && KopeteChatWindowSettings::self()->useCompact() ) {
+ return d->currentChatStyle->compact( styleVariant );
+ }
+ return styleVariant;
+}
#include "chatmessagepart.moc"
// vim: set noet ts=4 sts=4 sw=4:
Index: kopete/chatwindow/kopetechatwindow.cpp
===================================================================
--- kopete/chatwindow/kopetechatwindow.cpp (revision 736355)
+++ 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 736355)
+++ 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 736355)
+++ 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 736355)
+++ 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 736355)
+++ 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 736355)
+++ 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 736355)
+++ 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 736355)
+++ 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.
Index: styles/Kopete/Contents/Resources/Variants/_compact_Contact_color.css
===================================================================
--- styles/Kopete/Contents/Resources/Variants/_compact_Contact_color.css (revision 0)
+++ styles/Kopete/Contents/Resources/Variants/_compact_Contact_color.css (revision 0)
@@ -0,0 +1,23 @@
+.IncomingBody2
+{
+ min-height: 0;
+ padding-bottom: 7px;
+}
+
+.inUserPicture
+{
+ display: none;
+ float: none;
+}
+
+.OutgoingBody2
+{
+ min-height: 0;
+ padding-bottom: 7px;
+}
+
+.outUserPicture
+{
+ display: none;
+ float: none;
+}
Index: styles/Kopete/Contents/Resources/Variants/_compact_.css
===================================================================
--- styles/Kopete/Contents/Resources/Variants/_compact_.css (revision 0)
+++ styles/Kopete/Contents/Resources/Variants/_compact_.css (revision 0)
@@ -0,0 +1,23 @@
+.IncomingBody2
+{
+ min-height: 0;
+ padding-bottom: 7px;
+}
+
+.inUserPicture
+{
+ display: none;
+ float: none;
+}
+
+.OutgoingBody2
+{
+ min-height: 0;
+ padding-bottom: 7px;
+}
+
+.outUserPicture
+{
+ display: none;
+ float: none;
+}
Index: styles/Kopete/Contents/Resources/Variants/CMakeLists.txt
===================================================================
--- styles/Kopete/Contents/Resources/Variants/CMakeLists.txt (revision 736355)
+++ styles/Kopete/Contents/Resources/Variants/CMakeLists.txt (working copy)
@@ -1,6 +1,6 @@
########### install files ###############
-install( FILES Big_pictures.css Contact_color.css DESTINATION ${DATA_INSTALL_DIR}/kopete/styles/Kopete/Contents/Resources/Variants)
+install( FILES Big_pictures.css Contact_color.css _compact_.css _compact_Contact_color.css DESTINATION ${DATA_INSTALL_DIR}/kopete/styles/Kopete/Contents/Resources/Variants)
_______________________________________________
kopete-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kopete-devel