Factor out the shared parts of the agent action manager setup.
[kdepim.git] / knode / knarticle.h
blob85eb674153d255d8435dc5a180a99fddfbcac5ad
1 /*
2 KNode, the KDE newsreader
3 Copyright (c) 1999-2005 the KNode authors.
4 See file AUTHORS for details
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15 #ifndef KNARTICLE_H
16 #define KNARTICLE_H
18 #include "knjobdata.h"
20 #include <boost/shared_ptr.hpp>
21 #include <QFile>
22 #include <QColor>
23 #include <kmime/kmime_headers.h>
24 #include <kmime/kmime_newsarticle.h>
25 #include <kmime/boolflags.h>
27 class KNLoadHelper;
28 class KNHdrViewItem;
29 class KNArticleCollection;
31 /** This class encapsulates a generic article. It provides all the
32 usual headers of a RFC822-message. Further more it contains an
33 unique id and can store a pointer to a @ref QListViewItem. It is
34 used as a base class for all visible articles. */
35 class KNArticle : public KMime::NewsArticle, public KNJobItem {
37 public:
38 /// Shared pointer to a KNArticle. To be used instead of raw KNArticle*.
39 typedef boost::shared_ptr<KNArticle> Ptr;
40 /// List of articles.
41 typedef QList<KNArticle::Ptr> List;
43 enum articleType {
44 ATmimeContent,
45 ATremote,
46 ATlocal
49 KNArticle( boost::shared_ptr<KNArticleCollection> c );
50 ~KNArticle();
52 virtual void clear();
54 virtual articleType type() const { return ATmimeContent; }
56 /** Returns the article id. */
57 int id() const { return i_d; }
58 /** Sets the article id.
59 * @param i The article id.
61 void setId( int i ) { i_d = i; }
63 //list item handling
64 KNHdrViewItem* listItem() const { return i_tem; }
65 /**
66 Sets the headerview item associated to this article.
67 @param i The item associated to this item or 0 to break the link to the previous item.
68 @param a The shared pointer of <strong>this</strong> article.
70 void setListItem( KNHdrViewItem *i, KNArticle::Ptr a );
71 virtual void updateListItem() {}
73 //network lock (reimplemented from KNJobItem)
74 bool isLocked() { return f_lags.get(0); }
75 void setLocked(bool b=true);
77 //prevent that the article is unloaded automatically
78 bool isNotUnloadable() { return f_lags.get(1); }
79 void setNotUnloadable(bool b=true) { f_lags.set(1, b); }
81 //article-collection
82 boost::shared_ptr<KNArticleCollection> collection() const { return c_ol; }
83 void setCollection( boost::shared_ptr<KNArticleCollection> c ) { c_ol = c; }
84 bool isOrphant() const { return (i_d==-1); }
86 protected:
87 int i_d; //unique in the given collection
88 boost::shared_ptr<KNArticleCollection> c_ol;
89 KNHdrViewItem *i_tem;
91 KMime::BoolFlags f_lags;
93 }; // KNArticle
96 class KNGroup;
98 /** KNRemoteArticle represents an article, whos body has to be
99 retrieved from a remote host or from the local cache.
100 All articles in a newsgroup are stored in instances
101 of this class. */
103 class KNRemoteArticle : public KNArticle {
105 public:
106 /// Shared pointer to a KNRemoteArticle. To be used instead of raw KNRemoteArticle*.
107 typedef boost::shared_ptr<KNRemoteArticle> Ptr;
108 /// List of remote articles.
109 typedef QList<KNRemoteArticle::Ptr> List;
111 KNRemoteArticle( boost::shared_ptr<KNGroup> g );
112 ~KNRemoteArticle();
114 // type
115 articleType type() const { return ATremote; }
117 // content handling
118 virtual void parse();
120 // article number
121 int articleNumber() const { return a_rticleNumber; }
122 void setArticleNumber(int number) { a_rticleNumber = number; }
124 // status
125 bool isNew() { return f_lags.get(2); }
126 void setNew(bool b=true) { f_lags.set(2, b); }
127 bool getReadFlag() { return f_lags.get(3); }
128 bool isRead() { return f_lags.get(7) || f_lags.get(3); } // ignored articles == read
129 void setRead(bool b=true) { f_lags.set(3, b); }
130 bool isExpired() { return f_lags.get(4); }
131 void setExpired(bool b=true) { f_lags.set(4, b); }
132 bool isKept() { return f_lags.get(5); }
133 void setKept(bool b=true) { f_lags.set(5, b); }
134 bool hasChanged() { return f_lags.get(6); }
135 void setChanged(bool b=true) { f_lags.set(6, b); }
136 bool isIgnored() { return f_lags.get(7); }
137 void setIgnored(bool b=true) { f_lags.set(7, b); }
138 bool isWatched() { return f_lags.get(8); }
139 void setWatched(bool b=true) { f_lags.set(8, b); }
141 // thread info
142 int idRef() { return i_dRef; }
143 void setIdRef(int i) { if (i != id())
144 i_dRef=i;
145 else
146 i_dRef=0; }
147 KNRemoteArticle::Ptr displayedReference() { return d_ref; }
148 void setDisplayedReference( KNRemoteArticle::Ptr dr ) { d_ref=dr; }
149 bool threadMode() { return f_lags.get(9); }
150 void setThreadMode(bool b=true) { f_lags.set(9, b); }
151 unsigned char threadingLevel() { return t_hrLevel; }
152 void setThreadingLevel(unsigned char l) { t_hrLevel=l; }
153 short score() { return s_core; }
154 void setScore(short s) { s_core=s; }
155 unsigned short newFollowUps() { return n_ewFups; }
156 bool hasNewFollowUps() { return (n_ewFups>0); }
157 void setNewFollowUps(unsigned short s) { n_ewFups=s; }
158 void incNewFollowUps(unsigned short s=1) { n_ewFups+=s; }
159 void decNewFollowUps(unsigned short s=1) { n_ewFups-=s; }
160 unsigned short unreadFollowUps() { return u_nreadFups; }
161 bool hasUnreadFollowUps() { return (u_nreadFups>0); }
162 void setUnreadFollowUps(unsigned short s) { u_nreadFups=s; }
163 void incUnreadFollowUps(unsigned short s=1) { u_nreadFups+=s; }
164 void decUnreadFollowUps(unsigned short s=1) { u_nreadFups-=s; }
165 void thread(List &f);
167 //filtering
168 bool filterResult() { return f_lags.get(10); }
169 void setFilterResult(bool b=true) { f_lags.set(10, b); }
170 bool isFiltered() { return f_lags.get(11); }
171 void setFiltered(bool b=true) { f_lags.set(11, b); }
172 bool hasVisibleFollowUps() { return f_lags.get(12); }
173 void setVisibleFollowUps(bool b=true) { f_lags.set(12, b); }
175 // list item handling
176 void initListItem();
177 void updateListItem();
179 virtual void setForceDefaultCharset( bool b );
181 QColor color() const { return c_olor; }
182 void setColor(const QColor& c) { c_olor = c; }
184 time_t subThreadChangeDate() { return s_ubThreadChangeDate; }
185 void setSubThreadChangeDate(time_t date) { s_ubThreadChangeDate = date; }
186 // propagate the change date to the root article
187 void propagateThreadChangedDate();
189 protected:
190 int a_rticleNumber;
191 int i_dRef; // id of a reference-article (0 == none)
192 KNRemoteArticle::Ptr d_ref; // displayed reference-article (may differ from i_dRef)
193 unsigned char t_hrLevel; // quality of threading
194 short s_core; // guess what ;-)
195 QColor c_olor; // color for the header list
196 unsigned short u_nreadFups, // number of the article's unread follow-ups
197 n_ewFups; // number of the article's new follow-ups
198 time_t s_ubThreadChangeDate; // the last time the sub-thread of this article changed
199 // i.e. when the last article arrived...
201 }; // KNRemoteArticle
205 /** This class encapsulates an article, that is
206 stored locally in an MBOX-file. All own and
207 saved articles are represented by instances
208 of this class.
210 class KNLocalArticle : public KNArticle {
212 public:
213 /// Shared pointer to a KNLocalArticle. To be used instead of raw KNLocalArticle*.
214 typedef boost::shared_ptr<KNLocalArticle> Ptr;
215 /// List of local articles.
216 typedef QList<KNLocalArticle::Ptr> List;
218 KNLocalArticle( boost::shared_ptr<KNArticleCollection> c = boost::shared_ptr<KNArticleCollection>() );
219 ~KNLocalArticle();
221 //type
222 articleType type() const { return ATlocal; }
224 //send article as mail
225 bool doMail() { return f_lags.get(2); }
226 void setDoMail(bool b=true) { f_lags.set(2, b); }
227 bool mailed() { return f_lags.get(3); }
228 void setMailed(bool b=true) { f_lags.set(3, b); }
230 //post article to a newsgroup
231 bool doPost() { return f_lags.get(4); }
232 void setDoPost(bool b=true) { f_lags.set(4, b); }
233 bool posted() { return f_lags.get(5); }
234 void setPosted(bool b=true) { f_lags.set(5, b); }
235 bool canceled() { return f_lags.get(6); }
236 void setCanceled(bool b=true) { f_lags.set(6, b); }
238 // status
239 bool pending() { return ( (doPost() && !posted()) || (doMail() && !mailed()) ); }
240 bool isSavedRemoteArticle() { return ( !doPost() && !doMail() && editDisabled() ); }
242 //edit
243 bool editDisabled() { return f_lags.get(7); }
244 void setEditDisabled(bool b=true) { f_lags.set(7, b); }
246 //search
247 bool filterResult() { return f_lags.get(8); }
248 void setFilterResult(bool b=true) { f_lags.set(8, b); }
250 //MBOX information
251 int startOffset() const { return s_Offset; }
252 void setStartOffset(int so) { s_Offset=so; }
253 int endOffset() const { return e_Offset; }
254 void setEndOffset(int eo) { e_Offset=eo; }
256 //nntp-server id
257 int serverId() { if(!doPost()) return -1; else return s_erverId; }
258 void setServerId(int i) { s_erverId=i; }
260 //list item handling
261 void updateListItem();
263 virtual void setForceDefaultCharset(bool b);
265 protected:
266 int s_Offset, //position in mbox-file : start
267 e_Offset, //position in mbox-file : end
268 s_erverId; //id of the nntp-server this article is posted to
272 /** KNAttachment represents a file that is
273 * or will be attached to an article.
275 class KNAttachment {
277 public:
279 Shared pointer to a KNAttachment. To be used instead of raw KNAttachment*.
281 typedef boost::shared_ptr<KNAttachment> Ptr;
283 KNAttachment(KMime::Content *c);
284 KNAttachment(KNLoadHelper *helper);
285 ~KNAttachment();
287 //name (used as a Content-Type parameter and as filename)
288 const QString& name() { return n_ame; }
289 void setName(const QString &s) { n_ame=s; h_asChanged=true; }
291 //mime type
292 QString mimeType() { return mMimeType; }
293 void setMimeType(const QString &s);
295 //Content-Description
296 const QString& description() { return d_escription; }
297 void setDescription(const QString &s) { d_escription=s; h_asChanged=true; }
299 //Encoding
300 int cte() { return e_ncoding.encoding(); }
301 void setCte(int e) { e_ncoding.setEncoding( (KMime::Headers::contentEncoding)(e) );
302 h_asChanged=true; }
303 bool isFixedBase64()const { return f_b64; }
304 QString encoding() { return e_ncoding.asUnicodeString(); }
306 //content handling
307 KMime::Content* content()const { return c_ontent; }
308 QString contentSize() const;
309 bool isAttached() const { return i_sAttached; }
310 bool hasChanged() const { return h_asChanged; }
311 void updateContentInfo();
312 void attach(KMime::Content *c);
313 void detach(KMime::Content *c);
315 protected:
316 KMime::Content *c_ontent;
317 KNLoadHelper *l_oadHelper;
318 QFile *f_ile;
319 QString mMimeType;
320 QString n_ame,
321 d_escription;
322 KMime::Headers::ContentTransferEncoding e_ncoding;
323 bool i_sAttached,
324 h_asChanged,
325 f_b64;
328 #endif //KNARTICLE_H