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

List:       kopete-devel
Subject:    [kopete-devel] [PATCH] Decouple tabs from the ChatView class
From:       Matt Rogers <mattr () kde ! org>
Date:       2005-06-05 19:24:14
Message-ID: 200506051424.17235.mattr () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi,

The attached patch removes the most of implementation details of tabs from the 
ChatView class and moves them to the KopeteChatWindow class. This is so that 
I can (if I have to) write a new chatwindow using the ChatView class as a 
base for my chat window without having to worry about the underlying tab 
widget implementation.

This is a preliminary patch. The handling of the tab state from 
KopeteChatWindow (I'm talking about the colors for the tabs based on whether 
a user is typing, we've received a message, etc.) is missing. I would like 
some advice on how to get this moved the best. I still think that the 
ChatView class has to track it's state and the current patch reflects that, 
but some suggestions on how to proceed from here is welcome.

Thanks,
Matt

["chatview-decouple-tabs.patch" (text/x-diff)]

Index: chatview.cpp
===================================================================
--- chatview.cpp	(revision 422441)
+++ chatview.cpp	(working copy)
@@ -79,7 +79,6 @@ ChatView::ChatView( Kopete::ChatSession 
 
 	m_mainWindow = 0L;
 	membersDock = 0L;
-	m_tabBar = 0L;
 	membersStatus = Smart;
 	m_tabState=Normal;
 
@@ -320,7 +319,7 @@ void ChatView::makeVisible()
 
 bool ChatView::isVisible()
 {
-	return ( m_mainWindow && m_mainWindow->isVisible() && ( d->isActive || docked() ) \
); +	return ( m_mainWindow && m_mainWindow->isVisible() && d->isActive  );
 }
 
 bool ChatView::visibleMembersList()
@@ -378,53 +377,6 @@ bool ChatView::closeView( bool force )
 	return false;
 }
 
-void ChatView::setTabState( KopeteTabState newState )
-{
-	if ( newState == Undefined )
-		newState = m_tabState;
-	else if ( newState != Typing && ( newState != Changed || ( m_tabState != Message && \
                m_tabState != Highlighted ) )
-		&& ( newState != Message ||  m_tabState != Highlighted ) )
-	{ //if the new state is not a typing state and we don't already have a message or a \
                highlighted message
-	  //change the tab state
-		m_tabState = newState;
-	}
-
-	newState = m_remoteTypingMap.isEmpty() ? m_tabState : Typing ;
-
-	if( m_tabBar )
-	{
-		switch( newState )
-		{
-			case Highlighted:
-				m_tabBar->setTabColor( this, Qt::blue );
-				break;
-
-			case Message:
-				m_tabBar->setTabColor( this, Qt::red );
-				break;
-
-			case Changed:
-				m_tabBar->setTabColor( this, Qt::darkRed );
-				break;
-
-			case Typing:
-				m_tabBar->setTabColor( this, Qt::darkGreen );
-				break;
-
-			case Normal:
-			default:
-				m_tabBar->setTabColor( this, KGlobalSettings::textColor() );
-				break;
-		}
-	}
-
-	if( newState != Typing )
-	{
-		setStatusText( i18n( "One other person in the chat",
-			       "%n other people in the chat", m_manager->members().count() ) );
-	}
-}
-
 void ChatView::setMainWindow( KopeteChatWindow* parent )
 {
 	m_mainWindow = parent;
@@ -562,12 +514,9 @@ void ChatView::remoteTyping( const Kopet
 			QString statusTyping = typingList.join( QString::fromLatin1( ", " ) );
 			setStatusText( i18n( "%1 is a list of names", "%1 are typing a message" ).arg( \
statusTyping ) );  }
-		setTabState( Typing );
-	}
-	else
-	{
-		setTabState();
 	}
+
+	emit updateChatState( this, Typing );
 }
 
 void ChatView::setStatusText( const QString &status )
@@ -625,7 +574,7 @@ void ChatView::slotContactAdded(const Ko
 		}
 	}
 
-	setTabState();
+	//Tell window to update tab state
 	emit updateStatusIcon( this );
 }
 
@@ -654,7 +603,7 @@ void ChatView::slotContactRemoved( const
 		}
 	}
 
-	setTabState();
+	//Tell window to update tab state
 	emit updateStatusIcon( this );
 }
 
