OSDN Git Service

Add BoardDatabase class
[kita/kita.git] / kita / src / libkita / datmanager.cpp
index 928e6b4..1415a03 100644 (file)
@@ -1,6 +1,6 @@
-/**************************************************************************
-*   Copyright (C) 2003 by Hideki Ikemoto , (c)2004 by 421                 *
-*   ikemo@wakaba.jp                                                       *
+/***************************************************************************
+*   Copyright (C) 2004 by Kita Developers                                 *
+*   ikemo@users.sourceforge.jp                                            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
@@ -8,92 +8,44 @@
 *   (at your option) any later version.                                   *
 ***************************************************************************/
 
-#include <qobject.h>
-#include <qmutex.h>
-#include <qstringlist.h>
-
-#include "thread.h"
-#include "parsemisc.h"
+/* DatManager manages all information about thread */
 #include "datmanager.h"
+
+#include <QtCore/QFile>
+#include <QtCore/QObject>
+#include <QtCore/QRegExp>
+#include <QtCore/QStringList>
+
+#include "boarddatabase.h"
+#include "cache.h"
 #include "datinfo.h"
-#include "board.h"
 #include "kita_misc.h"
-#include "kita-utf8.h"
-#include "kita-utf16.h"
+#include "thread.h"
+#include "threadindex.h"
+#include "threadinfo.h"
 
 using namespace Kita;
 
-#define DMANAGER_MAXQUEUE 16
+static const int DMANAGER_MAXQUEUE = 16;
 
-/*-------------------------------------------------*/
-/* DatManager manages all information about *.dat. */
+DatInfoList DatManager::m_datInfoList;
 
-DatInfoList DatManager::m_datInfo;
-QMutex DatManager::m_mutex;
 
-/* This function searches instance of DatInfo specified by url.
-   If instance does not exist, create instance.  */  /* private */
-DatInfo* DatManager::getDatInfo( const KURL& url )
+/*-----------------------------------------------------------------------*/
+DatManager::DatManager(const KUrl& url) : m_url(url)
 {
-    if ( url.isEmpty() ) {
-        return NULL;
-    }
-
-    int i = 0;
-    DatInfoList::Iterator it;
-    DatInfo* datInfo;
-    
-    KURL inurl = Kita::ParseMisc::parseURLonly( url );
-    
-    /* search */
-    if ( m_datInfo.count() ) {
-        for ( it = m_datInfo.begin(); it != m_datInfo.end(); ++it, i++ ) {
-
-           datInfo = ( *it );
-
-            if ( inurl == datInfo->url() ){
-
-                /* LRU */
-                if ( i ) {
-                    m_datInfo.remove( it );
-                    m_datInfo.prepend( datInfo );
-                }
-
-                return datInfo;
-            }
-        }
-    }
-
-    /* not found */
-
-    /*create new DatInfo and insert it into list. */
-    KURL daturl = url.protocol() + "://" + url.host() + url.path();
-
-    datInfo = new DatInfo( daturl );
-    if ( datInfo->getRawDat() == QString::null ) { /* cache does not exist */
-        delete( datInfo );
-
-        return NULL;
-    }
-
-    m_datInfo.prepend( datInfo );
-
-    /* delete the last items of list */
-    if ( m_datInfo.count() > DMANAGER_MAXQUEUE ) {
-
-       /* collect unlocked datInfos */
-       typedef QValueList<KURL> DELETELIST;
-       DELETELIST deleteList;
+    m_datUrl = getDatUrl(url);
+    m_searchDatInfo = searchDatInfo();
+    m_datInfo = getDatInfo();
+}
 
-       for ( it = m_datInfo.at(DMANAGER_MAXQUEUE); it != m_datInfo.end(); ++it ) 
-           if(! (*it)->isLocked() ) deleteList += ( *it ) ->url();
 
-       /* delete unlocked datInfos */
-       for (DELETELIST::Iterator itdel = deleteList.begin(); itdel != deleteList.end(); ++itdel )
-           deleteDatInfoPrivate( (*itdel) );
-    }
-
-    return datInfo;
+/* create DatInfo explicitly.                    */
+/* Usually, DatInfo is NOT created
+   if cache does not exist(i.e. ReadNum == 0). */ /* public */
+bool DatManager::createDatInfo() const
+{
+    return getDatInfo(false /* don't check the existence of cache */) != 0;
 }
 
 
@@ -102,580 +54,446 @@ DatInfo* DatManager::getDatInfo( 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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    return getDatInfo( url );
+    return m_datInfo;
 }
 
 
+/*------------------------------------------------------------------------*/
 
