OSDN Git Service

>>935
[kita/kita.git] / kita / src / libkita / thread.cpp
1 /***************************************************************************
2 *   Copyright (C) 2003 by Hideki Ikemoto                                  *
3 *   ikemo@users.sourceforge.jp                                            *
4 *                                                                         *
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 ***************************************************************************/
10
11 #include "thread.h"
12
13 #include <config.h>
14
15 #include <stdlib.h>
16 #include <unistd.h>
17
18 #include <kurl.h>
19 #include <kdebug.h>
20 #include <kprotocolmanager.h>
21 #include <kglobal.h>
22 #include <kstandarddirs.h>
23
24 #include <kio/slaveconfig.h>
25 #include <kio/jobclasses.h>
26 #include <kio/scheduler.h>
27 #include <kio/netaccess.h>
28
29 #include <qwidget.h>
30 #include <qapplication.h>
31 #include <qregexp.h>
32
33 #include "board.h"
34 #include "kita_misc.h"
35 #include "qcp932codec.h"
36 #include "threadinfo.h"
37
38 using namespace Kita;
39
40 QDict<Thread>* Thread::m_threadDict = 0;
41
42 Thread::Thread()
43 {}
44
45 Thread::Thread( const QString& datURL, const QString& threadName )
46         : m_datURL( datURL ), m_threadName( threadName )
47 {}
48
49 Thread::~Thread()
50 {}
51
52 const QString& Thread::datURL() const
53 {
54     return m_datURL;
55 }
56
57 const QString Thread::url() const
58 {
59     return datToThread( m_datURL );
60 }
61
62 const QString Thread::datID() const
63 {
64     return KURL( m_datURL ).filename().section( ".", 0, 0 );
65 }
66
67 int Thread::resNum() const
68 {
69     return KitaThreadInfo::resNum( m_datURL );
70 }
71
72 const QString& Thread::name() const
73 {
74     if ( ! Kita::Thread::getByURL( m_datURL ) ->m_threadName.isEmpty() ) {
75         return Kita::Thread::getByURL( m_datURL ) ->m_threadName;
76     }
77     return m_threadName;
78 }
79
80 void Thread::setResNum( int resNum )
81 {
82     KitaThreadInfo::setResNum( m_datURL, resNum );
83 }
84
85 const QString& Thread::boardName() const
86 {
87     return Kita::Board::getName( boardURL() );
88 }
89
90 const QString Thread::boardURL() const
91 {
92     return datToBoard( m_datURL );
93 }
94
95 const QString Thread::boardID() const
96 {
97     return KURL( datToBoard( m_datURL ) ).fileName();
98 }
99
100 Thread* Thread::getByURL( const QString& datURL )
101 {
102     if ( m_threadDict == 0 ) {
103         m_threadDict = new QDict<Thread>();
104     }
105
106     Thread* thread = m_threadDict->find( datURL );
107     if ( thread ) return thread;
108
109     Thread* newThread = new Thread( datURL );
110     m_threadDict->insert( datURL, newThread );
111
112     return newThread;
113 }
114
115 /* static & public */
116 Thread* Thread::getByURLNew( const KURL& datURL )
117 {
118     if ( m_threadDict == NULL ) return NULL;
119     return m_threadDict->find( datURL.prettyURL() );
120 }
121
122 void Thread::setName( const QString& datURL, const QString& threadName )
123 {
124     if ( datURL.isNull() ) {
125         return ;
126     }
127
128     if ( m_threadDict == 0 ) {
129         m_threadDict = new QDict<Thread>();
130     }
131
132     if ( m_threadDict->find( datURL ) ) {
133         Thread * thread = getByURL( datURL );
134         thread->m_threadName = threadName;
135     } else {
136         Thread* newThread = new Thread( datURL, threadName );
137         m_threadDict->insert( datURL, newThread );
138     }
139
140     return ;
141 }
142
143 void Thread::replace( const QString& fromURL, const QString& toURL )
144 {
145     QDictIterator<Kita::Thread> it( *m_threadDict );
146     for( ; it.current(); ++it ) {
147         QString url = it.currentKey();
148         Kita::Thread* thread = it.current();
149         if ( url.find( fromURL ) == 0 ) {
150             m_threadDict->remove( url );
151             url = url.replace( 0, fromURL.length(), toURL );
152             thread->m_datURL = url;
153             Kita::Board::replace( fromURL, toURL );
154             m_threadDict->insert( url, thread );
155             it.toFirst();
156         }
157     }
158 }
159
160 NullThread::NullThread()
161 {}
162
163 NullThread::~NullThread()
164 {}