OSDN Git Service

>>593
authorikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Wed, 24 Nov 2004 16:06:42 +0000 (16:06 +0000)
committerikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Wed, 24 Nov 2004 16:06:42 +0000 (16:06 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@1557 56b19765-1e22-0410-a548-a0f45d66c51a

kita/src/hi16-action-open.png
kita/src/kita.cpp
kita/src/kitasubjectview.cpp
kita/src/libkita/datmanager.cpp
kita/src/libkita/datmanager.h
kita/src/libkita/thread.cpp
kita/src/libkita/thread.h
kita/src/part/kitahtmlpart.cpp
kita/src/part/kitathreadview.cpp

index 5885774..1454894 100644 (file)
Binary files a/kita/src/hi16-action-open.png and b/kita/src/hi16-action-open.png differ
index a08c135..9d387c0 100644 (file)
 #include "libkita/kita_misc.h"
 #include "libkita/kitaconfig.h"
 #include "libkita/signalcollection.h"
-#include "libkita/parsemisc.h"
 #include "libkita/account.h"
 #include "libkita/imgmanager.h"
+#include "libkita/datmanager.h"
+#include "libkita/boardmanager.h"
 
 #include <qdragobject.h>
 #include <qtextcodec.h>
@@ -240,6 +241,8 @@ KitaMainWindow::~KitaMainWindow()
     delete m_naviDock;
     delete m_imgDock;
     delete m_writeDock;
+
+    Kita::DatManager::deleteAllDatInfo();
 }
 
 void KitaMainWindow::load( const KURL& url )
@@ -398,7 +401,7 @@ void KitaMainWindow::setupActions()
 void KitaMainWindow::slotURLLine()
 {
     KURL url = m_urlLine->text();
-    KURL datURL = Kita::ParseMisc::parseURLonly( url );
+    KURL datURL = Kita::getDatURL( url );
     m_threadDock->slotShowThread( datURL, KitaConfig::alwaysUseTab() );
 }
 
@@ -808,10 +811,11 @@ void KitaMainWindow::slotOpenURLRequestExt(
         return ;
     }
 
-    KURL datURL = Kita::ParseMisc::parseURLonly( url ); /* convert "thread URL" into "dat URL" */
-
-    QRegExp regexp( "http://([^/]*)/([^/]*)/dat/(.*)\\.dat$" );
-    if ( regexp.search( datURL.url() ) == -1 ) { /* Is this URL 2ch? */
+    /* open thread with new thread tab */
+    if ( Kita::DatManager::isThreadEnrolled( url ) ){
+       m_threadDock->slotShowThread( url, true );
+       return;
+    }
 
         /* bmp file */
         if ( Kita::ImgManager::isBMP( url ) ) {
@@ -859,10 +863,6 @@ void KitaMainWindow::slotOpenURLRequestExt(
         }
 
         KRun::runURL( url, mimetype );
-
-    } else {
-        m_threadDock->slotShowThread( url, true );
-    }
 }
 
 
index 9346f21..65ca9f6 100644 (file)
@@ -338,7 +338,7 @@ void KitaSubjectView::updateListViewItem( QListViewItem* item, Kita::Thread* thr
     }
 
     // no effect: m_unreadNum, m_readNum, m_newNum, markOrder
-    if ( Kita::DatManager::isMainThreadOpenedFast( datURL ) ) { /* opened */
+    if ( thread->isOpened() ) { /* opened */
         item->setPixmap( Col_Mark, SmallIcon( "open" ) );
     }
 }
index 71e43f9..fe52819 100644 (file)
@@ -33,16 +33,19 @@ using namespace Kita;
 
 DatInfoList DatManager::m_datInfoList;
 QMutex DatManager::m_mutex;
-QStringList DatManager::m_opendMainThreadList; 
 
 
 /*-----------------------------------------------------------------------*/
 
 