@@ -665,6 +614,7 @@ QString& ChatView::caption() const
 
 void ChatView::setCaption( const QString &text, bool modified )
 {
+	Q_UNUSED( modified ); //previously used to update tab info
 // 	kdDebug(14000) << k_funcinfo << endl;
 	QString newCaption = text;
 
@@ -677,17 +627,7 @@ void ChatView::setCaption( const QString
 	//Call the original set caption
 	KDockMainWindow::setCaption( newCaption, false );
 
-	if( m_tabBar )
-	{
-		m_tabBar->setTabToolTip( this, QString::fromLatin1("<qt>%1</qt>").arg( \
                d->captionText ) );
-		m_tabBar->setTabLabel( this, newCaption  );
-
-		//Blink icon if modified and not active
-		if( !d->isActive && modified )
-			setTabState( Changed );
-		else
-			setTabState();
-	}
+	//update tab tooltip, label, and state (if modified and not active)
 
 	//Tell the parent we changed our caption
 	emit( captionChanged( d->isActive ) );
@@ -703,16 +643,15 @@ void ChatView::appendMessage(Kopete::Mes
 		switch ( message.importance() )
 		{
 			case Kopete::Message::Highlight:
-				setTabState( Highlighted );
+				//set highlighted tab state
 				break;
 			case Kopete::Message::Normal:
 				if ( message.direction() == Kopete::Message::Inbound )
-				{
-					setTabState( Message );
-					break;
-				}
+					//set message tab state
+				break;
 			default:
-				setTabState( Changed );
+				//set changed tab state
+				break;
 		}
 	}
 
@@ -769,19 +708,6 @@ void ChatView::slotContactStatusChanged(
 		}
 	}
 
-	if ( m_tabBar )
-	{
-		QPtrList<Kopete::Contact> chatMembers = m_manager->members();
-		Kopete::Contact *tempContact = 0L;
-		for ( QPtrListIterator<Kopete::Contact> it ( chatMembers ); it.current(); ++it )
-		{
-			if ( !tempContact || tempContact->onlineStatus() < (*it)->onlineStatus() )
-				tempContact = (*it);
-		}
-		if ( tempContact )
-			m_tabBar->setTabIconSet( this, m_manager->contactOnlineStatus( tempContact \
                ).iconFor( tempContact ) );
-	}
-
 	// update the windows caption
 	slotChatDisplayNameChanged();
 	emit updateStatusIcon( this );
@@ -855,16 +781,11 @@ void ChatView::setActive( bool value )
 	d->isActive = value;
 	if ( d->isActive )
 	{
-		setTabState( Normal );
+		//set normal tab state
 		emit( activated( static_cast<KopeteView*>(this) ) );
 	}
 }
 
-void ChatView::setTabBar( KTabWidget *tabBar )
-{
-	m_tabBar = tabBar;
-}
-
 void ChatView::slotRemoteTypingTimeout()
 {
 	// Remove the topmost timer from the list. Why does QPtrDict use void* keys and not \
                typed keys? *sigh*
Index: kopetechatwindow.cpp
===================================================================
--- kopetechatwindow.cpp	(revision 422441)
+++ kopetechatwindow.cpp	(working copy)
@@ -46,6 +46,7 @@
 #include <kstringhandler.h>
 #include <ksqueezedtextlabel.h>
 #include <kstdaccel.h>
+#include <kglobalsettings.h>
 
 #include "chatmessagepart.h"
 #include "chattexteditpart.h"
@@ -596,12 +597,13 @@ void KopeteChatWindow::addTab( ChatView 
 	QPixmap pluginIcon = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c) : \
SmallIcon( view->msgManager()->protocol()->pluginIcon() );  
 	view->reparent( m_tabBar, 0, QPoint(), true );
-	m_tabBar->addTab( view, pluginIcon, QString::null );
-	view->setTabBar( m_tabBar );
+	m_tabBar->addTab( view, pluginIcon, view->caption() );
+	//view->setTabBar( m_tabBar );
 	if( view == m_activeView )
 		view->show();
 	else
 		view->hide();
+	connect( view, SIGNAL( captionChanged( bool ) ), this, SLOT( updateChatLabel() ) );
 	view->setCaption( view->caption(), false );
 }
 
@@ -611,7 +613,7 @@ void KopeteChatWindow::setPrimaryChatVie
 	//reparent clears a lot of stuff out
 	QFont savedFont = view->font();
 	view->reparent( mainArea, 0, QPoint(), true );
-	view->setTabBar( 0L );
+	//view->setTabBar( 0L );
 	view->setFont( savedFont );
 	view->show();
 
