From: ikemo Date: Sun, 20 Jun 2004 13:02:03 +0000 (+0000) Subject: >>915 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=d7b7a1b5f62733cbf65cf958d924df2248b61ad4;p=kita%2Fkita.git >>915 git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@1181 56b19765-1e22-0410-a548-a0f45d66c51a --- diff --git a/kita/src/kita.cpp b/kita/src/kita.cpp index 03dd808..76d08e6 100644 --- a/kita/src/kita.cpp +++ b/kita/src/kita.cpp @@ -24,6 +24,7 @@ #include "libkita/kita_misc.h" #include "libkita/kitaconfig.h" #include "libkita/signalcollection.h" +#include "libkita/parsemisc.h" #include #include @@ -625,12 +626,13 @@ void KitaMainWindow::slotOpenURLRequest( const KURL& url, const KParts::URLArgs& return; } } + KURL datURL = Kita::ParseMisc::parseURLonly( url ); + QRegExp regexp( "http://([^/]*)/([^/]*)/dat/(.*)\\.dat" ); - if ( regexp.search( url.url() ) == -1 ) { + if ( regexp.search( datURL.url() ) == -1 ) { new KRun( url ); } else { - Kita::Thread* thread = Kita::Thread::getByURL( url.url() ); - m_threadTab->showThread( thread->datURL(), true ); + m_threadTab->showThread( url.prettyURL(), true ); } } diff --git a/kita/src/kitathreadtabwidget.cpp b/kita/src/kitathreadtabwidget.cpp index f45c33f..38a4e58 100644 --- a/kita/src/kitathreadtabwidget.cpp +++ b/kita/src/kitathreadtabwidget.cpp @@ -27,6 +27,7 @@ #include "libkita/kita_misc.h" #include "libkita/parsemisc.h" #include "libkita/signalcollection.h" +#include "libkita/datmanager.h" #define MAX_TABLABEL_LEN 20 @@ -62,11 +63,18 @@ KitaThreadTabWidget::~KitaThreadTabWidget() delete m_manager; } -void KitaThreadTabWidget::showThread( const QString& datURL, bool withNewTab ) +void KitaThreadTabWidget::showThread( const QString& url, bool withNewTab ) { QString refstr; - QString urlstr = Kita::ParseMisc::parseURL(datURL,refstr).prettyURL(); - Kita::Thread * thread = Kita::Thread::getByURL( urlstr ); + KURL datURL = Kita::ParseMisc::parseURL( url, refstr); + int num = 0; + if( refstr != QString::null ){ + int i = refstr.find( "-" ); + if( i != -1 ) num = refstr.left( i ).toInt(); + else num = refstr.toInt(); + } + if( num == 0 ) num = Kita::DatManager::getKokoyonNum( datURL ); + Kita::Thread * thread = Kita::Thread::getByURL( datURL.prettyURL() ); emit sigHideSubject(); @@ -74,7 +82,7 @@ void KitaThreadTabWidget::showThread( const QString& datURL, bool withNewTab ) if ( view ) { setCurrentPage( indexOf( view ) ); if ( view->threadURL().isEmpty() ) { - view->showThread( thread ); + view->showThread( datURL, num ); } else { view->slotReloadButton(); } @@ -84,12 +92,12 @@ void KitaThreadTabWidget::showThread( const QString& datURL, bool withNewTab ) if ( newView ) { addTab( newView, getTabLabel( thread->name() ) ); connectSignals( newView ); - newView->showThread( thread ); + newView->showThread( datURL, num ); showPage( newView ); m_viewList.append( newView ); } } else { - static_cast( currentPage() ) ->showThread( thread ); + static_cast( currentPage() ) ->showThread( datURL, num ); } setTabLabel( currentPage(), QString( "%1 (%2)" ).arg( getTabLabel( thread->name() ) ).arg( thread->resNum() ) ); diff --git a/kita/src/libkita/parsemisc.cpp b/kita/src/libkita/parsemisc.cpp index 2cef1e4..f598a22 100644 --- a/kita/src/libkita/parsemisc.cpp +++ b/kita/src/libkita/parsemisc.cpp @@ -764,6 +764,8 @@ bool ParseMisc::parseResAnchor( bool ret = FALSE; int i; + + if( length == 0 ) return FALSE; linkstr = QString::null; refNum[0] = 0; diff --git a/kita/src/libkita/signalcollection.h b/kita/src/libkita/signalcollection.h index 75fefc6..ed71e46 100644 --- a/kita/src/libkita/signalcollection.h +++ b/kita/src/libkita/signalcollection.h @@ -51,7 +51,7 @@ namespace Kita void isKitaActive(); /* to : KitaHTMLPart */ - void redrawScreen( const KURL& url ); + void redrawScreen( const KURL& url, bool force ); }; } diff --git a/kita/src/part/kitadomtree.cpp b/kita/src/part/kitadomtree.cpp index 1009913..6294961 100644 --- a/kita/src/part/kitadomtree.cpp +++ b/kita/src/part/kitadomtree.cpp @@ -18,7 +18,6 @@ #include #include "kitadomtree.h" -#include "kitathreadview.h" #include "libkita/kitaconfig.h" #include "libkita/datmanager.h" #include "libkita/datinfo.h" @@ -41,18 +40,13 @@ enum{ /* public functions */ /*-------------------------------------------------------------------*/ -KitaDomTree::KitaDomTree( KitaHTMLPart* threadPart ) +KitaDomTree::KitaDomTree( const DOM::HTMLDocument& hdoc, const KURL& datURL ) { m_semap = new QSemaphore( 1 ); m_krt = new KitaRenderThread( this ); m_datInfo = NULL; - - m_threadPart = threadPart; - if ( m_threadPart != NULL ) { - m_hdoc = m_threadPart->htmlDocument(); /* == NULL */ - } - - resetAllVar(); + m_hdoc = hdoc; + parseResInit( datURL ); } @@ -73,32 +67,14 @@ KitaDomTree::~KitaDomTree() /* setup & create HTML doc. */ /* call this before parsing */ /*--------------------------*/ -void KitaDomTree::parseResInit( Kita::Thread* thread ) +void KitaDomTree::parseResInit( const KURL& datURL ) { StopParseThread(); - if ( thread ) { - m_url = thread->datURL(); - } else { - m_url = ""; - } + m_url = datURL; m_templateNum = 20; /* number of templates */ - /* style */ - QString style = QString( "style=\"font-size: %1pt; " - "font-family: %2; " - "color: %3; " - "background-color: %4; border-width: 0; \"" ) - .arg( KitaConfig::threadFont().pointSize() ) - .arg( KitaConfig::threadFont().family() ) - .arg( KitaConfig::threadColor().name() ) - .arg( KitaConfig::threadBackgroundColor().name() ); - - /* create HTML Document */ - createHTMLDocument( style ); - m_hdoc = m_threadPart->htmlDocument(); - /* create the nodes of footer, header, etc. */ createKokoyon(); m_footer = createFooter( "footer" ); @@ -108,7 +84,6 @@ void KitaDomTree::parseResInit( Kita::Thread* thread ) /* get pointer of DatInfo */ m_datInfo = Kita::DatManager::getDatInfoPointer( m_url ); - if(m_datInfo) m_datInfo->resetAbone(); resetAllVar(); } @@ -151,6 +126,7 @@ bool KitaDomTree::parseRes( int num, int ) return FALSE; } + m_resparsed[ num ] = TRUE; if ( num > m_maxNum ) { @@ -207,6 +183,42 @@ bool KitaDomTree::removeRes( int num ) return TRUE; } + + +/* redraw all */ /* public */ +void KitaDomTree::redraw( bool force ){ + + if ( ! m_datInfo ) return; + if ( m_hdoc == NULL ) return; + StopParseThread(); + + for ( int i = 1; i <= m_maxNum; i++ ){ + + if ( !m_resparsed[ i ] ) continue; + + QString oldStatus = m_res[ i ].getAttribute( "kita_status" ).string(); + bool abone = m_datInfo->checkAbone( i ); + bool broken = m_datInfo->isResBroken( i ); + + /* reparsing */ + if( force + || ( oldStatus == "normal" && ( abone || broken ) ) + || ( oldStatus == "abone" && !abone ) + || ( oldStatus == "broken" && !broken ) + ){ + + DOM::Element newNode; + m_datInfo->getDomElement( i , m_hdoc, newNode ); + if ( m_resshown[ i ] ) m_hdoc.body().replaceChild( newNode, m_res[ i ] ); + + /* I don't know how to release the instance of DOM::Element explicitly... */ + m_res[ i ] = newNode; + } + } +} + + + /*---------------------------------*/ /* parse all res in the backgound */ /*---------------------------------*/ @@ -342,6 +354,8 @@ void KitaDomTree::appendKokoyon() { if ( m_hdoc == NULL ) return ; + m_kokoyonNum = Kita::DatManager::getKokoyonNum( m_url ); + /* call setKokoyonNum to set m_kokoyonNum */ if ( m_kokoyonNum <= 0 ) return ; @@ -413,7 +427,7 @@ void KitaDomTree::removeMae100() /*------------------------------*/ /* create & append comment node */ /*------------------------------*/ -void KitaDomTree::createCommentNode( QString comment, QString idstr, +void KitaDomTree::createCommentNode( const QString& comment, const QString& idstr, int beforeBR, int afterBR, bool binsert ) @@ -445,7 +459,7 @@ void KitaDomTree::createCommentNode( QString comment, QString idstr, /* create belt node */ -void KitaDomTree::createBeltNode( QString idstr ) +void KitaDomTree::createBeltNode( const QString& idstr ) { DOM::Element rootnode; @@ -470,33 +484,6 @@ void KitaDomTree::createBeltNode( QString idstr ) -/*----------------------*/ -/* create HTML Document */ -/*----------------------*/ -void KitaDomTree::createHTMLDocument( const QString& style ) -{ - QString text; - - /* I use JavaScript for resizing images */ - text = ""; - text += ""; - text += ""; - text += ""; - text += ""; - - m_threadPart->setJScriptEnabled( true ); - m_threadPart->setJavaEnabled( false ); - - /* Use dummy URL here, and it's protocol should be "file:". - If protocol is "http:", local image files are not shown - (for security reasons ?). - */ - m_threadPart->begin( "file:/dummy.htm" ); - m_threadPart->write( text ); - m_threadPart->end(); -} /*-----------*/ @@ -511,14 +498,13 @@ void KitaDomTree::resetAllVar() } m_topNum = KITADOM_MAXRES + 2; - m_bottomNum = -1; + m_bottomNum = 0; m_maxNum = 0; m_kokoyonNum = 0; m_appendtugi100 = FALSE; m_appendmae100 = FALSE; - findTextInit(); } @@ -746,165 +732,6 @@ void KitaDomTree::createMae100() m_mae100 = rootnode; } -/*----------------------------------------------------------------*/ -/* for Search */ - - -/*-----------*/ -/* init find */ /* public */ - -void KitaDomTree::findTextInit() -{ - m_initFindText = TRUE; - m_findNode = NULL; - m_findPos = -1; -} - - -/*--------------------------------*/ -/* search */ -/* - You need to call findTextInit() - before calling this. */ /* public */ - -bool KitaDomTree::findText( const QString &str, bool reverse ) -{ - if ( m_hdoc == NULL ) return FALSE; - - static int m_line = 0; - - QRect qr; - - int cy = 0, ch = 0; - KHTMLView *view = m_threadPart->view(); - - /* init */ - if ( m_findNode.isNull() || m_initFindText ) { - - m_findNode = m_hdoc.body(); - m_line = 0; - - /* move to the last child node */ - if ( reverse ) { - while ( !m_findNode.lastChild().isNull() ) { - m_findNode = m_findNode.lastChild(); - } - } - - m_findPos = -1; - } - - if ( m_initFindText ) { - cy = view->contentsY(); - ch = view->visibleHeight(); - } - - while ( 1 ) { - - if ( m_findNode.nodeType() == DOM::Node::TEXT_NODE - || m_findNode.nodeType() == DOM::Node::CDATA_SECTION_NODE - ) { - - /* move to the initial node */ - if ( m_initFindText ) { - QRect rt = m_findNode.getRect(); - if ( !reverse && rt.top() > cy ) { - m_initFindText = 0; - } else if ( rt.bottom() < cy + ch ) { - m_initFindText = 0; - } - } else { - /* find the word in the current node */ - DOM::DOMString nodeText = m_findNode.nodeValue(); - QString str2 = nodeText.string(); - int lastpos = str2.length(); - if ( reverse && m_findPos != -1 ) { - lastpos = m_findPos; - } - QConstString cstr( str2.unicode(), lastpos ); - - if ( reverse ) { - int foo; - foo = m_findPos = -1; - while ( ( foo = cstr.string().find( str, m_findPos + 1, FALSE ) ) != -1 ) - m_findPos = foo; - } else m_findPos = cstr.string().find( str, m_findPos + 1, FALSE ); - - /* scroll & select */ - if ( m_findPos != -1 ) { - int matchLen = str.length(); - - qr = m_findNode.getRect(); - view->setContentsPos( qr.left() - 50 - , m_find_y + m_line - 100 ); - DOM::Range rg( m_findNode, m_findPos, - m_findNode, m_findPos + matchLen ); - m_threadPart->setSelection( rg ); - return TRUE; - } - } - } else if ( - m_findNode.nodeName().string() == "dt" - || m_findNode.nodeName().string() == "dd" ) { - - qr = m_findNode.getRect(); - if ( reverse ) { - m_find_y = qr.bottom(); - } else { - m_find_y = qr.top(); - } - m_line = 0; - } else if ( m_findNode.nodeName().string() == "br" ) { - DOM::Node tmpnode = m_findNode.previousSibling(); - if ( tmpnode != NULL ) { - qr = tmpnode.getRect(); - if ( reverse ) { - m_line -= qr.bottom() - qr.top(); - } else { - m_line += qr.bottom() - qr.top(); - } - } - } - - m_findPos = -1; - DOM::Node next; - - /* move to the next node */ - if ( !reverse ) { - - next = m_findNode.firstChild(); - if ( next.isNull() ) { - next = m_findNode.nextSibling(); - } - while ( !m_findNode.isNull() && next.isNull() ) { - m_findNode = m_findNode.parentNode(); - if ( !m_findNode.isNull() ) { - next = m_findNode.nextSibling(); - } - } - } else { /* revearse */ - - next = m_findNode.lastChild(); - if ( next.isNull() ) { - next = m_findNode.previousSibling(); - } - while ( !m_findNode.isNull() && next.isNull() ) { - m_findNode = m_findNode.parentNode(); - if ( !m_findNode.isNull() ) { - next = m_findNode.previousSibling(); - } - } - } - - m_findNode = next; - if ( m_findNode.isNull() ) { - m_findNode = NULL; - return FALSE; - } - } - - return FALSE; -} /*------------------------------------------------------*/ diff --git a/kita/src/part/kitadomtree.h b/kita/src/part/kitadomtree.h index cbe05cd..71996c6 100644 --- a/kita/src/part/kitadomtree.h +++ b/kita/src/part/kitadomtree.h @@ -14,9 +14,6 @@ #include #include "kitahtmlpart.h" -#include "kitahtmlview.h" -#include "libkita/thread.h" -#include "libkita/cache.h" class KURL; class QMutex; @@ -30,7 +27,6 @@ class Element; namespace Kita { - class Thread; class DatInfo; } class KitaRenderThread; @@ -70,17 +66,11 @@ class KitaDomTree QSemaphore* m_semap; KitaRenderThread* m_krt; - /* for searching */ - bool m_initFindText; - DOM::Node m_findNode; - int m_findPos; - int m_find_y; - /*-------------------------------------------------------------*/ public: - KitaDomTree( KitaHTMLPart* threadPart ); + KitaDomTree( const DOM::HTMLDocument& hdoc, const KURL& datURL ); ~KitaDomTree(); /* parsing & rendering */ @@ -90,11 +80,12 @@ public: -> (3) parseRes -> (4) appendRes */ - void parseResInit( Kita::Thread* thread ); + void parseResInit( const KURL& datURL ); void setDat( const QString& line, int num ); bool parseRes( int num, int resnum ); bool appendRes( int num, bool binsert ); bool removeRes( int num ); + void redraw( bool force ); void parseAllRes(); void StopParseThread(); @@ -128,19 +119,15 @@ public: void removeMae100(); bool isMae100Shown() { return m_appendmae100;} - void createCommentNode( QString comment, QString idstr, int beforeBR, int afterBR, bool binsert ); - void createBeltNode( QString idstr ); + void createCommentNode( const QString& comment, const QString& idstr, int beforeBR, int afterBR, bool binsert ); + void createBeltNode( const QString& idstr ); - /* for searching */ - void findTextInit(); - bool findText( const QString &str, bool reverse ); /*-------------------------------------------------------------*/ private: /* for init */ - void createHTMLDocument( const QString& style ); void resetAllVar(); /* utils */ diff --git a/kita/src/part/kitahtmlpart.cpp b/kita/src/part/kitahtmlpart.cpp index 9fa2458..9cbb8cf 100644 --- a/kita/src/part/kitahtmlpart.cpp +++ b/kita/src/part/kitahtmlpart.cpp @@ -1,5 +1,5 @@ /*************************************************************************** -* Copyright (C) 2003 by Hideki Ikemoto * +* Copyright (C) 2003 by Hideki Ikemoto , 2004 by 421 * * ikemo@users.sourceforge.jp * * * * This program is free software; you can redistribute it and/or modify * @@ -8,286 +8,1908 @@ * (at your option) any later version. * ***************************************************************************/ -#include "kitahtmlpart.h" - -#include "kitathreadview.h" -#include "kitahtmlview.h" -#include "kitadomtree.h" -#include "libkita/kitaconfig.h" - #include #include -#include -#include #include +#include +#include + +#include +#include #include #include +#include +#include + +#include "kitahtmlpart.h" +#include "kitahtmlview.h" +#include "kitadomtree.h" +#include "kitanavi.h" -#include "libkita/thread.h" -#include "libkita/access.h" +#include "libkita/kitaconfig.h" +#include "libkita/datmanager.h" +#include "libkita/parsemisc.h" #include "libkita/signalcollection.h" -enum { - ID_COPY_Link, - ID_Start_Link, - ID_Temp_Link, - ID_Koko_Link, - ID_End_Link, - ID_SAVEC_Link, - ID_Back_Link, - ID_Copy_Str, - ID_Ext_Str, - ID_Del_IMGCache, - ID_COPY_IMGCachepath, - ID_DEL_ThreadLog, - ID_Abone_Word -}; +/*-------------------------------------------*/ + + +/*-------------------------------------*/ +/* Don't forget to call setup() later. */ KitaHTMLPart::KitaHTMLPart( QWidget* parent, const char* name ) : KHTMLPart( new KitaHTMLView( this, parent, name ) ) - , m_parent( parent ) - , m_thread ( 0) { - connect( this, SIGNAL( popupMenu( const QString&, const QPoint& ) ), - SLOT( slotPopupMenu( const QString&, const QPoint& ) ) ); + m_mode = HTMLPART_MODE_KHTML; + m_popup = NULL; + m_domtree = NULL; + m_datURL = QString::null; + m_updatedKokoyon = FALSE; + + clearPart(); + createHTMLDocument(); + connectSignals(); +} + + +KitaHTMLPart::~KitaHTMLPart() +{ + clearPart(); +} + + +/* private */ +void KitaHTMLPart::clearPart(){ + + deletePopup(); + + /* delete KitaDomTree */ + if ( m_domtree ) delete m_domtree; + m_domtree = NULL; + + /* update Kokomade Yonda */ + if( m_mode == HTMLPART_MODE_MAINPART && !m_updatedKokoyon && !m_datURL.isEmpty()) { + int maxNum = Kita::DatManager::getMaxResNumber( m_datURL ); + if( maxNum ) Kita::DatManager::setKokoyonNum( m_datURL, maxNum ); + } + m_updatedKokoyon = FALSE; + + /* don't forget to unlock previous datURL here. */ + if( !m_datURL.isEmpty() ) Kita::DatManager::unlock( m_datURL ); + + m_anchorStack.clear(); + m_centerNum = 0; + findTextInit(); + + for( int i = 0; i < 1200 ; i++ ) m_check[ i ] = FALSE; +} + + + +/* public */ +bool KitaHTMLPart::setup( int mode, const KURL& url ) +{ + if( url.isEmpty() ) return FALSE; + + clearPart(); + + /* Lock datURL. Don't forget to unlock it later ! */ + m_datURL = Kita::ParseMisc::parseURLonly( url ); + Kita::DatManager::lock( m_datURL ); + + /* reset abone */ + Kita::DatManager::resetAbone( m_datURL ); + + /* create HTML Document */ + createHTMLDocument(); + + /* create DOM manager */ + m_mode = mode; + if( m_mode == HTMLPART_MODE_MAINPART || m_mode == HTMLPART_MODE_NAVI ){ + m_domtree = new KitaDomTree( htmlDocument(), m_datURL ); + } + + return TRUE; +} + + +/* private */ +void KitaHTMLPart::connectSignals(){ + + Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance(); + + + /* rendering */ + connect( this, SIGNAL( redrawScreen( const KURL&, bool ) ), signalCollection, SIGNAL( redrawScreen( const KURL&, bool ) )); + connect( signalCollection, SIGNAL( redrawScreen( const KURL&, bool ) ), SLOT( slotRedrawScreen( const KURL& , bool) )); + + /* popup */ + connect( this, SIGNAL( onURL( const QString& ) ), SLOT( slotOnURL( const QString& ) )); + connect( this, SIGNAL( isKitaActive() ), signalCollection, SIGNAL( isKitaActive() )); + + connect( view(), SIGNAL( leave() ), SLOT( slotLeave() )); + connect( view(), SIGNAL( verticalSliderReleased() ), SLOT( slotVSliderReleased() )); + connect( view(), SIGNAL( horizontalSliderReleased() ), SLOT( slotHSliderReleased() )); + + connect( signalCollection, SIGNAL( kitaIsActive() ), SLOT( slotKitaIsActive() )); + connect( signalCollection, SIGNAL( windowDeactivated() ), SLOT( slotHideChildPopup() )); + + + /* click */ connect( this, SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ), - Kita::SignalCollection::getInstance(), SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ) ); + signalCollection, SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ) ); - - m_popupMenu = new KPopupMenu( view() ); - m_domtree = NULL; - m_threadView = NULL; - begin(); - write( " " ); + /* goto anchor */ + connect( view(), SIGNAL( pushDown() ), SLOT( slotClickTugi100() )); +} + + + +/* private */ +void KitaHTMLPart::createHTMLDocument() +{ + /* style */ + QString style = QString( "style=\"font-size: %1pt; " + "font-family: %2; " + "color: %3; " + "background-color: %4; border-width: 0; \"" ) + .arg( KitaConfig::threadFont().pointSize() ) + .arg( KitaConfig::threadFont().family() ) + .arg( KitaConfig::threadColor().name() ) + .arg( KitaConfig::threadBackgroundColor().name() ); + + QString text = ""; + text += ""; + + setJScriptEnabled( false ); + setJavaEnabled( false ); + + /* Use dummy URL here, and protocol should be "file:". + If protocol is "http:", local image files are not shown + (for security reasons ?). + */ + begin( "file:/dummy.htm" ); + write( text ); end(); - show(); } -KitaHTMLPart::~KitaHTMLPart() + +/* public */ +const int KitaHTMLPart::getMode() const { return m_mode; } + + + +/*---------------------------------------------------------------*/ +/*---------------------------------------------------------------*/ +/* direct rendering functions */ + + +/*-----------------*/ +/* show responses */ + +/* !!! don't forget to call updateScreen() later !!! */ /* public */ +void KitaHTMLPart::showResponses( int startnum, int endnum ) { - if(m_popupMenu) delete m_popupMenu; + if( !m_domtree ) return; + + for ( int i = startnum ; i <= endnum; i++ ) m_domtree->appendRes( i, FALSE ); } -bool KitaHTMLPart::gotoAnchor( const QString& name ) + +/* do parsing only. */ +/* call showResponses() later */ /* public */ +void KitaHTMLPart::parseResponses( int startnum, int endnum ) { - pushCurrentPosition(); - return KHTMLPart::gotoAnchor( name ); + if( !m_domtree ) return; + + for ( int i = startnum ; i <= endnum; i++ ) m_domtree->parseRes( i, i ); } -/* setup */ -void KitaHTMLPart::setupEx( KitaThreadView* threadView, KitaDomTree* domtree, - Kita::Thread* thread ) +/*------------------------------------------------*/ +/* Show all responses ,header, footer, and etc, + if these are not shown. */ + +/* note that updateScreen() is called internally. */ +/* So, you need not call it later. */ /* public slot */ +void KitaHTMLPart::showAll() { - m_threadView = threadView; - m_domtree = domtree; - m_thread = thread; - m_anchorStack.clear(); + if( !m_domtree ) return; + + int top = m_domtree->getTopResNumber(); + int bottom = m_domtree->getBottomResNumber(); + int totalNum = Kita::DatManager::getMaxResNumber( m_datURL ); + if ( top != 1 || bottom != totalNum ) { + showResponses( 1, totalNum ); + updateScreen( TRUE, TRUE ); + } } -void KitaHTMLPart::pushCurrentPosition() +/*------------------------*/ +/* insert belt node */ + +/* !!! don't forget to call updateScreen() later !!! */ /* public */ +void KitaHTMLPart::insertBeltNode( const QString& idstr ) { - QString anchor, ancundermouse; - DOM::Node node; + if( !m_domtree ) return; - /* find the current node */ - node = nodeUnderMouse(); - while ( node != NULL && node.nodeName().string() != "div" ) - node = node.parentNode(); - if ( node == NULL ) return ; - anchor = static_cast( node ).getAttribute( "id" ).string(); + m_domtree->createBeltNode( idstr ); +} - m_anchorStack += anchor; + +/*--------------------------*/ +/* insert header node */ + +/* !!! don't forget to call updateScreen() later !!! */ /* public */ +void KitaHTMLPart::insertHeaderNode( const QString& str ) +{ + if( !m_domtree ) return; + + m_domtree->createCommentNode( str, "header", 0, 2, TRUE ); } -/* jump to kokomade yonda */ -void KitaHTMLPart::gotoKokoyon() +/*--------------------------*/ +/* insert footer node */ + +/* !!! don't forget to call updateScreen() later !!! */ /* public */ +void KitaHTMLPart::insertFooterNode( const QString& str ) { - if(!m_domtree) return; + if( !m_domtree ) return; + + m_domtree->createCommentNode( str, "footer", 0, 0, FALSE ); +} + - int num = m_domtree->getKokoyonNum() - 1; - while ( num > 0 ) { - if ( m_domtree->isResShown( num ) ) break; - num--; +/*-------------------*/ +/* update screen */ /* public */ +void KitaHTMLPart::updateScreen( bool showHeaderEtc, bool clock ) +{ + if( !m_domtree ) return; + + /* show clock cursor */ + if( clock ){ + QCursor qc; qc.setShape( Qt::WaitCursor ); + QApplication::setOverrideCursor( qc ); } - KHTMLPart::gotoAnchor( QString().setNum( num ) ); -} + /* show header, footer, and kokomadeyonda, etc. */ + if( showHeaderEtc ){ + + int maxNum = Kita::DatManager::getMaxResNumber( m_datURL); + m_domtree->appendMae100(); + m_domtree->appendTugi100(); + m_domtree->appendKokoyon(); + m_domtree->appendFooter( maxNum ); + } + /*----------------------------*/ + + /* update display */ + htmlDocument().applyChanges(); + view()->layout(); + view()->setVScrollBarMode( QScrollView::AlwaysOn ); + view()->setFocus(); -/*-------------------------------------------------------------------*/ + if(clock) QApplication::restoreOverrideCursor(); +} -/* public slots */ -bool KitaHTMLPart::gobackAnchor() +/* public */ +void KitaHTMLPart::setInnerHTML( const QString& innerHTML ) { - QString anchor; + createHTMLDocument(); + htmlDocument().body().setInnerHTML( innerHTML ); +} - if ( m_anchorStack.empty() ) return FALSE; - anchor = m_anchorStack.last(); - m_anchorStack.pop_back(); - return KHTMLPart::gotoAnchor( anchor ); +/* redraw screen */ +/* This slot is connected to signalCollection. */ /* public slot */ +void KitaHTMLPart::slotRedrawScreen( const KURL& datURL, bool force ){ + + if( m_domtree == NULL ) return; + if( m_datURL != datURL ) return; + + m_domtree->redraw( force ); } -/*--------------------------------------------------*/ -/* private slot */ +/*---------------------------------------------------------------*/ +/*---------------------------------------------------------------*/ +/* cache functions */ -/* show popup menu */ -void KitaHTMLPart::slotPopupMenu( const QString& url, const QPoint& point ) -{ - if(!m_threadView) return; - if(!m_domtree) return; + +/*----------------------------------*/ +/* load thread from cache & show it */ /* public */ + +/* top = centerNum - preShowNum + bottom = centerNum + afterShowNum + maxNum = ita::DatManager::getMaxResNumber + + No.1 <- show -> No.20 <- not show -> No.(top) <- show -> No.(bottom) <- not show -> No.(maxNum) */ + +bool KitaHTMLPart::load( int centerNum ){ - QString str; - DOM::Node node = nodeUnderMouse(); + /* config */ + + const int preShowNum = 50; + const int afterShowNum = KitaConfig::afterShowNum(); + + /*--------------------------------*/ + m_centerNum = centerNum; + + if( m_mode != HTMLPART_MODE_MAINPART ) return FALSE; + if( !m_domtree ) return FALSE; + if( Kita::DatManager::getMaxResNumber( m_datURL ) == 0 ) return FALSE; + + m_domtree->appendTemplate(); + showResponses( m_centerNum - preShowNum, m_centerNum + afterShowNum ); + updateScreen( TRUE , FALSE ); + gotoAnchor( QString().setNum( m_centerNum ), FALSE ); + view()->setFocus(); + + return TRUE; +} + + + +/*----------------------------*/ +/* start reloading */ - m_popupMenu->clear(); +/* see also slotReceiveData() + and slotFinishLoad(). */ /* public */ +bool KitaHTMLPart::reload() +{ + /* config */ + + const bool online = TRUE; + + /*--------------------------------*/ - if ( !m_anchorStack.empty() ) { - str = i18n( "Back (%1)" ).arg( m_anchorStack.last() ); - m_popupMenu->insertItem( str, ID_Back_Link ); - m_popupMenu->insertSeparator(); + if( !online ) return FALSE; + if( !m_domtree ) return FALSE; + if( m_mode != HTMLPART_MODE_MAINPART ){ + /* If this is not MainPart, then open MainPart. */ + KParts::URLArgs argdummy; + emit openURLRequest( m_datURL, argdummy ); + return FALSE; } - m_popupMenu->insertItem( i18n( "Start" ), ID_Start_Link ); + m_domtree->StopParseThread(); + m_firstReceive = TRUE; + if( m_centerNum == 0 ) m_centerNum = m_domtree->getBottomResNumber(); + + /* DatManager will call back slotReceiveData and slotFinishLoad. */ + Kita::DatManager::updateCache( m_datURL , this ); + view()->setFocus(); + + return TRUE; +} + + + +/*---------------------------------------------*/ +/* This slot is called after Kita::DatManager + received new data, and emits receiveData() */ /* !!! "public" slot !!! */ +void KitaHTMLPart::slotReceiveData() +{ + /* config */ + + const int delta = 20; + const int afterShowNum = KitaConfig::afterShowNum();; + const int oneAfterAnother = TRUE; + + /*--------------------------------*/ + + if( m_mode != HTMLPART_MODE_MAINPART ) return; + if( !m_domtree ) return; + + int maxNum = Kita::DatManager::getMaxResNumber( m_datURL ); + int bottom = m_domtree->getBottomResNumber(); + int showNum = m_centerNum + afterShowNum; + + /* parsing */ + if( oneAfterAnother ) parseResponses( bottom+1, maxNum ); - if ( m_domtree->isMae100Shown() ) { - m_popupMenu->insertItem( i18n( "template" ), ID_Temp_Link ); + /* rendering */ + if( m_firstReceive + || ( bottom + delta < maxNum && maxNum <= showNum + delta -1 ) ){ + + if( oneAfterAnother ){ + showResponses( bottom+1, QMIN( maxNum, showNum ) ); + updateScreen( TRUE, FALSE ); + } + else parseResponses( bottom+1, QMIN( maxNum, showNum ) ); + } + + if( m_firstReceive && m_centerNum < maxNum ){ + gotoAnchor( QString().setNum( m_centerNum ), FALSE ); + m_firstReceive = FALSE; } + + emit receiveData(); +} + + +/*--------------------------------------------*/ +/* This slot is called after Kita::DatManager + finished updating new data, + and emits finishReload() */ /* !!! "public" slot !!! */ +void KitaHTMLPart::slotFinishLoad() +{ + /* config */ + const int afterShowNum = KitaConfig::afterShowNum();; + + /*--------------------------------*/ + + if( m_mode != HTMLPART_MODE_MAINPART ) return; + if( !m_domtree ) return; + + int bottom = m_domtree->getBottomResNumber(); + int shownNum = m_centerNum + afterShowNum; + + showResponses(bottom+1, shownNum ); + updateScreen( TRUE, FALSE ); + m_domtree->parseAllRes(); + m_centerNum = 0; + + emit finishReload(); +} + + + + +/*---------------------------------------------------------------*/ +/*---------------------------------------------------------------*/ +/* goto anchor */ + + +/* public */ +bool KitaHTMLPart::gotoAnchor( const QString& anc, bool pushPosition ) +{ + if( anc == QString::null ) return FALSE; + if( !m_domtree ) return KHTMLPart::gotoAnchor( anc ); + + hidePopup(); + + QString ancstr = anc; + int res = ancstr.toInt(); - if ( m_domtree->getKokoyonNum() ) { - str = i18n( "Kokomade Yonda (%1)" ).arg( m_domtree->getKokoyonNum() ); - m_popupMenu->insertItem( str, ID_Koko_Link ); + if ( res > 1 ) { + + /* is target valid ? */ + if ( !Kita::DatManager::isResValid( m_datURL, res ) ) return FALSE; + + /* show res if it is not shown */ + if ( !m_domtree->isResShown( res ) ) { + + if( m_mode != HTMLPART_MODE_MAINPART ) return FALSE; + + int top = m_domtree->getTopResNumber(); + int bottom = m_domtree->getBottomResNumber(); + + if ( res > bottom ){ + showResponses( bottom + 1, res ); + updateScreen( TRUE, TRUE ); + } + else if ( res < top ) { + m_domtree->appendTemplate(); + showResponses( res, bottom ); + updateScreen( TRUE , TRUE ); + } + } + + /* Target is not shown. Maybe it is aboned. */ + while ( res > 1 && !m_domtree->isResShown( res ) ) res--; + + ancstr = QString().setNum( res ); } + + if ( res == 1 ) ancstr = "header"; + if ( pushPosition ) pushCurrentPosition(); + return KHTMLPart::gotoAnchor( ancstr ); +} + + + +/* jump to kokomade yonda */ /* public slot */ +void KitaHTMLPart::slotGotoKokoyon() +{ + if( !m_domtree ) return; + if( m_mode != HTMLPART_MODE_MAINPART ) return; + + int kokoyon = Kita::DatManager::getKokoyonNum( m_datURL ); + gotoAnchor( QString().setNum( kokoyon ), TRUE ); +} + + + +/* public slot */ +void KitaHTMLPart::slotGobackAnchor() +{ + if ( m_anchorStack.empty() ) return; - m_popupMenu->insertItem( i18n( "End" ), ID_End_Link ); + QString anc = m_anchorStack.last(); + m_anchorStack.pop_back(); + gotoAnchor( anc , FALSE ); +} + + + + +/* private */ +void KitaHTMLPart::pushCurrentPosition() +{ + QString anchor, ancundermouse; + DOM::Node node; + + /* find the id of current node */ + node = nodeUnderMouse(); + while ( node != NULL && node.nodeName().string() != "div" ) node = node.parentNode(); + if ( node == NULL ) return ; + anchor = static_cast( node ).getAttribute( "id" ).string(); + + m_anchorStack += anchor; +} + + +/*---------------------------------------------------------------*/ +/*---------------------------------------------------------------*/ +/* Tugi100, Mae100 etc. */ + + +/* public slot */ +void KitaHTMLPart::slotClickTugi100() +{ + if( !m_domtree ) return; + if( m_mode != HTMLPART_MODE_MAINPART ) return; - if ( hasSelection() ) { - m_popupMenu->insertSeparator(); - m_popupMenu->insertItem( i18n( "Copy" ), ID_Copy_Str ); - m_popupMenu->insertItem( i18n( "Add '%1' to abone list" ).arg( selectedText() ), ID_Abone_Word ); + int bottom = m_domtree->getBottomResNumber(); + int maxNum = Kita::DatManager::getMaxResNumber( m_datURL ); + + if ( maxNum != bottom ) { + showResponses( bottom + 1, bottom + 100 ); + updateScreen( TRUE, TRUE ); } +} + + + +/* public slot */ +void KitaHTMLPart::slotClickNokori() +{ + if( !m_domtree ) return; + if( m_mode != HTMLPART_MODE_MAINPART ) return; - if ( url != NULL ) { - m_popupMenu->insertSeparator(); - m_popupMenu->insertItem( i18n( "Copy Link Location" ), ID_COPY_Link ); + int bottom = m_domtree->getBottomResNumber(); + int maxNum = Kita::DatManager::getMaxResNumber( m_datURL ); + + if ( maxNum != bottom ) { + showResponses( bottom + 1, maxNum ); + updateScreen( TRUE, TRUE ); + } +} + +/* public slot */ +void KitaHTMLPart::slotClickGotoFooter() +{ + if( !m_domtree + || m_mode != HTMLPART_MODE_MAINPART + ){ + gotoAnchor( "footer", TRUE ); + return; } - if ( m_threadView->getViewMode() == VIEWMODE_PARENT ) { - m_popupMenu->insertSeparator(); - m_popupMenu->insertItem( i18n( "Clear Log and Reload" ), ID_DEL_ThreadLog ); + int bottom = m_domtree->getBottomResNumber(); + int maxNum = Kita::DatManager::getMaxResNumber( m_datURL ); + + if ( maxNum != bottom ) { + showResponses( bottom + 1, maxNum ); + updateScreen( TRUE, TRUE ); } - QClipboard* clipboard = QApplication::clipboard(); + gotoAnchor( "footer", TRUE ); +} - switch ( m_popupMenu->exec( point ) ) { - case ID_COPY_Link: - clipboard->setText( url , QClipboard::Clipboard ); - clipboard->setText( url , QClipboard::Selection ); - break; - case ID_Start_Link: gotoAnchor( "header" ); break; - case ID_Temp_Link: gotoAnchor( "mae100" ); break; - case ID_Koko_Link: gotoKokoyon();break; - case ID_End_Link: gotoAnchor( "footer" ); break; - case ID_Back_Link: gobackAnchor(); break; - case ID_Copy_Str: - clipboard->setText( selectedText(), QClipboard::Clipboard ); - break; - case ID_DEL_ThreadLog: - if ( Kita::Access::deleteLog( m_thread, m_parent ) ) - m_threadView->showThread( m_thread ); - break; +/* public slot */ +void KitaHTMLPart::slotClickMae100() +{ + if( !m_domtree ) return; + if( m_mode != HTMLPART_MODE_MAINPART ) return; + + int top = m_domtree->getTopResNumber(); + int bottom = m_domtree->getBottomResNumber(); + + if ( top != 1 ) { + m_domtree->appendTemplate(); + showResponses( top - 100, bottom ); + updateScreen( TRUE, TRUE ); - case ID_Abone_Word: - KitaConfig::addAboneWord( selectedText() ); - break; - - default: - break; + gotoAnchor( QString().setNum( top ), FALSE ); } } -/*----------------------------------------------------*/ - -/* protected functions */ -void KitaHTMLPart::khtmlMousePressEvent( khtml::MousePressEvent* e ) +/* public slot */ +void KitaHTMLPart::slotClickMaeZenbu() { - m_pushctrl = FALSE; - m_pushmidbt = FALSE; - m_pushrightbt = FALSE; + if( !m_domtree ) return; + if( m_mode != HTMLPART_MODE_MAINPART ) return; + + int top = m_domtree->getTopResNumber(); + int bottom = m_domtree->getBottomResNumber(); + + if ( top != 1 ) { + showResponses( 1, bottom ); + updateScreen( TRUE, TRUE); - /* cancel popup */ - if(e->qmouseEvent()->button() & Qt::RightButton){ - m_pushrightbt = TRUE; - return; + gotoAnchor( QString().setNum( top ), FALSE ); } +} + + +/* public slot */ +void KitaHTMLPart::slotClickTmpNext100() +{ + if( !m_domtree ) return; + if( m_mode != HTMLPART_MODE_MAINPART ) return; - /* check if ctrl key is pushed */ - if ( e->url() != NULL ) { + int top = m_domtree->getTopResNumber(); + int bottom = m_domtree->getBottomResNumber(); + int tmpnum = m_domtree->getTemplateNumber(); - if ( e->qmouseEvent() ->state() & Qt::ControlButton ) { - m_pushctrl = TRUE; - } - if ( e->qmouseEvent() ->button() & Qt::MidButton ) { - m_pushmidbt = TRUE; - } + if ( tmpnum < top ) { + m_domtree->setTemplateNumber( tmpnum + 100 ); + m_domtree->appendTemplate(); + showResponses( top, bottom ); + updateScreen( TRUE, TRUE ); - if ( m_pushctrl || m_pushmidbt ) { - KURL kurl; - if ( e->url().string().at( 0 ) == '#' ) { - kurl = m_thread->datURL() + e->url().string(); - } else { - kurl = KURL( m_thread->boardURL(), e->url().string() ); - } + gotoAnchor( QString().setNum( tmpnum ), FALSE ); + } +} - if ( m_pushctrl ) { - emit browserExtension() ->openURLRequest( kurl ); - } + +/* public slot */ +void KitaHTMLPart::slotClickShowAll() +{ + if( !m_domtree ) return; + if( m_mode != HTMLPART_MODE_MAINPART ) return; + + int top = m_domtree->getTopResNumber(); + int bottom = m_domtree->getBottomResNumber(); + int maxNum = Kita::DatManager::getMaxResNumber( m_datURL ); - return ; - } + if ( top != 1 || bottom != maxNum ) { + showResponses( 1, maxNum ); + updateScreen( TRUE, TRUE ); + + gotoAnchor( "header", FALSE ); } - KHTMLPart::khtmlMousePressEvent( e ); } -void KitaHTMLPart::khtmlMouseMoveEvent( khtml::MouseMoveEvent* e ) + + + + + +/*---------------------------------------------------------------*/ +/*---------------------------------------------------------------*/ +/* search */ + + +/* private */ +void KitaHTMLPart::findTextInit() { - KHTMLPart::khtmlMouseMoveEvent( e ); + m_findNode = NULL; + m_findPos = -1; + m_find_y = 0; } -void KitaHTMLPart::khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *e ) + + +/* public */ +bool KitaHTMLPart::findText( const QString &query, bool reverse ) { - if ( e->qmouseEvent() ->button() & Qt::RightButton ) { - /* popup */ - if ( e->url().string().left(6) == "#idpop" || - (m_pushrightbt && e->url().string().left(6) == "#write" )) { - KURL kurl; - kurl = m_thread->datURL() + e->url().string(); - emit browserExtension() ->openURLRequest( kurl ); - return ; - } + if( m_mode != HTMLPART_MODE_MAINPART && m_mode != HTMLPART_MODE_NAVI ) return FALSE; - /* popup here & return */ - slotPopupMenu( e->url().string(), e->qmouseEvent() ->globalPos() ); - return ; + QRegExp regexp( query ); + regexp.setCaseSensitive( FALSE ); + + /* init */ + if ( m_findNode.isNull() ) { + + m_findNode = htmlDocument().body(); + m_find_y = 0; + + /* move to the last child node */ + if ( reverse ) { + while ( !m_findNode.lastChild().isNull() ) m_findNode = m_findNode.lastChild(); + m_find_y = view()->contentsHeight(); + } } - KHTMLPart::khtmlMouseReleaseEvent( e ); -} + + while ( 1 ) { + + if ( m_findNode.nodeType() == DOM::Node::TEXT_NODE + || m_findNode.nodeType() == DOM::Node::CDATA_SECTION_NODE ){ + + /* find the word in the current node */ + DOM::DOMString nodeText = m_findNode.nodeValue(); + QString nodestr = nodeText.string(); + if ( reverse && m_findPos != -1 ) nodestr.setLength( m_findPos ); + + if ( reverse ) m_findPos = nodestr.findRev( regexp, m_findPos ); + else m_findPos = nodestr.find( regexp, m_findPos + 1 ); + + /* scroll & select & return */ + if ( m_findPos != -1 ) { + + int matchLen = regexp.matchedLength(); + + QRect qr = m_findNode.getRect(); + view()->setContentsPos( qr.left() - 50, m_find_y - 100 ); + DOM::Range rg( m_findNode, m_findPos, m_findNode, m_findPos + matchLen ); + setSelection( rg ); + + return TRUE; + } + + } + + /*------------------------*/ + else if ( m_findNode.nodeName().string() == "dt" + || m_findNode.nodeName().string() == "dd" ){ + + QRect qr = m_findNode.getRect(); + + if ( reverse ) m_find_y = qr.bottom(); + else m_find_y = qr.top(); + } + + /*------------------------*/ + else if ( m_findNode.nodeName().string() == "br" ) { + + DOM::Node tmpnode = m_findNode.previousSibling(); + + if ( tmpnode != NULL ) { + + QRect qr = tmpnode.getRect(); + if ( reverse ) m_find_y -= qr.bottom() - qr.top(); + else m_find_y += qr.bottom() - qr.top(); + } + } + + /*------------------------*/ + + m_findPos = -1; + DOM::Node next; + + /* move to the next node */ + if ( !reverse ) { + + next = m_findNode.firstChild(); + if ( next.isNull() ) next = m_findNode.nextSibling(); + + while ( !m_findNode.isNull() && next.isNull() ) { + m_findNode = m_findNode.parentNode(); + if ( !m_findNode.isNull() ) next = m_findNode.nextSibling(); + } + } + /* revearse */ + else { + + next = m_findNode.lastChild(); + if ( next.isNull() ) next = m_findNode.previousSibling(); + + while ( !m_findNode.isNull() && next.isNull() ) { + m_findNode = m_findNode.parentNode(); + if ( !m_findNode.isNull() ) next = m_findNode.previousSibling(); + } + } + + m_findNode = next; + if ( m_findNode.isNull() ) { + m_findNode = NULL; + return FALSE; + } + } + + return FALSE; +} + + + + + + +/*---------------------------------------------------------------*/ +/*---------------------------------------------------------------*/ +/* popup menu */ + + +/* private */ +void KitaHTMLPart::showPopupMenu( const KURL& kurl ) +{ + enum { + ID_Home_Link, + ID_Temp_Link, + ID_Koko_Link, + ID_End_Link, + + ID_COPY_Link, + ID_Copy_Str, + ID_Abone_Word, + ID_Extract, + + + /*-----------------*/ + ID_Back_Link /* stay bottom */ + }; + + QPoint point = QCursor::pos(); + QString url = kurl.prettyURL(); + bool showppm = FALSE; + const int ID_Goto_Check = ID_Back_Link + m_anchorStack.size(); + + QString str; + + /* If selected Text is composed of only digits, then show res popup. */ + if( !m_pushctrl && showSelectedDigitPopup() ) return; + + /*-----------------------------------*/ + /* create menu items */ + + KPopupMenu* popupMenu = new KPopupMenu( view() ); + KPopupMenu* backSubMenu = NULL; + KPopupMenu* checkSubMenu = NULL; + + popupMenu->clear(); + + + /*------*/ + /* jump */ + if( m_domtree && + (m_mode == HTMLPART_MODE_MAINPART || m_mode == HTMLPART_MODE_NAVI ) ){ + + showppm = TRUE; + + /* back */ + if ( !m_anchorStack.empty() ) { + backSubMenu = new KPopupMenu( view() ); + backSubMenu->clear(); + + int i = m_anchorStack.size(); + QStringList::iterator it; + for ( it = m_anchorStack.begin(); it != m_anchorStack.end(); it++,i-- ){ + str = (*it) + " " + Kita::DatManager::getPlainBody( m_datURL, (*it).toInt() ).left( 10 ); + backSubMenu->insertItem( str, ID_Back_Link +(i-1), 0 ); + } + + popupMenu->insertItem( i18n( "Back" ), backSubMenu ); + popupMenu->insertSeparator(); + } + + /* check */ + for( int i = 1; i <= Kita::DatManager::getMaxResNumber( m_datURL ) ; i++ ){ + if( m_check[ i ] ){ + if( !checkSubMenu ){ + checkSubMenu = new KPopupMenu( view() ); + checkSubMenu->clear(); + popupMenu->insertItem( i18n( "Check" ), checkSubMenu ); + popupMenu->insertSeparator(); + } + + str = QString().setNum( i ) + " " + + Kita::DatManager::getPlainBody( m_datURL, i ).left( 10 ); + checkSubMenu->insertItem( str, ID_Goto_Check + i ); + } + } + + /* home */ + popupMenu->insertItem( i18n( "Start" ), ID_Home_Link ); + + + /* template */ + if ( m_mode == HTMLPART_MODE_MAINPART ){ + + if( m_domtree->isMae100Shown() ) popupMenu->insertItem( i18n( "template" ), ID_Temp_Link ); + + int kokoyon = Kita::DatManager::getKokoyonNum( m_datURL ); + if( kokoyon ){ + str = i18n( "Kokomade Yonda (%1)" ).arg( kokoyon ); + popupMenu->insertItem( str, ID_Koko_Link ); + } + } + + + /* end */ + popupMenu->insertItem( i18n("End"), ID_End_Link ); + } + + + /*--------------*/ + /* copy & abone */ + if ( hasSelection() ) { + if( showppm ) popupMenu->insertSeparator(); + showppm = TRUE; + + popupMenu->insertItem( "Copy", ID_Copy_Str ); + + popupMenu->insertItem( i18n( "Extract by '%1'" ).arg( selectedText() ), ID_Extract ); + popupMenu->insertItem( i18n( "Add '%1' to abone list" ).arg( selectedText() ), ID_Abone_Word ); + } + + + /*-----------*/ + /* copy link */ + if ( url != QString::null ) { + if( showppm ) popupMenu->insertSeparator(); + showppm = TRUE; + + popupMenu->insertItem( i18n( "Copy Link Location" ), ID_COPY_Link ); + } + + + /*-----------------------------------*/ + + /* show menu */ + if( showppm ){ + + QClipboard* clipboard = QApplication::clipboard(); + + int ret = popupMenu->exec( point ); + switch ( ret ) { + + case ID_COPY_Link: + clipboard->setText( url , QClipboard::Clipboard ); + clipboard->setText( url , QClipboard::Selection ); + break; + + case ID_Home_Link: gotoAnchor( "header", TRUE ); break; + + case ID_Temp_Link: gotoAnchor( "mae100", TRUE ); break; + + case ID_Koko_Link: slotGotoKokoyon(); break; + + case ID_End_Link: slotClickGotoFooter(); break; + + case ID_Copy_Str: + clipboard->setText( selectedText(), QClipboard::Clipboard ); + break; + + case ID_Abone_Word: + + if ( QMessageBox::question( view(),"Kita", + i18n( "Do you want to add '%1' to abone list ?" ).arg( selectedText() ), + QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default ) + == QMessageBox::Ok ){ + + KitaConfig::addAboneWord( selectedText() ); + Kita::DatManager::resetAbone( m_datURL ); + emit redrawScreen( m_datURL, FALSE ); + } + + break; + + case ID_Extract: + KitaNavi::showKitaNaviByWord( m_datURL, selectedText() ); + break; + + default: + + /* check */ + if( ret >= ID_Goto_Check ){ + gotoAnchor( QString().setNum( ret - ID_Goto_Check ), FALSE ); + } + + /* back */ + else if( ret >= ID_Back_Link ){ + for(int i = 0; i < ret - ID_Back_Link; i++ ) m_anchorStack.pop_back(); + slotGobackAnchor(); + } + + break; + } + + } + + if( popupMenu ) delete popupMenu; + if( backSubMenu ) delete backSubMenu; + if( checkSubMenu ) delete checkSubMenu; +} + + + +/*---------------------------------------------------------------*/ +/*---------------------------------------------------------------*/ +/* mouse event */ + + +/* protected */ +void KitaHTMLPart::khtmlMousePressEvent( khtml::MousePressEvent* e ) +{ + KURL kurl; + if( e->url().string() != QString::null ) + kurl = KURL( Kita::DatManager::thread_boardURL( m_datURL ), e->url().string() ); + + m_pushctrl = m_pushmidbt = m_pushrightbt = FALSE; + if(e->qmouseEvent()->button() & Qt::RightButton) m_pushrightbt = TRUE; + if ( e->qmouseEvent() ->state() & Qt::ControlButton ) m_pushctrl = TRUE; + if ( e->qmouseEvent() ->button() & Qt::MidButton ) m_pushmidbt = TRUE; + + if ( e->url() != NULL ){ + + if ( e->url().string().at( 0 ) == '#' ) { /* anchor */ + kurl = m_datURL; + kurl.setRef( e->url().string().mid(1) ) ; + } + + clickAnchor( kurl ); + m_pushctrl = m_pushmidbt = m_pushrightbt = FALSE; + return; + } + + /* popup menu */ + if( m_pushrightbt ) { + showPopupMenu( kurl ); + m_pushctrl = m_pushmidbt = m_pushrightbt = FALSE; + return; + } + + KHTMLPart::khtmlMousePressEvent( e ); +} + + + + + +/*-------------------------------------------------------*/ +/*-------------------------------------------------------*/ +/* click */ + + + +/* private slot */ +void KitaHTMLPart::slotOpenURLRequest( const KURL& urlin, const KParts::URLArgs& ){ + clickAnchor(urlin); +} + + +/*------------------------------------------------------*/ +/* This function is called when user clicked res anchor */ /* private */ +void KitaHTMLPart::clickAnchor( const KURL& urlin ) +{ + QString refstr; + KURL datURL = Kita::ParseMisc::parseURL( urlin ,refstr ); + + /*--------------------*/ + /* Ctrl + right click */ + if( m_pushctrl && m_pushrightbt ){ + showPopupMenu( urlin ); + return; + } + + /*--------------------------------*/ + /* If this is not anchor, then */ + /* emit openURLRequest and return */ + + if ( datURL.host() != m_datURL.host() || datURL.path() != m_datURL.path() ) { + + if( m_pushrightbt ){ /* right click */ + + /* start multi-popup mode or show popup menu */ + if( !startMultiPopup() ) showPopupMenu( urlin ); + + return; + } + + KParts::URLArgs argdummy; + emit openURLRequest( urlin, argdummy ); + return ; + } + + if ( refstr == QString::null ) return ; + + /*---------------------------*/ + /* show popupmenu for #write */ + + if ( refstr.left( 5 ) == "write" ) { + showWritePopupMenu( refstr ); + return; + } + + /*----------------------------*/ + /* extract responses by ID */ + + if( refstr.left(5) == "idpop"){ + showIDPopup( refstr ); + return; + } + + /*-------------------------*/ + /* start multi-popup mdde */ + if( m_pushrightbt && startMultiPopup() ) return; + + + /*----------------------------*/ + /* next 100 ,before 100 ,etc. */ + if( showNext100Etc( refstr ) ) return; + + + /*-------------------------------*/ + /* open Kita Navi or goto anchor */ + + int refNum,refNum2; + + int i = refstr.find( "-" ); + if ( i != -1 ) { + refNum = refstr.left( i ).toInt(); + refNum2 = refstr.mid(i+1).toInt(); + if( refNum2 < refNum ) refNum2 = refNum; + refstr = datURL.ref().left( i ); + } else refNum = refNum2 = refstr.toInt(); + + if ( !refNum ) return ; + + if( m_pushctrl || m_pushmidbt ) KitaNavi::showKitaNavi( m_datURL, refNum, refNum2 ); + else gotoAnchor( refstr, TRUE ); +} + + + +/*---------------------------------------------------------*/ +/* popup menu that is opened when user clicked res number. */ +/* This funtcion is called in only clickAnchor(). */ /* private */ +void KitaHTMLPart::showWritePopupMenu( const QString& refstr) +{ + enum{ + WRITEMENU_RES, + WRITEMENU_QUOTE, + WRITEMENU_SHOWBROWSER, + WRITEMENU_SHOWNAVI, + WRITEMENU_RESTREE, + WRITEMENU_REVERSERESTREE, + WRITEMENU_EXTRACTNAME, + WRITEMENU_COPY, + WRITEMENU_COPYURL, + WRITEMENU_COPYTHREADNAME, + WRITEMENU_SETKOKOYON, + WRITEMENU_CHECK, + WRITEMENU_ABONENAME + }; + + QClipboard * clipboard = QApplication::clipboard(); + QString str, resstr; + int resNum = refstr.mid( 5 ).toInt(); + QString namestr = Kita::DatManager::getName( m_datURL, resNum ); + + /* show res tree */ + if( m_pushrightbt ){ + int num; + QString htmlstr = Kita::DatManager::getTreeByRes( m_datURL, resNum, num ); + if ( !num ) return ; + QString tmpstr = QString("
No.%1 : [%2]
").arg( resNum ).arg( num ); + tmpstr += htmlstr + "