-/* create DatInfo explicitly. */ /* public */
+/* create DatInfo explicitly.                    */
+/* Usually, DatInfo is NOT created
+   if cache does not exist( i.e. ReadNum == 0 ). */ /* public */
 bool DatManager::createDatInfo( const KURL& url )
 {
-    if( getDatInfo( url, FALSE ) == NULL ) return FALSE;
+    if( getDatInfo( url,
+                   FALSE /* don't check the existence of cache */
+           ) == NULL ) return FALSE;
     return TRUE;
 }
 
@@ -132,15 +135,13 @@ DatInfo* DatManager::enrollDatInfo( const KURL& url, bool checkCached )
     /* Does cache exist ? */
     /* If cache does not exist, delete DatInfo here. */
     if( checkCached && datInfo->getReadNum() == 0 ){
-       qDebug("cache does not exist");
        delete datInfo;
        return NULL;
     }
 
     m_datInfoList.prepend( datInfo );
-    qDebug( "new DatInfo is created. (%d) %s",m_datInfoList.count(), datURL.prettyURL().ascii() );     
 
-    /* delete the all old instances */
+    /* delete the all old instances ( LRU algorithm )*/
     if ( m_datInfoList.count() > DMANAGER_MAXQUEUE ) {
 
        DatInfoList::Iterator it;
@@ -152,7 +153,6 @@ DatInfo* DatManager::enrollDatInfo( const KURL& url, bool checkCached )
             if ( ! deleteInfo->isLocked() ){
                 m_datInfoList.remove( it );
                 --it;
-                qDebug( "delete DatInfo (%d) %s",m_datInfoList.count(),deleteInfo->url().prettyURL().ascii());
                 deleteInfo->wait(); /* wait until DatInfo::m_mutex is released. */
                 delete deleteInfo;
            }
@@ -163,6 +163,19 @@ DatInfo* DatManager::enrollDatInfo( const KURL& url, bool checkCached )
 }
 
 
+/* public */
+void DatManager::deleteAllDatInfo()
+{
+    DatInfoList::Iterator it;
+    for ( it = m_datInfoList.begin(); it != m_datInfoList.end(); ++it ){
+
+       if( ( *it ) == NULL ) continue;
+       ( *it )->wait();
+       delete ( *it );
+    }
+}
+
+
 
 /*-------------------------------------------------------------*/
 
@@ -357,14 +370,11 @@ QString DatManager::getPlainTitle( const KURL& url, int num )
 /* get name (i.e. subject ) of thread from URL of dat file. */ /* public */
 const QString DatManager::threadName( const KURL& url )
 {
-
-    QString name = QString::null;
-
     KURL datURL = Kita::getDatURL( url );
     Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) name = thread->threadName();
+    if( thread != NULL ) return thread->threadName();
 
-    return name;
+    return QString::null;
 }
 
 
@@ -442,39 +452,33 @@ bool DatManager::getDomElement( const KURL& url, int num, DOM::HTMLDocument& hdo
 /* public */
 int DatManager::getResNum( const KURL& url )
 {
-    int resNum = 0;
-    
     KURL datURL = Kita::getDatURL( url );
     Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) resNum = thread->resNum();
+    if( thread != NULL ) return thread->resNum();
 
-    return resNum;
+    return 0;
 }
 
 
 /* public */
 int DatManager::getReadNum( const KURL& url )
 {
-    int readNum = 0;
-    
     KURL datURL = Kita::getDatURL( url );
     Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) readNum = thread->readNum();
+    if( thread != NULL ) return thread->readNum();
 
-    return readNum;
+    return 0;
 }
 
 
 /* public */
 int DatManager::getViewPos( const KURL& url )
 {
-    int viewPos = 0;
-
     KURL datURL = Kita::getDatURL( url );
     Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) viewPos = thread->viewPos();
+    if( thread != NULL ) return thread->viewPos();
 
-    return viewPos;
+    return 0;
 }
 
 
@@ -485,6 +489,7 @@ void DatManager::setViewPos( const KURL& url , int num )
     Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
     if( thread != NULL ) thread->setViewPos( num );
 
