1 /***************************************************************************
2 * Copyright (C) 2004 by Kita Developers *
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 ***************************************************************************/
11 #include "boardmanager.h"
12 #include "qcp932codec.h"
13 #include "downloadmanager.h"
15 #include "favoritethreads.h"
17 #include "threadinfo.h"
18 #include "favoriteboards.h"
19 #include "kita_misc.h"
20 #include "threadindex.h"
22 #include <config.h> /* VERSION */
25 #include <kio/netaccess.h>
26 #include <kfilterdev.h>
27 #include <kio/slaveconfig.h>
28 #include <kdeversion.h>
33 #include <qdatetime.h>
34 #include <qeucjpcodec.h>
39 /*---------------------------------------------------------*/
43 BoardData::BoardData( const QString& boardName,
44 const QString& hostname,
45 const QString& rootPath,
46 const QString& delimiter,
47 const QString& bbsPath,
52 m_boardName = boardName;
53 m_rootPath = rootPath;
54 m_delimiter = delimiter;
59 /* set hostname and create URL of board */
60 setHostName( hostname );
62 /* create default key */
63 QStringList keyHosts = m_hostname;
64 createKeys( keyHosts );
66 /* reset SETTING.TXT */
67 setSettingLoaded( FALSE );
70 BoardData::~BoardData()
75 void BoardData::setHostName( const QString& hostName )
77 m_hostname = hostName;
79 /* m_basePath = (hostname)/(rootPath)/(bbsPath)/ */
80 m_basePath = m_hostname + m_rootPath + m_bbsPath + "/";
84 case Board_MachiBBS: /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)?BBS=(bbsPath) */
85 m_cgiBasePath = m_hostname + m_rootPath + m_delimiter + "?BBS=" + m_bbsPath.mid( 1 );
88 /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)/(bbsPath)/ */
90 m_cgiBasePath = m_hostname + m_rootPath + m_delimiter + m_bbsPath + "/";
96 /*---------------------------*/
100 const bool BoardData::readIdx() const
106 void BoardData::setReadIdx( bool idx )
112 const QString& BoardData::boardName() const
118 const QString& BoardData::hostName() const
124 const QString& BoardData::rootPath() const
130 const QString& BoardData::delimiter() const
136 const QString& BoardData::bbsPath() const
142 const QString& BoardData::ext() const
148 const int BoardData::type() const
154 const QString& BoardData::basePath() const
160 const QString& BoardData::cgiBasePath() const
162 return m_cgiBasePath;
166 /*---------------------------*/
170 const QString BoardData::settingURL() const
172 return m_basePath + "SETTING.TXT";
176 const bool BoardData::settingLoaded() const
178 return m_settingLoaded;
182 const QString& BoardData::defaultName() const
184 return m_defaultName;
188 const int BoardData::lineNum() const
194 const int BoardData::msgCount() const
200 const KURL& BoardData::titleImgURL() const
202 return m_titleImgURL;
206 void BoardData::setSettingLoaded( bool set )
208 m_settingLoaded = set;
210 m_defaultName = QString::null;
213 m_titleImgURL = QString::null;
218 void BoardData::setDefaultName( const QString& newName )
220 m_defaultName = newName;
224 void BoardData::setLineNum( int newLine )
230 void BoardData::setMsgCount( int msgCount )
232 m_msgCount = msgCount;
236 void BoardData::setTitleImgURL( const KURL& url )
242 /*---------------------------*/
245 /* create keys of DB */ /* public */
246 void BoardData::createKeys( const QStringList& keyHostList )
249 m_keyBasePathList.clear();
250 m_keyCgiBasePathList.clear();
251 m_keyHostList.clear();
253 m_keyHostList = keyHostList;
255 /* m_basePath = (hostname)/(rootPath)/(bbsPath)/ */
256 for ( unsigned int i = 0; i < m_keyHostList.count(); ++i ) {
257 if ( m_keyHostList[ i ].length() > 0 )
258 m_keyBasePathList += m_keyHostList[ i ] + m_rootPath + m_bbsPath + "/";
263 case Board_MachiBBS: /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)?BBS=(bbsPath) */
264 for ( unsigned int i = 0; i < m_keyHostList.count(); ++i )
265 m_keyCgiBasePathList += m_keyHostList[ i ] + m_rootPath + m_delimiter
266 + "?BBS=" + m_bbsPath.mid( 1 );
269 /* m_cgiBasePath = (hostname)/(rootPath)/(delimiter)/(bbsPath)/ */
271 for ( unsigned int i = 0; i < m_keyHostList.count(); ++i )
272 m_keyCgiBasePathList += m_keyHostList[ i ] + m_rootPath + m_delimiter + m_bbsPath + "/";
278 const QStringList& BoardData::keyHostList() const
280 return m_keyHostList;
284 const QStringList& BoardData::keyBasePathList() const
286 return m_keyBasePathList;
290 const QStringList& BoardData::keyCgiBasePathList() const
292 return m_keyCgiBasePathList;
298 /*---------------------------------------------------------------*/
299 /*---------------------------------------------------------------*/
300 /*---------------------------------------------------------------*/
304 QCp932Codec* Kita::BoardManager::m_cp932Codec = NULL;
305 QEucJpCodec* Kita::BoardManager::m_eucJpCodec = NULL;
306 BoardDataList Kita::BoardManager::m_boardDataList;
307 BoardData* Kita::BoardManager::m_previousBoardData = NULL;
308 QString Kita::BoardManager::m_previousBoardURL;
311 BoardManager::BoardManager()
317 BoardManager::~BoardManager()
322 /* (hostname)/(rootPath)/(bbsPath)/ */ /* public */ /* static */
323 const QString BoardManager::boardURL( const KURL& url )
325 BoardData * bdata = getBoardData( url );
326 if ( bdata == NULL ) return QString::null;
328 return bdata->basePath();
331 /* public */ /* static */
332 const QStringList BoardManager::allBoardURLList()
337 for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it )
338 urlList += ( *it ) ->basePath();
343 /* (hostname)/(rootPath) */ /* public */ /* static */
344 const QString BoardManager::boardRoot( const KURL& url )
346 BoardData * bdata = getBoardData( url );
347 if ( bdata == NULL ) return QString::null;
349 return bdata->hostName() + bdata->rootPath();
352 /* (bbspath) */ /* public */ /* static */
353 const QString BoardManager::boardPath( const KURL& url )
355 BoardData * bdata = getBoardData( url );
356 if ( bdata == NULL ) return QString::null;
358 return bdata->bbsPath();
361 /* (ext) */ /* public */ /* static */
362 const QString BoardManager::ext( const KURL& url )
364 BoardData * bdata = getBoardData( url );
365 if ( bdata == NULL ) return QString::null;
370 /* ID of board for writing */ /* public */ /* static */
371 const QString BoardManager::boardID( const KURL& url )
373 BoardData * bdata = getBoardData( url );
374 if ( bdata == NULL ) return QString::null;
376 return bdata->bbsPath().mid( 1 ); /* remove "/" */
380 /* (hostname)/(rootPath)/(bbsPath)/subject.txt */ /* public */ /* static */
381 const QString BoardManager::subjectURL( const KURL& url )
383 BoardData * bdata = getBoardData( url );
384 if ( bdata == NULL ) return QString::null;
386 return bdata->basePath() + "subject.txt";
390 /* public */ /* static */
391 const QString BoardManager::boardName( const KURL& url )
393 BoardData * bdata = getBoardData( url );
394 if ( bdata == NULL ) return QString::null;
396 return bdata->boardName();
400 /* public */ /* static */
401 const int BoardManager::type( const KURL& url )
403 BoardData * bdata = getBoardData( url );
404 if ( bdata == NULL ) return Board_Unknown;
406 return bdata->type();
410 /*---------------------------*/
414 /* get list of pointers of Thread classes. */
419 oldLogs: If TRUE, search cache and get list of pointer of old threads.
420 online: online or offline mode.
424 threadList: list of pointers of Thread classes.
425 oldLogList: list of pointers of old threads.
427 */ /* public */ /* static */
428 void BoardManager::getThreadList(
436 QPtrList< Thread >& threadList,
437 QPtrList< Thread >& oldLogList )
442 /* get all obtained threads list from cache */
443 if ( url.prettyURL() == "http://virtual/obtained/" ) {
445 QStringList bbslist = allBoardURLList();
447 /* search all cache dirs */
448 for ( QStringList::iterator it = bbslist.begin() ; it != bbslist.end(); ++it ) {
450 getCachedThreadList( ( *it ), threadList );
456 /*-------------------------*/
458 BoardData* bdata = getBoardData( url );
459 if ( bdata == NULL ) return ;
461 /* download subject.txt */
465 QString cacheDir = Cache::baseDir() + Cache::serverDir( url ) + Cache::boardDir( url );
466 if ( !Kita::mkdir( cacheDir ) ) return ;
468 KIO::SlaveConfig::self() ->setConfigData( "http",
471 QString( "Monazilla/1.00 (Kita/%1)" ).arg( VERSION ) );
472 QString subjectPath = Cache::getSubjectPath( url );
473 KIO::NetAccess::download( subjectURL( url ), subjectPath, NULL );
475 /* download SETTING.TXT */
476 loadBBSSetting( url );
479 /* open and read subject.txt */
480 readSubjectTxt( bdata, url, threadList );
485 QPtrList< Thread > tmpList;
487 getCachedThreadList( url, tmpList );
489 for ( unsigned i = 0; i < tmpList.count(); i++ ) {
491 if ( threadList.contains( tmpList.at( i ) ) == 0 ) oldLogList.append( tmpList.at( i ) );
497 /* read the cache dir & get the list of all threads. */ /* private */ /* static */
498 void BoardManager::getCachedThreadList( const KURL& url, QPtrList< Thread >& threadList )
500 QString cacheDir = Cache::baseDir() + Cache::serverDir( url ) + Cache::boardDir( url );
504 /* get all file names */
505 QString ext = BoardManager::getBoardData( url ) ->ext();
506 QString boardURL = BoardManager::getBoardData( url ) ->basePath();
507 QStringList flist = d.entryList( "*" + ext );
509 for ( QStringList::iterator it = flist.begin(); it != flist.end(); ++it ) {
510 if ( ( *it ) == QString::null ) continue;
512 QString datURL = boardURL + "dat/" + ( *it );
515 Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
516 if ( thread == NULL ) {
518 thread = Kita::Thread::getByURL( datURL );
519 if ( thread == NULL ) continue;
520 ThreadIndex::loadIndex( thread, datURL, FALSE );
523 if ( thread != NULL ) threadList.append( thread );
530 /* open subject.txt and get list of Thread classes */ /* private */ /* static */
531 bool BoardManager::readSubjectTxt( BoardData* bdata, const KURL& url, QPtrList< Thread >& threadList )
533 /* get all names of cached files to read idx. */
534 QStringList cacheList;
535 if ( !bdata->readIdx() ) {
537 QString cacheDir = Cache::baseDir() + Cache::serverDir( url ) + Cache::boardDir( url );
540 QString ext = BoardManager::getBoardData( url ) ->ext();
541 cacheList = d.entryList( "*" + ext );
545 /* open subject.txt */
546 QString subjectPath = Cache::getSubjectPath( url );
547 QIODevice * device = KFilterDev::deviceForFile( subjectPath, "application/x-gzip" );
548 if ( !device->open( IO_ReadOnly ) ) return FALSE;
550 QTextStream stream( device );
552 if ( BoardManager::type( url ) == Board_JBBS ) {
553 if ( !m_eucJpCodec ) m_eucJpCodec = new QEucJpCodec();
554 stream.setCodec( m_eucJpCodec );
556 if ( !m_cp932Codec ) m_cp932Codec = new QCp932Codec();
557 stream.setCodec( m_cp932Codec );
560 // parse subject.txt(only one format...)
561 // FIXME: need to refactoring
563 switch ( BoardManager::type( url ) ) {
567 regexp.setPattern( "(\\d+\\.cgi),(.*)\\((\\d+)\\)" );
571 regexp.setPattern( "(\\d+\\.dat)<>(.*)\\((\\d+)\\)" );
576 while ( ( line = stream.readLine() ) != QString::null ) {
577 int pos = regexp.search( line );
579 QString fname = regexp.cap( 1 );
580 QString subject = regexp.cap( 2 );
581 QString num = regexp.cap( 3 );
583 /* get pointer of Thread class */
584 QString datURL = boardURL( url ) + "dat/" + fname;
585 Kita::Thread* thread = Kita::Thread::getByURL( datURL );
586 if ( threadList.find( thread ) == -1 ) {
587 threadList.append( thread );
590 /* set thread name */
591 thread->setThreadName( subject );
593 /* load index file */
594 if ( !bdata->readIdx() ) {
596 if ( cacheList.contains( fname ) ) ThreadIndex::loadIndex( thread, datURL, FALSE );
600 int newNum = num.toInt();
601 if ( thread->readNum() ) { /* cache exists */
602 int oldNum = thread->resNum();
604 if ( newNum > oldNum ) {
605 Kita::ThreadIndex::setResNum( datURL, newNum );
608 thread->setResNum( newNum );
613 bdata->setReadIdx( TRUE ); /* never read idx files again */
618 /*---------------------------*/
621 /* reset all BoardData */ /* public */ /* static */
622 void BoardManager::clearBoardData()
624 for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it )
627 m_boardDataList.clear();
628 m_previousBoardData = NULL;
629 m_previousBoardURL = QString::null;
635 * @param[in] boardName
641 * @retval Board_enrollEnrolled if board is already enrolled. oldURL is QString::null.
642 * @retval Board_enrollNew if board is new board. oldURL is QString::null.
643 * @retval Board_enrollMoved if board is moved. oldURL is old URL.
645 * @note board is NOT enrolled when board is moved.
646 * To enroll new URL, call BoardManager::moveBoard().
648 * "int type" is type of board. It could be "Kita::Board_Unknown". See also parseBoardURL().
650 * If "bool test" is TRUE, this function just checks if the board is enrolled (never enroll board).
653 /* public */ /* static */
654 int BoardManager::enrollBoard( const KURL& url, const QString& boardName, QString& oldURL, int type, bool test )
661 type = parseBoardURL( url, type, hostname, rootPath, delimiter, bbsPath, ext );
662 oldURL = QString::null;
664 if ( type == Board_Unknown ) return Board_enrollFailed;
666 /* check if the board is enrolled or moved. */
667 for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it ) {
669 if ( ( *it ) ->boardName() == boardName
670 && ( *it ) ->type() == type
671 && ( *it ) ->bbsPath() == bbsPath ) {
673 if ( ( *it ) ->hostName() == hostname
674 && ( *it ) ->rootPath() == rootPath ) { /* enrolled */
675 return Board_enrollEnrolled;
677 oldURL = ( *it ) ->basePath();
678 return Board_enrollMoved;
684 if ( test ) return Board_enrollNew;
686 /* enroll new board */
687 BoardData* bdata = new BoardData( boardName, hostname, rootPath, delimiter, bbsPath, ext, type );
688 m_boardDataList.append( bdata );
690 return Board_enrollNew;
694 /* parse board URL */
695 /* return board type. */ /* private */ /* static */
696 int BoardManager::parseBoardURL(
700 int type, /* If type = Board_Unknown, type will be decided according to url. */
709 hostname = url.protocol() + "://" + url.host();
710 rootPath = QString::null;
711 delimiter = QString::null;
712 bbsPath = QString::null;
716 if ( type == Board_Unknown ) {
718 if ( url.host().contains( "machi.to" ) ) type = Board_MachiBBS;
719 else if ( url.host().contains( "jbbs.livedoor.jp" ) ) type = Board_JBBS;
720 else type = Board_2ch;
726 case Board_MachiBBS: /* MACHI : http:// *.machi.to/(bbsPath)/ */
728 delimiter = "/bbs/read.pl";
729 bbsPath = url.filename();
733 case Board_JBBS: /* JBBS : http://jbbs.livedoor.jp/(bbsPath)/ */
735 delimiter = "/bbs/read.cgi";
736 bbsPath = url.prettyURL().remove( hostname );
741 case Board_FlashCGI: /* test for Flash CGI/Mini Thread */
743 delimiter = "/test/read.cgi";
744 bbsPath = url.filename();
745 rootPath = url.prettyURL().remove( hostname + "/" ).remove( bbsPath + "/" );
746 if ( rootPath.length() == 0 ) rootPath = QString::null;
750 default: /* 2ch : http://(hostname)/(rootPath)/(bbsPath)/ */
752 delimiter = "/test/read.cgi";
753 bbsPath = url.filename();
754 rootPath = url.prettyURL().remove( hostname + "/" ).remove( bbsPath + "/" );
755 if ( rootPath.length() == 0 ) rootPath = QString::null;
761 /* For example, if bbsPath = "linux/", then m_bbsPath = "/linux" */
762 const QRegExp exp( "/$" );
763 rootPath.remove( exp );
764 bbsPath.remove( exp );
765 if ( rootPath != QString::null && rootPath.at( 0 ) != '/' ) rootPath = "/" + rootPath;
766 if ( bbsPath != QString::null && bbsPath.at( 0 ) != '/' ) bbsPath = "/" + bbsPath;
772 /* public */ /* static */
773 bool BoardManager::isEnrolled( const KURL& url )
775 if ( getBoardData( url ) == NULL ) return FALSE;
780 /* public */ /* static */
781 BoardData* BoardManager::getBoardData( const KURL& url )
783 if ( url.isEmpty() ) return NULL;
784 QString urlstr = url.prettyURL();
787 if ( m_previousBoardData != NULL && m_previousBoardURL == urlstr ) return m_previousBoardData;
789 for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it ) {
791 int count = ( *it ) ->keyBasePathList().count();
792 for ( int i = 0; i < count ; ++i ) {
793 if ( urlstr.contains( ( *it ) ->keyBasePathList() [ i ] )
794 || urlstr.contains( ( *it ) ->keyCgiBasePathList() [ i ] ) ) {
797 m_previousBoardData = ( *it );
798 m_previousBoardURL = urlstr;
810 /*--------------------------------*/
814 /* load the bbs history file ( BBSHISTORY ), and create keys of Data Base. */
815 /* Before calling this, enroll the board by enrollBoard(). */
817 ex) If the host of board moved like :
819 http:://aaa.com -> http://bbb.com -> http://ccc.com -> http://ddd.com
827 */ /* public */ /* static */
828 bool BoardManager::loadBBSHistory( const KURL& url )
830 BoardData * bdata = getBoardData( url );
831 if ( bdata == NULL ) return FALSE;
833 QStringList keyHosts = bdata->hostName();
835 QFile file( Cache::getBBSHistoryPath( url ) );
836 if ( file.open( IO_ReadOnly ) ) {
838 QTextStream ts( &file );
841 while ( !ts.eof() ) {
843 line = ts.readLine();
847 bdata->createKeys( keyHosts );
857 /* public */ /* static */
858 bool BoardManager::moveBoard( const KURL& fromURL, const KURL& toURL )
860 QString oldhost = fromURL.protocol() + "://" + fromURL.host();
861 QString newhost = toURL.protocol() + "://" + toURL.host();
863 const QRegExp exp( "/$" );
864 QString oldURL = fromURL.prettyURL();
865 QString newURL = toURL.prettyURL();
866 oldURL.remove( exp );
867 newURL.remove( exp );
871 if ( oldURL == newURL ) return FALSE;
873 /* Is oldURL enrolled? */
874 BoardData* bdata = getBoardData( oldURL );
875 if ( bdata == NULL ) {
877 /* Is newURL enrolled? */
878 bdata = getBoardData( newURL );
879 if ( bdata == NULL ) return FALSE;
883 /*---------------------------*/
884 /* update BoardData */
886 /* get the path of old cache */
887 bdata->setHostName( oldhost );
888 QStringList keyHosts = bdata->keyHostList();
889 keyHosts.remove( oldhost );
890 keyHosts.prepend( oldhost );
891 bdata->createKeys( keyHosts );
892 QString oldCachePath = Cache::baseDir() + Cache::serverDir( bdata->basePath() )
893 + Cache::boardDir( bdata->basePath() );
896 bdata->setHostName( newhost );
899 /* The order of keyHosts will be like this:
907 keyHosts = bdata->keyHostList();
908 keyHosts.remove( oldhost );
909 keyHosts.prepend( oldhost );
910 keyHosts.remove( newhost );
911 keyHosts.prepend( newhost );
912 bdata->createKeys( keyHosts );
914 /* reset BoardData */
915 bdata->setReadIdx( FALSE );
916 bdata->setSettingLoaded( FALSE );
919 /*---------------------------*/
923 if ( ! qdir.exists( oldCachePath ) ) return TRUE;
925 /* mkdir new server dir */
926 QString newCachePath = Cache::baseDir() + Cache::serverDir( bdata->basePath() );
927 Kita::mkdir( newCachePath );
930 newCachePath += Cache::boardDir( bdata->basePath() );
931 if ( qdir.exists ( newCachePath ) ) {
932 QString bkupPath = newCachePath;
933 bkupPath.truncate( bkupPath.length() - 1 ); /* remove '/' */
934 bkupPath += "." + QString().setNum( QDateTime::currentDateTime().toTime_t() );
935 qdir.rename( newCachePath, bkupPath );
939 if ( qdir.exists( oldCachePath ) ) {
940 qdir.rename( oldCachePath, newCachePath );
941 } else Kita::mkdir( newCachePath );
944 if ( ! qdir.exists( oldCachePath ) ) {
945 Kita::mkdir( oldCachePath );
946 /* create BBS_MOVED */
947 QString movedPath = oldCachePath + "/BBS_MOVED";
948 QFile file( movedPath );
949 if ( file.open( IO_WriteOnly ) ) {
950 QTextStream stream( &file );
951 stream << newURL << endl;
956 /*---------------------------*/
957 /* update BBSHISTRY */
959 QFile file( Cache::getBBSHistoryPath( bdata->basePath() ) );
960 if ( file.open( IO_WriteOnly ) ) {
962 QTextStream ts( &file );
964 keyHosts.remove( newhost );
965 for ( QStringList::iterator it = keyHosts.begin() ; it != keyHosts.end(); ++it ) {
966 ts << ( *it ) << endl;
973 /*---------------------------*/
974 /* update other information */
975 FavoriteThreads::replace( oldURL, newURL );
976 Kita::Thread::replace( oldURL, newURL );
977 KitaThreadInfo::replace( oldURL, newURL );
978 Kita::FavoriteBoards::replace( oldURL, newURL );
984 /*--------------------------------*/
988 /* public */ /* static */
989 bool BoardManager::loadBBSSetting( const KURL& url, bool reload )
991 /* Is board enrolled ? */
992 BoardData * bdata = getBoardData( url );
993 if ( bdata == NULL ) return FALSE;
994 if ( bdata->type() != Board_2ch ) return FALSE;
996 KURL settingURL = bdata->settingURL();
997 QString path = Cache::getSettingPath( url );
1000 if ( DownloadManager::isLoadingNow( settingURL ) ) return FALSE;
1002 /* already loaded */
1003 if ( bdata->settingLoaded() && !reload ) return TRUE;
1005 /* reset names, linenum, etc. */
1006 bdata->setSettingLoaded( FALSE );
1008 /* download SETTING.TXT.*/
1009 DownloadManager::download( settingURL, path );
1010 bdata->setSettingLoaded( TRUE );
1016 /* public */ /* static */
1017 QString BoardManager::getBBSDefaultName( const KURL& url )
1019 BoardData * bdata = openSettingTxt( url );
1020 if ( bdata == NULL ) bdata = getBoardData( url );
1021 if ( bdata == NULL ) return "(default name)";
1022 if ( bdata->defaultName() == QString::null ) return "(default name)";
1023 return bdata->defaultName();
1027 /* public */ /* static */
1028 int BoardManager::getBBSMaxLine( const KURL& url )
1030 BoardData * bdata = openSettingTxt( url );
1031 if ( bdata == NULL ) bdata = getBoardData( url );
1032 if ( bdata == NULL ) return 0;
1033 return bdata->lineNum();
1036 /* public */ /* static */
1037 int BoardManager::getBBSMsgCount( const KURL& url )
1039 BoardData * bdata = openSettingTxt( url );
1040 if ( bdata == NULL ) bdata = getBoardData( url );
1041 if ( bdata == NULL ) return 0;
1042 return bdata->msgCount();
1046 /* public */ /* static */
1047 const KURL BoardManager::titleImgURL( const KURL& url )
1049 BoardData * bdata = openSettingTxt( url );
1050 if ( bdata == NULL ) bdata = getBoardData( url );
1051 if ( bdata == NULL ) return QString::null;
1052 return bdata->titleImgURL();
1055 /* open local SETTING.TXT, then get names, linenum, etc. */ /* private */ /* static */
1056 BoardData* BoardManager::openSettingTxt( const KURL& url )
1058 BoardData * bdata = getBoardData( url );
1059 if ( bdata == NULL ) return NULL;
1060 if ( !bdata->settingLoaded() ) return NULL;
1061 if ( DownloadManager::isLoadingNow( bdata->settingURL() ) ) return NULL;
1062 if ( bdata->defaultName() != QString::null ) return bdata;
1064 QFile file( Cache::getSettingPath( url ) );
1065 if ( file.open( IO_ReadOnly ) ) {
1067 QTextStream ts( &file );
1068 if ( m_cp932Codec == NULL ) m_cp932Codec = new QCp932Codec();
1069 ts.setCodec( m_cp932Codec );
1072 while ( !ts.eof() ) {
1074 line = ts.readLine();
1077 QString key = "BBS_NONAME_NAME=";
1078 if ( line.find( key ) != -1 ) bdata->setDefaultName( line.remove( key ) );
1081 key = "NANASI_NAME=";
1082 if ( line.find( key ) != -1 ) bdata->setDefaultName( line.remove( key ) );
1085 key = "BBS_LINE_NUMBER=";
1086 if ( line.find( key ) != -1 ) bdata->setLineNum( line.remove( key ).toInt() * 2 );
1089 key = "BBS_MESSAGE_COUNT=";
1090 if ( line.find( key ) != -1 ) bdata->setMsgCount( line.remove( key ).toInt() );
1093 key = "BBS_TITLE_PICTURE=";
1094 if ( line.find( key ) != -1 ) {
1095 QString path = line.remove( key );
1096 KURL titleImgURL = KURL( bdata->basePath(), path );
1097 bdata->setTitleImgURL( titleImgURL );
1104 if ( bdata->defaultName() == QString::null ) bdata->setDefaultName( "(default name)" );