| 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     // FIXME (API/ABI break) Remove the create method taking a RCCList and make the method taking
    00041     //                       a RCCSpecList have a default param.
    00042     static SharedPtr<GenericCapabilityFilter<T> > create(const RequestableChannelClassList &rccs
    00043             = RequestableChannelClassList())
    00044     {
    00045         return SharedPtr<GenericCapabilityFilter<T> >(new GenericCapabilityFilter<T>(rccs));
    00046     }
    00047
    00048     static SharedPtr<GenericCapabilityFilter<T> > create(
    00049             const RequestableChannelClassSpecList &rccSpecs)
    00050     {
    00051         return SharedPtr<GenericCapabilityFilter<T> >(new GenericCapabilityFilter<T>(
    00052                     rccSpecs.bareClasses()));
    00053     }
    00054
    00055     inline virtual ~GenericCapabilityFilter() { }
    00056
    00057     inline virtual bool isValid() const { return true; }
    00058
    00059     inline virtual bool matches(const SharedPtr<T> &t) const
    00060     {
    00061         bool supportedRcc;
    00062         RequestableChannelClassList objectRccs = t->capabilities() ?
    00063             t->capabilities()->allClassSpecs().bareClasses() :
    00064             RequestableChannelClassList();
    00065         Q_FOREACH (const RequestableChannelClass &filterRcc, mFilter) {
    00066             supportedRcc = false;
    00067
    00068             Q_FOREACH (const RequestableChannelClass &objectRcc, objectRccs) {
    00069                 /* check if fixed properties match */
    00070                 if (filterRcc.fixedProperties == objectRcc.fixedProperties) {
    00071                     supportedRcc = true;
    00072
    00073                     /* check if all allowed properties in the filter RCC
    00074                      * are in the object RCC allowed properties */
    00075                     Q_FOREACH (const QString &value, filterRcc.allowedProperties) {
    00076                         if (!objectRcc.allowedProperties.contains(value)) {
    00077                             /* one of the properties in the filter RCC
    00078                              * allowed properties is not in the object RCC
    00079                              * allowed properties */
    00080                             supportedRcc = false;
    00081                             break;
    00082                         }
    00083                     }
    00084
    00085                     /* this RCC is supported, no need to check anymore */
    00086                     if (supportedRcc) {
    00087                         break;
    00088                     }
    00089                 }
    00090             }
    00091
    00092             /* one of the filter RCC is not supported, this object
    00093              * won't match filter */
    00094             if (!supportedRcc) {
    00095                 return false;
    00096             }
    00097         }
    00098
    00099         return true;
    00100     }
    00101
    00102     // FIXME: (API/ABI break) Return a RCCSpecList instead
    00103     inline RequestableChannelClassList filter() const { return mFilter; }
    00104
    00105     TELEPATHY_QT4_DEPRECATED inline void addRequestableChannelClassSubset(const RequestableChannelClass &rcc)
    00106     {
    00107         mFilter.append(rcc);
    00108     }
    00109
    00110     inline void addRequestableChannelClassSubset(const RequestableChannelClassSpec &rccSpec)
    00111     {
    00112         mFilter.append(rccSpec.bareClass());
    00113     }
    00114
    00115     TELEPATHY_QT4_DEPRECATED inline void setRequestableChannelClassesSubset(const RequestableChannelClassList &rccs)
    00116     {
    00117         mFilter = rccs;
    00118     }
    00119
    00120     inline void setRequestableChannelClassesSubset(const RequestableChannelClassSpecList &rccSpecs)
    00121     {
    00122         mFilter = rccSpecs.bareClasses();
    00123     }
    00124
    00125 private:
    00126     GenericCapabilityFilter(const RequestableChannelClassList &rccs) : Filter<T>(), mFilter(rccs) { }
    00127
    00128     // FIXME: (API/ABI break) Use RCCSpecList instead
    00129     RequestableChannelClassList mFilter;
    00130 };
    00131
    00132 } // Tp
    00133
    00134 #endif