***************************************************************************/
#include "boardmanager.h"
-#include "qcp932codec.h"
-#include "downloadmanager.h"
-#include "cache.h"
-#include "favoritethreads.h"
-#include "threadinfo.h"
-#include "favoriteboards.h"
-#include <kdebug.h>
+#include <QtCore/QDateTime>
+#include <QtCore/QDir>
+#include <QtCore/QFile>
+#include <QtCore/QRegExp>
+#include <QtCore/QTextCodec>
+#include <QtCore/QTextStream>
+
+#include <kfilterdev.h>
#include <kio/netaccess.h>
+#include <kio/slaveconfig.h>
-#include <qfile.h>
-#include <qdir.h>
-#include <qregexp.h>
-#include <qdatetime.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;
/* BoardData */
-BoardData::BoardData( const QString& boardName,
- const QString& hostname,
- const QString& rootPath,
- const QString& delimiter,
- const QString& bbsPath,
- const QString& ext,
- int boardtype )
-{
- m_boardName = boardName;
- m_rootPath = rootPath;
- m_delimiter = delimiter;
- m_bbsPath = bbsPath;
- m_ext = ext;
- m_type = boardtype;
-
- /* For example, if bbsPath = "linux/", then m_bbsPath = "/linux" */
- const QRegExp exp( "/$" );
- m_rootPath.remove( exp );
- m_delimiter.remove( exp );
- m_bbsPath.remove( exp );
- if( m_rootPath != QString::null && m_rootPath.at( 0 ) != '/' ) m_rootPath = "/" + m_rootPath;
- if( m_delimiter != QString::null && m_delimiter.at( 0 ) != '/' ) m_delimiter = "/" + m_delimiter;
- if( m_bbsPath != QString::null && m_bbsPath.at( 0 ) != '/' ) m_bbsPath = "/" + m_bbsPath;
-
+BoardData::BoardData(const QString& boardName,
+ const QString& hostname,
+ const QString& rootPath,
+ const QString& delimiter,
+ const QString& bbsPath,
+ const QString& ext,
+ int boardtype)
+: m_boardName(boardName), m_readIdx(false), 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 );
-/*
- qDebug( "%s (type = %d)", ( const char * ) m_boardName.local8Bit(),m_type );
- qDebug( "basePath: %s", m_basePath.ascii() );
- qDebug( "cgiBasePath: %s", m_cgiBasePath.ascii() );
-*/
+ setSettingLoaded(false);
}
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 + "/";
-
- switch( m_type ){
-
- case Board_2ch: /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)/(bbsPath)/ */
- case Board_JBBS:
- m_cgiBasePath = m_hostname + m_rootPath + m_delimiter + m_bbsPath + "/";
- break;
-
- case Board_MachiBBS: /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)?BBS=(bbsPath) */
- m_cgiBasePath = m_hostname + m_rootPath + m_delimiter + "?BBS=" + m_bbsPath.mid( 1 );
- break;
+ m_basePath = m_hostname + m_rootPath + m_bbsPath + '/';
+
+ 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);
+ break;
+
+ /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)/(bbsPath)/ */
+ default:
+ m_cgiBasePath = m_hostname + m_rootPath + m_delimiter + m_bbsPath + '/';
+ break;
}
}
/* information */
/* public */
+bool BoardData::readIdx() const
+{
+ return m_readIdx;
+}
+
+/* public */
+void BoardData::setReadIdx(bool idx)
+{
+ m_readIdx = idx;
+}
+
+/* public */
const QString& BoardData::boardName() const
{
return m_boardName;
}
/* public */
-const int BoardData::type() const
+int BoardData::type() const
{
return m_type;
}
/* 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;
}
}
/* public */
-const int BoardData::lineNum() const
+int BoardData::lineNum() const
{
return m_linenum;
}
/* public */
-void BoardData::setSettingLoaded( bool set )
+int BoardData::msgCount() const
+{
+ return m_msgCount;
+}
+
+/* public */
+const KUrl& BoardData::titleImgUrl() const
+{
+ return m_titleImgUrl;
+}
+
+/* public */
+void BoardData::setSettingLoaded(bool set)
{
m_settingLoaded = set;
- if( ! set ){
- m_defaultName == QString::null;
- m_linenum = 0;
- }
+ if (! set) {
+ m_defaultName.clear();
+ m_linenum = 0;
+ m_msgCount = 0;
+ 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)
+{
+ m_msgCount = msgCount;
+}
+
+/* public */
+void BoardData::setTitleImgUrl(const KUrl& url)
+{
+ m_titleImgUrl = url;
+}
+
/*---------------------------*/
/* keys */
/* create keys of DB */ /* public */
-void BoardData::createKeys( const QStringList& keyHostList )
+void BoardData::createKeys(const QStringList& keyHostList)
{
/* reset keys */
m_keyBasePathList.clear();
m_keyCgiBasePathList.clear();
m_keyHostList.clear();
-
+
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 + "/";
+ /* m_basePath = (hostname)/(rootPath)/(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 ){
-
- case Board_2ch: /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)/(bbsPath)/ */
- case Board_JBBS:
- for( unsigned int i = 0; i < m_keyHostList.count(); ++i )
- m_keyCgiBasePathList += m_keyHostList[i] + m_rootPath + m_delimiter + m_bbsPath + "/";
- break;
-
- case Board_MachiBBS: /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)?BBS=(bbsPath) */
- for( unsigned int i = 0; i < m_keyHostList.count(); ++i )
- m_keyCgiBasePathList += m_keyHostList[i] + m_rootPath + m_delimiter
- + "?BBS=" + m_bbsPath.mid( 1 );
- break;
+ switch (m_type) {
+
+ case Board_MachiBBS: /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)?BBS=(bbsPath) */
+ for (int i = 0; i < m_keyHostList.count(); ++i)
+ m_keyCgiBasePathList += m_keyHostList[ i ] + m_rootPath + m_delimiter
+ + "?BBS=" + m_bbsPath.mid(1);
+ break;
+
+ /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)/(bbsPath)/ */
+ default:
+ for (int i = 0; i < m_keyHostList.count(); ++i)
+ m_keyCgiBasePathList += m_keyHostList[ i ] + m_rootPath + m_delimiter + m_bbsPath + '/';
+ break;
}
}
/* BoardManager */
-QCp932Codec* BoardManager::m_cp932Codec = NULL;
+QTextCodec* BoardManager::m_cp932Codec = 0;
+QTextCodec* BoardManager::m_eucJpCodec = 0;
BoardDataList BoardManager::m_boardDataList;
-BoardData* BoardManager::m_previousBoardData = NULL;
+BoardData* BoardManager::m_previousBoardData = 0;
+QString BoardManager::m_previousBoardUrl;
BoardManager::BoardManager()
-{}
+{
+ clearBoardData();
+}
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();
+ 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)
+{
+ 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();
}
/*---------------------------*/
+/* ThreadList */
+
+
+/* get list of pointers of Thread classes. */
+/*
+ Input:
+
+ url: URL of board.
+ oldLogs: If true, search cache and get list of pointer of old threads.
+ online: online or offline mode.
+
+ Output:
+
+ threadList: list of pointers of Thread classes.
+ oldLogList: list of pointers of old threads.
+
+ */ /* public */ /* static */
+void BoardManager::getThreadList(
+
+ /* input */
+ const KUrl& url,
+ bool oldLogs,
+ bool online,
+
+ /* output */
+ QList<Thread*>& threadList,
+ QList<Thread*>& oldLogList)
+{
+ threadList.clear();
+ oldLogList.clear();
+
+ /* get all obtained threads list from cache */
+ if (url.prettyUrl() == "http://virtual/obtained/") {
+
+ QStringList bbslist = allBoardUrlList();
+
+ /* search all cache dirs */
+ for (QStringList::iterator it = bbslist.begin() ; it != bbslist.end(); ++it) {
+
+ getCachedThreadList((*it), threadList);
+ }
+
+ return ;
+ }
+
+ /*-------------------------*/
+
+ BoardData* bdata = getBoardData(url);
+ if (bdata == 0) return ;
+
+ /* download subject.txt */
+ if (online) {
+
+ /* make directory */
+ Cache cache(url);
+ QString cacheDir = cache.getDirPath();
+ if (!QDir::root().mkpath(cacheDir)) return;
+
+ KIO::SlaveConfig::self() ->setConfigData("http",
+ url.host() ,
+ "UserAgent",
+ 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);
+
+ /* get old logs */
+ if (oldLogs) {
+
+ QList<Thread*> tmpList;
+ tmpList.clear();
+ getCachedThreadList(url, tmpList);
+
+ 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, QList<Thread*>& threadList)
+{
+ 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 filter('*' + ext);
+ QStringList flist = d.entryList(filter);
+
+ for (QStringList::iterator it = flist.begin(); it != flist.end(); ++it) {
+ if ((*it).isEmpty()) continue;
+
+ QString datUrl = boardUrl + "dat/" + (*it);
+
+ /* read idx file */
+ 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 != 0) threadList.append(thread);
+ }
+ }
+}
+
+
+
+/* open subject.txt and get list of Thread classes */ /* private */ /* static */
+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()) {
+ 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 */
+ 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);
+
+ if (BoardManager::type(url) == Board_JBBS) {
+ if (!m_eucJpCodec) m_eucJpCodec = QTextCodec::codecForName("eucJP");
+ stream.setCodec(m_eucJpCodec);
+ } else {
+ if (!m_cp932Codec) m_cp932Codec = QTextCodec::codecForName("Shift-JIS");
+ stream.setCodec(m_cp932Codec);
+ }
+
+ QRegExp regexp;
+ switch (BoardManager::type(url)) {
+
+ case Board_MachiBBS:
+ case Board_JBBS:
+ regexp.setPattern("(\\d+\\.cgi),(.*)\\((\\d+)\\)");
+ break;
+
+ default:
+ regexp.setPattern("(\\d+\\.dat)<>(.*)\\((\\d+)\\)");
+ break;
+ }
+ QString line;
+
+ 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;
+ Thread* thread = Thread::getByUrl(datUrl);
+ ThreadIndex threadIndex(datUrl);
+ if (threadList.indexOf(thread) == -1) {
+ threadList.append(thread);
+ }
+
+ /* set thread name */
+ thread->setThreadName(subject);
+
+ /* load index file */
+ if (!bdata->readIdx()) {
+
+ if (cacheList.contains(fname)) {
+ threadIndex.loadIndex(thread, false);
+ }
+ }
+
+ /* update res num */
+ int newNum = num.toInt();
+ if (thread->readNum()) { /* cache exists */
+ int oldNum = thread->resNum();
+
+ if (newNum > oldNum) {
+ threadIndex.setResNum(newNum);
+ }
+ }
+ thread->setResNum(newNum);
+ }
+ }
+
+ device->close();
+ bdata->setReadIdx(true); /* never read idx files again */
+
+ return true;
+}
+
+/*---------------------------*/
/* BoardData */
/* reset all BoardData */ /* public */ /* static */
-void BoardManager::clearBoardData()
+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 = 0;
+ m_previousBoardUrl.clear();
+}
+
+/**
+ *
+ * @param[in] board
+ * @param[in] boardName
+ * @param[in] type
+ * @param[in] test
+ *
+ * @param[out] oldURL
+ *
+ * @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 "Board_Unknown". See also parseBoardURL().
+ *
+ * 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)
+{
+ QString hostname;
+ QString rootPath;
+ QString delimiter;
+ QString bbsPath;
+ QString ext;
+ type = parseBoardUrl(url, type, hostname, rootPath, delimiter, bbsPath, ext);
+ oldUrl.clear();
+
+ 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) {
+
+ if ((*it) ->boardName() == boardName
+ && (*it) ->type() == type
+ && (*it) ->bbsPath() == bbsPath) {
+
+ if ((*it) ->hostName() == hostname
+ && (*it) ->rootPath() == rootPath) { /* enrolled */
+ return Board_enrollEnrolled;
+ } else { /* moved */
+ oldUrl = (*it) ->basePath();
+ return Board_enrollMoved;
+ }
+ }
+ }
+
+ /* test only */
+ if (test) return Board_enrollNew;
+
+ /* enroll new board */
+ BoardData* bdata = new BoardData(boardName, hostname, rootPath, delimiter, bbsPath, ext, type);
+ m_boardDataList.append(bdata);
+
+ return Board_enrollNew;
}
-/* enroll board */ /* public */ /* static */
-void BoardManager::enrollBoard( const KURL& url, const QString& boardName )
+
+/* parse board URL */
+/* return board type. */ /* private */ /* static */
+int BoardManager::parseBoardUrl(
+
+ /* input */
+ const KUrl& url,
+ int type, /* If type = Board_Unknown, type will be decided according to url. */
+
+ /* output */
+ QString& hostname,
+ QString& rootPath,
+ QString& delimiter,
+ QString& bbsPath,
+ QString& ext)
{
- qDebug( "\nenroll %s %s", ( const char * ) boardName.local8Bit(),url.prettyURL().ascii());
-
- if( isEnrolled( url ) ) return;
+ hostname = url.protocol() + "://" + url.host();
+ rootPath.clear();
+ delimiter.clear();
+ bbsPath.clear();
+ ext.clear();
- QString hostname = url.protocol() + "://" + url.host();
- QString rootPath = QString::null;
- QString delimiter = QString::null;
- QString bbsPath = QString::null;
- QString ext = QString::null;
- int type = Board_Unknown;
+ /* decide type */
+ if (type == Board_Unknown) {
- /* MACHI : http:// *.machi.to/(bbsPath)/ */
- if( url.host().contains( "machi.to" ) ){
-
- delimiter = "/bbs/read.pl";
- bbsPath = url.filename();
- ext = ".cgi";
- type = Board_MachiBBS;
- }
-
- /* JBBS : http://jbbs.livedoor.jp/(bbsPath)/ */
- else if( url.host().contains( "jbbs.livedoor.jp" ) ){
-
- delimiter = "/bbs/read.cgi";
- bbsPath = url.prettyURL().remove( hostname );
- type = Board_JBBS;
- ext = ".cgi";
+ if (url.host().contains("machi.to")) type = Board_MachiBBS;
+ else if (url.host().contains("jbbs.livedoor.jp")) type = Board_JBBS;
+ else type = Board_2ch;
}
- /* 2ch : http://(hostname)/(rootPath)/(bbsPath)/ */
- else {
-
- delimiter = "/test/read.cgi";
- bbsPath = url.filename();
- rootPath = url.prettyURL().remove( hostname + "/" ).remove( bbsPath + "/" );
- if( rootPath.length() == 0 ) rootPath = QString::null;
- ext = ".dat";
- type = Board_2ch;
+ /* parse */
+ switch (type) {
+
+ case Board_MachiBBS: /* MACHI : http:// *.machi.to/(bbsPath)/ */
+
+ delimiter = "/bbs/read.pl";
+ bbsPath = url.fileName();
+ ext = ".cgi";
+ break;
+
+ case Board_JBBS: /* JBBS : http://jbbs.livedoor.jp/(bbsPath)/ */
+
+ delimiter = "/bbs/read.cgi";
+ bbsPath = url.prettyUrl().remove(hostname);
+ type = Board_JBBS;
+ ext = ".cgi";
+ break;
+
+ 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.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.clear();
+ ext = ".dat";
+ type = Board_2ch;
+ break;
}
-/*
- qDebug( "host : %s", hostname.ascii() );
- qDebug( "root : %s", rootPath.ascii() );
- qDebug( "deli : %s", delimiter.ascii() );
- qDebug( "bbs : %s", bbsPath.ascii() );
-*/
- if( bbsPath == QString::null ) return;
-
- BoardData* bdata = new BoardData( boardName, hostname, rootPath, delimiter, bbsPath, ext, type );
- m_boardDataList.append( bdata );
+
+ /* For example, if bbsPath = "linux/", then m_bbsPath = "/linux" */
+ 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 )
-{
- QString urlstr = url.prettyURL();
-
- if( m_previousBoardData != NULL ){
- int count = m_previousBoardData->keyBasePathList().count();
- for( int i = 0; i < count ; ++i ){
- if( urlstr.contains( m_previousBoardData->keyBasePathList()[i] )
- || urlstr.contains( m_previousBoardData->keyCgiBasePathList()[i] ) ){
-
- return m_previousBoardData;
- }
- }
- }
-
- 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] ) ){
-
- m_previousBoardData = (*it);
- return (*it);
- }
- }
+BoardData* BoardManager::getBoardData(const KUrl& url)
+{
+ if (url.isEmpty()) return 0;
+ QString urlstr = url.prettyUrl();
+
+ /* cache */
+ if (m_previousBoardData != 0 && m_previousBoardUrl == urlstr) return m_previousBoardData;
+
+ 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 ])) {
+
+ /* cache */
+ m_previousBoardData = (*it);
+ m_previousBoardUrl = urlstr;
+
+ return (*it);
+ }
+ }
}
-
- return NULL;
+
+ return 0;
}
/* BBSHISTORY */
-/* load the bbs history file ( BBSHISTORY ), and create keys of Data Base. */
-/* Before calling this, enroll the board by enrollBoard(). */
+/* 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
+ then, BBSHISTORY is
+
http://ccc.com
http://bbb.com
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();
-
- QFile file( Cache::getBBSHistoryPath( url ) );
- if ( file.open( IO_ReadOnly ) ){
+ QStringList keyHosts(bdata->hostName());
- qDebug( "read BBSHISTRY : %s",Cache::getBBSHistoryPath( url ).ascii() );
+ Cache cache(url);
+ QFile file(cache.getBBSHistoryPath());
+ if (file.open(QIODevice::ReadOnly)) {
- QTextStream ts( &file );
+ QTextStream ts(&file);
- QString line;
- while( !ts.eof() ){
+ QString line;
+ while (!ts.atEnd()) {
- line = ts.readLine();
- qDebug("line: %s",line.ascii());
- keyHosts += line;
- }
+ line = ts.readLine();
+ keyHosts += line;
+ }
- bdata->createKeys( keyHosts );
- file.close();
+ bdata->createKeys(keyHosts);
+ file.close();
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
/* public */ /* static */
-bool BoardManager::moveBoard( const KURL& fromURL, const KURL& toURL )
-{
- 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 += "/";
-
- qDebug( "moveBoard : %s -> %s", oldURL.ascii(), newURL.ascii() );
-
- if( oldURL == newURL ) return FALSE;
-
+bool BoardManager::moveBoard(const KUrl& fromUrl, const KUrl& toUrl)
+{
+ 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 += '/';
+
+ 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;
+ /* Is newURL enrolled? */
+ bdata = getBoardData(newUrl);
+ if (bdata == 0) return false;
}
/*---------------------------*/
- /* updata BoardData */
-
+ /* 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:
*/
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);
+
-
/*---------------------------*/
/* move cache dir */
-
+
QDir qdir;
- QString newCachePath = Cache::baseDir() + Cache::serverDir( bdata->basePath() );
+ if (! qdir.exists(oldCachePath)) return true;
- /* mkdir server dir */
- if( !qdir.exists( newCachePath ) ){
- qDebug( "mkdir %s", newCachePath.ascii() );
- qdir.mkdir( newCachePath );
- }
-
- newCachePath += Cache::boardDir( bdata->basePath() );
+ /* mkdir new server dir */
+ Cache newCache(bdata->basePath());
+ QString newCachePath = Cache::baseDir() + newCache.serverDir();
+ QDir::root().mkpath(newCachePath);
/* backup old dir */
- if( qdir.exists ( newCachePath ) ){
- QString bkupPath = newCachePath;
- bkupPath.truncate( bkupPath.length() -1 ); /* remove '/' */
- bkupPath += "." + QString().setNum( QDateTime::currentDateTime().toTime_t() );
- qDebug( "mv %s\n -> %s", newCachePath.ascii(), bkupPath.ascii() );
- qdir.rename( newCachePath, bkupPath );
+ newCachePath += newCache.boardDir();
+ if (qdir.exists (newCachePath)) {
+ QString bkupPath = newCachePath;
+ bkupPath.truncate(bkupPath.length() - 1); /* remove '/' */
+ bkupPath +=
+ '.' + QString::number(QDateTime::currentDateTime().toTime_t());
+ qdir.rename(newCachePath, bkupPath);
}
/* move cache dir */
- qDebug( "old: %s", oldCachePath.ascii() );
- if( qdir.exists( oldCachePath ) ){
- qDebug( "move: %s\n-> %s", oldCachePath.ascii(), newCachePath.ascii() );
- qdir.rename( oldCachePath, newCachePath );
+ if (qdir.exists(oldCachePath)) {
+ qdir.rename(oldCachePath, newCachePath);
+ } else
+ QDir::root().mkpath(newCachePath);
+
+ /* make old dir */
+ if (! qdir.exists(oldCachePath)) {
+ QDir::root().mkpath(oldCachePath);
+ /* create BBS_MOVED */
+ QString movedPath = oldCachePath + "/BBS_MOVED";
+ QFile file(movedPath);
+ if (file.open(QIODevice::WriteOnly)) {
+ QTextStream stream(&file);
+ stream << newUrl << endl;
+ }
+ file.close();
}
- else qdir.mkdir( newCachePath );
-
/*---------------------------*/
/* update BBSHISTRY */
-
- QFile file( Cache::getBBSHistoryPath( bdata->basePath() ) );
- if ( file.open( IO_WriteOnly ) ){
-
- qDebug( "write BBSHISTRY : %s", Cache::getBBSHistoryPath( bdata->basePath() ).ascii() );
- QTextStream ts( &file );
-
- keyHosts.remove( newhost );
- for ( QStringList::iterator it = keyHosts.begin() ; it != keyHosts.end(); ++it ) {
- ts << (*it) << endl;
- }
-
- file.close();
- }
-
- /*---------------------------*/
- /* update other information */
- FavoriteThreads::replace( oldURL, newURL );
- Kita::Thread::replace( oldURL, newURL );
- KitaThreadInfo::replace( oldURL, newURL );
- Kita::FavoriteBoards::replace( oldURL, newURL );
-
- qDebug("%s",bdata->basePath().ascii() );
- qDebug("%s",bdata->cgiBasePath().ascii() );
- int count = bdata->keyBasePathList().count();
- for( int i = 0; i < count ; ++i ){
- qDebug("key: %s",bdata->keyBasePathList()[i].ascii() );
- qDebug("key: %s",bdata->keyCgiBasePathList()[i].ascii() );
- }
-
- return TRUE;
-}
-
-
-/*--------------------------------*/
-/* SETTING.TXT */
+ Cache historyCache(bdata->basePath());
+ QFile file(historyCache.getBBSHistoryPath());
+ if (file.open(QIODevice::WriteOnly)) {
+ QTextStream ts(&file);
-/* 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 );
-
- qDebug("LOAD SETTING.TXT : %s",settingURL.prettyURL().ascii());
- qDebug("path: %s",path.ascii());
-
- /* download SETTING.TXT.*/
- DownloadManager::download( settingURL, path );
- bdata->setSettingLoaded( TRUE );
-
- return TRUE;
-}
+ keyHosts.removeOne(newhost);
+ for (QStringList::iterator it = keyHosts.begin() ; it != keyHosts.end(); ++it) {
+ ts << (*it) << endl;
+ }
-
-/* public */ /* static */
-QString BoardManager::getBBSDefaultName( const KURL& url )
-{
- BoardData* bdata = openSettingTxt( url );
- if( bdata == NULL ) return QString::null;
- return bdata->defaultName();
-}
-
-
-/* public */ /* static */
-int BoardManager::getBBSMaxLine( const KURL& url )
-{
- BoardData* bdata = openSettingTxt( url );
- if( bdata == NULL ) return 0;
- return bdata->lineNum();
-}
-
-
-/* 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;
-
- qDebug( "read SETTING.TXT");
-
- 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();
-// qDebug("line: %s\n",(const char *)line.local8Bit());
-
- /* 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 );
- }
-
- file.close();
+ file.close();
}
- if( bdata->defaultName() == QString::null ) bdata->setDefaultName( "(default name)" );
- qDebug( "name: %s", (const char *)bdata->defaultName().local8Bit());
- qDebug( "line num: %d", bdata->lineNum() );
-
- return bdata;
+ /*---------------------------*/
+ /* update other information */
+ FavoriteThreads::replace(oldUrl, newUrl);
+ Thread::replace(oldUrl, newUrl);
+ ThreadInfo::replace(oldUrl, newUrl);
+ FavoriteBoards::replace(oldUrl, newUrl);
+
+ return true;
}