Factor out the shared parts of the agent action manager setup.
[kdepim.git] / knode / knarticlecollection.h
blob3f6cf1cdfa185f768631cbf6d3e963b3c8a2d7ac
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 KNARTICLECOLLECTION_H
16 #define KNARTICLECOLLECTION_H
18 #include "knarticle.h"
19 #include "kncollection.h"
21 #include <QByteArray>
24 /** Article storage used by KNArticleCollection.
26 class KNArticleVector {
28 public:
29 enum SortingType { STid, STmsgId, STunsorted };
31 explicit KNArticleVector(KNArticleVector *master=0, SortingType sorting=STunsorted);
32 virtual ~KNArticleVector();
34 // list-info
35 void setMaster(KNArticleVector *m) { m_aster=m; }
37 bool isEmpty() { return mList.isEmpty(); }
38 int size() { return mList.size(); }
40 // list-handling
41 /**
42 Appends an article to this store.
44 void append( KNArticle::Ptr a );
45 /**
46 Remove the element at position @p pos in this store.
48 void remove( int pos );
49 void clear();
50 void syncWithMaster();
52 // sorting
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 );
57 // article access
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 );
65 private:
66 void sort();
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 {
78 public:
79 /**
80 * Shared pointer to a KNArticle. To be used instead of raw KNArticleCollection*.
82 typedef boost::shared_ptr<KNArticleCollection> Ptr;
83 /**
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(); }
97 // cache behavior
98 bool isNotUnloadable() { return n_otUnloadable; }
99 void setNotUnloadable(bool b=true) { n_otUnloadable = b; }
101 // locking
102 unsigned int lockedArticles() { return l_ockedArticles; }
103 void articleLocked() { l_ockedArticles++; }
104 void articleUnlocked() { l_ockedArticles--; }
106 // list-handling
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 );
115 void clear();
116 void compact();
117 void setLastID();
119 // article access
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 );
133 // search index
134 void syncSearchIndex();
136 private:
137 int l_astID;
138 unsigned int l_ockedArticles;
139 bool n_otUnloadable;
140 KNArticleVector a_rticles;
141 KNArticleVector m_idIndex;
145 #endif