@@ -679,6 +681,7 @@ void KopeteChatWindow::detachChatView( C
 
 	disconnect( view, SIGNAL(captionChanged( bool)), this, SLOT(slotSetCaption(bool)) \
);  disconnect( view, SIGNAL(updateStatusIcon( const ChatView *)), this, \
SLOT(slotUpdateCaptionIcons( const ChatView * )) ); +	disconnect( view, \
SIGNAL(captionChanged( bool ) ), this, SLOT( updateChatLabel() ) );  \
view->editWidget()->removeEventFilter( this );  
 	if( m_tabBar )
@@ -695,7 +698,7 @@ void KopeteChatWindow::detachChatView( C
 				m_tabBar->setCurrentPage( curPage + 1 );
 		}
 
-		view->setTabBar( 0L );
+		//view->setTabBar( 0L );
 		m_tabBar->removePage( view );
 
 		if( m_tabBar->currentPage() )
@@ -844,8 +847,9 @@ void KopeteChatWindow::setActiveView( QW
 	slotUpdateSendEnabled();
 }
 
-void KopeteChatWindow::slotUpdateCaptionIcons( const ChatView *view )
+void KopeteChatWindow::slotUpdateCaptionIcons( const ChatView *cv )
 {
+	ChatView* view = const_cast<ChatView*>( cv );
 	if(!view||!m_activeView||view!=m_activeView )
 		return; //(pas de charité)
 	QPtrList<Kopete::Contact> chatMembers=view->msgManager()->members();
@@ -859,6 +863,8 @@ void KopeteChatWindow::slotUpdateCaption
 	QPixmap icon32 = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c , 32) \
: SmallIcon( view->msgManager()->protocol()->pluginIcon() );  
 	KWin::setIcons( winId(), icon32, icon16 );
+	if ( m_tabBar )
+		m_tabBar->setTabIconSet( view, view->msgManager()->contactOnlineStatus( c \
).iconFor( c ) );  }
 
 void KopeteChatWindow::slotChatClosed()
@@ -1131,6 +1137,71 @@ void KopeteChatWindow::slotConfToolbar()
 	delete dlg;
 }
 
+void KopeteChatWindow::updateChatState( ChatView* cv, int newState )
+{
+
+	if ( newState == ChatView::Undefined )
+		newState = cv->currentState();
+	else if ( newState != ChatView::Typing && ( newState != ChatView::Message ||
+	                                          cv->currentState() != \
ChatView::Highlighted ) && +	     ( newState != ChatView::Changed || ( \
cv->currentState() != ChatView::Message && cv->currentState() != \
ChatView::Highlighted ) ) ) +	{
+		//if the new state is not a typing state and we don't already
+		//have a message or a highlighted message. Change the tab
+		//state
+		//m_tabState = newState;
+	}
+
+	if ( m_tabBar )
+	{
+		switch( newState )
+		{
+			case ChatView::Highlighted:
+				m_tabBar->setTabColor( cv, Qt::blue );
+				break;
+			case ChatView::Message:
+				m_tabBar->setTabColor( cv, Qt::red );
+				break;
+			case ChatView::Changed:
+				m_tabBar->setTabColor( cv, Qt::darkRed );
+				break;
+			case ChatView::Typing:
+				m_tabBar->setTabColor( cv, Qt::darkGreen );
+				break;
+			case ChatView::Normal:
+			default:
+				m_tabBar->setTabColor( cv, KGlobalSettings::textColor() );
+				break;
+		}
+	}
+}
+
+void KopeteChatWindow::updateChatIcon( ChatView* cv )
+{
+	Q_UNUSED( cv );
+}
+
+void KopeteChatWindow::updateChatTooltip( ChatView* cv )
+{
+	if ( m_tabBar )
+		m_tabBar->setTabToolTip( cv, QString::fromLatin1("<qt>%1</qt>").arg( cv->caption() \
) ); +}
+
+void KopeteChatWindow::updateChatLabel()
+{
+	const ChatView* cv = dynamic_cast<const ChatView*>( sender() );
+	if ( !cv || !m_tabBar )
+		return;
+
+	ChatView* chat = const_cast<ChatView*>( cv );
+	if ( m_tabBar )
+	{
+		m_tabBar->setTabLabel( chat, chat->caption() );
+		if ( m_tabBar->count() < 2 || m_tabBar->currentPage() == cv )
+			setCaption( chat->caption() );
+	}
+}
+
 #include "kopetechatwindow.moc"
 
 // vim: set noet ts=4 sts=4 sw=4:
