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

channel-class-spec.h

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