-/* public */
-void DatManager::deleteDatInfo( const KURL& url )
-{
-    QMutexLocker locker( &m_mutex );
-
-    deleteDatInfoPrivate(url);
-}
-
-
-/* private */
-void DatManager::deleteDatInfoPrivate( const KURL& url ){
-
-    DatInfoList::Iterator it;
-
-    for ( it = m_datInfo.begin(); it != m_datInfo.end(); ++it ) {
-        if ( url == ( *it )->url() ){
-
-           if(! (*it)->isLocked() ){
-               m_datInfo.remove( it );
-               delete( *it );
-           }
 
-            return ;
-        }
-    }
+/* 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 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(bool checkCached) const
+{
+    /* search */
+    /* create and enroll instance */
+    return (m_searchDatInfo != 0)
+        ? m_searchDatInfo : enrollDatInfo(checkCached);
 }
 
 
-
-
-/*-------------------------------------------------------------*/
-
-
-
-/*--------------------------------------*/
-/* update cache, then return new lines  */
-
-/* If cache does not exist, then create
-   the new instance.                    */ /* public */
-bool DatManager::updateCache( const KURL& url , const QObject* parent )
+/* This function just searches instance of DatInfo specified by datURL
+   without creating instance.  */ /* private */
+DatInfo* DatManager::searchDatInfo() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-
-    /* create new DatInfo */
-    if ( datInfo == NULL ){
-       datInfo = new DatInfo( url );
-       m_datInfo.prepend( datInfo );
-    }
-    
-    return datInfo->updateCache(parent);
-}
+    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;
 
-/* public */
-int DatManager::getResponseCode( const KURL& url )
-{
-    QMutexLocker locker( &m_mutex );
+    for (it = m_datInfoList.begin(); it != m_datInfoList.end(); ++it, i++) {
 
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
+        datInfo = (*it);
 
-    return datInfo->getResponseCode();
-}
+        if (m_datUrl == datInfo->url()) {
 
-/* public */
-int DatManager::getServerTime( const KURL& url )
-{
-    QMutexLocker locker( &m_mutex );
+            /* LRU */
+            if (i) {
+                m_datInfoList.erase(it);
+                m_datInfoList.prepend(datInfo);
+            }
 
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
+            return datInfo;
+        }
+    }
 
-    return datInfo->getServerTime();
+    return 0;
 }
 
 
-/* public */
-bool DatManager::deleteCache( const KURL& url, QWidget* parent )
+/* 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 );
-
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
+    if (m_datUrl.isEmpty())
+        return 0; /* This url is not enrolled in BoardManager. */
 
-    return datInfo->deleteCache(parent);
-}
+    /* create DatInfo & read cached data */
+    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 0;
+    }
 
-/* public */
-bool DatManager::isLoadingNow( const KURL& url )
-{
-    QMutexLocker locker( &m_mutex );
-
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
+    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->isLoadingNow();
+    return datInfo;
 }
 
 
 /* public */
-void DatManager::stopLoading( const KURL& url )
+void DatManager::deleteAllDatInfo()
 {
-
-    /* Don't use QMutexLocker here !!
-       It will cause deadlock , because
-       Kita::Access::stopJob() calls KitaThreadView::slotFinishLoad() back.  */
-    m_mutex.lock();
-    DatInfo * datInfo = getDatInfo( url );
-    m_mutex.unlock();
-    if ( datInfo == NULL ) return;
-
-    return datInfo->stopLoading();
+    while (!m_datInfoList.isEmpty())
+        delete m_datInfoList.takeFirst();
 }
 
 
 
-/*----------------------*/
-/* lock, unlock DatInfo */
-
-/* If cache does not exist, then create
-   the new instance and lock it. 
-
-   Don't forget to unlock it. */  /* public */
+/*-------------------------------------------------------------*/
 
-void DatManager::lock( const KURL& url )
-{
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
 
-    /* create new DatInfo */
-    if ( datInfo == NULL ){
-       datInfo = new DatInfo( url );
-       m_datInfo.prepend( datInfo );
-    }
-    
-    datInfo->lock();
-}
 
-void DatManager::unlock( const KURL& url )
+/* update cache */   /* public */
+bool DatManager::updateCache(const QObject* parent) const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return;
-    
-    datInfo->unlock();
+    return (m_datInfo == 0) ? false : m_datInfo->updateCache(parent);
 }
 
 
-/*--------------------------------------*/
-/* string data */
-
 /* public */
-const QString& DatManager::getRawDat( const KURL& url )
+int DatManager::getResponseCode() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getRawDat();
+    return (m_datInfo == 0) ? 0 : m_datInfo->getResponseCode();
 }
 
-
 /* public */
-const QString& DatManager::getDat( const KURL& url, int num )
+int DatManager::getServerTime() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getDat( num );
+    return (m_datInfo == 0) ? 0 : m_datInfo->getServerTime();
 }
 
 
