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

generic-capability-filter.h

00001 /*
00002  * This file is part of TelepathyQt4
00003  *
00004  * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
00005  * Copyright (C) 2010 Nokia Corporation
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _TelepathyQt4_generic_capability_filter_h_HEADER_GUARD_
00023 #define _TelepathyQt4_generic_capability_filter_h_HEADER_GUARD_
00024 
00025 #ifndef IN_TELEPATHY_QT4_HEADER
00026 #error IN_TELEPATHY_QT4_HEADER
00027 #endif
00028 
00029 #include <TelepathyQt4/ConnectionCapabilities>
00030 #include <TelepathyQt4/Filter>
00031 #include <TelepathyQt4/Types>
00032 
00033 namespace Tp
00034 {
00035 
00036 template <class T>
00037 class GenericCapabilityFilter : public Filter<T>
00038 {
00039 public:
00040     static SharedPtr<GenericCapabilityFilter<T> > create(
00041             const RequestableChannelClassSpecList &rccSpecs = RequestableChannelClassSpecList())
00042     {
00043         return SharedPtr<GenericCapabilityFilter<T> >(new GenericCapabilityFilter<T>(
00044                     rccSpecs));
00045     }
00046 
00047     inline virtual ~GenericCapabilityFilter() { }
00048 
00049     inline virtual bool isValid() const { return true; }
00050 
00051     inline virtual bool matches(const SharedPtr<T> &t) const
00052     {
00053         bool supportedRcc;
00054         RequestableChannelClassSpecList objectRccSpecs = t->capabilities().allClassSpecs();
00055         Q_FOREACH (const RequestableChannelClassSpec &filterRccSpec, mFilter) {
00056             supportedRcc = false;
00057 
00058             Q_FOREACH (const RequestableChannelClassSpec &objectRccSpec, objectRccSpecs) {
00059                 /* check if fixed properties match */
00060                 if (filterRccSpec.fixedProperties() == objectRccSpec.fixedProperties()) {
00061                     supportedRcc = true;
00062 
00063                     /* check if all allowed properties in the filter RCC
00064                      * are in the object RCC allowed properties */
00065                     Q_FOREACH (const QString &value, filterRccSpec.allowedProperties()) {
00066                         if (!objectRccSpec.allowsProperty(value)) {
00067                             /* one of the properties in the filter RCC
00068                              * allowed properties is not in the object RCC
00069                              * allowed properties */
00070                             supportedRcc = false;
00071                             break;
00072                         }
00073                     }
00074 
00075                     /* this RCC is supported, no need to check anymore */
00076                     if (supportedRcc) {
00077                         break;
00078                     }
00079                 }
00080             }
00081 
00082             /* one of the filter RCC is not supported, this object
00083              * won't match filter */
00084             if (!supportedRcc) {
00085                 return false;
00086             }
00087         }
00088 
00089         return true;
00090     }
00091 
00092     inline RequestableChannelClassSpecList filter() const { return mFilter; }
00093 
00094     inline void addRequestableChannelClassSubset(const RequestableChannelClassSpec &rccSpec)
00095     {
00096         mFilter.append(rccSpec.bareClass());
00097     }
00098 
00099     inline void setRequestableChannelClassesSubset(const RequestableChannelClassSpecList &rccSpecs)
00100     {
00101         mFilter = rccSpecs.bareClasses();
00102     }
00103 
00104 private:
00105     GenericCapabilityFilter(const RequestableChannelClassSpecList &rccSpecs)
00106         : Filter<T>(), mFilter(rccSpecs) { }
00107 
00108     RequestableChannelClassSpecList mFilter;
00109 };
00110 
00111 } // Tp
00112 
00113 #endif


Copyright © 2008-2010 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.5.6.1