summaryrefslogtreecommitdiffstats
path: root/dcoprss/service.h
blob: c1cf6de1a251e96e99e14a8782cc3214910620e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* $Id$ */
#ifndef _RSS_SERVICE
#define _RSS_SERVICE

/***************************************************************************
                          service.h  -  A DCOP Service to provide RSS data
                             -------------------
    begin                : Saturday 15 February 2003
    copyright            : (C) 2003 by Ian Reinhart Geiser
    email                : geiseri@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <dcopobject.h>
#include <dcopref.h>
#include <tqdict.h>
#include <tqptrlist.h>
#include <tqstringlist.h>
#include <tqstring.h>
#include <tqdatetime.h>
#include <tqpixmap.h>
#include <librss/global.h>
#include <librss/loader.h>
#include <librss/document.h>
#include <librss/article.h>
#include <librss/image.h>
/**
* This is a DCOP Service do not include this header in anything
*
**/
using namespace RSS;

class RSSDocument;
class RSSArticle;

class RSSService : public DCOPObject
{
	K_DCOP

	private:

		TQDict<RSSDocument> m_list;

	public:
		RSSService();
		~RSSService();
		void saveLinks();
		void loadLinks();


	k_dcop_signals:
		/**
		* Emmitted when a new document has been added.  You can then
		* use document(TQString) to get the dcop ref for the object.
		* Note: this document may or may not be valid at this
		* point so you should connect your dcop signals and then
		* do a documentValid() on the dcop ref to make sure of its
		* state.
		**/

		void added(TQString);
		/**
		* Emmitted when the document has been removed.
		* note at this point the DCOPRef for this object is
		* invalid and you will cannot access it any longer.
		* When in doubt call a refresh on it, since if its in the
		* process of loading the document call will be safely ignored
		* and you will be notified of the updates.
		**/
		void removed(TQString);
	k_dcop:
		/**
		* Add a new rdf file resource.  This will return a dcop reference to the resource.  If its a new
		* one it will be added otherwise an existing resource reference will be returned.
		* once this reference has been returned you may connect dcop signals and then call
		* refresh on the RSSDocument.  The document will not be updated until refresh is called.
		**/
		DCOPRef add(TQString url);
		/**
		* Return a list of current rss documents
		**/
		TQStringList list();
		/**
		* Remove an rss document resource.  NOTE: Be aware that others may be using this
		* resource and if you remove it they may break.  Likewise be aware that someone may
		* decide to remove your resource on you so you should always check to see if the resource
		* is valid before you access it.
		**/
		void remove(TQString url);
		/**
		* Return the reference to a requested resource.  If this resource is not present a null dcopref is
		* returned.
		**/
		DCOPRef document(TQString url);
		/**
		* Exit the RSSService.  This will clean everything up and exit.
		**/
		void exit();
};

class RSSDocument :  public TQObject, public DCOPObject
{
	TQ_OBJECT
//	
	K_DCOP

	private:
		bool m_isLoading;
		TQString m_Url;
		Document *m_Doc;
		TQPixmap m_pix;
		TQPtrList<RSSArticle> m_list;
		TQMap<TQString,int> m_state;
		TQDateTime m_Timeout;
		int m_maxAge;

	private slots:
		void pixmapLoaded(const TQPixmap&);
		void loadingComplete(Loader *, Document, Status);

	public:
		RSSDocument(const TQString& url);
		~RSSDocument();

	k_dcop_signals:
		/**
		* The pixmap is currently loading
		**/
		void pixmapUpdating(DCOPRef);
		/**
		*  The pixmap is ready for viewing
		*  you can then use dcopref->call("pixmap()"); to return it.
		*
		**/
		void pixmapUpdated(DCOPRef);
		/**
		* The document is currently updating
		**/
		void documentUpdating(DCOPRef);
		/**
		* The document is ready for viewing
		* you can then use dcopref->call() to access its data
		**/
		void documentUpdated(DCOPRef);
		/**
		* The document failed to update, with and error...
		* 1 - RSS Parse Error
		* 2 - Could not access file
		* 3 - Unknown error.
		**/
		void documentUpdateError(DCOPRef, int);

	k_dcop:
		/**
		* Return the webmaster information from the RSS::Document
		**/
		TQString webMaster();
		/**
		* Return the manageing editor from the RSS::Document
		**/
		TQString managingEditor();
		/**
		* Returns the rating of the RSS::Document
		**/
		TQString rating();
		/**
		* Returns the last build date from the RSS::Document
		**/
		TQDateTime lastBuildDate();
		/**
		* Returns the publication date from the RSS::Document
		**/
		TQDateTime pubDate();
		/**
		* Returns the copyright information from the RSS::Document
		**/
		TQString copyright();
		/**
		* Returns a list of article titles
		**/
		TQStringList articles();
		/**
		* Returns the number of articles
		**/
		int count();
		/**
		* Returns a dcop reference to the article from the index
		**/
		DCOPRef article(int idx);
		/**
		* Returns the link from the  RSS::Document
		**/
		TQString link();
		/**
		* Returns the description from the RSS::Document
		**/
		TQString description();
		/**
		* Returns the title from the RSS::Document
		**/
		TQString title();
		/**
		*  Returns the text version from the RSS::Document
		**/
		TQString verbVersion();
		/**
		*  Returns the url for the pixmap from the RSS::Document
		**/
		TQString pixmapURL();
		/**
		* Returns the actual pixmap from the RSS::Document's RSS::Image
		**/
		TQPixmap pixmap();
		/**
		* Returns if the RSSDocument contains a valid RSS::Document yet.
		**/
		bool documentValid();
		/**
		* Returns if the RSSDocument contains a valid RSS::Image
		**/
		bool pixmapValid();
		/**
		* Refresh the current RSS::Document.
		* This must be called before the document is valid.
		**/
		void refresh();

		/**
		* Return the maximum age of the RSS document (Default is 60 minutes)
		**/
		int maxAge();

		/**
		* Set the maximum age of the RSS document.
		**/
		void setMaxAge(int minutes);
		
		/**
		 * Returns the state of the article
		 * 0 - not present (deleted from the rss service)
		 * 1 - new
		 * 2 - unread
		 * 3 - read
		 */
		int state( const TQString &title) const;
		
		/**
		 * Set the article state
		 */
		void setState( const TQString &title, int s );
		
		/**
		 * Convience method that will set a title to read.
		 */
		void read( const TQString &title);
};

class RSSArticle : public DCOPObject
{
	K_DCOP

	private:
		Article *m_Art;

	public:
		RSSArticle(Article *art);
		~RSSArticle();

	k_dcop:
		/**
		* Return the articles title
		**/
		TQString title();
		/**
		* Return the articles description
		**/
		TQString description();
		/**
		* Return the link to the article
		**/
		TQString link();
};
#endif