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(const RequestableChannelClassList &rccs
00041             = RequestableChannelClassList())
00042     {
00043         return SharedPtr<GenericCapabilityFilter<T> >(new GenericCapabilityFilter<T>(rccs));
00044     }
00045 
00046     inline virtual ~GenericCapabilityFilter() { }
00047 
00048     inline virtual bool isValid() const { return true; }
00049 
00050     inline virtual bool matches(const SharedPtr<T> &t) const
00051     {
00052         bool supportedRcc;
00053         RequestableChannelClassList objectRccs = t->capabilities() ?
00054             t->capabilities()->requestableChannelClasses() :
00055             RequestableChannelClassList();
00056         Q_FOREACH (const RequestableChannelClass &filterRcc, mFilter) {
00057             supportedRcc = false;
00058 
00059             Q_FOREACH (const RequestableChannelClass &objectRcc, objectRccs) {
00060                 /* check if fixed properties match */
00061                 if (filterRcc.fixedProperties == objectRcc.fixedProperties) {
00062                     supportedRcc = true;
00063 
00064                     /* check if all allowed properties in the filter RCC
00065                      * are in the object RCC allowed properties */
00066                     Q_FOREACH (const QString &value, filterRcc.allowedProperties) {
00067                         if (!objectRcc.allowedProperties.contains(value)) {
00068                             /* one of the properties in the filter RCC
00069                              * allowed properties is not in the object RCC
00070                              * allowed properties */
00071                             supportedRcc = false;
00072                             break;
00073                         }
00074                     }
00075 
00076                     /* this RCC is supported, no need to check anymore */
00077                     if (supportedRcc) {
00078                         break;
00079                     }
00080                 }
00081             }
00082 
00083             /* one of the filter RCC is not supported, this object
00084              * won't match filter */
00085             if (!supportedRcc) {
00086                 return false;
00087             }
00088         }
00089 
00090         return true;
00091     }
00092 
00093     inline RequestableChannelClassList filter() const { return mFilter; }
00094 
00095     inline void addRequestableChannelClassSubset(const RequestableChannelClass &rcc)
00096     {
00097         mFilter.append(rcc);
00098     }
00099 
00100     inline void setRequestableChannelClassesSubset(const RequestableChannelClassList &rccs)
00101     {
00102         mFilter = rccs;
00103     }
00104 
00105 private:
00106     GenericCapabilityFilter(const RequestableChannelClassList &rccs) : Filter<T>(), mFilter(rccs) { }
00107 
00108     RequestableChannelClassList mFilter;
00109 };
00110 
00111 } // Tp
00112 
00113 #endif


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