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 ***************************************************************************/
13 #include <QtCore/QRegExp>
17 QMultiHash<QString, Thread*>* Thread::m_threadDict = 0;
19 Thread::Thread(const KUrl& datUrl)
20 : m_datUrl(datUrl), m_threadName(0) , m_resNum(0), m_readNum(0), m_viewPos(0)
26 const KUrl& Thread::datUrl() const
32 const QString& Thread::threadName() const
38 void Thread::setThreadName(const QString& name)
40 QString threadName = name;
43 threadName.remove(qrx);
46 threadName.replace("<", "<").replace(">", ">").replace("&", "&");
48 m_threadName = threadName;
52 int Thread::resNum() const
58 void Thread::setResNum(int num)
64 int Thread::readNum() const
70 void Thread::setReadNum(int num)
73 if (m_resNum < m_readNum) setResNum(m_readNum);
77 int Thread::viewPos() const
83 void Thread::setViewPos(int num)
89 const QList<int>& Thread::markList() const
95 void Thread::setMarkList(const QList<int>& markList)
97 m_markList = markList;
101 bool Thread::isMarked(int num)
103 QList<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.removeAll(num);
124 /*--------------------------------------------*/
126 /* static functions */
128 Thread* Thread::getByUrl(const KUrl& datUrl)
130 if (m_threadDict == 0) {
131 m_threadDict = new QMultiHash<QString, Thread*>();
134 Thread* thread = m_threadDict->value(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 == 0) return 0;
148 return m_threadDict->value(datUrl.prettyUrl());
151 void Thread::replace(const QString& fromUrl, const QString& toUrl)
153 if (m_threadDict == 0) return ;
154 QHashIterator<QString, Thread*> it(*m_threadDict);
155 while (it.hasNext()) {
157 QString url = it.key();
158 Thread* thread = it.value();
159 if (url.indexOf(fromUrl) == 0) {
160 m_threadDict->remove(url);
161 url = url.replace(0, fromUrl.length(), toUrl);
162 thread->m_datUrl = url;
163 m_threadDict->insert(url, thread);