+    /* save idx */
     Kita::ThreadIndex::setViewPos( url, num );
 
     /* save "cache" */
@@ -501,7 +506,7 @@ int DatManager::getDatSize( const KURL& url )
     return datInfo->getDatSize();
 }
 
-/* public */
+/* get number of responses which have same ID. */ /* public */
 int DatManager::getNumByID( const KURL& url, const QString& strid )
 {
     DatInfo * datInfo = getDatInfo( url );
@@ -512,6 +517,16 @@ int DatManager::getNumByID( const KURL& url, const QString& strid )
 
 
 /* public */
+bool DatManager::isThreadEnrolled( const KURL& url )
+{
+    if( Kita::getDatURL( url ).isEmpty() ) return FALSE;
+
+    return TRUE;
+}
+
+
+
+/* public */
 bool DatManager::isResValid( const KURL& url, int num )
 {
     DatInfo * datInfo = getDatInfo( url );
@@ -541,7 +556,7 @@ bool DatManager::isResBroken( const KURL& url, int num )
 
 
 
-/* public */
+/* check if ID == strid  */ /* public */
 bool DatManager::checkID( const KURL& url, const QString& strid, int num )
 {
     DatInfo* datInfo = getDatInfo( url );
@@ -551,7 +566,7 @@ bool DatManager::checkID( const KURL& url, const QString& strid, int num )
 }
 
 
-/* check keywords */ /* public */
+/* check if keywords are included */ /* public */
 bool DatManager::checkWord( const KURL& url,
                             QStringList& strlist, int num,
                             bool checkOR /* AND or OR search */
@@ -607,39 +622,21 @@ void DatManager::resetAbone( const KURL& url )
 /* check if the thread is shown on the main thread tab. */ /* public */
 bool DatManager::isMainThreadOpened( const KURL& url )
 {
-    if( url.isEmpty() ) return FALSE;
-    QString datURL = Kita::getDatURL( url ).prettyURL();
-    if( datURL == QString::null ) return FALSE;
-    if( m_opendMainThreadList.contains( datURL ) ) return TRUE;
-
-    return FALSE;
-}
-
-/* omit calling Kita::getDatURL() */ /* public */
-bool DatManager::isMainThreadOpenedFast( const KURL& datURL )
-{
-    if( datURL.isEmpty() ) return FALSE;
-    if( m_opendMainThreadList.contains( datURL.prettyURL() ) ) return TRUE;
-
-    return FALSE;
-}
+    KURL datURL = Kita::getDatURL( url ).prettyURL();
+    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
+    if( thread == NULL ) return FALSE;
 
-/* public */
-void DatManager::addMainThreadToList( const KURL& url )
-{
-    QString datURL = Kita::getDatURL( url ).prettyURL();
-    if( datURL != QString::null ) m_opendMainThreadList += datURL;
+    return thread->isOpened();
 }
 
-/* public */
-void DatManager::removeMainThreadFromList( const KURL& url )
+void DatManager::setMainThreadOpened( const KURL& url, bool isOpened )
 {
-    QString datURL = Kita::getDatURL( url ).prettyURL();
-    m_opendMainThreadList.remove( datURL );
+    KURL datURL = Kita::getDatURL( url ).prettyURL();
+    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
+    if( thread != NULL ) thread->setIsOpened( isOpened );
 }
 
 
-
 /*--------------------------*/
 /* obsolete */
 
index 091908f..2da998a 100644 (file)
 #define KITADATMG_H
 
 #include <qvaluelist.h>
-#include <qstringlist.h>
 
 class QMutex;
 class KURL;
 class QObject;
+class QStringList;
 
 namespace DOM
 {
@@ -34,12 +34,12 @@ namespace Kita
     {
         static DatInfoList m_datInfoList;
         static QMutex m_mutex;
-       static QStringList m_opendMainThreadList; /* List of URL of thread shown on the main thread tab. */
 
     public:
 
         static bool createDatInfo( const KURL& url );
         static DatInfo* getDatInfoPointer( const KURL& url );
+        static void deleteAllDatInfo();
 
         /* caching */
         static bool updateCache( const KURL& url , const QObject* parent );
@@ -89,6 +89,7 @@ namespace Kita
        
        
         /* another information */
+        static bool isThreadEnrolled( const KURL& url );
         static bool isResValid( const KURL& url , int num );
         static bool isBroken( const KURL& url );
         static bool isResBroken( const KURL& url , int num );
@@ -104,15 +105,13 @@ namespace Kita
 
         /* check if the thread is shown on the main thread tab. */
         static bool isMainThreadOpened( const KURL& url );
-        static bool isMainThreadOpenedFast( const KURL& datURL );      
-        static void addMainThreadToList( const KURL& url );
-        static void removeMainThreadFromList( const KURL& url );
+        static void setMainThreadOpened( const KURL& url, bool isOpened );
 
         /* obsolete. Don't use them. */
        
         static const QString threadURL( const KURL& url );
         static bool is2chThread( const KURL& url );
-
+       
     private:
 
         static DatInfo* getDatInfo( const KURL& url, bool checkCached = TRUE );
index 4c02c57..aea92b0 100644 (file)
@@ -18,7 +18,7 @@ using namespace Kita;
 QDict<Thread>* Thread::m_threadDict = 0;
 
 Thread::Thread( const KURL& datURL )
-    : m_datURL( datURL ), m_threadName( 0 ) , m_resNum( 0 ), m_readNum( 0 ), m_viewPos( 0 )
+    : m_datURL( datURL ), m_threadName( 0 ) , m_resNum( 0 ), m_readNum( 0 ), m_viewPos( 0 ), m_isOpened( 0 )
 {}
 
 Thread::~Thread()
@@ -85,6 +85,20 @@ void Thread::setViewPos( int num )
     m_viewPos = num;
 }
 
+
+/* public */
+bool Thread::isOpened() const
+{
+    return m_isOpened;
+}
+
+/* public */
+void Thread::setIsOpened( bool isOpened )
+{
+    m_isOpened = isOpened;
+}
+
+
 /*--------------------------------------------*/
 
 /* static functions */
index 299ad7c..7861636 100644 (file)
@@ -28,6 +28,7 @@ namespace Kita
        int m_resNum;
        int m_readNum;
        int m_viewPos;
+       bool m_isOpened;
 
     public:
         Thread( const KURL& datURL );
@@ -47,6 +48,9 @@ namespace Kita
        const int viewPos() const;
        void setViewPos( int viewPos );
 
+       bool isOpened() const;
+       void setIsOpened( bool isOpend );
+       
        /*----------------------*/
        
         static Thread* getByURL( const KURL& datURL );
index eeb20ae..9459fb4 100644 (file)
@@ -81,28 +81,32 @@ void KitaHTMLPart::clearPart()
        }
     }
     m_updatedKokoyon = FALSE;
-
-    /* remove datURL from DatManager::m_opendMainThreadList */
-    /* Then, update subject tab.                            */
-    if( m_mode == HTMLPART_MODE_MAINPART && !m_datURL.isEmpty() ){
-       Kita::DatManager::removeMainThreadFromList( m_datURL );
-       emit updateSubjectTab( m_datURL );
-    }
     
-    if ( !m_datURL.isEmpty() ) {
+    /* clear variables */
+    m_anchorStack.clear();
+    m_centerNum = 0;
+    m_jumpNumAfterLoading = 0;
+    findTextInit();
+
+    if ( !m_datURL.isEmpty() ) {  /* This part is opened. */
 
         /* don't forget to unlock previous datURL here. */
         Kita::DatManager::unlock( m_datURL );
 
-        /* emit deactivated all thread view SIGNAL */
-        if ( m_mode == HTMLPART_MODE_MAINPART ) emit activateThreadView( QString::null );
+        if ( m_mode == HTMLPART_MODE_MAINPART ){ /* This part is on the main thread view. */
 
-    }
+           /* tell Thread class that "thread is closed" */         
+           Kita::DatManager::setMainThreadOpened( m_datURL, FALSE );
+           
+           /* emit "deactivated all thread view" SIGNAL */         
+           emit activateThreadView( QString::null );
 
-    m_anchorStack.clear();
-    m_centerNum = 0;
-    m_jumpNumAfterLoading = 0;
-    findTextInit();
+           /*  update subject tab. */
+           emit updateSubjectTab( m_datURL );
+       }
+    }
+    m_datURL = QString::null;
+    m_mode = HTMLPART_MODE_KHTML;
 }
 
 
@@ -114,24 +118,34 @@ bool KitaHTMLPart::setup( int mode, const KURL& url )
 
     clearPart();
 
-    /* Lock datURL. Don't forget to unlock it later ! */
     m_datURL = Kita::getDatURL( url );
-    Kita::DatManager::lock ( m_datURL );
+    m_mode = mode;
+    
+    if( m_mode == HTMLPART_MODE_MAINPART ){ /* This part is on the main thread view. */
+
+       /* create DatInfo explicitly to open new thread.   */
+       /* Usually, DatInfo is NOT created if ReadNum == 0.*/
+       /* See also DatManager::createDatInfo() and        */
+       /*          DatManager::getDatInfo().              */
+       if( Kita::DatManager::getReadNum( m_datURL ) == 0 ) Kita::DatManager::createDatInfo( m_datURL );
 
-    /* reset abone */
-    Kita::DatManager::resetAbone( m_datURL );
+       /* tell Thread class that "thread is opend" */
+       Kita::DatManager::setMainThreadOpened( m_datURL, TRUE );
+
+       /* reset abone */
+       Kita::DatManager::resetAbone( m_datURL );
+    }
+    
+    /* Lock datURL. Don't forget to unlock it later ! */
+    Kita::DatManager::lock ( m_datURL );
 
     /* create HTML Document */
     createHTMLDocument();
 
     /* create DOM manager */
-    m_mode = mode;
     if ( m_mode == HTMLPART_MODE_MAINPART || m_mode == HTMLPART_MODE_NAVI ) {
         m_domtree = new KitaDomTree( htmlDocument(), m_datURL );
     }
-
-    /* register datURL in DatManager::m_opendMainThreadList */
-    if( m_mode == HTMLPART_MODE_MAINPART ) Kita::DatManager::addMainThreadToList( m_datURL );
     
     return TRUE;
 }
