OSDN Git Service

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