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