Merge ICQ/AIM Presence stuff and clean it.
[kdenetwork.git] / kopete / libkopete / kopeteaccountmanager.h
blobefe311a8333b5ecc64cf8d62050fa99d7182c67f
1 /*
2 kopeteaccountmanager.h - Kopete Account Manager
4 Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org>
5 Copyright (c) 2003-2005 by Olivier Goffart <ogoffart@kde.org>
7 Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
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 *************************************************************************
19 #ifndef __kopeteaccountmanager_h__
20 #define __kopeteaccountmanager_h__
22 #include <QObject>
23 #include <QColor>
24 #include "kopete_export.h"
27 namespace Kopete {
29 class Account;
30 class Plugin;
31 class Protocol;
32 class Contact;
33 class OnlineStatus;
35 /**
36 * AccountManager manages all defined accounts in Kopete. You can
37 * query them and globally set them all online or offline from here.
39 * AccountManager is a singleton, you may uses it with @ref AccountManager::self()
41 * @author Martijn Klingens <klingens@kde.org>
42 * @author Olivier Goffart <ogoffart\@kde.org>
44 class KOPETE_EXPORT AccountManager : public QObject
46 Q_OBJECT
48 public:
49 /**
50 * \brief Retrieve the instance of AccountManager.
52 * The account manager is a singleton class of which only a single
53 * instance will exist. If no manager exists yet this function will
54 * create one for you.
56 * \return the instance of the AccountManager
58 static AccountManager* self();
60 ~AccountManager();
62 /**
63 * \brief Retrieve the list of accounts
64 * \return a list of all the accounts
66 const QList<Account *> & accounts() const;
68 /**
69 * \brief Retrieve a list of accounts per protocol
71 * Provides a list of accounts for a certain protocol. If there are
72 * no accounts for that protocol then the list is empty.
73 * \param protocol the protocol to get accounts for
74 * \return the list of accounts that belong to the @p protocol protocol
76 QList<Account*> accounts( Kopete::Protocol* protocol ) const;
78 /**
79 * \brief Return the account asked
80 * \param protocolId is the ID for the protocol
81 * \param accountId is the ID for the account you want
82 * \return the Account object found or NULL if no account was found
84 Account* findAccount( const QString &protocolId, const QString &accountId );
86 /**
87 * \brief Delete the account and clean the config data
89 * This is praticaly called by the account config page when you remove the account.
91 void removeAccount( Account *account );
93 /**
94 * \brief Guess the color for a new account
96 * Guesses a color for the next account of a given protocol based on the already registered colors
97 * \return the color guessed for the account
99 QColor guessColor( Protocol *protocol ) const ;
102 * @brief Register the account.
104 * This adds the account in the manager's account list.
105 * It will check no accounts already exist with the same ID, if any, the account is deleted. and not added
107 * @return @p account, or 0L if the account was deleted because id collision
109 Account *registerAccount( Account *account );
113 * Flag to be used in setOnlineStatus
115 * @c ConnectIfOffline : if set, this will connect offlines account with the status.
117 enum SetOnlineStatusFlag { ConnectIfOffline=0x01 };
120 public slots:
122 * @deprecated use setOnlineStatus
124 void connectAll();
127 * @deprecated use setOnlineStatus
129 void disconnectAll();
132 * @brief Set all accounts a status in the specified category
134 * Account that are offline will not be connected, unless the ConnectIfOffline flag is set.
136 * @param category is one of the Kopete::OnlineStatusManager::Categories
137 * @param awayMessage is the new away message
138 * @param flags is a bitmask of SetOnlineStatusFlag
140 void setOnlineStatus( /*Kopete::OnlineStatusManager::Categories*/ uint category,
141 const QString& awayMessage = QString::null, uint flags=0);
144 * @deprecated use setOnlineStatus
146 void setAwayAll( const QString &awayReason = QString::null, bool away=true );
149 * @deprecated use setOnlineStatus
151 void setAvailableAll( const QString &awayReason = QString::null );
154 * \internal
155 * Save the account data to KConfig
157 void save();
160 * \internal
161 * Load the account data from KConfig
163 void load();
167 signals:
169 * \brief Signals when an account is ready for use
171 void accountRegistered( Kopete::Account *account );
174 * \brief Signals when an account has been unregistered
176 * At this state, we are already in the Account destructor.
178 void accountUnregistered( const Kopete::Account *account );
181 * \brief An account has changed its onlinestatus
182 * Technically this monitors Account::myself() onlinestatus changes
183 * \param account Account which changed its onlinestatus
184 * \param oldStatus The online status before the change
185 * \param newStatus The new online status
187 void accountOnlineStatusChanged(Kopete::Account *account,
188 const Kopete::OnlineStatus &oldStatus, const Kopete::OnlineStatus &newStatus);
190 private:
192 * Private constructor, because we're a singleton
194 AccountManager();
196 private slots:
197 void slotPluginLoaded( Kopete::Plugin *plugin );
198 void slotAccountOnlineStatusChanged(Kopete::Contact *c,
199 const Kopete::OnlineStatus &oldStatus, const Kopete::OnlineStatus &newStatus);
202 * \internal
203 * Unregister the account.
205 void unregisterAccount( const Kopete::Account *account );
207 private:
208 bool isAnyAccountConnected();
209 static AccountManager *s_self;
210 class Private;
211 Private *d;
214 } //END namespace Kopete
217 #endif