OSDN Git Service

Add BoardDatabase class
[kita/kita.git] / kita / src / libkita / datmanager.cpp
index 836ee72..1415a03 100644 (file)
@@ -9,44 +9,43 @@
 ***************************************************************************/
 
 /* DatManager manages all information about thread */
+#include "datmanager.h"
 
-#include <qobject.h>
-#include <qmutex.h>
-#include <qstringlist.h>
-#include <qregexp.h>
-#include <qfile.h>
+#include <QtCore/QFile>
+#include <QtCore/QObject>
+#include <QtCore/QRegExp>
+#include <QtCore/QStringList>
 
-#include "thread.h"
-#include "threadinfo.h"
-#include "datmanager.h"
-#include "datinfo.h"
+#include "boarddatabase.h"
 #include "cache.h"
+#include "datinfo.h"
 #include "kita_misc.h"
-#include "kita-utf8.h"
-#include "kita-utf16.h"
+#include "thread.h"
 #include "threadindex.h"
-#include "boardmanager.h"
+#include "threadinfo.h"
 
 using namespace Kita;
 
-#define DMANAGER_MAXQUEUE 16
+static const int DMANAGER_MAXQUEUE = 16;
 
 DatInfoList DatManager::m_datInfoList;
-QMutex DatManager::m_mutex;
 
 
 /*-----------------------------------------------------------------------*/
+DatManager::DatManager(const KUrl& url) : m_url(url)
+{
+    m_datUrl = getDatUrl(url);
+    m_searchDatInfo = searchDatInfo();
+    m_datInfo = getDatInfo();
+}
 
 
 /* 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 cache does not exist(i.e. ReadNum == 0). */ /* public */
+bool DatManager::createDatInfo() const
 {
-    if( getDatInfo( url,
-                   FALSE /* don't check the existence of cache */
-           ) == NULL ) return FALSE;
-    return TRUE;
+    return getDatInfo(false /* don't check the existence of cache */) != 0;
 }
 
 
@@ -55,9 +54,9 @@ bool DatManager::createDatInfo( const KURL& url )
 /*    !!!  NOTICE  !!!   */
 /* It is very dangerous to access to DatInfo directly. */
 /* Usually, access to it through DatManager.           */ /* public */
-DatInfo * DatManager::getDatInfoPointer( const KURL& url )
+DatInfo * DatManager::getDatInfoPointer() const
 {
-    return getDatInfo( url );
+    return m_datInfo;
 }
 
 
@@ -65,98 +64,88 @@ DatInfo * DatManager::getDatInfoPointer( const KURL& url )
 
 
 /* This function searches instance of DatInfo in m_datInfoList.
-
    If cache exists, create DatInfo and return its pointer.
-
-   If checkCached == TRUE and cache does not exist, return NULL.
-
-   If checkCached == FALSE and cache does not exist,
+   If checkCached == true and cache does not exist, return 0.
+   If checkCached == false and cache does not exist,
    create DatInfo and return its pointer anyway.
-
    see also DatManager::searchDatInfo() and DatManager::createDatInfo() */ /* private */
 
-DatInfo* DatManager::getDatInfo( const KURL& url, bool checkCached )
+DatInfo* DatManager::getDatInfo(bool checkCached) const
 {
     /* search */
-    DatInfo* datInfo = searchDatInfo( url );
-    if( datInfo != NULL ) return datInfo;
-
     /* create and enroll instance */
-    return enrollDatInfo( url, checkCached );
+    return (m_searchDatInfo != 0)
+        ? m_searchDatInfo : enrollDatInfo(checkCached);
 }
 
 
 /* This function just searches instance of DatInfo specified by datURL
    without creating instance.  */ /* private */
