#include "thread.h"
-#include <qregexp.h>
-
+#include <QtCore/QRegExp>
using namespace Kita;
-QDict<Thread>* Thread::m_threadDict = 0;
+QMultiHash<QString, 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 )
+Thread::Thread(const KUrl& datUrl)
+ : m_datUrl(datUrl), m_threadName(0) , m_resNum(0), m_readNum(0), m_viewPos(0)
{}
Thread::~Thread()
{}
-const KURL& Thread::datURL() const
+const KUrl& Thread::datUrl() const
{
- return m_datURL;
+ return m_datUrl;
}
/* public */
}
/* public */
-void Thread::setThreadName( QString threadName )
+void Thread::setThreadName(const QString& name)
{
+ QString threadName = name;
/* remove space */
- QRegExp qrx( " +$" );
- threadName.replace( qrx, "" );
+ QRegExp qrx(" +$");
+ threadName.remove(qrx);
/* unescape */
- threadName.replace( "<", "<" ).replace( ">", ">" ).replace( "&", "&" );
+ threadName.replace("<", "<").replace(">", ">").replace("&", "&");
m_threadName = threadName;
}
/* public */
-const int Thread::resNum() const
+int Thread::resNum() const
{
return m_resNum;
}
/* public */
-void Thread::setResNum( int num )
+void Thread::setResNum(int num)
{
m_resNum = num;
}
/* public */
-const int Thread::readNum() const
+int Thread::readNum() const
{
return m_readNum;
}
/* public */
-void Thread::setReadNum( int num )
+void Thread::setReadNum(int num)
{
m_readNum = num;
- if ( m_resNum < m_readNum ) setResNum( m_readNum );
+ if (m_resNum < m_readNum) setResNum(m_readNum);
}
/* public */
-const int Thread::viewPos() const
+int Thread::viewPos() const
{
return m_viewPos;
}
/* public */
-void Thread::setViewPos( int num )
+void Thread::setViewPos(int num)
{
m_viewPos = num;
}
/* public */
-const QValueList< int >& Thread::markList() const
+const QList<int>& Thread::markList() const
{
return m_markList;
}
/* public */
-void Thread::setMarkList( const QValueList< int >& markList )
+void Thread::setMarkList(const QList<int>& markList)
{
m_markList = markList;
}
/* public */
-bool Thread::isMarked( int num )
+bool Thread::isMarked(int num)
{
- QValueList< int >::iterator it;
- for ( it = m_markList.begin(); it != m_markList.end(); ++it ) {
- if ( ( *it ) == num ) return TRUE;
+ QList<int>::iterator it;
+ for (it = m_markList.begin(); it != m_markList.end(); ++it) {
+ if ((*it) == num) return true;
}
- return FALSE;
+ return false;
}
/* public */
-bool Thread::setMark( int num, bool newStatus )
+bool Thread::setMark(int num, bool newStatus)
{
- bool status = isMarked( num );
- if ( status == newStatus ) return FALSE;
+ bool status = isMarked(num);
+ if (status == newStatus) return false;
- if ( newStatus ) m_markList += num;
- else m_markList.remove( num );
+ if (newStatus) m_markList += num;
+ else m_markList.removeAll(num);
- return TRUE;
+ return true;
}
/* static functions */
-Thread* Thread::getByURL( const KURL& datURL )
+Thread* Thread::getByUrl(const KUrl& datUrl)
{
- if ( m_threadDict == 0 ) {
- m_threadDict = new QDict<Thread>();
+ if (m_threadDict == 0) {
+ m_threadDict = new QMultiHash<QString, Thread*>();
}
- Thread* thread = m_threadDict->find( datURL.prettyURL() );
- if ( thread ) return thread;
+ Thread* thread = m_threadDict->value(datUrl.prettyUrl());
+ if (thread) return thread;
- Thread* newThread = new Thread( datURL );
- m_threadDict->insert( datURL.prettyURL(), newThread );
+ Thread* newThread = new Thread(datUrl);
+ m_threadDict->insert(datUrl.prettyUrl(), newThread);
return newThread;
}
/* static & public */
-Thread* Thread::getByURLNew( const KURL& datURL )
+Thread* Thread::getByUrlNew(const KUrl& datUrl)
{
- if ( m_threadDict == NULL ) return NULL;
+ if (m_threadDict == 0) return 0;
- return m_threadDict->find( datURL.prettyURL() );
+ return m_threadDict->value(datUrl.prettyUrl());
}
-void Thread::replace( const QString& fromURL, const QString& toURL )
+void Thread::replace(const QString& fromUrl, const QString& toUrl)
{
- if ( m_threadDict == NULL ) return ;
- QDictIterator<Kita::Thread> it( *m_threadDict );
- for ( ; it.current(); ++it ) {
- QString url = it.currentKey();
- Kita::Thread* thread = it.current();
- if ( url.find( fromURL ) == 0 ) {
- m_threadDict->remove( url );
- url = url.replace( 0, fromURL.length(), toURL );
- thread->m_datURL = url;
- m_threadDict->insert( url, thread );
- it.toFirst();
+ if (m_threadDict == 0) return ;
+ QHashIterator<QString, Thread*> it(*m_threadDict);
+ while (it.hasNext()) {
+ it.next();
+ QString url = it.key();
+ Thread* thread = it.value();
+ if (url.indexOf(fromUrl) == 0) {
+ m_threadDict->remove(url);
+ url = url.replace(0, fromUrl.length(), toUrl);
+ thread->m_datUrl = url;
+ m_threadDict->insert(url, thread);
+ it.toFront();
}
}
}