Logo Search packages:      
Sourcecode: kmess version File versions

chatmaster.h

/***************************************************************************
                          chatmaster.h  -  description
                             -------------------
    begin                : Sat Jan 18 2003
    copyright            : (C) 2003 by Mike K. Bennett
    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 CHATMASTER_H
#define CHATMASTER_H

#include "../network/mimemessage.h"

#include <qptrlist.h>
#include <qwidget.h>

// Forward declarations
class Contact;
class ContactBase;
class ChatInformation;
class ChatMessage;
class ChatWindow;
class Application;
class ApplicationList;
class MimeMessage;
class MimeApplication;
class P2PMessage;
class P2PApplication;
class MsnSwitchboardConnection;
class MsnObject;

/**
 * This class governs the chat windows, detecting when a chat
 * can be restarted in an open window and the like.
 * @author Mike K. Bennett
 */
00046 class ChatMaster : public QObject
{
  Q_OBJECT

  public: // Public methods
    // The constructor
                       ChatMaster(QObject *parent = 0);
    // The destructor
    virtual           ~ChatMaster();
    // Initialize the class
    bool               initialize();

  public slots: // Public slots
    // The user has disconnected, so close all open chats
    void               disconnected();
    // Deliver a chat message to the chat window (can be submitted by an Application or Offline-IM from MsnNotificationConnection).
    void               showChatMessage(const ChatMessage &message);
    // Start the chat with the information gathered from the Notification connection
    void               startChat( const ChatInformation &chatInfo );
    // Start a file transfer with the information from the ChatWindow
    void               startFileTransfer( const QString &handle, const QString &filename );

  private slots: // Private slots
    // Forward a new chat signal from a chat window
    void               forwardNewChat(const ContactBase *contact, QString message, ChatWindow *chatWindow);
      // Forward a request chat signal from a chat window
    void               forwardRequestChat(QString handle);
    // A chat window is closing
    void               slotChatWindowClosing(QObject *chatWindow);
    // A chat window was destroyed
    void               slotChatWindowDestroyed(QObject *chatWindow);
    // A new application was created for a contact.
    void               slotConnectApplication(Application *application);
    // Determine what to do when a contact changed it's picture.
    void               slotContactChangedMsnObject( Contact *contact );
    // A contact joined to one of our switchboard sessions.
    void               slotContactJoinedChat(QString handle);
    // Deliver an application command to the correct application
    void               slotDeliverAppCommand(QString cookie, QString handle, QString command);
    // Deliver a message from a Application to the switchboard connection.
    void               slotDeliverMimeMessage(const MimeMessage &message, const QString &handle, bool privateChatRequired);
    // The switchboard received a Mime message
    void               slotGotMessage(const MimeMessage &message, const QString &handle);
    // The switchboard received a P2P message
    void               slotGotMessage(const P2PMessage &message, const QString &handle);
    // The switchboard received an msn object
    void               slotGotMsnObject(const QString &msnObjectData, const QString &handle);
    // A msn object (picture, wink, emoticon) was received for the contact.
    void               slotMsnObjectReceived(const QString &handle, const MsnObject &msnObject);
    // The application wants to show an application message.
    void               slotShowAppMessage(QString filename);
    // The application wants to show an application event message.
    void               slotShowAppEventMessage(QString filename);
    // The application indicated a file was transferred
    void               slotShowFileTransferred(QString filename);
    // The application wants to show an system message
    void               slotShowSystemMessage(QString message);
    // The switchboard is ready to send more messages.
    void               slotSwitchboardReady();
    // Start a netmeeting invitation
    void               startNetMeeting(const QString &handle);

  private:  // private methods
    // Create and initialize a new chat window.
    ChatWindow *       createChatWindow();
    // Check whether the contact is in any of the existing chat windows.
    bool               isContactInChat( const QString &handle );
    // Display an MSN Object that was received.
    void               showMsnObject(const QString &handle, const MsnObject &msnObject, ChatWindow *chatWindow);
    // Configure and start the mime application object.
    void               startApplication( MimeApplication *application );
    // Configure and start the P2P application object.
    void               startApplication( P2PApplication *application );
    // Start the transfer of the contact's picture
    void               startMsnObjectDownload(const QString &handle, const MsnObject *msnObject, ChatWindow *chatWindow);
    // Return the application list for a given contact
    ApplicationList *  getApplicationList(const QString &handle);
    // Return the chat window which uses the given switchboard connection
    ChatWindow *       getChatWindowBySwitchboard(const MsnSwitchboardConnection *connection);
    // Return the chat window where we're having an conversation with the given contact.
    ChatWindow *       getContactChatWindow(const QString &handle, bool privateChat);
    // Return the chat connection where we're having an conversation with the given contact.
    MsnSwitchboardConnection * getContactSwitchboardConnection(const QString &handle, bool privateChat);
    // Append the message to the queue, waiting to be delivered
    void               queueMessage( const MimeMessage &message, const QString &handle, bool privateChatRequired );
    // Send all pending chat messages for the contact.
    void               sendPendingChatMessages( const QString &handle, ChatWindow *chatWindow );
    // Send all pending mime messages for the contact.
    void               sendPendingMimeMessages( const QString &handle, MsnSwitchboardConnection *connection );

  private: // Private attributes
    struct PendingMimeMessage
    {
      QString     handle;
      MimeMessage message;
      bool        privateChatRequired;
    };
    
    // The pointers to the chat windows
    QPtrList<ChatWindow> chatWindows_;
    // The pointers of chat windows that are closing
    QPtrList<ChatWindow> closingChatWindows_;
    // Whether or not the object was initialized
    bool               initialized_;
    // A list of chat messages that should be displayed in the chat window when connection is reestablished
    QPtrList< QPair<QString,ChatMessage> > pendingChatMessages_;
    // A list of mime messages that should be sent to the contact when connection is reestablished
    QPtrList< PendingMimeMessage > pendingMimeMessages_;

  signals: // Public signals
    // Signal that a new chat has started
    void               newChat(const ContactBase *contact, QString message, ChatWindow *chatWindow);
    // Ask the Notification connection to initiate a new chat conversation with the contact
    void               requestChat(QString handle);
};

#endif

Generated by  Doxygen 1.6.0   Back to index