From: ikemo Date: Sat, 10 Apr 2004 12:26:08 +0000 (+0000) Subject: don't duplicate tab of the same thread. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b625e3424a4dd0e706867000c99e02ad92a828a8;p=kita%2Fkita.git don't duplicate tab of the same thread. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@990 56b19765-1e22-0410-a548-a0f45d66c51a --- diff --git a/kita/src/kitasubjecttabwidget.cpp b/kita/src/kitasubjecttabwidget.cpp index d3f9011..b54dbe4 100644 --- a/kita/src/kitasubjecttabwidget.cpp +++ b/kita/src/kitasubjecttabwidget.cpp @@ -25,6 +25,7 @@ KitaSubjectTabWidget::KitaSubjectTabWidget( QWidget* parent, const char* name, W KitaSubjectView * view = new KitaSubjectView( this ); addTab( view, " " ); m_latestView = view; + m_viewList.append( view ); m_favoriteList = new FavoriteListView( this, "favoriteTab" ); addTab( m_favoriteList, "Favorite" ); @@ -45,13 +46,18 @@ KitaSubjectTabWidget::~KitaSubjectTabWidget() void KitaSubjectTabWidget::loadBoard( const Kita::Board* board, bool withNewTab ) { - if ( withNewTab ) { - KitaSubjectView * view = new KitaSubjectView( this ); - connectSignals( view ); - connect( view, SIGNAL( loadBoardCompleted( const KURL& ) ), - this, SIGNAL( loadBoardCompleted( const KURL& ) ) ); - insertTab( view, board->name(), count() - 1 ); + KitaSubjectView * view = findView( board->url() ); + if ( view ) { m_latestView = view; + setTabLabel( m_latestView, board->name() ); + } else if ( withNewTab ) { + KitaSubjectView * newView = new KitaSubjectView( this ); + connectSignals( newView ); + connect( newView, SIGNAL( loadBoardCompleted( const KURL& ) ), + this, SIGNAL( loadBoardCompleted( const KURL& ) ) ); + insertTab( newView, board->name(), count() - 1 ); + m_latestView = newView; + m_viewList.append( newView ); } else { setTabLabel( m_latestView, board->name() ); } @@ -63,7 +69,7 @@ void KitaSubjectTabWidget::loadBoard( const Kita::Board* board, bool withNewTab void KitaSubjectTabWidget::loadBoard( const QString& boardURL, bool withNewTab ) { - Kita::Board* board = Kita::Board::getByURL( boardURL ); + Kita::Board * board = Kita::Board::getByURL( boardURL ); loadBoard( board, withNewTab ); } @@ -86,6 +92,17 @@ void KitaSubjectTabWidget::connectSignals( Kita::ThreadListView* view ) this, SIGNAL( showThreadRequested( const Kita::Thread*, bool ) ) ); } +KitaSubjectView* KitaSubjectTabWidget::findView( const QString& boardURL ) +{ + KitaSubjectView * view; + for ( view = m_viewList.first(); view; view = m_viewList.next() ) { + if ( view->boardURL() == boardURL ) { + return view; + } + } + return 0; +} + void KitaSubjectTabWidget::slotCurrentChanged( QWidget* widget ) { if ( QString::compare( widget->name(), "favoriteTab" ) == 0 ) { @@ -101,6 +118,7 @@ void KitaSubjectTabWidget::deleteView( KitaSubjectView* view ) return ; // favorite¤È¤³¤ì¤À¤±¤Î¤È¤­¤Ï²¿¤â¤·¤Ê¤¤ } + m_viewList.remove( view ); removePage( view ); delete view; diff --git a/kita/src/kitasubjecttabwidget.h b/kita/src/kitasubjecttabwidget.h index 3415093..86b820d 100644 --- a/kita/src/kitasubjecttabwidget.h +++ b/kita/src/kitasubjecttabwidget.h @@ -36,7 +36,9 @@ public slots: private: FavoriteListView* m_favoriteList; KitaSubjectView* m_latestView; + QPtrList m_viewList; void connectSignals( Kita::ThreadListView* ); + KitaSubjectView* findView( const QString& boardURL ); private slots: void slotCurrentChanged( QWidget* widget ); diff --git a/kita/src/kitathreadtabwidget.cpp b/kita/src/kitathreadtabwidget.cpp index bec4f61..0f91f86 100644 --- a/kita/src/kitathreadtabwidget.cpp +++ b/kita/src/kitathreadtabwidget.cpp @@ -38,6 +38,7 @@ KitaThreadTabWidget::KitaThreadTabWidget( QWidget* parent, const char* name, WFl KitaThreadView* view = createView(); if ( view ) { + m_viewList.append( view ); addTab( view, "thread" ); connectSignals( view ); } @@ -48,8 +49,13 @@ KitaThreadTabWidget::~KitaThreadTabWidget() void KitaThreadTabWidget::showThread( const Kita::Thread* thread ) { - // TODO: ¥¹¥ì¤¬¤É¤³¤«¤Î¥¿¥Ö¤Ë¤¹¤Ç¤Ë¤¢¤ë¤È¤­¤Ï¤½¤ì¤ò»È¤¦ - static_cast( currentPage() ) ->showThread( thread ); + KitaThreadView * view = findView( thread->url() ); + if ( view ) { + setCurrentPage( indexOf( view ) ); + view->showThread( thread ); + } else { + static_cast( currentPage() ) ->showThread( thread ); + } // FIXME: showThreadWithNewTab()¤Ø¥³¥Ô¡¼ setTabLabel( currentPage(), Kita::unescape( thread->name().left( MAX_TABLABEL_LEN ) ) ); @@ -58,7 +64,7 @@ void KitaThreadTabWidget::showThread( const Kita::Thread* thread ) void KitaThreadTabWidget::showThread( const QString& datURL, bool withNewTab ) { - Kita::Thread* thread = Kita::Thread::getByURL( datURL ); + Kita::Thread * thread = Kita::Thread::getByURL( datURL ); if ( withNewTab ) { showThreadWithNewTab( thread ); } else { @@ -92,21 +98,28 @@ KitaThreadView* KitaThreadTabWidget::createView() void KitaThreadTabWidget::showThreadWithNewTab( const Kita::Thread* thread ) { - KitaThreadView * view = createView(); - + KitaThreadView * view = findView( thread->url() ); if ( view ) { - addTab( view, Kita::unescape( thread->name().left( MAX_TABLABEL_LEN ) ) ); - setTabToolTip( view, thread->name() ); + setCurrentPage( indexOf( view ) ); + showThread( thread ); + } else { + KitaThreadView * newView = createView(); - connectSignals( view ); - view->showThread( thread ); - showPage( view ); + if ( newView ) { + addTab( newView, Kita::unescape( thread->name().left( MAX_TABLABEL_LEN ) ) ); + setTabToolTip( newView, thread->name() ); + + connectSignals( newView ); + newView->showThread( thread ); + showPage( newView ); + m_viewList.append( newView ); - QString threadName = view->threadName(); + QString threadName = newView->threadName(); - // FIXME: showThread()¤«¤é¥³¥Ô¡¼ - setTabLabel( currentPage(), Kita::unescape( threadName.left( MAX_TABLABEL_LEN ) ) ); - setTabToolTip( currentPage(), threadName ); + // FIXME: showThread()¤«¤é¥³¥Ô¡¼ + setTabLabel( currentPage(), Kita::unescape( threadName.left( MAX_TABLABEL_LEN ) ) ); + setTabToolTip( currentPage(), threadName ); + } } } @@ -126,16 +139,29 @@ void KitaThreadTabWidget::connectSignals( KitaThreadView* view ) this, SIGNAL( showThreadCompleted( const KURL& ) ) ); } +KitaThreadView* KitaThreadTabWidget::findView( const QString& threadURL ) +{ + KitaThreadView * view; + for ( view = m_viewList.first(); view; view = m_viewList.next() ) { + if ( view->threadURL().url() == threadURL ) { + return view; + } + } + return 0; +} + void KitaThreadTabWidget::deleteView( KitaThreadView* view ) { kdDebug() << "deleteView(" << static_cast( view ) << ")" << endl; removePage( view ); + m_viewList.remove( view ); delete view; if ( count() == 0 ) { KitaThreadView * view = createView(); if ( view ) { + m_viewList.append( view ); addTab( view, "thread" ); connectSignals( view ); diff --git a/kita/src/kitathreadtabwidget.h b/kita/src/kitathreadtabwidget.h index 7d26f64..f12032a 100644 --- a/kita/src/kitathreadtabwidget.h +++ b/kita/src/kitathreadtabwidget.h @@ -48,6 +48,8 @@ public slots: private: void connectSignals( KitaThreadView* ); KitaThreadView* createView(); + QPtrList m_viewList; + KitaThreadView* findView( const QString& threadURL ); private slots: void slotOpenURLRequest( const KURL& url, const KParts::URLArgs& args = KParts::URLArgs() );