1.1.46
by Alessandro Ghersi
Import upstream version 4.3.80 |
1 |
/******************************************************************************
|
2 |
*
|
|
3 |
* Copyright 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
8 |
* (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
18 |
*
|
|
19 |
*******************************************************************************/
|
|
20 |
||
21 |
#ifndef __MESSAGELIST_CORE_MODEL_H__
|
|
22 |
#define __MESSAGELIST_CORE_MODEL_H__
|
|
23 |
||
24 |
#include <QAbstractItemModel> |
|
25 |
#include <QList> |
|
26 |
#include <QHash> |
|
27 |
#include <QMultiHash> |
|
28 |
#include <QDate> |
|
29 |
#include <QTimer> |
|
30 |
||
31 |
#include <messagelist/core/aggregation.h> |
|
32 |
#include <messagelist/core/enums.h> |
|
33 |
#include <messagelist/core/sortorder.h> |
|
34 |
||
35 |
#include <time.h> // time_t |
|
36 |
||
37 |
#include <messagelist/messagelist_export.h> |
|
38 |
||
39 |
class QTime; |
|
40 |
||
41 |
namespace MessageList |
|
42 |
{
|
|
43 |
||
44 |
namespace Core |
|
45 |
{
|
|
46 |
||
0.2.13
by Philip Muškovac
Import upstream version 4.7.0 |
47 |
typedef long int MessageItemSetReference; |
1.1.46
by Alessandro Ghersi
Import upstream version 4.3.80 |
48 |
|
49 |
class ViewItemJob; |
|
50 |
class Filter; |
|
51 |
class GroupHeaderItem; |
|
52 |
class Item; |
|
53 |
class Manager; |
|
54 |
class MessageItem; |
|
55 |
class Theme; |
|
56 |
class StorageModel; |
|
57 |
class ModelInvariantRowMapper; |
|
58 |
class MessageItemSetManager; |
|
59 |
class View; |
|
60 |
class ModelPrivate; |
|
61 |
||
62 |
/**
|
|
63 |
* This class manages the huge tree of displayable objects: GroupHeaderItems and MessageItems.
|
|
64 |
* The tree is exposed via a 'hacked' QAbstractItemModel interface to a QTreeView
|
|
65 |
* subclass (which is MessageList::View).
|
|
66 |
*
|
|
67 |
* The keypoint in this class is that it has to be non-blocking in manipulating the tree:
|
|
68 |
* fill, cleanup and update operations are performed in timed chunks. Perfect non-blocking
|
|
69 |
* behaviour is not possible since there are some small operations that basically can't be
|
|
0.2.13
by Philip Muškovac
Import upstream version 4.7.0 |
70 |
* split in chunks. However, these exceptions apply to a minority of tasks and in the
|
71 |
* average case the user will not notice.
|
|
1.1.46
by Alessandro Ghersi
Import upstream version 4.3.80 |
72 |
*
|
73 |
* The data for building the tree is obtained from a subclass of StorageModel. The
|
|
74 |
* StorageModel must offer a consistent rappresentation of a "flat" folder containing
|
|
75 |
* messages.
|
|
76 |
*/
|
|
77 |
class MESSAGELIST_EXPORT Model : public QAbstractItemModel |
|
78 |
{
|
|
79 |
friend class Item; |
|
80 |
friend class ItemPrivate; |
|
81 |
||
82 |
Q_OBJECT
|
|
83 |
public: |
|
84 |
||
85 |
/**
|
|
86 |
* Creates the mighty Model attached to the specified View.
|
|
87 |
*/
|
|
88 |
Model( View *pParent ); |
|
89 |
||
90 |
/**
|
|
91 |
* Destroys the mighty model along with the tree of items it manages.
|
|
92 |
*/
|
|
93 |
~Model(); |
|
94 |
||
95 |
/**
|
|
96 |
* Returns the StorageModel currently set.
|
|
97 |
*/
|
|
98 |
StorageModel *storageModel() const; |
|
99 |
||
100 |
/**
|
|
101 |
* Sets the storage model from that the messages to be displayed should be fetched.
|
|
102 |
* The model is then reset and a new fill operation is started. The fill operation may
|
|
103 |
* or may not complete before setStorageModel() returns. This depends on the fill
|
|
104 |
* strategy and the size of the folder. You can check if the fill operation has
|
|
105 |
* completed by looking at the return value of isLoading().
|
|
106 |
*
|
|
107 |
* Pre-selection is the action of automatically selecting a message just after the folder
|
|
108 |
* has finished loading. We may want to select the message that was selected the last
|
|
109 |
* time this folder has been open, or we may want to select the first unread message.
|
|
110 |
* We also may want to do no pre-selection at all (for example, when the user
|
|
111 |
* starts navigating the view before the pre-selection could actually be made
|
|
112 |
* and pre-selecting would confuse him). The pre-selection is applied once
|
|
113 |
* loading is complete.
|
|
114 |
*/
|
|
115 |
void setStorageModel( StorageModel *storageModel, PreSelectionMode preSelectionMode = PreSelectLastSelected ); |
|
116 |
||
117 |
/**
|
|
118 |
* Aborts any pending message pre-selection. This may be done if the user
|
|
119 |
* starts navigating the view and selecting items before we actually could
|
|
120 |
* apply the pre-selection.
|
|
121 |
*/
|
|
122 |
void abortMessagePreSelection(); |
|
123 |
||
124 |
/**
|
|
125 |
* Attempt to select the message with the specified unique id AND storage row as soon
|
|
126 |
* as possible (either now or when the view finishes loading). Please note that BOTH the uniqueId
|
|
127 |
* and the storage row are needed in order to perform the operation in all cases.
|
|
128 |
*
|
|
129 |
* This is a very special function. It can be called ONLY when the model is actually
|
|
130 |
* loading: it will assert if you do otherwise. This call is actually the only
|
|
131 |
* way to select an item that hasn't been read from the storage yet.
|
|
132 |
*/
|
|
133 |
void activateMessageAfterLoading( unsigned long uniqueIdOfMessage, int row ); |
|
134 |
||
135 |
/**
|
|
136 |
* Returns the hidden root item that all the messages are (or will be) attached to.
|
|
137 |
* The returned value is never 0.
|
|
138 |
*/
|
|
139 |
Item *rootItem() const; |
|
140 |
||
141 |
/**
|
|
142 |
* Returns true if the view is currently loading, that is
|
|
143 |
* it's in the first (possibly lenghty) job batch after attacching to a StorageModel.
|
|
144 |
*/
|
|
145 |
bool isLoading() const; |
|
146 |
||
147 |
/**
|
|
148 |
* Returns the message item that is at the _current_ storage row index
|
|
149 |
* or zero if no such storage item is found. Please note that this may return 0
|
|
150 |
* also if the specified storage row hasn't been actually read yet. This may happen
|
|
151 |
* if isLoading() returns true. In this case the only thing you can do is to retry in a while.
|
|
152 |
*/
|
|
153 |
MessageItem * messageItemByStorageRow( int row ) const; |
|
154 |
||
155 |
/**
|
|
156 |
* Sets the Aggregation mode.
|
|
157 |
* Does not reload the model in any way: you need to call setStorageModel( storageModel() ) for this to happen.
|
|
158 |
* The pointer ownership remains of the caller which must ensure its validity until the next
|
|
159 |
* call to setAggretation() or until this Model dies. The caller, in fact, is Widget which
|
|
160 |
* takes care of meeting the above conditions. The aggregation pointer must not be null.
|
|
161 |
*/
|
|
162 |
void setAggregation( const Aggregation * aggregation ); |
|
163 |
||
164 |
/**
|
|
165 |
* Sets the Theme.
|
|
166 |
* Does not reload the model in any way: you need to call setStorageModel( storageModel() ) for this to happen.
|
|
167 |
* The pointer ownership remains of the caller which must ensure its validity until the next
|
|
168 |
* call to setTheme() or until this Model dies. The caller, in fact, is Widget which
|
|
169 |
* takes care of meeting the above conditions. The theme pointer must not be null.
|
|
170 |
*/
|
|
171 |
void setTheme( const Theme * theme ); |
|
172 |
||
173 |
/**
|
|
174 |
* Sets the sort order. As with setTheme() and setAggregation(), this does not reload the
|
|
175 |
* model in any way.
|
|
176 |
*/
|
|
177 |
void setSortOrder( const SortOrder * sortOrder ); |
|
178 |
||
179 |
/**
|
|
180 |
* Sets the Filter to be applied on messages. filter may be null (no filter is applied).
|
|
181 |
* The pointer ownership remains of the caller which must ensure its validity until the next
|
|
182 |
* call to setFilter() or until this Model dies. The caller, in fact, is Widget which
|
|
183 |
* takes care of meeting the above conditions. The Filter pointer may be null.
|
|
184 |
*/
|
|
185 |
void setFilter( const Filter *filter ); |
|
186 |
||
187 |
/**
|
|
188 |
* Creates a persistent set for the specified MessageItems and
|
|
189 |
* returns its reference. Later you can use this reference
|
|
190 |
* to retrieve the list of MessageItems that are still valid.
|
|
191 |
* See persistentSetActualMessageList() for that.
|
|
192 |
*
|
|
193 |
* Persistent sets consume resources (both memory and CPU time
|
|
194 |
* while manipulating the view) so be sure to call deletePersistentSet()
|
|
195 |
* when you no longer need it.
|
|
196 |
*/
|
|
197 |
MessageItemSetReference createPersistentSet( const QList< MessageItem * > &items ); |
|
198 |
||
199 |
/**
|
|
200 |
* Returns the list of MessageItems that are still existing in the
|
|
201 |
* set pointed by the specified reference. This list will contain
|
|
202 |
* at most the messages that you have passed to createPersistentSet()
|
|
203 |
* but may contain less (even 0) if these MessageItem object were removed
|
|
204 |
* from the view for some reason.
|
|
205 |
*/
|
|
206 |
QList< MessageItem * > persistentSetCurrentMessageItemList( MessageItemSetReference ref ); |
|
207 |
||
208 |
/**
|
|
209 |
* Deletes the persistent set pointed by the specified reference.
|
|
210 |
* If the set does not exist anymore, nothing happens.
|
|
211 |
*/
|
|
212 |
void deletePersistentSet( MessageItemSetReference ref ); |
|
213 |
||
214 |
// Mandatory QAbstractItemModel interface.
|
|
215 |
||
216 |
virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; |
|
217 |
virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; |
|
218 |
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
|
219 |
virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; |
|
220 |
QModelIndex index( Item *item, int column ) const; |
|
221 |
virtual QModelIndex parent( const QModelIndex &index ) const; |
|
222 |
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; |
|
223 |
virtual Qt::ItemFlags flags( const QModelIndex &index ) const; |
|
224 |
||
0.2.13
by Philip Muškovac
Import upstream version 4.7.0 |
225 |
/// Called when user initiates a drag from the messagelist
|
226 |
virtual QMimeData* mimeData( const QModelIndexList& indexes ) const; |
|
227 |
||
1.1.46
by Alessandro Ghersi
Import upstream version 4.3.80 |
228 |
Q_SIGNALS: |
229 |
/**
|
|
230 |
* Notify the outside when updating the status bar with a message
|
|
231 |
* could be useful
|
|
232 |
*/
|
|
233 |
void statusMessage( const QString &message ); |
|
234 |
||
235 |
private: |
|
236 |
Q_PRIVATE_SLOT(d, void checkIfDateChanged()) |
|
237 |
Q_PRIVATE_SLOT(d, void viewItemJobStep()) |
|
238 |
Q_PRIVATE_SLOT(d, void slotStorageModelRowsInserted( const QModelIndex &, int, int )) |
|
239 |
Q_PRIVATE_SLOT(d, void slotStorageModelRowsRemoved( const QModelIndex &, int, int )) |
|
240 |
Q_PRIVATE_SLOT(d, void slotStorageModelDataChanged( const QModelIndex &, const QModelIndex & )) |
|
241 |
Q_PRIVATE_SLOT(d, void slotStorageModelHeaderDataChanged( Qt::Orientation, int, int )) |
|
242 |
Q_PRIVATE_SLOT(d, void slotStorageModelLayoutChanged()) |
|
243 |
||
244 |
friend class ModelPrivate; |
|
245 |
ModelPrivate * const d; |
|
246 |
};
|
|
247 |
||
248 |
} // namespace Core |
|
249 |
||
250 |
} // namespace MessageList |
|
251 |
||
252 |
#endif //!__MESSAGELIST_CORE_MODEL_H__ |