-
 /* public */
-const QString& DatManager::getId( const KURL& url, int num )
+bool DatManager::deleteCache() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    if (thread == 0)
+        return false;
+    if (thread->readNum() == 0)
+        return false;
 
-    return datInfo->getId( num );
-}
+    /* init DatInfo */
+    if (m_searchDatInfo && !m_searchDatInfo->deleteCache()) {
+        return false;
+    }
 
+    /* reset readNum & veiwPos */
+    thread->setReadNum(0);
+    thread->setViewPos(0);
 
-/* public */
-const QString& DatManager::getName( const KURL& url, int num )
-{
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
+    /* delete cache */
+    Cache cache(m_datUrl);
+    QString cachePath = cache.getPath();
+    QString indexPath = cache.getIndexPath();
+    QFile::remove(indexPath);
+    QFile::remove(cachePath);
 
-    return datInfo->getName( num );
+    /* delete log from "cache" */
+    ThreadInfo::removeThreadInfo(m_datUrl.prettyUrl());
+    return true;
 }
 
 
 /* public */
-const QString& DatManager::getBody( const KURL& url, int num )
+bool DatManager::isLoadingNow() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getBody( num );
+    return (m_searchDatInfo == 0) ? false : m_searchDatInfo->isLoadingNow();
 }
 
 
 /* public */
-QString DatManager::getPlainName( const KURL& url, int num )
+void DatManager::stopLoading() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getPlainName(num);
+    if (m_searchDatInfo == 0)
+        return;
+    m_searchDatInfo->stopLoading();
 }
 
-
-/* public */
-QString DatManager::getPlainBody( const KURL& url, int num )
-{
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getPlainBody(num);
-}
+/*--------------------------------------*/
+/* string data */
 
 
 /* public */
-QString DatManager::getPlainTitle( const KURL& url, int num )
+QString DatManager::getDat(int num) const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getPlainTitle(num);
+    return (m_datInfo == 0) ? QString() : m_datInfo->getDat(num);
 }
 
 
-/* get URL of thread from URL of dat file. */ /* public */
-const QString DatManager::threadURL( const KURL& url )
-{
-    QMutexLocker locker( &m_mutex );
 
-    KURL datURL =  Kita::ParseMisc::parseURLonly( url );
-    return Kita::datToThread( datURL.prettyURL() );
+/* public */
+QString DatManager::getId(int num) const
+{
+    return (m_datInfo == 0) ? QString() : m_datInfo->getId(num);
 }
 
 
-/* get name (i.e. subject ) of thread from URL of dat file. */ /* public */
-const QString& DatManager::threadName( const KURL& url )
+/* public */
+QString DatManager::getPlainName(int num) const
 {
-    QMutexLocker locker( &m_mutex );
-
-    KURL datURL =  Kita::ParseMisc::parseURLonly( url );    
-    Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-
-    if( thread == NULL ){
-       
-       /* get subject from DatInfo */
-       DatInfo * datInfo = getDatInfo( url );
-       if ( datInfo == NULL ) return QString::null;
-       return datInfo->getSubject();
-    }
-
-    return thread->name();
+    return (m_datInfo == 0) ? QString() : m_datInfo->getPlainName(num);
 }
 
 
 /* public */
-const QString DatManager::threadID( const KURL& url )
+QString DatManager::getPlainBody(int num) const
 {
-    QMutexLocker locker( &m_mutex );
-
-    KURL datURL =  Kita::ParseMisc::parseURLonly( url );
-    return datURL.filename().section( ".", 0, 0 );
+    return (m_datInfo == 0) ? QString() : m_datInfo->getPlainBody(num);
 }
 
 
-/* get URL of board from URL of dat file. */ /* public */
-const QString DatManager::boardURL( const KURL& url )
+/* public */
+QString DatManager::getPlainTitle(int num) const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    KURL datURL =  Kita::ParseMisc::parseURLonly( url );
-    return Kita::datToBoard( datURL.prettyURL() );
+    return (m_datInfo == 0) ? QString() : m_datInfo->getPlainTitle(num);
 }
 
 
-/* get name of board from URL of dat file. */ /* public */
-const QString& DatManager::boardName( const KURL& url )
+/* get name (i.e. subject) of thread from URL of dat file. */ /* public */
+QString DatManager::threadName() const
 {
-    QMutexLocker locker( &m_mutex );
-
-    KURL datURL =  Kita::ParseMisc::parseURLonly( url );
-    QString bdURL = Kita::datToBoard( datURL.prettyURL() );
-    return Kita::Board::getName( bdURL );
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    return (thread != 0) ? thread->threadName() : QString();
 }
 
 
 /* public */
