Messagelib

aggregation.cpp
1 /******************************************************************************
2  *
3  * Copyright 2008 Szymon Tomasz Stefanek <[email protected]>
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 #include "core/aggregation.h"
22 
23 #include <QDataStream>
24 
25 #include <KLocalizedString>
26 
27 using namespace MessageList::Core;
28 
29 static const int gAggregationCurrentVersion = 0x1009; // increase if you add new fields of change the meaning of some
30 
31 Aggregation::Aggregation(
32  const QString &name, const QString &description, Grouping grouping, GroupExpandPolicy groupExpandPolicy, Threading threading, ThreadLeader threadLeader, ThreadExpandPolicy threadExpandPolicy, FillViewStrategy fillViewStrategy, bool readOnly)
33  : OptionSet(name, description, readOnly)
34  , mGrouping(grouping)
35  , mGroupExpandPolicy(groupExpandPolicy)
36  , mThreading(threading)
37  , mThreadLeader(threadLeader)
38  , mThreadExpandPolicy(threadExpandPolicy)
39  , mFillViewStrategy(fillViewStrategy)
40 {
41 }
42 
43 Aggregation::Grouping Aggregation::grouping() const
44 {
45  return mGrouping;
46 }
47 
48 Aggregation::Aggregation(
49  const Aggregation &opt)
50  : OptionSet(opt)
51  , mGrouping(opt.mGrouping)
52  , mGroupExpandPolicy(opt.mGroupExpandPolicy)
53  , mThreading(opt.mThreading)
54  , mThreadLeader(opt.mThreadLeader)
55  , mThreadExpandPolicy(opt.mThreadExpandPolicy)
56  , mFillViewStrategy(opt.mFillViewStrategy)
57 {
58 }
59 
60 Aggregation::Aggregation()
61  : OptionSet()
62  , mGrouping(NoGrouping)
63  , mGroupExpandPolicy(NeverExpandGroups)
64  , mThreading(NoThreading)
65  , mThreadLeader(TopmostMessage)
66  , mThreadExpandPolicy(NeverExpandThreads)
67  , mFillViewStrategy(FavorInteractivity)
68 {
69 }
70 
72 {
73  int val;
74 
75  stream >> val;
76  if (val != gAggregationCurrentVersion) {
77  return false; // b0rken (invalid version)
78  }
79 
80  stream >> val;
81  mGrouping = static_cast<Grouping>(val);
82  switch (mGrouping) {
83  case NoGrouping:
84  case GroupByDate:
85  case GroupByDateRange:
87  case GroupBySender:
88  case GroupByReceiver:
89  // ok
90  break;
91  default:
92  // b0rken
93  return false;
94  }
95 
96  stream >> val; // Formerly contained group sorting
97  stream >> val; // Formerly contained group sorting direction
98 
99  stream >> val;
100  mGroupExpandPolicy = (GroupExpandPolicy)val;
101  switch (mGroupExpandPolicy) {
102  case NeverExpandGroups:
103  case ExpandRecentGroups:
104  case AlwaysExpandGroups:
105  // ok
106  break;
107  default:
108  // b0rken
109  return false;
110  break;
111  }
112 
113  stream >> val;
114  mThreading = (Threading)val;
115  switch (mThreading) {
116  case NoThreading:
117  case PerfectOnly:
120  // ok
121  break;
122  default:
123  // b0rken
124  return false;
125  }
126 
127  stream >> val;
128  mThreadLeader = (ThreadLeader)val;
129  switch (mThreadLeader) {
130  case MostRecentMessage:
131  case TopmostMessage:
132  // ok
133  // FIXME: Should check that thread leaders setting matches grouping and threading settings.
134  break;
135  default:
136  // b0rken
137  return false;
138  }
139 
140  stream >> val;
141  mThreadExpandPolicy = (ThreadExpandPolicy)val;
142  switch (mThreadExpandPolicy) {
143  case NeverExpandThreads:
147  case AlwaysExpandThreads:
148  // ok
149  break;
150  default:
151  // b0rken
152  return false;
153  }
154 
155  stream >> val; // Formerly contained message sorting
156  stream >> val; // Formerly contained message sort direction
157 
158  stream >> val;
159  mFillViewStrategy = (FillViewStrategy)val;
160  switch (mFillViewStrategy) {
161  case FavorSpeed:
162  case FavorInteractivity:
164  // ok
165  break;
166  default:
167  // b0rken
168  return false;
169  }
170 
171  return true;
172 }
173 
174 void Aggregation::save(QDataStream &stream) const
175 {
176  stream << (int)gAggregationCurrentVersion;
177  stream << (int)mGrouping;
178  stream << 0; // Formerly group sorting
179  stream << 0; // Formerly group sort direction
180  stream << (int)mGroupExpandPolicy;
181  stream << (int)mThreading;
182  stream << (int)mThreadLeader;
183  stream << (int)mThreadExpandPolicy;
184  stream << 0; // Formerly message sorting
185  stream << 0; // Formerly message sort direction
186  stream << (int)mFillViewStrategy;
187 }
188 
190 {
191  return { {
192  i18nc("No grouping of messages", "None"), NoGrouping
193  },
194  {
195  i18n("By Exact Date (of Thread Leaders)"), GroupByDate
196  },
197  {
198  i18n("By Smart Date Ranges (of Thread Leaders)"), GroupByDateRange
199  },
200  {
201  i18n("By Smart Sender/Receiver"), GroupBySenderOrReceiver
202  },
203  {
204  i18n("By Sender"), GroupBySender
205  },
206  {
207  i18n("By Receiver"), GroupByReceiver
208  } };
209 }
210 
212 {
214  if (g == NoGrouping) {
215  return ret;
216  }
217  ret.append({ i18n("Never Expand Groups"), NeverExpandGroups });
218  if ((g == GroupByDate) || (g == GroupByDateRange)) {
219  ret.append({ i18n("Expand Recent Groups"), ExpandRecentGroups });
220  }
221  ret.append({ i18n("Always Expand Groups"), AlwaysExpandGroups });
222  return ret;
223 }
224 
226 {
227  return { {
228  i18nc("No threading of messages", "None"), NoThreading
229  },
230  {
231  i18n("Perfect Only"), PerfectOnly
232  },
233  {
234  i18n("Perfect and by References"), PerfectAndReferences
235  },
236  {
237  i18n("Perfect, by References and by Subject"), PerfectReferencesAndSubject
238  } };
239 }
240 
242 {
244  if (t == NoThreading) {
245  return ret;
246  }
247  ret.append({ i18n("Topmost Message"), TopmostMessage });
248  if ((g != GroupByDate) && (g != GroupByDateRange)) {
249  return ret;
250  }
251  ret.append({ i18n("Most Recent Message"), MostRecentMessage });
252  return ret;
253 }
254 
256 {
257  if (t == NoThreading) {
258  return {};
259  }
260 
261  return { {
262  i18n("Never Expand Threads"), NeverExpandThreads
263  },
264  {
265  i18n("Expand Threads With Unread Messages"), ExpandThreadsWithUnreadMessages
266  },
267  {
268  i18n("Expand Threads With Unread or Important Messages"), ExpandThreadsWithUnreadOrImportantMessages
269  },
270  {
271  i18n("Always Expand Threads"), AlwaysExpandThreads
272  } };
273 }
274 
276 {
277  return { {
278  i18n("Favor Interactivity"), FavorInteractivity
279  },
280  {
281  i18n("Favor Speed"), FavorSpeed
282  },
283  {
284  i18n("Batch Job (No Interactivity)"), BatchNoInteractivity
285  } };
286 }
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:80
A set of aggregation options that can be applied to the MessageList::Model in a single shot...
Definition: aggregation.h:39
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:43
ThreadExpandPolicy
The available thread expand policies.
Definition: aggregation.h:101
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:81
Perform no threading at all.
Definition: aggregation.h:78
Threading
The available threading methods.
Definition: aggregation.h:77
Makes sense only with GroupByDate or GroupByDateRange.
Definition: aggregation.h:67
FillViewStrategy
The available fill view strategies.
Definition: aggregation.h:115
Group the messages by the date of the thread leader.
Definition: aggregation.h:50
Thread by "In-Reply-To" field only.
Definition: aggregation.h:79
Never expand groups during a view fill algorithm.
Definition: aggregation.h:66
Use smart (thread leader) date ranges ("Today","Yesterday","Last Week"...)
Definition: aggregation.h:51
The implementation independent part of the MessageList library.
Definition: aggregation.h:33
Don&#39;t group messages at all.
Definition: aggregation.h:49
GroupExpandPolicy
The available group expand policies.
Definition: aggregation.h:65
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:91
Expand all threads (this might be very slow)
Definition: aggregation.h:105
ThreadLeader
The available thread leading options.
Definition: aggregation.h:90
Expand threads with unread messages (this includes new)
Definition: aggregation.h:104
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:68
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:117
Expand threads with "hot" messages (this includes new, unread, important, todo)
Definition: aggregation.h:106
Never expand any thread, this is fast.
Definition: aggregation.h:102
QString i18n(const char *text, const TYPE &arg...)
Grouping
Message grouping.
Definition: aggregation.h:48
The thread grouping is computed from the most recent message.
Definition: aggregation.h:92
Do small chunks of work, small intervals between chunks to allow for UI event processing.
Definition: aggregation.h:116
bool load(QDataStream &stream) override
Pure virtual reimplemented from OptionSet.
Definition: aggregation.cpp:71
DEPRECATED. New message status no longer exists.
Definition: aggregation.h:103
Do one large chunk, no interactivity at all.
Definition: aggregation.h:118
Group by sender (incoming) or receiver (outgoing) field.
Definition: aggregation.h:52
void save(QDataStream &stream) const override
Pure virtual reimplemented from OptionSet.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 1 2020 23:06:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.