Messagelib

aggregation.cpp
1 /******************************************************************************
2  *
3  * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <[email protected]>
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 
15 using namespace MessageList::Core;
16 
17 static const int gAggregationCurrentVersion = 0x1009; // increase if you add new fields of change the meaning of some
18 
19 Aggregation::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 
38 Aggregation::Grouping Aggregation::grouping() const
39 {
40  return mGrouping;
41 }
42 
43 Aggregation::Aggregation(const Aggregation &opt)
44 
45  = default;
46 
47 Aggregation::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:
72  case GroupByDateRange:
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) {
89  case NeverExpandGroups:
90  case ExpandRecentGroups:
91  case AlwaysExpandGroups:
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) {
117  case MostRecentMessage:
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) {
130  case NeverExpandThreads:
134  case AlwaysExpandThreads:
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:
149  case FavorInteractivity:
151  // ok
152  break;
153  default:
154  // b0rken
155  return false;
156  }
157 
158  return true;
159 }
160 
161 void Aggregation::save(QDataStream &stream) const
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 }
static QVector< QPair< QString, int > > enumerateGroupExpandPolicyOptions(Grouping g)
Enumerates the group sort direction options compatible with the specified Grouping.
Thread by "In-Reply-To" and "References" fields.
Definition: aggregation.h:68
A set of aggregation options that can be applied to the MessageList::Model in a single shot...
Definition: aggregation.h:28
static QVector< QPair< QString, int > > enumerateThreadExpandPolicyOptions(Threading t)
Enumerates the thread expand policies compatible with the specified Threading option.
A set of options that can be applied to the MessageList in one shot.
Definition: optionset.h:32
ThreadExpandPolicy
The available thread expand policies.
Definition: aggregation.h:90
void append(const T &value)
static QVector< QPair< QString, int > > enumerateThreadingOptions()
Enumerates the available threading method options.
Thread by all of the above and try to match subjects too.
Definition: aggregation.h:69
Perform no threading at all.
Definition: aggregation.h:66
Threading
The available threading methods.
Definition: aggregation.h:65
Makes sense only with GroupByDate or GroupByDateRange.
Definition: aggregation.h:55
FillViewStrategy
The available fill view strategies.
Definition: aggregation.h:104
Group the messages by the date of the thread leader.
Definition: aggregation.h:38
Thread by "In-Reply-To" field only.
Definition: aggregation.h:67
Never expand groups during a view fill algorithm.
Definition: aggregation.h:54
Use smart (thread leader) date ranges ("Today","Yesterday","Last Week"...)
Definition: aggregation.h:39
The implementation independent part of the MessageList library.
Definition: aggregation.h:21
Don&#39;t group messages at all.
Definition: aggregation.h:37
GroupExpandPolicy
The available group expand policies.
Definition: aggregation.h:53
The thread grouping is computed from the topmost message (very similar to least recent, but might be different if timezones or machine clocks are screwed)
Definition: aggregation.h:79
Expand all threads (this might be very slow)
Definition: aggregation.h:94
ThreadLeader
The available thread leading options.
Definition: aggregation.h:78
Expand threads with unread messages (this includes new)
Definition: aggregation.h:93
QString i18nc(const char *context, const char *text, const TYPE &arg...)
static QVector< QPair< QString, int > > enumerateThreadLeaderOptions(Grouping g, Threading t)
Enumerates the thread leader determination methods compatible with the specified Threading and the sp...
All groups are expanded as they are inserted.
Definition: aggregation.h:56
static QVector< QPair< QString, int > > enumerateGroupingOptions()
Enumerates the available grouping options as a QList of pairs in that the first item is the localized...
static QVector< QPair< QString, int > > enumerateFillViewStrategyOptions()
Enumerates the fill view strategies.
Do larger chunks of work, zero intervals between chunks.
Definition: aggregation.h:106
Expand threads with "hot" messages (this includes new, unread, important, todo)
Definition: aggregation.h:95
Never expand any thread, this is fast.
Definition: aggregation.h:91
QString i18n(const char *text, const TYPE &arg...)
Grouping
Message grouping.
Definition: aggregation.h:36
The thread grouping is computed from the most recent message.
Definition: aggregation.h:81
Do small chunks of work, small intervals between chunks to allow for UI event processing.
Definition: aggregation.h:105
bool load(QDataStream &stream) override
Pure virtual reimplemented from OptionSet.
Definition: aggregation.cpp:58
DEPRECATED. New message status no longer exists.
Definition: aggregation.h:92
Do one large chunk, no interactivity at all.
Definition: aggregation.h:107
Group by sender (incoming) or receiver (outgoing) field.
Definition: aggregation.h:40
void save(QDataStream &stream) const override
Pure virtual reimplemented from OptionSet.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.