"; + showPopup( m_datURL, tmpstr ); + startMultiPopup(); + return; + } + + /* open kitanavi */ + else if( m_pushctrl | m_pushmidbt ){ + KitaNavi::showKitaNaviResTree(m_datURL,resNum); + return; + } + + /*---------------------*/ + /* create popup menu */ + QString plainStr; + + KPopupMenu *popupMenu = new KPopupMenu( view() ); + popupMenu->clear(); + + /* write */ + if( m_mode == HTMLPART_MODE_MAINPART || m_mode == HTMLPART_MODE_NAVI ){ + + popupMenu->insertItem( i18n( "write response" ), WRITEMENU_RES ); + popupMenu->insertItem( i18n( "quote this" ), WRITEMENU_QUOTE ); + popupMenu->insertSeparator(); + + } + + /* check */ + if( m_mode == HTMLPART_MODE_MAINPART ){ + popupMenu->insertItem( i18n( "Check" ), WRITEMENU_CHECK ); + popupMenu->setItemChecked( WRITEMENU_CHECK, m_check[ resNum ] ); + popupMenu->insertSeparator(); + } + + /* open */ + popupMenu->insertItem( i18n( "Open with KitaNavi" ), WRITEMENU_SHOWNAVI ); + popupMenu->insertItem( i18n( "Open with Web Browser" ), WRITEMENU_SHOWBROWSER ); + popupMenu->insertSeparator(); + + /* util */ + popupMenu->insertItem( i18n( "res tree" ), WRITEMENU_RESTREE ); + popupMenu->insertItem( i18n( "reverse res tree" ), WRITEMENU_REVERSERESTREE ); + popupMenu->insertItem( i18n( "extract by name" ), WRITEMENU_EXTRACTNAME ); + popupMenu->insertSeparator(); + + /* copy */ + popupMenu->insertItem( i18n( "copy URL" ), WRITEMENU_COPYURL ); + popupMenu->insertItem( i18n( "Copy title and URL" ), WRITEMENU_COPYTHREADNAME ); + popupMenu->insertItem( i18n( "copy" ), WRITEMENU_COPY ); + + /* kokkoma de yonda */ + if( m_domtree && m_mode == HTMLPART_MODE_MAINPART ){ + popupMenu->insertSeparator(); + popupMenu->insertItem( i18n( "set Kokomade Yonda" ), WRITEMENU_SETKOKOYON ); + } + + /* abone */ + popupMenu->insertSeparator(); + popupMenu->insertItem( i18n( "add name to abone list" ), WRITEMENU_ABONENAME ); + + + /*--------------------------------------*/ + /* show popup menu */ + + int ret = popupMenu->exec( QCursor::pos() ); + delete popupMenu; + switch ( ret ) { + + case WRITEMENU_RES: + resstr = ">>" + QString().setNum( resNum ) + "\n"; + emit openWriteDialog( resstr ); + break; + + case WRITEMENU_QUOTE: + resstr = ">>" + QString().setNum( resNum ) + "\n" + + "> " + Kita::DatManager::getPlainTitle( m_datURL, resNum ) + "\n" + + "> " + Kita::DatManager::getPlainBody( m_datURL, resNum ).replace("\n","\n> ") + "\n"; + emit openWriteDialog( resstr ); + break; + + case WRITEMENU_CHECK: + m_check[ resNum ] = !m_check[ resNum ]; + break; + + case WRITEMENU_COPY: + case WRITEMENU_COPYURL: + case WRITEMENU_COPYTHREADNAME: + str = QString::null; + + /* title */ + if( ret == WRITEMENU_COPYTHREADNAME || ret == WRITEMENU_COPY ){ + str = Kita::DatManager::thread_name( m_datURL ); + } + + /* url */ + if( str != QString::null ) str += "\n"; + str += Kita::DatManager::thread_url( m_datURL ) + QString().setNum( resNum ) + "\n"; + + /* body */ + if( ret == WRITEMENU_COPY ){ + str += "\n" + + Kita::DatManager::getPlainTitle( m_datURL, resNum ) + "\n" + + Kita::DatManager::getPlainBody( m_datURL, resNum ) + "\n"; + } + + /* copy */ + clipboard->setText( str , QClipboard::Clipboard ); + clipboard->setText( str , QClipboard::Selection ); + break; + + + case WRITEMENU_SETKOKOYON: + Kita::DatManager::setKokoyonNum( m_datURL, resNum ); + m_updatedKokoyon = TRUE; + updateScreen( TRUE, TRUE ); + gotoAnchor( QString().setNum( resNum ), FALSE ); + break; + + case WRITEMENU_SHOWBROWSER: + str = Kita::DatManager::thread_url( m_datURL ) + + QString().setNum( resNum ); + + KRun::runURL( str, "text/html" ); + break; + + + case WRITEMENU_SHOWNAVI: + KitaNavi::showKitaNavi( m_datURL, resNum, resNum); + break; + + + case WRITEMENU_RESTREE: + KitaNavi::showKitaNaviResTree( m_datURL, resNum); + break; + + case WRITEMENU_REVERSERESTREE: +// KitaNavi::showKitaNaviRevResTree( m_datURL, resNum); + break; + + case WRITEMENU_EXTRACTNAME: +// KitaNavi::showKitaNaviByName( m_datURL, namestr ); + break; + + case WRITEMENU_ABONENAME: + if ( QMessageBox::question( view(),"Kita", + i18n( "Do you want to add '%1' to abone list ?" ).arg( namestr ), + QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default ) + == QMessageBox::Ok ){ + + KitaConfig::addAboneName( namestr ); + Kita::DatManager::resetAbone( m_datURL ); + emit redrawScreen( m_datURL, FALSE ); + } + break; + + default: + break; + } + +} + + + +/*--------------------------------------------------*/ +/* popup that is opened when user clicked ID */ +/* This funtcion is called in only clickAnchor(). */ /* private */ +void KitaHTMLPart::showIDPopup( const QString& refstr ) +{ + QString strid = refstr.mid(5) + .replace("%2B","+") /* decode %2B -> + */ + .replace("%2F", "/"); /* decode %2F -> / */ + + /* popup */ + if( m_pushrightbt ){ + int num; + QString htmlstr + = Kita::DatManager::getHtmlByID( m_datURL, strid, num ); + if ( num <= 1 ) return ; + QString tmpstr = QString("
ID:%1:[%2]
").arg( strid ).arg( num ); + tmpstr += htmlstr + "

