/***************************************************************************
- * Copyright (C) 2003 by Hideki Ikemoto *
- * 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. *
- ***************************************************************************/
+* Copyright (C) 2003 by Hideki Ikemoto *
+* 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 "favoritethreads.h"
FavoriteThreads* FavoriteThreads::instance = 0;
FavoriteThreads::FavoriteThreads()
-{
-}
+{}
FavoriteThreads::~FavoriteThreads()
-{
-}
+{}
FavoriteThreads* FavoriteThreads::getInstance()
{
- if( ! instance ) {
- instance = new FavoriteThreads();
- }
- return instance;
+ if ( ! instance ) {
+ instance = new FavoriteThreads();
+ }
+ return instance;
}
void FavoriteThreads::insert( const Kita::Thread* thread )
{
- if( ! m_threadDict.find( thread->datURL() ) ) {
- m_threadDict.insert( thread->datURL(), thread );
- }
+ if ( ! m_threadDict.find( thread->datURL() ) ) {
+ m_threadDict.insert( thread->datURL(), thread );
+ }
}
void FavoriteThreads::remove( const QString& datURL )
{
- m_threadDict.remove( datURL );
+ m_threadDict.remove( datURL );
}
bool FavoriteThreads::contains( const QString& datURL ) const
{
- if( m_threadDict.find( datURL ) ) {
- return true;
- } else {
- return false;
- }
+ if ( m_threadDict.find( datURL ) ) {
+ return true;
+ } else {
+ return false;
+ }
}
FavoriteThreads* FavoriteThreads::fromXml( const QString& xml )
{
- FavoriteThreads* instance = FavoriteThreads::getInstance();
-
- FavoritesXmlParser parser;
- QXmlSimpleReader reader;
- QXmlInputSource source;
- source.setData( xml );
- reader.setContentHandler( &parser );
- reader.parse( &source );
-
- if( parser.isValid() ) {
- QPtrList<Kita::Thread> threads = parser.getThreads();
-
- instance->m_threadDict.clear();
- for( Kita::Thread* thread = threads.first(); thread; thread = threads.next() ) {
- instance->insert( thread );
+ FavoriteThreads * instance = FavoriteThreads::getInstance();
+
+ FavoritesXmlParser parser;
+ QXmlSimpleReader reader;
+ QXmlInputSource source;
+ source.setData( xml );
+ reader.setContentHandler( &parser );
+ reader.parse( &source );
+
+ if ( parser.isValid() ) {
+ QPtrList<Kita::Thread> threads = parser.getThreads();
+
+ instance->m_threadDict.clear();
+ for ( Kita::Thread * thread = threads.first(); thread; thread = threads.next() ) {
+ instance->insert( thread );
+ }
+ } else {
+ kdError() << "inValid" << endl;
}
- } else {
- kdError() << "inValid" << endl;
- }
- return instance;
+ return instance;
}
const QString FavoriteThreads::toXml() const
{
- QString ret;
+ QString ret;
- ret += "<favorites xmlns=\"http://kita.sourceforge.jp/ns/favorites\">\n";
+ ret += "<favorites xmlns=\"http://kita.sourceforge.jp/ns/favorites\">\n";
-// FavoriteThreads::const_iterator it;
- QDictIterator<Kita::Thread> it( threads() );
- for( ; it.current(); ++it ) {
- ret += it.current()->toXmlFragment();
- }
- ret += "</favorites>\n";
+ // FavoriteThreads::const_iterator it;
+ QDictIterator<Kita::Thread> it( threads() );
+ for ( ; it.current(); ++it ) {
+ ret += it.current() ->toXmlFragment();
+ }
+ ret += "</favorites>\n";
- return ret;
+ return ret;
}
bool FavoriteThreads::test()
{
- kdDebug() << "FavoriteThreads::test()" << endl;
-
- QString xml = "<favorites xmlns=\"http://kita.sourceforge.jp/ns/favorites\">\n"
- "<thread xmlns=\"http://kita.sourceforge.jp/ns/thread\">\n"
- "<daturl>http://pc.2ch.net/linux/dat/1022744633.dat</daturl>\n"
- "<name>2ch browser thread</name>\n"
- "<board xmlns=\"http://kita.sourceforge.jp/ns/board\">\n"
- "<url>http://pc.2ch.net/linux/</url>\n"
- "<name>Linux</name>\n"
- "</board>\n"
- "</thread>\n"
- "<thread xmlns=\"http://kita.sourceforge.jp/ns/thread\">\n"
- "<daturl>http://pc.2ch.net/unix/dat/956134538.dat</daturl>\n"
- "<name>NeXT</name>\n"
- "<board xmlns=\"http://kita.sourceforge.jp/ns/board\">\n"
- "<url>http://pc.2ch.net/unix/</url>\n"
- "<name>Unix</name>\n"
- "</board>\n"
- "</thread>\n"
- "</favorites>\n";
-
- FavoriteThreads* favorites = FavoriteThreads::fromXml( xml );
- QDict<Kita::Thread> threads = favorites->threads();
-
- if( threads.size() != 2 ) kdError() << "inValid: line=" << __LINE__ << endl;
- if( favorites->contains( "http://pc.2ch.net/linux/dat/1022744633.dat" ) != true ) {
- kdError() << "inValid: line=" << __LINE__;
- }
- if( favorites->contains( "http://pc.2ch.net/unix/dat/956134538.dat" ) != true ) {
- kdError() << "inValid: line=" << __LINE__;
- }
- return true;
+ kdDebug() << "FavoriteThreads::test()" << endl;
+
+ QString xml = "<favorites xmlns=\"http://kita.sourceforge.jp/ns/favorites\">\n"
+ "<thread xmlns=\"http://kita.sourceforge.jp/ns/thread\">\n"
+ "<daturl>http://pc.2ch.net/linux/dat/1022744633.dat</daturl>\n"
+ "<name>2ch browser thread</name>\n"
+ "<board xmlns=\"http://kita.sourceforge.jp/ns/board\">\n"
+ "<url>http://pc.2ch.net/linux/</url>\n"
+ "<name>Linux</name>\n"
+ "</board>\n"
+ "</thread>\n"
+ "<thread xmlns=\"http://kita.sourceforge.jp/ns/thread\">\n"
+ "<daturl>http://pc.2ch.net/unix/dat/956134538.dat</daturl>\n"
+ "<name>NeXT</name>\n"
+ "<board xmlns=\"http://kita.sourceforge.jp/ns/board\">\n"
+ "<url>http://pc.2ch.net/unix/</url>\n"
+ "<name>Unix</name>\n"
+ "</board>\n"
+ "</thread>\n"
+ "</favorites>\n";
+
+ FavoriteThreads* favorites = FavoriteThreads::fromXml( xml );
+ QDict<Kita::Thread> threads = favorites->threads();
+
+ if ( threads.size() != 2 ) kdError() << "inValid: line=" << __LINE__ << endl;
+ if ( favorites->contains( "http://pc.2ch.net/linux/dat/1022744633.dat" ) != true ) {
+ kdError() << "inValid: line=" << __LINE__;
+ }
+ if ( favorites->contains( "http://pc.2ch.net/unix/dat/956134538.dat" ) != true ) {
+ kdError() << "inValid: line=" << __LINE__;
+ }
+ return true;
}
bool FavoritesXmlParser::startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts )
{
- if( m_inThread ) {
- m_threadParser->startElement( namespaceURI, localName, qName, atts );
- } else if( m_inFavorites ) {
- if( localName == "thread" ) {
- m_inThread = true;
- m_threadParser = new Kita::ThreadXmlParser();
- m_threadParser->startElement( namespaceURI, localName, qName, atts );
+ if ( m_inThread ) {
+ m_threadParser->startElement( namespaceURI, localName, qName, atts );
+ } else if ( m_inFavorites ) {
+ if ( localName == "thread" ) {
+ m_inThread = true;
+ m_threadParser = new Kita::ThreadXmlParser();
+ m_threadParser->startElement( namespaceURI, localName, qName, atts );
+ } else {
+ // error
+ return false;
+ }
} else {
- // error
- return false;
+ if ( localName == "favorites" ) {
+ m_inFavorites = true;
+ } else {
+ // error
+ return false;
+ }
}
- } else {
- if( localName == "favorites" ) {
- m_inFavorites = true;
- } else {
- // error
- return false;
- }
- }
- return true;
+ return true;
}
bool FavoritesXmlParser::endElement( const QString& namespaceURI, const QString& localName, const QString& qName )
{
- if( localName == "thread" ) {
- m_inThread = false;
- m_threadParser->endElement( namespaceURI, localName, qName );
- Kita::Thread thread = m_threadParser->getThread();
- Kita::Thread::setName( thread.datURL(), thread.name() );
- m_threadList.append( Kita::Thread::getByURL( thread.datURL() ) );
- KitaThreadInfo::setResNum( thread.datURL(), thread.resNum() );
-
- delete m_threadParser;
- m_threadParser = 0;
- } else if( m_inThread ) {
- m_threadParser->endElement( namespaceURI, localName, qName );
- } else if( localName == "favorites" ) {
- m_inFavorites = false;
- m_isValid = true;
- } else {
- // error
- return false;
- }
- return true;
+ if ( localName == "thread" ) {
+ m_inThread = false;
+ m_threadParser->endElement( namespaceURI, localName, qName );
+ Kita::Thread* thread = m_threadParser->getThread();
+ Kita::Thread::setName( thread->datURL(), thread->name() );
+ m_threadList.append( Kita::Thread::getByURL( thread->datURL() ) );
+ KitaThreadInfo::setResNum( thread->datURL(), thread->resNum() );
+
+ delete m_threadParser;
+ m_threadParser = 0;
+ } else if ( m_inThread ) {
+ m_threadParser->endElement( namespaceURI, localName, qName );
+ } else if ( localName == "favorites" ) {
+ m_inFavorites = false;
+ m_isValid = true;
+ } else {
+ // error
+ return false;
+ }
+ return true;
}
bool FavoritesXmlParser::characters( const QString& ch )
{
- if( m_inThread ) {
- m_threadParser->characters( ch );
- } else {
- m_characters = ch;
- }
- return true;
+ if ( m_inThread ) {
+ m_threadParser->characters( ch );
+ } else {
+ m_characters = ch;
+ }
+ return true;
}
"</board>\n"
"</thread>\n" );
- m_fromxml2 = Thread::fromXml( m_fromxml.toXmlFragment() );
+ m_fromxml2 = Thread::fromXml( m_fromxml->toXmlFragment() );
m_fromxml3 = Thread::fromXml( "<thread xmlns=\"http://kita.sourceforge.jp/ns/thread\">\n"
" <daturl>http://pc.2ch.net/linux/dat/1022744633.dat</daturl>\n"
CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/dat/1069738960.dat"),
m_normal->datURL() );
CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/dat/1022744633.dat"),
- m_fromxml.datURL() );
+ m_fromxml->datURL() );
CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/dat/1022744633.dat"),
- m_fromxml2.datURL() );
+ m_fromxml2->datURL() );
CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/dat/1022744633.dat"),
- m_fromxml3.datURL() );
+ m_fromxml3->datURL() );
}
void ThreadTest::testURL()
CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/test/read.cgi/linux/1069738960/"),
m_normal->url() );
CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/test/read.cgi/linux/1022744633/"),
- m_fromxml.url() );
+ m_fromxml->url() );
CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/test/read.cgi/linux/1022744633/"),
- m_fromxml2.url() );
+ m_fromxml2->url() );
CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/test/read.cgi/linux/1022744633/"),
- m_fromxml3.url() );
+ m_fromxml3->url() );
}
void ThreadTest::testDatID()
{
CPPUNIT_ASSERT_EQUAL( QString( "1069738960" ), m_normal->datID() );
- CPPUNIT_ASSERT_EQUAL( QString( "1022744633" ), m_fromxml.datID() );
- CPPUNIT_ASSERT_EQUAL( QString( "1022744633" ), m_fromxml2.datID() );
- CPPUNIT_ASSERT_EQUAL( QString( "1022744633" ), m_fromxml3.datID() );
+ CPPUNIT_ASSERT_EQUAL( QString( "1022744633" ), m_fromxml->datID() );
+ CPPUNIT_ASSERT_EQUAL( QString( "1022744633" ), m_fromxml2->datID() );
+ CPPUNIT_ASSERT_EQUAL( QString( "1022744633" ), m_fromxml3->datID() );
}
void ThreadTest::testResNum()
{
CPPUNIT_ASSERT_EQUAL( 0, m_normal->resNum() );
- CPPUNIT_ASSERT_EQUAL( 700, m_fromxml.resNum() );
- CPPUNIT_ASSERT_EQUAL( 700, m_fromxml2.resNum() );
- CPPUNIT_ASSERT_EQUAL( 700, m_fromxml3.resNum() );
+ CPPUNIT_ASSERT_EQUAL( 700, m_fromxml->resNum() );
+ CPPUNIT_ASSERT_EQUAL( 700, m_fromxml2->resNum() );
+ CPPUNIT_ASSERT_EQUAL( 700, m_fromxml3->resNum() );
}
void ThreadTest::testName()
CPPUNIT_ASSERT_EQUAL( QString( "Kita - 2ch client for KDE" ),
m_normal->name() );
CPPUNIT_ASSERT_EQUAL( QString( "2ch browser thread" ),
- m_fromxml.name() );
+ m_fromxml->name() );
CPPUNIT_ASSERT_EQUAL( QString( "2ch browser thread" ),
- m_fromxml2.name() );
+ m_fromxml2->name() );
CPPUNIT_ASSERT_EQUAL( QString( "2ch browser thread" ),
- m_fromxml3.name() );
+ m_fromxml3->name() );
}
void ThreadTest::testBoardName()
{
CPPUNIT_ASSERT_EQUAL( QString( "Linux" ), m_normal->boardName() );
- CPPUNIT_ASSERT_EQUAL( QString( "Linux" ), m_fromxml.boardName() );
- CPPUNIT_ASSERT_EQUAL( QString( "Linux" ), m_fromxml2.boardName() );
- CPPUNIT_ASSERT_EQUAL( QString( "Linux" ), m_fromxml3.boardName() );
+ CPPUNIT_ASSERT_EQUAL( QString( "Linux" ), m_fromxml->boardName() );
+ CPPUNIT_ASSERT_EQUAL( QString( "Linux" ), m_fromxml2->boardName() );
+ CPPUNIT_ASSERT_EQUAL( QString( "Linux" ), m_fromxml3->boardName() );
}
void ThreadTest::testBoardURL()
{
CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/" ), m_normal->boardURL() );
- CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/" ), m_fromxml.boardURL() );
- CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/" ), m_fromxml2.boardURL() );
- CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/" ), m_fromxml3.boardURL() );
+ CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/" ), m_fromxml->boardURL() );
+ CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/" ), m_fromxml2->boardURL() );
+ CPPUNIT_ASSERT_EQUAL( QString( "http://pc.2ch.net/linux/" ), m_fromxml3->boardURL() );
}
void ThreadTest::testBoardID()
{
CPPUNIT_ASSERT_EQUAL( QString( "linux" ), m_normal->boardID() );
- CPPUNIT_ASSERT_EQUAL( QString( "linux" ), m_fromxml.boardID() );
- CPPUNIT_ASSERT_EQUAL( QString( "linux" ), m_fromxml2.boardID() );
- CPPUNIT_ASSERT_EQUAL( QString( "linux" ), m_fromxml3.boardID() );
+ CPPUNIT_ASSERT_EQUAL( QString( "linux" ), m_fromxml->boardID() );
+ CPPUNIT_ASSERT_EQUAL( QString( "linux" ), m_fromxml2->boardID() );
+ CPPUNIT_ASSERT_EQUAL( QString( "linux" ), m_fromxml3->boardID() );
}
+