Messagelib

aggregation.cpp
1/******************************************************************************
2 *
3 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 *
7 *******************************************************************************/
8
9#include "core/aggregation.h"
10
11#include <QDataStream>
12
13#include <KLocalizedString>
14
15using namespace MessageList::Core;
16
17static const int gAggregationCurrentVersion = 0x1009; // increase if you add new fields of change the meaning of some
18
19Aggregation::Aggregation(const QString &name,
20 const QString &description,
21 Grouping grouping,
22 GroupExpandPolicy groupExpandPolicy,
23 Threading threading,
24 ThreadLeader threadLeader,
25 ThreadExpandPolicy threadExpandPolicy,
26 FillViewStrategy fillViewStrategy,
27 bool readOnly)
28 : OptionSet(name, description, readOnly)
29 , mGrouping(grouping)
30 , mGroupExpandPolicy(groupExpandPolicy)
31 , mThreading(threading)
32 , mThreadLeader(threadLeader)
33 , mThreadExpandPolicy(threadExpandPolicy)
34 , mFillViewStrategy(fillViewStrategy)
35{
36}
37
39{
40 return mGrouping;
41}
42
43Aggregation::Aggregation(const Aggregation &opt)
44
45 = default;
46
47Aggregation::Aggregation()
48 : OptionSet()
49 , mGrouping(NoGrouping)
50 , mGroupExpandPolicy(NeverExpandGroups)
51 , mThreading(NoThreading)
52 , mThreadLeader(TopmostMessage)
53 , mThreadExpandPolicy(NeverExpandThreads)
54 , mFillViewStrategy(FavorInteractivity)
55{
56}
57
59{
60 int val;
61
62 stream >> val;
63 if (val != gAggregationCurrentVersion) {
64 return false; // b0rken (invalid version)
65 }
66
67 stream >> val;
68 mGrouping = static_cast<Grouping>(val);
69 switch (mGrouping) {
70 case NoGrouping:
71 case GroupByDate:
74 case GroupBySender:
75 case GroupByReceiver:
76 // ok
77 break;
78 default:
79 // b0rken
80 return false;
81 }
82
83 stream >> val; // Formerly contained group sorting
84 stream >> val; // Formerly contained group sorting direction
85
86 stream >> val;
87 mGroupExpandPolicy = (GroupExpandPolicy)val;
88 switch (mGroupExpandPolicy) {
92 // ok
93 break;
94 default:
95 // b0rken
96 return false;
97 break;
98 }
99
100 stream >> val;
101 mThreading = (Threading)val;
102 switch (mThreading) {
103 case NoThreading:
104 case PerfectOnly:
107 // ok
108 break;
109 default:
110 // b0rken
111 return false;
112 }
113
114 stream >> val;
115 mThreadLeader = (ThreadLeader)val;
116 switch (mThreadLeader) {
118 case TopmostMessage:
119 // ok
120 // FIXME: Should check that thread leaders setting matches grouping and threading settings.
121 break;
122 default:
123 // b0rken
124 return false;
125 }
126
127 stream >> val;
128 mThreadExpandPolicy = (ThreadExpandPolicy)val;
129 switch (mThreadExpandPolicy) {
135 // ok
136 break;
137 default:
138 // b0rken
139 return false;
140 }
141
142 stream >> val; // Formerly contained message sorting
143 stream >> val; // Formerly contained message sort direction
144
145 stream >> val;
146 mFillViewStrategy = (FillViewStrategy)val;
147 switch (mFillViewStrategy) {
148 case FavorSpeed:
151 // ok
152 break;
153 default:
154 // b0rken
155 return false;
156 }
157
158 return true;
159}
160
162{
163 stream << (int)gAggregationCurrentVersion;
164 stream << (int)mGrouping;
165 stream << 0; // Formerly group sorting
166 stream << 0; // Formerly group sort direction
167 stream << (int)mGroupExpandPolicy;
168 stream << (int)mThreading;
169 stream << (int)mThreadLeader;
170 stream << (int)mThreadExpandPolicy;
171 stream << 0; // Formerly message sorting
172 stream << 0; // Formerly message sort direction
173 stream << (int)mFillViewStrategy;
174}
175
177{
178 return {{i18nc("No grouping of messages", "None"), NoGrouping},
179 {i18n("By Exact Date (of Thread Leaders)"), GroupByDate},
180 {i18n("By Smart Date Ranges (of Thread Leaders)"), GroupByDateRange},
181 {i18n("By Smart Sender/Receiver"), GroupBySenderOrReceiver},
182 {i18n("By Sender"), GroupBySender},
183 {i18n("By Receiver"), GroupByReceiver}};
184}
185
187{
189 if (g == NoGrouping) {
190 return ret;
191 }
192 ret.append({i18n("Never Expand Groups"), NeverExpandGroups});
193 if ((g == GroupByDate) || (g == GroupByDateRange)) {
194 ret.append({i18n("Expand Recent Groups"), ExpandRecentGroups});
195 }
196 ret.append({i18n("Always Expand Groups"), AlwaysExpandGroups});
197 return ret;
198}
199
201{
202 return {{i18nc("No threading of messages", "None"), NoThreading},
203 {i18n("Perfect Only"), PerfectOnly},
204 {i18n("Perfect and by References"), PerfectAndReferences},
205 {i18n("Perfect, by References and by Subject"), PerfectReferencesAndSubject}};
206}
207
209{
211 if (t == NoThreading) {
212 return ret;
213 }
214 ret.append({i18n("Topmost Message"), TopmostMessage});
215 if ((g != GroupByDate) && (g != GroupByDateRange)) {
216 return ret;
217 }
218 ret.append({i18n("Most Recent Message"), MostRecentMessage});
219 return ret;
220}
221
223{
224 if (t == NoThreading) {
225 return {};
226 }
227
228 return {{i18n("Never Expand Threads"), NeverExpandThreads},
229 {i18n("Expand Threads With Unread Messages"), ExpandThreadsWithUnreadMessages},
230 {i18n("Expand Threads With Unread or Important Messages"), ExpandThreadsWithUnreadOrImportantMessages},
231 {i18n("Always Expand Threads"), AlwaysExpandThreads}};
232}
233
235{
236 return {{i18n("Favor Interactivity"), FavorInteractivity}, {i18n("Favor Speed"), FavorSpeed}, {i18n("Batch Job (No Interactivity)"), BatchNoInteractivity}};
237}
A set of aggregation options that can be applied to the MessageList::Model in a single shot.
Definition aggregation.h:29
@ GroupBySender
Group by sender, always.
Definition aggregation.h:41
@ NoGrouping
Don't group messages at all.
Definition aggregation.h:37
@ GroupByDateRange
Use smart (thread leader) date ranges ("Today","Yesterday","Last Week"...)
Definition aggregation.h:39
@ GroupBySenderOrReceiver
Group by sender (incoming) or receiver (outgoing) field.
Definition aggregation.h:40
@ GroupByDate
Group the messages by the date of the thread leader.
Definition aggregation.h:38
@ GroupByReceiver
Group by receiver, always.
Definition aggregation.h:42
GroupExpandPolicy
The available group expand policies.
Definition aggregation.h:53
@ NeverExpandGroups
Never expand groups during a view fill algorithm.
Definition aggregation.h:54
@ ExpandRecentGroups
Makes sense only with GroupByDate or GroupByDateRange.
Definition aggregation.h:55
@ AlwaysExpandGroups
All groups are expanded as they are inserted.
Definition aggregation.h:56
static QList< QPair< QString, int > > enumerateGroupExpandPolicyOptions(Grouping g)
Enumerates the group sort direction options compatible with the specified Grouping.
void save(QDataStream &stream) const override
Pure virtual reimplemented from OptionSet.
Threading
The available threading methods.
Definition aggregation.h:65
@ NoThreading
Perform no threading at all.
Definition aggregation.h:66
@ PerfectReferencesAndSubject
Thread by all of the above and try to match subjects too.
Definition aggregation.h:69
@ PerfectOnly
Thread by "In-Reply-To" field only.
Definition aggregation.h:67
@ PerfectAndReferences
Thread by "In-Reply-To" and "References" fields.
Definition aggregation.h:68
static QList< QPair< QString, int > > enumerateGroupingOptions()
Enumerates the available grouping options as a QList of pairs in that the first item is the localized...
static QList< QPair< QString, int > > enumerateFillViewStrategyOptions()
Enumerates the fill view strategies.
Grouping grouping() const
Returns the currently set Grouping option.
static QList< QPair< QString, int > > enumerateThreadExpandPolicyOptions(Threading t)
Enumerates the thread expand policies compatible with the specified Threading option.
static QList< QPair< QString, int > > enumerateThreadLeaderOptions(Grouping g, Threading t)
Enumerates the thread leader determination methods compatible with the specified Threading and the sp...
bool load(QDataStream &stream) override
Pure virtual reimplemented from OptionSet.
ThreadExpandPolicy
The available thread expand policies.
Definition aggregation.h:90
@ AlwaysExpandThreads
Expand all threads (this might be very slow)
Definition aggregation.h:94
@ ExpandThreadsWithUnreadOrImportantMessages
Expand threads with "hot" messages (this includes new, unread, important, todo)
Definition aggregation.h:95
@ ExpandThreadsWithNewMessages
DEPRECATED. New message status no longer exists.
Definition aggregation.h:92
@ ExpandThreadsWithUnreadMessages
Expand threads with unread messages (this includes new)
Definition aggregation.h:93
@ NeverExpandThreads
Never expand any thread, this is fast.
Definition aggregation.h:91
ThreadLeader
The available thread leading options.
Definition aggregation.h:78
@ TopmostMessage
The thread grouping is computed from the topmost message (very similar to least recent,...
Definition aggregation.h:79
@ MostRecentMessage
The thread grouping is computed from the most recent message.
Definition aggregation.h:81
static QList< QPair< QString, int > > enumerateThreadingOptions()
Enumerates the available threading method options.
FillViewStrategy
The available fill view strategies.
@ FavorSpeed
Do larger chunks of work, zero intervals between chunks.
@ FavorInteractivity
Do small chunks of work, small intervals between chunks to allow for UI event processing.
@ BatchNoInteractivity
Do one large chunk, no interactivity at all.
A set of options that can be applied to the MessageList in one shot.
Definition optionset.h:33
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString name(StandardAction id)
The implementation independent part of the MessageList library.
Definition aggregation.h:22
void append(QList< T > &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.