Akonadi

server/notificationsubscriber.h
1 /*
2  Copyright (c) 2015 Daniel Vrátil <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #ifndef NOTIFICATIONSUBSCRIBER_H
21 #define NOTIFICATIONSUBSCRIBER_H
22 
23 #include <QObject>
24 #include <QByteArray>
25 #include <QMimeDatabase>
26 #include <QMutex>
27 
28 #include <private/protocol_p.h>
29 #include "entities.h"
30 
31 class QLocalSocket;
32 
33 namespace Akonadi
34 {
35 namespace Server
36 {
37 
38 class NotificationManager;
39 
40 class NotificationSubscriber : public QObject
41 {
42  Q_OBJECT
43 
44 public:
45  explicit NotificationSubscriber(NotificationManager *manager, quintptr socketDescriptor);
46  ~NotificationSubscriber();
47 
48  Q_REQUIRED_RESULT inline QByteArray subscriber() const
49  {
50  return mSubscriber;
51  }
52 
53  Q_REQUIRED_RESULT QLocalSocket *socket() const
54  {
55  return mSocket;
56  }
57 
58  void handleIncomingData();
59 
60 public Q_SLOTS:
61  bool notify(const Akonadi::Protocol::ChangeNotificationPtr &notification);
62 
63 private Q_SLOTS:
64  void socketDisconnected();
65 
66 Q_SIGNALS:
67  void notificationDebuggingChanged(bool enabled);
68 
69 protected:
70  void registerSubscriber(const Protocol::CreateSubscriptionCommand &command);
71  void modifySubscription(const Protocol::ModifySubscriptionCommand &command);
72  void disconnectSubscriber();
73 
74 private:
75  bool acceptsNotification(const Protocol::ChangeNotification &notification) const;
76  bool acceptsItemNotification(const Protocol::ItemChangeNotification &notification) const;
77  bool acceptsCollectionNotification(const Protocol::CollectionChangeNotification &notification) const;
78  bool acceptsTagNotification(const Protocol::TagChangeNotification &notification) const;
79  bool acceptsRelationNotification(const Protocol::RelationChangeNotification &notification) const;
80  bool acceptsSubscriptionNotification(const Protocol::SubscriptionChangeNotification &notification) const;
81  bool acceptsDebugChangeNotification(const Protocol::DebugChangeNotification &notification) const;
82 
83  bool isCollectionMonitored(Entity::Id id) const;
84  bool isMimeTypeMonitored(const QString &mimeType) const;
85  bool isMoveDestinationResourceMonitored(const Protocol::ItemChangeNotification &msg) const;
86  bool isMoveDestinationResourceMonitored(const Protocol::CollectionChangeNotification &msg) const;
87 
88  Protocol::CollectionChangeNotificationPtr customizeCollection(const Protocol::CollectionChangeNotificationPtr &msg);
89  Protocol::SubscriptionChangeNotificationPtr toChangeNotification() const;
90 
91 protected Q_SLOTS:
92  virtual void writeNotification(const Akonadi::Protocol::ChangeNotificationPtr &notification);
93 
94 protected:
95  explicit NotificationSubscriber(NotificationManager *manager = nullptr);
96 
97  void writeCommand(qint64 tag, const Protocol::CommandPtr &cmd);
98 
99  mutable QMutex mLock;
100  NotificationManager *mManager = nullptr;
101  QLocalSocket *mSocket = nullptr;
102  QByteArray mSubscriber;
103  QSet<Entity::Id> mMonitoredCollections;
104  QSet<Entity::Id> mMonitoredItems;
105  QSet<Entity::Id> mMonitoredTags;
107  QSet<QString> mMonitoredMimeTypes;
108  QSet<QByteArray> mMonitoredResources;
109  QSet<QByteArray> mIgnoredSessions;
110  QByteArray mSession;
111  Protocol::ItemFetchScope mItemFetchScope;
112  Protocol::CollectionFetchScope mCollectionFetchScope;
113  Protocol::TagFetchScope mTagFetchScope;
114  bool mAllMonitored;
115  bool mExclusive;
116  bool mNotificationDebugging;
117 
118  static QMimeDatabase sMimeDatabase;
119 };
120 
121 } // namespace Server
122 } // namespace Akonadi
123 
124 #endif
Q_SIGNALSQ_SIGNALS
Q_OBJECTQ_OBJECT
Helper integration between Akonadi and Qt.
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.