-DatInfo* DatManager::searchDatInfo( const KURL& url )
+DatInfo* DatManager::searchDatInfo() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    KURL datURL = Kita::getDatURL( url );
-    if ( datURL.isEmpty() ) return NULL; /* This url is not enrolled in BoardManager. */
-    if ( m_datInfoList.count() == 0 ) return NULL;
+    if (m_datUrl.isEmpty())
+        return 0; /* This url is not enrolled in BoardManager. */
+    if (m_datInfoList.isEmpty())
+        return 0;
 
     int i = 0;
     DatInfoList::Iterator it;
     DatInfo* datInfo;
-    
-    for ( it = m_datInfoList.begin(); it != m_datInfoList.end(); ++it, i++ ) {
 
-       datInfo = ( *it );
+    for (it = m_datInfoList.begin(); it != m_datInfoList.end(); ++it, i++) {
+
+        datInfo = (*it);
 
-       if ( datURL == datInfo->url() ) {
+        if (m_datUrl == datInfo->url()) {
 
-           /* LRU */
-           if ( i ) {
-               m_datInfoList.remove( it );
-               m_datInfoList.prepend( datInfo );
-           }
+            /* LRU */
+            if (i) {
+                m_datInfoList.erase(it);
+                m_datInfoList.prepend(datInfo);
+            }
 
-           return datInfo;
-       }
+            return datInfo;
+        }
     }
 
-    return NULL;
+    return 0;
 }
 
 
-/* create and enroll the instance of DatInfo and delete old instances. 
-   Note that DatInfo::DatInfo() opens cached data and reads it. */  /* private */
-DatInfo* DatManager::enrollDatInfo( const KURL& url, bool checkCached )
+/* create and enroll the instance of DatInfo and delete old instances.
+   Note that DatInfo::DatInfo() opens cached data and reads it. */
+/* private */
+DatInfo* DatManager::enrollDatInfo(bool checkCached) const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    KURL datURL = Kita::getDatURL( url );
-    if( datURL.isEmpty() ) return NULL; /* This url is not enrolled in BoardManager. */
+    if (m_datUrl.isEmpty())
+        return 0; /* This url is not enrolled in BoardManager. */
 
     /* create DatInfo & read cached data */
-    DatInfo* datInfo = new DatInfo( datURL );
+    DatInfo* datInfo = new DatInfo(m_datUrl);
 
     /* Does cache exist ? */
     /* If cache does not exist, delete DatInfo here. */
-    if( checkCached && datInfo->getReadNum() == 0 ){
-       delete datInfo;
-       return NULL;
+    if (checkCached && datInfo->getReadNum() == 0) {
+        delete datInfo;
+        return 0;
     }
 
-    m_datInfoList.prepend( datInfo );
-
-    /* delete the all old instances ( LRU algorithm )*/
-    if ( m_datInfoList.count() > DMANAGER_MAXQUEUE ) {
-
-       DatInfoList::Iterator it;
-        for ( it = m_datInfoList.at( DMANAGER_MAXQUEUE ); it != m_datInfoList.end(); ++it ){
-
-           if( ( *it ) == NULL ) continue;
-           DatInfo* deleteInfo = ( *it );
-           
-            if ( ! deleteInfo->isLocked() ){
-                m_datInfoList.remove( it );
-                --it;
-                deleteInfo->wait(); /* wait until DatInfo::m_mutex is released. */
-                delete deleteInfo;
-           }
-       }
+    m_datInfoList.prepend(datInfo);
+
+    /* delete the all old instances (LRU algorithm)*/
+    if (m_datInfoList.count() > DMANAGER_MAXQUEUE) {
+        for (int i = DMANAGER_MAXQUEUE; i < m_datInfoList.count(); i++) {
+            DatInfo* deleteInfo = m_datInfoList.at(i);
+            if (deleteInfo == 0)
+                continue;
+            m_datInfoList.removeAt(i);
+            i--;
+            delete datInfo;
+        }
     }
 
     return datInfo;
@@ -166,13 +155,8 @@ 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 );
-    }
+    while (!m_datInfoList.isEmpty())
+        delete m_datInfoList.takeFirst();
 }
 
 
