OSDN Git Service

don't duplicate tab of the same thread.
authorikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Sat, 10 Apr 2004 12:26:08 +0000 (12:26 +0000)
committerikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Sat, 10 Apr 2004 12:26:08 +0000 (12:26 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@990 56b19765-1e22-0410-a548-a0f45d66c51a

kita/src/kitasubjecttabwidget.cpp
kita/src/kitasubjecttabwidget.h
kita/src/kitathreadtabwidget.cpp
kita/src/kitathreadtabwidget.h

index d3f9011..b54dbe4 100644 (file)
@@ -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;
 
index 3415093..86b820d 100644 (file)
@@ -36,7 +36,9 @@ public slots:
 private:
     FavoriteListView* m_favoriteList;
     KitaSubjectView* m_latestView;
+    QPtrList<KitaSubjectView> m_viewList;
     void connectSignals( Kita::ThreadListView* );
+    KitaSubjectView* findView( const QString& boardURL );
 
 private slots:
     void slotCurrentChanged( QWidget* widget );
index bec4f61..0f91f86 100644 (file)
@@ -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<KitaThreadView *>( currentPage() ) ->showThread( thread );
+    KitaThreadView * view = findView( thread->url() );
+    if ( view ) {
+        setCurrentPage( indexOf( view ) );
+        view->showThread( thread );
+    } else {
+        static_cast<KitaThreadView *>( 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<void*>( 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 );
 
index 7d26f64..f12032a 100644 (file)
@@ -48,6 +48,8 @@ public slots:
 private:
     void connectSignals( KitaThreadView* );
     KitaThreadView* createView();
+    QPtrList<KitaThreadView> m_viewList;
+    KitaThreadView* findView( const QString& threadURL );
 
 private slots:
     void slotOpenURLRequest( const KURL& url, const KParts::URLArgs& args = KParts::URLArgs() );