| Home · All Classes · All Namespaces · Modules · Functions · Files

generic-capability-filter.h
1
23 #ifndef _TelepathyQt_generic_capability_filter_h_HEADER_GUARD_
24 #define _TelepathyQt_generic_capability_filter_h_HEADER_GUARD_
25
26 #ifndef IN_TP_QT_HEADER
27 #error IN_TP_QT_HEADER
28 #endif
29
30 #include <TelepathyQt/ConnectionCapabilities>
31 #include <TelepathyQt/Filter>
32 #include <TelepathyQt/Types>
33
34 namespace Tp
35 {
36
37 template <class T>
38 class GenericCapabilityFilter : public Filter<T>
39 {
40 public:
41 static SharedPtr<GenericCapabilityFilter<T> > create(
42 const RequestableChannelClassSpecList &rccSpecs = RequestableChannelClassSpecList())
43 {
44 return SharedPtr<GenericCapabilityFilter<T> >(new GenericCapabilityFilter<T>(
45 rccSpecs));
46 }
47
48 inline virtual ~GenericCapabilityFilter() { }
49
50 inline virtual bool isValid() const { return true; }
51
52 inline virtual bool matches(const SharedPtr<T> &t) const
53 {
54 bool supportedRcc;
55 RequestableChannelClassSpecList objectRccSpecs = t->capabilities().allClassSpecs();
56 Q_FOREACH (const RequestableChannelClassSpec &filterRccSpec, mFilter) {
57 supportedRcc = false;
58
59 Q_FOREACH (const RequestableChannelClassSpec &objectRccSpec, objectRccSpecs) {
60 /* check if fixed properties match */
61 if (filterRccSpec.fixedProperties() == objectRccSpec.fixedProperties()) {
62 supportedRcc = true;
63
64 /* check if all allowed properties in the filter RCC
65 * are in the object RCC allowed properties */
66 Q_FOREACH (const QString &value, filterRccSpec.allowedProperties()) {
67 if (!objectRccSpec.allowsProperty(value)) {
68 /* one of the properties in the filter RCC
69 * allowed properties is not in the object RCC
70 * allowed properties */
71 supportedRcc = false;
72 break;
73 }
74 }
75
76 /* this RCC is supported, no need to check anymore */
77 if (supportedRcc) {
78 break;
79 }
80 }
81 }
82
83 /* one of the filter RCC is not supported, this object
84 * won't match filter */
85 if (!supportedRcc) {
86 return false;
87 }
88 }
89
90 return true;
91 }
92
93 inline RequestableChannelClassSpecList filter() const { return mFilter; }
94
95 inline void addRequestableChannelClassSubset(const RequestableChannelClassSpec &rccSpec)
96 {
97 mFilter.append(rccSpec.bareClass());
98 }
99
100 inline void setRequestableChannelClassesSubset(const RequestableChannelClassSpecList &rccSpecs)
101 {
102 mFilter = rccSpecs.bareClasses();
103 }
104
105 private:
106 GenericCapabilityFilter(const RequestableChannelClassSpecList &rccSpecs)
107 : Filter<T>(), mFilter(rccSpecs) { }
108
109 RequestableChannelClassSpecList mFilter;
110 };
111
112 } // Tp
113
114 #endif
Tp::GenericCapabilityFilter::isValid
virtual bool isValid() const
Definition: generic-capability-filter.h:50
Tp
Definition: abstract-adaptor.cpp:31
Tp::RequestableChannelClassSpecList::bareClasses
RequestableChannelClassList bareClasses() const
Definition: requestable-channel-class-spec.h:125
Tp::GenericCapabilityFilter::filter
RequestableChannelClassSpecList filter() const
Definition: generic-capability-filter.h:93
Tp::RequestableChannelClassSpec::allowedProperties
QStringList allowedProperties() const
Definition: requestable-channel-class-spec.cpp:575
Tp::GenericCapabilityFilter::matches
virtual bool matches(const SharedPtr< T > &t) const
Definition: generic-capability-filter.h:52
QList::append
void append(const T &value)
Tp::RequestableChannelClassSpecList
The RequestableChannelClassSpecList class represents a list of RequestableChannelClassSpec.
Definition: requestable-channel-class-spec.h:101
Tp::GenericCapabilityFilter
The GenericCapabilityFilter class provides a generic filter object to be used to filter objects by ca...
Definition: generic-capability-filter.h:38
QString
Tp::GenericCapabilityFilter::addRequestableChannelClassSubset
void addRequestableChannelClassSubset(const RequestableChannelClassSpec &rccSpec)
Definition: generic-capability-filter.h:95
Tp::RequestableChannelClassSpec::bareClass
RequestableChannelClass bareClass() const
Definition: requestable-channel-class-spec.cpp:583
Tp::RequestableChannelClassSpec::fixedProperties
QVariantMap fixedProperties() const
Definition: requestable-channel-class-spec.cpp:559
Tp::GenericCapabilityFilter::~GenericCapabilityFilter
virtual ~GenericCapabilityFilter()
Definition: generic-capability-filter.h:48
Tp::RequestableChannelClassSpec
The RequestableChannelClassSpec class represents a Telepathy requestable channel class.
Definition: requestable-channel-class-spec.h:36
Tp::Filter
The Filter class provides a base class to be used by specialized filters such as GenericCapabilityFil...
Definition: filter.h:37
Tp::GenericCapabilityFilter::create
static SharedPtr< GenericCapabilityFilter< T > > create(const RequestableChannelClassSpecList &rccSpecs=RequestableChannelClassSpecList())
Definition: generic-capability-filter.h:41
Tp::RequestableChannelClassSpec::allowsProperty
bool allowsProperty(const QString &name) const
Definition: requestable-channel-class-spec.cpp:567
Tp::GenericCapabilityFilter::setRequestableChannelClassesSubset
void setRequestableChannelClassesSubset(const RequestableChannelClassSpecList &rccSpecs)
Definition: generic-capability-filter.h:100
Tp::SharedPtr
The SharedPtr class is a pointer to an explicitly shared object.
Definition: shared-ptr.h:39