OSDN Git Service

Use an initialization list in BoardData
[kita/kita.git] / kita / src / libkita / boardmanager.cpp
index 3ae63bf..9f5a58b 100644 (file)
@@ -9,29 +9,26 @@
 ***************************************************************************/
 
 #include "boardmanager.h"
-#include "qcp932codec.h"
-#include "downloadmanager.h"
-#include "cache.h"
-#include "favoritethreads.h"
-#include "thread.h"
-#include "threadinfo.h"
-#include "favoriteboards.h"
-#include "kita_misc.h"
-#include "threadindex.h"
 
-#include <config.h>  /* VERSION */
+#include <QtCore/QDateTime>
+#include <QtCore/QDir>
+#include <QtCore/QFile>
+#include <QtCore/QRegExp>
+#include <QtCore/QTextCodec>
+#include <QtCore/QTextStream>
 
-#include <kdebug.h>
-#include <kio/netaccess.h>
 #include <kfilterdev.h>
+#include <kio/netaccess.h>
 #include <kio/slaveconfig.h>
-#include <kdeversion.h>
 
-#include <qfile.h>
-#include <qdir.h>
-#include <qregexp.h>
-#include <qdatetime.h>
-#include <qeucjpcodec.h>
+#include "cache.h"
+#include "config.h"
+#include "favoriteboards.h"
+#include "favoritethreads.h"
+#include "kita_misc.h"
+#include "thread.h"
+#include "threadindex.h"
+#include "threadinfo.h"
 
 using namespace Kita;
 
@@ -40,31 +37,25 @@ using namespace Kita;
 
 /* BoardData */
 
-BoardData::BoardData( const QString& boardName,
+BoardData::BoardData(const QString& boardName,
                       const QString& hostname,
                       const QString& rootPath,
                       const QString& delimiter,
                       const QString& bbsPath,
                       const QString& ext,
-                      int boardtype )
+                      int boardtype)
+: m_boardName(boardName), m_readIdx(false), m_rootPath(rootPath),
+    m_delimiter(delimiter), m_bbsPath(bbsPath), m_ext(ext), m_type(boardtype)
 {
-    m_readIdx = FALSE;
-    m_boardName = boardName;
-    m_rootPath = rootPath;
-    m_delimiter = delimiter;
-    m_bbsPath = bbsPath;
-    m_ext = ext;
-    m_type = boardtype;
-
     /* set hostname and create URL of board */
-    setHostName( hostname );
+    setHostName(hostname);
 
     /* create default key */
-    QStringList keyHosts = m_hostname;
-    createKeys( keyHosts );
+    QStringList keyHosts(m_hostname);
+    createKeys(keyHosts);
 
     /* reset SETTING.TXT */
-    setSettingLoaded( FALSE );
+    setSettingLoaded(false);
 }
 
 BoardData::~BoardData()
@@ -72,22 +63,22 @@ BoardData::~BoardData()
 
 
 /* public */
-void BoardData::setHostName( const QString& hostName )
+void BoardData::setHostName(const QString& hostName)
 {
     m_hostname = hostName;
 
     /* m_basePath = (hostname)/(rootPath)/(bbsPath)/ */
-    m_basePath = m_hostname + m_rootPath + m_bbsPath + "/";
+    m_basePath = m_hostname + m_rootPath + m_bbsPath + '/';
 
-    switch ( m_type ) {
+    switch (m_type) {
 
     case Board_MachiBBS:  /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)?BBS=(bbsPath) */
-        m_cgiBasePath = m_hostname + m_rootPath + m_delimiter + "?BBS=" + m_bbsPath.mid( 1 );
+        m_cgiBasePath = m_hostname + m_rootPath + m_delimiter + "?BBS=" + m_bbsPath.mid(1);
         break;
 
         /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)/(bbsPath)/ */
     default:
-        m_cgiBasePath = m_hostname + m_rootPath + m_delimiter + m_bbsPath + "/";
+        m_cgiBasePath = m_hostname + m_rootPath + m_delimiter + m_bbsPath + '/';
         break;
     }
 }
@@ -97,13 +88,13 @@ void BoardData::setHostName( const QString& hostName )
 /* information */
 
 /* public */
-const bool BoardData::readIdx() const
+bool BoardData::readIdx() const
 {
     return m_readIdx;
 }
 
 /* public */
-void BoardData::setReadIdx( bool idx )
+void BoardData::setReadIdx(bool idx)
 {
     m_readIdx = idx;
 }
@@ -145,7 +136,7 @@ const QString& BoardData::ext() const
 }
 
 /* public */
-const int BoardData::type() const
+int BoardData::type() const
 {
     return m_type;
 }
@@ -167,13 +158,13 @@ const QString& BoardData::cgiBasePath() const
 /* SETTING.TXT */
 
 /* public */
-const QString BoardData::settingURL() const
+const QString BoardData::settingUrl() const
 {
     return m_basePath + "SETTING.TXT";
 }
 
 /* public */
-const bool BoardData::settingLoaded() const
+bool BoardData::settingLoaded() const
 {
     return m_settingLoaded;
 }
@@ -185,57 +176,57 @@ const QString& BoardData::defaultName() const
 }
 
 /* public */
-const int BoardData::lineNum() const
+int BoardData::lineNum() const
 {
     return m_linenum;
 }
 
 /* public */
-const int BoardData::msgCount() const
+int BoardData::msgCount() const
 {
     return m_msgCount;
 }
 
 /* public */
-const KURL& BoardData::titleImgURL() const
+const KUrl& BoardData::titleImgUrl() const
 {
-    return m_titleImgURL;
+    return m_titleImgUrl;
 }
 
 /* public */
