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_account_h_HEADER_GUARD_ 00023 #define _TelepathyQt4_cli_account_h_HEADER_GUARD_ 00024 00025 #ifndef IN_TELEPATHY_QT4_HEADER 00026 #error IN_TELEPATHY_QT4_HEADER 00027 #endif 00028 00029 #include <TelepathyQt4/_gen/cli-account.h> 00030 00031 #include <TelepathyQt4/Client/DBus> 00032 #include <TelepathyQt4/Client/DBusProxy> 00033 #include <TelepathyQt4/Client/OptionalInterfaceFactory> 00034 #include <TelepathyQt4/Constants> 00035 00036 #include <QSet> 00037 #include <QSharedPointer> 00038 #include <QString> 00039 #include <QStringList> 00040 #include <QVariantMap> 00041 00042 namespace Telepathy 00043 { 00044 namespace Client 00045 { 00046 00047 class Account; 00048 class AccountManager; 00049 class Connection; 00050 class PendingConnection; 00051 class PendingOperation; 00052 class PendingReady; 00053 class ProtocolInfo; 00054 00055 class Account : public StatelessDBusProxy, 00056 private OptionalInterfaceFactory<Account> 00057 { 00058 Q_OBJECT 00059 Q_DISABLE_COPY(Account) 00060 00061 public: 00062 enum Feature { 00063 FeatureCore = 0, 00064 FeatureAvatar = 1, 00065 FeatureProtocolInfo = 2, 00066 _Padding = 0xFFFFFFFF 00067 }; 00068 Q_DECLARE_FLAGS(Features, Feature) 00069 00070 Account(AccountManager *am, const QString &objectPath, 00071 QObject *parent = 0); 00072 00073 virtual ~Account(); 00074 00075 AccountManager *manager() const; 00076 00077 bool isValidAccount() const; 00078 00079 bool isEnabled() const; 00080 PendingOperation *setEnabled(bool value); 00081 00082 QString cmName() const; 00083 00084 QString protocol() const; 00085 00086 QString displayName() const; 00087 PendingOperation *setDisplayName(const QString &value); 00088 00089 QString icon() const; 00090 PendingOperation *setIcon(const QString &value); 00091 00092 QString nickname() const; 00093 PendingOperation *setNickname(const QString &value); 00094 00095 // requires spec 0.17.16 00096 const Telepathy::Avatar &avatar() const; 00097 PendingOperation *setAvatar(const Telepathy::Avatar &avatar); 00098 00099 QVariantMap parameters() const; 00100 PendingOperation *updateParameters(const QVariantMap &set, 00101 const QStringList &unset); 00102 00103 // comes from the ConnectionManager 00104 ProtocolInfo *protocolInfo() const; 00105 00106 bool connectsAutomatically() const; 00107 PendingOperation *setConnectsAutomatically(bool value); 00108 00109 Telepathy::ConnectionStatus connectionStatus() const; 00110 Telepathy::ConnectionStatusReason connectionStatusReason() const; 00111 bool haveConnection() const; 00112 QSharedPointer<Connection> connection() const; 00113 00114 Telepathy::SimplePresence automaticPresence() const; 00115 PendingOperation *setAutomaticPresence( 00116 const Telepathy::SimplePresence &value); 00117 00118 Telepathy::SimplePresence currentPresence() const; 00119 00120 Telepathy::SimplePresence requestedPresence() const; 00121 PendingOperation *setRequestedPresence( 00122 const Telepathy::SimplePresence &value); 00123 00124 QString uniqueIdentifier() const; 00125 00126 // doc as for advanced users 00127 QString connectionObjectPath() const; 00128 00129 QString normalizedName() const; 00130 00131 PendingOperation *remove(); 00132 00133 bool isReady(const QSet<uint> &features = QSet<uint>()) const; 00134 00135 PendingReady *becomeReady(const QSet<uint> &requestedFeatures = QSet<uint>()); 00136 00137 QSet<uint> requestedFeatures() const; 00138 QSet<uint> actualFeatures() const; 00139 QSet<uint> missingFeatures() const; 00140 00141 QStringList interfaces() const; 00142 00143 template <class Interface> 00144 inline Interface *optionalInterface( 00145 InterfaceSupportedChecking check = CheckInterfaceSupported) const 00146 { 00147 // Check for the remote object supporting the interface 00148 QString name(Interface::staticInterfaceName()); 00149 if (check == CheckInterfaceSupported && !interfaces().contains(name)) { 00150 return 0; 00151 } 00152 00153 // If present or forced, delegate to OptionalInterfaceFactory 00154 return OptionalInterfaceFactory<Account>::interface<Interface>(); 00155 } 00156 00157 inline DBus::PropertiesInterface *propertiesInterface() const 00158 { 00159 return optionalInterface<DBus::PropertiesInterface>(BypassInterfaceCheck); 00160 } 00161 00162 inline AccountInterfaceAvatarInterface *avatarInterface( 00163 InterfaceSupportedChecking check = CheckInterfaceSupported) const 00164 { 00165 return optionalInterface<AccountInterfaceAvatarInterface>(check); 00166 } 00167 00168 Q_SIGNALS: 00169 void displayNameChanged(const QString &); 00170 void iconChanged(const QString &); 00171 void nicknameChanged(const QString &); 00172 void normalizedNameChanged(const QString &); 00173 void validityChanged(bool); 00174 void stateChanged(bool); 00175 void connectsAutomaticallyPropertyChanged(bool); 00176 void parametersChanged(const QVariantMap &); 00177 void automaticPresenceChanged(const Telepathy::SimplePresence &) const; 00178 void currentPresenceChanged(const Telepathy::SimplePresence &) const; 00179 void requestedPresenceChanged(const Telepathy::SimplePresence &) const; 00180 void avatarChanged(const Telepathy::Avatar &); 00181 void connectionStatusChanged(Telepathy::ConnectionStatus, 00182 Telepathy::ConnectionStatusReason); 00183 void haveConnectionChanged(bool haveConnection); 00184 00185 protected: 00186 AccountInterface *baseInterface() const; 00187 00188 private Q_SLOTS: 00189 void gotMainProperties(QDBusPendingCallWatcher *); 00190 void gotAvatar(QDBusPendingCallWatcher *); 00191 void onAvatarChanged(); 00192 void onConnectionManagerReady(Telepathy::Client::PendingOperation *); 00193 void onPropertyChanged(const QVariantMap &delta); 00194 void onRemoved(); 00195 00196 private: 00197 struct Private; 00198 friend struct Private; 00199 Private *mPriv; 00200 }; 00201 00202 Q_DECLARE_OPERATORS_FOR_FLAGS(Account::Features) 00203 00204 } // Telepathy::Client 00205 } // Telepathy 00206 00207 #endif