@@ -182,437 +166,326 @@ void DatManager::deleteAllDatInfo()
 
 
 /* update cache */   /* public */
-bool DatManager::updateCache( const KURL& url , const QObject* parent )
+bool DatManager::updateCache(const QObject* parent) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->updateCache( parent );
+    return (m_datInfo == 0) ? false : m_datInfo->updateCache(parent);
 }
 
 
 /* public */
-int DatManager::getResponseCode( const KURL& url )
+int DatManager::getResponseCode() const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
-
-    return datInfo->getResponseCode();
+    return (m_datInfo == 0) ? 0 : m_datInfo->getResponseCode();
 }
 
 /* public */
-int DatManager::getServerTime( const KURL& url )
+int DatManager::getServerTime() const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
-
-    return datInfo->getServerTime();
+    return (m_datInfo == 0) ? 0 : m_datInfo->getServerTime();
 }
 
 
 /* public */
-bool DatManager::deleteCache( const KURL& url )
+bool DatManager::deleteCache() const
 {
-    KURL datURL = Kita::getDatURL( url );
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread == NULL ) return FALSE;
-    if( thread->readNum() == 0 ) return FALSE;
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    if (thread == 0)
+        return false;
+    if (thread->readNum() == 0)
+        return false;
 
     /* init DatInfo */
-    DatInfo * datInfo = searchDatInfo( datURL );
-    if( datInfo ){
-       if( !datInfo->deleteCache() ) return FALSE;
+    if (m_searchDatInfo && !m_searchDatInfo->deleteCache()) {
+        return false;
     }
 
     /* reset readNum & veiwPos */
-    thread->setReadNum( 0 );
-    thread->setViewPos( 0 );
+    thread->setReadNum(0);
+    thread->setViewPos(0);
 
     /* delete cache */
-    QString cachePath = Kita::Cache::getPath( datURL );
-    QString indexPath = Kita::Cache::getIndexPath( datURL );
-    QFile::remove( indexPath );
-    QFile::remove( cachePath );
+    Cache cache(m_datUrl);
+    QString cachePath = cache.getPath();
+    QString indexPath = cache.getIndexPath();
+    QFile::remove(indexPath);
+    QFile::remove(cachePath);
 
     /* delete log from "cache" */
-    KitaThreadInfo::removeThreadInfo( datURL.prettyURL() );
-    return TRUE;
-}
-
-
-/* public */
-bool DatManager::isLoadingNow( const KURL& url )
-{
-    DatInfo * datInfo = searchDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->isLoadingNow();
+    ThreadInfo::removeThreadInfo(m_datUrl.prettyUrl());
+    return true;
 }
 
 
 /* public */
-void DatManager::stopLoading( const KURL& url )
+bool DatManager::isLoadingNow() const
 {
-    DatInfo * datInfo = searchDatInfo( url );
-    if ( datInfo == NULL ) return ;
-
-    return datInfo->stopLoading();
+    return (m_searchDatInfo == 0) ? false : m_searchDatInfo->isLoadingNow();
 }
 
 
-
-/*----------------------*/
-/* lock, unlock DatInfo */
-
-/* public */
-void DatManager::lock( const KURL& url )
-{
-    DatInfo * datInfo = getDatInfo( url );
-    if( datInfo == NULL ) return;
-
-    datInfo->lock ();
-}
-
 /* public */
-void DatManager::unlock( const KURL& url )
+void DatManager::stopLoading() const
 {
-    DatInfo * datInfo = searchDatInfo( url );
-    if ( datInfo == NULL ) return ;
-
-    datInfo->unlock();
+    if (m_searchDatInfo == 0)
+        return;
+    m_searchDatInfo->stopLoading();
 }
 
-
 /*--------------------------------------*/
 /* string data */
 
 
 /* public */