-void BoardData::setSettingLoaded( bool set )
+void BoardData::setSettingLoaded(bool set)
 {
     m_settingLoaded = set;
-    if ( ! set ) {
-            m_defaultName = QString::null;
+    if (! set) {
+            m_defaultName.clear();
             m_linenum = 0;
             m_msgCount = 0;
-            m_titleImgURL = QString::null;
+            m_titleImgUrl.clear();
         }
 }
 
 /* public */
-void BoardData::setDefaultName( const QString& newName )
+void BoardData::setDefaultName(const QString& newName)
 {
     m_defaultName = newName;
 }
 
 /* public */
-void BoardData::setLineNum( int newLine )
+void BoardData::setLineNum(int newLine)
 {
     m_linenum = newLine;
 }
 
 /* public */
-void BoardData::setMsgCount( int msgCount )
+void BoardData::setMsgCount(int msgCount)
 {
     m_msgCount = msgCount;
 }
 
 /* public */
-void BoardData::setTitleImgURL( const KURL& url )
+void BoardData::setTitleImgUrl(const KUrl& url)
 {
-    m_titleImgURL = url;
+    m_titleImgUrl = url;
 }
 
 
@@ -243,7 +234,7 @@ void BoardData::setTitleImgURL( const KURL& url )
 /* keys */
 
 /* create keys of DB */ /* public */
-void BoardData::createKeys( const QStringList& keyHostList )
+void BoardData::createKeys(const QStringList& keyHostList)
 {
     /* reset keys */
     m_keyBasePathList.clear();
@@ -253,23 +244,23 @@ void BoardData::createKeys( const QStringList& keyHostList )
     m_keyHostList = keyHostList;
 
     /* m_basePath = (hostname)/(rootPath)/(bbsPath)/ */
-    for ( unsigned int i = 0; i < m_keyHostList.count(); ++i ) {
-        if ( m_keyHostList[ i ].length() > 0 )
-            m_keyBasePathList += m_keyHostList[ i ] + m_rootPath + m_bbsPath + "/";
+    for (int i = 0; i < m_keyHostList.count(); ++i) {
+        if (m_keyHostList[ i ].length() > 0)
+            m_keyBasePathList += m_keyHostList[ i ] + m_rootPath + m_bbsPath + '/';
     }
 
-    switch ( m_type ) {
+    switch (m_type) {
 
     case Board_MachiBBS:  /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)?BBS=(bbsPath) */
-        for ( unsigned int i = 0; i < m_keyHostList.count(); ++i )
+        for (int i = 0; i < m_keyHostList.count(); ++i)
             m_keyCgiBasePathList += m_keyHostList[ i ] + m_rootPath + m_delimiter
-                                    + "?BBS=" + m_bbsPath.mid( 1 );
+                                    + "?BBS=" + m_bbsPath.mid(1);
         break;
 
         /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)/(bbsPath)/ */
     default:
-        for ( unsigned int i = 0; i < m_keyHostList.count(); ++i )
-            m_keyCgiBasePathList += m_keyHostList[ i ] + m_rootPath + m_delimiter + m_bbsPath + "/";
+        for (int i = 0; i < m_keyHostList.count(); ++i)
+            m_keyCgiBasePathList += m_keyHostList[ i ] + m_rootPath + m_delimiter + m_bbsPath + '/';
         break;
     }
 }
@@ -301,11 +292,11 @@ const QStringList& BoardData::keyCgiBasePathList() const
 
 /* BoardManager */
 
-QCp932Codec* Kita::BoardManager::m_cp932Codec = NULL;
-QEucJpCodec* Kita::BoardManager::m_eucJpCodec = NULL;
-BoardDataList Kita::BoardManager::m_boardDataList;
-BoardData* Kita::BoardManager::m_previousBoardData = NULL;
-QString Kita::BoardManager::m_previousBoardURL;
+QTextCodec* BoardManager::m_cp932Codec = 0;
+QTextCodec* BoardManager::m_eucJpCodec = 0;
+BoardDataList BoardManager::m_boardDataList;
+BoardData* BoardManager::m_previousBoardData = 0;
+QString BoardManager::m_previousBoardUrl;
 
 
 BoardManager::BoardManager()
@@ -320,88 +311,88 @@ BoardManager::~BoardManager()
 }
 
 /* (hostname)/(rootPath)/(bbsPath)/ */ /* public */ /* static */
-const QString BoardManager::boardURL( const KURL& url )
+const QString BoardManager::boardUrl(const KUrl& url)
 {
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return QString::null;
+    BoardData * bdata = getBoardData(url);
+    if (bdata == 0) return QString();
 
     return bdata->basePath();
 }
 
 /* public */ /* static */
-const QStringList BoardManager::allBoardURLList()
+const QStringList BoardManager::allBoardUrlList()
 {
     QStringList urlList;
     urlList.clear();
 
-    for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it )
-        urlList += ( *it ) ->basePath();
+    for (BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it)
+        urlList += (*it) ->basePath();
 
     return urlList;
 }
 
 /* (hostname)/(rootPath) */ /* public */ /* static */
-const QString BoardManager::boardRoot( const KURL& url )
+const QString BoardManager::boardRoot(const KUrl& url)
 {
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return QString::null;
+    BoardData * bdata = getBoardData(url);
+    if (bdata == 0) return QString();
 
     return bdata->hostName() + bdata->rootPath();
 }
 
 /* (bbspath) */ /* public */ /* static */
-const QString BoardManager::boardPath( const KURL& url )
+const QString BoardManager::boardPath(const KUrl& url)
 {
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return QString::null;
+    BoardData * bdata = getBoardData(url);
+    if (bdata == 0) return QString();
 
     return bdata->bbsPath();
 }
 
 /* (ext) */ /* public */ /* static */
-const QString BoardManager::ext( const KURL& url )
+const QString BoardManager::ext(const KUrl& url)
 {
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return QString::null;
+    BoardData * bdata = getBoardData(url);
+    if (bdata == 0) return QString();
 
     return bdata->ext();
 }
 
 /* ID of board for writing */ /* public */ /* static */
-const QString BoardManager::boardID( const KURL& url )
+const QString BoardManager::boardId(const KUrl& url)
 {
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return QString::null;
+    BoardData * bdata = getBoardData(url);
+    if (bdata == 0) return QString();
 
-    return bdata->bbsPath().mid( 1 ); /* remove "/" */
+    return bdata->bbsPath().mid(1); /* remove "/" */
 }
 
 
 /* (hostname)/(rootPath)/(bbsPath)/subject.txt */ /* public */ /* static */
