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 ), m_isOpened( 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 )
90 bool Thread::isOpened() const
96 void Thread::setIsOpened( bool isOpened )
98 m_isOpened = isOpened;
102 const QValueList< int >& Thread::markList() const
108 void Thread::setMarkList( const QValueList< int >& markList )
110 m_markList = markList;
114 bool Thread::isMarked( int num )
116 QValueList< int >::iterator it;
117 for ( it = m_markList.begin(); it != m_markList.end(); ++it ) {
118 if ( ( *it ) == num ) return TRUE;
125 bool Thread::setMark( int num, bool newStatus )
127 bool status = isMarked( num );
128 if ( status == newStatus ) return FALSE;
130 if ( newStatus ) m_markList += num;
131 else m_markList.remove( num );
137 /*--------------------------------------------*/
139 /* static functions */
141 Thread* Thread::getByURL( const KURL& datURL )
143 if ( m_threadDict == 0 ) {
144 m_threadDict = new QDict<Thread>();
147 Thread* thread = m_threadDict->find( datURL.prettyURL() );
148 if ( thread ) return thread;
150 Thread* newThread = new Thread( datURL );
151 m_threadDict->insert( datURL.prettyURL(), newThread );
156 /* static & public */
157 Thread* Thread::getByURLNew( const KURL& datURL )
159 if ( m_threadDict == NULL ) return NULL;
160 if ( datURL.isEmpty() ) return NULL;
161 return m_threadDict->find( datURL.prettyURL() );
164 void Thread::replace( const QString& fromURL, const QString& toURL )
166 if ( m_threadDict == NULL ) return ;
167 QDictIterator<Kita::Thread> it( *m_threadDict );
168 for ( ; it.current(); ++it ) {
169 QString url = it.currentKey();
170 Kita::Thread* thread = it.current();
171 if ( url.find( fromURL ) == 0 ) {
172 m_threadDict->remove( url );
173 url = url.replace( 0, fromURL.length(), toURL );
174 thread->m_datURL = url;
175 m_threadDict->insert( url, thread );