| 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 hasCallInitialAudioFlag() const
    00116     {
    00117         return qdbus_cast<bool>(
    00118                 property(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialAudio")));
    00119     }
    00120
    00121     void setCallInitialAudioFlag()
    00122     {
    00123         setProperty(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialAudio"),
    00124                 QVariant::fromValue(true));
    00125     }
    00126
    00127     void unsetCallInitialAudioFlag()
    00128     {
    00129         unsetProperty(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialAudio"));
    00130     }
    00131
    00132     bool hasCallInitialVideoFlag() const
    00133     {
    00134         return qdbus_cast<bool>(
    00135                 property(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialVideo")));
    00136     }
    00137
    00138     void setCallInitialVideoFlag()
    00139     {
    00140         setProperty(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialVideo"),
    00141                 QVariant::fromValue(true));
    00142     }
    00143
    00144     void unsetCallInitialVideoFlag()
    00145     {
    00146         unsetProperty(TP_QT_IFACE_CHANNEL_TYPE_CALL + QLatin1String(".InitialVideo"));
    00147     }
    00148
    00149     bool hasStreamedMediaInitialAudioFlag() const
    00150     {
    00151         return qdbus_cast<bool>(
    00152                 property(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialAudio")));
    00153     }
    00154
    00155     void setStreamedMediaInitialAudioFlag()
    00156     {
    00157         setProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialAudio"),
    00158                 QVariant::fromValue(true));
    00159     }
    00160
    00161     void unsetStreamedMediaInitialAudioFlag()
    00162     {
    00163         unsetProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialAudio"));
    00164     }
    00165
    00166     bool hasStreamedMediaInitialVideoFlag() const
    00167     {
    00168         return qdbus_cast<bool>(
    00169                 property(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialVideo")));
    00170     }
    00171
    00172     void setStreamedMediaInitialVideoFlag()
    00173     {
    00174         setProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialVideo"),
    00175                 QVariant::fromValue(true));
    00176     }
    00177
    00178     void unsetStreamedMediaInitialVideoFlag()
    00179     {
    00180         unsetProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialVideo"));
    00181     }
    00182
    00183     bool hasProperty(const QString &qualifiedName) const;
    00184     QVariant property(const QString &qualifiedName) const;
    00185
    00186     void setProperty(const QString &qualifiedName, const QVariant &value);
    00187     void unsetProperty(const QString &qualifiedName);
    00188
    00189     QVariantMap allProperties() const;
    00190     ChannelClass bareClass() const;
    00191
    00192     static ChannelClassSpec textChat(const QVariantMap &additionalProperties = QVariantMap());
    00193     static ChannelClassSpec textChatroom(const QVariantMap &additionalProperties = QVariantMap());
    00194     static ChannelClassSpec unnamedTextChat(const QVariantMap &additionalProperties = QVariantMap());
    00195
    00196     static ChannelClassSpec audioCall(const QVariantMap &additionalProperties =
    00197             QVariantMap());
    00198     static ChannelClassSpec videoCall(const QVariantMap &additionalProperties =
    00199             QVariantMap());
    00200     static ChannelClassSpec videoCallWithAudio(const QVariantMap &additionalProperties =
    00201             QVariantMap());
    00202
    00203     static ChannelClassSpec streamedMediaCall(const QVariantMap &additionalProperties = QVariantMap());
    00204     static ChannelClassSpec streamedMediaAudioCall(const QVariantMap &additionalProperties =
    00205             QVariantMap());
    00206     static ChannelClassSpec streamedMediaVideoCall(const QVariantMap &additionalProperties =
    00207             QVariantMap());
    00208     static ChannelClassSpec streamedMediaVideoCallWithAudio(const QVariantMap &additionalProperties =
    00209             QVariantMap());
    00210
    00211     static ChannelClassSpec unnamedStreamedMediaCall(const QVariantMap &additionalProperties =
    00212             QVariantMap());
    00213     static ChannelClassSpec unnamedStreamedMediaAudioCall(const QVariantMap &additionalProperties =
    00214             QVariantMap());
    00215     static ChannelClassSpec unnamedStreamedMediaVideoCall(const QVariantMap &additionalProperties =
    00216             QVariantMap());
    00217     static ChannelClassSpec unnamedStreamedMediaVideoCallWithAudio(const QVariantMap &additionalProperties =
    00218             QVariantMap());
    00219
    00220     static ChannelClassSpec serverAuthentication(const QVariantMap &additionalProperties =
    00221             QVariantMap());
    00222
    00223     static ChannelClassSpec roomList(const QVariantMap &additionalProperties = QVariantMap());
    00224     static ChannelClassSpec outgoingFileTransfer(const QVariantMap &additionalProperties = QVariantMap());
    00225     static ChannelClassSpec incomingFileTransfer(const QVariantMap &additionalProperties = QVariantMap());
    00226     static ChannelClassSpec outgoingStreamTube(const QString &service = QString(),
    00227             const QVariantMap &additionalProperties = QVariantMap());
    00228     static ChannelClassSpec incomingStreamTube(const QString &service = QString(),
    00229             const QVariantMap &additionalProperties = QVariantMap());
    00230     static ChannelClassSpec outgoingRoomStreamTube(const QString &service = QString(),
    00231             const QVariantMap &additionalProperties = QVariantMap());
    00232     static ChannelClassSpec incomingRoomStreamTube(const QString &service = QString(),
    00233             const QVariantMap &additionalProperties = QVariantMap());
    00234     // TODO: add dbus tubes when they're implemented
    00235     static ChannelClassSpec contactSearch(const QVariantMap &additionalProperties = QVariantMap());
    00236
    00237 private:
    00238     struct Private;
    00239     friend struct Private;
    00240     QSharedDataPointer<Private> mPriv;
    00241 };
    00242
    00243 class TP_QT_EXPORT ChannelClassSpecList :
    00244                 public QList<ChannelClassSpec>
    00245 {
    00246 public:
    00247     ChannelClassSpecList() { }
    00248
    00249     ChannelClassSpecList(const ChannelClassSpec &spec)
    00250     {
    00251         append(spec);
    00252     }
    00253
    00254     ChannelClassSpecList(const QList<ChannelClassSpec> &other)
    00255         : QList<ChannelClassSpec>(other)
    00256     {
    00257     }
    00258
    00259     ChannelClassSpecList(const ChannelClassList &classes)
    00260     {
    00261         // Why doesn't Qt have range constructors like STL... stupid, so stupid.
    00262         Q_FOREACH (const ChannelClass &cc, classes) {
    00263             append(cc);
    00264         }
    00265     }
    00266
    00267     ChannelClassList bareClasses() const
    00268     {
    00269         ChannelClassList list;
    00270         Q_FOREACH (const ChannelClassSpec &spec, *this) {
    00271             list.append(spec.bareClass());
    00272         }
    00273         return list;
    00274     }
    00275 };
    00276
    00277 inline uint qHash(const ChannelClassSpec &spec)
    00278 {
    00279     uint ret = 0;
    00280     QVariantMap::const_iterator it = spec.allProperties().constBegin();
    00281     QVariantMap::const_iterator end = spec.allProperties().constEnd();
    00282     int i = spec.allProperties().size() + 1;
    00283     for (; it != end; ++it) {
    00284         // all D-Bus types should be convertible to QString
    00285         QPair<QString, QString> p(it.key(), it.value().toString());
    00286         int h = qHash(p);
    00287         ret ^= ((h << (2 << i)) | (h >> (2 >> i)));
    00288         i--;
    00289     }
    00290     return ret;
    00291 }
    00292
    00293 inline uint qHash(const QSet<ChannelClassSpec> &specSet)
    00294 {
    00295     int ret = 0;
    00296     Q_FOREACH (const ChannelClassSpec &spec, specSet) {
    00297         int h = qHash(spec);
    00298         ret ^= h;
    00299     }
    00300     return ret;
    00301 }
    00302
    00303 inline uint qHash(const ChannelClassSpecList &specList)
    00304 {
    00305     // Make it unique by converting to QSet
    00306     QSet<ChannelClassSpec> uniqueSet = specList.toSet();
    00307     return qHash(uniqueSet);
    00308 }
    00309
    00310 } // Tp
    00311
    00312 Q_DECLARE_METATYPE(Tp::ChannelClassSpec);
    00313 Q_DECLARE_METATYPE(Tp::ChannelClassSpecList);
    00314
    00315 #endif