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

List:       kopete-devel
Subject:    [kopete-devel] [PATCH] decouple tabs from ChatView (the real thing)
From:       Matt Rogers <mattr () kde ! org>
Date:       2005-06-13 0:54:54
Message-ID: 200506121954.57704.mattr () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi,

This patch should decouple the implemenation of the tab widget from the=20
ChatView class. Please review.

Thanks,
Matt

["chatwindow-decouple-tab.patch" (text/x-diff)]

Index: chatview.cpp
===================================================================
--- chatview.cpp	(revision 424635)
+++ chatview.cpp	(working copy)
@@ -77,12 +77,13 @@ ChatView::ChatView( Kopete::ChatSession 
 	d->isActive = false;
 	d->visibleMembers = false;
 	d->sendInProgress = false;
+	
 
 	m_mainWindow = 0L;
 	membersDock = 0L;
-	m_tabBar = 0L;
 	membersStatus = Smart;
-	m_tabState=Normal;
+	m_tabState = Normal;
+	
 
 	//FIXME: don't widgets start off hidden anyway?
 	hide();
@@ -322,7 +323,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()
@@ -380,7 +381,7 @@ bool ChatView::closeView( bool force )
 	return false;
 }
 
-void ChatView::setTabState( KopeteTabState newState )
+void ChatView::updateChatState( KopeteTabState newState )
 {
 	if ( newState == Undefined )
 		newState = m_tabState;
@@ -393,32 +394,7 @@ void ChatView::setTabState( KopeteTabSta
 
 	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;
-		}
-	}
+	emit updateChatState( this, newState );
 
 	if( newState != Typing )
 	{
@@ -564,11 +540,11 @@ 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 );
+		updateChatState( Typing );
 	}
 	else
 	{
-		setTabState();
+		updateChatState();
 	}
 }
 
@@ -627,7 +603,7 @@ void ChatView::slotContactAdded(const Ko
 		}
 	}
 
-	setTabState();
+	updateChatState();
 	emit updateStatusIcon( this );
 }
 
@@ -656,7 +632,7 @@ void ChatView::slotContactRemoved( const
 		}
 	}
 
-	setTabState();
+	updateChatState();
 	emit updateStatusIcon( this );
 }
 
@@ -679,17 +655,13 @@ 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();
-	}
+	emit updateChatTooltip( this, QString::fromLatin1("<qt>%1</qt>").arg( \
d->captionText ) ); +	emit updateChatLabel( this, newCaption );
+	//Blink icon if modified and not active
+	if( !d->isActive && modified )
+		updateChatState( Changed );
+	else
+		updateChatState();
 
 	//Tell the parent we changed our caption
 	emit( captionChanged( d->isActive ) );
@@ -705,16 +677,16 @@ void ChatView::appendMessage(Kopete::Mes
 		switch ( message.importance() )
 		{
 			case Kopete::Message::Highlight:
-				setTabState( Highlighted );
+				updateChatState( Highlighted );
 				break;
 			case Kopete::Message::Normal:
 				if ( message.direction() == Kopete::Message::Inbound )
 				{
-					setTabState( Message );
+					updateChatState( Message );
 					break;
 				}
 			default:
-				setTabState( Changed );
+				updateChatState( Changed );
 		}
 	}
 