"; + showPopup( m_datURL, tmpstr ); + startMultiPopup(); + } + + /* open kitanavi when user pushed Ctrl+Left or Mid button. */ + else if( m_pushctrl | m_pushmidbt ) KitaNavi::showKitaNaviByID( m_datURL, strid ); + + else { + + enum{ + IDMENU_EXTRACT, + IDMENU_ABONE + }; + + KPopupMenu *popupMenu = new KPopupMenu( view() ); + popupMenu->clear(); + if( Kita::DatManager::getNumByID( m_datURL, strid ) > 1 ) + popupMenu->insertItem( i18n( "extract by ID" ), IDMENU_EXTRACT ); + popupMenu->insertItem( i18n( "add id to abone list" ), IDMENU_ABONE ); + int ret = popupMenu->exec( QCursor::pos() ); + delete popupMenu; + switch ( ret ) { + + case IDMENU_EXTRACT: + KitaNavi::showKitaNaviByID( m_datURL, strid ); + break; + + case IDMENU_ABONE: + /* add ID to abone list */ + if ( QMessageBox::question( view(),"Kita", + i18n( "Do you want to add '%1' to abone list ?" ).arg( strid ), + QMessageBox::Ok, QMessageBox::Cancel | QMessageBox::Default ) + == QMessageBox::Ok ){ + + KitaConfig::addAboneID( strid ); + Kita::DatManager::resetAbone( m_datURL ); + emit redrawScreen( m_datURL, FALSE ); + } + break; + + default: + break; + } + } +} + + + +/*-------------------------------------------------------*/ +/* funtcion when user clicked next 100 ,before 100 ,etc. */ +/* This funtcion is called in only clickAnchor(). */ /* private */ +bool KitaHTMLPart::showNext100Etc( const QString& refstr ) +{ + if( m_mode != HTMLPART_MODE_MAINPART ) return FALSE; + + if ( refstr.left( 7 ) == "tugi100" ) { + slotClickTugi100(); + return TRUE; + + } else if ( refstr.left( 6 ) == "nokori" ) { + slotClickNokori(); + return TRUE; + + } else if ( refstr.left( 7 ) == "tosaigo" ) { + slotClickGotoFooter(); + return TRUE; + + } else if ( refstr.left( 6 ) == "mae100" ) { + slotClickMae100(); + return TRUE; + + } else if ( refstr.left( 8 ) == "maezenbu" ) { + slotClickMaeZenbu(); + return TRUE; + + } else if ( refstr.left( 6 ) == "tmp100" ) { + slotClickTmpNext100(); + return TRUE; + + } else if ( refstr.left( 5 ) == "zenbu" ) { + slotClickShowAll(); + return TRUE; + } + + return FALSE; +} + + + +/*-------------------------------------------------------*/ +/*-------------------------------------------------------*/ +/* popup */ + + +/*---------------------*/ +/* show popup window */ /* private */ +void KitaHTMLPart::showPopup( const KURL& url, const QString& innerHTML ) +{ + deletePopup(); + m_multiPopup = FALSE; + + m_popup = new Kita::ResPopup( view() , url ); + + connect( m_popup, SIGNAL( hideChildPopup() ),SLOT( slotHideChildPopup() ) ); + + m_popup->setText( innerHTML ); + m_popup->adjustSize(); + m_popup->adjustPos(); + m_popup->show(); +} + + +/*------------------------*/ +/* start multi-popup mode */ /* private */ +bool KitaHTMLPart::startMultiPopup(){ + + if( m_popup && m_popup->isVisible() ){ + m_multiPopup = TRUE; + m_popup->moveMouseAbove(); + } + else m_multiPopup = FALSE; + + return m_multiPopup; +} + + +/* Is it multi-popup mode now ? */ /* private */ +bool KitaHTMLPart::isMultiPopupMode() +{ + if( !m_popup ) m_multiPopup = FALSE; + else if( m_popup->isHidden() ) m_multiPopup = FALSE; + + return m_multiPopup; +} + + +/* private */ +void KitaHTMLPart::hidePopup() +{ + if( m_popup ) m_popup->hide(); + m_multiPopup = FALSE; +} + + + +/* private */ +void KitaHTMLPart::deletePopup() +{ + if ( m_popup ) delete m_popup; + m_popup = NULL; + m_multiPopup = FALSE; +} + + +/* return TRUE if this view is under mouse. */ /* private */ +bool KitaHTMLPart::isUnderMouse( int mrgwd, int mrght ) +{ + QPoint pos = QCursor::pos(); + int cx = pos.x(), cy = pos.y(); + + QPoint viewpos = view()->mapToGlobal( QPoint(0,0) ); + int px = viewpos.x(), py = viewpos.y(); + int wd = view()->visibleWidth(), ht = view()->visibleHeight(); + + if( ( px < cx && cx < px + wd + mrgwd ) + && ( py < cy && cy < py + ht + mrght ) ){ + return TRUE; + } + + return FALSE; +} + + +/* private slot */ +void KitaHTMLPart::slotLeave() +{ + if ( isMultiPopupMode() ) return; + if( view()->isHorizontalSliderPressed() ) return; + if( view()->isVerticalSliderPressed () ) return; + + hidePopup(); + + /* emit signal to have parent hide this if this is popup . */ + if( m_mode == HTMLPART_MODE_POPUP && !isUnderMouse( 0, 0 ) ) emit hideChildPopup(); +} + + +/* private slot */ +void KitaHTMLPart::slotVSliderReleased(){ + + QScrollBar* bar = view()->verticalScrollBar(); + QRect rt = bar->sliderRect(); + int mrg = rt.right() - rt.left(); + + hidePopup(); + + /* emit signal to have parent hide this if this is popup . */ + if( m_mode == HTMLPART_MODE_POPUP && !isUnderMouse( mrg, 0 ) ) emit hideChildPopup(); +} + + +/* private slot */ +void KitaHTMLPart::slotHSliderReleased(){ + + QScrollBar* bar = view()->horizontalScrollBar(); + QRect rt = bar->sliderRect(); + int mrg = rt.bottom() - rt.top(); + + hidePopup(); + + /* emit signal to have parent hide this if this is popup . */ + if( m_mode == HTMLPART_MODE_POPUP && !isUnderMouse( 0, mrg ) ) emit hideChildPopup(); +} + + + +/* private slot */ +void KitaHTMLPart::slotHideChildPopup() +{ + hidePopup(); + + /* emit signal to have parent hide this if this is popup . */ + if( m_mode == HTMLPART_MODE_POPUP && !isUnderMouse( 0, 0 ) ) emit hideChildPopup(); +} + + + +/*------------------------------------------*/ +/* called back when kita is active . + see also an explanation in slotOnURL. */ /* private slot */ +void KitaHTMLPart::slotKitaIsActive(){ + m_kitaIsActive = TRUE; +} + + + +/*---------------------------------------------------*/ +/* This slot is called when mouse moves onto the URL */ /* private slot */ +void KitaHTMLPart::slotOnURL( const QString& url ) +{ + /* config */ + + const int maxpopup = 10; /* max number of responses shown in the popup window */ + + /*----------------------------*/ + + if( isMultiPopupMode() ) return; + + deletePopup(); + + if ( url.isEmpty() ) return ; + if ( url.left( 7 ) == "mailto:" ) return; + + /* Is Kita active now ? + + emit SIGNAL( isKitaActive() ) to KitaMainWindow, KitaNavi, etc. , + and if one of them is active, then slotKitaIsActive() is called + back, and m_kitaIsActive is set to TRUE. */ + m_kitaIsActive = FALSE; + emit isKitaActive(); + if( !m_kitaIsActive ) return; + + /*------------------------*/ + /* id popup */ + + if ( url.left( 6 ) == "#idpop" ) { + int num = Kita::DatManager::getNumByID( m_datURL, url.mid( 6 ) ); + if ( num <= 1 ) return ; + QString tmpstr = QString( "
ID:%1:[%2]
" ).arg( url.mid( 6 ) ).arg( num ); + showPopup( m_datURL, tmpstr ); + return ; + } + + + /*-------------------------*/ + /* popup for anchor */ + + QString innerHTML = QString::null; + QString refstr; + KURL datURL = m_datURL; + int refNum; + int refNum2; + + /* get reference */ + if ( url.at( 0 ) == '#' ) refstr = url.mid( 1 ); + else datURL = Kita::ParseMisc::parseURL( KURL( m_datURL, url ) ,refstr); + + int i = refstr.find( "-" ); + if ( i != -1 ) { /* >>refNum-refNum2 */ + + refNum = refstr.left( i ).toInt(); + refNum2 = refstr.mid( i + 1 ).toInt(); + + if ( refNum ) { + if ( refNum2 < refNum ) refNum2 = refNum; + if ( refNum2 - refNum > maxpopup - 1 ) refNum2 = refNum + maxpopup - 1; + } + + } else { /* >>refNum */ + refNum = refstr.toInt(); + refNum2 = refNum; + } + + /* another thread ? */ + if ( datURL.host() != m_datURL.host() || datURL.path() != m_datURL.path() ) { + + /* show them with boadname & subject */ + QString boardName = Kita::DatManager::thread_boardName( datURL ); + if ( boardName != QString::null ) innerHTML += "[" +boardName +"] "; + QString subName = Kita::DatManager::getSubject( datURL ); + if ( subName != QString::null ) innerHTML += subName +"

