Logo Search packages:      
Sourcecode: kmess version File versions  Download package

networkwindow.h

/***************************************************************************
                          networkwindow.cpp  -  description
                             -------------------
    begin                : Wed Jan 28 2005
    copyright            : (C) 2005 by Diederik van der Boor
    email                : "vdboor" --at-- "codingdomain.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 NETWORKWINDOW_H
#define NETWORKWINDOW_H

#include "../kmessdebug.h"

#include <kdialogbase.h>
#include <ktextbrowser.h>

#include <qptrdict.h>  // a hashmap with key and value pointers.
#include <qdatetime.h>

class QTabWidget;


/**
 * Network log window, to filter MSN protocol information in a readable way.
 * Based on the original work of Michael Jarrett, but totally revised.
 *
 * @author Diederik van der Boor
 */
00039 class NetworkWindow : public KDialogBase
{
  public:
    // Constructor
                           NetworkWindow(QWidget *parent = 0, const char *name = 0);

    // List of connection types
    enum ConnectionType
    {
      TYPE_UNKNOWN = 0,
      TYPE_NS      = 1,
      TYPE_SB      = 2,
      TYPE_FTP     = 3,
      TYPE_FTP_RAW = 4,
      TYPE_DC      = 5,
      TYPE_HTTP    = 6
    };

#ifdef KMESS_NETWORK_WINDOW
    // Show the window if there are connection logs to show
    void                   show();
    // Add a log message to the last log entry
    void                   addLogMessage(QObject *connection, const QString &message);
    // Add an incoming message to the log.
    void                   addIncomingMessage(QObject *connection, const QByteArray &message);
    // Add an outgoing message to the log.
    void                   addOutgoingMessage(QObject *connection, const QByteArray &message);
    // Inform the connection was closed
    void                   connectionClosed(QObject *connection);
    // Return the primary instance of the network window.
    static NetworkWindow*  instance();
    // Set the title of the connection in the display
    void                   setConnectionTitle(QObject *connection, const QString &title);

  private:
    struct ConnectionEntry;
    // The internal function to add a message
    void                   addMessage(ConnectionEntry *entry, QString html);
    // Return a log description for a standard command.
    QString                describeCommand(const QString &command);
    // Return a log description for the direct connection preamble
    QString                describeDirectConnectionPreamble(const QByteArray &message);
    // Return a log description for the mime message
    QString                describeMimeMessage(const QString &mimeMessage);
    // Return a log description for the p2p message
    QString                describeP2PMessage(const QByteArray &message, const int headerStart);
    // Format the description to be displayed
    QString                formatDescription(const QString &description);
    // Format the message to be displayed
    QString                formatMessage(ConnectionEntry *entry, bool incoming, const QByteArray &message);
    // Format a msnp2p message to be displayed.
    QString                formatP2PMessage(bool incoming, const QByteArray &message, const int headerStart);
    // Format a utf-8 string to be displayed
    QString                formatRawData(bool incoming, const QByteArray &message,
                                         const int start, const int length, const int bytesPerRow = 32);
    // Format a utf-8 string to be displayed
    QString                formatString(const QString &message);
    // Return the current time.
    QString                getTime() const;
    // Find the tab for the connection, or create a new one.
    ConnectionEntry *      getConnectionEntry(QObject *connection);

    private slots: // Private slots
    // The 'save tab' button was pressed.
      void                  slotUser1();
    // The 'clear tab' button was pressed.
      void                  slotUser2();
    // The 'close tab' button was pressed.
      void                  slotUser3();

#endif

  private:
    // The connection types
    struct ConnectionEntry
    {
      KTextBrowser  *logView;
      ConnectionType type;
      QDateTime      lastMessage;
    };

    // The html view for each connection
    QPtrDict<ConnectionEntry> connectionViews_;  // void* keys, KTextBrowser* values
    // The tab bar with all connections
    QTabWidget            *connectionTabs_;
    // The instance of the network window
    static NetworkWindow  *instance_;

};


#endif

Generated by  Doxygen 1.6.0   Back to index