-const QString& DatManager::getDat( const KURL& url, int num )
+QString DatManager::getDat(int num) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getDat( num );
+    return (m_datInfo == 0) ? QString() : m_datInfo->getDat(num);
 }
 
 
 
 /* public */
-const QString& DatManager::getId( const KURL& url, int num )
+QString DatManager::getId(int num) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getId( num );
+    return (m_datInfo == 0) ? QString() : m_datInfo->getId(num);
 }
 
 
 /* public */
-QString DatManager::getPlainName( const KURL& url, int num )
+QString DatManager::getPlainName(int num) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getPlainName( num );
+    return (m_datInfo == 0) ? QString() : m_datInfo->getPlainName(num);
 }
 
 
 /* public */
-QString DatManager::getPlainBody( const KURL& url, int num )
+QString DatManager::getPlainBody(int num) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getPlainBody( num );
+    return (m_datInfo == 0) ? QString() : m_datInfo->getPlainBody(num);
 }
 
 
 /* public */
-QString DatManager::getPlainTitle( const KURL& url, int num )
+QString DatManager::getPlainTitle(int num) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getPlainTitle( num );
+    return (m_datInfo == 0) ? QString() : m_datInfo->getPlainTitle(num);
 }
 
 
-/* get name (i.e. subject ) of thread from URL of dat file. */ /* public */
-const QString DatManager::threadName( const KURL& url )
+/* get name (i.e. subject) of thread from URL of dat file. */ /* public */
+QString DatManager::threadName() const
 {
-    KURL datURL = Kita::getDatURL( url );
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) return thread->threadName();
-
-    return QString::null;
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    return (thread != 0) ? thread->threadName() : QString();
 }
 
 
 /* public */
-const QString DatManager::threadID( const KURL& url )
-{
-    KURL datURL = Kita::getDatURL( url );
-    return datURL.filename().section( ".", 0, 0 );
-}
-
-
-const QString DatManager::getCachePath( const KURL& url )
+QString DatManager::threadId() const
 {
-    return Kita::Cache::getPath( url );
-}
-
-const QString DatManager::getCacheIndexPath( const KURL& url )
-{
-    return Kita::Cache::getIndexPath( url );
+    return m_datUrl.fileName().section('.', 0, 0);
 }
 
 /*---------------------------------------*/
 /* HTML data */
 
 /* public */
-QString DatManager::getHtml( const KURL& url, int startnum, int endnum, bool checkAbone )
+QString DatManager::getHtml(int startnum, int endnum, bool checkAbone) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getHTMLString( startnum, endnum, checkAbone );
+    return (m_datInfo == 0)
+        ? QString() : m_datInfo->getHTMLString(startnum, endnum, checkAbone);
 }
 
 
 
 /* public */
-QString DatManager::getHtmlByID( const KURL& url, const QString& strid, int &count )
+QString DatManager::getHtmlById(const QString& strid, int &count) const
 {
-    DatInfo* datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getHtmlByID( strid, count );
+    return (m_datInfo == 0) ? QString() : m_datInfo->getHtmlById(strid, count);
 }
 
 
 
 /* Get HTML document of res tree.*/ /* public */
-QString DatManager::getTreeByRes( const KURL& url, const int rootnum, int &count )
+QString DatManager::getTreeByRes(int rootnum, int &count) const
 {
-    DatInfo* datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getTreeByRes( rootnum, count );
+    return (m_datInfo == 0)
+        ? QString() : m_datInfo->getTreeByRes(rootnum, count);
 }
 
 /* Get HTML document of reverse res tree.*/ /* public */
-QString DatManager::getTreeByResReverse( const KURL& url, const int rootnum, int &count )
+QString DatManager::getTreeByResReverse(int rootnum, int &count) const
 {
-    DatInfo* datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getTreeByResReverse( rootnum, count );
+    return (m_datInfo == 0)
+        ? QString() : m_datInfo->getTreeByResReverse(rootnum, count);
 }
 
 
 /* public */
