1 /***************************************************************************
2 * Copyright (C) 2003 by Hideki Ikemoto *
3 * ikemo@users.sourceforge.jp *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
15 #include <kio/slaveconfig.h>
16 #include <kio/netaccess.h>
19 #include <kfilterdev.h>
24 #include "kita_misc.h"
25 #include "threadinfo.h"
27 #include "qcp932codec.h"
31 QDict<Board>* Board::m_boardDict = 0;
37 Board::Board(const QString& boardURL, const QString boardName) : m_boardURL(boardURL), m_boardName(boardName)
45 const KURL Board::subjectTxtURL() const
47 if( m_boardURL.isEmpty() ) {
50 return KURL(m_boardURL, "./subject.txt");
54 const QString& Board::url() const
59 const QString& Board::name() const
64 const QString Board::id() const
66 return KURL( m_boardURL ).fileName();
69 const QPtrList<Thread> Board::getThreadList() const
71 if( m_boardURL.isEmpty() ) {
72 kdWarning() << "Waring: board url is empty!" << endl;
73 return QPtrList<Thread>();
75 QPtrList<Thread> threadList;
77 KIO::SlaveConfig::self()->setConfigData("http",
78 KURL( m_boardURL ).host() ,
80 QString( "Monazilla/1.00 (Kita/%1)" ).arg( VERSION ) );
82 if(KIO::NetAccess::download(subjectTxtURL(), tmpFile)) {
83 QIODevice* tmpDevice = KFilterDev::deviceForFile(tmpFile, "application/x-gzip");
84 tmpDevice->open(IO_ReadOnly);
86 QCp932Codec cp932Codec;
87 QTextStream stream(tmpDevice);
88 stream.setCodec(&cp932Codec);
90 // parse subject.txt(only one format...)
91 QRegExp regexp("(\\d+\\.dat)<>(.*)\\((\\d+)\\)");
94 while((line = stream.readLine()) != QString::null) {
95 int pos = regexp.search(line);
97 QString fname = regexp.cap(1);
98 QString subject = regexp.cap(2);
99 QString num = regexp.cap(3);
101 KURL datURL = m_boardURL;
102 datURL.addPath("/dat/" + fname);
103 Kita::Board::setName( datToBoard( datURL.url() ), name() );
104 Kita::Thread::setName( datURL.url(), subject );
105 Kita::Thread* thread = Kita::Thread::getByURL( datURL.url() );
106 KitaThreadInfo::setResNum( datURL.url(), num.toInt() );
107 threadList.append(thread);
111 KIO::NetAccess::removeTempFile(tmpFile);
116 const QString Board::toXmlFragment() const
120 // FIXME: Thread¥¯¥é¥¹¤Ø¥³¥Ô¡¼
121 ret += "<board xmlns=\"http://kita.sourceforge.jp/ns/board\">\n";
122 ret += QString("<url>%1</url>\n").arg( m_boardURL );
123 ret += QString("<name>%1</name>\n").arg( m_boardName );
129 Board* Board::getByURL( const QString& boardURL )
131 // FIXME: null¥ª¥Ö¥¸¥§¥¯¥È¤òÍ×µá¤Î¤¿¤Ó¤Ëºî¤Ã¤Æ¤¤¤ë¡£
132 if ( boardURL.isNull() ) {
133 return new NullBoard();
136 if ( m_boardDict == 0 ) {
137 // FIXME: setAutoDelete¤ò²Ã¤¨¤ÆÆ°¤¯¤³¤È¤ò³Î¤«¤á¤ë¤³¤È
138 m_boardDict = new QDict<Board>();
141 if( m_boardDict->find( boardURL ) ) {
142 return m_boardDict->find( boardURL );
145 Board* newBoard = new Board( boardURL );
146 m_boardDict->insert( boardURL, newBoard );
151 void Board::setName( const QString& boardURL, const QString& boardName )
153 if ( boardURL.isNull() ) {
157 if ( m_boardDict == 0 ) {
158 // FIXME: setAutoDelete¤ò²Ã¤¨¤ÆÆ°¤¯¤³¤È¤ò³Î¤«¤á¤ë¤³¤È
159 m_boardDict = new QDict<Board>();
162 Board* newBoard = new Board( boardURL, boardName );
163 m_boardDict->replace( boardURL, newBoard );
168 NullBoard::NullBoard()
172 NullBoard::~ NullBoard()
176 bool BoardXmlParser::startElement( const QString&, const QString& localName, const QString&, const QXmlAttributes& )
178 if( m_inBoard == true ) {
179 if( localName == "url" ) {
180 } else if( localName == "name" ) {
186 if( localName == "board" ) {
196 bool BoardXmlParser::endElement( const QString&, const QString& localName, const QString& )
198 if( localName == "board" ) {
200 Kita::Board::setName( m_urlStr, m_nameStr );
201 m_board = Kita::Board::getByURL( m_urlStr );
204 } else if( localName == "url" ) {
205 m_urlStr = m_characters;
206 } else if( localName == "name" ) {
207 m_nameStr = m_characters;
215 bool BoardXmlParser::characters( const QString& ch )