@@ -1995,9 +2009,15 @@ void KitaHTMLPart::slotOnURL( const QString& url )
     /* another thread ? */
     if ( datURL.host() != m_datURL.host() || datURL.path() != m_datURL.path() ) {
 
-        /* show them with boadname & subject */
+        /* get board name */
         QString boardName = Kita::BoardManager::boardName( datURL );
         if ( boardName != QString::null ) innerHTML += "[" + boardName + "] ";
+
+       /* If idx file of datURL is not read, thread name cannot be obtained.
+          so, create DatInfo if cache exists, and read idx file in DatInfo::DatInfo(). */
+       Kita::DatManager::getDatInfoPointer( datURL ); 
+
+       /* get thread Name */
         QString subName = Kita::DatManager::threadName( datURL );
         if ( subName != QString::null ) innerHTML += subName + "<br><br>";
 
index c141e86..52f1256 100644 (file)
@@ -455,10 +455,7 @@ void KitaThreadView::setup( const KURL& datURL, int mode )
     /* setup                                 */
 
     m_datURL = Kita::getDatURL( datURL );
-
-    /* create DatInfo explicitly. */
-    Kita::DatManager::createDatInfo( m_datURL );
-    
+   
     /* setup HTMLPart */
     int partMode = HTMLPART_MODE_MAINPART;
     if ( mode == VIEWMODE_KITANAVI ) partMode = HTMLPART_MODE_NAVI;