"; + + if ( !refNum ) refNum = refNum2 = 1; + } + + /* get HTML and show it */ + if ( !refNum ) return ; + innerHTML += Kita::DatManager::getHtml( datURL, refNum, refNum2 ); + + if ( innerHTML != QString::null ) showPopup( datURL, innerHTML ); +} + + + +/* If selected Text is composed of only digits, + then show res popup. */ /* private */ +bool KitaHTMLPart::showSelectedDigitPopup(){ + + if( !hasSelection() ) return FALSE; + + QString linkstr; + int refNum[2]; + unsigned int pos; + QString selectText = selectedText(); + const QChar *chpt = selectText.unicode(); + unsigned int length = selectText.length(); + + if( Kita::ParseMisc::parseResAnchor( chpt, length, linkstr, refNum, pos ) ){ + if( refNum[1] < refNum[0] ) refNum[1] = refNum[0]; + QString innerHTML = Kita::DatManager::getHtml( m_datURL, refNum[0], refNum[1] ); + if ( innerHTML != QString::null ) { + showPopup( m_datURL, innerHTML ); + startMultiPopup(); + return TRUE; + } + } + + return FALSE; +} + + + + +/*--------------------------------------------------------------*/ +/*--------------------------------------------------------------*/ +/* class ResPopup */ + + +namespace Kita +{ + ResPopup::ResPopup( KHTMLView* view, const KURL& datURL ) + : QFrame( view, "res_popup", + WStyle_Customize + | WStyle_NoBorder + | WStyle_Tool + | WType_TopLevel + | WX11BypassWM + ) + { + m_textBrowser = new QTextBrowser( this ); + m_textBrowser->setWordWrap( QTextEdit::NoWrap ); + m_textBrowser->setResizePolicy( QScrollView::AutoOne ); + m_textBrowser->setFont( KitaConfig::threadFont() ); + + m_htmlPart = new KitaHTMLPart(this); + m_htmlPart->setup( HTMLPART_MODE_POPUP , datURL ); + connect( m_htmlPart, SIGNAL( hideChildPopup() ), SIGNAL( hideChildPopup() ) ); + } + + + ResPopup::~ResPopup() + { + if(m_textBrowser) delete m_textBrowser; + m_textBrowser = NULL; + if(m_htmlPart) delete m_htmlPart; + m_htmlPart = NULL; + } + + + /* public */ + void ResPopup::setText( const QString& str ) + { + + QString style = QString( "style=\"font-size: %1pt; " + "font-family: %2; " + "color: %3; " + "background-color: %4; border-width: 0; \"" ) + .arg( KitaConfig::threadFont().pointSize() ) + .arg( KitaConfig::threadFont().family() ) + .arg( KitaConfig::popupColor().name() ) + .arg( KitaConfig::popupBackgroundColor().name() ); + + QString text = ""; + text += ""; + text += str + ""; + + if( m_textBrowser ) m_textBrowser->setText( text ); + + if( m_htmlPart ){ + m_htmlPart->setJScriptEnabled(false); + m_htmlPart->setJavaEnabled(false); + m_htmlPart->begin("file:/dummy.htm"); + m_htmlPart->write(text); + m_htmlPart->end(); + m_htmlPart->view()->setVScrollBarMode(QScrollView::AlwaysOff); + } + } + + + /* public */ + void ResPopup::adjustSize() + { + /* config */ + + const int mrg = 50; + const int mrg2 = 10; + + /*---------------------------*/ + + if( !m_textBrowser || !m_htmlPart ) return; + + /* get frame size from qtextbrowser because I could not + get size by resizing the view of KHTMLPart... + ( It is very ugly... Is there any good idea? ) */ + m_textBrowser->resize( m_textBrowser->contentsWidth() + mrg2, + m_textBrowser->contentsHeight() ); + int wd = m_textBrowser->contentsWidth() +mrg; + int ht = m_textBrowser->contentsHeight() +mrg; + delete m_textBrowser; + m_textBrowser = NULL; + + m_htmlPart->view()->resize( wd,ht ); + QFrame::adjustSize(); + } + + + /* public */ + void ResPopup::adjustPos() + { + /* config */ + + const int mrg = 10; + + /*----------------------------*/ + + if( !m_htmlPart ) return; + + QRect qr = QApplication::desktop() ->rect(); + int sw = qr.width(), sh = qr.height(); + int wd = width(), ht = height(); + + QPoint pos = QCursor::pos(); + int x = pos.x(), y = pos.y(); + + if ( x + mrg + wd < sw ) { + x = x + mrg; + y = QMAX( 0, y - ( ht + mrg ) ); + + } else if ( y - ( mrg + ht ) >= 0 ) { + x = QMAX( 0, sw - wd ); + y = y - ( ht + mrg ); + + } else if ( y + ( mrg + ht ) <= sh ) { + x = QMAX( 0, sw - wd ); + y = y + mrg; + + } else if ( x - ( mrg + wd ) >= 0 ) { + x = x - ( mrg + wd ); + y = QMAX( 0, y - ( ht + mrg ) ); + + } else { + x = x + mrg; + y = QMAX( 0, y - ( ht + mrg ) ); + } + + pos.setX( x ); + pos.setY( y ); + move( pos ); + + if( x + wd >= sw ){ + m_htmlPart->view()->setVScrollBarMode( QScrollView::AlwaysOn ); + wd = sw - x; + } + if( y + ht >= sh ){ + m_htmlPart->view()->setVScrollBarMode( QScrollView::AlwaysOn ); + ht = sh - y; + } + m_htmlPart->view()->resize( wd, ht ); + resize( wd, ht ); + } + + + /* move mouse pointer above the popup frame */ /* public */ + void ResPopup::moveMouseAbove() + { + /* config */ + + const int mrg = 10; + + /*-------------------------------*/ + + QPoint pos = QCursor::pos(); + int cx = pos.x(), cy = pos.y(); + int px = x(); + int py = y(); + int wd = width(); + int ht = height(); + + if( cx <= px ) cx = px+mrg; + else if(cx >= px+wd ) cx = px+wd-mrg; + + if( cy <= py ) cy = py+mrg; + else if( cy >= py+ht ) cy = py+ht-mrg; + + QCursor::setPos( cx, cy ); + } + +} + diff --git a/kita/src/part/kitahtmlpart.h b/kita/src/part/kitahtmlpart.h index 8b6331f..dc29173 100644 --- a/kita/src/part/kitahtmlpart.h +++ b/kita/src/part/kitahtmlpart.h @@ -1,5 +1,5 @@ /*************************************************************************** -* Copyright (C) 2003 by Hideki Ikemoto * +* Copyright (C) 2003 by Hideki Ikemoto , 2004 by 421 * * ikemo@users.sourceforge.jp * * * * This program is free software; you can redistribute it and/or modify * @@ -11,69 +11,221 @@ #ifndef KITAHTMLPART_H #define KITAHTMLPART_H -#include #include +#include -#include +/* mode */ +enum { + HTMLPART_MODE_KHTML, /* This part is not initialized. This part works as just KHTMLPart */ -#include // for gcc-2.9x -template class QValueStack; + HTMLPART_MODE_MAINPART,/* on main window */ + HTMLPART_MODE_NAVI, /* on Kita Navi */ + HTMLPART_MODE_POPUP /* on popup */ +}; -namespace Kita + +class KitaHTMLPart; +class KitaDomTree; +class KitaThreadView; +class KPopupMenu; +class KURL; + +namespace Kita{ + class ResPopup; +} + +namespace DOM { - class Thread; +class Node; } -class KPopupMenu; -#include -class KitaDomTree; -class KitaThreadView; +/*-------------------------------------------------------------*/ -/** -@author Hideki Ikemoto -*/ class KitaHTMLPart : public KHTMLPart { Q_OBJECT - QWidget* m_parent; - KPopupMenu* m_popupMenu; + KitaDomTree* m_domtree; + Kita::ResPopup* m_popup; + + /* basic information */ + int m_mode; + KURL m_datURL; + bool m_updatedKokoyon; + + bool m_check[ 1200 ]; /* I will move this variable to DatInfo later. */ + + + /* cache */ + bool m_firstReceive; + int m_centerNum; + + /* goto anchor */ + QStringList m_anchorStack; + + /* mouse event */ bool m_pushctrl; bool m_pushmidbt; bool m_pushrightbt; - KitaDomTree* m_domtree; - KitaThreadView* m_threadView; - Kita::Thread* m_thread; - QStringList m_anchorStack; + /* search */ + DOM::Node m_findNode; + int m_findPos; + int m_find_y; + + /* res popup */ + bool m_multiPopup; + bool m_kitaIsActive; + + public: - void pushCurrentPosition(); - bool gotoAnchor( const QString& name ); KitaHTMLPart( QWidget* parent, const char* name = 0 ); ~KitaHTMLPart(); - void setupEx( KitaThreadView* threadView, KitaDomTree* domtree, - Kita::Thread* thread ); - void gotoKokoyon(); - bool isCtrlClick(){return m_pushctrl;} - bool isMidClick(){return m_pushmidbt;} - bool isRightClick(){return m_pushrightbt;} + bool setup( int mode , const KURL& url ); + const int getMode() const; + + /* rendering */ + void showResponses( int startnum, int endnum ); + void parseResponses( int startnum, int endnum ); + void showAll(); + void insertBeltNode( const QString& idstr ); + void insertHeaderNode( const QString& str ); + void insertFooterNode( const QString& str ); + void updateScreen( bool showHeaderEtc, bool clock); + void setInnerHTML( const QString& innerHTML ); + + /* cache */ + bool load( int centerNum ); + bool reload(); + + /* goto anchor */ + bool gotoAnchor( const QString& anc, bool pushPosition ); + + /* search */ + bool findText( const QString &query, bool reverse ); -protected: - virtual void khtmlMousePressEvent( khtml::MousePressEvent* e ); - virtual void khtmlMouseReleaseEvent( khtml::MouseReleaseEvent *e ); - virtual void khtmlMouseMoveEvent( khtml::MouseMoveEvent* e ); public slots: - bool gobackAnchor(); + /* rendering */ + void slotRedrawScreen( const KURL& datURL, bool force ); + + /* cache */ + void slotReceiveData(); + void slotFinishLoad(); + + /* goto anchor */ + void slotGotoKokoyon(); + void slotGobackAnchor(); + + /* Tugi100, Mae100 etc. */ + void slotClickTugi100(); + void slotClickNokori(); + void slotClickGotoFooter(); + void slotClickMae100(); + void slotClickMaeZenbu(); + void slotClickTmpNext100(); + void slotClickShowAll(); + + +private: + + void clearPart(); + + /* setup */ + void connectSignals(); + void createHTMLDocument(); + + /* goto anchor */ + void pushCurrentPosition(); + + /* popup menu */ + void showPopupMenu( const KURL& kurl ); + + /* click */ + void clickAnchor( const KURL& urlin ); + void showWritePopupMenu( const QString& refstr); + void showIDPopup( const QString& refstr ); + bool showNext100Etc( const QString& refstr ); + + /* search */ + void findTextInit(); + + /* res popup */ + void showPopup( const KURL& url, const QString& innerHTML ); + bool startMultiPopup(); + bool isMultiPopupMode(); + void hidePopup(); + void deletePopup(); + bool isUnderMouse( int mrgwd, int mrght ); + bool showSelectedDigitPopup(); + +protected: + + /* mouse event */ + virtual void khtmlMousePressEvent( khtml::MousePressEvent* e ); + + private slots: - void slotPopupMenu( const QString& url, const QPoint& point ); + /* click */ + void slotOpenURLRequest( const KURL&, const KParts::URLArgs& ); + + /* res popup */ + void slotLeave(); + void slotVSliderReleased(); + void slotHSliderReleased(); + void slotHideChildPopup(); + void slotKitaIsActive(); + void slotOnURL( const QString& url ); + + signals: - void setLocationBarURL( const QString &url ); - void openURLRequest( const KURL& url, const KParts::URLArgs& args = KParts::URLArgs() ); + + void openWriteDialog( QString ); + void openURLRequest( const KURL& url, const KParts::URLArgs &args = KParts::URLArgs() ); + void redrawScreen( const KURL& url, bool force ); + + /* cache */ + void receiveData(); + void finishReload(); + + /* res popup */ + void hideChildPopup(); + void isKitaActive(); }; + + +/*---------------------------------------------------*/ +/*---------------------------------------------------*/ +/*---------------------------------------------------*/ + + +namespace Kita +{ + class ResPopup : public QFrame + { + Q_OBJECT + + KitaHTMLPart* m_htmlPart; + QTextBrowser* m_textBrowser; + + public: + ResPopup( KHTMLView* view, const KURL& datURL ); + ~ResPopup(); + void setText( const QString& str ); + void adjustSize(); + void adjustPos(); + void moveMouseAbove(); + + signals: + void hideChildPopup(); + }; +} + + + #endif diff --git a/kita/src/part/kitahtmlview.cpp b/kita/src/part/kitahtmlview.cpp index 52020b8..0654c43 100644 --- a/kita/src/part/kitahtmlview.cpp +++ b/kita/src/part/kitahtmlview.cpp @@ -27,15 +27,35 @@ void KitaHTMLView::leaveEvent( QEvent* ) emit leave(); } +/* protected */ void KitaHTMLView::keyPressEvent( QKeyEvent* e ) { - if ( e->key() == Key_Space || e->key() == Key_PageDown ) { - int y = contentsY(); - if( y >= contentsHeight() - visibleHeight() ){ - emit pushDown(); - return; - } + if ( e->key() == Key_Space || e->key() == Key_PageDown + || e->key() == Key_Down || e->key() == Key_End ) { + if( emitPushDown() ) return; } KHTMLView::keyPressEvent( e ); } + +/* protected */ +void KitaHTMLView::viewportWheelEvent(QWheelEvent * e) +{ + if( e->delta() < 0 ){ /* scroll down */ + if( emitPushDown() ) return; + } + + KHTMLView::viewportWheelEvent( e ); +} + +/* private */ +bool KitaHTMLView::emitPushDown(){ + + int y = contentsY(); + if( y >= contentsHeight() - visibleHeight() ){ + emit pushDown();/* to KitaHTMLPart in order to call slotClickTugi100 */ + return TRUE; + } + + return FALSE; +} diff --git a/kita/src/part/kitahtmlview.h b/kita/src/part/kitahtmlview.h index b44c7e3..82b1e99 100644 --- a/kita/src/part/kitahtmlview.h +++ b/kita/src/part/kitahtmlview.h @@ -25,6 +25,11 @@ public: protected: void leaveEvent( QEvent* ); void keyPressEvent( QKeyEvent* e ); + void viewportWheelEvent(QWheelEvent * e); + +private: + bool emitPushDown(); + signals: void leave(); void pushDown(); diff --git a/kita/src/part/kitathreadpart.cpp b/kita/src/part/kitathreadpart.cpp index ce3b2b6..99f4573 100644 --- a/kita/src/part/kitathreadpart.cpp +++ b/kita/src/part/kitathreadpart.cpp @@ -11,6 +11,7 @@ #include "kitahtmlpart.h" #include "libkita/board.h" #include "libkita/signalcollection.h" +#include "libkita/datmanager.h" //static const char * version = $VERSION$; static const char* version = "1.0"; @@ -103,7 +104,7 @@ bool KitaThreadPart::openURL( const KURL& _url ) connect( Kita::SignalCollection::getInstance(), SIGNAL( showThreadCompleted( const KURL& ) ), this, SLOT( slotOpenURLResult() ) ); - m_threadview->showThread( Kita::Thread::getByURL( m_url.url() ) ); + m_threadview->showThread( m_url, Kita::DatManager::getKokoyonNum( m_url ) ); emit started( 0 ); return true; } diff --git a/kita/src/part/kitathreadview.cpp b/kita/src/part/kitathreadview.cpp index 13ec57e..660c083 100644 --- a/kita/src/part/kitathreadview.cpp +++ b/kita/src/part/kitathreadview.cpp @@ -70,11 +70,10 @@ static const char* cookie_message = "Á´ÀÕǤ¤òÉ餦¤³¤È¤ò¾µÂú¤·¤Æ½ñ¤­¹þ¤ß¤Þ¤¹¤«\n"; KitaThreadView::KitaThreadView( QWidget* parent, const char* name ) - : KitaThreadViewBase( parent, name ), m_popup( 0 ) + : KitaThreadViewBase( parent, name ) { m_thread = new Kita::NullThread(); m_threadPart = new KitaHTMLPart( threadFrame ); - m_domtree = new KitaDomTree( m_threadPart ); QHBoxLayout* aLayout = new QHBoxLayout( threadFrame ); aLayout->addWidget( m_threadPart->view() ); @@ -106,12 +105,12 @@ KitaThreadView::KitaThreadView( QWidget* parent, const char* name ) connect( writeButton, SIGNAL( clicked() ), SLOT( slotWriteButtonClicked() ) ); + connect( m_threadPart, SIGNAL( openWriteDialog( QString ) ), + SLOT( slotWriteButtonClicked ( QString ) ) ); + connect( m_threadPart, SIGNAL( finishReload() ), + SLOT( slotUpdateInfo() ) ); connect( m_threadPart, SIGNAL( nodeActivated( const DOM::Node& ) ), SLOT( slotDOMNodeActivated( const DOM::Node& ) ) ); - connect( m_threadPart, SIGNAL( onURL( const QString& ) ), - SLOT( slotOnURL( const QString& ) ) ); - connect( m_threadPart, SIGNAL( setLocationBarURL( const QString& ) ), - SIGNAL( setLocationBarURL( const QString& ) ) ); connect( BookmarkButton, SIGNAL( toggled( bool ) ), SLOT( slotBookmarkButtonClicked( bool ) ) ); connect( SearchButton, SIGNAL( clicked() ), @@ -119,7 +118,7 @@ KitaThreadView::KitaThreadView( QWidget* parent, const char* name ) connect( SearchCombo, SIGNAL( activated( int ) ), SLOT( slotSearchButton() ) ); connect( GobackAnchorButton, SIGNAL( clicked() ), - m_threadPart, SLOT( gobackAnchor() ) ); + m_threadPart, SLOT( slotGobackAnchor() ) ); connect( ReloadButton, SIGNAL( clicked() ), SLOT( slotReloadButton() ) ); connect( gotoCombo, SIGNAL( activated( int ) ), @@ -127,12 +126,8 @@ KitaThreadView::KitaThreadView( QWidget* parent, const char* name ) KParts::BrowserExtension* ext = m_threadPart->browserExtension(); Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance(); - connect( ext, SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ), - SLOT( slotOpenURLRequest( const KURL&, const KParts::URLArgs& ) ) ); connect( this, SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ), signalCollection, SIGNAL( openURLRequest( const KURL&, const KParts::URLArgs& ) ) ); - connect( this, SIGNAL( writeSucceeded() ), - signalCollection, SIGNAL( writeSucceeded() ) ); connect( ext, SIGNAL( createNewWindow ( const KURL&, const KParts::URLArgs& ) ), SIGNAL( createNewWindow ( const KURL&, const KParts::URLArgs& ) ) ); connect( ext, SIGNAL( setLocationBarURL( const QString& ) ), @@ -161,21 +156,6 @@ KitaThreadView::KitaThreadView( QWidget* parent, const char* name ) KitaThreadView::~KitaThreadView() { - if ( m_popup ) - { - delete m_popup; - m_popup = NULL; - } - - /* unlock URL */ - Kita::DatManager::unlock(m_datURL); - - /* don't delete m_threadPart before deleting m_domtree */ - if ( m_domtree ) - { - delete m_domtree; - m_domtree = NULL; - } if ( m_threadPart ) { delete m_threadPart; @@ -266,7 +246,6 @@ void KitaThreadView::slotShowErrorDialog( const QString& input, const KURL& ) { case Kita::K2ch_Unknown: // probably OK. - emit writeSucceeded(); slotReloadButton(); break; case Kita::K2ch_True: @@ -316,6 +295,7 @@ KitaWriteDialog* KitaThreadView::openDialog( const Kita::PostInfo& info ) /*--------------------*/ /* private slots */ void KitaThreadView::slotWriteButtonClicked( QString resstr ) { + m_serverTime = Kita::DatManager::getServerTime(m_datURL); if ( ! m_serverTime ) return ; // TODO: machiBBS kakiko support. @@ -366,14 +346,6 @@ QStringList KitaThreadView::parseSearchQuery( const QString& input ) const } -void KitaThreadView::hidePopup() -{ - if ( m_popup ) - { - m_popup->hide(); - } -} - void KitaThreadView::slotPopupMenu( KXMLGUIClient* client, const QPoint& global, const KURL& url, const QString& mimeType, mode_t mode ) { KActionCollection * collection = client->actionCollection(); @@ -528,40 +500,6 @@ namespace Kita } } - PopupTextBrowser::PopupTextBrowser( QFrame* frame ) - : QTextBrowser( frame ) - { - zoomOut( static_cast( pointSize() * 0.3 ) ); - setWordWrap( QTextEdit::NoWrap ); - setResizePolicy( QScrollView::AutoOne ); - setFont( KitaConfig::threadFont() ); - setPaletteForegroundColor( KitaConfig::popupColor() ); - setPaletteBackgroundColor( KitaConfig::popupBackgroundColor() ); - } - - PopupTextBrowser::~ PopupTextBrowser() - {} - - ResPopup::ResPopup( KHTMLView* view ) - : QFrame( view, "res_popup", WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WType_TopLevel | WX11BypassWM ) - { - m_browser = new Kita::PopupTextBrowser( this ); - } - - ResPopup::~ ResPopup() - {} - - void ResPopup::setText( QString& str ) - { - m_browser->setText( str ); - } - - void ResPopup::adjustSize() - { - m_browser->resize( m_browser->contentsWidth() + 10, m_browser->contentsHeight() ); - QFrame::adjustSize(); - } - } @@ -573,41 +511,25 @@ namespace Kita /*-------*/ /* setup */ /*-------*/ -void KitaThreadView::setupEx( const Kita::Thread* thread, int serverTime, int mode ) +void KitaThreadView::setupEx( const Kita::Thread* thread, int , int mode ) { /* config. */ - /* show m_preShowNum responses before 'kokomade yonda' */ - m_preShowNum = 50; - - /* max size of responses in the popup window */ - m_maxpopup = 10; - /* default name */ m_mailaddr = "sage"; - /* online mode */ - m_online = TRUE; - - /*---------------------------------------*/ /* setup */ - /* unlock previous URL */ - Kita::DatManager::unlock(m_datURL); - m_thread = const_cast( thread ); QString refstr; m_datURL = Kita::ParseMisc::parseURL(m_thread->datURL(),refstr); - /* lock new URL */ - Kita::DatManager::lock(m_datURL); - /* setup HTMLPart */ - m_threadPart->setupEx( this, m_domtree, m_thread ); - - /* setup DOM */ - m_domtree->parseResInit( m_thread ); + int partMode = HTMLPART_MODE_MAINPART; + if( mode == VIEWMODE_KITANAVI ) partMode = HTMLPART_MODE_NAVI; + if( mode == VIEWMODE_PREVIEW ) partMode = HTMLPART_MODE_KHTML; + m_threadPart->setup( partMode, m_datURL ); /* mode. Mode is defined in kitathreadview.h */ m_viewmode = mode; @@ -620,9 +542,6 @@ void KitaThreadView::setupEx( const Kita::Thread* thread, int serverTime, int mo Base->removeItem( layout2 ); } - /* m_serverTime is used for writing */ - m_serverTime = serverTime; - /* reset search direction */ m_revsearch = FALSE; } @@ -632,9 +551,8 @@ void KitaThreadView::setupEx( const Kita::Thread* thread, int serverTime, int mo /* Show thread */ /* This function is called from KitaThreadTabWidget class */ /*--------------------------------------------------------*/ -void KitaThreadView::showThread( const Kita::Thread* thread2h ) +void KitaThreadView::showThread( const KURL& datURL, int num ) { - /* If this widget is not parent, then do nothing. */ if ( m_viewmode != VIEWMODE_PARENT ) return ; @@ -643,37 +561,16 @@ void KitaThreadView::showThread( const Kita::Thread* thread2h ) setActiveWindow(); /* setup */ - setupEx( thread2h , 0, VIEWMODE_PARENT ); + Kita::Thread* thread2ch = Kita::Thread::getByURL( datURL.prettyURL() ); + setupEx( thread2ch , 0, VIEWMODE_PARENT ); /* get log from cahce */ - int maxnum = Kita::DatManager::getMaxResNumber(m_datURL); m_rescode = 200; - if ( maxnum ) - { - /* show templates (No.1->No.KitaDomTree::m_templateNum) */ - m_domtree->appendTemplate(); - - /* rendering */ - m_kokoyonNum = Kita::DatManager::getKokoyonNum(m_datURL); - for ( int i = m_kokoyonNum - m_preShowNum ; i <= m_kokoyonNum ; i++ ) - m_domtree->appendRes( i, FALSE ); - updateScreen(); - - m_threadPart->gotoKokoyon(); - } - else - { - m_kokoyonNum = 0; - showStatusBar( "" ); - } + if( !m_threadPart->load( num ) ) showStatusBar( "" ); /* update data */ - updateInfo(); - m_firstReceive = TRUE; - if( m_online ) slotReloadButton(); - - topLevelWidget() ->raise(); - setActiveWindow(); + slotUpdateInfo(); + slotReloadButton(); } @@ -683,78 +580,14 @@ void KitaThreadView::showThread( const Kita::Thread* thread2h ) /*---------*/ /* public slot */ void KitaThreadView::slotReloadButton() { - switch ( m_viewmode ) - { - - case VIEWMODE_PREVIEW: break; - - case VIEWMODE_PARENT: - - /* update cache */ - /* After updating cache, DatManager will call slotFinishLoad.*/ - if( m_online ) - { - m_domtree->StopParseThread(); - if ( KitaConfig::afterShowNum() != 0 ) { - m_showNum = m_domtree->getBottomResNumber() + KitaConfig::afterShowNum(); - } else { - // TODO: fix it. - m_showNum = 5000; - } - Kita::DatManager::updateCache(m_datURL,this); - m_threadPart->view()->setFocus(); - showStatusBar( Kita::ParseMisc::utf8ToUnicode( KITAUTF8_NOWRENEW ) ); - } - break; - - default: - - /* When this is not parent, show the thread with new tab */ - KParts::URLArgs tmp; - emit openURLRequest( m_thread->datURL() , tmp ); - break; - - } -} - -/*-----------------------------------*/ -/* slot called when Kita::DatManager - received new data. */ /* public slot */ -void KitaThreadView::slotReceiveData() -{ - - int bottomNum = m_domtree->getBottomResNumber(); - int afterNum = Kita::DatManager::getMaxResNumber(m_datURL); - - m_rescode = Kita::DatManager::getResponseCode(m_datURL); - m_serverTime = Kita::DatManager::getServerTime(m_datURL); - - /* rendering */ - if( (m_firstReceive && bottomNum < afterNum ) - || (bottomNum + 20 < afterNum && m_showNum +2 >= afterNum ) ) - { - for ( int i = bottomNum+1 ; i <= QMIN( m_showNum, afterNum ) ; i++ ) m_domtree->appendRes( i, FALSE ); - updateScreen(); - if(m_firstReceive && m_kokoyonNum < afterNum ) - { - m_threadPart->gotoKokoyon(); - m_firstReceive = FALSE; - } + topLevelWidget() ->raise(); + setActiveWindow(); + + if( m_threadPart->reload() ){ + showStatusBar( Kita::ParseMisc::utf8ToUnicode( KITAUTF8_NOWRENEW ) ); } } -/*-----------------------------------*/ -/* slot called when Kita::DatManager - finished updating new data. */ /* public slot */ -void KitaThreadView::slotFinishLoad() -{ - - m_firstReceive = FALSE; - int bottomNum = m_domtree->getBottomResNumber(); - for ( int i = bottomNum+1 ; i <= m_showNum; i++ ) m_domtree->appendRes( i, FALSE ); - updateScreen(); - updateInfo(); -} /*-----------------------------------*/ /* stop loading the thread */ /* public slot */ @@ -763,279 +596,6 @@ void KitaThreadView::slotStopLoading(){ } -/*---------------------------------------------------*/ -/* This function is called when user clicks the link */ -/*---------------------------------------------------*/ /* public slot */ -void KitaThreadView::slotOpenURLRequest( const KURL& urlin, const KParts::URLArgs& args ) -{ - KURL url = urlin; - - /* convert to the correct URL */ - /* see also comments in KitaDomTree::createHTMLDocument for details */ - if ( urlin.protocol() == "file" ) - { - - if ( urlin.prettyURL().mid( 5, 14 ) == "/test/read.cgi" ) - url = KURL( m_thread->datURL(), ".." + urlin.prettyURL().mid( 5 ) ); - else - url = KURL( m_thread->datURL(), urlin.prettyURL().mid( 15 ) ); - } - - KURL datURL = filterReadCGI( url , m_thread ); - - /* If this is not anchor, then emit openURLRequest and return */ - if ( datURL.host() != KURL( m_thread->datURL() ).host() - || datURL.path() != KURL( m_thread->datURL() ).path() ) - { - emit openURLRequest( datURL, args ); - return ; - } - - if ( ! datURL.hasRef() ) return ; - if ( m_viewmode == VIEWMODE_PREVIEW ) return ; - - /*---------------------------*/ - /* show popupmenu for #write */ - - if ( datURL.ref().left( 5 ) == "write" ) - { - - QClipboard * clipboard = QApplication::clipboard(); - QString str, resstr; - int resNum = datURL.ref().mid( 5 ).toInt(); - - /* show res tree on the popup */ - if(m_threadPart->isRightClick()) - { - int num; - QString htmlstr - = Kita::DatManager::getTreeByRes(m_thread->datURL(),resNum,num); - if ( !num ) return ; - QString tmpstr = QString("
No.%1 : [%2]
").arg(resNum).arg(num); - tmpstr += htmlstr; - tmpstr += "

"; - showPopup( tmpstr, QString::null ); - return; - } - /* show tree on the kitanavi */ - else if(m_threadPart->isCtrlClick() || m_threadPart->isMidClick()) - { - KitaNavi::showKitaNaviResTree(m_datURL,resNum); - return; - } - - KPopupMenu *popupMenu = new KPopupMenu( m_threadPart->view() ); - popupMenu->clear(); - popupMenu->insertItem( i18n( "write response" ), 0 ); - popupMenu->insertItem( i18n( "quote this" ), 1 ); - popupMenu->insertItem( i18n( "copy" ), 3 ); - if ( m_viewmode == VIEWMODE_PARENT ) - { - popupMenu->insertSeparator(); - popupMenu->insertItem( i18n( "set Kokomade Yonda" ), 2 ); - } - - switch ( popupMenu->exec( QCursor::pos() ) ) - { - case 0: - resstr = ">>" + QString().setNum( resNum ) + "\n"; - break; - - case 1: - resstr = ">>" + QString().setNum( resNum ) + "\n"; - resstr += m_domtree->getResStr( resNum, "> " ); - break; - - case 2: - delete popupMenu; - m_kokoyonNum = resNum; - Kita::DatManager::setKokoyonNum(m_datURL,resNum); - updateScreen(); - gotoAnchor( QString().setNum( resNum ) ); - return ; - - case 3: - delete popupMenu; - str = threadName() - + "\n" + threadURL().url() + QString().setNum( resNum ) - + "\n\n" + m_domtree->getResStr( resNum, "" ); - clipboard->setText( str , QClipboard::Clipboard ); - clipboard->setText( str , QClipboard::Selection ); - return ; - - default: - delete popupMenu; - return ; - } - - delete popupMenu; - slotWriteButtonClicked( resstr ); - return ; - } - - /*----------------------------*/ - /* extract responses by ID */ - - if(datURL.ref().left(5) == "idpop") - { - - QString strid = datURL.ref().mid(5).replace("%2B","+").replace("%2F", "/"); /* decode %2B -> +, %2F -> / */ - - /* show them on the popup */ - if(m_threadPart->isRightClick()) - { - int num; - QString htmlstr - = Kita::DatManager::getHtmlByID(m_thread->datURL(),strid,num ); - if ( num <= 1 ) return ; - QString tmpstr = QString("
ID:%1:[%2]
").arg(strid).arg(num); - tmpstr += htmlstr; - tmpstr += "

"; - showPopup( tmpstr, QString::null ); - } - - /* show them on the kitanavi */ - else if(m_threadPart->isCtrlClick() || m_threadPart->isMidClick()) - KitaNavi::showKitaNaviByID(m_datURL,strid); - else - { - KPopupMenu *popupMenu = new KPopupMenu( m_threadPart->view() ); - popupMenu->clear(); - popupMenu->insertItem( i18n( "add id to abone list" ), 0 ); - switch ( popupMenu->exec( QCursor::pos() ) ) - { - case 0: - KitaConfig::addAboneID( strid ); - delete popupMenu; - break; - default: - delete popupMenu; - break; - } - } - - return; - } - - /*----------------------------*/ - /* next 100 ,before 100 ,etc. */ - - int top = m_domtree->getTopResNumber(); - int bottom = m_domtree->getBottomResNumber(); - int totalNum = Kita::DatManager::getMaxResNumber(m_datURL); - - if ( datURL.ref().left( 7 ) == "tugi100" ) - { - - if ( totalNum != bottom ) - { - appendRes( bottom + 1, bottom + 100 ); - } - gotoAnchor( QString().setNum( bottom ) ); - return ; - - } - else if ( datURL.ref().left( 6 ) == "nokori" ) - { - - if ( totalNum != bottom ) - { - appendRes( bottom + 1, totalNum ); - } - gotoAnchor( QString().setNum( bottom ) ); - return ; - - } - else if ( datURL.ref().left( 7 ) == "tosaigo" ) - { - - if ( totalNum != bottom ) - { - appendRes( bottom + 1, totalNum ); - } - gotoAnchor( "footer" ); - return ; - - } - else if ( datURL.ref().left( 6 ) == "mae100" ) - { - - if ( top != 1 ) - { - m_domtree->appendTemplate(); - appendRes( top - 100, bottom ); - gotoAnchor( QString().setNum( top ) ); - } - return ; - - } - else if ( datURL.ref().left( 8 ) == "maezenbu" ) - { - - if ( top != 1 ) - { - appendRes( 1, bottom ); - gotoAnchor( QString().setNum( top ) ); - } - return ; - - } - else if ( datURL.ref().left( 6 ) == "tmp100" ) - { - - int tmpnum = m_domtree->getTemplateNumber(); - - if ( tmpnum < top ) - { - m_domtree->setTemplateNumber( tmpnum + 100 ); - m_domtree->appendTemplate(); - appendRes( top, bottom ); - gotoAnchor( QString().setNum( tmpnum ) ); - } - return ; - - } - else if ( datURL.ref().left( 5 ) == "zenbu" ) - { - - if ( top != 1 || bottom != totalNum ) - { - appendRes( 1, totalNum ); - gotoAnchor( "header" ); - } - return ; - - } - - /*---------------------*/ - /* jump to anchor */ - - QString refstr = datURL.ref(); - int refNum,refNum2; - - int i = refstr.find( "-" ); - if ( i != -1 ) - { - refNum = refstr.left( i ).toInt(); - refNum2 = QMIN(refstr.mid(i+1).toInt(),totalNum); - if(refNum2 < refNum) refNum2 = refNum; - refstr = datURL.ref().left( i ); - } - else refNum = refNum2 = refstr.toInt(); - - if ( !refNum ) return ; - - /* show Kita Navi or goto anchor */ - if(m_threadPart->isCtrlClick() || m_threadPart->isMidClick() - || m_viewmode == VIEWMODE_KITANAVI) - { - KitaNavi::showKitaNavi(m_datURL,refNum,refNum2); - } - else gotoAnchor( refstr ); -} - - - /*-----------------------------------------*/ /* show the information at the statusbar. */ /*-----------------------------------------*/ @@ -1045,7 +605,8 @@ void KitaThreadView::showStatusBar( QString info ) bool broken = FALSE; QString infostr = QString::null; QString errstr = QString::null; - + int kokoyonNum = Kita::DatManager::getKokoyonNum(m_datURL); + switch( m_viewmode ) { @@ -1062,7 +623,7 @@ void KitaThreadView::showStatusBar( QString info ) /* show status bar */ infostr = m_thread->name() + - QString( " [Total: %1 New: %2] %3 k" ).arg( totalNum ).arg( totalNum - m_kokoyonNum ).arg( datSize / 1024 ) + QString( " [Total: %1 New: %2] %3 k" ).arg( totalNum ).arg( totalNum - kokoyonNum ).arg( datSize / 1024 ) + info + " " + errstr; emit signalChangeStatusbar( infostr ); @@ -1084,115 +645,13 @@ void KitaThreadView::showStatusBar( QString info ) -/* TODO: need to write test case. */ /* !!! public & static !!! */ -KURL KitaThreadView::filterReadCGI( const KURL& url, const Kita::Thread* thread ) -{ - KURL newURL = url; - - if ( url.path().contains( "/test/read.cgi" ) ) - { - newURL.setProtocol( KURL( thread->datURL() ).protocol() ); - QString tmp = url.path().section( "/test/read.cgi", 1 ); - - QString newPath = QString( "/%1/dat/%2.dat" ) - .arg( tmp.section( '/', 1, 1 ) ) - .arg( tmp.section( '/', 2, 2 ) ); - newURL.setPath( newPath ); - - QString refBase = tmp.section( '/', 3 ); - if ( ! refBase.isEmpty() ) - { - - QString newRef; - if ( refBase.at( 0 ) == '-' ) newRef = "1" + refBase; - else newRef = refBase; - - newURL.setRef( newRef ); - - } - } - kdDebug() << "newURL: " << newURL.url() << endl; - return newURL; -} - - - - - -/*----------------------*/ -/* move to anchor */ -/*----------------------*/ -void KitaThreadView::gotoAnchor( QString anc ) -{ - - int top = m_domtree->getTopResNumber(); - int bottom = m_domtree->getBottomResNumber(); - int res = anc.toInt(); - - if ( res == 1 ) - { - anc = "header"; - } - else if ( res > 1 ) - { - - /* data is not set */ - if ( !m_domtree->isResDataSet( res ) ) return ; - - /* show res if it is not shown */ - if ( !m_domtree->isResShown( res ) ) - { - - if ( res > bottom ) appendRes( bottom + 1, res + 99 ); - else if ( res < top ) - { - m_domtree->appendTemplate(); - appendRes( res, bottom ); - } - } - - /* aboned */ - if ( !m_domtree->isResShown( res ) ) - { - while ( res > 0 ) - { - if ( m_domtree->isResShown( res ) ) break; - res--; - } - } - - anc = QString().setNum( res ); - } - - m_threadPart->gotoAnchor( anc ); -} - - -/*-------------------*/ -/* update screen */ /* public */ -void KitaThreadView::updateScreen() -{ - int totalNum = Kita::DatManager::getMaxResNumber(m_datURL); - - /* set header, footer , etc. */ - m_domtree->appendMae100(); - m_domtree->appendTugi100(); - m_domtree->setKokoyonNum( m_kokoyonNum ); - m_domtree->appendKokoyon(); - m_domtree->appendFooter( totalNum ); - - /* update display */ - m_threadPart->htmlDocument().applyChanges(); - m_threadPart->view() ->layout(); - m_threadPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn ); - -} - /*--------------------*/ /* update information */ /* public */ -void KitaThreadView::updateInfo() +void KitaThreadView::slotUpdateInfo() { + m_rescode = Kita::DatManager::getResponseCode(m_datURL); + m_serverTime = Kita::DatManager::getServerTime(m_datURL); /* uptate informations */ setSubjectLabel(Kita::DatManager::thread_boardName(m_datURL), @@ -1201,204 +660,13 @@ void KitaThreadView::updateInfo() .arg( Kita::DatManager::getMaxResNumber(m_datURL) ), Kita::DatManager::thread_boardURL( m_datURL ) ); emit showThreadCompleted( Kita::DatManager::thread_url(m_datURL) ); - m_domtree->findTextInit(); updateButton(); - - gotoCombo->clear(); - gotoCombo->insertItem( Kita::ParseMisc::utf8ToUnicode( KITAUTF8_GOTO ) ); - gotoCombo->insertItem( Kita::ParseMisc::utf8ToUnicode( KITAUTF8_KOKOYON ) ); - for( int i = 1; i < m_thread->resNum(); i += 100 ) - { - gotoCombo->insertItem( QString().setNum( i ) + "-" ); - } - gotoCombo->insertItem( Kita::ParseMisc::utf8ToUnicode( KITAUTF8_SAIGO ) ); - gotoCombo->adjustSize(); - emit signalThread( m_thread ); showStatusBar( "" ); - m_threadPart->view() ->setFocus(); - m_domtree->parseAllRes(); } -/*-------------------*/ -/* append responses */ -/*-------------------*/ -void KitaThreadView::appendRes( int startnum, int endnum ) -{ - - showStatusBar( Kita::ParseMisc::utf8ToUnicode( KITAUTF8_NOWEXPAND ) ); - - /* show clock cursor */ - QCursor qc; qc.setShape( Qt::WaitCursor ); - QApplication::setOverrideCursor( qc ); - - for ( int i = startnum ; i <= endnum; i++ ) m_domtree->appendRes( i, FALSE ); - - updateScreen(); - showStatusBar( "" ); - QApplication::restoreOverrideCursor(); -} - -/*---------------------*/ -/* open popup window */ -/*---------------------*/ -void KitaThreadView::showPopup( QString innerHTML, QString imgfile ) -{ - - if ( m_popup ) - { - delete m_popup; - m_popup = NULL; - } - - /* text popup */ - if ( imgfile == NULL ) - { - m_popup = new Kita::ResPopup( m_threadPart->view() ); - m_popup->setText( innerHTML ); - m_popup->adjustSize(); - } - - connect( m_threadPart->view(), SIGNAL( leave() ), SLOT( hidePopup() ) ); - - QRect qr = QApplication::desktop() ->rect(); - int sw = qr.width(), sh = qr.height(); - int pw = m_popup->width(), ph = m_popup->height(); - const int mrg = 10; - - QPoint pos = QCursor::pos(); - int x = pos.x(), y = pos.y(); - - if ( x + mrg + pw < sw ) - { - x = x + mrg; - y = QMAX( 0, y - ( ph + mrg ) ); - } - else if ( y - ( mrg + ph ) >= 0 ) - { - x = QMAX( 0, sw - pw ); - y = y - ( ph + mrg ); - } - else if ( y + ( mrg + ph ) <= sh ) - { - x = QMAX( 0, sw - pw ); - y = y + mrg; - } - else if ( x - ( mrg + pw ) >= 0 ) - { - x = x - ( mrg + pw ); - y = QMAX( 0, y - ( ph + mrg ) ); - } - else - { - x = x + mrg; - y = QMAX( 0, y - ( ph + mrg ) ); - } - - pos.setX( x ); - pos.setY( y ); - - m_popup->move( pos ); - m_popup->show(); - -} - -/*------------------------------------------------------*/ -/* This function is called when the mouse is on the URL */ -/*------------------------------------------------------*/ /* private slots */ -void KitaThreadView::slotOnURL( const QString& url ) -{ - hidePopup(); - if ( !isActiveWindow() ) return ; - if ( url.isEmpty() ) return ; - - if ( m_popup ) - { - delete m_popup; - m_popup = NULL; - } - - /* id popup */ - if ( url.left( 6 ) == "#idpop" ) - { - int num = Kita::DatManager::getNumByID( m_thread->datURL(), url.mid( 6 ) ); - if ( num <= 1 ) return ; - QString tmpstr = QString( "
ID:%1:[%2]

" ).arg( url.mid( 6 ) ).arg( num ); - showPopup( tmpstr, QString::null ); - return ; - } - - /*-------------------------*/ - /* popup for anchor */ - - QString innerHTML = QString::null; - QString refstr; - KURL datURL = m_thread->datURL(); - int refNum; - int refNum2; - - if ( url.at( 0 ) == '#' ) refstr = url.mid( 1 ); - else if ( url.left( 7 ) == "mailto:" ) - { - DOM::Node node = m_threadPart->nodeUnderMouse().firstChild(); - QString nodeValue = node.nodeValue().string(); - refstr = nodeValue; - } - else - { - datURL = filterReadCGI( KURL( m_thread->datURL(), url ) , m_thread ); - refstr = datURL.ref(); - } - - /* Is this url 2ch ? */ - /* copied from KitaThreadTabWidget::slotOpenURLRequest */ - QRegExp regexp( "http://([^/]*)/([^/]*)/dat/(.*)\\.dat" ); - if ( regexp.search( datURL.url() ) == -1 ) { - if( Kita::boardType( datURL.url() ) != Kita::Board_MachiBBS ) - return ; - } - - int i = refstr.find( "-" ); - if ( i != -1 ) - { /* >>refNum-refNum2 */ - - refNum = refstr.left( i ).toInt(); - refNum2 = refstr.mid( i + 1 ).toInt(); - - if ( refNum ) - { - if ( refNum2 < refNum ) refNum2 = refNum; - if ( refNum2 - refNum > m_maxpopup - 1 ) refNum2 = refNum + m_maxpopup - 1; - } - - } - else - { /* >>refNum */ - refNum = refstr.toInt(); - refNum2 = refNum; - } - - /* another thread ? */ - if ( datURL.host() != KURL( m_thread->datURL() ).host() - || datURL.path() != KURL( m_thread->datURL() ).path() ) - { - - /* show subject */ - innerHTML = Kita::DatManager::getSubject( datURL ); - if ( innerHTML != QString::null ) innerHTML += "

"; - - if ( !refNum ) refNum = refNum2 = 1; - } - - /* get HTML and show it */ - if ( !refNum ) return ; - innerHTML += Kita::DatManager::getHtml( datURL, refNum, refNum2 ); - - if ( innerHTML != QString::null ) showPopup( innerHTML, QString::null ); -} - /*------------------------*/ /* search function */ @@ -1414,7 +682,7 @@ void KitaThreadView::slotSearchButton() if ( str.at( 0 ) == ':' ) { QString anc = str.mid( 1 ); - gotoAnchor( anc ); + m_threadPart->gotoAnchor( anc, TRUE ); SearchCombo->setFocus(); return ; } @@ -1428,20 +696,11 @@ void KitaThreadView::slotSearchButton() } /* if this is parent, then show all responses, and search */ - if ( m_viewmode == VIEWMODE_PARENT ) - { - int top = m_domtree->getTopResNumber(); - int bottom = m_domtree->getBottomResNumber(); - int totalNum = m_domtree->getMaxResNumber(); - if ( top != 1 || bottom != totalNum ) - { - appendRes( 1, totalNum ); - } - } + if ( m_viewmode == VIEWMODE_PARENT ) m_threadPart->showAll(); insertSearchCombo(); QStringList list = parseSearchQuery( SearchCombo->currentText() ); - m_domtree->findText( SearchCombo->currentText(), m_revsearch ); + m_threadPart->findText( SearchCombo->currentText(), m_revsearch ); SearchCombo->setFocus(); } // vim:sw=2: @@ -1451,18 +710,18 @@ void KitaThreadView::slotComboActivated( int index ) if ( index == gotoCombo->count() - 1 ) { // last - gotoAnchor( "footer" ); + m_threadPart->gotoAnchor( "footer", TRUE ); } else if ( index == 1 ) { // kokomade yonda - gotoAnchor( "kokomade_yonda" ); + m_threadPart->gotoAnchor( "kokomade_yonda", TRUE ); } else if ( index != 0 ) { QString numText = gotoCombo->text( index ); numText.truncate( numText.length() - 1 ); - gotoAnchor( numText ); + m_threadPart->gotoAnchor( numText, TRUE ); } } @@ -1473,31 +732,29 @@ void KitaThreadView::slotComboActivated( int index ) /*---------------------*/ /* set data & parse it */ /*---------------------*/ /* public */ -void KitaThreadView::domAppendData( QString& str, int bufnum , int num ) +void KitaThreadView::domAppendData( QString& , int bufnum , int ) { - m_domtree->appendRes( bufnum, FALSE ); + m_threadPart->showResponses(bufnum,bufnum); } /* public */ -void KitaThreadView::domDeleteRes( int bufnum ) +void KitaThreadView::domDeleteRes( int ) { - m_domtree->removeRes( bufnum ); + } /* public */ void KitaThreadView::domAppendBelt( QString idstr ) { - m_domtree->createBeltNode( idstr ); + m_threadPart->insertBeltNode(idstr); } /* public */ void KitaThreadView::domSetInnerHTML(const QString& html ) { - m_threadPart->htmlDocument().body().setInnerHTML(html); - KitaThreadViewBaseLayout->remove( subjectLabel ); - KitaThreadViewBaseLayout->removeItem( layout2 ); + m_threadPart->setInnerHTML( html ); showStatusBar( "" ); } @@ -1511,37 +768,20 @@ void KitaThreadView::domApplyChange( QString lbstr, /* label */ { /* label, header & footer */ - if ( hstr != NULL ) m_domtree->createCommentNode( hstr, "header", 0, 2, TRUE ); - if ( fstr != NULL ) m_domtree->createCommentNode( fstr, "footer", 0, 0, FALSE ); - if ( lbstr != NULL ) subjectLabel->setText( lbstr ); - - /* update display */ - m_threadPart->htmlDocument().applyChanges(); - m_threadPart->view() ->layout(); - m_threadPart->view() ->setVScrollBarMode( QScrollView::AlwaysOn ); - m_threadPart->view() ->setFocus(); - - GobackAnchorButton->setEnabled( FALSE ); - BookmarkButton->setEnabled( FALSE ); - switch( m_viewmode ) - { - - case VIEWMODE_PREVIEW: - writeButton->setEnabled( FALSE ); - SearchCombo->setEnabled( FALSE ); - SearchButton->setEnabled( FALSE ); - HighLightButton->setEnabled( FALSE ); - ReloadButton->setEnabled( FALSE ); - break; - - case VIEWMODE_KITANAVI: - writeButton->setEnabled( TRUE ); - ReloadButton->setEnabled( TRUE ); - break; - } - + if ( hstr != NULL ) m_threadPart->insertHeaderNode( hstr ); + if ( fstr != NULL ) m_threadPart->insertFooterNode( fstr ); if ( cmbstr != NULL ) SearchCombo->insertItem( cmbstr ); - if ( anchor != NULL ) gotoAnchor( anchor ); + if ( anchor != NULL ) m_threadPart->gotoAnchor( anchor, TRUE ); + if ( lbstr != QString::null ){ + QString str = QString( "[%2] " ) + .arg( Kita::DatManager::thread_boardURL( m_datURL ) ) + .arg( Kita::DatManager::thread_boardName(m_datURL) ) + lbstr; + subjectLabel->setText( str ); + } + + /* update display */ + m_threadPart->updateScreen(FALSE,FALSE); + updateButton(); showStatusBar( "" ); } diff --git a/kita/src/part/kitathreadview.h b/kita/src/part/kitathreadview.h index d87e963..2b7f4fb 100644 --- a/kita/src/part/kitathreadview.h +++ b/kita/src/part/kitathreadview.h @@ -16,7 +16,6 @@ #include #include -#include #include #include "kita2ch.h" @@ -67,12 +66,9 @@ public: void setupEx( const Kita::Thread* thread, int serverTime, int mode ); void showStatusBar( QString info ); - void gotoAnchor( QString anc ); Kita::Thread* get2chThread() { return m_thread; } int getViewMode() { return m_viewmode; } - /* !! static !! */ - static KURL filterReadCGI( const KURL&, const Kita::Thread* thread ); /* for preview and KitaNavi */ void domAppendData( QString& str, int bufnum, int num ); @@ -84,12 +80,9 @@ public: public slots: void subjectlinkClicked(const QString& URL ); void subjectlinkMClicked( const QString &URL ); - void showThread( const Kita::Thread* thread ); + void showThread( const KURL& datURL, int num ); void setFont( const QFont& font ); void slotReloadButton(); - void slotOpenURLRequest( const KURL&, const KParts::URLArgs& ); - void slotReceiveData(); - void slotFinishLoad(); void slotStopLoading(); void focusSearchCombo(); @@ -103,28 +96,16 @@ private: // Private attributes KURL m_datURL; KitaHTMLPart* m_threadPart; Kita::PostInfo m_postInfo; - Kita::ResPopup* m_popup; Kita::KitaSubjectLabel* subjectLabel; - KitaDomTree* m_domtree; bool m_revsearch; int m_viewmode; int m_rescode; - int m_kokoyonNum; - int m_showNum; /* for config */ - int m_preShowNum; QString m_mailaddr; - int m_maxpopup; - bool m_online; - bool m_firstReceive; - - void updateScreen(); - void updateInfo(); void appendRes( int startnum, int endnum ); - void showPopup( QString innerHTML, QString imgfile ); void insertSearchCombo(); void setSubjectLabel( const QString& boardName, const QString& threadName, const QString boardURL ); @@ -135,13 +116,12 @@ private: // Private attributes private slots: void slotSearchButton(); - void slotOnURL( const QString& url ); void slotPostStarted( KIO::Job*, const Kita::PostInfo& ); void slotBookmarkButtonClicked( bool on ); void slotWriteButtonClicked( QString resstr = QString::null ); void slotShowErrorDialog( const QString& input, const KURL& urlOfInput = 0 ); void slotComboActivated( int index ); - void hidePopup(); + void slotUpdateInfo(); signals: void showThreadCompleted( const KURL& threadUrl ); @@ -155,7 +135,6 @@ signals: void enableAction( const char* name, bool enabled ); void popupMenu( KXMLGUIClient*, const QPoint&, const KURL&, const QString&, mode_t ); void signalThread( const Kita::Thread* ); - void writeSucceeded(); void bookmarked( const QString& datURL, bool on ); void openBoardRequested( const QString& URL, bool useTab ); }; @@ -188,23 +167,6 @@ namespace Kita QString m_popupURL; }; - class PopupTextBrowser : public QTextBrowser - { - public: - PopupTextBrowser( QFrame* frame ); - ~PopupTextBrowser(); - }; - - class ResPopup : public QFrame - { - KHTMLPart* m_part; - Kita::PopupTextBrowser* m_browser; - public: - ResPopup( KHTMLView* view ); - ~ResPopup(); - void setText( QString& str ); - void adjustSize(); - }; } #endif