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->isSubsetOf(other) && this->allProperties().size() ==
00063 other.allProperties().size();
00064 }
00065
00066 bool isSubsetOf(const ChannelClassSpec &other) const;
00067 bool matches(const QVariantMap &immutableProperties) const;
00068
00069
00070 QString channelType() const
00071 {
00072 return qdbus_cast<QString>(
00073 property(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
00074 }
00075
00076 void setChannelType(const QString &type)
00077 {
00078 setProperty(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
00079 QVariant::fromValue(type));
00080 }
00081
00082 HandleType targetHandleType() const
00083 {
00084 return (HandleType) qdbus_cast<uint>(
00085 property(
00086 QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType")));
00087 }
00088
00089 void setTargetHandleType(HandleType type)
00090 {
00091 setProperty(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
00092 QVariant::fromValue((uint) type));
00093 }
00094
00095 bool hasRequested() const
00096 {
00097 return hasProperty(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".Requested"));
00098 }
00099
00100 bool isRequested() const
00101 {
00102 return qdbus_cast<bool>(
00103 property(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".Requested")));
00104 }
00105
00106 void setRequested(bool requested)
00107 {
00108 setProperty(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".Requested"),
00109 QVariant::fromValue(requested));
00110 }
00111
00112 void unsetRequested()
00113 {
00114 unsetProperty(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".Requested"));
00115 }
00116
00117 bool hasStreamedMediaInitialAudioFlag() const
00118 {
00119 return qdbus_cast<bool>(
00120 property(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA
00121 ".InitialAudio")));
00122 }
00123
00124 void setStreamedMediaInitialAudioFlag()
00125 {
00126 setProperty(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialAudio"),
00127 QVariant::fromValue(true));
00128 }
00129
00130 void unsetStreamedMediaInitialAudioFlag()
00131 {
00132 unsetProperty(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA
00133 ".InitialAudio"));
00134 }
00135
00136 bool hasStreamedMediaInitialVideoFlag() const
00137 {
00138 return qdbus_cast<bool>(
00139 property(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA
00140 ".InitialVideo")));
00141 }
00142
00143 void setStreamedMediaInitialVideoFlag()
00144 {
00145 setProperty(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialVideo"),
00146 QVariant::fromValue(true));
00147 }
00148
00149 void unsetStreamedMediaInitialVideoFlag()
00150 {
00151 unsetProperty(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA
00152 ".InitialVideo"));
00153 }
00154
00155 bool hasProperty(const QString &qualifiedName) const;
00156 QVariant property(const QString &qualifiedName) const;
00157
00158 void setProperty(const QString &qualifiedName, const QVariant &value);
00159 void unsetProperty(const QString &qualifiedName);
00160
00161 QVariantMap allProperties() const;
00162 ChannelClass bareClass() const;
00163
00164 static ChannelClassSpec textChat(const QVariantMap &additionalProperties = QVariantMap());
00165 static ChannelClassSpec textChatroom(const QVariantMap &additionalProperties = QVariantMap());
00166 static ChannelClassSpec unnamedTextChat(const QVariantMap &additionalProperties = QVariantMap());
00167
00168 static ChannelClassSpec streamedMediaCall(const QVariantMap &additionalProperties = QVariantMap());
00169 static ChannelClassSpec streamedMediaAudioCall(const QVariantMap &additionalProperties =
00170 QVariantMap());
00171 static ChannelClassSpec streamedMediaVideoCall(const QVariantMap &additionalProperties =
00172 QVariantMap());
00173 static ChannelClassSpec streamedMediaVideoCallWithAudio(const QVariantMap &additionalProperties =
00174 QVariantMap());
00175
00176 static ChannelClassSpec unnamedStreamedMediaCall(const QVariantMap &additionalProperties =
00177 QVariantMap());
00178 static ChannelClassSpec unnamedStreamedMediaAudioCall(const QVariantMap &additionalProperties =
00179 QVariantMap());
00180 static ChannelClassSpec unnamedStreamedMediaVideoCall(const QVariantMap &additionalProperties =
00181 QVariantMap());
00182 static ChannelClassSpec unnamedStreamedMediaVideoCallWithAudio(const QVariantMap &additionalProperties =
00183 QVariantMap());
00184
00185
00186 static ChannelClassSpec roomList(const QVariantMap &additionalProperties = QVariantMap());
00187 static ChannelClassSpec outgoingFileTransfer(const QVariantMap &additionalProperties = QVariantMap());
00188 static ChannelClassSpec incomingFileTransfer(const QVariantMap &additionalProperties = QVariantMap());
00189 static ChannelClassSpec outgoingStreamTube(const QString &service = QString(),
00190 const QVariantMap &additionalProperties = QVariantMap());
00191 static ChannelClassSpec incomingStreamTube(const QString &service = QString(),
00192 const QVariantMap &additionalProperties = QVariantMap());
00193
00194 static ChannelClassSpec contactSearch(const QVariantMap &additionalProperties = QVariantMap());
00195
00196 private:
00197 struct Private;
00198 friend struct Private;
00199 QSharedDataPointer<Private> mPriv;
00200 };
00201
00202 class TELEPATHY_QT4_EXPORT ChannelClassSpecList :
00203 public QList<ChannelClassSpec>
00204 {
00205 public:
00206 ChannelClassSpecList() { }
00207
00208 ChannelClassSpecList(const ChannelClassSpec &spec)
00209 {
00210 append(spec);
00211 }
00212
00213 ChannelClassSpecList(const QList<ChannelClassSpec> &other)
00214 : QList<ChannelClassSpec>(other)
00215 {
00216 }
00217
00218 ChannelClassSpecList(const ChannelClassList &classes)
00219 {
00220
00221 Q_FOREACH (const ChannelClass &cc, classes) {
00222 append(cc);
00223 }
00224 }
00225
00226 ChannelClassList bareClasses() const
00227 {
00228 ChannelClassList list;
00229 Q_FOREACH (const ChannelClassSpec &spec, *this) {
00230 list.append(spec.bareClass());
00231 }
00232 return list;
00233 }
00234 };
00235
00236 inline uint qHash(const ChannelClassSpec &spec)
00237 {
00238 uint ret = 0;
00239 QVariantMap::const_iterator it = spec.allProperties().constBegin();
00240 QVariantMap::const_iterator end = spec.allProperties().constEnd();
00241 int i = spec.allProperties().size() + 1;
00242 for (; it != end; ++it) {
00243
00244 QPair<QString, QString> p(it.key(), it.value().toString());
00245 int h = qHash(p);
00246 ret ^= ((h << (2 << i)) | (h >> (2 >> i)));
00247 i--;
00248 }
00249 return ret;
00250 }
00251
00252 inline uint qHash(const QSet<ChannelClassSpec> &specSet)
00253 {
00254 int ret = 0;
00255 Q_FOREACH (const ChannelClassSpec &spec, specSet) {
00256 int h = qHash(spec);
00257 ret ^= h;
00258 }
00259 return ret;
00260 }
00261
00262 inline uint qHash(const ChannelClassSpecList &specList)
00263 {
00264
00265 QSet<ChannelClassSpec> uniqueSet = specList.toSet();
00266 return qHash(uniqueSet);
00267 }
00268
00269 }
00270
00271 Q_DECLARE_METATYPE(Tp::ChannelClassSpec);
00272 Q_DECLARE_METATYPE(Tp::ChannelClassSpecList);
00273
00274 #endif