Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / libkopete / kopeteaccountmanager.h
blob9466fe22e293d7b2e5fa43aefac1dbd7a42c9b97
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 <QtCore/QObject>
23 #include <QtGui/QColor>
25 #include "kopete_export.h"
27 #include "kopetestatusmessage.h"
29 namespace Kopete {
31 class Account;
32 class Plugin;
33 class Protocol;
34 class Contact;
35 class OnlineStatus;
36 class StatusMessage;
38 /**
39 * AccountManager manages all defined accounts in Kopete. You can
40 * query them and globally set them all online or offline from here.
42 * AccountManager is a singleton, you may uses it with @ref AccountManager::self()
44 * @author Martijn Klingens <klingens@kde.org>
45 * @author Olivier Goffart <ogoffart\@kde.org>
47 class KOPETE_EXPORT AccountManager : public QObject
49 Q_OBJECT
51 public:
52 /**
53 * \brief Retrieve the instance of AccountManager.
55 * The account manager is a singleton class of which only a single
56 * instance will exist. If no manager exists yet this function will
57 * create one for you.
59 * \return the instance of the AccountManager
61 static AccountManager* self();
63 ~AccountManager();
65 /**
66 * \brief Retrieve the list of accounts
67 * \return a list of all the accounts
69 const QList<Account *> & accounts() const;
71 /**
72 * \brief Retrieve a list of accounts per protocol
74 * Provides a list of accounts for a certain protocol. If there are
75 * no accounts for that protocol then the list is empty.
76 * \param protocol the protocol to get accounts for
77 * \return the list of accounts that belong to the @p protocol protocol
79 QList<Account*> accounts( Kopete::Protocol* protocol ) const;
81 /**
82 * \brief Return the account asked
83 * \param protocolId is the ID for the protocol
84 * \param accountId is the ID for the account you want
85 * \return the Account object found or NULL if no account was found
87 Account* findAccount( const QString &protocolId, const QString &accountId );
89 /**
90 * \brief Delete the account and clean the config data
92 * This is praticaly called by the account config page when you remove the account.
94 void removeAccount( Account *account );
96 /**
97 * \brief Guess the color for a new account
99 * Guesses a color for the next account of a given protocol based on the already registered colors
100 * \return the color guessed for the account
102 QColor guessColor( Protocol *protocol ) const ;
105 * @brief Register the account.
107 * This adds the account in the manager's account list.
108 * It will check no accounts already exist with the same ID, if any, the account is deleted. and not added
110 * @return @p account, or 0L if the account was deleted because id collision
112 Account *registerAccount( Account *account );
116 * Flag to be used in setOnlineStatus
118 * @c ConnectIfOffline : if set, this will connect offlines account with the status.
120 enum SetOnlineStatusFlag { ConnectIfOffline=0x01 };
123 public slots:
125 * @brief Set all accounts a status in the specified category
127 * Account that are offline will not be connected, unless the ConnectIfOffline flag is set.
129 * @param category is one of the Kopete::OnlineStatusManager::Categories
130 * @param statusMessage is the new status message
131 * @param flags is a bitmask of SetOnlineStatusFlag
133 void setOnlineStatus( /*Kopete::OnlineStatusManager::Categories*/ uint category,
134 const Kopete::StatusMessage &statusMessage = Kopete::StatusMessage(), uint flags=0);
137 * @brief Set the given status message for all online accounts
139 * @param message Status message to set
141 void setStatusMessage(const QString &message);
144 * \internal
145 * Save the account data to KConfig
147 void save();
150 * \internal
151 * Load the account data from KConfig
153 void load();
157 signals:
159 * \brief Signals when an account is ready for use
161 void accountRegistered( Kopete::Account *account );
164 * \brief Signals when an account has been unregistered
166 * At this state, we are already in the Account destructor.
168 void accountUnregistered( const Kopete::Account *account );
171 * \brief An account has changed its onlinestatus
172 * Technically this monitors Account::myself() onlinestatus changes
173 * \param account Account which changed its onlinestatus
174 * \param oldStatus The online status before the change
175 * \param newStatus The new online status
177 void accountOnlineStatusChanged(Kopete::Account *account,
178 const Kopete::OnlineStatus &oldStatus, const Kopete::OnlineStatus &newStatus);
180 private:
182 * Private constructor, because we're a singleton
184 AccountManager();
186 private slots:
188 * Try to connect every account that should be connected automatically
190 void networkConnected();
192 * Disconnect everything
194 void networkDisconnected();
196 void slotPluginLoaded( Kopete::Plugin *plugin );
197 void slotAccountOnlineStatusChanged(Kopete::Contact *c,
198 const Kopete::OnlineStatus &oldStatus, const Kopete::OnlineStatus &newStatus);
201 * \internal
202 * Unregister the account.
204 void unregisterAccount( const Kopete::Account *account );
206 private:
207 bool isAnyAccountConnected() const;
208 static AccountManager *s_self;
209 class Private;
210 Private * const d;
213 } //END namespace Kopete
216 #endif