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     QString channelType() const;
00070     QStringList interfaces() const;
00071 
00072     uint targetHandleType() const;
00073     uint targetHandle() const;
00074 
00075     bool isRequested() const;
00076     ContactPtr initiatorContact() const;
00077 
00078     PendingOperation *requestClose();
00079 
00080     uint groupFlags() const;
00081 
00082     bool groupCanAddContacts() const;
00083     bool groupCanAddContactsWithMessage() const;
00084     bool groupCanAcceptContactsWithMessage() const;
00085     PendingOperation *groupAddContacts(const QList<ContactPtr> &contacts,
00086             const QString &message = QString());
00087     bool groupCanRescindContacts() const;
00088     bool groupCanRescindContactsWithMessage() const;
00089     bool groupCanRemoveContacts() const;
00090     bool groupCanRemoveContactsWithMessage() const;
00091     bool groupCanRejectContactsWithMessage() const;
00092     bool groupCanDepartWithMessage() const;
00093     PendingOperation *groupRemoveContacts(const QList<ContactPtr> &contacts,
00094             const QString &message = QString(),
00095             uint reason = ChannelGroupChangeReasonNone);
00096 
00097     Contacts groupContacts() const;
00098     Contacts groupLocalPendingContacts() const;
00099     Contacts groupRemotePendingContacts() const;
00100 
00101     class GroupMemberChangeDetails
00102     {
00103     public:
00104         GroupMemberChangeDetails()
00105             : mIsValid(false) {}
00106 
00107         bool isValid() const { return mIsValid; }
00108 
00109         bool hasActor() const { return !mActor.isNull(); }
00110         ContactPtr actor() const { return mActor; }
00111 
00112         bool hasReason() const { return mDetails.contains("change-reason"); }
00113         uint reason() const { return qdbus_cast<uint>(mDetails.value("change-reason")); }
00114 
00115         bool hasMessage() const { return mDetails.contains("message"); }
00116         QString message () const { return qdbus_cast<QString>(mDetails.value("message")); }
00117 
00118         bool hasError() const { return mDetails.contains("error"); }
00119         QString error() const { return qdbus_cast<QString>(mDetails.value("error")); }
00120 
00121         bool hasDebugMessage() const { return mDetails.contains("debug-message"); }
00122         QString debugMessage() const { return qdbus_cast<QString>(mDetails.value("debug-message")); }
00123 
00124         QVariantMap allDetails() const { return mDetails; }
00125 
00126     private:
00127         friend class Channel;
00128 
00129         GroupMemberChangeDetails(const ContactPtr &actor, const QVariantMap &details)
00130             : mActor(actor), mDetails(details), mIsValid(true) {}
00131 
00132         ContactPtr mActor;
00133         QVariantMap mDetails;
00134         bool mIsValid;
00135     };
00136 
00137     GroupMemberChangeDetails groupLocalPendingContactChangeInfo(const ContactPtr &contact) const;
00138     GroupMemberChangeDetails groupSelfContactRemoveInfo() const;
00139 
00140     bool groupAreHandleOwnersAvailable() const;
00141     HandleOwnerMap groupHandleOwners() const;
00142 
00143     bool groupIsSelfContactTracked() const;
00144     ContactPtr groupSelfContact() const;
00145 
00146 Q_SIGNALS:
00147     void groupFlagsChanged(uint flags, uint added, uint removed);
00148 
00149     void groupCanAddContactsChanged(bool canAddContacts);
00150     void groupCanRemoveContactsChanged(bool canRemoveContacts);
00151     void groupCanRescindContactsChanged(bool canRescindContacts);
00152 
00153     void groupMembersChanged(
00154             const Tp::Contacts &groupMembersAdded,
00155             const Tp::Contacts &groupLocalPendingMembersAdded,
00156             const Tp::Contacts &groupRemotePendingMembersAdded,
00157             const Tp::Contacts &groupMembersRemoved,
00158             const Tp::Channel::GroupMemberChangeDetails &details);
00159 
00160     void groupHandleOwnersChanged(const Tp::HandleOwnerMap &owners,
00161             const Tp::UIntList &added, const Tp::UIntList &removed);
00162 
00163     void groupSelfContactChanged();
00164 
00165 protected:
00166     bool groupSelfHandleIsLocalPending() const;
00167 
00168 protected Q_SLOTS:
00169     PendingOperation *groupAddSelfHandle();
00170 
00171 public:
00172     template <class Interface>
00173     inline Interface *optionalInterface(
00174             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00175     {
00176         // Check for the remote object supporting the interface
00177         QString name(Interface::staticInterfaceName());
00178         if (check == CheckInterfaceSupported && !interfaces().contains(name))
00179             return 0;
00180 
00181         // If present or forced, delegate to OptionalInterfaceFactory
00182         return OptionalInterfaceFactory<Channel>::interface<Interface>();
00183     }
00184 
00185     inline Client::ChannelInterfaceCallStateInterface *callStateInterface(
00186             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00187     {
00188         return optionalInterface<Client::ChannelInterfaceCallStateInterface>(check);
00189     }
00190 
00191     inline Client::ChannelInterfaceChatStateInterface *chatStateInterface(
00192             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00193     {
00194         return optionalInterface<Client::ChannelInterfaceChatStateInterface>(check);
00195     }
00196 
00197     inline Client::ChannelInterfaceDTMFInterface *DTMFInterface(
00198             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00199     {
00200         return optionalInterface<Client::ChannelInterfaceDTMFInterface>(check);
00201     }
00202 
00203     inline Client::ChannelInterfaceHoldInterface *holdInterface(
00204             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00205     {
00206         return optionalInterface<Client::ChannelInterfaceHoldInterface>(check);
00207     }
00208 
00209     inline Client::ChannelInterfaceMediaSignallingInterface *mediaSignallingInterface(
00210             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00211     {
00212         return optionalInterface<Client::ChannelInterfaceMediaSignallingInterface>(check);
00213     }
00214 
00215     inline Client::ChannelInterfaceMessagesInterface *messagesInterface(
00216             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00217     {
00218         return optionalInterface<Client::ChannelInterfaceMessagesInterface>(check);
00219     }
00220 
00221     inline Client::ChannelInterfacePasswordInterface *passwordInterface(
00222             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00223     {
00224         return optionalInterface<Client::ChannelInterfacePasswordInterface>(check);
00225     }
00226 
00227     inline Client::DBus::PropertiesInterface *propertiesInterface() const
00228     {
00229         return optionalInterface<Client::DBus::PropertiesInterface>(BypassInterfaceCheck);
00230     }
00231 
00232     template <class Interface>
00233     inline Interface *typeInterface(
00234             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00235     {
00236         // Check for the remote object having the correct channel type
00237         QString name(Interface::staticInterfaceName());
00238         if (check == CheckInterfaceSupported && channelType() != name)
00239             return 0;
00240 
00241         // If correct type or check bypassed, delegate to OIF
00242         return OptionalInterfaceFactory<Channel>::interface<Interface>();
00243     }
00244 
00245     inline Client::ChannelTypeRoomListInterface *roomListInterface(
00246             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00247     {
00248         return typeInterface<Client::ChannelTypeRoomListInterface>(check);
00249     }
00250 
00251     inline Client::ChannelTypeStreamedMediaInterface *streamedMediaInterface(
00252             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00253     {
00254         return typeInterface<Client::ChannelTypeStreamedMediaInterface>(check);
00255     }
00256 
00257     inline Client::ChannelTypeTextInterface *textInterface(
00258             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00259     {
00260         return typeInterface<Client::ChannelTypeTextInterface>(check);
00261     }
00262 
00263     inline Client::ChannelTypeTubesInterface *tubesInterface(
00264             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00265     {
00266         return typeInterface<Client::ChannelTypeTubesInterface>(check);
00267     }
00268 
00269 protected:
00270     Channel(const ConnectionPtr &connection,const QString &objectPath,
00271             const QVariantMap &immutableProperties);
00272 
00273     Client::ChannelInterface *baseInterface() const;
00274 
00275     inline Client::ChannelInterfaceGroupInterface *groupInterface(
00276             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00277     {
00278         return optionalInterface<Client::ChannelInterfaceGroupInterface>(check);
00279     }
00280 
00281 private Q_SLOTS:
00282     void gotMainProperties(QDBusPendingCallWatcher *watcher);
00283     void gotChannelType(QDBusPendingCallWatcher *watcher);
00284     void gotHandle(QDBusPendingCallWatcher *watcher);
00285     void gotInterfaces(QDBusPendingCallWatcher *watcher);
00286     void onClosed();
00287 
00288     void onConnectionInvalidated();
00289     void onConnectionDestroyed();
00290 
00291     void gotGroupProperties(QDBusPendingCallWatcher *watcher);
00292     void gotGroupFlags(QDBusPendingCallWatcher *watcher);
00293     void gotAllMembers(QDBusPendingCallWatcher *watcher);
00294     void gotLocalPendingMembersWithInfo(QDBusPendingCallWatcher *watcher);
00295     void gotSelfHandle(QDBusPendingCallWatcher *watcher);
00296     void gotContacts(Tp::PendingOperation *op);
00297 
00298     void onGroupFlagsChanged(uint, uint);
00299     void onMembersChanged(const QString&,
00300             const Tp::UIntList&, const Tp::UIntList&,
00301             const Tp::UIntList&, const Tp::UIntList&, uint, uint);
00302     void onMembersChangedDetailed(
00303         const Tp::UIntList &added, const Tp::UIntList &removed,
00304         const Tp::UIntList &localPending, const Tp::UIntList &remotePending,
00305         const QVariantMap &details);
00306     void onHandleOwnersChanged(const Tp::HandleOwnerMap&, const Tp::UIntList&);
00307     void onSelfHandleChanged(uint);
00308 
00309     void continueIntrospection();
00310 
00311 private:
00312     struct Private;
00313     friend struct Private;
00314     Private *mPriv;
00315 };
00316 
00317 } // Tp
00318 
00319 Q_DECLARE_METATYPE(Tp::Channel::GroupMemberChangeDetails);
00320 
00321 #endif


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