-int DatManager::getResNum( const KURL& url )
+int DatManager::getResNum() const
 {
-    KURL datURL = Kita::getDatURL( url );
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) return thread->resNum();
-
-    return 0;
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    return (thread != 0) ? thread->resNum() : 0;
 }
 
 
 /* public */
-int DatManager::getReadNum( const KURL& url )
+int DatManager::getReadNum() const
 {
-    KURL datURL = Kita::getDatURL( url );
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) return thread->readNum();
-
-    return 0;
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    return (thread != 0) ? thread->readNum() : 0;
 }
 
 
 /* public */
-int DatManager::getViewPos( const KURL& url )
+int DatManager::getViewPos() const
 {
-    KURL datURL = Kita::getDatURL( url );
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) return thread->viewPos();
-
-    return 0;
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    return (thread != 0) ? thread->viewPos() : 0;
 }
 
 
 /* public */
-void DatManager::setViewPos( const KURL& url , int num )
+void DatManager::setViewPos(int num) const
 {
-    KURL datURL = Kita::getDatURL( url );
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) thread->setViewPos( num );
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    if (thread != 0)
+        thread->setViewPos(num);
 
     /* save idx */
-    Kita::ThreadIndex::setViewPos( url, num );
+    ThreadIndex threadIndex(m_url);
+    threadIndex.setViewPos(num);
 
     /* save "cache" */
-    KitaThreadInfo::setReadNum( datURL.prettyURL(), num );
+    ThreadInfo::setReadNum(m_datUrl.prettyUrl(), num);
 }
 
 
 /* public */
-int DatManager::getDatSize( const KURL& url )
+int DatManager::getDatSize() const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
-
-    return datInfo->getDatSize();
+    return (m_datInfo == 0) ? 0 : m_datInfo->getDatSize();
 }
 
 /* get number of responses which have same ID. */ /* public */
-int DatManager::getNumByID( const KURL& url, const QString& strid )
+int DatManager::getNumById(const QString& strid) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
-
-    return datInfo->getNumByID( strid );
+    return (m_datInfo == 0) ? 0 : m_datInfo->getNumById(strid);
 }
 
 
 /* public */
-bool DatManager::isThreadEnrolled( const KURL& url )
+bool DatManager::isThreadEnrolled() const
 {
-    if( Kita::getDatURL( url ).isEmpty() ) return FALSE;
-
-    return TRUE;
+    return !m_datUrl.isEmpty();
 }
 
 
 /* public */
-bool DatManager::is2chThread( const KURL& url )
+bool DatManager::is2chThread() const
 {
-    if( BoardManager::type( url ) != Board_2ch ) return FALSE;
-    if( Kita::getDatURL( url ).isEmpty() ) return FALSE;
-    
-    QRegExp url_2ch( ".*\\.2ch\\.net" );
-    QRegExp url_bbspink( ".*\\.bbspink\\.com" );
-    
-    if ( url_2ch.search( url.host() ) != -1
-        || url_bbspink.search( url.host() ) != -1 ) return TRUE;
-    
-    return FALSE;
+    BoardDatabase db(m_url);
+    if (db.type() != Board_2ch)
+        return false;
+    if (m_datUrl.isEmpty())
+        return false;
+
+    QRegExp url_2ch(".*\\.2ch\\.net");
+    QRegExp url_bbspink(".*\\.bbspink\\.com");
+
+    if (url_2ch.indexIn(m_url.host()) != -1
+            || url_bbspink.indexIn(m_url.host()) != -1)
+        return true;
+
+    return false;
 }
 
 
 /* public */
-bool DatManager::isResValid( const KURL& url, int num )
+bool DatManager::isResValid(int num) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->isResValid( num );
+    return (m_datInfo == 0) ? false : m_datInfo->isResValid(num);
 }
 
 
 /* public */
-bool DatManager::isBroken( const KURL& url )
+bool DatManager::isBroken() const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->isBroken();
+    return (m_datInfo == 0) ? false : m_datInfo->isBroken();
 }
 
 /* public */
