OSDN Git Service

e1f2b2a5d9439a7cb7fdfe519b273452416339e0
[kita/kita.git] / src / libkita / datinfo.h
1 /***************************************************************************
2 *   Copyright (C) 2004 by Kita Developers                                 *
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 #ifndef KITADATINFO_H
11 #define KITADATINFO_H
12
13 #include <QtCore/QDateTime>
14 #include <QtCore/QList>
15 #include <QtCore/QObject>
16 #include <QtCore/QVector>
17
18 #include <kurl.h>
19
20 #include "threadindex.h"
21
22 class QStringList;
23
24
25 /* return val of DatInfo::getHTML() */
26 enum{
27     HTML_NOTPARSED,
28     HTML_NORMAL,
29     HTML_ABONE,
30     HTML_BROKEN
31 };
32
33
34 enum{
35     ABONECHK_BY_ID,
36     ABONECHK_BY_NAME,
37     ABONECHK_BY_WORD
38 };
39
40
41
42 /* Data Base of anchor
43  
44    For example, No.5 res has name = "foo", id "id1234", and anchors >>2-3 and >>4, then,
45  
46    m_resDatVec[5].name = "foo",
47    m_resDatVec[5].id = "id1234",
48    m_resDatVec[5].anclist[0].from = 2,
49    m_resDatVec[5].anclist[0].to = 3,
50    m_resDatVec[5].anclist[1].from = 4,
51    m_resDatVec[5].anclist[1].to = 4.   
52  
53 */
54 struct ANCNUM
55 {
56     int from;
57     int to;
58 };
59
60 typedef QList<ANCNUM> AncList;
61
62
63 /* Data Base of response */
64 struct RESDAT
65 {
66     int num;         /* number */
67     QString linestr; /* raw line data */
68
69     bool parsed;
70     bool broken;
71
72     QString name;
73     QString nameHTML;
74     QString address;
75     QString date;
76     QDateTime dateTime;
77     QString id;
78     QString be;
79     QString bepointmark;
80     QString host;
81     QString bodyHTML;
82
83     AncList anclist; /* anchor list. See above. */
84
85     bool checkAbone; /* Is abone checked ? */
86     bool abone;
87
88     /* Is this res responsed by other one? */
89     bool isResponsed;
90 };
91 typedef QVector<RESDAT> ResDatVec;
92
93
94 namespace Kita
95 {
96
97     class Access;
98     class OfflawAccess;
99     class Thread;
100
101     /*-----------------------*/
102
103     class KDE_EXPORT DatInfo : public QObject
104     {
105         Q_OBJECT
106
107         /* pointer of Thread class */
108         Thread* m_thread;
109
110         /* basic information */
111         KUrl m_datUrl;
112         ThreadIndex m_threadIndex;
113         bool m_broken;
114         ResDatVec m_resDatVec;
115         bool m_isOpened;
116
117         /* for caching */
118         Access* m_access;
119         OfflawAccess* m_access2;
120         QString m_lastLine;
121         bool m_nowLoading;
122
123         /* abone */
124         bool m_aboneByID;
125         bool m_aboneByName;
126         bool m_aboneByBody;
127         bool m_aboneChain;
128
129
130         /* japanese strings */
131         QString m_spacestr;
132         QString m_framestr1; /* '|' */
133         QString m_framestr2; /* '|-' */
134         QString m_framestr3; /* 'L' */
135
136         /*-------------------------------*/
137
138     public:
139
140         DatInfo();
141         DatInfo(const KUrl& url);
142         ~DatInfo();
143         void init();
144         const KUrl& url() const;
145
146         /* for caching */
147         bool updateCache(const QObject* parent);
148         int getResponseCode() const;
149         int getServerTime() const;
150         bool deleteCache();
151         bool isLoadingNow() const;
152         void stopLoading() const;
153
154         /* string data */
155         QString getDat(int num);
156         QString getId(int num);
157         QString getPlainName(int num);
158         QString getPlainTitle(int num);
159         QString getPlainBody(int num);
160
161         /* HTML data */
162         int getHTML(int num, bool checkAbone, QString& titleHTML,
163                 QString& bodyHTML);
164         QString getHTMLString(int startnum, int endnum,
165                 bool checkAbone = true);
166         QString getHtmlById(const QString& strid, int &count);
167         QString getTreeByRes(int rootnum, int& count);
168         QString getTreeByResReverse(int rootnum, int& count);
169
170         /* numerical data */
171         int getResNum() const;
172         int getReadNum() const;
173         int getViewPos() const;
174         int getNumById(const QString& strid);
175         int getDatSize() const;
176
177         /* several information */
178         bool isResponsed (int num) const;
179         bool isResValid(int num);
180         bool isBroken() const;
181         bool isResBroken(int num);
182         bool checkId(const QString& strid, int num);
183         bool checkWord(const QStringList& stlist, int num, bool checkOr);
184         bool isOpened() const;
185         void setOpened(bool isOpened);
186
187         /* abone check */
188         bool checkAbone(int num);
189         void resetAbone();
190
191         /*-------------------------*/
192
193     private:
194
195         void initPrivate(bool loadCache = true);
196         void resetResDat(RESDAT& resdat) const;
197         void increaseResDatVec(int delta);
198         void deleteAccessJob();
199
200         /* copy data */
201         bool copyOneLineToResDat(const QString& line);
202
203         /* HTML data */
204         int getHTMLPrivate(int num, bool checkAbone, QString& titleHTML,
205                 QString& bodyHTML);
206         void getHtmlOfOneRes(int num, bool checkAbone, QString& html);
207         QString getTreeByResPrivate(int rootnum, bool reverse, int& count);
208         QString getTreeByResCore(int rootnum, bool reverse, int& count,
209                 const QString& prestr);
210         bool checkRes(int num, int target);
211
212         /* for abone */
213         void resetAbonePrivate();
214         bool checkAbonePrivate(int num);
215         bool checkAboneCore(const QString& str, const QStringList& strlist)
216             const;
217
218         /* parsing functions */
219         bool parseDat(int num);
220
221         void createTitleHtml(RESDAT& resdat, QString& titleHtml);
222
223         DatInfo(const DatInfo&);
224         DatInfo& operator=(const DatInfo&);
225         /*----------------------------*/
226
227     private slots:
228
229         void slotReceiveData(const QStringList& lineList);
230         void slotFinishLoad();
231
232     signals:
233         void receiveData();
234         void finishLoad();
235     };
236
237 }
238
239 #endif