-const QString DatManager::boardID( const KURL& url )
+QString DatManager::threadId() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    KURL datURL =  Kita::ParseMisc::parseURLonly( url );
-    return KURL( Kita::datToBoard( datURL.prettyURL() ) ).fileName();
+    return m_datUrl.fileName().section('.', 0, 0);
 }
 
-
 /*---------------------------------------*/
 /* HTML data */
 
 /* public */
-QString DatManager::getHtml( const KURL& url, int startnum, int endnum )
+QString DatManager::getHtml(int startnum, int endnum, bool checkAbone) const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return QString::null;
-
-    return datInfo->getHtml(startnum,endnum);
+    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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    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);
 }
 
-/* Get DOM element */ /* public */
-bool DatManager::getDomElement(const KURL& url, int num, DOM::HTMLDocument& hdoc, DOM::Element& retelm)
-{
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo* datInfo = getDatInfo(url);
-    if(datInfo == NULL) return FALSE;
 
-    return datInfo->getDomElement(num,hdoc,retelm);
+/* public */
+int DatManager::getResNum() const
+{
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    return (thread != 0) ? thread->resNum() : 0;
 }
 
 
-
 /* public */
-int DatManager::getMaxResNumber( const KURL& url )
+int DatManager::getReadNum() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
-
-    return datInfo->getMaxResNumber();
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    return (thread != 0) ? thread->readNum() : 0;
 }
 
 
+/* public */
+int DatManager::getViewPos() const
+{
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    return (thread != 0) ? thread->viewPos() : 0;
+}
+
 
 /* public */
-int DatManager::getNumByID( const KURL& url, const QString& strid )
+void DatManager::setViewPos(int num) const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    if (thread != 0)
+        thread->setViewPos(num);
 
-    return datInfo->getNumByID(strid);
-}
+    /* save idx */
+    ThreadIndex threadIndex(m_url);
+    threadIndex.setViewPos(num);
 
+    /* save "cache" */
+    ThreadInfo::setReadNum(m_datUrl.prettyUrl(), num);
+}
 
 
 /* public */
-int DatManager::getKokoyonNum( const KURL& url )
+int DatManager::getDatSize() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
+    return (m_datInfo == 0) ? 0 : m_datInfo->getDatSize();
+}
 
-    return datInfo->getKokoyonNum();
+/* get number of responses which have same ID. */ /* public */
+int DatManager::getNumById(const QString& strid) const
+{
+    return (m_datInfo == 0) ? 0 : m_datInfo->getNumById(strid);
 }
 
 
 /* public */
-void DatManager::setKokoyonNum( const KURL& url , int num )
+bool DatManager::isThreadEnrolled() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return;
-
-    return datInfo->setKokoyonNum(num);
+    return !m_datUrl.isEmpty();
 }
 
 
 /* public */
-int DatManager::getDatSize( const KURL& url )
+bool DatManager::is2chThread() const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return 0;
+    BoardDatabase db(m_url);
+    if (db.type() != Board_2ch)
+        return false;
+    if (m_datUrl.isEmpty())
+        return false;
 
-    return datInfo->getDatSize();
-}
+    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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->isResBroken(num);
+    return (m_datInfo == 0) ? false : m_datInfo->isResBroken(num);
 }
 
 
 
-/* public */
-bool DatManager::checkID(const KURL& url, const QString& strid, int num )
+/* check if ID == strid  */ /* public */
+bool DatManager::checkId(const QString& strid, int num) const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    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 keywords */ /* public */
-bool DatManager::checkWord(const KURL& url,
-                           QStringList& strlist, int num,
-                           bool checkOR /* AND or OR search */
-    )
+/* check if keywords are included */ /* public */
+bool DatManager::checkWord(const QStringList& strlist, int num,
+        bool checkOr /* AND or OR search */) const
 {
-    QMutexLocker locker( &m_mutex );
-    
-    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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return FALSE;
-
-    return datInfo->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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    DatInfo * datInfo = getDatInfo( url );
-    if ( datInfo == NULL ) return;
+    Thread* thread = Thread::getByUrlNew(m_datUrl);
+    if (thread == 0)
+        return;
 
-    datInfo->setMark( num, mark );
+    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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    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
 {
-    QMutexLocker locker( &m_mutex );
-    
-    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
+{
+    return (m_datInfo == 0) ? false : m_datInfo->isOpened();
+}
 
+void DatManager::setMainThreadOpened(bool isOpened) const
+{
+    if (m_datInfo == 0)
+        return;
+    m_datInfo->setOpened(isOpened);
+}
 
 
+/*--------------------------*/
+/* obsolete */
 
+/* public */
+QString DatManager::threadUrl() const
+{
+    return getThreadUrl(m_url);
+}