Index: chatview.h
===================================================================
--- chatview.h	(revision 422441)
+++ chatview.h	(working copy)
@@ -58,11 +58,20 @@ public:
 	ChatView( Kopete::ChatSession *manager, ChatWindowPlugin *parent, const char *name \
= 0 );  ~ChatView();
 
+	/** the state of our tab */
+	enum KopeteTabState { Normal, Highlighted, Changed, Typing, Message, Undefined };
+
 	ChatMembersListWidget *membersList() const { return m_membersList; }
 	ChatMessagePart *messagePart() const { return m_messagePart; }
 	ChatTextEditPart *editPart() const { return m_editPart; }
 
 	/**
+	 * Get the current state of the chat view as described
+	 * by the KopeteTabState enum
+	 */
+	int currentState() const { return m_tabState; }
+
+	/**
 	 * Adds text into the edit area. Used when you select an emoticon
 	 * @param text The text to be inserted
 	 */
@@ -97,8 +106,7 @@ public:
 	void setMainWindow( KopeteChatWindow* parent );
 
 	/**
-	 * Returns the message currently in the edit area
-	 * Reimplemented from KopeteView
+	 * Returns the message currently in the edit area.
 	 * @return The Kopete::Message object for the message
 	 *
 	 * Reimplemented from KopeteView
@@ -113,8 +121,6 @@ public:
 	 */
 	virtual void setCurrentMessage( const Kopete::Message &newMessage );
 
-	void setTabBar( KTabWidget *tabBar );
-
 	/**
 	 * Sets the placement of the chat members list.
 	 * DockLeft, DockRight, or DockNone.
@@ -147,8 +153,6 @@ public:
 
 	const QString &statusText();
 
-	bool docked() { return ( m_tabBar != 0L ); }
-
 	QString &caption() const;
 
 	bool sendInProgress();
@@ -169,10 +173,10 @@ public:
 
 	bool canSend();
 
-	/** Reimplimented from KopeteView **/
+	/** Reimplemented from KopeteView **/
 	virtual void registerContextMenuHandler( QObject *target, const char* slot );
 
-	/** Reimplimented from KopeteView **/
+	/** Reimplemented from KopeteView **/
 	virtual void registerTooltipHandler( QObject *target, const char* slot );
 
 public slots:
@@ -280,6 +284,16 @@ signals:
 	void updateStatusIcon( const ChatView* );
 
 	/**
+	 * Emitted when a possible tab tooltip needs updating
+	 */
+	void updateChatTooltip( ChatView* );
+
+	/**
+	 * Emitted when the state of the chat changes
+	 */
+	void updateChatState( ChatView*, int );
+
+	/**
 	 * Our send-button-enabled flag has changed
 	 */
 	void canSendChanged(bool);
@@ -336,7 +350,6 @@ protected:
 private:
 	// widget stuff
 	KopeteChatWindow *m_mainWindow;
-	KTabWidget *m_tabBar;
 
 	KDockWidget *viewDock;
 	ChatMessagePart *m_messagePart;
@@ -347,8 +360,6 @@ private:
 	KDockWidget *editDock;
 	ChatTextEditPart *m_editPart;
 
-	// the state of our tab
-	enum KopeteTabState { Normal, Highlighted, Changed, Typing, Message, Undefined };
 	KopeteTabState m_tabState;
 
 	// position and visibility of the chat member list
@@ -361,8 +372,6 @@ private:
 	QString unreadMessageFrom;
 	QString m_status;
 
-	void setTabState( KopeteTabState state = Undefined );
-
 	/**
 	 * Creates the members list widget
 	 */
Index: kopetechatwindow.h
===================================================================
--- kopetechatwindow.h	(revision 422441)
+++ kopetechatwindow.h	(working copy)
@@ -216,6 +216,13 @@ private slots:
 	void slotNickComplete();
 	void slotCloseChat( QWidget* );
 
+	//slots for tabs from the chatview widget
+	void updateChatState( ChatView* cv, int state );
+	void updateChatIcon( ChatView* cv);
+	void updateChatTooltip( ChatView* cv );
+	void updateChatLabel();
+	
+
 protected:
 	virtual void closeEvent( QCloseEvent *e );
 	virtual void windowActivationChange( bool );


[Attachment #8 (application/pgp-signature)]

_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://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