1 /***************************************************************************
2 * Copyright (C) 2004 by Kita Developers *
3 * ikemo@users.sourceforge.jp *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
18 QDict<Thread>* Thread::m_threadDict = 0;
20 Thread::Thread( const KURL& datURL )
21 : m_datURL( datURL ), m_threadName( 0 ) , m_resNum( 0 ), m_readNum( 0 ), m_viewPos( 0 )
27 const KURL& Thread::datURL() const
33 const QString& Thread::threadName() const
39 void Thread::setThreadName( QString threadName )
43 threadName.replace( qrx, "" );
46 threadName.replace( "<", "<" ).replace( ">", ">" ).replace( "&", "&" );
48 m_threadName = threadName;
52 const int Thread::resNum() const
58 void Thread::setResNum( int num )
64 const int Thread::readNum() const
70 void Thread::setReadNum( int num )
73 if ( m_resNum < m_readNum ) setResNum( m_readNum );
77 const int Thread::viewPos() const
83 void Thread::setViewPos( int num )
89 const QValueList< int >& Thread::markList() const
95 void Thread::setMarkList( const QValueList< int >& markList )
97 m_markList = markList;
101 bool Thread::isMarked( int num )
103 QValueList< int >::iterator it;
104 for ( it = m_markList.begin(); it != m_markList.end(); ++it ) {
105 if ( ( *it ) == num ) return TRUE;
112 bool Thread::setMark( int num, bool newStatus )
114 bool status = isMarked( num );
115 if ( status == newStatus ) return FALSE;
117 if ( newStatus ) m_markList += num;
118 else m_markList.remove( num );
124 /*--------------------------------------------*/
126 /* static functions */
128 Thread* Thread::getByURL( const KURL& datURL )
130 if ( m_threadDict == 0 ) {
131 m_threadDict = new QDict<Thread>();
134 Thread* thread = m_threadDict->find( datURL.prettyURL() );
135 if ( thread ) return thread;
137 Thread* newThread = new Thread( datURL );
138 m_threadDict->insert( datURL.prettyURL(), newThread );
143 /* static & public */
144 Thread* Thread::getByURLNew( const KURL& datURL )
146 if ( m_threadDict == NULL ) return NULL;
148 return m_threadDict->find( datURL.prettyURL() );
151 void Thread::replace( const QString& fromURL, const QString& toURL )
153 if ( m_threadDict == NULL ) return ;
154 QDictIterator<Kita::Thread> it( *m_threadDict );
155 for ( ; it.current(); ++it ) {
156 QString url = it.currentKey();
157 Kita::Thread* thread = it.current();
158 if ( url.find( fromURL ) == 0 ) {
159 m_threadDict->remove( url );
160 url = url.replace( 0, fromURL.length(), toURL );
161 thread->m_datURL = url;
162 m_threadDict->insert( url, thread );