#include "viewmediator.h"
#include "kitaui/listviewitem.h"
-#include "libkita/boardmanager.h"
+#include "libkita/boarddatabase.h"
#include "libkita/favoriteboards.h"
#include "libkita/globalconfig.h"
#include "libkita/kita_misc.h"
QString boardUrl = *it2;
QString boardName = category.boardNameList[ count ];
QString oldUrl;
- int ret = BoardManager::enrollBoard(
- boardUrl, boardName, oldUrl, Board_Unknown,
- true /* test only */);
+ BoardDatabase db(boardUrl);
+ int ret = db.enrollBoard(
+ boardName, oldUrl, Board_Unknown, true /* test only */);
if (ret == Board_enrollNew) {
newBoards += boardName + " ( " + category.category_name
+ " ) " + boardUrl + '\n';
QString newUrl = newUrls[ i ];
// qDebug("move %s -> %s", oldURL.latin1(), newURL.latin1());
- BoardManager::moveBoard(oldUrl, newUrl);
+ BoardDatabase db;
+ db.moveBoard(oldUrl, newUrl);
}
/* save config */
continue;
}
QString oldUrl;
- BoardManager::enrollBoard(boardUrl, boardName, oldUrl);
- BoardManager::loadBBSHistory(boardUrl);
+ BoardDatabase db(boardUrl);
+ db.enrollBoard(boardName, oldUrl);
+ db.loadBBSHistory();
previousBoard = new ListViewItem(categoryItem, previousBoard,
QStringList() << boardName << boardUrl);
}
QString boardName = i18nc("@item:inlistbox", "Kita Board");
QString oldUrl;
new ListViewItem(m_boardList, 0, QStringList() << boardName << boardUrl);
- BoardManager::enrollBoard(boardUrl, boardName, oldUrl);
+ BoardDatabase db(boardUrl);
+ db.enrollBoard(boardName, oldUrl);
loadExtBoard();
refreshFavoriteBoards();
QString oldUrl;
int type = Board_Unknown;
if (list.size() == 3) type = list[ 2 ].toInt();
- BoardManager::enrollBoard(
- board_url, board_title, oldUrl, type);
+ BoardDatabase db(board_url);
+ db.enrollBoard(board_title, oldUrl, type);
}
}
}
for (it = boards.begin(); it != boards.end(); ++it) {
QString boardUrl = (*it).prettyUrl();
- QString boardName = BoardManager::boardName(boardUrl);
+ BoardDatabase db(boardUrl);
+ QString boardName = db.boardName();
new ListViewItem(m_favorites, QStringList() << boardName << boardUrl);
}
if (! item) return ;
QString boardName = item->text(0);
- QString boardUrl = BoardManager::boardUrl(item->text(1));
+ BoardDatabase db(item->text(1));
+ QString boardUrl = db.boardUrl();
if (boardUrl.isEmpty()) {
return ;
QString boardName = item->text(0);
KUrl boardUrl = item->text(1);
- KUrl boardUrl_upToDate = BoardManager::boardUrl(boardUrl);
+ BoardDatabase db(boardUrl);
+ KUrl boardUrl_upToDate = db.boardUrl();
QClipboard* clipboard = QApplication::clipboard();
QAction *action = popup.exec(point);
if (!item) return;
QString boardName = item->text(0);
- QString boardUrl = BoardManager::boardUrl(item->text(1));
+ BoardDatabase db(item->text(1));
+ QString boardUrl = db.boardUrl();
if (boardUrl.isEmpty()) {
item->setExpanded(!item->isExpanded());
return ;
#include "boardview.h"
#include "favoritelistview.h"
#include "viewmediator.h"
-#include "libkita/boardmanager.h"
+#include "libkita/boarddatabase.h"
using namespace Kita;
void BoardTabWidget::loadBoard(const KUrl& boardUrl)
{
BoardView * view = findView(boardUrl);
- QString boardName = BoardManager::boardName(boardUrl);
+ BoardDatabase db(boardUrl);
+ QString boardName = db.boardName();
if (!view) {
view = createView(boardName);
}
} else if (action == m_openBrowserAct) {
KRun::runUrl(subjectView->boardUrl(), "text/html", this);
} else if (action == m_copyTitleAct) {
- QString cliptxt = BoardManager::boardName(subjectView->boardUrl())
+ BoardDatabase db(subjectView->boardUrl());
+ QString cliptxt = db.boardName()
+ '\n' + subjectView->boardUrl().prettyUrl();
clipboard->setText(cliptxt , QClipboard::Clipboard);
clipboard->setText(cliptxt , QClipboard::Selection);
#include "threadlistheaderview.h"
#include "threadlistviewitem.h"
#include "viewmediator.h"
-#include "libkita/boardmanager.h"
+#include "libkita/boarddatabase.h"
#include "libkita/datmanager.h"
#include "libkita/globalconfig.h"
#include "libkita/kita_misc.h"
/* get list of pointers of Thread classes */
QList<Thread*> oldLogList;
QList<Thread*> threadList;
- BoardManager::getThreadList(
- m_boardUrl, m_showOldLogs, online, threadList, oldLogList);
+ BoardDatabase db(m_boardUrl);
+ db.getThreadList(m_showOldLogs, online, threadList, oldLogList);
// reset list
subjectList->clearContents();
#include "threadlistviewitem.h"
#include "viewmediator.h"
-#include "libkita/boardmanager.h"
+#include "libkita/boarddatabase.h"
#include "libkita/datmanager.h"
#include "libkita/favoritethreads.h"
#include "libkita/kita_misc.h"
int viewPos = datManager.getViewPos();
int resNum = datManager.getResNum();
- subjectList->item(i, ColumnBoard)
- ->setText(BoardManager::boardName(datUrl));
+ BoardDatabase db(datUrl);
+ subjectList->item(i, ColumnBoard)->setText(db.boardName());
subjectList->item(i, ColumnSubject)
->setText(datManager.threadName());
subjectList->item(i, ColumnReadNum)
for (int i = 0; FavoriteThreads::count() > i; i++) {
QString datUrl = FavoriteThreads::getDatUrl(i);
- QString boardUrl = BoardManager::boardUrl(datUrl);
+ BoardDatabase db(datUrl);
+ QString boardUrl = db.boardUrl();
if (boardList.contains(boardUrl) == 0) {
boardList.append(boardUrl);
}
bool online = true;
QList<Thread*> threadList;
QList<Thread*> tmpList;
- BoardManager::getThreadList((*it), false, online, threadList, tmpList);
+ BoardDatabase db((*it));
+ db.getThreadList(false, online, threadList, tmpList);
}
}
#include "viewmediator.h"
#include "kitaui/htmlview.h"
#include "libkita/abone.h"
-#include "libkita/boardmanager.h"
+#include "libkita/boarddatabase.h"
#include "libkita/colorconfig.h"
#include "libkita/datmanager.h"
#include "libkita/globalconfig.h"
emit mousePressed(); /* to ThreadView to focus this view. */
KUrl kurl;
- if (!e->url().string().isEmpty())
- kurl = KUrl(BoardManager::boardUrl(m_datUrl), e->url().string());
+ if (!e->url().string().isEmpty()) {
+ BoardDatabase db(m_datUrl);
+ kurl = KUrl(db.boardUrl(), e->url().string());
+ }
m_pushctrl = m_pushmidbt = m_pushrightbt = false;
if (e->qmouseEvent() ->button() & Qt::RightButton) m_pushrightbt = true;
if (datUrl.host() != m_datUrl.host() || datUrl.path() != m_datUrl.path()) {
/* get board name */
- QString boardName = BoardManager::boardName(datUrl);
+ BoardDatabase db(datUrl);
+ QString boardName = db.boardName();
if (!boardName.isEmpty()) innerHTML += '[' + boardName + "] ";
/* If idx file of datURL is not read, thread name cannot be obtained.
access.cpp
account.cpp
bbs.cpp
+ boarddatabase.cpp
boardmanager.cpp
cache.cpp
datinfo.cpp
#include <kio/slaveconfig.h>
#include "account.h"
-#include "boardmanager.h"
+#include "boarddatabase.h"
#include "cache.h"
#include "config.h"
#include "flashcgi.h"
{
m_readNum = 0;
m_lastLine.clear();
- m_bbstype = BoardManager::type(m_datUrl);
+ BoardDatabase db(m_datUrl);
+ m_bbstype = db.type();
m_header = "HTTP/1.1 200 "; /* dummy header */
m_dataSize = 0;
m_threadData.clear();
--- /dev/null
+/***************************************************************************
+* Copyright (C) 2010 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 *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "boarddatabase.h"
+
+#include <QtCore/QDateTime>
+#include <QtCore/QDir>
+#include <QtCore/QTextCodec>
+#include <QtCore/QTextStream>
+
+#include <kfilterdev.h>
+#include <kio/netaccess.h>
+#include <kio/slaveconfig.h>
+
+#include "cache.h"
+#include "config.h"
+#include "favoriteboards.h"
+#include "favoritethreads.h"
+#include "thread.h"
+#include "threadindex.h"
+#include "threadinfo.h"
+
+using namespace Kita;
+
+BoardDataList BoardDatabase::m_boardDataList;
+QTextCodec* BoardDatabase::m_cp932Codec = 0;
+QTextCodec* BoardDatabase::m_eucJpCodec = 0;
+BoardData* BoardDatabase::m_previousBoardData = 0;
+QString BoardDatabase::m_previousBoardUrl;
+
+BoardDatabase::BoardDatabase(const KUrl& url) : m_url(url)
+{
+}
+
+void BoardDatabase::setUrl(const KUrl& url)
+{
+ m_url = url;
+}
+
+/* (hostname)/(rootPath)/(bbsPath)/ */ /* public */
+QString BoardDatabase::boardUrl()
+{
+ BoardData * bdata = getBoardData();
+ return (bdata == 0) ? QString() : bdata->basePath();
+}
+
+/* public */
+QStringList BoardDatabase::allBoardUrlList()
+{
+ QStringList urlList;
+
+ BoardData *data;
+ foreach (data, m_boardDataList)
+ urlList += data->basePath();
+ return urlList;
+}
+
+/* (hostname)/(rootPath) */ /* public */
+QString BoardDatabase::boardRoot()
+{
+ BoardData * bdata = getBoardData();
+ return (bdata == 0) ? QString() : bdata->hostName() + bdata->rootPath();
+}
+
+/* (bbspath) */ /* public */
+QString BoardDatabase::boardPath()
+{
+ BoardData * bdata = getBoardData();
+ return (bdata == 0) ? QString() : bdata->bbsPath();
+}
+
+/* (ext) */ /* public */
+QString BoardDatabase::ext()
+{
+ BoardData * bdata = getBoardData();
+ return (bdata == 0) ? QString() : bdata->ext();
+}
+
+/* ID of board for writing */ /* public */
+QString BoardDatabase::boardId()
+{
+ BoardData * bdata = getBoardData();
+ return (bdata == 0) ? QString() : bdata->bbsPath().mid(1); /* remove "/" */
+}
+
+/* (hostname)/(rootPath)/(bbsPath)/subject.txt */ /* public */
+QString BoardDatabase::subjectUrl()
+{
+ BoardData * bdata = getBoardData();
+ return (bdata == 0) ? QString() : bdata->basePath() + "subject.txt";
+}
+
+/* public */
+QString BoardDatabase::boardName()
+{
+ BoardData * bdata = getBoardData();
+ return (bdata == 0) ? QString() : bdata->boardName();
+}
+
+/* public */
+int BoardDatabase::type()
+{
+ BoardData * bdata = getBoardData();
+ return (bdata == 0) ? Board_Unknown : bdata->type();
+}
+
+/*---------------------------*/
+/* ThreadList */
+
+
+/* get list of pointers of Thread classes. */
+/*
+ Input:
+
+ 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 */
+void BoardDatabase::getThreadList(
+
+ /* input */
+ bool oldLogs,
+ bool online,
+
+ /* output */
+ QList<Thread*>& threadList,
+ QList<Thread*>& oldLogList)
+{
+ threadList.clear();
+ oldLogList.clear();
+
+ /* get all obtained threads list from cache */
+ if (m_url.prettyUrl() == "http://virtual/obtained/") {
+
+ QStringList bbslist = allBoardUrlList();
+
+ /* search all cache dirs */
+ QString thread;
+ foreach (thread, bbslist) {
+ getCachedThreadList(thread, threadList);
+ }
+
+ return ;
+ }
+
+ /*-------------------------*/
+
+ BoardData* bdata = getBoardData();
+ if (bdata == 0) return ;
+
+ /* download subject.txt */
+ if (online) {
+
+ /* make directory */
+ Cache cache(m_url);
+ QString cacheDir = cache.getDirPath();
+ if (!QDir::root().mkpath(cacheDir)) return;
+
+ KIO::SlaveConfig::self() ->setConfigData("http",
+ m_url.host() ,
+ "UserAgent",
+ QString("Monazilla/1.00 (Kita/%1)").arg(VERSION));
+ QString subjectPath = cache.getSubjectPath();
+ KIO::NetAccess::download(subjectUrl(), subjectPath, 0);
+ }
+
+ /* open and read subject.txt */
+ readSubjectTxt(bdata, threadList);
+
+ /* get old logs */
+ if (oldLogs) {
+
+ QList<Thread*> tmpList;
+ tmpList.clear();
+ getCachedThreadList(m_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 */
+void BoardDatabase::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 = getBoardData(url)->ext();
+ QString boardUrl = getBoardData(url)->basePath();
+ QStringList filter('*' + ext);
+ QStringList flist = d.entryList(filter);
+ QString file;
+ foreach (file, flist) {
+ if (file.isEmpty()) continue;
+
+ QString datUrl = boardUrl + "dat/" + file;
+
+ /* 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 */
+bool BoardDatabase::readSubjectTxt(BoardData* bdata, QList<Thread*>& threadList)
+{
+ /* get all names of cached files to read idx. */
+ QStringList cacheList;
+ if (!bdata->readIdx()) {
+ Cache cache(m_url);
+ QString cacheDir = cache.getDirPath();
+ QDir d(cacheDir);
+ if (d.exists()) {
+ QString ext = getBoardData()->ext();
+ QStringList filter('*' + ext);
+ cacheList = d.entryList(filter);
+ }
+ }
+
+ /* open subject.txt */
+ Cache cache(m_url);
+ QString subjectPath = cache.getSubjectPath();
+ QIODevice * device = KFilterDev::deviceForFile(subjectPath, "application/x-gzip");
+ if (!device->open(QIODevice::ReadOnly))
+ return false;
+
+ QTextStream stream(device);
+
+ if (type() == 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 (type()) {
+
+ 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() + "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 */
+void BoardDatabase::clearBoardData()
+{
+ BoardData *data;
+ foreach (data, m_boardDataList)
+ delete data;
+
+ 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 BoardDatabase::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 */
+int BoardDatabase::enrollBoard(const QString& boardName, QString& oldUrl, int type, bool test)
+{
+ QString hostname;
+ QString rootPath;
+ QString delimiter;
+ QString bbsPath;
+ QString ext;
+ type = parseBoardUrl(type, hostname, rootPath, delimiter, bbsPath, ext);
+ oldUrl.clear();
+
+ if (type == Board_Unknown) return Board_enrollFailed;
+
+ /* check if the board is enrolled or moved. */
+ BoardData *data;
+ foreach (data, m_boardDataList) {
+
+ if (data->boardName() == boardName
+ && data->type() == type
+ && data->bbsPath() == bbsPath) {
+
+ if (data->hostName() == hostname
+ && data->rootPath() == rootPath) { /* enrolled */
+ return Board_enrollEnrolled;
+ } else { /* moved */
+ oldUrl = data->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;
+}
+
+/* parse board URL */
+/* return board type. */ /* private */
+int BoardDatabase::parseBoardUrl(
+
+ /* input */
+ int type, /* If type = Board_Unknown, type will be decided according to url. */
+
+ /* output */
+ QString& hostname,
+ QString& rootPath,
+ QString& delimiter,
+ QString& bbsPath,
+ QString& ext)
+{
+ hostname = m_url.protocol() + "://" + m_url.host();
+ rootPath.clear();
+ delimiter.clear();
+ bbsPath.clear();
+ ext.clear();
+
+ /* decide type */
+ if (type == Board_Unknown) {
+
+ if (m_url.host().contains("machi.to"))
+ type = Board_MachiBBS;
+ else if (m_url.host().contains("jbbs.livedoor.jp"))
+ type = Board_JBBS;
+ else
+ type = Board_2ch;
+ }
+
+ /* parse */
+ switch (type) {
+
+ case Board_MachiBBS: /* MACHI : http:// *.machi.to/(bbsPath)/ */
+
+ delimiter = "/bbs/read.pl";
+ bbsPath = m_url.fileName();
+ ext = ".cgi";
+ break;
+
+ case Board_JBBS: /* JBBS : http://jbbs.livedoor.jp/(bbsPath)/ */
+
+ delimiter = "/bbs/read.cgi";
+ bbsPath = m_url.prettyUrl().remove(hostname);
+ type = Board_JBBS;
+ ext = ".cgi";
+ break;
+
+ case Board_FlashCGI: /* test for Flash CGI/Mini Thread */
+
+ delimiter = "/test/read.cgi";
+ bbsPath = m_url.fileName();
+ rootPath = m_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 = m_url.fileName();
+ rootPath = m_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.isEmpty() && rootPath.at(0) != '/')
+ rootPath = '/' + rootPath;
+ if (!bbsPath.isEmpty() && bbsPath.at(0) != '/')
+ bbsPath = '/' + bbsPath;
+
+ return type;
+}
+
+/* public */
+bool BoardDatabase::isEnrolled()
+{
+ return getBoardData() != 0;
+}
+
+/* public */
+BoardData* BoardDatabase::getBoardData(const KUrl& url)
+{
+ if (url.isEmpty())
+ return 0;
+ QString urlstr = url.prettyUrl();
+
+ /* cache */
+ if (m_previousBoardData != 0 && m_previousBoardUrl == urlstr)
+ return m_previousBoardData;
+
+ BoardData *data;
+ foreach (data, m_boardDataList) {
+
+ int count = data->keyBasePathList().count();
+ for (int i = 0; i < count ; ++i) {
+ if (urlstr.contains(data->keyBasePathList()[i])
+ || urlstr.contains(data->keyCgiBasePathList()[i])) {
+
+ /* cache */
+ m_previousBoardData = data;
+ m_previousBoardUrl = urlstr;
+
+ return data;
+ }
+ }
+ }
+ return 0;
+}
+
+/* public */
+BoardData* BoardDatabase::getBoardData()
+{
+ return getBoardData(m_url);
+}
+
+/*--------------------------------*/
+/* BBSHISTORY */
+
+
+/* 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
+ http://bbb.com
+ http://aaa.com
+
+*/ /* public */
+bool BoardDatabase::loadBBSHistory()
+{
+ BoardData * bdata = getBoardData();
+ if (bdata == 0)
+ return false;
+
+ QStringList keyHosts(bdata->hostName());
+
+ Cache cache(m_url);
+ QFile file(cache.getBBSHistoryPath());
+ if (file.open(QIODevice::ReadOnly)) {
+
+ QTextStream ts(&file);
+
+ QString line;
+ while (!ts.atEnd()) {
+
+ line = ts.readLine();
+ keyHosts += line;
+ }
+
+ bdata->createKeys(keyHosts);
+ file.close();
+
+ return true;
+ }
+
+ return false;
+}
+
+/* public */
+bool BoardDatabase::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 == 0) {
+
+ /* Is newURL enrolled? */
+ bdata = getBoardData(newUrl);
+ if (bdata == 0) return false;
+ }
+
+
+ /*---------------------------*/
+ /* update BoardData */
+
+ /* get the path of old cache */
+ bdata->setHostName(oldhost);
+ QStringList keyHosts = bdata->keyHostList();
+ keyHosts.removeOne(oldhost);
+ keyHosts.prepend(oldhost);
+ bdata->createKeys(keyHosts);
+ Cache cache(bdata->basePath());
+ QString oldCachePath = cache.getDirPath();
+
+ /* update URL */
+ bdata->setHostName(newhost);
+
+ /* update keys */
+ /* The order of keyHosts will be like this:
+
+ newhost
+ oldhost
+ foohost1
+ foohost2
+
+ */
+ keyHosts = bdata->keyHostList();
+ 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;
+ if (! qdir.exists(oldCachePath)) return true;
+
+ /* mkdir new server dir */
+ Cache newCache(bdata->basePath());
+ QString newCachePath = Cache::baseDir() + newCache.serverDir();
+ QDir::root().mkpath(newCachePath);
+
+ /* backup old dir */
+ 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 */
+ 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();
+ }
+
+ /*---------------------------*/
+ /* update BBSHISTRY */
+
+ Cache historyCache(bdata->basePath());
+ QFile file(historyCache.getBBSHistoryPath());
+ if (file.open(QIODevice::WriteOnly)) {
+
+ QTextStream ts(&file);
+
+ keyHosts.removeOne(newhost);
+ QString host;
+ foreach (host, keyHosts) {
+ ts << host << endl;
+ }
+
+ file.close();
+ }
+
+
+ /*---------------------------*/
+ /* update other information */
+ FavoriteThreads::replace(oldUrl, newUrl);
+ Thread::replace(oldUrl, newUrl);
+ ThreadInfo::replace(oldUrl, newUrl);
+ FavoriteBoards::replace(oldUrl, newUrl);
+
+ return true;
+}
--- /dev/null
+/***************************************************************************
+* Copyright (C) 2010 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 *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef KITABOARDDATABASE_H
+#define KITABOARDDATABASE_H
+
+#include "boardmanager.h"
+
+namespace Kita {
+ class Thread;
+
+ class KDE_EXPORT BoardDatabase
+ {
+ static BoardDataList m_boardDataList;
+ static BoardData* m_previousBoardData;
+ static QString m_previousBoardUrl;
+ static QTextCodec* m_cp932Codec;
+ static QTextCodec* m_eucJpCodec;
+ KUrl m_url;
+
+ public:
+ explicit BoardDatabase(const KUrl& url = KUrl());
+
+ void setUrl(const KUrl& url);
+ QString boardUrl();
+ QStringList allBoardUrlList();
+ QString boardRoot();
+ QString boardPath();
+ QString ext();
+ QString boardId();
+ QString subjectUrl();
+ QString boardName();
+ int type();
+
+ /* ThreadList */
+ void getThreadList(bool oldLogs, bool online,
+ QList<Thread*>& threadList, QList<Thread*>& oldLogList);
+
+ /* BoardData */
+ void clearBoardData();
+ int enrollBoard(const QString& boardName, QString& oldUrl,
+ int type = Board_Unknown, bool test = false);
+ bool isEnrolled();
+ BoardData* getBoardData(const KUrl& url);
+ BoardData* getBoardData();
+
+ /* BBSHISTORY */
+ bool loadBBSHistory();
+ bool moveBoard(const KUrl& fromUrl, const KUrl& toUrl);
+
+ private:
+ /* BoardData */
+ int parseBoardUrl(int type, QString& hostname,
+ QString& rootPath, QString& delimiter,
+ QString& bbsPath, QString& ext);
+
+
+ /* ThreadList */
+ void getCachedThreadList(const KUrl& url, QList<Thread*>& threadList);
+ bool readSubjectTxt(BoardData* bdata, QList<Thread*>& threadList);
+
+
+ /* SETTING.TXT */
+ BoardData* openSettingTxt();
+ };
+}
+
+#endif
#include "boardmanager.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 "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 */
{
return m_keyCgiBasePathList;
}
-
-
-
-
-/*---------------------------------------------------------------*/
-/*---------------------------------------------------------------*/
-/*---------------------------------------------------------------*/
-
-/* BoardManager */
-
-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()
-{
- clearBoardData();
-}
-
-
-BoardManager::~BoardManager()
-{
- clearBoardData();
-}
-
-/* (hostname)/(rootPath)/(bbsPath)/ */ /* public */ /* static */
-const QString BoardManager::boardUrl(const KUrl& url)
-{
- BoardData * bdata = getBoardData(url);
- if (bdata == 0) return QString();
-
- return bdata->basePath();
-}
-
-/* public */ /* static */
-const QStringList BoardManager::allBoardUrlList()
-{
- QStringList urlList;
- urlList.clear();
-
- 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)
-{
- BoardData * bdata = getBoardData(url);
- if (bdata == 0) return QString();
-
- return bdata->hostName() + bdata->rootPath();
-}
-
-/* (bbspath) */ /* public */ /* static */
-const QString BoardManager::boardPath(const KUrl& url)
-{
- 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)
-{
- BoardData * bdata = getBoardData(url);
- if (bdata == 0) return QString();
-
- return bdata->bbsPath().mid(1); /* remove "/" */
-}
-
-
-/* (hostname)/(rootPath)/(bbsPath)/subject.txt */ /* public */ /* static */
-const QString BoardManager::subjectUrl(const KUrl& url)
-{
- BoardData * bdata = getBoardData(url);
- if (bdata == 0) return QString();
-
- return bdata->basePath() + "subject.txt";
-}
-
-
-/* public */ /* static */
-const QString BoardManager::boardName(const KUrl& url)
-{
- BoardData * bdata = getBoardData(url);
- if (bdata == 0) return QString();
-
- return bdata->boardName();
-}
-
-
-/* public */ /* static */
-int BoardManager::type(const KUrl& url)
-{
- 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()
-{
- 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;
-}
-
-
-/* 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)
-{
- hostname = url.protocol() + "://" + url.host();
- rootPath.clear();
- delimiter.clear();
- bbsPath.clear();
- ext.clear();
-
- /* decide type */
- if (type == Board_Unknown) {
-
- 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) {
-
- 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;
- }
-
- /* 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)
-{
- if (getBoardData(url) == 0) return false;
- return true;
-}
-
-
-/* public */ /* static */
-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 0;
-}
-
-
-
-/*--------------------------------*/
-/* BBSHISTORY */
-
-
-/* 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
- http://bbb.com
- http://aaa.com
-
-*/ /* public */ /* static */
-bool BoardManager::loadBBSHistory(const KUrl& url)
-{
- BoardData * bdata = getBoardData(url);
- if (bdata == 0) return false;
-
- QStringList keyHosts(bdata->hostName());
-
- Cache cache(url);
- QFile file(cache.getBBSHistoryPath());
- if (file.open(QIODevice::ReadOnly)) {
-
- QTextStream ts(&file);
-
- QString line;
- while (!ts.atEnd()) {
-
- line = ts.readLine();
- keyHosts += line;
- }
-
- bdata->createKeys(keyHosts);
- file.close();
-
- return true;
- }
-
- 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 += '/';
-
- if (oldUrl == newUrl) return false;
-
- /* Is oldURL enrolled? */
- BoardData* bdata = getBoardData(oldUrl);
- if (bdata == 0) {
-
- /* Is newURL enrolled? */
- bdata = getBoardData(newUrl);
- if (bdata == 0) return false;
- }
-
-
- /*---------------------------*/
- /* update BoardData */
-
- /* get the path of old cache */
- bdata->setHostName(oldhost);
- QStringList keyHosts = bdata->keyHostList();
- keyHosts.removeOne(oldhost);
- keyHosts.prepend(oldhost);
- bdata->createKeys(keyHosts);
- Cache cache(bdata->basePath());
- QString oldCachePath = cache.getDirPath();
-
- /* update URL */
- bdata->setHostName(newhost);
-
- /* update keys */
- /* The order of keyHosts will be like this:
-
- newhost
- oldhost
- foohost1
- foohost2
-
- */
- keyHosts = bdata->keyHostList();
- 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;
- if (! qdir.exists(oldCachePath)) return true;
-
- /* mkdir new server dir */
- Cache newCache(bdata->basePath());
- QString newCachePath = Cache::baseDir() + newCache.serverDir();
- QDir::root().mkpath(newCachePath);
-
- /* backup old dir */
- 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 */
- 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();
- }
-
- /*---------------------------*/
- /* update BBSHISTRY */
-
- Cache historyCache(bdata->basePath());
- QFile file(historyCache.getBBSHistoryPath());
- if (file.open(QIODevice::WriteOnly)) {
-
- QTextStream ts(&file);
-
- keyHosts.removeOne(newhost);
- for (QStringList::iterator it = keyHosts.begin() ; it != keyHosts.end(); ++it) {
- ts << (*it) << endl;
- }
-
- file.close();
- }
-
-
- /*---------------------------*/
- /* update other information */
- FavoriteThreads::replace(oldUrl, newUrl);
- Thread::replace(oldUrl, newUrl);
- ThreadInfo::replace(oldUrl, newUrl);
- FavoriteBoards::replace(oldUrl, newUrl);
-
- return true;
-}
#include <kurl.h>
-class QSjisCodec;
-class QEucJpCodec;
-
namespace Kita
{
- class Thread;
-
/* type of board */
enum {
Board_MachiBBS,
/*--------------------------------------*/
typedef QList<BoardData*> BoardDataList;
-
- /**
- @author Hideki Ikemoto
- */
- class KDE_EXPORT BoardManager
- {
- static BoardDataList m_boardDataList;
- static BoardData* m_previousBoardData; /* used in getBoardData() */
- static QString m_previousBoardUrl; /* used in getBoardData() */
- static QTextCodec* m_cp932Codec;
- static QTextCodec* m_eucJpCodec;
-
- public:
- BoardManager();
- ~BoardManager();
-
- static const QString boardUrl(const KUrl& url);
- static const QStringList allBoardUrlList();
- static const QString boardRoot(const KUrl& url);
- static const QString boardPath(const KUrl& url);
- static const QString ext(const KUrl& url);
- static const QString boardId(const KUrl& url);
- static const QString subjectUrl(const KUrl& url);
- static const QString boardName(const KUrl& url);
- static int type(const KUrl& url);
-
- /* ThreadList */
- static void getThreadList(const KUrl& url, bool oldLogs, bool online,
- QList<Thread*>& threadList, QList<Thread*>& oldLogList);
-
- /* BoardData */
- static void clearBoardData();
- static int enrollBoard(const KUrl& url, const QString& boardName, QString& oldUrl,
- int type = Board_Unknown, bool test = false);
- static bool isEnrolled(const KUrl& url);
- static BoardData* getBoardData(const KUrl& url);
-
- /* BBSHISTORY */
- static bool loadBBSHistory(const KUrl& url);
- static bool moveBoard(const KUrl& fromUrl, const KUrl& toUrl);
-
- private:
-
- /* BoardData */
- static int parseBoardUrl(const KUrl& url, int type, QString& hostname,
- QString& rootPath, QString& delimiter,
- QString& bbsPath, QString& ext);
-
-
- /* ThreadList */
- static void getCachedThreadList(const KUrl& url, QList<Thread*>& threadList);
- static bool readSubjectTxt(BoardData* bdata, const KUrl& url, QList<Thread*>& threadList);
-
-
- /* SETTING.TXT */
- static BoardData* openSettingTxt(const KUrl& url);
- };
}
#endif
#include <kglobal.h>
#include <kstandarddirs.h>
-#include "boardmanager.h"
+#include "boarddatabase.h"
using namespace Kita;
QString Cache::serverDir() const
{
/* Is board enrolled ? */
- BoardData * bdata = BoardManager::getBoardData(m_url);
+ BoardDatabase db(m_url);
+ BoardData * bdata = db.getBoardData();
if (bdata == 0) return QString();
QString root = bdata->hostName() + bdata->rootPath();
QString Cache::boardDir() const
{
/* Is board enrolled ? */
- BoardData * bdata = BoardManager::getBoardData(m_url);
+ BoardDatabase db(m_url);
+ BoardData * bdata = db.getBoardData();
if (bdata == 0) return QString();
QString bbs = bdata->bbsPath();
#include <QtCore/QRegExp>
#include <QtCore/QStringList>
-#include "boardmanager.h"
+#include "boarddatabase.h"
#include "cache.h"
#include "datinfo.h"
#include "kita_misc.h"
/* public */
bool DatManager::is2chThread() const
{
- if (BoardManager::type(m_url) != Board_2ch)
+ BoardDatabase db(m_url);
+ if (db.type() != Board_2ch)
return false;
if (m_datUrl.isEmpty())
return false;
#include <QtXml/QDomDocument>
-#include "boardmanager.h"
+#include "boarddatabase.h"
using namespace Kita;
board.appendChild(urlElement);
urlElement.appendChild(document.createTextNode(boardUrl));
- QString boardName = BoardManager::boardName(boardUrl);
+ BoardDatabase db(boardUrl);
+ QString boardName = db.boardName();
QDomElement nameElement = document.createElement("name");
board.appendChild(nameElement);
nameElement.appendChild(document.createTextNode(boardName));
#include <QtCore/QList>
#include <QtXml/QDomDocument>
-#include "boardmanager.h"
+#include "boarddatabase.h"
#include "datmanager.h"
#include "kita_misc.h"
#include "thread.h"
QDomElement board = document.createElementNS("http://kita.sourceforge.jp/ns/board", "board");
threadElement.appendChild(board);
- QString boardUrl = BoardManager::boardUrl(datUrl);
+ BoardDatabase db(datUrl);
+ QString boardUrl = db.boardUrl();
QDomElement boardUrlElement = document.createElement("url");
board.appendChild(boardUrlElement);
boardUrlElement.appendChild(document.createTextNode(boardUrl));
- QString boardName = BoardManager::boardName(boardUrl);
+ BoardDatabase db2(boardUrl);
+ QString boardName = db2.boardName();
QDomElement boardNameElement = document.createElement("name");
board.appendChild(boardNameElement);
boardNameElement.appendChild(document.createTextNode(boardName));
#include <kurl.h>
-#include "boardmanager.h"
+#include "boarddatabase.h"
#include "datmanager.h"
#include "kita-utf16.h"
QString Kita::getWriteUrl(const KUrl& m_datUrl)
{
- int m_bbstype = BoardManager::type(m_datUrl);
+ BoardDatabase db(m_datUrl);
+ int m_bbstype = db.type();
QString m_bbscgi;
/* set path of bbs.cgi */
switch (m_bbstype) {
case Board_JBBS: {
- QString cgipath = BoardManager::boardRoot(m_datUrl)
- + "/bbs/write.cgi/" + BoardManager::boardId(m_datUrl) + '/';
+ QString cgipath = db.boardRoot()
+ + "/bbs/write.cgi/" + db.boardId() + '/';
cgipath += DatManager(m_datUrl).threadId() + '/';
break;
case Board_MachiBBS: {
- QString cgipath = BoardManager::boardRoot(m_datUrl)
+ QString cgipath = db.boardRoot()
+ "/bbs/write.cgi";
m_bbscgi = cgipath;
}
default:
- m_bbscgi = BoardManager::boardRoot(m_datUrl) + "/test/bbs.cgi";
+ m_bbscgi = db.boardRoot() + "/test/bbs.cgi";
}
return m_bbscgi;
}
/* Is board enrolled ? */
- BoardData* bdata = BoardManager::getBoardData(url);
+ BoardDatabase db(url);
+ BoardData* bdata = db.getBoardData();
if (bdata == 0) return QString();
QString urlstr = url.prettyUrl();
#include "htmlpart.h"
#include "threadtabwidget.h"
#include "viewmediator.h"
-#include "libkita/boardmanager.h"
+#include "libkita/boarddatabase.h"
#include "libkita/datmanager.h"
#include "libkita/favoritethreads.h"
#include "libkita/kita_misc.h"
m_serverTime = datManager.getServerTime();
/* uptate information */
- setSubjectLabel(BoardManager::boardName(m_datUrl),
- datManager.threadName()
- + QString(" (%1)")
- .arg(datManager.getReadNum()),
- BoardManager::boardUrl(m_datUrl));
+ BoardDatabase db(m_datUrl);
+ setSubjectLabel(db.boardName(), datManager.threadName() + QString(" (%1)")
+ .arg(datManager.getReadNum()), db.boardUrl());
updateButton();
gotoCombo->clear();
#include <kmessagebox.h>
#include "writeview.h"
-#include "libkita/boardmanager.h"
+#include "libkita/boarddatabase.h"
#include "libkita/datmanager.h"
#include "libkita/kita_misc.h"
const QString& resStr, const QString& subject)
{
// TODO: machiBBS kakiko support.
- if (BoardManager::type(url) == Board_MachiBBS) {
+ BoardDatabase db(url);
+ if (db.type() == Board_MachiBBS) {
// KMessageBox::sorry(this,
// i18n("Can't write to machi BBS in this version."),
// "<(_ _)>");
#include "libkita/account.h"
#include "libkita/accountconfig.h"
#include "libkita/asciiart.h"
-#include "libkita/boardmanager.h"
+#include "libkita/boarddatabase.h"
#include "libkita/datmanager.h"
#include "libkita/flashcgi.h"
#include "libkita/globalconfig.h"
{
setupUi(this);
m_datUrl = getDatUrl(url);
- m_bbstype = BoardManager::type(m_datUrl);
+ BoardDatabase db(m_datUrl);
+ m_bbstype = db.type();
m_bbscgi = getWriteUrl(m_datUrl);
m_parent = parent;
bodyText->setFont(font);
bodyText->setTabChangesFocus(true);
- boardNameLabel->setText(BoardManager::boardName(m_datUrl));
+ BoardDatabase db(m_datUrl);
+ boardNameLabel->setText(db.boardName());
// setup name field.
nameLine->setText(WriteConfig::defaultName());
const QString WriteView::boardId() const
{
- return BoardManager::boardId(m_datUrl);
+ BoardDatabase db(m_datUrl);
+ return db.boardId();
}
const QString WriteView::boardName() const
{
- return BoardManager::boardName(m_datUrl);
+ BoardDatabase db(m_datUrl);
+ return db.boardName();
}
/* public slot */ /* virtual */
void WriteView::setFocus()
QString postStr = buildPostMessage();
/* referrer */
- QString refStr = BoardManager::boardUrl(m_datUrl);
+ BoardDatabase db(m_datUrl);
+ QString refStr = db.boardUrl();
m_array.clear();