monitor.cpp
author Markus Bröker <mbroeker@largo.homelinux.org>
Fri, 10 Apr 2009 21:21:11 +0200
changeset 5 70980306fd61
parent 4 fdf04a93faeb
child 7 f23b595e590e
permissions -rw-r--r--
lintian checks minimized the lintian warnings, QoS

/*
 *  $Id: monitor.cpp 54 2008-01-10 00:24:52Z mbroeker $
 * $URL: http://localhost/svn/cpp/qMonitor/trunk/monitor.cpp $
 */

#include "include/monitor.h"
#include "include/readerthread.h"

#ifndef ICON_PATH
#define ICON_PATH "/usr/share/icons/qMonitor_icon.png"
#endif

#define HTML_MESSAGE \
"<p align='center'><h1>qMonitor</h1><br></p>" \
"<p align='center'>" \
"<li>W&auml;hlen Sie das Protokoll</li>" \
"<li>W&auml;hlen Sie einen Port (0=ALLE)</li>" \
"<li>Dr&uuml;cken Sie Start</li>" \
"<br><br>" \
"<h5>Dieses Programm zeigt den Traffic im Netz an und unterst&uuml;tzt Sie bei t&auml;glichen Aufgaben:</h5><br><br>" \
"<li>Kontrolle der TCP/UDP Verbindungen</li>" \
"<li>&Uuml;berwachung von textbasierten Serverdiensten</li>" \
"<li>Protokollanalyse</li>" \
"</p>"

Monitor::Monitor (QWidget * parent)
{
    setupUi ((QDialog *) this);
    textEdit->setReadOnly (true);

    listWidget1->insertItem (0, "TCP");
    listWidget1->insertItem (1, "UDP");
    listWidget1->insertItem (2, "ICMP");
    listWidget1->insertItem (3, "RAW");
    listWidget1->insertItem (4, "IP");

    Protocol["TCP"] = IPPROTO_TCP;
    Protocol["UDP"] = IPPROTO_UDP;
    Protocol["ICMP"] = IPPROTO_ICMP;
    Protocol["RAW"] = IPPROTO_RAW;
    Protocol["IP"] = IPPROTO_IP;

    listWidget1->setCurrentRow (0);
    lineEdit1->setText ("0");

    setWindowIcon (QPixmap (ICON_PATH));

    textEdit->insertHtml (HTML_MESSAGE);

    try {
        reader = new readerThread (this);
    } catch (std::exception const &e) {
        textEdit->append (e.what ());
        reader = NULL;
    }

    connect (pushButton1, SIGNAL (clicked ()), this, SLOT (startCapture ()));
    connect (pushButton2, SIGNAL (clicked ()), this, SLOT (stopCapture ()));

}

Monitor::~Monitor ()
{
    if (reader != NULL)
        delete reader;
}

void Monitor::startCapture ()
{
    textEdit->clear ();

    if (reader != NULL) {
        if (!reader->isRunning ())
            reader->start (QThread::NormalPriority);
    }
}

void Monitor::stopCapture ()
{
    if (reader != NULL) {
        if (reader->isRunning ())
            reader->terminate ();
    }
}

int Monitor::getProtocol ()
{
    return Protocol[listWidget1->item (listWidget1->currentRow ())->text ()];
}

int Monitor::getPort ()
{
    return lineEdit1->text ().toInt ();
}

void Monitor::customEvent (QEvent * e)
{
    if (e->type () == MSG_EVENT) {
        DataChangeEvent *me = (DataChangeEvent *) e;

        textEdit->append (me->Text ());
    }
}