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     TP_QT_DEPRECATED bool hasStreamedMediaInitialAudioFlag() const
00150     {
00151         return qdbus_cast<bool>(
00152                 property(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialAudio")));
00153     }
00154 
00155     TP_QT_DEPRECATED void setStreamedMediaInitialAudioFlag()
00156     {
00157         setProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialAudio"),
00158                 QVariant::fromValue(true));
00159     }
00160 
00161     TP_QT_DEPRECATED void unsetStreamedMediaInitialAudioFlag()
00162     {
00163         unsetProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialAudio"));
00164     }
00165 
00166     TP_QT_DEPRECATED bool hasStreamedMediaInitialVideoFlag() const
00167     {
00168         return qdbus_cast<bool>(
00169                 property(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialVideo")));
00170     }
00171 
00172     TP_QT_DEPRECATED void setStreamedMediaInitialVideoFlag()
00173     {
00174         setProperty(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA + QLatin1String(".InitialVideo"),
00175                 QVariant::fromValue(true));
00176     }
00177 
00178     TP_QT_DEPRECATED 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 mediaCall(const QVariantMap &additionalProperties = QVariantMap());
00197     static ChannelClassSpec audioCall(const QVariantMap &additionalProperties = QVariantMap());
00198     static ChannelClassSpec videoCall(const QVariantMap &additionalProperties = QVariantMap());
00199     static ChannelClassSpec videoCallWithAudio(const QVariantMap &additionalProperties =
00200             QVariantMap());
00201 
00202     TP_QT_DEPRECATED static ChannelClassSpec streamedMediaCall(const QVariantMap &additionalProperties = QVariantMap());
00203     TP_QT_DEPRECATED static ChannelClassSpec streamedMediaAudioCall(const QVariantMap &additionalProperties =
00204             QVariantMap());
00205     TP_QT_DEPRECATED static ChannelClassSpec streamedMediaVideoCall(const QVariantMap &additionalProperties =
00206             QVariantMap());
00207     TP_QT_DEPRECATED static ChannelClassSpec streamedMediaVideoCallWithAudio(const QVariantMap &additionalProperties =
00208             QVariantMap());
00209 
00210     TP_QT_DEPRECATED static ChannelClassSpec unnamedStreamedMediaCall(const QVariantMap &additionalProperties =
00211             QVariantMap());
00212     TP_QT_DEPRECATED static ChannelClassSpec unnamedStreamedMediaAudioCall(const QVariantMap &additionalProperties =
00213             QVariantMap());
00214     TP_QT_DEPRECATED static ChannelClassSpec unnamedStreamedMediaVideoCall(const QVariantMap &additionalProperties =
00215             QVariantMap());
00216     TP_QT_DEPRECATED static ChannelClassSpec unnamedStreamedMediaVideoCallWithAudio(const QVariantMap &additionalProperties =
00217             QVariantMap());
00218 
00219     static ChannelClassSpec serverAuthentication(const QVariantMap &additionalProperties =
00220             QVariantMap());
00221 
00222     static ChannelClassSpec roomList(const QVariantMap &additionalProperties = QVariantMap());
00223     static ChannelClassSpec outgoingFileTransfer(const QVariantMap &additionalProperties = QVariantMap());
00224     static ChannelClassSpec incomingFileTransfer(const QVariantMap &additionalProperties = QVariantMap());
00225     static ChannelClassSpec outgoingStreamTube(const QString &service = QString(),
00226             const QVariantMap &additionalProperties = QVariantMap());
00227     static ChannelClassSpec incomingStreamTube(const QString &service = QString(),
00228             const QVariantMap &additionalProperties = QVariantMap());
00229     static ChannelClassSpec outgoingRoomStreamTube(const QString &service = QString(),
00230             const QVariantMap &additionalProperties = QVariantMap());
00231     static ChannelClassSpec incomingRoomStreamTube(const QString &service = QString(),
00232             const QVariantMap &additionalProperties = QVariantMap());
00233     static ChannelClassSpec outgoingDBusTube(const QString &serviceName = QString(),
00234             const QVariantMap &additionalProperties = QVariantMap());
00235     static ChannelClassSpec incomingDBusTube(const QString &serviceName = QString(),
00236             const QVariantMap &additionalProperties = QVariantMap());
00237     static ChannelClassSpec outgoingRoomDBusTube(const QString &serviceName = QString(),
00238             const QVariantMap &additionalProperties = QVariantMap());
00239     static ChannelClassSpec incomingRoomDBusTube(const QString &serviceName = QString(),
00240             const QVariantMap &additionalProperties = QVariantMap());
00241     static ChannelClassSpec contactSearch(const QVariantMap &additionalProperties = QVariantMap());
00242 
00243 private:
00244     struct Private;
00245     friend struct Private;
00246     QSharedDataPointer<Private> mPriv;
00247 };
00248 
00249 class TP_QT_EXPORT ChannelClassSpecList :
00250                 public QList<ChannelClassSpec>
00251 {
00252 public:
00253     ChannelClassSpecList() { }
00254 
00255     ChannelClassSpecList(const ChannelClassSpec &spec)
00256     {
00257         append(spec);
00258     }
00259 
00260     ChannelClassSpecList(const QList<ChannelClassSpec> &other)
00261         : QList<ChannelClassSpec>(other)
00262     {
00263     }
00264 
00265     ChannelClassSpecList(const ChannelClassList &classes)
00266     {
00267         // Why doesn't Qt have range constructors like STL... stupid, so stupid.
00268         Q_FOREACH (const ChannelClass &cc, classes) {
00269             append(cc);
00270         }
00271     }
00272 
00273     ChannelClassList bareClasses() const
00274     {
00275         ChannelClassList list;
00276         Q_FOREACH (const ChannelClassSpec &spec, *this) {
00277             list.append(spec.bareClass());
00278         }
00279         return list;
00280     }
00281 };
00282 
00283 inline uint qHash(const ChannelClassSpec &spec)
00284 {
00285     uint ret = 0;
00286     QVariantMap::const_iterator it = spec.allProperties().constBegin();
00287     QVariantMap::const_iterator end = spec.allProperties().constEnd();
00288     int i = spec.allProperties().size() + 1;
00289     for (; it != end; ++it) {
00290         // all D-Bus types should be convertible to QString
00291         QPair<QString, QString> p(it.key(), it.value().toString());
00292         int h = qHash(p);
00293         ret ^= ((h << (2 << i)) | (h >> (2 >> i)));
00294         i--;
00295     }
00296     return ret;
00297 }
00298 
00299 inline uint qHash(const QSet<ChannelClassSpec> &specSet)
00300 {
00301     int ret = 0;
00302     Q_FOREACH (const ChannelClassSpec &spec, specSet) {
00303         int h = qHash(spec);
00304         ret ^= h;
00305     }
00306     return ret;
00307 }
00308 
00309 inline uint qHash(const ChannelClassSpecList &specList)
00310 {
00311     // Make it unique by converting to QSet
00312     QSet<ChannelClassSpec> uniqueSet = specList.toSet();
00313     return qHash(uniqueSet);
00314 }
00315 
00316 } // Tp
00317 
00318 Q_DECLARE_METATYPE(Tp::ChannelClassSpec);
00319 Q_DECLARE_METATYPE(Tp::ChannelClassSpecList);
00320 
00321 #endif


Copyright © 2008-2011 Collabora Ltd. and Nokia Corporation
Telepathy-Qt 0.9.3