File indexing completed on 2024-12-15 04:54:36
0001 /****************************************************************************** 0002 * 0003 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 * 0007 *******************************************************************************/ 0008 0009 #pragma once 0010 0011 class QDataStream; 0012 0013 #include <QList> 0014 #include <QPair> 0015 #include <QString> 0016 0017 #include "core/optionset.h" 0018 0019 namespace MessageList 0020 { 0021 namespace Core 0022 { 0023 /** 0024 * A set of aggregation options that can be applied to the MessageList::Model in a single shot. 0025 * The set defines the behaviours related to the population of the model, threading 0026 * of messages and grouping. 0027 */ 0028 class Aggregation : public OptionSet 0029 { 0030 public: 0031 /** 0032 * Message grouping. 0033 * If you add values here please look at the implementations of the enumerate* functions 0034 * and add appropriate descriptors. 0035 */ 0036 enum Grouping { 0037 NoGrouping, ///< Don't group messages at all 0038 GroupByDate, ///< Group the messages by the date of the thread leader 0039 GroupByDateRange, ///< Use smart (thread leader) date ranges ("Today","Yesterday","Last Week"...) 0040 GroupBySenderOrReceiver, ///< Group by sender (incoming) or receiver (outgoing) field 0041 GroupBySender, ///< Group by sender, always 0042 GroupByReceiver ///< Group by receiver, always 0043 // Never add enum entries in the middle: always add them at the end (numeric values are stored in configuration) 0044 // TODO: Group by message status: "Important messages", "Urgent messages", "To reply", "To do" etc... 0045 // TODO: Group by message unread status: "Unread messages", "Read messages" (maybe "New" ?) 0046 }; 0047 0048 /** 0049 * The available group expand policies. 0050 * If you add values here please look at the implementations of the enumerate* functions 0051 * and add appropriate descriptors. 0052 */ 0053 enum GroupExpandPolicy { 0054 NeverExpandGroups, ///< Never expand groups during a view fill algorithm 0055 ExpandRecentGroups, ///< Makes sense only with GroupByDate or GroupByDateRange 0056 AlwaysExpandGroups ///< All groups are expanded as they are inserted 0057 // Never add enum entries in the middle: always add them at the end (numeric values are stored in configuration) 0058 }; 0059 0060 /** 0061 * The available threading methods. 0062 * If you add values here please look at the implementations of the enumerate* functions 0063 * and add appropriate descriptors. 0064 */ 0065 enum Threading { 0066 NoThreading, ///< Perform no threading at all 0067 PerfectOnly, ///< Thread by "In-Reply-To" field only 0068 PerfectAndReferences, ///< Thread by "In-Reply-To" and "References" fields 0069 PerfectReferencesAndSubject ///< Thread by all of the above and try to match subjects too 0070 // Never add enum entries in the middle: always add them at the end (numeric values are stored in configuration) 0071 }; 0072 0073 /** 0074 * The available thread leading options. Meaningless when threading is set to NoThreading. 0075 * If you add values here please look at the implementations of the enumerate* functions 0076 * and add appropriate descriptors. 0077 */ 0078 enum ThreadLeader { 0079 TopmostMessage, ///< The thread grouping is computed from the topmost message (very similar to least recent, but might be different if timezones or 0080 ///< machine clocks are screwed) 0081 MostRecentMessage ///< The thread grouping is computed from the most recent message 0082 // Never add enum entries in the middle: always add them at the end (numeric values are stored in configuration) 0083 }; 0084 0085 /** 0086 * The available thread expand policies. Meaningless when threading is set to NoThreading. 0087 * If you add values here please look at the implementations of the enumerate* functions 0088 * and add appropriate descriptors. 0089 */ 0090 enum ThreadExpandPolicy { 0091 NeverExpandThreads, ///< Never expand any thread, this is fast 0092 ExpandThreadsWithNewMessages, ///< DEPRECATED. New message status no longer exists. 0093 ExpandThreadsWithUnreadMessages, ///< Expand threads with unread messages (this includes new) 0094 AlwaysExpandThreads, ///< Expand all threads (this might be very slow) 0095 ExpandThreadsWithUnreadOrImportantMessages ///< Expand threads with "hot" messages (this includes new, unread, important, todo) 0096 // Never add enum entries in the middle: always add them at the end (numeric values are stored in configuration) 0097 }; 0098 0099 /** 0100 * The available fill view strategies. 0101 * If you add values here please look at the implementations of the enumerate* functions 0102 * and add appropriate descriptors. 0103 */ 0104 enum FillViewStrategy { 0105 FavorInteractivity, ///< Do small chunks of work, small intervals between chunks to allow for UI event processing 0106 FavorSpeed, ///< Do larger chunks of work, zero intervals between chunks 0107 BatchNoInteractivity ///< Do one large chunk, no interactivity at all 0108 // Warning: Never add enum entries in the middle: always add them at the end (numeric values are stored in configuration) 0109 }; 0110 0111 private: 0112 Grouping mGrouping; 0113 GroupExpandPolicy mGroupExpandPolicy; 0114 Threading mThreading; 0115 ThreadLeader mThreadLeader; 0116 ThreadExpandPolicy mThreadExpandPolicy; 0117 FillViewStrategy mFillViewStrategy; 0118 0119 public: 0120 explicit Aggregation(); 0121 explicit Aggregation(const Aggregation &opt); 0122 explicit Aggregation(const QString &name, 0123 const QString &description, 0124 Grouping grouping, 0125 GroupExpandPolicy groupExpandPolicy, 0126 Threading threading, 0127 ThreadLeader threadLeader, 0128 ThreadExpandPolicy threadExpandPolicy, 0129 FillViewStrategy fillViewStrategy, 0130 bool readOnly); 0131 [[nodiscard]] static bool compareName(Aggregation *agg1, Aggregation *agg2) 0132 { 0133 return agg1->name() < agg2->name(); 0134 } 0135 0136 public: 0137 /** 0138 * Returns the currently set Grouping option. 0139 */ 0140 [[nodiscard]] Grouping grouping() const; 0141 0142 /** 0143 * Sets the Grouping option. 0144 */ 0145 void setGrouping(Grouping g) 0146 { 0147 mGrouping = g; 0148 } 0149 0150 /** 0151 * Enumerates the available grouping options as a QList of 0152 * pairs in that the first item is the localized description of the 0153 * option value and the second item is the integer option value itself. 0154 */ 0155 static QList<QPair<QString, int>> enumerateGroupingOptions(); 0156 0157 /** 0158 * Returns the current GroupExpandPolicy. 0159 */ 0160 [[nodiscard]] GroupExpandPolicy groupExpandPolicy() const 0161 { 0162 return mGroupExpandPolicy; 0163 } 0164 0165 /** 0166 * Sets the GroupExpandPolicy for the groups. 0167 * Note that this option has no meaning if grouping is set to NoGrouping. 0168 */ 0169 void setGroupExpandPolicy(GroupExpandPolicy groupExpandPolicy) 0170 { 0171 mGroupExpandPolicy = groupExpandPolicy; 0172 } 0173 0174 /** 0175 * Enumerates the group sort direction options compatible with the specified Grouping. 0176 * The returned descriptors are pairs in that the first item is the localized description 0177 * of the option value and the second item is the integer option value itself. 0178 * If the returned list is empty then the value of the option is meaningless in the current context. 0179 */ 0180 static QList<QPair<QString, int>> enumerateGroupExpandPolicyOptions(Grouping g); 0181 0182 /** 0183 * Returns the current threading method. 0184 */ 0185 [[nodiscard]] Threading threading() const 0186 { 0187 return mThreading; 0188 } 0189 0190 /** 0191 * Sets the threading method option. 0192 */ 0193 void setThreading(Threading t) 0194 { 0195 mThreading = t; 0196 } 0197 0198 /** 0199 * Enumerates the available threading method options. 0200 * The returned descriptors are pairs in that the first item is the localized description 0201 * of the option value and the second item is the integer option value itself. 0202 */ 0203 static QList<QPair<QString, int>> enumerateThreadingOptions(); 0204 0205 /** 0206 * Returns the current thread leader determination method. 0207 */ 0208 [[nodiscard]] ThreadLeader threadLeader() const 0209 { 0210 return mThreadLeader; 0211 } 0212 0213 /** 0214 * Sets the current thread leader determination method. 0215 * Please note that when Threading is set to NoThreading this value is meaningless 0216 * and by policy should be set to TopmostMessage. 0217 */ 0218 void setThreadLeader(ThreadLeader tl) 0219 { 0220 mThreadLeader = tl; 0221 } 0222 0223 /** 0224 * Enumerates the thread leader determination methods compatible with the specified Threading 0225 * and the specified Grouping options. 0226 * The returned descriptors are pairs in that the first item is the localized description 0227 * of the option value and the second item is the integer option value itself. 0228 * If the returned list is empty then the value of the option is meaningless in the current context. 0229 */ 0230 static QList<QPair<QString, int>> enumerateThreadLeaderOptions(Grouping g, Threading t); 0231 0232 /** 0233 * Returns the current thread expand policy. 0234 */ 0235 ThreadExpandPolicy threadExpandPolicy() const 0236 { 0237 return mThreadExpandPolicy; 0238 } 0239 0240 /** 0241 * Sets the current thread expand policy. 0242 * Please note that when Threading is set to NoThreading this value is meaningless 0243 * and by policy should be set to NeverExpandThreads. 0244 */ 0245 void setThreadExpandPolicy(ThreadExpandPolicy threadExpandPolicy) 0246 { 0247 mThreadExpandPolicy = threadExpandPolicy; 0248 } 0249 0250 /** 0251 * Enumerates the thread expand policies compatible with the specified Threading option. 0252 * The returned descriptors are pairs in that the first item is the localized description 0253 * of the option value and the second item is the integer option value itself. 0254 * If the returned list is empty then the value of the option is meaningless in the current context. 0255 */ 0256 static QList<QPair<QString, int>> enumerateThreadExpandPolicyOptions(Threading t); 0257 0258 /** 0259 * Returns the current fill view strategy. 0260 */ 0261 [[nodiscard]] FillViewStrategy fillViewStrategy() const 0262 { 0263 return mFillViewStrategy; 0264 } 0265 0266 /** 0267 * Sets the current fill view strategy. 0268 */ 0269 void setFillViewStrategy(FillViewStrategy fillViewStrategy) 0270 { 0271 mFillViewStrategy = fillViewStrategy; 0272 } 0273 0274 /** 0275 * Enumerates the fill view strategies. 0276 * The returned descriptors are pairs in that the first item is the localized description 0277 * of the option value and the second item is the integer option value itself. 0278 */ 0279 static QList<QPair<QString, int>> enumerateFillViewStrategyOptions(); 0280 0281 /** 0282 * Pure virtual reimplemented from OptionSet. 0283 */ 0284 void save(QDataStream &stream) const override; 0285 0286 /** 0287 * Pure virtual reimplemented from OptionSet. 0288 */ 0289 bool load(QDataStream &stream) override; 0290 }; 0291 } // namespace Core 0292 } // namespace MessageList