From 54ffe6c79aafb10805ad4b57e064ecd8e2973bcb Mon Sep 17 00:00:00 2001 From: ikemo Date: Wed, 13 Jun 2007 15:47:39 +0000 Subject: [PATCH] refactoring. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@1952 56b19765-1e22-0410-a548-a0f45d66c51a --- TODO | 3 ++ kita/src/thread/domtree.cpp | 92 ++++++++++++++++++++++----------------------- kita/src/thread/domtree.h | 43 +++++++-------------- 3 files changed, 62 insertions(+), 76 deletions(-) diff --git a/TODO b/TODO index f1090ea..d7692c0 100644 --- a/TODO +++ b/TODO @@ -119,3 +119,6 @@ src.rpm ¡¦¤¢¤Èµ¤¤Þ¤°¤ì¤Ë¤¤¤í¤¤¤í 7. ¥ê¥ê¡¼¥¹¡¢¥Ë¥å¡¼¥¹¤ÎÅê¹Æ +--- +¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°¤¬´°Î»¤·¤¿¥¯¥é¥¹ +¡¦KitaDomTree diff --git a/kita/src/thread/domtree.cpp b/kita/src/thread/domtree.cpp index 36c6655..c94e00a 100644 --- a/kita/src/thread/domtree.cpp +++ b/kita/src/thread/domtree.cpp @@ -1,12 +1,12 @@ /*************************************************************************** -* Copyright (C) 2004 by Kita Developers * -* ikemo@users.sourceforge.jp * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -***************************************************************************/ + * Copyright (C) 2004, 2007 by Kita Developers * + * ikemo@users.sourceforge.jp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ /* This class manages the DOM elements */ @@ -38,32 +38,26 @@ KitaDomTree::KitaDomTree( const DOM::HTMLDocument& hdoc, const KURL& datURL ) m_datInfo = Kita::DatManager::getDatInfoPointer( datURL ); } - KitaDomTree::~KitaDomTree() {} - /* * This function creates DOM elements of both title and body. * To show the res, call appendRes() */ bool KitaDomTree::createResElement( int num ) { - const int mrg = 100; - const int delta = 500; - - /*---------------------------------*/ - - if ( ! m_datInfo ) return FALSE; - if ( num <= 0 ) return FALSE; + Q_ASSERT( num > 0 ); + Q_ASSERT( m_datInfo != NULL ); - if ( num < m_bufSize ) { - if ( m_resStatus[ num ] != KITA_HTML_NOTPARSED ) return TRUE; /* already parsed */ + if ( num < m_bufSize && m_resStatus[ num ] != KITA_HTML_NOTPARSED ) { + /* already parsed */ + return TRUE; } - /* resize buffer size */ - else { - if ( m_bufSize == 0 ) m_bufSize = mrg; - while ( num >= m_bufSize ) m_bufSize += delta; + if ( num >= m_bufSize ) { + /* resize buffer size */ + if ( m_bufSize == 0 ) m_bufSize = 100; + while ( num >= m_bufSize ) m_bufSize += 500; m_titleElm.resize( m_bufSize ); m_bodyElm.resize( m_bufSize ); @@ -74,7 +68,10 @@ bool KitaDomTree::createResElement( int num ) /* cleate elements */ QString titleHTML, bodyHTML; m_resStatus[ num ] = m_datInfo->getHTML( num, TRUE, titleHTML, bodyHTML ); - if ( m_resStatus[ num ] == KITA_HTML_NOTPARSED ) return FALSE; + + if ( m_resStatus[ num ] == KITA_HTML_NOTPARSED ) { + return FALSE; + } m_titleElm[ num ] = m_hdoc.createElement( "DIV" ); m_titleElm[ num ].setAttribute( "class", "res_title" ); @@ -89,9 +86,9 @@ bool KitaDomTree::createResElement( int num ) return TRUE; } - - -/* append the response */ /* public */ +/* + * append the response + */ bool KitaDomTree::appendRes( int num ) { if ( !createResElement( num ) ) return FALSE; @@ -104,13 +101,13 @@ bool KitaDomTree::appendRes( int num ) return TRUE; } - - - -/* redraw all */ /* public */ +/* + * redraw all + */ void KitaDomTree::redraw( bool force ) { - if ( ! m_datInfo ) return ; + Q_ASSERT( m_datInfo != NULL ); + int readNum = m_datInfo->getReadNum(); /* don't forget to reset abone here... */ @@ -118,11 +115,11 @@ void KitaDomTree::redraw( bool force ) for ( int i = 1; i <= readNum; i++ ) { QString titleHTML, bodyHTML; + int oldStatus = m_resStatus[ i ]; m_resStatus[ i ] = m_datInfo->getHTML( i , TRUE, titleHTML, bodyHTML ); if ( force || oldStatus != m_resStatus[ i ] ) { - m_titleElm[ i ].setInnerHTML( titleHTML ); m_bodyElm[ i ].setInnerHTML( bodyHTML ); } @@ -130,31 +127,33 @@ void KitaDomTree::redraw( bool force ) } -/* change color of number of the res which is responsed. */ -/* See also KitaDomTree::changeColorOfNumber() , - DatInfo::copyOneLineToResDat(), - and DatInfo::collectResponsedRes(). */ /* public */ +/* + * change color of number of the res which is responsed. + * + * See also KitaDomTree::changeColorOfNumber() , + * DatInfo::copyOneLineToResDat(), + * and DatInfo::collectResponsedRes(). + */ void KitaDomTree::changeColorOfAllResponsedNumber() { for ( int i = 1; i <= m_bottomNum; ++i ) { - if ( m_datInfo->isResponsed( i ) ) changeColorOfNumber( i ); + if ( m_datInfo->isResponsed( i ) ) { + changeColorOfNumber( i ); + } } } -/* public information */ - -/* public */ const int KitaDomTree::getBottomResNumber() const { return m_bottomNum; } -/* +/* * append footer & header */ void KitaDomTree::appendFooterAndHeader() { - if ( ! m_datInfo ) return ; + Q_ASSERT( m_datInfo != NULL ); int readNum = m_datInfo->getReadNum(); if ( !readNum ) return ; @@ -171,7 +170,7 @@ void KitaDomTree::appendFooterAndHeader() */ void KitaDomTree::appendKokoyon() { - if ( ! m_datInfo ) return ; + Q_ASSERT( m_datInfo != NULL ); int readNum = m_datInfo->getReadNum(); if ( !readNum ) return ; @@ -204,7 +203,7 @@ void KitaDomTree::appendAnchorNode( DOM::Element rootnode, const QString& href, } -/* +/* * update header * * example @@ -258,7 +257,7 @@ void KitaDomTree::updateHeader( DOM::Element& headerElement ) */ void KitaDomTree::updateFooter( DOM::Element& footerElement ) { - if ( ! m_datInfo ) return ; + Q_ASSERT( m_datInfo != NULL ); DOM::Element backupElement; int readNum = m_datInfo->getReadNum(); @@ -361,7 +360,6 @@ void KitaDomTree::createKokoyon() m_kokoyon = rootnode; } - /* * change color of number * specify color like this: "a.coloredLink:link{ color: red; }" diff --git a/kita/src/thread/domtree.h b/kita/src/thread/domtree.h index 5b33d84..a0860e2 100644 --- a/kita/src/thread/domtree.h +++ b/kita/src/thread/domtree.h @@ -1,18 +1,20 @@ /*************************************************************************** -* Copyright (C) 2004 by Kita Developers * -* ikemo@users.sourceforge.jp * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -***************************************************************************/ + * Copyright (C) 2004, 2007 by Kita Developers * + * ikemo@users.sourceforge.jp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ #ifndef KITADOMTREE_H #define KITADOMTREE_H #include + #include + #include namespace Kita @@ -25,22 +27,11 @@ class KitaDomTree Kita::DatInfo* m_datInfo; int m_bufSize; - /* - - When readNum = m_datInfo->getReadNum(), the responses are - - No.1 <-- shown --> m_templateNum <-- not shown --> - m_topNum <-- shown ---> m_bottomNum <-- not shown --> readNum. - - If m_topNum <= i <= m_bottomNum, then m_resshown[i] = TRUE. - - If m_bottomNum < i <= readNum, where m_bottomNum < readNum, - then m_resshown[i] = FALSE. - */ - int m_templateNum; + /* bottom number of shown. probably m_bottomNum == m_datInfo->getReadNum */ int m_bottomNum; - QValueVector < int > m_resStatus; /* return val of DatInfo::getHTML(). See datinfo.h */ - QValueVector < bool > m_coloredNum; /* colored number */ + + QValueVector< int > m_resStatus; /* return val of DatInfo::getHTML(). See datinfo.h */ + QValueVector< bool > m_coloredNum; /* colored number */ /* DOM elements */ DOM::HTMLDocument m_hdoc; /* root node of document*/ @@ -50,10 +41,7 @@ class KitaDomTree DOM::Element m_footer; DOM::Element m_kokoyon; - /*-------------------------------------------------------------*/ - public: - KitaDomTree( const DOM::HTMLDocument& hdoc, const KURL& datURL ); ~KitaDomTree(); @@ -74,7 +62,6 @@ public: void appendKokoyon(); private: - void appendAnchorNode( DOM::Element rootnode, const QString& linkstr, const QString& comment ); void updateHeader( DOM::Element& targetelm ); void updateFooter( DOM::Element& targetelm ); @@ -84,6 +71,4 @@ private: void changeColorOfNumber( int num ); }; - - #endif -- 2.11.0