1 /** 2 * This file is part of TelepathyQt 3 * 4 * @copyright Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> 5 * @copyright Copyright (C) 2010 Nokia Corporation 6 * @license LGPL 2.1 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 */ 22 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 ~GenericCapabilityFilter()48 inline virtual ~GenericCapabilityFilter() { } 49 isValid()50 inline virtual bool isValid() const { return true; } 51 matches(const SharedPtr<T> & t)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 filter()93 inline RequestableChannelClassSpecList filter() const { return mFilter; } 94 addRequestableChannelClassSubset(const RequestableChannelClassSpec & rccSpec)95 inline void addRequestableChannelClassSubset(const RequestableChannelClassSpec &rccSpec) 96 { 97 mFilter.append(rccSpec.bareClass()); 98 } 99 setRequestableChannelClassesSubset(const RequestableChannelClassSpecList & rccSpecs)100 inline void setRequestableChannelClassesSubset(const RequestableChannelClassSpecList &rccSpecs) 101 { 102 mFilter = rccSpecs.bareClasses(); 103 } 104 105 private: GenericCapabilityFilter(const RequestableChannelClassSpecList & rccSpecs)106 GenericCapabilityFilter(const RequestableChannelClassSpecList &rccSpecs) 107 : Filter<T>(), mFilter(rccSpecs) { } 108 109 RequestableChannelClassSpecList mFilter; 110 }; 111 112 } // Tp 113 114 #endif 115