-bool DatManager::isResBroken( const KURL& url, int num )
+bool DatManager::isResBroken(int num) const
 {
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->isResBroken( num );
+    return (m_datInfo == 0) ? false : m_datInfo->isResBroken(num);
 }
 
 
 
 /* check if ID == strid  */ /* public */
-bool DatManager::checkID( const KURL& url, const QString& strid, int num )
+bool DatManager::checkId(const QString& strid, int num) const
 {
-    DatInfo* datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->checkID( strid, num );
+    return (m_datInfo == 0) ? false : m_datInfo->checkId(strid, num);
 }
 
 
 /* check if keywords are included */ /* public */
-bool DatManager::checkWord( const KURL& url,
-                            QStringList& strlist, int num,
-                            bool checkOR /* AND or OR search */
-                          )
+bool DatManager::checkWord(const QStringList& strlist, int num,
+        bool checkOr /* AND or OR search */) const
 {
-    DatInfo* datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->checkWord( strlist, num, checkOR );
+    return (m_datInfo == 0)
+        ? false : m_datInfo->checkWord(strlist, num, checkOr);
 }
 
 
 /* public */
-bool DatManager::isMarked( const KURL& url, int num )
+bool DatManager::isMarked(int num) const
 {
-    KURL datURL = Kita::getDatURL( url );
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread == NULL ) return FALSE;
-
-    return thread->isMarked( num );
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    return (thread == 0) ? false : thread->isMarked(num);
 }
 
 
 /* public */
-void DatManager::setMark( const KURL& url, int num, bool mark )
+void DatManager::setMark(int num, bool mark) const
 {
-    KURL datURL = Kita::getDatURL( url );
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread == NULL ) return;
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    if (thread == 0)
+        return;
 
-    if( thread->setMark( num, mark ) ) Kita::ThreadIndex::setMarkList( url, thread->markList() );
+    if (thread->setMark(num, mark)) {
+        ThreadIndex threadIndex(m_url);
+        threadIndex.setMarkList(thread->markList());
+    }
 }
 
 
 /* public */
-bool DatManager::checkAbone( const KURL& url, int num )
+bool DatManager::checkAbone(int num) const
 {
-    DatInfo* datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->checkAbone( num );
+    return (m_datInfo == 0) ? false : m_datInfo->checkAbone(num);
 }
 
 
 /* public */
-void DatManager::resetAbone( const KURL& url )
+void DatManager::resetAbone() const
 {
-    DatInfo* datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return ;
-
-    datInfo->resetAbone();
+    if (m_datInfo == 0)
+        return;
+    m_datInfo->resetAbone();
 }
 
 
 /* check if the thread is shown on the main thread tab. */ /* public */
-bool DatManager::isMainThreadOpened( const KURL& url )
+bool DatManager::isMainThreadOpened() const
 {
-    KURL datURL = Kita::getDatURL( url ).prettyURL();
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread == NULL ) return FALSE;
-
-    return thread->isOpened();
+    return (m_datInfo == 0) ? false : m_datInfo->isOpened();
 }
 
-void DatManager::setMainThreadOpened( const KURL& url, bool isOpened )
+void DatManager::setMainThreadOpened(bool isOpened) const
 {
-    KURL datURL = Kita::getDatURL( url ).prettyURL();
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-    if( thread != NULL ) thread->setIsOpened( isOpened );
+    if (m_datInfo == 0)
+        return;
+    m_datInfo->setOpened(isOpened);
 }
 
 
@@ -620,8 +493,7 @@ void DatManager::setMainThreadOpened( const KURL& url, bool isOpened )
 /* obsolete */
 
 /* public */
-const QString DatManager::threadURL( const KURL& url )
+QString DatManager::threadUrl() const
 {
-    return Kita::getThreadURL( url );
+    return getThreadUrl(m_url);
 }
-