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* BoardManager::m_cp932Codec = NULL;
305 QEucJpCodec* BoardManager::m_eucJpCodec = NULL;
306 BoardDataList BoardManager::m_boardDataList;
307 BoardData* BoardManager::m_previousBoardData = NULL;
310 BoardManager::BoardManager()
316 BoardManager::~BoardManager()
321 /* (hostname)/(rootPath)/(bbsPath)/ */ /* public */ /* static */
322 const QString BoardManager::boardURL( const KURL& url )
324 BoardData* bdata = getBoardData( url );
325 if( bdata == NULL ) return QString::null;
327 return bdata->basePath();
330 /* public */ /* static */
331 const QStringList BoardManager::allBoardURLList()
336 for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it )
337 urlList += (*it)->basePath();
342 /* (hostname)/(rootPath) */ /* public */ /* static */
343 const QString BoardManager::boardRoot( const KURL& url )
345 BoardData* bdata = getBoardData( url );
346 if( bdata == NULL ) return QString::null;
348 return bdata->hostName() + bdata->rootPath();
351 /* (bbspath) */ /* public */ /* static */
352 const QString BoardManager::boardPath( const KURL& url )
354 BoardData* bdata = getBoardData( url );
355 if( bdata == NULL ) return QString::null;
357 return bdata->bbsPath();
360 /* ID of board for writing */ /* public */ /* static */
361 const QString BoardManager::boardID( const KURL& url )
363 BoardData* bdata = getBoardData( url );
364 if( bdata == NULL ) return QString::null;
366 return bdata->bbsPath().mid( 1 ); /* remove "/" */
370 /* (hostname)/(rootPath)/(bbsPath)/subject.txt */ /* public */ /* static */
371 const QString BoardManager::subjectURL( const KURL& url )
373 BoardData* bdata = getBoardData( url );
374 if( bdata == NULL ) return QString::null;
376 return bdata->basePath() + "subject.txt";
380 /* public */ /* static */
381 const QString BoardManager::boardName( const KURL& url )
383 BoardData* bdata = getBoardData( url );
384 if( bdata == NULL ) return QString::null;
386 return bdata->boardName();
390 /* public */ /* static */
391 const int BoardManager::type( const KURL& url )
393 BoardData* bdata = getBoardData( url );
394 if( bdata == NULL ) return Board_Unknown;
396 return bdata->type();
400 /*---------------------------*/
404 /* get list of pointers of Thread classes. */
409 oldLogs: If TRUE, search cache and get list of pointer of old threads.
410 online: online or offline mode.
414 threadList: list of pointers of Thread classes.
415 oldLogList: list of pointers of old threads.
417 */ /* public */ /* static */
418 void BoardManager::getThreadList(
426 QPtrList< Thread >& threadList,
427 QPtrList< Thread >& oldLogList )
432 /* get all obtained threads list from cache */
433 if ( url.prettyURL() == "http://virtual/obtained/" ) {
435 QStringList bbslist = allBoardURLList();
437 /* search all cache dirs */
438 for ( QStringList::iterator it = bbslist.begin() ; it != bbslist.end(); ++it ) {
440 getCachedThreadList( ( *it ), threadList );
446 /*-------------------------*/
448 BoardData* bdata = getBoardData( url );
449 if( bdata == NULL ) return;
451 /* download subject.txt */
455 QString cacheDir = Cache::baseDir() + Cache::serverDir( url ) + Cache::boardDir( url );
456 if( !Kita::mkdir( cacheDir ) ) return;
458 KIO::SlaveConfig::self() ->setConfigData( "http",
461 QString( "Monazilla/1.00 (Kita/%1)" ).arg( VERSION ) );
462 QString subjectPath = Cache::getSubjectPath( url );
463 #if KDE_IS_VERSION( 3, 2, 0 )
464 KIO::NetAccess::download( subjectURL( url ), subjectPath, NULL );
466 KIO::NetAccess::download( subjectURL( url ), subjectPath );
469 /* download SETTING.TXT */
470 loadBBSSetting( url );
473 /* open and read subject.txt */
474 readSubjectTxt( url, threadList );
477 if( !bdata->readIdx() ){
478 getThreadInfoFromIdx( url, threadList );
479 bdata->setReadIdx( TRUE );
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 idx file and get information */ /* private */ /* static */
498 void BoardManager::getThreadInfoFromIdx( const KURL& url, QPtrList< Thread >& threadList )
500 QString cacheDir = Cache::baseDir() + Cache::serverDir( url ) + Cache::boardDir( url );
503 qDebug( "readIndexFile: %s", cacheDir.ascii() );
505 /* get all file names */
506 QString ext = BoardManager::getBoardData( url )->ext();
507 QStringList flist = d.entryList( "*" + ext );
509 unsigned int count = threadList.count();
510 for ( unsigned i = 0; i < count; i++ ) {
512 Kita::Thread* thread = threadList.at( i );
513 QString fname = KURL( thread->datURL() ).filename();
514 if( flist.contains( fname ) ){
516 int readNum = QMAX( ThreadIndex::getReadNum( thread->datURL() ), 1 );
517 KitaThreadInfo::setReadNum( thread->datURL(), readNum );
518 qDebug( "%s : %d",(const char*)thread->threadName().local8Bit(), readNum );
526 /* read the cache dir & get the list of all threads. */ /* private */ /* static */
527 void BoardManager::getCachedThreadList( const KURL& url, QPtrList< Thread >& threadList )
529 QString cacheDir = Cache::baseDir() + Cache::serverDir( url ) + Cache::boardDir( url );
533 /* get all file names */
534 QString ext = BoardManager::getBoardData( url )->ext();
535 QString boardURL = BoardManager::getBoardData( url )->basePath();
536 QStringList flist = d.entryList( "*" + ext );
538 for ( QStringList::iterator it = flist.begin(); it != flist.end(); ++it ) {
539 if ( ( *it ) == QString::null ) continue;
541 QString datURL = boardURL + "dat/" + ( *it );
544 if( Kita::Thread::getByURLNew( datURL ) == NULL ){
546 QString subject = Kita::ThreadIndex::getSubject( datURL );
547 if ( subject == QString::null ) subject = "?";
548 Kita::Thread::setName( datURL, subject );
550 int resNum = QMAX( 1, Kita::ThreadIndex::getResNum( datURL ) );
551 KitaThreadInfo::setResNum( datURL, resNum );
553 int readNum = QMAX( 1, Kita::ThreadIndex::getReadNum( datURL ) );
554 KitaThreadInfo::setReadNum( datURL, readNum );
557 Kita::Thread* thread = Kita::Thread::getByURL( datURL );
558 threadList.append( thread );
565 /* open subject.txt and get list of Thread classes */ /* private */ /* static */
566 bool BoardManager::readSubjectTxt( const KURL& url, QPtrList< Thread >& threadList )
568 QString subjectPath = Cache::getSubjectPath( url );
569 QIODevice * device = KFilterDev::deviceForFile( subjectPath, "application/x-gzip" );
570 if( !device->open( IO_ReadOnly ) ) return FALSE;
572 QTextStream stream( device );
574 if ( BoardManager::type( url ) == Board_JBBS ) {
575 if ( !m_eucJpCodec ) m_eucJpCodec = new QEucJpCodec();
576 stream.setCodec( m_eucJpCodec );
578 if ( !m_cp932Codec ) m_cp932Codec = new QCp932Codec();
579 stream.setCodec( m_cp932Codec );
582 // parse subject.txt(only one format...)
583 // FIXME: need to refactoring
585 switch ( BoardManager::type( url ) ) {
589 regexp.setPattern( "(\\d+\\.cgi),(.*)\\((\\d+)\\)" );
593 regexp.setPattern( "(\\d+\\.dat)<>(.*)\\((\\d+)\\)" );
598 while ( ( line = stream.readLine() ) != QString::null ) {
599 int pos = regexp.search( line );
601 QString fname = regexp.cap( 1 );
602 QString subject = regexp.cap( 2 );
603 QString num = regexp.cap( 3 );
605 QString datURL = boardURL( url ) + "dat/" + fname;
606 Kita::Thread::setName( datURL, subject );
607 Kita::Thread* thread = Kita::Thread::getByURL( datURL );
608 KitaThreadInfo::setResNum( datURL, num.toInt() );
609 threadList.append( thread );
619 /*---------------------------*/
622 /* reset all BoardData */ /* public */ /* static */
623 void BoardManager::clearBoardData()
625 for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it )
628 m_boardDataList.clear();
629 m_previousBoardData = NULL;
634 /* Input: board, boardName
637 If board is already enrolled, return Board_enrollEnrolled and oldURL is QString::null.
638 If board is new board, return Board_enrollNew and oldURL is QString::null.
639 If board is moved, return Board_enrollMoved, and oldURL is old URL.
641 Note that board is NOT enrolled when board is moved.
642 To enroll new URL, call BoardManager::moveBoard().
644 /* public */ /* static */
645 int BoardManager::enrollBoard( const KURL& url, const QString& boardName, QString& oldURL )
647 // qDebug( "enroll %s %s", ( const char * ) boardName.local8Bit(),url.prettyURL().ascii());
654 int type = parseBoardURL( url, hostname, rootPath, delimiter, bbsPath, ext );
655 oldURL = QString::null;
657 if( type == Board_Unknown ) return Board_enrollFailed;
659 /* check if the board is enrolled or moved. */
660 for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it ){
662 if( ( *it )->boardName() == boardName
663 && ( *it )->type() == type
664 && ( *it )->bbsPath() == bbsPath ){
666 if( ( *it )->hostName() == hostname
667 && ( *it )->rootPath() == rootPath ){ /* enrolled */
668 // qDebug( "enrolled" );
669 return Board_enrollEnrolled;
672 // qDebug( "moved" );
673 oldURL = ( *it )->basePath();
674 return Board_enrollMoved;
679 /* enroll new board */
680 BoardData* bdata = new BoardData( boardName, hostname, rootPath, delimiter, bbsPath, ext, type );
681 m_boardDataList.append( bdata );
683 return Board_enrollNew;
687 /* private */ /* static */
688 int BoardManager::parseBoardURL( const KURL& url,
695 int type = Board_Unknown;
697 hostname = url.protocol() + "://" + url.host();
698 rootPath = QString::null;
699 delimiter = QString::null;
700 bbsPath = QString::null;
703 /* MACHI : http:// *.machi.to/(bbsPath)/ */
704 if( url.host().contains( "machi.to" ) ){
706 delimiter = "/bbs/read.pl";
707 bbsPath = url.filename();
709 type = Board_MachiBBS;
712 /* JBBS : http://jbbs.livedoor.jp/(bbsPath)/ */
713 else if( url.host().contains( "jbbs.livedoor.jp" ) ){
715 delimiter = "/bbs/read.cgi";
716 bbsPath = url.prettyURL().remove( hostname );
721 /* test for Flash CGI/Mini Thread */
722 else if( url.host().contains( "oooug.jp" ) ){
724 delimiter = "/test/read.cgi";
725 bbsPath = url.filename();
726 rootPath = url.prettyURL().remove( hostname + "/" ).remove( bbsPath + "/" );
727 if( rootPath.length() == 0 ) rootPath = QString::null;
729 type = Board_FlashCGI;
732 /* 2ch : http://(hostname)/(rootPath)/(bbsPath)/ */
735 delimiter = "/test/read.cgi";
736 bbsPath = url.filename();
737 rootPath = url.prettyURL().remove( hostname + "/" ).remove( bbsPath + "/" );
738 if( rootPath.length() == 0 ) rootPath = QString::null;
743 /* For example, if bbsPath = "linux/", then m_bbsPath = "/linux" */
744 const QRegExp exp( "/$" );
745 rootPath.remove( exp );
746 bbsPath.remove( exp );
747 if( rootPath != QString::null && rootPath.at( 0 ) != '/' ) rootPath = "/" + rootPath;
748 if( bbsPath != QString::null && bbsPath.at( 0 ) != '/' ) bbsPath = "/" + bbsPath;
751 qDebug( "host : %s", hostname.ascii() );
752 qDebug( "root : %s", rootPath.ascii() );
753 qDebug( "deli : %s", delimiter.ascii() );
754 qDebug( "bbs : %s", bbsPath.ascii() );
761 /* public */ /* static */
762 bool BoardManager::isEnrolled( const KURL& url )
764 if( getBoardData( url ) == NULL ) return FALSE;
769 /* public */ /* static */
770 BoardData* BoardManager::getBoardData( const KURL& url )
772 QString urlstr = url.prettyURL();
774 if( m_previousBoardData != NULL ){
775 int count = m_previousBoardData->keyBasePathList().count();
776 for( int i = 0; i < count ; ++i ){
777 if( urlstr.contains( m_previousBoardData->keyBasePathList()[i] )
778 || urlstr.contains( m_previousBoardData->keyCgiBasePathList()[i] ) ){
780 return m_previousBoardData;
785 for ( BoardDataList::Iterator it = m_boardDataList.begin(); it != m_boardDataList.end(); ++it ){
787 int count = (*it)->keyBasePathList().count();
788 for( int i = 0; i < count ; ++i ){
789 if( urlstr.contains( (*it)->keyBasePathList()[i] )
790 || urlstr.contains( (*it)->keyCgiBasePathList()[i] ) ){
792 m_previousBoardData = (*it);
803 /*--------------------------------*/
807 /* load the bbs history file ( BBSHISTORY ), and create keys of Data Base. */
808 /* Before calling this, enroll the board by enrollBoard(). */
810 ex) If the host of board moved like :
812 http:://aaa.com -> http://bbb.com -> http://ccc.com -> http://ddd.com
820 */ /* public */ /* static */
821 bool BoardManager::loadBBSHistory( const KURL& url )
823 BoardData* bdata = getBoardData( url );
824 if( bdata == NULL ) return FALSE;
826 QStringList keyHosts = bdata->hostName();
828 QFile file( Cache::getBBSHistoryPath( url ) );
829 if ( file.open( IO_ReadOnly ) ){
831 qDebug( "read BBSHISTRY : %s",Cache::getBBSHistoryPath( url ).ascii() );
833 QTextStream ts( &file );
838 line = ts.readLine();
839 qDebug("line: %s",line.ascii());
843 bdata->createKeys( keyHosts );
853 /* public */ /* static */
854 bool BoardManager::moveBoard( const KURL& fromURL, const KURL& toURL )
856 QString oldhost = fromURL.protocol() + "://" + fromURL.host();
857 QString newhost = toURL.protocol() + "://" + toURL.host();
859 const QRegExp exp( "/$" );
860 QString oldURL = fromURL.prettyURL();
861 QString newURL = toURL.prettyURL();
862 oldURL.remove( exp );
863 newURL.remove( exp );
867 qDebug( "moveBoard : %s -> %s", oldURL.ascii(), newURL.ascii() );
869 if( oldURL == newURL ) return FALSE;
871 /* Is oldURL enrolled? */
872 BoardData* bdata = getBoardData( oldURL );
875 /* Is newURL enrolled? */
876 bdata = getBoardData( newURL );
877 if( bdata == NULL ) return FALSE;
881 /*---------------------------*/
882 /* updata BoardData */
884 /* get the path of old cache */
885 bdata->setHostName( oldhost );
886 QStringList keyHosts = bdata->keyHostList();
887 keyHosts.remove( oldhost );
888 keyHosts.prepend( oldhost );
889 bdata->createKeys( keyHosts );
890 QString oldCachePath = Cache::baseDir() + Cache::serverDir( bdata->basePath() )
891 + Cache::boardDir( bdata->basePath() );
894 bdata->setHostName( newhost );
897 /* The order of keyHosts will be like this:
905 keyHosts = bdata->keyHostList();
906 keyHosts.remove( oldhost );
907 keyHosts.prepend( oldhost );
908 keyHosts.remove( newhost );
909 keyHosts.prepend( newhost );
910 bdata->createKeys( keyHosts );
913 /*---------------------------*/
918 /* mkdir new server dir */
919 QString newCachePath = Cache::baseDir() + Cache::serverDir( bdata->basePath() );
920 Kita::mkdir( newCachePath );
923 newCachePath += Cache::boardDir( bdata->basePath() );
924 if( qdir.exists ( newCachePath ) ){
925 QString bkupPath = newCachePath;
926 bkupPath.truncate( bkupPath.length() -1 ); /* remove '/' */
927 bkupPath += "." + QString().setNum( QDateTime::currentDateTime().toTime_t() );
928 qDebug( "mv %s\n -> %s", newCachePath.ascii(), bkupPath.ascii() );
929 qdir.rename( newCachePath, bkupPath );
933 qDebug( "old: %s", oldCachePath.ascii() );
934 if( qdir.exists( oldCachePath ) ){
935 qDebug( "move: %s\n-> %s", oldCachePath.ascii(), newCachePath.ascii() );
936 qdir.rename( oldCachePath, newCachePath );
938 else Kita::mkdir( newCachePath );
941 if ( ! qdir.exists( oldCachePath ) ) {
942 Kita::mkdir( oldCachePath );
943 /* create BBS_MOVED */
944 QString movedPath = oldCachePath + "/BBS_MOVED";
945 QFile file( movedPath );
946 if ( file.open( IO_WriteOnly ) ) {
947 qDebug( "write BBS_MOVED : %s", movedPath.ascii() );
948 QTextStream stream( &file );
949 stream << newURL << endl;
954 /*---------------------------*/
955 /* update BBSHISTRY */
957 QFile file( Cache::getBBSHistoryPath( bdata->basePath() ) );
958 if ( file.open( IO_WriteOnly ) ){
960 qDebug( "write BBSHISTRY : %s", Cache::getBBSHistoryPath( bdata->basePath() ).ascii() );
961 QTextStream ts( &file );
963 keyHosts.remove( newhost );
964 for ( QStringList::iterator it = keyHosts.begin() ; it != keyHosts.end(); ++it ) {
972 /*---------------------------*/
973 /* update other information */
974 FavoriteThreads::replace( oldURL, newURL );
975 Kita::Thread::replace( oldURL, newURL );
976 KitaThreadInfo::replace( oldURL, newURL );
977 Kita::FavoriteBoards::replace( oldURL, newURL );
979 qDebug("%s",bdata->basePath().ascii() );
980 qDebug("%s",bdata->cgiBasePath().ascii() );
981 int count = bdata->keyBasePathList().count();
982 for( int i = 0; i < count ; ++i ){
983 qDebug("key: %s",bdata->keyBasePathList()[i].ascii() );
984 qDebug("key: %s",bdata->keyCgiBasePathList()[i].ascii() );
991 /*--------------------------------*/
995 /* public */ /* static */
996 bool BoardManager::loadBBSSetting( const KURL& url, bool reload )
998 /* Is board enrolled ? */
999 BoardData* bdata = getBoardData( url );
1000 if( bdata == NULL ) return FALSE;
1001 if( bdata->type() != Board_2ch ) return FALSE;
1003 KURL settingURL = bdata->settingURL();
1004 QString path = Cache::getSettingPath( url );
1007 if( DownloadManager::isLoadingNow( settingURL ) ) return FALSE;
1009 /* already loaded */
1010 if( bdata->settingLoaded() && !reload ) return TRUE;
1012 /* reset names, linenum, etc. */
1013 bdata->setSettingLoaded( FALSE );
1015 qDebug("LOAD SETTING.TXT : %s",settingURL.prettyURL().ascii());
1016 qDebug("path: %s",path.ascii());
1018 /* download SETTING.TXT.*/
1019 DownloadManager::download( settingURL, path );
1020 bdata->setSettingLoaded( TRUE );
1026 /* public */ /* static */
1027 QString BoardManager::getBBSDefaultName( const KURL& url )
1029 BoardData* bdata = openSettingTxt( url );
1030 if( bdata == NULL ) return QString::null;
1031 return bdata->defaultName();
1035 /* public */ /* static */
1036 int BoardManager::getBBSMaxLine( const KURL& url )
1038 BoardData* bdata = openSettingTxt( url );
1039 if( bdata == NULL ) return 0;
1040 return bdata->lineNum();
1043 /* public */ /* static */
1044 int BoardManager::getBBSMsgCount( const KURL& url )
1046 BoardData* bdata = openSettingTxt( url );
1047 if( bdata == NULL ) return 0;
1048 return bdata->msgCount();
1052 /* public */ /* static */
1053 const KURL BoardManager::titleImgURL( const KURL& url )
1055 BoardData* bdata = openSettingTxt( url );
1056 if( bdata == NULL ) return QString::null;
1057 return bdata->titleImgURL();
1060 /* open local SETTING.TXT, then get names, linenum, etc. */ /* private */ /* static */
1061 BoardData* BoardManager::openSettingTxt( const KURL& url )
1063 BoardData* bdata = getBoardData( url );
1064 if( bdata == NULL ) return NULL;
1065 if( !bdata->settingLoaded() ) return NULL;
1066 if( DownloadManager::isLoadingNow( bdata->settingURL() ) ) return NULL;
1067 if( bdata->defaultName() != QString::null ) return bdata;
1069 qDebug( "read SETTING.TXT");
1071 QFile file( Cache::getSettingPath( url ) );
1072 if ( file.open( IO_ReadOnly ) ){
1074 QTextStream ts( &file );
1075 if( m_cp932Codec == NULL) m_cp932Codec = new QCp932Codec();
1076 ts.setCodec( m_cp932Codec );
1081 line = ts.readLine();
1082 // qDebug("line: %s\n",(const char *)line.local8Bit());
1085 QString key = "BBS_NONAME_NAME=";
1086 if( line.find( key ) != -1 ) bdata->setDefaultName( line.remove( key ) );
1089 key = "NANASI_NAME=";
1090 if( line.find( key ) != -1 ) bdata->setDefaultName( line.remove( key ) );
1093 key = "BBS_LINE_NUMBER=";
1094 if( line.find( key ) != -1 ) bdata->setLineNum( line.remove( key ).toInt() * 2 );
1097 key = "BBS_MESSAGE_COUNT=";
1098 if( line.find( key ) != -1 ) bdata->setMsgCount( line.remove( key ).toInt() );
1101 key = "BBS_TITLE_PICTURE=";
1102 if( line.find( key ) != -1 ){
1103 QString path = line.remove( key );
1104 KURL titleImgURL = KURL( bdata->basePath(), path );
1105 bdata->setTitleImgURL( titleImgURL );
1112 if( bdata->defaultName() == QString::null ) bdata->setDefaultName( "(default name)" );
1114 qDebug( "name: %s", (const char *)bdata->defaultName().local8Bit());
1115 qDebug( "line num: %d", bdata->lineNum() );