/***************************************************************************
                          contactlist.h  -  description
                             -------------------
    begin                : Sun Jan 5 2003
    copyright            : (C) 2003 by Mike K. Bennett
                           (C) 2005 by Diederik van der Boor
    email                : mkb137b@hotmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef CONTACTLIST_H
#define CONTACTLIST_H

#include <qptrlist.h>
#include <qobject.h>

// Forward declarations
class Contact;
class CurrentAccount;
class Group;
class KConfig;
class KMessTest;


/**
 * The list of contacts.
 * @author Mike K. Bennett
 */
class ContactList : public QObject
{
  Q_OBJECT

  friend class KMessTest;

  public: // Public methods
    // The constructor
                         ContactList();
    // The destructor
                        ~ContactList();
    // Add a contact to the contact list
    Contact *            addContact( QString handle, QString friendlyName, int lists, QString groupIds );
    // Add a group to the contact list
    Group *              addGroup( QString groupId, QString groupName );
    // Change a contact's status (and update the friendly name)
    void                 changeContactStatus( QString handle, QString friendlyName, QString status,
                                              uint capabilities = 0, QString msnObject = 0, bool showBaloon = true );
    // Return the contact with the given handle
    Contact*             getContactByHandle( QString handle ) const;
    // Get the friendly name of the given contact
    QString              getContactFriendlyNameByHandle( const QString& handle ) const;
    // Return the contact which was last dragged.
    Contact*             getContactLastDragged() const;
    // Return the list of contacts
    const QPtrList<Contact>& getContactList() const;
    // Return the group with the given id
    Group*               getGroupById( QString groupId ) const;
    // Return the group with the given sort position
    Group*               getGroupBySortPosition(int sortPosition) const;
    // Return the list of groups
    const QPtrList<Group>& getGroupList() const;
    // Read in account and other properties
    void                 readProperties(KConfig *config);
    // Remove a group
    void                 removeGroup( QString groupId );
    // Change a contact's name
    void                 renameContact( QString handle, QString newName );
    // Change a group's name
    void                 renameGroup( QString groupId, QString newName );
    // Restore the orginal state of the contact list (empty it)
    void                 reset();
    // Save account and other properties
    void                 saveProperties(KConfig *config);
    // Set a contact to offline
    void                 setContactOffline( QString handle );

  private: // Private methods
    // Return whether or not the contact with the given handle exists
    bool                 contactExists( QString handle );
    // Delete all the contacts
    void                 deleteAllContacts();
    // Delete all non-special groups
    void                 deleteNonSpecialGroups();
    // Return whether or not a group with the given id exists
    bool                 groupExists( QString groupId );

  private slots: // Private slots
    // Forward from a contact that is has moved
    void                 slotForwardContactMoved(Contact *contact);
    // Forward from a contact that it is offline
    void                 slotForwardContactOffline(Contact *contact, bool showBaloon);
    // Forward from a contact that it is contact is online
    void                 slotForwardContactOnline(Contact *contact, bool showBaloon);


  private: // Private attributes
    // The list of contacts
    QPtrList<Contact>    contacts_;
    // The list of groups
    QPtrList<Group>      groups_;

  signals: // Signals
    // Signal that a contact has been added.
    void                 contactAdded(Contact *contact);
    // Signal that a contact changed it's status.
    void                 contactChangeStatus(Contact *contact);
    // Signal that a contact has moved to a different position in the group list
    void                 contactMoved( Contact *contact );
    // Signal that a contact is offline
    void                 contactOffline( Contact *contact, bool showBaloon );
    // Signal that a contact is online
    void                 contactOnline( Contact *contact, bool showBaloon );
    // Signal that a contact has been removed.
    void                 contactRemoved(const Contact *contact);
    // Signal that a group has been added
    void                 groupAdded(Group *group);
    // Signal that a group has been added
    void                 groupRemoved(const Group *group);
};

#endif
