#include <kio/slaveconfig.h>
#include <kio/jobclasses.h>
#include <kio/scheduler.h>
-#include <kmessagebox.h>
-#include <krun.h>
#include <khtml_part.h>
#include <khtmlview.h>
: KitaThreadViewBase(parent, name)
, m_parent( parent )
, m_currentJob( 0 )
- , m_labelMaxLength( 100 )
+ , m_labelMaxLength( 60 )
{
threadPart = new KHTMLPart(threadFrame);
QHBoxLayout* aLayout = new QHBoxLayout(threadFrame);
+
+ { // We must use KHTMLView::setFont(), don't we?
+ QFont font = threadPart->view()->font();
+ // Use Mona font with a native scale.
+#if 0
+ font.setRawMode( true );
+ font.setRawName("-mona-gothic-medium-r-normal--12-110-75-75-p-120-jisx0208.1990-0");
+#elif 0
+ font.setFamily("Mona [gothic]");
+ font.setPixelSize( 12 );
+#else
threadPart->setStandardFont("Gothic [Mona]");
- threadPart->setZoomFactor(120); // 12px;
+ threadPart->setZoomFactor(120); // 12px;
+#endif
+ threadPart->view()->setFont( font );
+#if 0 // provides you with mona font info.
+ QString info;
+ info += view()->font().family();
+ info +="\n";
+ info += QString("size: %1pt %2px\n").arg( view()->font().pointSizeFloat() ).arg( view()->font().pixelSize() );
+ QMessageBox::information( 0, "", info );
+#endif
+ }
{
SearchButton->setPixmap( SmallIcon("find") );
KParts::BrowserExtension * ext = threadPart->browserExtension();
connect( ext, SIGNAL( openURLRequest(const KURL&, const KParts::URLArgs&) ),
SIGNAL( openURLRequest(const KURL&, const KParts::URLArgs&) ) );
-// connect( this, SIGNAL(openURLRequest(const KURL&, const KParts::URLArgs&)),
-//SLOT(slotOpenURLRequest(const KURL&)));
- connect( ext, SIGNAL( createNewWindow (const KURL &, const KParts::URLArgs&) ),
- SIGNAL( createNewWindow (const KURL &, const KParts::URLArgs&) ) );
+ connect( ext, SIGNAL( createNewWindow (const KURL&, const KParts::URLArgs&) ),
+ SIGNAL( createNewWindow (const KURL&, const KParts::URLArgs&) ) );
connect( ext, SIGNAL( setLocationBarURL(const QString &) ),
SIGNAL( setLocationBarURL(const QString &) ) );
connect( ext, SIGNAL( enableAction(const char*, bool) ),
void KitaThreadView::slotShowThread(const KURL& _datURL, const KURL& _boardURL, const QString& boardName)
{
+ { //reset member variables associated with a thread.
+ m_prevquery = "";
+ m_nextHit = 0;
+ m_hitcount = 0;
+ m_writeResult = "";
+ m_threadData = "";
+ m_subject = "";
+ m_contents = "";
+ }
+
if ( _datURL.protocol() != "k2ch" ) {
KIO::SlaveConfig::self()->setConfigData("http", _datURL.host() ,
"UserAgent", "Monazilla/1.00 (test)");
}
- m_datURL = _datURL; // ex. http://pc.2ch.net/linux/dat/XXXXXXXXXX.dat
- m_boardURL = _boardURL; // ex. http://pc.2ch.net/linux/
- m_boardID = m_boardURL.fileName(); // ex. linux
- m_datName = QStringList::split(".", m_datURL.fileName())[0]; // ex. XXXXXXXXXX
- // ex. http://pc.2ch.net/test/read.cgi/linux/XXXXXXXXXX
+ m_datURL = _datURL;
+ m_boardURL = _boardURL;
+ m_boardID = m_boardURL.fileName();
+ m_datName = m_datURL.fileName().section('.', 0, 0);
m_threadURL = KURL(m_boardURL, QString("../test/read.cgi/") + QString(m_boardURL.filename()) + QString("/") + QString( m_datURL.filename().section('.',0) ) );
- m_boardName = boardName; // ex. Linux
-
+ m_boardName = boardName;
+
KIO::TransferJob* job = KIO::get(m_datURL, true, true);
m_currentJob = job;
void KitaThreadView::slotRedirection(KIO::Job *, const KURL & newURL)
{
+ printf(" Redirected to newURL: %s\n", newURL.url().latin1() );
m_datURL = newURL;
- emit datURLRedirected(newURL);
+ emit setLocationBarURL(newURL.url());
}
-void KitaThreadView::slotReceiveThreadData(KIO::Job* job, const QByteArray& data)
+void KitaThreadView::slotReceiveThreadData(KIO::Job*, const QByteArray& data)
{
QCString cstr(data.data(), data.size()+1);
m_threadData.append(cstr);
// 1970/01/01 00:00:00 GMT
QDateTime zeroTime(QDate(1970, 1, 1), QTime(0, 0));
-
serverTime = zeroTime.secsTo(QDateTime::fromString(usLocalDateStr));
}
-
+
+ int total = m_threadData.length();
+ int step = 0;
+ int divide = total / ( 100 / 5 );
+ int next = divide;
QProgressDialog * progress = new QProgressDialog( m_parent );
- progress->setTotalSteps( QString(m_threadData).length() );
- progress->setLabelText("Parse DAT file.....");
+ progress->setTotalSteps( static_cast<int>(total * 0.7) );
+ progress->setLabelText( "Parse DAT file.....");
progress->show();
- int step = 0;
while(!stream.atEnd()) {
line = stream.readLine();
QStringList list = QStringList::split("<>", line, true);
m_subject = subject;
{
QString disp( m_subject );
- disp = "[" + m_boardName + "] " + disp;
+ if ( ! m_boardName.isEmpty() ) { disp.prepend( QString("[%1]").arg(m_boardName) ); }
disp.truncate( m_labelMaxLength );
subjectLabel->setText( disp );
}
text += "<html><head>";
- (text += "<title>") += m_subject +="</title>";
text += "</head><body>";
}
text += "<dl><dt>";
text += "<br/><br/></dd></dl>"; // Using '/>' is Recommended for performance reasons.
num++;
- progress->setProgress( (step += line.length()) );
+ if( (step+=line.length()) > next ) {
+ progress->setProgress( step );
+ next += divide;
+ }
}
delete progress;
m_rescount = num - 1;
m_contents = text;
slotDisplayContents(text, (m_datURL.protocol() == "k2ch")?m_datURL:m_threadURL );
if ( HighLightButton->isOn() ) {
- slotHighLightenButton(true);
+ HighLightButton->toggle();
}
m_threadData.truncate(0);
emit showThreadCompleted();
}
-#include <qapplication.h>
-
void KitaThreadView::slotDisplayContents(const QString& input, const KURL& url)
{
threadPart->begin( url );
QSjisCodec cp932Codec;
KURL bbscgiURL = KURL(m_boardURL, "../test/bbs.cgi");
bbscgiURL.setProtocol( "http" );
- QString bbsName = m_boardURL.fileName();
- QString datName = QStringList::split(".", m_datURL.fileName())[0];
KitaWriteDialog::PostInfo info;
info.host = bbscgiURL.host();
- info.bbs = bbsName;
- info.key = datName;
+ info.bbs = m_boardID;
+ info.key = m_datName;
info.time = QString("%1").arg(serverTime);
QDialog * new_dialog = KitaWriteDialog::open( info );
connect( new_dialog, SIGNAL( postResponse(const QString&) ),
QSjisCodec codec;
QTextStream stream(m_writeResult, IO_ReadOnly);
stream.setCodec(&codec);
- QString resultHtml = stream.read();
threadPart->begin();
threadPart->write( m_writeResult.data(), m_writeResult.size() );
threadPart->end();
qDebug("#%s#", (const char *)stream.read().local8Bit());
-
- // parse 2ch_X
- QString _2ch_X;
- QRegExp regexp_2ch_X("<!-- 2ch_X:(.*) -->");
- int pos = regexp_2ch_X.search(resultHtml);
- if(pos != -1) {
- _2ch_X = regexp_2ch_X.cap(1);
- } else {
- // not match
- _2ch_X = QString::null;
- }
-
- QString title;
- QRegExp regexp_title("<title>(.*)</title>");
- pos = regexp_title.search(resultHtml);
- if(pos != -1) {
- title = regexp_title.cap(1);
- } else {
- // not match
- title = QString::null;
- }
-
- QString errMsg;
- QRegExp regexp_message("<b>([^<]*)</b>"); // Probably, the first bold-decorated text is error message.
- pos = regexp_message.search(resultHtml);
- if(pos != -1) {
- errMsg = regexp_message.cap(1);
- } else {
- // not match
- errMsg = QString::null;
- }
-
- if(_2ch_X == "true") {} else if(_2ch_X == "false") {} else if(_2ch_X == "error") {
- KMessageBox::error(0, errMsg, title);
- } else if(_2ch_X == "check") {} else if(_2ch_X == "cookie") {} else {
- // probably ok.
- }
-
- qDebug("#%s#", (const char *)resultHtml.local8Bit());
m_writeResult.truncate(0);
}
}
{
int count;
bool found = false;
+
for( count = 0; count < SearchCombo->count(); ++count ) {
if ( SearchCombo->text( count ) == SearchCombo->currentText() ) {
found = true;
void KitaThreadView::highLighten(bool yes, const QStringList &query)
{
if ( ! yes ) {
- //slotDisplayContents( m_contents );
threadPart->setUserStyleSheet( QString("") );
return;
}
- { // Use style sheet to highlighten.
- QString highlightCSS( ".highlight { color: %1; background: %2; } ");
- QColorGroup cg = threadPart->view()->colorGroup();
- //highlightCSS = highlightCSS.arg( cg.highlightedText().name() ).arg( cg.highlight().name() );
- highlightCSS = highlightCSS.arg( "yellow" ).arg( "black" );
- threadPart->setUserStyleSheet( highlightCSS );
- }
+ // Use style sheet to highlighten.
+ QString highlightCSS( ".highlight { color: %1; background: %2; } ");
+#if 0
+ QColorGroup cg = threadPart->view()->colorGroup();
+ highlightCSS = highlightCSS.arg( cg.highlightedText().name() ).arg( cg.highlight().name() );
+#else
+ highlightCSS = highlightCSS.arg( "yellow" ).arg( "black" );
+#endif
+ threadPart->setUserStyleSheet( highlightCSS );
+
if ( m_prevquery == query ) return;
m_prevquery = query;
if ( query.isEmpty() ) return;
+ slotDisplayContents( m_contents );
DOM::NodeList nodes;
m_hitcount = 0;
nodes = threadPart->document().getElementsByTagName("body");
highLightenNodes( nodes, query );
+ threadPart->setUserStyleSheet( highlightCSS );
}
QStringList KitaThreadView::lt_gt_spliter( const QString & input )
//printf(" dd %d: %s\n", count, dd.innerHTML().string().latin1() );
QStringList lt_gt_split = lt_gt_spliter( dd.innerHTML().string() );
- QStringList::const_iterator it = query.begin();
- for( ; it != query.end(); ++it )
+ QProgressDialog progress(m_parent);
+ progress.setLabelText("Searching...");
+ progress.setTotalSteps( lt_gt_split.size() );
+ progress.show();
+ int step = 0;
+ int divide = lt_gt_split.size() / ( 100 / 5 );
+ int next = divide;
+
+ //loop order not optimized. Need optim. that also needs any codes & members?
+ QStringList::iterator it_msg = lt_gt_split.begin();
+ for( ; it_msg != lt_gt_split.end(); ++it_msg )
{
- QStringList::iterator it_msg = lt_gt_split.begin();
- for( ; it_msg != lt_gt_split.end(); ++it_msg ) {
+ QStringList::const_iterator it = query.begin();
+ for( ; it != query.end(); ++it )
+ {
int pos = 0;
QString message = *it_msg;
//printf("dd %d: %s\n", count, (*it_msg).latin1() );
++m_hitcount;
}
}
+ if( ++step > next ) {
+ progress.setProgress( step );
+ next += divide;
+ }
}
dd.setInnerHTML( lt_gt_split.join("") );