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

channel.h

00001 /*
00002  * This file is part of TelepathyQt4
00003  *
00004  * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
00005  * Copyright (C) 2008 Nokia Corporation
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _TelepathyQt4_channel_h_HEADER_GUARD_
00023 #define _TelepathyQt4_channel_h_HEADER_GUARD_
00024 
00025 #ifndef IN_TELEPATHY_QT4_HEADER
00026 #error IN_TELEPATHY_QT4_HEADER
00027 #endif
00028 
00029 #include <TelepathyQt4/_gen/cli-channel.h>
00030 
00031 #include <TelepathyQt4/Constants>
00032 #include <TelepathyQt4/Contact>
00033 #include <TelepathyQt4/DBus>
00034 #include <TelepathyQt4/DBusProxy>
00035 #include <TelepathyQt4/OptionalInterfaceFactory>
00036 #include <TelepathyQt4/ReadinessHelper>
00037 #include <TelepathyQt4/ReadyObject>
00038 #include <TelepathyQt4/Types>
00039 #include <TelepathyQt4/SharedPtr>
00040 
00041 #include <QSet>
00042 #include <QSharedDataPointer>
00043 #include <QVariantMap>
00044 
00045 namespace Tp
00046 {
00047 
00048 class Connection;
00049 class PendingOperation;
00050 class PendingReady;
00051 
00052 class TELEPATHY_QT4_EXPORT Channel : public StatefulDBusProxy,
00053                 public OptionalInterfaceFactory<Channel>,
00054                 public ReadyObject,
00055                 public RefCounted
00056 {
00057     Q_OBJECT
00058     Q_DISABLE_COPY(Channel)
00059 
00060 public:
00061     static const Feature FeatureCore;
00062 
00063     static ChannelPtr create(const ConnectionPtr &connection,
00064             const QString &objectPath, const QVariantMap &immutableProperties);
00065 
00066     virtual ~Channel();
00067 
00068     ConnectionPtr connection() const;
00069 
00070     QVariantMap immutableProperties() const;
00071 
00072     QString channelType() const;
00073 
00074     uint targetHandleType() const;
00075     uint targetHandle() const;
00076 
00077     bool isRequested() const;
00078     ContactPtr initiatorContact() const;
00079 
00080     PendingOperation *requestClose();
00081 
00082     uint groupFlags() const;
00083 
00084     bool groupCanAddContacts() const;
00085     bool groupCanAddContactsWithMessage() const;
00086     bool groupCanAcceptContactsWithMessage() const;
00087     PendingOperation *groupAddContacts(const QList<ContactPtr> &contacts,
00088             const QString &message = QString());
00089     bool groupCanRescindContacts() const;
00090     bool groupCanRescindContactsWithMessage() const;
00091     bool groupCanRemoveContacts() const;
00092     bool groupCanRemoveContactsWithMessage() const;
00093     bool groupCanRejectContactsWithMessage() const;
00094     bool groupCanDepartWithMessage() const;
00095     PendingOperation *groupRemoveContacts(const QList<ContactPtr> &contacts,
00096             const QString &message = QString(),
00097             uint reason = ChannelGroupChangeReasonNone);
00098 
00099     Contacts groupContacts() const;
00100     Contacts groupLocalPendingContacts() const;
00101     Contacts groupRemotePendingContacts() const;
00102 
00103     class GroupMemberChangeDetails
00104     {
00105     public:
00106         GroupMemberChangeDetails();
00107         GroupMemberChangeDetails(const GroupMemberChangeDetails &other);
00108         ~GroupMemberChangeDetails();
00109 
00110         GroupMemberChangeDetails &operator=(const GroupMemberChangeDetails &other);
00111 
00112         bool isValid() const { return mPriv.constData() != 0; }
00113 
00114         bool hasActor() const;
00115         ContactPtr actor() const;
00116 
00117         bool hasReason() const { return allDetails().contains("change-reason"); }
00118         uint reason() const { return qdbus_cast<uint>(allDetails().value("change-reason")); }
00119 
00120         bool hasMessage() const { return allDetails().contains("message"); }
00121         QString message () const { return qdbus_cast<QString>(allDetails().value("message")); }
00122 
00123         bool hasError() const { return allDetails().contains("error"); }
00124         QString error() const { return qdbus_cast<QString>(allDetails().value("error")); }
00125 
00126         bool hasDebugMessage() const { return allDetails().contains("debug-message"); }
00127         QString debugMessage() const { return qdbus_cast<QString>(allDetails().value("debug-message")); }
00128 
00129         QVariantMap allDetails() const;
00130 
00131     private:
00132         friend class Channel;
00133 
00134         GroupMemberChangeDetails(const ContactPtr &actor, const QVariantMap &details);
00135 
00136         struct Private;
00137         friend struct Private;
00138         QSharedDataPointer<Private> mPriv;
00139     };
00140 
00141     GroupMemberChangeDetails groupLocalPendingContactChangeInfo(const ContactPtr &contact) const;
00142     GroupMemberChangeDetails groupSelfContactRemoveInfo() const;
00143 
00144     bool groupAreHandleOwnersAvailable() const;
00145     HandleOwnerMap groupHandleOwners() const;
00146 
00147     bool groupIsSelfContactTracked() const;
00148     ContactPtr groupSelfContact() const;
00149 
00150     inline Client::DBus::PropertiesInterface *propertiesInterface() const
00151     {
00152         return optionalInterface<Client::DBus::PropertiesInterface>(BypassInterfaceCheck);
00153     }
00154 
00155     inline Client::ChannelInterfaceCallStateInterface *callStateInterface(
00156             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00157     {
00158         return optionalInterface<Client::ChannelInterfaceCallStateInterface>(check);
00159     }
00160 
00161     inline Client::ChannelInterfaceChatStateInterface *chatStateInterface(
00162             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00163     {
00164         return optionalInterface<Client::ChannelInterfaceChatStateInterface>(check);
00165     }
00166 
00167     inline Client::ChannelInterfaceDTMFInterface *DTMFInterface(
00168             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00169     {
00170         return optionalInterface<Client::ChannelInterfaceDTMFInterface>(check);
00171     }
00172 
00173     inline Client::ChannelInterfaceHoldInterface *holdInterface(
00174             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00175     {
00176         return optionalInterface<Client::ChannelInterfaceHoldInterface>(check);
00177     }
00178 
00179     inline Client::ChannelInterfaceMediaSignallingInterface *mediaSignallingInterface(
00180             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00181     {
00182         return optionalInterface<Client::ChannelInterfaceMediaSignallingInterface>(check);
00183     }
00184 
00185     inline Client::ChannelInterfaceMessagesInterface *messagesInterface(
00186             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00187     {
00188         return optionalInterface<Client::ChannelInterfaceMessagesInterface>(check);
00189     }
00190 
00191     inline Client::ChannelInterfacePasswordInterface *passwordInterface(
00192             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00193     {
00194         return optionalInterface<Client::ChannelInterfacePasswordInterface>(check);
00195     }
00196 
00197     inline Client::ChannelInterfaceTubeInterface *tubeInterface(
00198             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00199     {
00200         return optionalInterface<Client::ChannelInterfaceTubeInterface>(check);
00201     }
00202 
00203     template <class Interface>
00204     inline Interface *typeInterface(
00205             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00206     {
00207         // Check for the remote object having the correct channel type
00208         QString name(Interface::staticInterfaceName());
00209         if (check == CheckInterfaceSupported && channelType() != name)
00210             return 0;
00211 
00212         // If correct type or check bypassed, delegate to OIF
00213         return OptionalInterfaceFactory<Channel>::interface<Interface>();
00214     }
00215 
00216     inline Client::ChannelTypeRoomListInterface *roomListInterface(
00217             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00218     {
00219         return typeInterface<Client::ChannelTypeRoomListInterface>(check);
00220     }
00221 
00222     inline Client::ChannelTypeStreamedMediaInterface *streamedMediaInterface(
00223             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00224     {
00225         return typeInterface<Client::ChannelTypeStreamedMediaInterface>(check);
00226     }
00227 
00228     inline Client::ChannelTypeTextInterface *textInterface(
00229             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00230     {
00231         return typeInterface<Client::ChannelTypeTextInterface>(check);
00232     }
00233 
00234     inline Client::ChannelTypeFileTransferInterface *fileTransferInterface(
00235             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00236     {
00237         return typeInterface<Client::ChannelTypeFileTransferInterface>(check);
00238     }
00239 
00240     inline Client::ChannelTypeTubesInterface *tubesInterface(
00241             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00242     {
00243         return typeInterface<Client::ChannelTypeTubesInterface>(check);
00244     }
00245 
00246     inline Client::ChannelTypeStreamTubeInterface *streamTubeInterface(
00247             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00248     {
00249         return typeInterface<Client::ChannelTypeStreamTubeInterface>(check);
00250     }
00251 
00252 Q_SIGNALS:
00253     void groupFlagsChanged(uint flags, uint added, uint removed);
00254 
00255     void groupCanAddContactsChanged(bool canAddContacts);
00256     void groupCanRemoveContactsChanged(bool canRemoveContacts);
00257     void groupCanRescindContactsChanged(bool canRescindContacts);
00258 
00259     void groupMembersChanged(
00260             const Tp::Contacts &groupMembersAdded,
00261             const Tp::Contacts &groupLocalPendingMembersAdded,
00262             const Tp::Contacts &groupRemotePendingMembersAdded,
00263             const Tp::Contacts &groupMembersRemoved,
00264             const Tp::Channel::GroupMemberChangeDetails &details);
00265 
00266     void groupHandleOwnersChanged(const Tp::HandleOwnerMap &owners,
00267             const Tp::UIntList &added, const Tp::UIntList &removed);
00268 
00269     void groupSelfContactChanged();
00270 
00271 protected:
00272     Channel(const ConnectionPtr &connection,const QString &objectPath,
00273             const QVariantMap &immutableProperties);
00274 
00275     Client::ChannelInterface *baseInterface() const;
00276 
00277     inline Client::ChannelInterfaceGroupInterface *groupInterface(
00278             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00279     {
00280         return optionalInterface<Client::ChannelInterfaceGroupInterface>(check);
00281     }
00282 
00283     bool groupSelfHandleIsLocalPending() const;
00284 
00285 protected Q_SLOTS:
00286     PendingOperation *groupAddSelfHandle();
00287 
00288 private Q_SLOTS:
00289     void gotMainProperties(QDBusPendingCallWatcher *watcher);
00290     void gotChannelType(QDBusPendingCallWatcher *watcher);
00291     void gotHandle(QDBusPendingCallWatcher *watcher);
00292     void gotInterfaces(QDBusPendingCallWatcher *watcher);
00293     void onClosed();
00294 
00295     void onConnectionReady(Tp::PendingOperation *op);
00296     void onConnectionInvalidated();
00297     void onConnectionDestroyed();
00298 
00299     void gotGroupProperties(QDBusPendingCallWatcher *watcher);
00300     void gotGroupFlags(QDBusPendingCallWatcher *watcher);
00301     void gotAllMembers(QDBusPendingCallWatcher *watcher);
00302     void gotLocalPendingMembersWithInfo(QDBusPendingCallWatcher *watcher);
00303     void gotSelfHandle(QDBusPendingCallWatcher *watcher);
00304     void gotContacts(Tp::PendingOperation *op);
00305 
00306     void onGroupFlagsChanged(uint, uint);
00307     void onMembersChanged(const QString&,
00308             const Tp::UIntList&, const Tp::UIntList&,
00309             const Tp::UIntList&, const Tp::UIntList&, uint, uint);
00310     void onMembersChangedDetailed(
00311         const Tp::UIntList &added, const Tp::UIntList &removed,
00312         const Tp::UIntList &localPending, const Tp::UIntList &remotePending,
00313         const QVariantMap &details);
00314     void onHandleOwnersChanged(const Tp::HandleOwnerMap&, const Tp::UIntList&);
00315     void onSelfHandleChanged(uint);
00316 
00317     void continueIntrospection();
00318 
00319 private:
00320     struct Private;
00321     friend struct Private;
00322     Private *mPriv;
00323 };
00324 
00325 } // Tp
00326 
00327 Q_DECLARE_METATYPE(Tp::Channel::GroupMemberChangeDetails);
00328 
00329 #endif


Copyright © 2009 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.2.1