1 /* 2 kopeteaccountmanager.h - Kopete Account Manager 3 4 Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org> 5 Copyright (c) 2003-2005 by Olivier Goffart <ogoffart@kde.org> 6 7 Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org> 8 9 ************************************************************************* 10 * * 11 * This library is free software; you can redistribute it and/or * 12 * modify it under the terms of the GNU Lesser General Public * 13 * License as published by the Free Software Foundation; either * 14 * version 2 of the License, or (at your option) any later version. * 15 * * 16 ************************************************************************* 17 */ 18 19 #ifndef KOPETEACCOUNTMANAGER_H 20 #define KOPETEACCOUNTMANAGER_H 21 22 #include <QObject> 23 #include <QColor> 24 25 #include "libkopete_export.h" 26 #include "libkopete_debug.h" 27 #include "kopetestatusmessage.h" 28 29 namespace Kopete { 30 class Account; 31 class Plugin; 32 class Protocol; 33 class Contact; 34 class OnlineStatus; 35 class StatusMessage; 36 37 /** 38 * AccountManager manages all defined accounts in Kopete. You can 39 * query them and globally set them all online or offline from here. 40 * 41 * AccountManager is a singleton, you may uses it with @ref AccountManager::self() 42 * 43 * @author Martijn Klingens <klingens@kde.org> 44 * @author Olivier Goffart <ogoffart\@kde.org> 45 */ 46 class LIBKOPETE_EXPORT AccountManager : public QObject 47 { 48 Q_OBJECT 49 50 public: 51 /** 52 * \brief Retrieve the instance of AccountManager. 53 * 54 * The account manager is a singleton class of which only a single 55 * instance will exist. If no manager exists yet this function will 56 * create one for you. 57 * 58 * \return the instance of the AccountManager 59 */ 60 static AccountManager *self(); 61 62 ~AccountManager(); 63 64 /** 65 * \brief Retrieve the list of accounts 66 * \return a list of all the accounts 67 */ 68 const QList<Account *> &accounts() const; 69 70 /** 71 * \brief Retrieve a list of accounts per protocol 72 * 73 * Provides a list of accounts for a certain protocol. If there are 74 * no accounts for that protocol then the list is empty. 75 * \param protocol the protocol to get accounts for 76 * \return the list of accounts that belong to the @p protocol protocol 77 */ 78 QList<Account *> accounts(Kopete::Protocol *protocol) const; 79 80 /** 81 * \brief Return the account asked 82 * \param protocolId is the ID for the protocol 83 * \param accountId is the ID for the account you want 84 * \return the Account object found or NULL if no account was found 85 */ 86 Account *findAccount(const QString &protocolId, const QString &accountId); 87 88 /** 89 * \brief Delete the account and clean the config data 90 * 91 * This is praticaly called by the account config page when you remove the account. 92 */ 93 void removeAccount(Account *account); 94 95 /** 96 * \brief Guess the color for a new account 97 * 98 * Guesses a color for the next account of a given protocol based on the already registered colors 99 * \return the color guessed for the account 100 */ 101 QColor guessColor(Protocol *protocol) const; 102 103 /** 104 * @brief Register the account. 105 * 106 * This adds the account in the manager's account list. 107 * It will check no accounts already exist with the same ID, if any, the account is deleted. and not added 108 * 109 * @return @p account, or 0L if the account was deleted because id collision 110 */ 111 Account *registerAccount(Account *account); 112 113 /** 114 * \brief Check if there is at least one account connected. 115 * \return true if there at least one account connected, false otherwise. 116 */ 117 bool isAnyAccountConnected() const; 118 119 /** 120 * Flag to be used in setOnlineStatus 121 * 122 * @c ConnectIfOffline : if set, this will connect offlines account with the status. 123 */ 124 enum SetOnlineStatusFlag { 125 ConnectIfOffline = 0x01 126 }; 127 128 public Q_SLOTS: 129 /** 130 * @brief Set all accounts a status in the specified category 131 * 132 * Account that are offline will not be connected, unless the ConnectIfOffline flag is set. 133 * 134 * @param category is one of the Kopete::OnlineStatusManager::Categories 135 * @param statusMessage is the new status message 136 * @param flags is a bitmask of SetOnlineStatusFlag 137 * @param forced is a boolean indicating that all accounts are required to change status 138 * 139 * @note KDE5: Merge these two setOnlineStatus functions (default value for forced is false) 140 */ 141 void setOnlineStatus(/*Kopete::OnlineStatusManager::Categories*/ uint category, const Kopete::StatusMessage &statusMessage, uint flags, bool forced); 142 143 void setOnlineStatus(/*Kopete::OnlineStatusManager::Categories*/ uint category, const Kopete::StatusMessage &statusMessage = Kopete::StatusMessage(), uint flags = 0); 144 145 /** 146 * @brief Set the given status message for all online accounts 147 * 148 * @param message Status message to set 149 */ 150 void setStatusMessage(const QString &message); 151 152 /** 153 * Suspends all accounts. 154 */ 155 void suspend(); 156 157 /** 158 * Resumes all accounts. 159 * Returns false if network is not available. 160 */ 161 bool resume(); 162 163 /** 164 * \internal 165 * Save the account data to KConfig 166 */ 167 void save(); 168 169 /** 170 * \internal 171 * Load the account data from KConfig 172 */ 173 void load(); 174 175 Q_SIGNALS: 176 /** 177 * \brief Signals when an account is ready for use 178 */ 179 void accountRegistered(Kopete::Account *account); 180 181 /** 182 * \brief Signals when an account has been unregistered 183 * 184 * At this state, we are already in the Account destructor. 185 */ 186 void accountUnregistered(const Kopete::Account *account); 187 188 /** 189 * \brief An account has changed its onlinestatus 190 * Technically this monitors Account::myself() onlinestatus changes 191 * \param account Account which changed its onlinestatus 192 * \param oldStatus The online status before the change 193 * \param newStatus The new online status 194 */ 195 void accountOnlineStatusChanged(Kopete::Account *account, const Kopete::OnlineStatus &oldStatus, const Kopete::OnlineStatus &newStatus); 196 197 private: 198 /** 199 * Private constructor, because we're a singleton 200 */ 201 AccountManager(); 202 203 private Q_SLOTS: 204 /** 205 * Try to connect every account that should be connected automatically 206 */ 207 void networkConnected(); 208 /** 209 * Disconnect everything 210 */ 211 void networkDisconnected(); 212 213 void slotPluginLoaded(Kopete::Plugin *plugin); 214 void slotAccountOnlineStatusChanged(Kopete::Contact *c, const Kopete::OnlineStatus &oldStatus, const Kopete::OnlineStatus &newStatus); 215 216 /** 217 * \internal 218 * Unregister the account. 219 */ 220 void unregisterAccount(const Kopete::Account *account); 221 222 void removeAccountConnectedChanged(); 223 224 /** 225 * Remove account and its contacts. 226 */ 227 void removeAccountInternal(); 228 229 private: 230 static AccountManager *s_self; 231 class Private; 232 Private *const d; 233 }; 234 } //END namespace Kopete 235 236 #endif 237