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_cli_channel_h_HEADER_GUARD_
00023 #define _TelepathyQt4_cli_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 <QVariantMap>
00043 
00044 namespace Tp
00045 {
00046 
00047 class Connection;
00048 class PendingOperation;
00049 class PendingReady;
00050 
00051 class Channel : public StatefulDBusProxy,
00052                 private OptionalInterfaceFactory<Channel>,
00053                 public ReadyObject,
00054                 public RefCounted
00055 {
00056     Q_OBJECT
00057     Q_DISABLE_COPY(Channel)
00058 
00059 public:
00060     static const Feature FeatureCore;
00061 
00062     static ChannelPtr create(const ConnectionPtr &connection,
00063             const QString &objectPath, const QVariantMap &immutableProperties);
00064 
00065     ~Channel();
00066 
00067     ConnectionPtr connection() const;
00068 
00069     QVariantMap immutableProperties() const;
00070 
00071     QString channelType() const;
00072     QStringList interfaces() 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             : mIsValid(false) {}
00108 
00109         bool isValid() const { return mIsValid; }
00110 
00111         bool hasActor() const { return !mActor.isNull(); }
00112         ContactPtr actor() const { return mActor; }
00113 
00114         bool hasReason() const { return mDetails.contains("change-reason"); }
00115         uint reason() const { return qdbus_cast<uint>(mDetails.value("change-reason")); }
00116 
00117         bool hasMessage() const { return mDetails.contains("message"); }
00118         QString message () const { return qdbus_cast<QString>(mDetails.value("message")); }
00119 
00120         bool hasError() const { return mDetails.contains("error"); }
00121         QString error() const { return qdbus_cast<QString>(mDetails.value("error")); }
00122 
00123         bool hasDebugMessage() const { return mDetails.contains("debug-message"); }
00124         QString debugMessage() const { return qdbus_cast<QString>(mDetails.value("debug-message")); }
00125 
00126         QVariantMap allDetails() const { return mDetails; }
00127 
00128     private:
00129         friend class Channel;
00130 
00131         GroupMemberChangeDetails(const ContactPtr &actor, const QVariantMap &details)
00132             : mActor(actor), mDetails(details), mIsValid(true) {}
00133 
00134         ContactPtr mActor;
00135         QVariantMap mDetails;
00136         bool mIsValid;
00137     };
00138 
00139     GroupMemberChangeDetails groupLocalPendingContactChangeInfo(const ContactPtr &contact) const;
00140     GroupMemberChangeDetails groupSelfContactRemoveInfo() const;
00141 
00142     bool groupAreHandleOwnersAvailable() const;
00143     HandleOwnerMap groupHandleOwners() const;
00144 
00145     bool groupIsSelfContactTracked() const;
00146     ContactPtr groupSelfContact() const;
00147 
00148 Q_SIGNALS:
00149     void groupFlagsChanged(uint flags, uint added, uint removed);
00150 
00151     void groupCanAddContactsChanged(bool canAddContacts);
00152     void groupCanRemoveContactsChanged(bool canRemoveContacts);
00153     void groupCanRescindContactsChanged(bool canRescindContacts);
00154 
00155     void groupMembersChanged(
00156             const Tp::Contacts &groupMembersAdded,
00157             const Tp::Contacts &groupLocalPendingMembersAdded,
00158             const Tp::Contacts &groupRemotePendingMembersAdded,
00159             const Tp::Contacts &groupMembersRemoved,
00160             const Tp::Channel::GroupMemberChangeDetails &details);
00161 
00162     void groupHandleOwnersChanged(const Tp::HandleOwnerMap &owners,
00163             const Tp::UIntList &added, const Tp::UIntList &removed);
00164 
00165     void groupSelfContactChanged();
00166 
00167 protected:
00168     bool groupSelfHandleIsLocalPending() const;
00169 
00170 protected Q_SLOTS:
00171     PendingOperation *groupAddSelfHandle();
00172 
00173 public:
00174     template <class Interface>
00175     inline Interface *optionalInterface(
00176             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00177     {
00178         // Check for the remote object supporting the interface
00179         QString name(Interface::staticInterfaceName());
00180         if (check == CheckInterfaceSupported && !interfaces().contains(name))
00181             return 0;
00182 
00183         // If present or forced, delegate to OptionalInterfaceFactory
00184         return OptionalInterfaceFactory<Channel>::interface<Interface>();
00185     }
00186 
00187     inline Client::ChannelInterfaceCallStateInterface *callStateInterface(
00188             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00189     {
00190         return optionalInterface<Client::ChannelInterfaceCallStateInterface>(check);
00191     }
00192 
00193     inline Client::ChannelInterfaceChatStateInterface *chatStateInterface(
00194             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00195     {
00196         return optionalInterface<Client::ChannelInterfaceChatStateInterface>(check);
00197     }
00198 
00199     inline Client::ChannelInterfaceDTMFInterface *DTMFInterface(
00200             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00201     {
00202         return optionalInterface<Client::ChannelInterfaceDTMFInterface>(check);
00203     }
00204 
00205     inline Client::ChannelInterfaceHoldInterface *holdInterface(
00206             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00207     {
00208         return optionalInterface<Client::ChannelInterfaceHoldInterface>(check);
00209     }
00210 
00211     inline Client::ChannelInterfaceMediaSignallingInterface *mediaSignallingInterface(
00212             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00213     {
00214         return optionalInterface<Client::ChannelInterfaceMediaSignallingInterface>(check);
00215     }
00216 
00217     inline Client::ChannelInterfaceMessagesInterface *messagesInterface(
00218             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00219     {
00220         return optionalInterface<Client::ChannelInterfaceMessagesInterface>(check);
00221     }
00222 
00223     inline Client::ChannelInterfacePasswordInterface *passwordInterface(
00224             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00225     {
00226         return optionalInterface<Client::ChannelInterfacePasswordInterface>(check);
00227     }
00228 
00229     inline Client::DBus::PropertiesInterface *propertiesInterface() const
00230     {
00231         return optionalInterface<Client::DBus::PropertiesInterface>(BypassInterfaceCheck);
00232     }
00233 
00234     template <class Interface>
00235     inline Interface *typeInterface(
00236             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00237     {
00238         // Check for the remote object having the correct channel type
00239         QString name(Interface::staticInterfaceName());
00240         if (check == CheckInterfaceSupported && channelType() != name)
00241             return 0;
00242 
00243         // If correct type or check bypassed, delegate to OIF
00244         return OptionalInterfaceFactory<Channel>::interface<Interface>();
00245     }
00246 
00247     inline Client::ChannelTypeRoomListInterface *roomListInterface(
00248             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00249     {
00250         return typeInterface<Client::ChannelTypeRoomListInterface>(check);
00251     }
00252 
00253     inline Client::ChannelTypeStreamedMediaInterface *streamedMediaInterface(
00254             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00255     {
00256         return typeInterface<Client::ChannelTypeStreamedMediaInterface>(check);
00257     }
00258 
00259     inline Client::ChannelTypeTextInterface *textInterface(
00260             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00261     {
00262         return typeInterface<Client::ChannelTypeTextInterface>(check);
00263     }
00264 
00265     inline Client::ChannelTypeTubesInterface *tubesInterface(
00266             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00267     {
00268         return typeInterface<Client::ChannelTypeTubesInterface>(check);
00269     }
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 private Q_SLOTS:
00284     void gotMainProperties(QDBusPendingCallWatcher *watcher);
00285     void gotChannelType(QDBusPendingCallWatcher *watcher);
00286     void gotHandle(QDBusPendingCallWatcher *watcher);
00287     void gotInterfaces(QDBusPendingCallWatcher *watcher);
00288     void onClosed();
00289 
00290     void onConnectionReady(Tp::PendingOperation *op);
00291     void onConnectionInvalidated();
00292     void onConnectionDestroyed();
00293 
00294     void gotGroupProperties(QDBusPendingCallWatcher *watcher);
00295     void gotGroupFlags(QDBusPendingCallWatcher *watcher);
00296     void gotAllMembers(QDBusPendingCallWatcher *watcher);
00297     void gotLocalPendingMembersWithInfo(QDBusPendingCallWatcher *watcher);
00298     void gotSelfHandle(QDBusPendingCallWatcher *watcher);
00299     void gotContacts(Tp::PendingOperation *op);
00300 
00301     void onGroupFlagsChanged(uint, uint);
00302     void onMembersChanged(const QString&,
00303             const Tp::UIntList&, const Tp::UIntList&,
00304             const Tp::UIntList&, const Tp::UIntList&, uint, uint);
00305     void onMembersChangedDetailed(
00306         const Tp::UIntList &added, const Tp::UIntList &removed,
00307         const Tp::UIntList &localPending, const Tp::UIntList &remotePending,
00308         const QVariantMap &details);
00309     void onHandleOwnersChanged(const Tp::HandleOwnerMap&, const Tp::UIntList&);
00310     void onSelfHandleChanged(uint);
00311 
00312     void continueIntrospection();
00313 
00314 private:
00315     struct Private;
00316     friend struct Private;
00317     Private *mPriv;
00318 };
00319 
00320 } // Tp
00321 
00322 Q_DECLARE_METATYPE(Tp::Channel::GroupMemberChangeDetails);
00323 
00324 #endif


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