@@ -743,7 +715,7 @@ void ChatView::slotToggleRtfToolbar( boo
 
 void ChatView::slotContactStatusChanged( Kopete::Contact *contact, const \
Kopete::OnlineStatus &newStatus, const Kopete::OnlineStatus &oldStatus )  {
-// 	kdDebug(14000) << k_funcinfo << endl;
+ 	kdDebug(14000) << k_funcinfo << contact << endl;
 	bool inhibitNotification = ( newStatus.status() == Kopete::OnlineStatus::Unknown ||
 	                             oldStatus.status() == Kopete::OnlineStatus::Unknown );
 	if ( contact && KopetePrefs::prefs()->showEvents() && !inhibitNotification )
@@ -771,19 +743,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 );
@@ -857,16 +816,11 @@ void ChatView::setActive( bool value )
 	d->isActive = value;
 	if ( d->isActive )
 	{
-		setTabState( Normal );
+		updateChatState( Normal );
 		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: chatview.h
===================================================================
--- chatview.h	(revision 424635)
+++ chatview.h	(working copy)
@@ -58,6 +58,9 @@ public:
 	ChatView( Kopete::ChatSession *manager, ChatWindowPlugin *parent, const char *name \
= 0 );  ~ChatView();
 
+	/** the state of our chat */
+	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; }
@@ -113,8 +116,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 +148,6 @@ public:
 
 	const QString &statusText();
 
-	bool docked() { return ( m_tabBar != 0L ); }
-
 	QString &caption() const;
 
 	bool sendInProgress();
@@ -277,8 +276,17 @@ signals:
 
 	void captionChanged( bool active );
 
-	void updateStatusIcon( const ChatView* );
+	void updateStatusIcon( ChatView* );
 
+	/** Emitted when a possible tab tooltip needs updating */
+	void updateChatTooltip( ChatView*, const QString& );
+	
+	/** Emitted when the state of the chat changes */
+	void updateChatState( ChatView*, int );
+
+	/** Emitted when a possible tab label needs updating */
+	void updateChatLabel( ChatView*, const QString& );
+	
 	/**
 	 * Our send-button-enabled flag has changed
 	 */
@@ -338,7 +346,6 @@ protected:
 private:
 	// widget stuff
 	KopeteChatWindow *m_mainWindow;
-	KTabWidget *m_tabBar;
 
 	KDockWidget *viewDock;
 	ChatMessagePart *m_messagePart;
@@ -349,8 +356,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
@@ -363,7 +368,7 @@ private:
 	QString unreadMessageFrom;
 	QString m_status;
 
-	void setTabState( KopeteTabState state = Undefined );
+	void updateChatState( KopeteTabState state = Undefined );
 
 	/**
 	 * Creates the members list widget
Index: kopetechatwindow.cpp
===================================================================
--- kopetechatwindow.cpp	(revision 424493)
+++ 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() );
 	if( view == m_activeView )
 		view->show();
 	else
 		view->hide();
+	connect( view, SIGNAL( captionChanged( bool ) ), this, SLOT( updateChatLabel() ) );
+	connect( view, SIGNAL( updateStatusIcon( ChatView* ) ), this, SLOT( \
slotUpdateCaptionIcons( ChatView* ) ) );  view->setCaption( view->caption(), false );
 }
 
@@ -611,7 +613,6 @@ void KopeteChatWindow::setPrimaryChatVie
 	//reparent clears a lot of stuff out
 	QFont savedFont = view->font();
 	view->reparent( mainArea, 0, QPoint(), true );
-	view->setTabBar( 0L );
 	view->setFont( savedFont );
 	view->show();
 
@@ -655,7 +656,8 @@ void KopeteChatWindow::attachChatView( C
 	KCursor::setAutoHideCursor( newView->editWidget(), true, true );
 	connect( newView, SIGNAL(captionChanged( bool)), this, SLOT(slotSetCaption(bool)) \
);  connect( newView, SIGNAL(messageSuccess( ChatView* )), this, \
                SLOT(slotStopAnimation( ChatView* )) );
-	connect( newView, SIGNAL(updateStatusIcon( const ChatView* )), this, \
SLOT(slotUpdateCaptionIcons( const ChatView* )) ); +	connect( newView, \
SIGNAL(updateStatusIcon( ChatView* ) ), this, SLOT(slotUpdateCaptionIcons( ChatView* \
) ) ); +	connect( newView, SIGNAL(updateChatState( ChatView*, int ) ), this, SLOT( \
updateChatState( ChatView*, int ) ) );  
 	checkDetachEnable();
 }
@@ -678,7 +680,8 @@ void KopeteChatWindow::detachChatView( C
 		return;
 
 	disconnect( view, SIGNAL(captionChanged( bool)), this, SLOT(slotSetCaption(bool)) \
                );
-	disconnect( view, SIGNAL(updateStatusIcon( const ChatView *)), this, \
SLOT(slotUpdateCaptionIcons( const ChatView * )) ); +	disconnect( view, SIGNAL( \
updateStatusIcon( ChatView* ) ), this, SLOT( slotUpdateCaptionIcons( ChatView* ) ) ); \
+	disconnect( view, SIGNAL( updateChatState( ChatView*, int ) ), this, SLOT( \
updateChatState( ChatView*, int ) ) );  view->editWidget()->removeEventFilter( this \
);  
 	if( m_tabBar )
@@ -695,7 +698,6 @@ void KopeteChatWindow::detachChatView( C
 				m_tabBar->setCurrentPage( curPage + 1 );
 		}
 
-		view->setTabBar( 0L );
 		m_tabBar->removePage( view );
 
 		if( m_tabBar->currentPage() )
@@ -844,10 +846,11 @@ void KopeteChatWindow::setActiveView( QW
 	slotUpdateSendEnabled();
 }
 
-void KopeteChatWindow::slotUpdateCaptionIcons( const ChatView *view )
+void KopeteChatWindow::slotUpdateCaptionIcons( ChatView *view )
 {
-	if(!view||!m_activeView||view!=m_activeView )
+	if ( !view )
 		return; //(pas de charité)
+
 	QPtrList<Kopete::Contact> chatMembers=view->msgManager()->members();
 	Kopete::Contact *c=0L;
 	for ( Kopete::Contact *contact = chatMembers.first(); contact; contact = \
chatMembers.next() ) @@ -855,10 +858,18 @@ void KopeteChatWindow::slotUpdateCaption
 		if(!c || c->onlineStatus() < contact->onlineStatus())
 			c=contact;
 	}
-	QPixmap icon16 = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c , 16) \
                : SmallIcon( view->msgManager()->protocol()->pluginIcon() );
-	QPixmap icon32 = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c , 32) \
: SmallIcon( view->msgManager()->protocol()->pluginIcon() ); +	
+	if ( view == m_activeView )
+ 	{
+		QPixmap icon16 = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c , 16) \
: +		                     SmallIcon( view->msgManager()->protocol()->pluginIcon() );
+		QPixmap icon32 = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c , 32) \
: +		                     SmallIcon( view->msgManager()->protocol()->pluginIcon() );
+		KWin::setIcons( winId(), icon32, icon16 );
+	}
 
-	KWin::setIcons( winId(), icon32, icon16 );
+	if ( m_tabBar )
+		m_tabBar->setTabIconSet( view, view->msgManager()->contactOnlineStatus( c \
).iconFor( c ) );  }
 
 void KopeteChatWindow::slotChatClosed()
@@ -1131,6 +1142,53 @@ void KopeteChatWindow::slotConfToolbar()
 	delete dlg;
 }
 
+void KopeteChatWindow::updateChatState( ChatView* cv, int 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::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: kopetechatwindow.h
===================================================================
--- kopetechatwindow.h	(revision 424493)
+++ kopetechatwindow.h	(working copy)
@@ -209,13 +209,18 @@ private slots:
 	void slotEnableUpdateBg() { updateBg = true; }
 
 	void slotSetCaption( bool );
-	void slotUpdateCaptionIcons( const ChatView * );
+	void slotUpdateCaptionIcons( ChatView* );
 	void slotChatClosed();
 	void slotTabContextMenu( QWidget*, const QPoint & );
 	void slotStopAnimation( ChatView* );
 	void slotNickComplete();
 	void slotCloseChat( QWidget* );
 
+	//slots for tabs from the chatview widget
+	void updateChatState( ChatView* cv, int state );
+	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