1 /**************************************************************************
2 * Copyright (C) 2003 by Hideki Ikemoto , (c)2004 by 421 *
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 ***************************************************************************/
12 #include <qstringlist.h>
14 #include <dom/html_document.h>
15 #include <dom/html_element.h>
16 #include <dom/html_table.h>
17 #include <dom/dom_text.h>
20 #include "datmanager.h"
21 #include "parsemisc.h"
24 #include "threadinfo.h"
25 #include "kitaconfig.h"
26 #include "kita-utf8.h"
27 #include "kita-utf16.h"
28 #include "kita_misc.h"
32 #define RESDAT_DEFAULTSIZE 10
33 #define RESDAT_DELTA 1000
36 /*------------------------------------------------------*/
37 /* DatInfo stores & handles all information about *.dat */
39 DatInfo::DatInfo( const KURL& url ) : m_access ( 0 )
42 m_datURL = Kita::ParseMisc::parseURL( url, refstr);
43 m_thread = Kita::Thread::getByURLNew( m_datURL );
45 /* japanese strings */
47 m_framestr1 = ParseMisc::utf8ToUnicode( KITAUTF8_FRAME1 ); /* | */
48 m_framestr2 = ParseMisc::utf8ToUnicode( KITAUTF8_FRAME2 ); /* |- */
49 m_framestr3 = ParseMisc::utf8ToUnicode( KITAUTF8_FRAME3 ); /* L */
61 /* Usually, don't call this. */ /* public */
64 QMutexLocker locker( &m_mutex );
70 void DatInfo::initPrivate()
73 /* stop & delete dat loader */
78 m_rawData = QString::null;
79 m_subject = QString::null;
83 m_lastLine = QString::null;
84 m_kokoyonNum = KitaThreadInfo::readNum( m_datURL.prettyURL() );
88 increaseResDatVec( RESDAT_DEFAULTSIZE );
93 /* create dat loader */
94 m_access = new Kita::Access( m_datURL );
96 connect( m_access, SIGNAL( receiveData( const QString& ) ),
97 SLOT( slotReceiveData( const QString& ) ) );
98 connect( m_access, SIGNAL( finishLoad() ),SLOT( slotFinishLoad() ) );
100 /* get dat from cahce & copy it to buffer */
101 copyRawDataToBuffer(m_access->getcache());
102 copyRawDataToBuffer(QString::null); /* copy the last line */
107 void DatInfo::resetResDat(RESDAT& resdat)
111 resdat.parsed = FALSE;
112 resdat.broken = FALSE;
113 resdat.setAnclist = FALSE;
114 resdat.anclist.clear();
115 resdat.checkAbone = FALSE;
116 resdat.abone = FALSE;
117 resdat.marked = FALSE;
122 void DatInfo::increaseResDatVec( int delta )
124 int size = m_resDatVec.size();
127 m_resDatVec.resize( size + delta, resdat);
131 /* delete dat loader */ /* private */
132 void DatInfo::deleteAccessJob()
142 /* copy raw lines to buffer */
145 You need to call this function last
146 with rawData = QString::null in order
147 to copy the last line to buffer. */ /* private */
148 void DatInfo::copyRawDataToBuffer(const QString& rawData)
150 QStringList linelist;
151 int basenum = m_readNum + 1;
154 if ( Kita::boardType( m_datURL.url() ) == Board_MachiBBS && m_lastLine == QString::null && m_access->responseCode() == 200 )
160 bool endIsLF = FALSE;
161 if ( rawData != QString::null )
164 if(rawData.at(rawData.length()-1) == '\n') endIsLF = TRUE;
166 /* split the raw data */
167 m_lastLine += rawData;
168 linelist = QStringList::split( "\n", m_lastLine );
170 /* backup the last line */
171 QStringList::iterator lastit = linelist.end();
173 if( lastit != linelist.end() )
175 m_lastLine = (*lastit);
176 linelist.remove(lastit);
178 /* If the last char of rawData is LF, then
179 add LF to m_lastLine, because LF was
180 removed by above QStringList::split(). */
181 if(endIsLF) m_lastLine += '\n';
183 else m_lastLine = QString::null;
187 { /* If rawData == null, then copy the last line */
189 if ( m_lastLine != QString::null
190 && m_lastLine.contains( "<>" ) == 4
191 && m_lastLine.at(m_lastLine.length()-1) == '\n' )
194 m_lastLine.truncate(m_lastLine.length()-1);/* remove LF */
195 linelist += m_lastLine;
196 m_lastLine = QString::null;
200 /* copy lines to buffer */
201 for ( QStringList::iterator it = linelist.begin();
202 it != linelist.end(); ++it, ++basenum )
204 if((*it) != QString::null)
206 QString line = ParseMisc::qcpToUnicode((*it));
207 copyOneLineToResDat(line,basenum);
211 /* update thread info */
212 if ( !m_thread && m_readNum ) {
213 m_thread = Kita::Thread::getByURL( m_datURL.prettyURL() );
216 if( m_thread->resNum() < m_readNum ) m_thread->setResNum( m_readNum );
217 KitaThreadInfo::setReadNum( m_datURL.prettyURL(), m_readNum );
223 /* copy one line to resdat. */
224 /* This private function is called in
225 copyRawDataToBuffer. */ /* private */
226 bool DatInfo::copyOneLineToResDat( const QString& line, int num )
229 if ( num <= 0 ) return FALSE;
230 if ( line == QString::null ) return FALSE;
232 /* If resdat vector is short, then resize the vector. */
233 while( (int) m_resDatVec.size() <= num ) increaseResDatVec( RESDAT_DELTA );
235 /* reset and set new data */
236 RESDAT& resdat = m_resDatVec[ num ];
240 resdat.linestr = line;
241 if(m_readNum < num) m_readNum = num;
242 m_rawData += line + '\n';
244 if(num == 1) parseDat ( num ); /* to get subject */
246 /* is this dat file broken ? */
247 if ( line.contains( "<>" ) != 4 )
249 resdat.broken = TRUE;
259 const KURL& DatInfo::url()
261 QMutexLocker locker( &m_mutex );
268 /*--------------------------------------*/
269 /* cache handling functions */
273 /* When Kita::Access received new data,
274 slotReceiveData is called. */
276 /* When Kita::Access fineshed loading,
277 slotFinishLoad is called, and
278 DatInfo emits the finishLoad signal to the parent object */ /* public */
279 bool DatInfo::updateCache(const QObject* parent)
281 QMutexLocker locker( &m_mutex );
282 if ( m_access == NULL ) return FALSE;
283 if ( m_nowLoading ) return FALSE;
286 m_lock++; /* By locking, DatManager can't delete this while loading. */
288 connect( this, SIGNAL( receiveData() ),
289 parent,SLOT( slotReceiveData() ) );
291 connect( this, SIGNAL( finishLoad() ),
292 parent,SLOT( slotFinishLoad() ) );
294 m_access->getupdate();
300 /* slot called when Kita::Access
301 received new data */ /* private slot */
302 void DatInfo::slotReceiveData(const QString& newLine)
305 int rescode = m_access->responseCode();
307 if(rescode != 200 && rescode != 206) return;
309 copyRawDataToBuffer(newLine);
315 /* slot called when Kita::Access
316 finished loading new dat */ /* private slot */
317 void DatInfo::slotFinishLoad()
320 /* copy the last line */
321 copyRawDataToBuffer(QString::null);
323 /* finish loading session & emit signal to the parent object */
324 m_nowLoading = FALSE;
327 /* disconnect signals */
328 disconnect( SIGNAL( receiveData() ));
329 disconnect( SIGNAL( finishLoad() ) );
336 int DatInfo::getResponseCode()
338 QMutexLocker locker( &m_mutex );
339 if ( m_access == NULL ) return 0;
341 return m_access->responseCode();
346 int DatInfo::getServerTime()
348 QMutexLocker locker( &m_mutex );
349 if ( m_access == NULL ) return 0;
351 return m_access->serverTime();
356 bool DatInfo::deleteCache()
358 QMutexLocker locker( &m_mutex );
359 if ( m_access == NULL ) return FALSE;
360 if ( m_nowLoading ) return FALSE;
363 if( m_thread ) ret = Kita::Access::deleteLog( m_thread );
364 KitaThreadInfo::removeThreadInfo( m_datURL.prettyURL() );
365 if(ret) initPrivate();
372 bool DatInfo::isLoadingNow()
375 QMutexLocker locker( &m_mutex );
383 void DatInfo::stopLoading()
386 /* Don't lock the mutex here !!!
387 It will cause deadlock , because
388 Kita::Access::stopJob() calls KitaThreadView::slotFinishLoad() back,
389 then slotFinishLoad calls another functions in DatInfo. */
390 if ( m_access == NULL ) return;
391 if (! m_nowLoading ) return;
399 /*---------------------------------------------------*/
400 /* locking , unlocking functions */
402 /* If m_lock is not 0, DatManager can't delete this. */
403 /* Don't forget to call unlock() after locking this. */
405 /* They are public */
409 QMutexLocker locker( &m_mutex );
414 void DatInfo::unlock()
416 QMutexLocker locker( &m_mutex );
421 int DatInfo::isLocked()
423 QMutexLocker locker( &m_mutex );
429 /*------------------------------------------------------*/
430 /* get subject, linedata, id, body, name, HTML, etc. */
432 /* They are public */
434 const QString& DatInfo::getSubject()
436 QMutexLocker locker( &m_mutex );
441 const QString& DatInfo::getRawDat()
443 QMutexLocker locker( &m_mutex );
448 const QString& DatInfo::getDat( int num )
450 QMutexLocker locker( &m_mutex );
452 if ( num <= 0 || (int) m_resDatVec.size() <= num ) return QString::null;
453 if ( ! m_resDatVec[ num ].set ) return QString::null;
455 return m_resDatVec[ num ].linestr;
458 const QString& DatInfo::getId( int num )
460 QMutexLocker locker( &m_mutex );
461 if(!parseDat(num)) return QString::null;
463 return m_resDatVec[ num ].id;
466 const QString& DatInfo::getBody( int num )
468 QMutexLocker locker( &m_mutex );
469 if(!parseDat(num)) return QString::null;
471 return m_resDatVec[ num ].body;
474 const QString& DatInfo::getName( int num )
476 QMutexLocker locker( &m_mutex );
477 if(!parseDat(num)) return QString::null;
479 return m_resDatVec[ num ].name;
482 /* plain (parsed) strings of name */
483 QString DatInfo::getPlainName( int num )
485 QMutexLocker locker( &m_mutex );
486 if(!parseDat(num)) return QString::null;
488 return m_resDatVec[ num ].parsedName;
492 /* plain (parsed) strings of body */
493 QString DatInfo::getPlainBody(int num)
495 QMutexLocker locker( &m_mutex );
496 if(!parseDat(num)) return QString::null;
499 QString line = m_resDatVec[ num ].body;
501 ParseMisc::parseBODYdatText(PARSEMODE_TEXT,line,bodytext);
507 /* plain (parsed) strings of title */
508 QString DatInfo::getPlainTitle(int num)
510 QMutexLocker locker( &m_mutex );
511 if(!parseDat(num)) return QString::null;
513 bool showAddr = KitaConfig::showMailAddress();
515 ParseMisc::parseTITLEdatText(PARSEMODE_TEXT,num,showAddr,m_resDatVec[ num ],titletext);
521 /*-----------------------------------------*/
525 /* Note that this function checks Abone internally. */ /* public */
526 QString DatInfo::getHtml(int startnum, int endnum)
528 QMutexLocker locker( &m_mutex );
530 QString retstr = QString::null;
531 bool showAddr = KitaConfig::showMailAddress();
533 for(int num = startnum; num <= endnum; num++)
536 if(!parseDat(num)) continue;
537 if(checkAbonePrivate(num)) retstr += aboneHTML( num );
538 else if(m_resDatVec[ num ].broken) retstr += brokenHTML( num );
539 else retstr += ParseMisc::ResDatToHtml(m_resDatVec[ num ], num, showAddr );
546 /* return HTML strings that have ID = strid. */
547 /* Note that this function checks Abone internally. */ /* public */
548 QString DatInfo::getHtmlByID(const QString& strid, int &count )
550 QMutexLocker locker( &m_mutex );
552 QString retstr = QString::null;
553 bool showAddr = KitaConfig::showMailAddress();
557 for ( int i = 1; i <= m_readNum; i++ )
560 if(!parseDat(i)) continue;
562 if(m_resDatVec[i].id == strid)
565 if(checkAbonePrivate(i)) retstr += aboneHTML(i);
566 else if(m_resDatVec[ i ].broken) retstr += brokenHTML(i);
567 else retstr += ParseMisc::ResDatToHtml(m_resDatVec[i], i, showAddr);
576 QString DatInfo::aboneHTML(int num)
579 QString tmpstr = QString( "<dl><dt>" );
580 tmpstr += QString().setNum( num ) + " " + ParseMisc::utf8ToUnicode( KITAUTF8_ABONE );
581 tmpstr += "</dt><dd>";
582 tmpstr += ParseMisc::utf8ToUnicode( KITAUTF8_ABONE );;
583 tmpstr += "<br/><br/></dd></dl>";
590 QString DatInfo::brokenHTML(int num)
593 QString tmpstr = QString( "<dl><dt>" );
594 tmpstr += QString().setNum( num ) + " " + ParseMisc::utf8ToUnicode( KITAUTF8_NAME );
595 tmpstr += "</dt><dd>";
596 tmpstr += ParseMisc::utf8ToUnicode( KITAUTF8_KOWARE );;
597 tmpstr += "<br/><br/></dd></dl>";
603 /*-------------------------------*/
604 /* Get HTML document of res tree.*/
605 /* For example, when rootnum = 1,
611 |-->>20, and return count = 3. */
613 /* Note that this function checks Abone internally. */ /* public */
614 QString DatInfo::getTreeByRes(const int rootnum, int& count)
616 QMutexLocker locker( &m_mutex );
617 return getTreeByResPrivate(rootnum,FALSE,count);
620 /*---------------------------------------*/
621 /* Get HTML document of reverse res tree.*/
622 /* For example, when rootnum = 10,
628 |-->>6, and returns count = 3. */
630 /* Note that this function checks Abone internally. */ /* public */
631 QString DatInfo::getTreeByResReverse(const int rootnum, int& count)
633 QMutexLocker locker( &m_mutex );
634 return getTreeByResPrivate(rootnum,TRUE,count);
639 QString DatInfo::getTreeByResPrivate(
641 bool reverse, /* reverse search */
645 QString tmp = QString().setNum( rootnum );
646 QString retstr = "<a href=\"#" + tmp + "\">>>" + tmp + "</a><br>";
648 retstr += getTreeByResCore(rootnum,reverse,count,"");
654 QString DatInfo::getTreeByResCore(
656 bool reverse, /* reverse search */
657 int& count, QString prestr)
659 if(!parseDat(rootnum)) return QString::null;
660 if( checkAbonePrivate(rootnum) ) return QString::null;
662 QString retstr = QString::null ;
664 QStringList strlists;
669 /* collect responses that have anchor to rootnum */
670 for ( int i = rootnum+1; i <= m_readNum; i++ )
672 if(checkAbonePrivate( i ) ) continue;
673 if(checkRes(i,rootnum))
676 strlists += QString().setNum( i );
682 { /* collect responses for which rootnum has anchors */
685 AncList& anclist = m_resDatVec[ rootnum ].anclist;
686 for ( AncList::iterator it = anclist.begin(); it != anclist.end(); ++it )
688 for( int i = (*it).from; i <= QMIN(rootnum-1,(*it).to) ; i++)
690 if(checkAbonePrivate(i) ) continue;
692 strlists += QString().setNum( i );
697 /* make HTML document */
701 for ( QStringList::iterator it = strlists.begin(); it != strlists.end(); ++it )
704 if((*it) == strlists.last()) tmpstr = m_framestr3; /* 'L' */
705 else tmpstr = m_framestr2; /* '|-' */
707 retstr += prestr + tmpstr + "<a href=\"#" + (*it) + "\">>>" + (*it) + "</a><br>";
709 /* call myself recursively */
712 if((*it) == strlists.last()) tmpstr += m_spacestr + m_spacestr + m_spacestr; /* " " */
713 else tmpstr += m_framestr1 + m_spacestr; /* "| " */
714 retstr += getTreeByResCore((*it).toInt(),reverse,tmpnum,tmpstr);
724 /*----------------------------------------------*/
725 /* Check if No.num has anchors to No.target */
726 /* For exsample, if target = 4, and No.num have
727 an anchor >>4, or >>2-6, etc.,
728 then return TRUE. */ /* private */
729 bool DatInfo::checkRes(const int num, const int target )
731 if(! parseDat(num)) return FALSE;
734 AncList& anclist = m_resDatVec[ num ].anclist;
736 for ( AncList::iterator it = anclist.begin(); it != anclist.end(); ++it )
738 if ( target >= (*it).from && target <= (*it).to ) return TRUE;
746 /*--------------------------*/
747 /* set AncList */ /* private */
749 /* This function sets anchor list.
750 For example, a res has anchors >>2-3 and >>4, then
757 void DatInfo::setAncList(int num)
760 if(! parseDat(num)) return;
761 if( m_resDatVec[ num ].setAnclist ) return;
763 m_resDatVec[ num ].setAnclist = TRUE;
770 AncList& anclist = m_resDatVec[ num ].anclist;
773 QString line = m_resDatVec[ num ].body;
775 /* remove HTML tags */
776 QRegExp rex( "<[^>]*>" );
779 const QChar *chpt = line.unicode();
781 unsigned int length = line.length();
784 for ( i = 0 ; i < length ; i++ )
787 if( chpt[ i ].unicode() == UTF16_BRACKET || /* > */
788 (chpt[ i] == '&' && chpt[ i+1] == 'g' && chpt[ i+2] == 't' && chpt[ i+3] == ';') /* ">" */
791 while(ParseMisc::parseResAnchor(chpt+i,length-i,linkstr,refNum,pos))
793 if(refNum[1] < refNum[0]) refNum[1] = refNum[0];
794 anctmp.from = refNum[0];
795 anctmp.to = refNum[1];
805 line = m_resDatVec[ num ].name;
806 chpt = line.unicode();
808 length = line.length();
810 while(ParseMisc::parseResAnchor(chpt+i,length-i,linkstr,refNum,pos))
812 if(refNum[1] < refNum[0]) refNum[1] = refNum[0];
813 anctmp.from = refNum[0];
814 anctmp.to = refNum[1];
822 /*----------------------------------*/
823 /* Get DOM element */
825 /* This function returns the element
828 This function checks Abone
829 internally. So, if the res is
830 aboned,the output is "abone" node.
832 If the res is broken, the output
836 bool DatInfo::getDomElement(
840 DOM::HTMLDocument& hdoc, /* root of HTML document */
843 DOM::Element& retelm)
846 QMutexLocker locker( &m_mutex );
847 if(!parseDat(num)) return FALSE;
850 QString status = "normal";
851 DOM::Element bodynode, titlenode, tmpelm;
852 DOM::HTMLTableElement table;
853 bool showAddr = KitaConfig::showMailAddress();
854 bool showAA = KitaConfig::showAA();
855 bool abone = checkAbonePrivate( num );
857 RESDAT& resdat = m_resDatVec[ num ];
859 if ( !resdat.broken && !abone )
863 table = hdoc.createElement( "TABLE" );
865 tmpelm = table.insertRow( 0 );
866 ParseMisc::parseTITLEdat(PARSEMODE_DOM,hdoc,num,showAddr,resdat,tmpelm,tmpstr);
869 bodynode = hdoc.createElement( "DIV" );
871 /* put the span node at the head of each line */
875 tmpelm = bodynode.appendChild( hdoc.createElement( "SPAN" ) );
877 tmpelm.setAttribute( "style", "color: white" );
878 tmpelm.appendChild( hdoc.createTextNode( "" ) );
882 ParseMisc::parseBODYdat(PARSEMODE_DOM,resdat.body,hdoc,showAA,bodynode,tmpstr);
887 { /* abone or data is broken */
894 namestr = ParseMisc::utf8ToUnicode( KITAUTF8_ABONE );
895 bodystr = ParseMisc::utf8ToUnicode( KITAUTF8_ABONE );
899 { /* "broken" node */
900 namestr = ParseMisc::utf8ToUnicode( KITAUTF8_NAME );
901 bodystr = ParseMisc::utf8ToUnicode( KITAUTF8_KOWARE );
906 table = hdoc.createElement( "TABLE" );
908 tmpelm = table.insertRow( 0 );
909 tmpelm = tmpelm.appendChild( hdoc.createElement( "TD" ) );
910 tmpelm.appendChild( hdoc.createTextNode(
911 QString().setNum( num ) + " " + namestr ) );
914 bodynode = hdoc.createElement( "DIV" );
915 tmpelm = bodynode.appendChild( hdoc.createElement( "SPAN" ) );
917 tmpelm.setAttribute( "style", "color: red" );
918 tmpelm.appendChild( hdoc.createTextNode( bodystr ) );
924 /*-----------------------------*/
926 retelm = hdoc.createElement( "DIV" );
928 retelm.setAttribute( "kita_type", "res" );
929 retelm.setAttribute( "kita_status", status );
930 retelm.setAttribute( "id", QString().setNum( num ) );
931 retelm.setAttribute( "kita_rname", resdat.name );
932 retelm.setAttribute( "kita_rid", resdat.id );
934 titlenode.setAttribute( "class", "res_title" );
935 bodynode.setAttribute( "class", "res_body" );
936 retelm.appendChild( titlenode );
937 retelm.appendChild( bodynode );
945 /*-----------------------*/
946 /* several information */
949 int DatInfo::getReadNum()
951 QMutexLocker locker( &m_mutex );
957 /* return number of responses that have ID = strid. */
958 /* Note that this function checks Abone internally. */ /* public */
959 int DatInfo::getNumByID( const QString& strid )
961 QMutexLocker locker( &m_mutex );
965 for ( int i = 1; i <= m_readNum; i++ )
968 if( !parseDat(i) ) continue;
969 if( checkAbonePrivate( i ) ) continue;
971 if ( m_resDatVec[i].id == strid ) count++;
978 int DatInfo::getKokoyonNum()
980 QMutexLocker locker( &m_mutex );
982 return QMIN(m_kokoyonNum, m_readNum);
986 void DatInfo::setKokoyonNum(int num)
988 QMutexLocker locker( &m_mutex );
990 num = QMIN(num, m_readNum);
993 KitaThreadInfo::setReadNum( m_datURL.prettyURL(), num );
997 int DatInfo::getDatSize()
999 QMutexLocker locker( &m_mutex );
1001 return m_rawData.length();
1006 bool DatInfo::isResValid(int num)
1008 QMutexLocker locker( &m_mutex );
1010 return parseDat(num);
1014 bool DatInfo::isBroken()
1016 QMutexLocker locker( &m_mutex );
1022 bool DatInfo::isResBroken(int num)
1024 QMutexLocker locker( &m_mutex );
1025 if(!parseDat(num)) return FALSE;
1027 return m_resDatVec[ num ].broken;
1030 /* ID = strid ? */ /* public */
1031 bool DatInfo::checkID(const QString& strid, int num )
1033 QMutexLocker locker( &m_mutex );
1034 if(!parseDat(num)) return FALSE;
1036 if(m_resDatVec[num].id == strid) return TRUE;
1042 /* Are keywords included ? */ /* public */
1043 bool DatInfo::checkWord(QStringList& stlist, /* list of keywords */
1045 bool checkOR /* AND or OR search */
1048 QMutexLocker locker( &m_mutex );
1049 if(!parseDat(num)) return FALSE;
1051 QString str_text = m_resDatVec[ num ].body;
1053 for ( QStringList::iterator it = stlist.begin(); it != stlist.end(); ++it )
1056 QRegExp regexp( (*it) );
1057 regexp.setCaseSensitive( FALSE );
1061 if ( str_text.find( regexp, 0 ) != -1 )
1068 if ( str_text.find( regexp, 0 ) == -1 ) return FALSE;
1072 if ( checkOR ) return FALSE;
1078 bool DatInfo::isMarked( int num )
1080 QMutexLocker locker( &m_mutex );
1082 return m_resDatVec[ num ].marked;
1087 void DatInfo::setMark( int num, bool mark )
1089 QMutexLocker locker( &m_mutex );
1091 m_resDatVec[ num ].marked = mark;
1097 /*--------------------------------*/
1098 /* abone functions */
1101 /*-----------------------*/
1104 /* call this when config
1105 of abone changed. */ /* public */
1107 void DatInfo::resetAbone()
1109 QMutexLocker locker( &m_mutex );
1111 return resetAbonePrivate();
1115 void DatInfo::resetAbonePrivate()
1117 for ( int i = 1; i < (int) m_resDatVec.size(); i++ ) m_resDatVec[ i ].checkAbone = FALSE;
1119 m_aboneByID = ( !KitaConfig::aboneIDList().empty() );
1120 m_aboneByName = ( !KitaConfig::aboneNameList().empty() );
1121 m_aboneByBody = ( !KitaConfig::aboneWordList().empty() );
1122 m_aboneByRes = m_aboneByID | m_aboneByName | m_aboneByBody;
1127 /* check abone */ /* public */
1129 bool DatInfo::checkAbone(int num)
1131 QMutexLocker locker( &m_mutex );
1133 return checkAbonePrivate(num);
1138 bool DatInfo::checkAbonePrivate(int num)
1140 if(!parseDat(num)) return FALSE;
1142 if ( m_resDatVec[ num ].checkAbone ) return m_resDatVec[ num ].abone;
1144 m_resDatVec[ num ].checkAbone = TRUE;
1145 bool checktmp = FALSE;
1148 checktmp = checkAboneCore(m_resDatVec[ num ].id,KitaConfig::aboneIDList());
1150 if(!checktmp && m_aboneByName )
1151 checktmp = checkAboneCore(m_resDatVec[ num ].parsedName,KitaConfig::aboneNameList());
1153 if(!checktmp && m_aboneByBody )
1154 checktmp = checkAboneCore(m_resDatVec[ num ].body,KitaConfig::aboneWordList());
1156 if(!checktmp && m_aboneByRes )
1159 AncList& anclist = m_resDatVec[ num ].anclist;
1161 for ( AncList::iterator it = anclist.begin();
1162 it != anclist.end() && !checktmp ; ++it )
1165 int refNum = (*it).from;
1166 int refNum2 = (*it).to;
1168 /* I don't want to enter loop... */
1169 if ( refNum >= num ) continue;
1170 if ( refNum2 >= num ) refNum2 = num - 1;
1172 for (int i = refNum; i <= refNum2; i++ )
1174 if (checkAbonePrivate(i))
1183 m_resDatVec[ num ].abone = checktmp;
1185 return m_resDatVec[ num ].abone;
1189 bool DatInfo::checkAboneCore(const QString& str, QStringList& strlist)
1195 for ( QStringList::iterator it = strlist.begin();
1196 it != strlist.end(); ++it )
1198 i = str.find( ( *it ) );
1211 /*---------------------------------------*/
1212 /* simple parsing function */
1214 /* This function parses struct RESDAT by
1215 ParseMisc::parseResDat. In short, this
1216 splits the raw date into name, id,
1217 date, and bodytext, etc.
1219 Note that this function keeps data as
1220 the raw data. So, you need to parse them
1221 later by getPlainBody, getHtml,
1224 bool DatInfo::parseDat( int num )
1227 if ( num <= 0 || (int) m_resDatVec.size() <= num ) return FALSE;
1228 if( m_resDatVec[ num ].parsed ) return TRUE;
1231 if( !ParseMisc::parseResDat( m_resDatVec[ num ], tmpstr ) ) return FALSE;
1234 if ( m_subject == QString::null && tmpstr != QString::null )
1237 Kita::Thread::setName( m_datURL.prettyURL(), m_subject );