Factor out the shared parts of the agent action manager setup.
[kdepim.git] / knode / knfolder.h
blobe5821e473abbed2af4bb14f6d1871a1112a36e45
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 KNFOLDER_H
16 #define KNFOLDER_H
18 #include "utilities.h"
19 #include "knarticle.h"
20 #include "knarticlecollection.h"
22 #include <QByteArray>
25 /** Representation of a folder. This includes:
26 * - Information about the folder (eg. name, parent)
27 * - Methods to load the folder content from a mbox file.
28 * - Methods to store the folder content in a mbox file.
30 class KNFolder : public KNArticleCollection {
32 friend class KNCleanUp;
34 public:
35 /**
36 * Shared pointer to a KNFolder. To be used instead of raw KNFolder*.
38 typedef boost::shared_ptr<KNFolder> Ptr;
39 /**
40 * List of folders.
42 typedef QList<KNFolder::Ptr> List;
44 KNFolder();
45 KNFolder(int id, const QString &name, KNFolder::Ptr parent = KNFolder::Ptr() );
46 KNFolder( int id, const QString &name, const QString &prefix, KNFolder::Ptr parent = KNFolder::Ptr() );
47 ~KNFolder();
49 //type
50 collectionType type() { return CTfolder; }
52 //id
53 int id() const { return i_d; }
54 void setId(int i) { i_d=i; }
55 int parentId() const { return p_arentId; }
56 bool isStandardFolder() { return (i_d > 0) && (i_d <=3); }
57 bool isRootFolder() { return i_d==0; }
59 //list item handling
60 void updateListItem();
61 bool wasOpen()const { return w_asOpen; }
63 //info
64 QString path();
65 bool readInfo(const QString &confPath);
66 bool readInfo();
67 void writeConfig();
69 //article access
70 KNLocalArticle::Ptr at( int i )
71 { return boost::static_pointer_cast<KNLocalArticle>( KNArticleCollection::at( i ) ); }
72 KNLocalArticle::Ptr byId( int id )
73 { return boost::static_pointer_cast<KNLocalArticle>( KNArticleCollection::byId( id ) ); }
74 KNLocalArticle::Ptr byMessageId( const QByteArray &mId )
75 { return boost::static_pointer_cast<KNLocalArticle>( KNArticleCollection::byMessageId( mId ) ); }
77 //parent
78 void setParent( KNCollection::Ptr p );
80 //load, save and delete
81 bool loadHdrs();
82 bool unloadHdrs(bool force=true);
83 /**
84 Load the full content of an article.
85 @param a the article to load.
86 @return true if the article is successfully loaded.
88 bool loadArticle( KNLocalArticle::Ptr a );
89 bool saveArticles( KNLocalArticle::List &l );
90 void removeArticles( KNLocalArticle::List &l, bool del = true );
91 void deleteAll();
92 void deleteFiles();
94 //index synchronization
95 void syncIndex(bool force=false);
97 protected:
98 void closeFiles();
99 int i_d; // unique id: 0: root folder 1-3: standard folders
100 int p_arentId; // -1 for the root folder
101 bool i_ndexDirty; // do we need to sync?
102 bool w_asOpen; // was this folder open in the listview on the last shutdown?
103 QFile m_boxFile;
104 QFile i_ndexFile;
105 QString i_nfoPath;
107 /* helper-class: stores index-data of an article */
108 class DynData {
109 public:
110 DynData() {}
111 ~DynData() {}
112 void setData( KNLocalArticle::Ptr a );
113 void getData( KNLocalArticle::Ptr a );
115 int id,
118 sId;
119 time_t ti;
120 bool flags[6];
123 private:
125 * Returns a shared pointer pointing to this folder.
127 KNFolder::Ptr thisFolderPtr();
130 * Reimplemented from KNArticleCollection::selfPtr().
132 virtual KNCollection::Ptr selfPtr()
134 return thisFolderPtr();
139 #endif