Messagelib

manager.h
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 #pragma once
10 
11 #include "core/sortorder.h"
12 #include <QList>
13 #include <QMap>
14 #include <QObject>
15 
16 #include <Akonadi/Collection>
17 
18 namespace KMime
19 {
20 class DateFormatter;
21 }
22 
23 namespace MessageList
24 {
25 namespace Core
26 {
27 class Aggregation;
28 class Theme;
29 class StorageModel;
30 class Widget;
31 
32 /**
33  * @brief: The manager for all the existing MessageList::Widget objects.
34  *
35  * This class is the "central" object of the whole MessageList framework.
36  * It's a singleton that can be accessed only by the means of static methods,
37  * is created automatically when the first MessageList::Widget object is created
38  * and destroyed automatically when the last MessageList::Widget object is destroyed.
39  *
40  * This class takes care of loading/storing/maintaining the settings for the
41  * whole MessageList framework. It also keeps track of all the existing
42  * MessageList::Widget objects and takes care of updating them when settings change.
43  */
44 class Manager : public QObject
45 {
46  Q_OBJECT
47 protected:
48  explicit Manager();
49  ~Manager() override;
50 
51 private:
52  static Manager *mInstance;
53  QList<Widget *> mWidgetList;
54  QMap<QString, Aggregation *> mAggregations;
55  QMap<QString, Theme *> mThemes;
56  KMime::DateFormatter *mDateFormatter = nullptr;
57  QString mCachedLocalizedUnknownText;
58 
59 public:
60  // instance management
61  static Manager *instance()
62  {
63  return mInstance;
64  }
65 
66  // widget registration
67  static void registerWidget(Widget *pWidget);
68  static void unregisterWidget(Widget *pWidget);
69 
70  const KMime::DateFormatter *dateFormatter() const
71  {
72  return mDateFormatter;
73  }
74 
75  const QString &cachedLocalizedUnknownText() const
76  {
77  return mCachedLocalizedUnknownText;
78  }
79 
80  // aggregation sets management
81  const Aggregation *aggregationForStorageModel(const StorageModel *storageModel, bool *storageUsesPrivateAggregation);
82  const Aggregation *aggregationForStorageModel(const QString &storageModel, bool *storageUsesPrivateAggregation);
83  const Aggregation *aggregationForStorageModel(const Akonadi::Collection &storageModel, bool *storageUsesPrivateAggregation);
84 
85  void saveAggregationForStorageModel(const StorageModel *storageModel, const QString &id, bool storageUsesPrivateAggregation);
86  void saveAggregationForStorageModel(const QString &index, const QString &id, bool storageUsesPrivateAggregation);
87  void saveAggregationForStorageModel(const Akonadi::Collection &col, const QString &id, bool storageUsesPrivateAggregation);
88 
89  const Aggregation *defaultAggregation();
90  const Aggregation *aggregation(const QString &id);
91 
92  void addAggregation(Aggregation *set);
93  void removeAllAggregations();
94 
95  const QMap<QString, Aggregation *> &aggregations() const
96  {
97  return mAggregations;
98  }
99 
100  /**
101  * This is called by the aggregation configuration dialog
102  * once the sets have been changed.
103  */
104  void aggregationsConfigurationCompleted();
105 
106  // sort order management
107  const SortOrder sortOrderForStorageModel(const StorageModel *storageModel, bool *storageUsesPrivateSortOrder);
108  void saveSortOrderForStorageModel(const StorageModel *storageModel, SortOrder order, bool storageUsesPrivateSortOrder);
109 
110  // theme sets management
111  const Theme *themeForStorageModel(const Akonadi::Collection &col, bool *storageUsesPrivateTheme);
112  const Theme *themeForStorageModel(const StorageModel *storageModel, bool *storageUsesPrivateTheme);
113  const Theme *themeForStorageModel(const QString &id, bool *storageUsesPrivateTheme);
114 
115  void saveThemeForStorageModel(const StorageModel *storageModel, const QString &id, bool storageUsesPrivateTheme);
116  void saveThemeForStorageModel(int index, const QString &id, bool storageUsesPrivateTheme);
117  void saveThemeForStorageModel(const QString &storageModelIndex, const QString &id, bool storageUsesPrivateTheme);
118 
119  const Theme *defaultTheme();
120  const Theme *theme(const QString &id);
121 
122  void addTheme(Theme *set);
123  void removeAllThemes();
124 
125  const QMap<QString, Theme *> &themes() const
126  {
127  return mThemes;
128  }
129 
130  /**
131  * This is called by the theme configuration dialog
132  * once the sets have been changed.
133  */
134  void themesConfigurationCompleted();
135 
136 protected Q_SLOTS:
137  /**
138  * Reloads the global configuration from the config files (so we assume it has changed)
139  * The settings private to MessageList (like Themes or Aggregations) aren't reloaded.
140  * If the global configuration has changed then all the views are reloaded.
141  */
142  void reloadGlobalConfiguration();
143 
144  /**
145  * Explicitly reloads the contents of all the widgets.
146  */
147  void reloadAllWidgets();
148 
149 Q_SIGNALS:
150  void aggregationsChanged();
151  void themesChanged();
152 
153 private:
154  // internal configuration stuff
155  void loadConfiguration();
156  void saveConfiguration();
157  void loadGlobalConfiguration();
158  void saveGlobalConfiguration();
159 
160  // internal option set management
161  void createDefaultAggregations();
162  void createDefaultThemes();
163 };
164 } // namespace Core
165 } // namespace MessageList
166 
A class which holds information about sorting, e.g.
Definition: sortorder.h:22
A set of aggregation options that can be applied to the MessageList::Model in a single shot...
Definition: aggregation.h:28
Provides a widget which has the messagelist and the most important helper widgets, like the search line and the comboboxes for changing status filtering, aggregation etc.
Definition: widgetbase.h:40
: The manager for all the existing MessageList::Widget objects.
Definition: manager.h:44
The QAbstractItemModel based interface that you need to provide for your storage to work with Message...
The Theme class defines the visual appearance of the MessageList.
Definition: theme.h:48
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.