-const QString BoardManager::subjectURL( const KURL& url )
+const QString BoardManager::subjectUrl(const KUrl& url)
 {
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return QString::null;
+    BoardData * bdata = getBoardData(url);
+    if (bdata == 0) return QString();
 
     return bdata->basePath() + "subject.txt";
 }
 
 
 /* public */ /* static */
-const QString BoardManager::boardName( const KURL& url )
+const QString BoardManager::boardName(const KUrl& url)
 {
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return QString::null;
+    BoardData * bdata = getBoardData(url);
+    if (bdata == 0) return QString();
 
     return bdata->boardName();
 }
 
 
 /* public */ /* static */
-const int BoardManager::type( const KURL& url )
+int BoardManager::type(const KUrl& url)
 {
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return Board_Unknown;
+    BoardData * bdata = getBoardData(url);
+    if (bdata == 0) return Board_Unknown;
 
     return bdata->type();
 }
@@ -416,7 +407,7 @@ const int BoardManager::type( const KURL& url )
   Input:
  
   url:  URL of board.
-  oldLogs: If TRUE, search cache and get list of pointer of old threads.
+  oldLogs: If true, search cache and get list of pointer of old threads.
   online: online or offline mode.
  
   Output:
@@ -428,26 +419,26 @@ const int BoardManager::type( const KURL& url )
 void BoardManager::getThreadList(
 
     /* input */
-    const KURL& url,
+    const KUrl& url,
     bool oldLogs,
     bool online,
 
     /* output */
-    QPtrList< Thread >& threadList,
-    QPtrList< Thread >& oldLogList )
+    QList<Thread*>& threadList,
+    QList<Thread*>& oldLogList)
 {
     threadList.clear();
     oldLogList.clear();
 
     /* get all obtained threads list from cache */
-    if ( url.prettyURL() == "http://virtual/obtained/" ) {
+    if (url.prettyUrl() == "http://virtual/obtained/") {
 
-        QStringList bbslist = allBoardURLList();
+        QStringList bbslist = allBoardUrlList();
 
         /* search all cache dirs */
-        for ( QStringList::iterator it = bbslist.begin() ; it != bbslist.end(); ++it ) {
+        for (QStringList::iterator it = bbslist.begin() ; it != bbslist.end(); ++it) {
 
-            getCachedThreadList( ( *it ), threadList );
+            getCachedThreadList((*it), threadList);
         }
 
         return ;
@@ -455,76 +446,74 @@ void BoardManager::getThreadList(
 
     /*-------------------------*/
 
-    BoardData* bdata = getBoardData( url );
-    if ( bdata == NULL ) return ;
+    BoardData* bdata = getBoardData(url);
+    if (bdata == 0) return ;
 
     /* download subject.txt */
-    if ( online ) {
+    if (online) {
 
         /* make directory */
-        QString cacheDir = Cache::baseDir() + Cache::serverDir( url ) + Cache::boardDir( url );
-        if ( !Kita::mkdir( cacheDir ) ) return ;
+        Cache cache(url);
+        QString cacheDir = cache.getDirPath();
+        if (!QDir::root().mkpath(cacheDir)) return;
 
-        KIO::SlaveConfig::self() ->setConfigData( "http",
+        KIO::SlaveConfig::self() ->setConfigData("http",
                 url.host() ,
                 "UserAgent",
-                QString( "Monazilla/1.00 (Kita/%1)" ).arg( VERSION ) );
-        QString subjectPath = Cache::getSubjectPath( url );
-#if KDE_IS_VERSION( 3, 2, 0 )
-        KIO::NetAccess::download( subjectURL( url ), subjectPath, NULL );
-#else
-        KIO::NetAccess::download( subjectURL( url ), subjectPath );
-#endif
-
-        /* download SETTING.TXT */
-        loadBBSSetting( url );
+                QString("Monazilla/1.00 (Kita/%1)").arg(VERSION));
+        QString subjectPath = cache.getSubjectPath();
+        KIO::NetAccess::download(subjectUrl(url), subjectPath, 0);
     }
 
     /* open and read subject.txt */
-    readSubjectTxt( bdata, url, threadList );
+    readSubjectTxt(bdata, url, threadList);
 
     /* get old logs */
-    if ( oldLogs ) {
+    if (oldLogs) {
 
-        QPtrList< Thread > tmpList;
+        QList<Thread*> tmpList;
         tmpList.clear();
-        getCachedThreadList( url, tmpList );
+        getCachedThreadList(url, tmpList);
 
-        for ( unsigned i = 0; i < tmpList.count(); i++ ) {
-
-            if ( threadList.contains( tmpList.at( i ) ) == 0 ) oldLogList.append( tmpList.at( i ) );
+        for (int i = 0; i < tmpList.count(); i++) {
+            if (threadList.contains(tmpList.at(i)) == 0)
+                oldLogList.append(tmpList.at(i));
         }
     }
 }
 
 
 /* read the cache dir & get the list of all threads. */ /* private */ /* static */
-void BoardManager::getCachedThreadList( const KURL& url, QPtrList< Thread >& threadList )
+void BoardManager::getCachedThreadList(const KUrl& url, QList<Thread*>& threadList)
 {
-    QString cacheDir = Cache::baseDir() + Cache::serverDir( url ) + Cache::boardDir( url );
-    QDir d( cacheDir );
-    if ( d.exists() ) {
+    Cache cache(url);
+    QString cacheDir = cache.getDirPath();
+    QDir d(cacheDir);
+    if (d.exists()) {
 
         /* get all file names */
-        QString ext = BoardManager::getBoardData( url ) ->ext();
-        QString boardURL = BoardManager::getBoardData( url ) ->basePath();
-        QStringList flist = d.entryList( "*" + ext );
+        QString ext = BoardManager::getBoardData(url) ->ext();
+        QString boardUrl = BoardManager::getBoardData(url) ->basePath();
+        QStringList filter('*' + ext);
+        QStringList flist = d.entryList(filter);
 
-        for ( QStringList::iterator it = flist.begin(); it != flist.end(); ++it ) {
-            if ( ( *it ) == QString::null ) continue;
+        for (QStringList::iterator it = flist.begin(); it != flist.end(); ++it) {
+            if ((*it).isEmpty()) continue;
 
-            QString datURL = boardURL + "dat/" + ( *it );
+            QString datUrl = boardUrl + "dat/" + (*it);
 
             /* read idx file */
-            Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
-            if ( thread == NULL ) {
-
-                thread = Kita::Thread::getByURL( datURL );
-                if ( thread == NULL ) continue;
-                ThreadIndex::loadIndex( thread, datURL, FALSE );
+            Thread* thread = Thread::getByUrlNew(datUrl);
+            if (thread == 0) {
+
+                thread = Thread::getByUrl(datUrl);
+                if (thread == 0)
+                    continue;
+                ThreadIndex threadIndex(datUrl);
+                threadIndex.loadIndex(thread, false);
             }
 
-            if ( thread != NULL ) threadList.append( thread );
+            if (thread != 0) threadList.append(thread);
         }
     }
 }
@@ -532,91 +521,94 @@ void BoardManager::getCachedThreadList( const KURL& url, QPtrList< Thread >& thr
 
 
 /* open subject.txt and get list of Thread classes */ /* private */ /* static */
-bool BoardManager::readSubjectTxt( BoardData* bdata, const KURL& url, QPtrList< Thread >& threadList )
+bool BoardManager::readSubjectTxt(BoardData* bdata, const KUrl& url, QList<Thread*>& threadList)
 {
     /* get all names of cached files to read idx.  */
     QStringList cacheList;
-    if ( !bdata->readIdx() ) {
-
-        QString cacheDir = Cache::baseDir() + Cache::serverDir( url ) + Cache::boardDir( url );
-        QDir d( cacheDir );
-        if ( d.exists() ) {
-            QString ext = BoardManager::getBoardData( url ) ->ext();
-            cacheList = d.entryList( "*" + ext );
+    if (!bdata->readIdx()) {
+        Cache cache(url);
+        QString cacheDir = cache.getDirPath();
+        QDir d(cacheDir);
+        if (d.exists()) {
+            QString ext = BoardManager::getBoardData(url) ->ext();
+            QStringList filter('*' + ext);
+            cacheList = d.entryList(filter);
         }
     }
 
     /* open subject.txt */
-    QString subjectPath = Cache::getSubjectPath( url );
-    QIODevice * device = KFilterDev::deviceForFile( subjectPath, "application/x-gzip" );
-    if ( !device->open( IO_ReadOnly ) ) return FALSE;
+    Cache cache(url);
+    QString subjectPath = cache.getSubjectPath();
+    QIODevice * device = KFilterDev::deviceForFile(subjectPath, "application/x-gzip");
+    if (!device->open(QIODevice::ReadOnly)) return false;
 
-    QTextStream stream( device );
+    QTextStream stream(device);
 
-    if ( BoardManager::type( url ) == Board_JBBS ) {
-        if ( !m_eucJpCodec ) m_eucJpCodec = new QEucJpCodec();
-        stream.setCodec( m_eucJpCodec );
+    if (BoardManager::type(url) == Board_JBBS) {
+        if (!m_eucJpCodec) m_eucJpCodec = QTextCodec::codecForName("eucJP");
+        stream.setCodec(m_eucJpCodec);
     } else {
-        if ( !m_cp932Codec ) m_cp932Codec = new QCp932Codec();
-        stream.setCodec( m_cp932Codec );
+        if (!m_cp932Codec) m_cp932Codec = QTextCodec::codecForName("Shift-JIS");
+        stream.setCodec(m_cp932Codec);
     }
 
-    // parse subject.txt(only one format...)
-    // FIXME: need to refactoring
     QRegExp regexp;
-    switch ( BoardManager::type( url ) ) {
+    switch (BoardManager::type(url)) {
 
     case Board_MachiBBS:
     case Board_JBBS:
-        regexp.setPattern( "(\\d+\\.cgi),(.*)\\((\\d+)\\)" );
+        regexp.setPattern("(\\d+\\.cgi),(.*)\\((\\d+)\\)");
         break;
 
     default:
-        regexp.setPattern( "(\\d+\\.dat)<>(.*)\\((\\d+)\\)" );
+        regexp.setPattern("(\\d+\\.dat)<>(.*)\\((\\d+)\\)");
         break;
     }
     QString line;
 
-    while ( ( line = stream.readLine() ) != QString::null ) {
-        int pos = regexp.search( line );
-        if ( pos != -1 ) {
-            QString fname = regexp.cap( 1 );
-            QString subject = regexp.cap( 2 );
-            QString num = regexp.cap( 3 );
+    while (!(line = stream.readLine()).isEmpty()) {
+        int pos = regexp.indexIn(line);
+        if (pos != -1) {
+            QString fname = regexp.cap(1);
+            QString subject = regexp.cap(2);
+            QString num = regexp.cap(3);
 
             /* get pointer of Thread class */
-            QString datURL = boardURL( url ) + "dat/" + fname;
-            Kita::Thread* thread = Kita::Thread::getByURL( datURL );
-            if ( threadList.find( thread ) == -1 ) {
-                threadList.append( thread );
+            QString datUrl = boardUrl(url) + "dat/" + fname;
+            Thread* thread = Thread::getByUrl(datUrl);
+            ThreadIndex threadIndex(datUrl);
+            if (threadList.indexOf(thread) == -1) {
+                threadList.append(thread);
             }
 
             /* set thread name */
-            thread->setThreadName( subject );
+            thread->setThreadName(subject);
 
             /* load index file */
-            if ( !bdata->readIdx() ) {
+            if (!bdata->readIdx()) {
 
-                if ( cacheList.contains( fname ) ) ThreadIndex::loadIndex( thread, datURL, FALSE );
+                if (cacheList.contains(fname)) {
+                    threadIndex.loadIndex(thread, false);
+                }
             }
 
             /* update res num */
             int newNum = num.toInt();
-            if ( thread->readNum() ) { /* cache exists */
+            if (thread->readNum()) { /* cache exists */
                 int oldNum = thread->resNum();
 
-                if ( newNum > oldNum ) {
-                    Kita::ThreadIndex::setResNum( datURL, newNum );
+                if (newNum > oldNum) {
+                    threadIndex.setResNum(newNum);
                 }
             }
-            thread->setResNum( newNum );
+            thread->setResNum(newNum);
         }
     }
 
     device->close();
-    bdata->setReadIdx( TRUE ); /* never read idx files again */
+    bdata->setReadIdx(true); /* never read idx files again */
 
-    return TRUE;
+    return true;
 }
 
 /*---------------------------*/
@@ -625,12 +617,12 @@ bool BoardManager::readSubjectTxt( BoardData* bdata, const KURL& url, QPtrList<
 /* reset all BoardData */ /* public */ /* static */
 void BoardManager::clearBoardData()
 {
-    for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it )
-        delete( *it );
+    for (BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it)
+        delete(*it);
 
     m_boardDataList.clear();
-    m_previousBoardData = NULL;
-    m_previousBoardURL = QString::null;
+    m_previousBoardData = 0;
+    m_previousBoardUrl.clear();
 }
 
 /**
@@ -642,54 +634,54 @@ void BoardManager::clearBoardData()
  *
  * @param[out] oldURL
  *
- * @retval Board_enrollEnrolled if board is already enrolled. oldURL is QString::null.
- * @retval Board_enrollNew if board is new board. oldURL is QString::null.
+ * @retval Board_enrollEnrolled if board is already enrolled. oldURL is QString().
+ * @retval Board_enrollNew if board is new board. oldURL is QString().
  * @retval Board_enrollMoved if board is moved. oldURL is old URL.
  *
  * @note board is NOT enrolled when board is moved.
  * To enroll new URL, call BoardManager::moveBoard(). 
  *
- * "int type" is type of board. It could be "Kita::Board_Unknown". See also parseBoardURL().
+ * "int type" is type of board. It could be "Board_Unknown". See also parseBoardURL().
  * 
- * If "bool test" is TRUE, this function just checks if the board is enrolled (never enroll board).
+ * If "bool test" is true, this function just checks if the board is enrolled (never enroll board).
  *
  */ 
 /* public */ /* static */
-int BoardManager::enrollBoard( const KURL& url, const QString& boardName, QString& oldURL, int type, bool test )
+int BoardManager::enrollBoard(const KUrl& url, const QString& boardName, QString& oldUrl, int type, bool test)
 {
     QString hostname;
     QString rootPath;
     QString delimiter;
     QString bbsPath;
     QString ext;
-    type = parseBoardURL( url, type, hostname, rootPath, delimiter, bbsPath, ext );
-    oldURL = QString::null;
+    type = parseBoardUrl(url, type, hostname, rootPath, delimiter, bbsPath, ext);
+    oldUrl.clear();
 
-    if ( type == Board_Unknown ) return Board_enrollFailed;
+    if (type == Board_Unknown) return Board_enrollFailed;
 
     /* check if the board is enrolled or moved. */
-    for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it ) {
+    for (BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it) {
 
-        if ( ( *it ) ->boardName() == boardName
-                && ( *it ) ->type() == type
-                && ( *it ) ->bbsPath() == bbsPath ) {
+        if ((*it) ->boardName() == boardName
+                && (*it) ->type() == type
+                && (*it) ->bbsPath() == bbsPath) {
 
-            if ( ( *it ) ->hostName() == hostname
-                    && ( *it ) ->rootPath() == rootPath ) { /* enrolled */
+            if ((*it) ->hostName() == hostname
+                    && (*it) ->rootPath() == rootPath) { /* enrolled */
                 return Board_enrollEnrolled;
             } else { /* moved */
-                oldURL = ( *it ) ->basePath();
+                oldUrl = (*it) ->basePath();
                 return Board_enrollMoved;
             }
         }
     }
 
     /* test only */
-    if ( test ) return Board_enrollNew;
+    if (test) return Board_enrollNew;
 
     /* enroll new board */
-    BoardData* bdata = new BoardData( boardName, hostname, rootPath, delimiter, bbsPath, ext, type );
-    m_boardDataList.append( bdata );
+    BoardData* bdata = new BoardData(boardName, hostname, rootPath, delimiter, bbsPath, ext, type);
+    m_boardDataList.append(bdata);
 
     return Board_enrollNew;
 }
@@ -697,10 +689,10 @@ int BoardManager::enrollBoard( const KURL& url, const QString& boardName, QStrin
 
 /* parse board URL      */
 /* return board type.   */ /* private */ /* static */
-int BoardManager::parseBoardURL(
+int BoardManager::parseBoardUrl(
 
     /* input */
-    const KURL& url,
+    const KUrl& url,
     int type,   /* If type = Board_Unknown, type will be decided according to url. */
 
     /* output */
@@ -708,36 +700,36 @@ int BoardManager::parseBoardURL(
     QString& rootPath,
     QString& delimiter,
     QString& bbsPath,
-    QString& ext )
+    QString& ext)
 {
     hostname = url.protocol() + "://" + url.host();
-    rootPath = QString::null;
-    delimiter = QString::null;
-    bbsPath = QString::null;
-    ext = QString::null;
+    rootPath.clear();
+    delimiter.clear();
+    bbsPath.clear();
+    ext.clear();
 
     /* decide type */
-    if ( type == Board_Unknown ) {
+    if (type == Board_Unknown) {
 
-        if ( url.host().contains( "machi.to" ) ) type = Board_MachiBBS;
-        else if ( url.host().contains( "jbbs.livedoor.jp" ) ) type = Board_JBBS;
+        if (url.host().contains("machi.to")) type = Board_MachiBBS;
+        else if (url.host().contains("jbbs.livedoor.jp")) type = Board_JBBS;
         else type = Board_2ch;
     }
 
     /* parse */
-    switch ( type ) {
+    switch (type) {
 
     case Board_MachiBBS:     /* MACHI : http:// *.machi.to/(bbsPath)/ */
 
         delimiter = "/bbs/read.pl";
-        bbsPath = url.filename();
+        bbsPath = url.fileName();
         ext = ".cgi";
         break;
 
     case Board_JBBS:   /* JBBS : http://jbbs.livedoor.jp/(bbsPath)/ */
 
         delimiter = "/bbs/read.cgi";
-        bbsPath = url.prettyURL().remove( hostname );
+        bbsPath = url.prettyUrl().remove(hostname);
         type = Board_JBBS;
         ext = ".cgi";
         break;
@@ -745,68 +737,68 @@ int BoardManager::parseBoardURL(
     case Board_FlashCGI:  /* test for Flash CGI/Mini Thread  */
 
         delimiter = "/test/read.cgi";
-        bbsPath = url.filename();
-        rootPath = url.prettyURL().remove( hostname + "/" ).remove( bbsPath + "/" );
-        if ( rootPath.length() == 0 ) rootPath = QString::null;
+        bbsPath = url.fileName();
+        rootPath = url.prettyUrl().remove(hostname + '/').remove(bbsPath + '/');
+        if (rootPath.length() == 0) rootPath.clear();
         ext = ".dat";
         break;
 
     default:   /* 2ch : http://(hostname)/(rootPath)/(bbsPath)/ */
 
         delimiter = "/test/read.cgi";
-        bbsPath = url.filename();
-        rootPath = url.prettyURL().remove( hostname + "/" ).remove( bbsPath + "/" );
-        if ( rootPath.length() == 0 ) rootPath = QString::null;
+        bbsPath = url.fileName();
+        rootPath = url.prettyUrl().remove(hostname + '/').remove(bbsPath + '/');
+        if (rootPath.length() == 0) rootPath.clear();
         ext = ".dat";
         type = Board_2ch;
         break;
     }
 
     /* For example, if bbsPath = "linux/", then m_bbsPath = "/linux" */
-    const QRegExp exp( "/$" );
-    rootPath.remove( exp );
-    bbsPath.remove( exp );
-    if ( rootPath != QString::null && rootPath.at( 0 ) != '/' ) rootPath = "/" + rootPath;
-    if ( bbsPath != QString::null && bbsPath.at( 0 ) != '/' ) bbsPath = "/" + bbsPath;
+    const QRegExp exp("/$");
+    rootPath.remove(exp);
+    bbsPath.remove(exp);
+    if (!rootPath.isEmpty() && rootPath.at(0) != '/') rootPath = '/' + rootPath;
+    if (!bbsPath.isEmpty() && bbsPath.at(0) != '/') bbsPath = '/' + bbsPath;
 
     return type;
 }
 
 
 /* public */ /* static */
-bool BoardManager::isEnrolled( const KURL& url )
+bool BoardManager::isEnrolled(const KUrl& url)
 {
-    if ( getBoardData( url ) == NULL ) return FALSE;
-    return TRUE;
+    if (getBoardData(url) == 0) return false;
+    return true;
 }
 
 
 /* public */ /* static */
-BoardData* BoardManager::getBoardData( const KURL& url )
+BoardData* BoardManager::getBoardData(const KUrl& url)
 {
-    if ( url.isEmpty() ) return NULL;
-    QString urlstr = url.prettyURL();
+    if (url.isEmpty()) return 0;
+    QString urlstr = url.prettyUrl();
 
     /* cache */
-    if ( m_previousBoardData != NULL && m_previousBoardURL == urlstr ) return m_previousBoardData;
+    if (m_previousBoardData != 0 && m_previousBoardUrl == urlstr) return m_previousBoardData;
 
-    for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it ) {
+    for (BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it) {
 
-        int count = ( *it ) ->keyBasePathList().count();
-        for ( int i = 0; i < count ; ++i ) {
-            if ( urlstr.contains( ( *it ) ->keyBasePathList() [ i ] )
-                    || urlstr.contains( ( *it ) ->keyCgiBasePathList() [ i ] ) ) {
+        int count = (*it) ->keyBasePathList().count();
+        for (int i = 0; i < count ; ++i) {
+            if (urlstr.contains((*it) ->keyBasePathList() [ i ])
+                    || urlstr.contains((*it) ->keyCgiBasePathList() [ i ])) {
 
                 /* cache */
-                m_previousBoardData = ( *it );
-                m_previousBoardURL = urlstr;
+                m_previousBoardData = (*it);
+                m_previousBoardUrl = urlstr;
 
-                return ( *it );
+                return (*it);
             }
         }
     }
 
-    return NULL;
+    return 0;
 }
 
 
@@ -815,13 +807,13 @@ BoardData* BoardManager::getBoardData( const KURL& url )
 /* BBSHISTORY */
 
 
-/* load the bbs history file ( BBSHISTORY ), and create keys of Data Base.  */
+/* load the bbs history file (BBSHISTORY), and create keys of Data Base.  */
 /* Before calling this, enroll the board by enrollBoard().                  */
 /*
     ex) If the host of board moved like :
  
     http:://aaa.com -> http://bbb.com -> http://ccc.com -> http://ddd.com
-    
+
     then, BBSHISTORY is
  
     http://ccc.com
@@ -829,58 +821,59 @@ BoardData* BoardManager::getBoardData( const KURL& url )
     http://aaa.com
  
 */ /* public */ /* static */
-bool BoardManager::loadBBSHistory( const KURL& url )
+bool BoardManager::loadBBSHistory(const KUrl& url)
 {
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return FALSE;
+    BoardData * bdata = getBoardData(url);
+    if (bdata == 0) return false;
 
-    QStringList keyHosts = bdata->hostName();
+    QStringList keyHosts(bdata->hostName());
 
-    QFile file( Cache::getBBSHistoryPath( url ) );
-    if ( file.open( IO_ReadOnly ) ) {
+    Cache cache(url);
+    QFile file(cache.getBBSHistoryPath());
+    if (file.open(QIODevice::ReadOnly)) {
 
-        QTextStream ts( &file );
+        QTextStream ts(&file);
 
         QString line;
-        while ( !ts.eof() ) {
+        while (!ts.atEnd()) {
 
             line = ts.readLine();
             keyHosts += line;
         }
 
-        bdata->createKeys( keyHosts );
+        bdata->createKeys(keyHosts);
         file.close();
 
-        return TRUE;
+        return true;
     }
 
-    return FALSE;
+    return false;
 }
 
 
 /* public */ /* static */
-bool BoardManager::moveBoard( const KURL& fromURL, const KURL& toURL )
+bool BoardManager::moveBoard(const KUrl& fromUrl, const KUrl& toUrl)
 {
-    QString oldhost = fromURL.protocol() + "://" + fromURL.host();
-    QString newhost = toURL.protocol() + "://" + toURL.host();
+    QString oldhost = fromUrl.protocol() + "://" + fromUrl.host();
+    QString newhost = toUrl.protocol() + "://" + toUrl.host();
 
-    const QRegExp exp( "/$" );
-    QString oldURL = fromURL.prettyURL();
-    QString newURL = toURL.prettyURL();
-    oldURL.remove( exp );
-    newURL.remove( exp );
-    oldURL += "/";
-    newURL += "/";
+    const QRegExp exp("/$");
+    QString oldUrl = fromUrl.prettyUrl();
+    QString newUrl = toUrl.prettyUrl();
+    oldUrl.remove(exp);
+    newUrl.remove(exp);
+    oldUrl += '/';
+    newUrl += '/';
 
-    if ( oldURL == newURL ) return FALSE;
+    if (oldUrl == newUrl) return false;
 
     /* Is oldURL enrolled? */
-    BoardData* bdata = getBoardData( oldURL );
-    if ( bdata == NULL ) {
+    BoardData* bdata = getBoardData(oldUrl);
+    if (bdata == 0) {
 
         /* Is newURL enrolled? */
-        bdata = getBoardData( newURL );
-        if ( bdata == NULL ) return FALSE;
+        bdata = getBoardData(newUrl);
+        if (bdata == 0) return false;
     }
 
 
@@ -888,16 +881,16 @@ bool BoardManager::moveBoard( const KURL& fromURL, const KURL& toURL )
     /* update BoardData */
 
     /* get the path of old cache */
-    bdata->setHostName( oldhost );
+    bdata->setHostName(oldhost);
     QStringList keyHosts = bdata->keyHostList();
-    keyHosts.remove( oldhost );
-    keyHosts.prepend( oldhost );
-    bdata->createKeys( keyHosts );
-    QString oldCachePath = Cache::baseDir() + Cache::serverDir( bdata->basePath() )
-                           + Cache::boardDir( bdata->basePath() );
+    keyHosts.removeOne(oldhost);
+    keyHosts.prepend(oldhost);
+    bdata->createKeys(keyHosts);
+    Cache cache(bdata->basePath());
+    QString oldCachePath = cache.getDirPath();
 
     /* update URL */
-    bdata->setHostName( newhost );
+    bdata->setHostName(newhost);
 
     /* update keys */
     /* The order of keyHosts will be like this:
@@ -909,50 +902,53 @@ bool BoardManager::moveBoard( const KURL& fromURL, const KURL& toURL )
       
     */
     keyHosts = bdata->keyHostList();
-    keyHosts.remove( oldhost );
-    keyHosts.prepend( oldhost );
-    keyHosts.remove( newhost );
-    keyHosts.prepend( newhost );
-    bdata->createKeys( keyHosts );
+    keyHosts.removeOne(oldhost);
+    keyHosts.prepend(oldhost);
+    keyHosts.removeOne(newhost);
+    keyHosts.prepend(newhost);
+    bdata->createKeys(keyHosts);
 
     /* reset BoardData */
-    bdata->setReadIdx( FALSE );
-    bdata->setSettingLoaded( FALSE );
+    bdata->setReadIdx(false);
+    bdata->setSettingLoaded(false);
 
 
     /*---------------------------*/
     /* move cache dir */
 
     QDir qdir;
-    if ( ! qdir.exists( oldCachePath ) ) return TRUE;
+    if (! qdir.exists(oldCachePath)) return true;
 
     /* mkdir new server dir */
-    QString newCachePath = Cache::baseDir() + Cache::serverDir( bdata->basePath() );
-    Kita::mkdir( newCachePath );
+    Cache newCache(bdata->basePath());
+    QString newCachePath = Cache::baseDir() + newCache.serverDir();
+    QDir::root().mkpath(newCachePath);
 
     /* backup old dir */
-    newCachePath += Cache::boardDir( bdata->basePath() );
-    if ( qdir.exists ( newCachePath ) ) {
+    newCachePath += newCache.boardDir();
+    if (qdir.exists (newCachePath)) {
         QString bkupPath = newCachePath;
-        bkupPath.truncate( bkupPath.length() - 1 ); /* remove '/' */
-        bkupPath += "." + QString().setNum( QDateTime::currentDateTime().toTime_t() );
-        qdir.rename( newCachePath, bkupPath );
+        bkupPath.truncate(bkupPath.length() - 1); /* remove '/' */
+        bkupPath +=
+            '.' + QString::number(QDateTime::currentDateTime().toTime_t());
+        qdir.rename(newCachePath, bkupPath);
     }
 
     /* move cache dir */
-    if ( qdir.exists( oldCachePath ) ) {
-        qdir.rename( oldCachePath, newCachePath );
-    } else Kita::mkdir( newCachePath );
+    if (qdir.exists(oldCachePath)) {
+        qdir.rename(oldCachePath, newCachePath);
+    } else
+        QDir::root().mkpath(newCachePath);
 
     /* make old dir */
-    if ( ! qdir.exists( oldCachePath ) ) {
-        Kita::mkdir( oldCachePath );
+    if (! qdir.exists(oldCachePath)) {
+        QDir::root().mkpath(oldCachePath);
         /* create BBS_MOVED */
         QString movedPath = oldCachePath + "/BBS_MOVED";
-        QFile file( movedPath );
-        if ( file.open( IO_WriteOnly ) ) {
-            QTextStream stream( &file );
-            stream << newURL << endl;
+        QFile file(movedPath);
+        if (file.open(QIODevice::WriteOnly)) {
+            QTextStream stream(&file);
+            stream << newUrl << endl;
         }
         file.close();
     }
@@ -960,14 +956,15 @@ bool BoardManager::moveBoard( const KURL& fromURL, const KURL& toURL )
     /*---------------------------*/
     /* update BBSHISTRY */
 
-    QFile file( Cache::getBBSHistoryPath( bdata->basePath() ) );
-    if ( file.open( IO_WriteOnly ) ) {
+    Cache historyCache(bdata->basePath());
+    QFile file(historyCache.getBBSHistoryPath());
+    if (file.open(QIODevice::WriteOnly)) {
 
-        QTextStream ts( &file );
+        QTextStream ts(&file);
 
-        keyHosts.remove( newhost );
-        for ( QStringList::iterator it = keyHosts.begin() ; it != keyHosts.end(); ++it ) {
-            ts << ( *it ) << endl;
+        keyHosts.removeOne(newhost);
+        for (QStringList::iterator it = keyHosts.begin() ; it != keyHosts.end(); ++it) {
+            ts << (*it) << endl;
         }
 
         file.close();
@@ -976,136 +973,10 @@ bool BoardManager::moveBoard( const KURL& fromURL, const KURL& toURL )
 
     /*---------------------------*/
     /* update other information */
-    FavoriteThreads::replace( oldURL, newURL );
-    Kita::Thread::replace( oldURL, newURL );
-    KitaThreadInfo::replace( oldURL, newURL );
-    Kita::FavoriteBoards::replace( oldURL, newURL );
-
-    return TRUE;
-}
-
-
-/*--------------------------------*/
-/* SETTING.TXT  */
-
-
-/* public */ /* static */
-bool BoardManager::loadBBSSetting( const KURL& url, bool reload )
-{
-    /* Is board enrolled ? */
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return FALSE;
-    if ( bdata->type() != Board_2ch ) return FALSE;
-
-    KURL settingURL = bdata->settingURL();
-    QString path = Cache::getSettingPath( url );
-
-    /* now loading */
-    if ( DownloadManager::isLoadingNow( settingURL ) ) return FALSE;
-
-    /* already loaded */
-    if ( bdata->settingLoaded() && !reload ) return TRUE;
-
-    /* reset names, linenum, etc. */
-    bdata->setSettingLoaded( FALSE );
-
-    /* download SETTING.TXT.*/
-    DownloadManager::download( settingURL, path );
-    bdata->setSettingLoaded( TRUE );
-
-    return TRUE;
-}
-
-
-/* public */ /* static */
-QString BoardManager::getBBSDefaultName( const KURL& url )
-{
-    BoardData * bdata = openSettingTxt( url );
-    if ( bdata == NULL ) bdata = getBoardData( url );
-    if ( bdata == NULL ) return "(default name)";
-    if ( bdata->defaultName() == QString::null ) return "(default name)";
-    return bdata->defaultName();
-}
-
-
-/* public */ /* static */
-int BoardManager::getBBSMaxLine( const KURL& url )
-{
-    BoardData * bdata = openSettingTxt( url );
-    if ( bdata == NULL ) bdata = getBoardData( url );
-    if ( bdata == NULL ) return 0;
-    return bdata->lineNum();
-}
-
-/* public */ /* static */
-int BoardManager::getBBSMsgCount( const KURL& url )
-{
-    BoardData * bdata = openSettingTxt( url );
-    if ( bdata == NULL ) bdata = getBoardData( url );
-    if ( bdata == NULL ) return 0;
-    return bdata->msgCount();
-}
-
-
-/* public */ /* static */
-const KURL BoardManager::titleImgURL( const KURL& url )
-{
-    BoardData * bdata = openSettingTxt( url );
-    if ( bdata == NULL ) bdata = getBoardData( url );
-    if ( bdata == NULL ) return QString::null;
-    return bdata->titleImgURL();
-}
-
-/* open local SETTING.TXT, then get names, linenum, etc. */ /* private */ /* static */
-BoardData* BoardManager::openSettingTxt( const KURL& url )
-{
-    BoardData * bdata = getBoardData( url );
-    if ( bdata == NULL ) return NULL;
-    if ( !bdata->settingLoaded() ) return NULL;
-    if ( DownloadManager::isLoadingNow( bdata->settingURL() ) ) return NULL;
-    if ( bdata->defaultName() != QString::null ) return bdata;
-
-    QFile file( Cache::getSettingPath( url ) );
-    if ( file.open( IO_ReadOnly ) ) {
-
-        QTextStream ts( &file );
-        if ( m_cp932Codec == NULL ) m_cp932Codec = new QCp932Codec();
-        ts.setCodec( m_cp932Codec );
-
-        QString line;
-        while ( !ts.eof() ) {
-
-            line = ts.readLine();
-
-            /* default name */
-            QString key = "BBS_NONAME_NAME=";
-            if ( line.find( key ) != -1 ) bdata->setDefaultName( line.remove( key ) );
-
-            /* 0ch type */
-            key = "NANASI_NAME=";
-            if ( line.find( key ) != -1 ) bdata->setDefaultName( line.remove( key ) );
-
-            /* line number */
-            key = "BBS_LINE_NUMBER=";
-            if ( line.find( key ) != -1 ) bdata->setLineNum( line.remove( key ).toInt() * 2 );
-
-            /* msg count */
-            key = "BBS_MESSAGE_COUNT=";
-            if ( line.find( key ) != -1 ) bdata->setMsgCount( line.remove( key ).toInt() );
-
-            /* title image */
-            key = "BBS_TITLE_PICTURE=";
-            if ( line.find( key ) != -1 ) {
-                QString path = line.remove( key );
-                KURL titleImgURL = KURL( bdata->basePath(), path );
-                bdata->setTitleImgURL( titleImgURL );
-            }
-        }
-
-        file.close();
-    }
-
-    if ( bdata->defaultName() == QString::null ) bdata->setDefaultName( "(default name)" );
+    FavoriteThreads::replace(oldUrl, newUrl);
+    Thread::replace(oldUrl, newUrl);
+    ThreadInfo::replace(oldUrl, newUrl);
+    FavoriteBoards::replace(oldUrl, newUrl);
 
-    return bdata;
+    return true;
 }