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 : mGrouping(NoGrouping)
49 , mGroupExpandPolicy(NeverExpandGroups)
50 , mThreading(NoThreading)
51 , mThreadLeader(TopmostMessage)
52 , mThreadExpandPolicy(NeverExpandThreads)
53 , mFillViewStrategy(FavorInteractivity)
54{
55}
56
58{
59 int val;
60
61 stream >> val;
62 if (val != gAggregationCurrentVersion) {
63 return false; // b0rken (invalid version)
64 }
65
66 stream >> val;
67 mGrouping = static_cast<Grouping>(val);
68 switch (mGrouping) {
69 case NoGrouping:
70 case GroupByDate:
73 case GroupBySender:
74 case GroupByReceiver:
75 // ok
76 break;
77 default:
78 // b0rken
79 return false;
80 }
81
82 stream >> val; // Formerly contained group sorting
83 stream >> val; // Formerly contained group sorting direction
84
85 stream >> val;
86 mGroupExpandPolicy = (GroupExpandPolicy)val;
87 switch (mGroupExpandPolicy) {
91 // ok
92 break;
93 default:
94 // b0rken
95 return false;
96 break;
97 }
98
99 stream >> val;
100 mThreading = (Threading)val;
101 switch (mThreading) {
102 case NoThreading:
103 case PerfectOnly:
106 // ok
107 break;
108 default:
109 // b0rken
110 return false;
111 }
112
113 stream >> val;
114 mThreadLeader = (ThreadLeader)val;
115 switch (mThreadLeader) {
117 case TopmostMessage:
118 // ok
119 // FIXME: Should check that thread leaders setting matches grouping and threading settings.
120 break;
121 default:
122 // b0rken
123 return false;
124 }
125
126 stream >> val;
127 mThreadExpandPolicy = (ThreadExpandPolicy)val;
128 switch (mThreadExpandPolicy) {
134 // ok
135 break;
136 default:
137 // b0rken
138 return false;
139 }
140
141 stream >> val; // Formerly contained message sorting
142 stream >> val; // Formerly contained message sort direction
143
144 stream >> val;
145 mFillViewStrategy = (FillViewStrategy)val;
146 switch (mFillViewStrategy) {
147 case FavorSpeed:
150 // ok
151 break;
152 default:
153 // b0rken
154 return false;
155 }
156
157 return true;
158}
159
161{
162 stream << (int)gAggregationCurrentVersion;
163 stream << (int)mGrouping;
164 stream << 0; // Formerly group sorting
165 stream << 0; // Formerly group sort direction
166 stream << (int)mGroupExpandPolicy;
167 stream << (int)mThreading;
168 stream << (int)mThreadLeader;
169 stream << (int)mThreadExpandPolicy;
170 stream << 0; // Formerly message sorting
171 stream << 0; // Formerly message sort direction
172 stream << (int)mFillViewStrategy;
173}
174
176{
177 return {{i18nc("No grouping of messages", "None"), NoGrouping},
178 {i18n("By Exact Date (of Thread Leaders)"), GroupByDate},
179 {i18n("By Smart Date Ranges (of Thread Leaders)"), GroupByDateRange},
180 {i18n("By Smart Sender/Receiver"), GroupBySenderOrReceiver},
181 {i18n("By Sender"), GroupBySender},
182 {i18n("By Receiver"), GroupByReceiver}};
183}
184
186{
188 if (g == NoGrouping) {
189 return ret;
190 }
191 ret.append({i18n("Never Expand Groups"), NeverExpandGroups});
192 if ((g == GroupByDate) || (g == GroupByDateRange)) {
193 ret.append({i18n("Expand Recent Groups"), ExpandRecentGroups});
194 }
195 ret.append({i18n("Always Expand Groups"), AlwaysExpandGroups});
196 return ret;
197}
198
200{
201 return {{i18nc("No threading of messages", "None"), NoThreading},
202 {i18n("Perfect Only"), PerfectOnly},
203 {i18n("Perfect and by References"), PerfectAndReferences},
204 {i18n("Perfect, by References and by Subject"), PerfectReferencesAndSubject}};
205}
206
208{
210 if (t == NoThreading) {
211 return ret;
212 }
213 ret.append({i18n("Topmost Message"), TopmostMessage});
214 if ((g != GroupByDate) && (g != GroupByDateRange)) {
215 return ret;
216 }
217 ret.append({i18n("Most Recent Message"), MostRecentMessage});
218 return ret;
219}
220
222{
223 if (t == NoThreading) {
224 return {};
225 }
226
227 return {{i18n("Never Expand Threads"), NeverExpandThreads},
228 {i18n("Expand Threads With Unread Messages"), ExpandThreadsWithUnreadMessages},
229 {i18n("Expand Threads With Unread or Important Messages"), ExpandThreadsWithUnreadOrImportantMessages},
230 {i18n("Always Expand Threads"), AlwaysExpandThreads}};
231}
232
234{
235 return {{i18n("Favor Interactivity"), FavorInteractivity}, {i18n("Favor Speed"), FavorSpeed}, {i18n("Batch Job (No Interactivity)"), BatchNoInteractivity}};
236}
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-2025 The KDE developers.
Generated on Fri Apr 18 2025 12:11:02 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.