OSDN Git Service

eccc1050556cd79b8075162cd23765577df8483b
[kita/kita.git] / kita / src / libkita / datinfo.h
1 /**************************************************************************
2  *   Copyright (C) 2003 by Hideki Ikemoto , (c)2004 by 421                 *
3  *   ikemo@wakaba.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 #ifndef KITADATINFO_H
12 #define KITADATINFO_H
13
14 #include <qobject.h>
15 #include <kurl.h>
16 #include <qvaluevector.h>
17 #include <qdatetime.h>
18 #include <qmutex.h>
19
20 class QStringList;
21
22 namespace Kita
23 {
24
25 class Access;
26 class Thread; 
27     
28 enum{
29     ABONECHK_BY_ID,
30     ABONECHK_BY_NAME,
31     ABONECHK_BY_WORD
32 };
33
34 /* ResDatVec is the Database for responses. */
35 /* For example, No.5 res has name = "foo", id "id1234", and anchors >>2-3 and >>4,
36    then,
37
38    m_resDatVec[5].name = "foo",
39    m_resDatVec[5].id = "id1234",
40    m_resDatVec[5].anclist[0].from = 2,
41    m_resDatVec[5].anclist[0].to = 3,
42    m_resDatVec[5].anclist[1].from = 4,
43    m_resDatVec[5].anclist[1].to = 4.   
44
45 */
46 struct ANCNUM{
47     int from;
48     int to;
49 };
50 typedef QValueList<ANCNUM> AncList;
51
52 /* Data of one response */ 
53 struct RESDAT{
54
55      bool set; /* Is linestr set ? */
56
57      QString linestr; /* raw line strings */
58
59      /*-------*/
60     
61      bool parsed; /* Is dat parsed ? */
62
63      bool broken; /* This dat is broken */
64
65      QString name;
66      QString address;
67      QString body;
68      QString id;
69      QDateTime dateTime;
70      QString dateId;
71
72      /*-------*/
73     
74      bool setAnclist; /* Is anclist set ? */
75
76      AncList anclist; /* anchor list. See also setAncList()  */ 
77
78      /*-------*/
79
80      bool checkAbone; /* Is abone checked ? */
81
82      bool abone;
83 };
84
85 typedef QValueVector<RESDAT> ResDatVec;
86  
87
88 /*-----------------------*/
89
90 class DatInfo : public QObject
91     {
92         Q_OBJECT
93
94         QMutex m_mutex;
95
96       /* basic information */
97       int m_maxNum;
98         QString m_rawData;
99         KURL m_url;
100         QString m_subject;
101         bool m_broken;
102         ResDatVec m_resDatVec;
103         int m_lock;
104         int m_kokoyonNum; /* kokomade yonda */
105         
106         /* for caching */
107         Access* m_access;
108         Thread* m_thread;
109         QString m_lastLine;
110         bool m_nowLoading;
111         
112         /* japanese strings */
113         QString m_spacestr;
114         QString m_framestr1; /* '|' */
115         QString m_framestr2; /* '|-' */
116         QString m_framestr3; /* 'L' */
117
118         /*-------------------------------*/
119         
120       public:
121     
122         DatInfo();
123         DatInfo( const KURL& url );
124         ~DatInfo();
125         void init();
126         const KURL& url();
127         
128         /* for caching */
129         bool updateCache(const QObject* parent);
130         int getResponseCode();
131         int getServerTime();
132         bool deleteCache(QWidget* parent);
133         bool isLoadingNow();
134         void stopLoading();
135     
136         /* lock, unlock */
137         void lock();
138         void unlock();
139         int isLocked();
140
141         /* string data */
142         const QString& getSubject();
143         const QString& getRawDat();
144         const QString& getDat( int num );
145         const QString& getId( int num );
146         const QString& getName( int num );
147         const QString& getBody( int num );      
148         QString getPlainBody(int num);
149         QString getPlainTitle(int num);
150
151         /* HTML data */
152         QString getHtml(int startnum, int endnum);
153         QString getHtmlByID(const QString& strid, int &count );
154         QString getTreeByRes(const int rootnum, int& count );
155
156         /* numerical data */
157         int getMaxResNumber();
158         int getNumByID( const QString& strid );
159         int getKokoyonNum();
160         void setKokoyonNum(int num);
161         int getDatSize();
162
163         /* several informations */
164         bool isResValid(int num);
165         bool isBroken();
166         bool isResBroken(int num);
167         bool checkID(const QString& strid, int num );
168         bool checkWord(QStringList& stlist, int num, bool checkOR);
169
170         /* abone check */
171         bool checkAbone(int num);
172                 
173         /* Wrapper functions for Thread */
174         const QString  thread_datID();
175         const QString& thread_name();
176         const QString& thread_boardName();
177         const QString  thread_url();
178         const QString  thread_boardURL();
179         const QString  thread_boardID();
180
181         /*-------------------------*/
182
183       private:
184
185         void initPrivate();
186         void resetResDat(RESDAT& resdat);
187         void deleteAccessJob();
188
189         /* copy data */
190         void copyRawDataToBuffer(const QString& rawData);
191         bool setDat( const QString& line, int num );
192         
193         /* HTML data */
194         QString getTreeByResPrivate(const int rootnum, int& count, QString prestr);
195         bool checkRes(const  int num, const int target );
196         void setAncList(int num);
197         
198         /* for abone */
199         bool checkAbonePrivate(int num);
200         bool checkAboneCore(const QString& str, QStringList& strlist);
201
202         /* parsing funtions */
203         bool parseDat( int num );
204         QString toHtml(RESDAT& resdat, int num, bool showMailAddress ) const;
205         QString linkedAddress(RESDAT& resdat, bool showMailAddress ) const;
206         QString linkedBody(RESDAT& resdat) const;
207         QString getDateId(RESDAT&) const;
208         
209         /*----------------------------*/
210
211         private slots:
212
213       void slotReceiveData(const QString& newLine);
214         void slotFinishLoad();
215
216       signals:
217         void receiveData();
218         void finishLoad();      
219     };
220
221 }
222
223 #endif