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 KNARTICLECOLLECTION_H
16 #define KNARTICLECOLLECTION_H
18 #include "knarticle.h"
19 #include "kncollection.h"
24 /** Article storage used by KNArticleCollection.
26 class KNArticleVector
{
29 enum SortingType
{ STid
, STmsgId
, STunsorted
};
31 explicit KNArticleVector(KNArticleVector
*master
=0, SortingType sorting
=STunsorted
);
32 virtual ~KNArticleVector();
35 void setMaster(KNArticleVector
*m
) { m_aster
=m
; }
37 bool isEmpty() { return mList
.isEmpty(); }
38 int size() { return mList
.size(); }
42 Appends an article to this store.
44 void append( KNArticle::Ptr a
);
46 Remove the element at position @p pos in this store.
48 void remove( int pos
);
50 void syncWithMaster();
53 void setSortMode(SortingType s
) { s_ortType
=s
; }
54 static bool compareById( KNArticle::Ptr a1
, KNArticle::Ptr a2
);
55 static bool compareByMsgId( KNArticle::Ptr a1
, KNArticle::Ptr a2
);
58 KNArticle::Ptr
at( int i
) { return mList
.value( i
); }
59 KNArticle::Ptr
bsearch( int id
);
60 KNArticle::Ptr
bsearch( const QByteArray
&id
);
62 int indexForId(int id
);
63 int indexForMsgId( const QByteArray
&id
);
68 KNArticleVector
*m_aster
;
69 QList
<KNArticle::Ptr
> mList
;
70 SortingType s_ortType
;
74 /** Abstract base class for article collections, ie. news groups and folders.
76 class KNArticleCollection
: public KNCollection
{
80 * Shared pointer to a KNArticle. To be used instead of raw KNArticleCollection*.
82 typedef boost::shared_ptr
<KNArticleCollection
> Ptr
;
84 * List of KNArticleCollection.
86 typedef QList
<KNArticleCollection::Ptr
> List
;
89 KNArticleCollection( KNCollection::Ptr p
= KNCollection::Ptr() );
90 ~KNArticleCollection();
92 /** Returns true if this collection doesn't contain any article. */
93 bool isEmpty() { return a_rticles
.isEmpty(); }
94 bool isLoaded() { return ( c_ount
==0 || !a_rticles
.isEmpty() ); }
95 int length() { return a_rticles
.size(); }
98 bool isNotUnloadable() { return n_otUnloadable
; }
99 void setNotUnloadable(bool b
=true) { n_otUnloadable
= b
; }
102 unsigned int lockedArticles() { return l_ockedArticles
; }
103 void articleLocked() { l_ockedArticles
++; }
104 void articleUnlocked() { l_ockedArticles
--; }
108 Appends an article to this collection.
110 void append( KNArticle::Ptr a
);
112 * Remove the article @p art from this collection.
114 void remove( const KNArticle::Ptr
&art
);
121 Returns the article at index @p i in this collection, or an empty KNArticle::Ptr if it is not found.
123 KNArticle::Ptr
at( int i
) { return a_rticles
.at(i
); }
125 Returns the article whose id is @p id, or an empty KNArticle::Ptr if it is not found.
127 KNArticle::Ptr
byId( int id
);
129 Returns the article whose message-id is @p mid, or an empty KNArticle::Ptr if it is not found.
131 KNArticle::Ptr
byMessageId( const QByteArray
&mid
);
134 void syncSearchIndex();
138 unsigned int l_ockedArticles
;
140 KNArticleVector a_rticles
;
141 KNArticleVector m_idIndex
;