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

channel-class-spec.h

    00001
    00023 #ifndef _TelepathyQt_channel_class_spec_h_HEADER_GUARD_
    00024 #define _TelepathyQt_channel_class_spec_h_HEADER_GUARD_
    00025
    00026 #ifndef IN_TP_QT_HEADER
    00027 #error IN_TP_QT_HEADER
    00028 #endif
    00029
    00030 #include <TelepathyQt/Constants>
    00031 #include <TelepathyQt/Global>
    00032 #include <TelepathyQt/Types>
    00033
    00034 #include <QSharedDataPointer>
    00035 #include <QVariant>
    00036 #include <QVariantMap>
    00037 #include <QPair>
    00038
    00039 namespace Tp
    00040 {
    00041
    00042 class TP_QT_EXPORT ChannelClassSpec
    00043 {
    00044 public:
    00045     ChannelClassSpec();
    00046     ChannelClassSpec(const ChannelClass &cc);
    00047     ChannelClassSpec(const QVariantMap &props);
    00048     ChannelClassSpec(const QString &channelType, HandleType targetHandleType,
    00049             const QVariantMap &otherProperties = QVariantMap());
    00050     ChannelClassSpec(const QString &channelType, HandleType targetHandleType, bool requested,
    00051             const QVariantMap &otherProperties = QVariantMap());
    00052     ChannelClassSpec(const ChannelClassSpec &other,
    00053             const QVariantMap &additionalProperties = QVariantMap());
    00054     ~ChannelClassSpec();
    00055
    00056     bool isValid() const;
    00057
    00058     ChannelClassSpec &operator=(const ChannelClassSpec &other);
    00059
    00060     bool operator==(const ChannelClassSpec &other) const
    00061     {
    00062         return this->allProperties() == other.allProperties();
    00063     }
    00064
    00065     bool isSubsetOf(const ChannelClassSpec &other) const;
    00066     bool matches(const QVariantMap &immutableProperties) const;
    00067
    00068     QString channelType() const
    00069     {
    00070         return qdbus_cast<QString>(
    00071                 property(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")));
    00072     }
    00073
    00074     void setChannelType(const QString &type)
    00075     {
    00076         setProperty(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"),
    00077                 QVariant::fromValue(type));
    00078     }
    00079
    00080     HandleType targetHandleType() const
    00081     {
    00082         return (HandleType) qdbus_cast<uint>(
    00083                 property(
    00084                     TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")));
    00085     }
    00086
    00087     void setTargetHandleType(HandleType type)
    00088     {
    00089         setProperty(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType"),
    00090                 QVariant::fromValue((uint) type));
    00091     }
    00092
    00093     bool hasRequested() const
    00094     {
    00095         return hasProperty(TP_QT_IFACE_CHANNEL + QLatin1String(".Requested"));
    00096     }
    00097
    00098     bool isRequested() const
    00099     {
    00100         return qdbus_cast<bool>(
    00101                 property(TP_QT_IFACE_CHANNEL + QLatin1String(".Requested")));
    00102     }
    00103
    00104     void setRequested(bool requested)
    00105     {
    00106         setProperty(TP_QT_IFACE_CHANNEL + QLatin1String(".Requested"),
    00107                 QVariant::fromValue(requested));
    00108     }
    00109
    00110     void unsetRequested()
    00111     {
    00112         unsetProperty(TP_QT_IFACE_CHANNEL + QLatin1String(".Requested"));
    00113     }
    00114
    00115     bool hasStreamedMediaInitialAudioFlag() const
    00116     {
    00117         return qdbus_cast<bool>(
    00118                 property(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialAudio")));
    00119     }
    00120
    00121     void setStreamedMediaInitialAudioFlag()
    00122     {
    00123         setProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialAudio"),
    00124                 QVariant::fromValue(true));
    00125     }
    00126
    00127     void unsetStreamedMediaInitialAudioFlag()
    00128     {
    00129         unsetProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialAudio"));
    00130     }
    00131
    00132     bool hasStreamedMediaInitialVideoFlag() const
    00133     {
    00134         return qdbus_cast<bool>(
    00135                 property(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialVideo")));
    00136     }
    00137
    00138     void setStreamedMediaInitialVideoFlag()
    00139     {
    00140         setProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialVideo"),
    00141                 QVariant::fromValue(true));
    00142     }
    00143
    00144     void unsetStreamedMediaInitialVideoFlag()
    00145     {
    00146         unsetProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialVideo"));
    00147     }
    00148
    00149     bool hasProperty(const QString &qualifiedName) const;
    00150     QVariant property(const QString &qualifiedName) const;
    00151
    00152     void setProperty(const QString &qualifiedName, const QVariant &value);
    00153     void unsetProperty(const QString &qualifiedName);
    00154
    00155     QVariantMap allProperties() const;
    00156     ChannelClass bareClass() const;
    00157
    00158     static ChannelClassSpec textChat(const QVariantMap &additionalProperties = QVariantMap());
    00159     static ChannelClassSpec textChatroom(const QVariantMap &additionalProperties = QVariantMap());
    00160     static ChannelClassSpec unnamedTextChat(const QVariantMap &additionalProperties = QVariantMap());
    00161
    00162     static ChannelClassSpec streamedMediaCall(const QVariantMap &additionalProperties = QVariantMap());
    00163     static ChannelClassSpec streamedMediaAudioCall(const QVariantMap &additionalProperties =
    00164             QVariantMap());
    00165     static ChannelClassSpec streamedMediaVideoCall(const QVariantMap &additionalProperties =
    00166             QVariantMap());
    00167     static ChannelClassSpec streamedMediaVideoCallWithAudio(const QVariantMap &additionalProperties =
    00168             QVariantMap());
    00169
    00170     static ChannelClassSpec unnamedStreamedMediaCall(const QVariantMap &additionalProperties =
    00171             QVariantMap());
    00172     static ChannelClassSpec unnamedStreamedMediaAudioCall(const QVariantMap &additionalProperties =
    00173             QVariantMap());
    00174     static ChannelClassSpec unnamedStreamedMediaVideoCall(const QVariantMap &additionalProperties =
    00175             QVariantMap());
    00176     static ChannelClassSpec unnamedStreamedMediaVideoCallWithAudio(const QVariantMap &additionalProperties =
    00177             QVariantMap());
    00178
    00179     // TODO: add Call when it's undrafted
    00180     static ChannelClassSpec roomList(const QVariantMap &additionalProperties = QVariantMap());
    00181     static ChannelClassSpec outgoingFileTransfer(const QVariantMap &additionalProperties = QVariantMap());
    00182     static ChannelClassSpec incomingFileTransfer(const QVariantMap &additionalProperties = QVariantMap());
    00183     static ChannelClassSpec outgoingStreamTube(const QString &service = QString(),
    00184             const QVariantMap &additionalProperties = QVariantMap());
    00185     static ChannelClassSpec incomingStreamTube(const QString &service = QString(),
    00186             const QVariantMap &additionalProperties = QVariantMap());
    00187     static ChannelClassSpec outgoingRoomStreamTube(const QString &service = QString(),
    00188             const QVariantMap &additionalProperties = QVariantMap());
    00189     static ChannelClassSpec incomingRoomStreamTube(const QString &service = QString(),
    00190             const QVariantMap &additionalProperties = QVariantMap());
    00191     // TODO: add dbus tubes when they're implemented
    00192     static ChannelClassSpec contactSearch(const QVariantMap &additionalProperties = QVariantMap());
    00193
    00194 private:
    00195     struct Private;
    00196     friend struct Private;
    00197     QSharedDataPointer<Private> mPriv;
    00198 };
    00199
    00200 class TP_QT_EXPORT ChannelClassSpecList :
    00201                 public QList<ChannelClassSpec>
    00202 {
    00203 public:
    00204     ChannelClassSpecList() { }
    00205
    00206     ChannelClassSpecList(const ChannelClassSpec &spec)
    00207     {
    00208         append(spec);
    00209     }
    00210
    00211     ChannelClassSpecList(const QList<ChannelClassSpec> &other)
    00212         : QList<ChannelClassSpec>(other)
    00213     {
    00214     }
    00215
    00216     ChannelClassSpecList(const ChannelClassList &classes)
    00217     {
    00218         // Why doesn't Qt have range constructors like STL... stupid, so stupid.
    00219         Q_FOREACH (const ChannelClass &cc, classes) {
    00220             append(cc);
    00221         }
    00222     }
    00223
    00224     ChannelClassList bareClasses() const
    00225     {
    00226         ChannelClassList list;
    00227         Q_FOREACH (const ChannelClassSpec &spec, *this) {
    00228             list.append(spec.bareClass());
    00229         }
    00230         return list;
    00231     }
    00232 };
    00233
    00234 inline uint qHash(const ChannelClassSpec &spec)
    00235 {
    00236     uint ret = 0;
    00237     QVariantMap::const_iterator it = spec.allProperties().constBegin();
    00238     QVariantMap::const_iterator end = spec.allProperties().constEnd();
    00239     int i = spec.allProperties().size() + 1;
    00240     for (; it != end; ++it) {
    00241         // all D-Bus types should be convertible to QString
    00242         QPair<QString, QString> p(it.key(), it.value().toString());
    00243         int h = qHash(p);
    00244         ret ^= ((h << (2 << i)) | (h >> (2 >> i)));
    00245         i--;
    00246     }
    00247     return ret;
    00248 }
    00249
    00250 inline uint qHash(const QSet<ChannelClassSpec> &specSet)
    00251 {
    00252     int ret = 0;
    00253     Q_FOREACH (const ChannelClassSpec &spec, specSet) {
    00254         int h = qHash(spec);
    00255         ret ^= h;
    00256     }
    00257     return ret;
    00258 }
    00259
    00260 inline uint qHash(const ChannelClassSpecList &specList)
    00261 {
    00262     // Make it unique by converting to QSet
    00263     QSet<ChannelClassSpec> uniqueSet = specList.toSet();
    00264     return qHash(uniqueSet);
    00265 }
    00266
    00267 } // Tp
    00268
    00269 Q_DECLARE_METATYPE(Tp::ChannelClassSpec);
    00270 Q_DECLARE_METATYPE(Tp::ChannelClassSpecList);
    00271
    00272 #endif