#include "libkita/kita_misc.h"
#include "libkita/kitaconfig.h"
#include "libkita/signalcollection.h"
-#include "libkita/parsemisc.h"
#include "libkita/account.h"
#include "libkita/imgmanager.h"
+#include "libkita/datmanager.h"
+#include "libkita/boardmanager.h"
#include <qdragobject.h>
#include <qtextcodec.h>
delete m_naviDock;
delete m_imgDock;
delete m_writeDock;
+
+ Kita::DatManager::deleteAllDatInfo();
}
void KitaMainWindow::load( const KURL& url )
void KitaMainWindow::slotURLLine()
{
KURL url = m_urlLine->text();
- KURL datURL = Kita::ParseMisc::parseURLonly( url );
+ KURL datURL = Kita::getDatURL( url );
m_threadDock->slotShowThread( datURL, KitaConfig::alwaysUseTab() );
}
return ;
}
- KURL datURL = Kita::ParseMisc::parseURLonly( url ); /* convert "thread URL" into "dat URL" */
-
- QRegExp regexp( "http://([^/]*)/([^/]*)/dat/(.*)\\.dat$" );
- if ( regexp.search( datURL.url() ) == -1 ) { /* Is this URL 2ch? */
+ /* open thread with new thread tab */
+ if ( Kita::DatManager::isThreadEnrolled( url ) ){
+ m_threadDock->slotShowThread( url, true );
+ return;
+ }
/* bmp file */
if ( Kita::ImgManager::isBMP( url ) ) {
}
KRun::runURL( url, mimetype );
-
- } else {
- m_threadDock->slotShowThread( url, true );
- }
}
}
// no effect: m_unreadNum, m_readNum, m_newNum, markOrder
- if ( Kita::DatManager::isMainThreadOpenedFast( datURL ) ) { /* opened */
+ if ( thread->isOpened() ) { /* opened */
item->setPixmap( Col_Mark, SmallIcon( "open" ) );
}
}
DatInfoList DatManager::m_datInfoList;
QMutex DatManager::m_mutex;
-QStringList DatManager::m_opendMainThreadList;
/*-----------------------------------------------------------------------*/
-/* create DatInfo explicitly. */ /* public */
+/* create DatInfo explicitly. */
+/* Usually, DatInfo is NOT created
+ if cache does not exist( i.e. ReadNum == 0 ). */ /* public */
bool DatManager::createDatInfo( const KURL& url )
{
- if( getDatInfo( url, FALSE ) == NULL ) return FALSE;
+ if( getDatInfo( url,
+ FALSE /* don't check the existence of cache */
+ ) == NULL ) return FALSE;
return TRUE;
}
/* Does cache exist ? */
/* If cache does not exist, delete DatInfo here. */
if( checkCached && datInfo->getReadNum() == 0 ){
- qDebug("cache does not exist");
delete datInfo;
return NULL;
}
m_datInfoList.prepend( datInfo );
- qDebug( "new DatInfo is created. (%d) %s",m_datInfoList.count(), datURL.prettyURL().ascii() );
- /* delete the all old instances */
+ /* delete the all old instances ( LRU algorithm )*/
if ( m_datInfoList.count() > DMANAGER_MAXQUEUE ) {
DatInfoList::Iterator it;
if ( ! deleteInfo->isLocked() ){
m_datInfoList.remove( it );
--it;
- qDebug( "delete DatInfo (%d) %s",m_datInfoList.count(),deleteInfo->url().prettyURL().ascii());
deleteInfo->wait(); /* wait until DatInfo::m_mutex is released. */
delete deleteInfo;
}
}
+/* public */
+void DatManager::deleteAllDatInfo()
+{
+ DatInfoList::Iterator it;
+ for ( it = m_datInfoList.begin(); it != m_datInfoList.end(); ++it ){
+
+ if( ( *it ) == NULL ) continue;
+ ( *it )->wait();
+ delete ( *it );
+ }
+}
+
+
/*-------------------------------------------------------------*/
/* get name (i.e. subject ) of thread from URL of dat file. */ /* public */
const QString DatManager::threadName( const KURL& url )
{
-
- QString name = QString::null;
-
KURL datURL = Kita::getDatURL( url );
Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
- if( thread != NULL ) name = thread->threadName();
+ if( thread != NULL ) return thread->threadName();
- return name;
+ return QString::null;
}
/* public */
int DatManager::getResNum( const KURL& url )
{
- int resNum = 0;
-
KURL datURL = Kita::getDatURL( url );
Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
- if( thread != NULL ) resNum = thread->resNum();
+ if( thread != NULL ) return thread->resNum();
- return resNum;
+ return 0;
}
/* public */
int DatManager::getReadNum( const KURL& url )
{
- int readNum = 0;
-
KURL datURL = Kita::getDatURL( url );
Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
- if( thread != NULL ) readNum = thread->readNum();
+ if( thread != NULL ) return thread->readNum();
- return readNum;
+ return 0;
}
/* public */
int DatManager::getViewPos( const KURL& url )
{
- int viewPos = 0;
-
KURL datURL = Kita::getDatURL( url );
Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
- if( thread != NULL ) viewPos = thread->viewPos();
+ if( thread != NULL ) return thread->viewPos();
- return viewPos;
+ return 0;
}
Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
if( thread != NULL ) thread->setViewPos( num );
+ /* save idx */
Kita::ThreadIndex::setViewPos( url, num );
/* save "cache" */
return datInfo->getDatSize();
}
-/* public */
+/* get number of responses which have same ID. */ /* public */
int DatManager::getNumByID( const KURL& url, const QString& strid )
{
DatInfo * datInfo = getDatInfo( url );
/* public */
+bool DatManager::isThreadEnrolled( const KURL& url )
+{
+ if( Kita::getDatURL( url ).isEmpty() ) return FALSE;
+
+ return TRUE;
+}
+
+
+
+/* public */
bool DatManager::isResValid( const KURL& url, int num )
{
DatInfo * datInfo = getDatInfo( url );
-/* public */
+/* check if ID == strid */ /* public */
bool DatManager::checkID( const KURL& url, const QString& strid, int num )
{
DatInfo* datInfo = getDatInfo( url );
}
-/* check keywords */ /* public */
+/* check if keywords are included */ /* public */
bool DatManager::checkWord( const KURL& url,
QStringList& strlist, int num,
bool checkOR /* AND or OR search */
/* check if the thread is shown on the main thread tab. */ /* public */
bool DatManager::isMainThreadOpened( const KURL& url )
{
- if( url.isEmpty() ) return FALSE;
- QString datURL = Kita::getDatURL( url ).prettyURL();
- if( datURL == QString::null ) return FALSE;
- if( m_opendMainThreadList.contains( datURL ) ) return TRUE;
-
- return FALSE;
-}
-
-/* omit calling Kita::getDatURL() */ /* public */
-bool DatManager::isMainThreadOpenedFast( const KURL& datURL )
-{
- if( datURL.isEmpty() ) return FALSE;
- if( m_opendMainThreadList.contains( datURL.prettyURL() ) ) return TRUE;
-
- return FALSE;
-}
+ KURL datURL = Kita::getDatURL( url ).prettyURL();
+ Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
+ if( thread == NULL ) return FALSE;
-/* public */
-void DatManager::addMainThreadToList( const KURL& url )
-{
- QString datURL = Kita::getDatURL( url ).prettyURL();
- if( datURL != QString::null ) m_opendMainThreadList += datURL;
+ return thread->isOpened();
}
-/* public */
-void DatManager::removeMainThreadFromList( const KURL& url )
+void DatManager::setMainThreadOpened( const KURL& url, bool isOpened )
{
- QString datURL = Kita::getDatURL( url ).prettyURL();
- m_opendMainThreadList.remove( datURL );
+ KURL datURL = Kita::getDatURL( url ).prettyURL();
+ Kita::Thread* thread = Kita::Thread::getByURLNew( datURL );
+ if( thread != NULL ) thread->setIsOpened( isOpened );
}
-
/*--------------------------*/
/* obsolete */
#define KITADATMG_H
#include <qvaluelist.h>
-#include <qstringlist.h>
class QMutex;
class KURL;
class QObject;
+class QStringList;
namespace DOM
{
{
static DatInfoList m_datInfoList;
static QMutex m_mutex;
- static QStringList m_opendMainThreadList; /* List of URL of thread shown on the main thread tab. */
public:
static bool createDatInfo( const KURL& url );
static DatInfo* getDatInfoPointer( const KURL& url );
+ static void deleteAllDatInfo();
/* caching */
static bool updateCache( const KURL& url , const QObject* parent );
/* another information */
+ static bool isThreadEnrolled( const KURL& url );
static bool isResValid( const KURL& url , int num );
static bool isBroken( const KURL& url );
static bool isResBroken( const KURL& url , int num );
/* check if the thread is shown on the main thread tab. */
static bool isMainThreadOpened( const KURL& url );
- static bool isMainThreadOpenedFast( const KURL& datURL );
- static void addMainThreadToList( const KURL& url );
- static void removeMainThreadFromList( const KURL& url );
+ static void setMainThreadOpened( const KURL& url, bool isOpened );
/* obsolete. Don't use them. */
static const QString threadURL( const KURL& url );
static bool is2chThread( const KURL& url );
-
+
private:
static DatInfo* getDatInfo( const KURL& url, bool checkCached = TRUE );
QDict<Thread>* Thread::m_threadDict = 0;
Thread::Thread( const KURL& datURL )
- : m_datURL( datURL ), m_threadName( 0 ) , m_resNum( 0 ), m_readNum( 0 ), m_viewPos( 0 )
+ : m_datURL( datURL ), m_threadName( 0 ) , m_resNum( 0 ), m_readNum( 0 ), m_viewPos( 0 ), m_isOpened( 0 )
{}
Thread::~Thread()
m_viewPos = num;
}
+
+/* public */
+bool Thread::isOpened() const
+{
+ return m_isOpened;
+}
+
+/* public */
+void Thread::setIsOpened( bool isOpened )
+{
+ m_isOpened = isOpened;
+}
+
+
/*--------------------------------------------*/
/* static functions */
int m_resNum;
int m_readNum;
int m_viewPos;
+ bool m_isOpened;
public:
Thread( const KURL& datURL );
const int viewPos() const;
void setViewPos( int viewPos );
+ bool isOpened() const;
+ void setIsOpened( bool isOpend );
+
/*----------------------*/
static Thread* getByURL( const KURL& datURL );
}
}
m_updatedKokoyon = FALSE;
-
- /* remove datURL from DatManager::m_opendMainThreadList */
- /* Then, update subject tab. */
- if( m_mode == HTMLPART_MODE_MAINPART && !m_datURL.isEmpty() ){
- Kita::DatManager::removeMainThreadFromList( m_datURL );
- emit updateSubjectTab( m_datURL );
- }
- if ( !m_datURL.isEmpty() ) {
+ /* clear variables */
+ m_anchorStack.clear();
+ m_centerNum = 0;
+ m_jumpNumAfterLoading = 0;
+ findTextInit();
+
+ if ( !m_datURL.isEmpty() ) { /* This part is opened. */
/* don't forget to unlock previous datURL here. */
Kita::DatManager::unlock( m_datURL );
- /* emit deactivated all thread view SIGNAL */
- if ( m_mode == HTMLPART_MODE_MAINPART ) emit activateThreadView( QString::null );
+ if ( m_mode == HTMLPART_MODE_MAINPART ){ /* This part is on the main thread view. */
- }
+ /* tell Thread class that "thread is closed" */
+ Kita::DatManager::setMainThreadOpened( m_datURL, FALSE );
+
+ /* emit "deactivated all thread view" SIGNAL */
+ emit activateThreadView( QString::null );
- m_anchorStack.clear();
- m_centerNum = 0;
- m_jumpNumAfterLoading = 0;
- findTextInit();
+ /* update subject tab. */
+ emit updateSubjectTab( m_datURL );
+ }
+ }
+ m_datURL = QString::null;
+ m_mode = HTMLPART_MODE_KHTML;
}
clearPart();
- /* Lock datURL. Don't forget to unlock it later ! */
m_datURL = Kita::getDatURL( url );
- Kita::DatManager::lock ( m_datURL );
+ m_mode = mode;
+
+ if( m_mode == HTMLPART_MODE_MAINPART ){ /* This part is on the main thread view. */
+
+ /* create DatInfo explicitly to open new thread. */
+ /* Usually, DatInfo is NOT created if ReadNum == 0.*/
+ /* See also DatManager::createDatInfo() and */
+ /* DatManager::getDatInfo(). */
+ if( Kita::DatManager::getReadNum( m_datURL ) == 0 ) Kita::DatManager::createDatInfo( m_datURL );
- /* reset abone */
- Kita::DatManager::resetAbone( m_datURL );
+ /* tell Thread class that "thread is opend" */
+ Kita::DatManager::setMainThreadOpened( m_datURL, TRUE );
+
+ /* reset abone */
+ Kita::DatManager::resetAbone( m_datURL );
+ }
+
+ /* Lock datURL. Don't forget to unlock it later ! */
+ Kita::DatManager::lock ( 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 );
}
-
- /* register datURL in DatManager::m_opendMainThreadList */
- if( m_mode == HTMLPART_MODE_MAINPART ) Kita::DatManager::addMainThreadToList( m_datURL );
return TRUE;
}
/* another thread ? */
if ( datURL.host() != m_datURL.host() || datURL.path() != m_datURL.path() ) {
- /* show them with boadname & subject */
+ /* get board name */
QString boardName = Kita::BoardManager::boardName( datURL );
if ( boardName != QString::null ) innerHTML += "[" + boardName + "] ";
+
+ /* If idx file of datURL is not read, thread name cannot be obtained.
+ so, create DatInfo if cache exists, and read idx file in DatInfo::DatInfo(). */
+ Kita::DatManager::getDatInfoPointer( datURL );
+
+ /* get thread Name */
QString subName = Kita::DatManager::threadName( datURL );
if ( subName != QString::null ) innerHTML += subName + "<br><br>";
/* setup */
m_datURL = Kita::getDatURL( datURL );
-
- /* create DatInfo explicitly. */
- Kita::DatManager::createDatInfo( m_datURL );
-
+
/* setup HTMLPart */
int partMode = HTMLPART_MODE_MAINPART;
if ( mode == VIEWMODE_KITANAVI ) partMode = HTMLPART_MODE_NAVI;