[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/network/ksniffer
From: Giovanni Venturi <gventuri73 () tiscali ! it>
Date: 2008-10-16 20:24:05
Message-ID: 1224188645.280325.2460.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 872300 by gianni:
- Remember the last network device you used to capture packets in the previous \
execution of KSniffer
- Avoid the overlap of message popup
M +2 -0 Changelog
M +1 -1 Makefile.am
M +33 -23 ksniffer.cpp
M +5 -5 ksniffer.h
M +52 -6 ksnifferpassivepopup.cpp
M +45 -4 ksnifferpassivepopup.h
M +2 -2 main.cpp
M +0 -1 options/guioptiontab.cpp
M +0 -1 options/snifferoptiontab.cpp
--- trunk/playground/network/ksniffer/Changelog #872299:872300
@@ -3,7 +3,9 @@
- Fixed bug: don't get the correct number of packets if you change them more times \
in the options
- Fixed a Debian/Ubuntu issue starting ksniff backend: thanks to Kubuntu \
developers for the patch :)
- When you decide for a "New Capture" the dialog remember your last choice
+ - Remember the last network device you used to capture packets in the previous \
execution of KSniffer
- Added more output in the error dialog in case of libpcap gets an error
+ - Avoid the overlap of message popup
KSniffer 0.3.2 [21 February 2008]
- More information for ARP protocol
--- trunk/playground/network/ksniffer/Makefile.am #872299:872300
@@ -8,7 +8,7 @@
# set the include path for X, qt and KDE
INCLUDES = -I./options $(LIBPCAP_CFLAGS) $(all_includes)
-# the library search path.
+# the library search path.
ksniffer_LDFLAGS = $(KDE_RPATH) $(all_libraries)
# the libraries to link against.
--- trunk/playground/network/ksniffer/ksniffer.cpp #872299:872300
@@ -65,7 +65,6 @@
#include "packet.h"
#include "ksniffermainwidget.h"
//#include "ksnifferiface.h"
-#include "ksnifferpassivepopup.h"
#include "errorcode.h"
@@ -207,21 +206,6 @@
}
-KSniffer::~KSniffer()
-{
- m_packets->clearList();
-
- delete m_sysTray;
- delete m_sniffer;
- delete m_options;
- delete m_packets;
- delete m_actStop;
- delete m_mainWidgetUI;
- delete m_actOpenRecent;
- delete m_timer;
- delete m_portNumberNameList;
-}
-
void KSniffer::load(const KURL& url)
{
QString target;
@@ -428,6 +412,11 @@
m_mustShowPacketsNow = !m_options->showAfter();
m_showTrayBar = m_options->showTrayBar();
+
+ // reassign the network interface where last time you started capture
+ KConfig* c = kapp->config();
+ c->setGroup( "General Options" );
+ m_currentInterfaceText = c->readEntry( "Last Captured Device" ) ;
}
@@ -436,6 +425,14 @@
// save recent opened files
m_actOpenRecent->saveEntries( m_config );
m_config->sync();
+
+ // reassign the network interface where last time you started capture
+ KConfig* c = kapp->config();
+ c->setGroup( "General Options" );
+ c->writeEntry( "Last Captured Device", m_currentInterfaceText );
+
+ // assign the version number of KSniffer: not yet used
+ c->writeEntry( "Version", "0.3.3" );
}
@@ -756,7 +753,7 @@
// start sniffing getting packets from a libpcap selected file
startSniffingFromFile();
- KSnifferPassivePopup::message( i18n("Capturing"), i18n("<p>Now starting to get \
the packets from the file.</p>"), this ); + m_messagePopup.message( \
i18n("Capturing"), i18n("<p>Now starting to get the packets from the file.</p>"), \
this ); changeStatusbar( i18n("Getting packets from file.") );
}
}
@@ -942,7 +939,7 @@
if (m_options->showWarning())
{
if (m_options->showPassiveWarn())
- KSnifferPassivePopup::message( i18n("Capturing"), i18n("<p>You got no \
packets.</p>"), this ); + m_messagePopup.message( i18n("Capturing"), \
i18n("<p>You got no packets.</p>"), this ); else
KMessageBox::information(this, i18n("You got no packets."));
}
@@ -965,7 +962,7 @@
if (m_options->showWarning())
{
if (m_options->showPassiveWarn())
- KSnifferPassivePopup::message( i18n("Capturing"), i18n("<p>You got no \
packets.</p>"), this ); + m_messagePopup.message( i18n("Capturing"), \
i18n("<p>You got no packets.</p>"), this ); else
//FIXME: this dialog is shown also when the sniffing is too fast and the \
packets are not displayed at once KMessageBox::information(this, i18n("You got no \
packets.")); @@ -1002,7 +999,7 @@
if (m_sniffer->countPackets() > 0)
{
- KSnifferPassivePopup::message( i18n("Capturing"), i18n("<p>Captured <b>%1</b> \
packets for a total of <b>%2</b> bytes.</p>") + m_messagePopup.message( \
i18n("Capturing"), i18n("<p>Captured <b>%1</b> packets for a total of <b>%2</b> \
bytes.</p>")
.arg(m_sniffer->countPackets()).arg(m_sniffer->packetsTotalSize()), this );
}
}
@@ -1073,7 +1070,7 @@
// to avoid crash disable sorting
m_mainWidgetUI->setSortList( false );
- KSnifferPassivePopup::message( i18n("Capturing"), i18n("<p>Now starting to display \
the captured packets.</p>"), this ); + m_messagePopup.message( i18n("Capturing"), \
i18n("<p>Now starting to display the captured packets.</p>"), this ); \
changeStatusbar( i18n("Displaying captured packets.") );
// tell the view what file use to get packets
@@ -1135,7 +1132,7 @@
}
else
{
- KSnifferPassivePopup::message( i18n("Displaying captured packets"),
+ m_messagePopup.message( i18n("Displaying captured packets"),
i18n("<p>Ok, the captured packets are all in the list.</p>"), this );
readyStatusbar();
@@ -1223,6 +1220,19 @@
// delay exit from KSniffer if Job's not finished
kapp->deref();
+
+ /*
+ delete m_sysTray;
+ delete m_sniffer;
+ delete m_options;
+ delete m_packets;
+ delete m_actStop;
+ delete m_mainWidgetUI;
+ delete m_actOpenRecent;
+ delete m_timer;
+ delete m_portNumberNameList;
+
+ */
}
@@ -1489,7 +1499,7 @@
// starting capture variable
m_doingCapture = true;
- KSnifferPassivePopup::message( i18n("Capturing"),
+ m_messagePopup.message( i18n("Capturing"),
i18n("<p>You selected <b>%1</b> interface.<br>Now starting \
to capture packets.</p>")
.arg(interface), this );
--- trunk/playground/network/ksniffer/ksniffer.h #872299:872300
@@ -31,6 +31,7 @@
#include "sniffer.h"
#include "options/captureoptions.h"
#include "options/ksnifferconfig.h"
+#include "ksnifferpassivepopup.h"
//#include "ksnifferiface.h"
class KToggleAction;
@@ -40,7 +41,9 @@
class KSystemTray;
class KTempFile;
class KProcess;
+
class PacketManager;
+class KSnifferPassivePopup;
class QString;
class QTimer;
@@ -65,11 +68,6 @@
*/
KSniffer(const bool captureEnabled);
- /**
- * Default Destructor
- */
- virtual ~KSniffer();
-
KSnifferMainWidget* getMainView() { return m_mainWidgetUI; }
KSystemTray* getSysTray() { return m_sysTray; }
@@ -229,6 +227,8 @@
* is the current selected interface assigned by the combobox
*/
QString m_currentInterfaceText;
+
+ KSnifferPassivePopup m_messagePopup;
};
#endif // KSNIFFER_H
--- trunk/playground/network/ksniffer/ksnifferpassivepopup.cpp #872299:872300
@@ -19,27 +19,73 @@
***************************************************************************/
#include <qpixmap.h>
+#include <qtimer.h>
+#include <qptrlist.h>
+#include <kpassivepopup.h>
#include <kiconloader.h>
#include "ksnifferpassivepopup.h"
KSnifferPassivePopup::KSnifferPassivePopup()
{
+ m_timer = new QTimer;
+ m_queue = new QPtrQueue<PassiveMessage>;
+ m_queue->setAutoDelete( true );
+
+ connect(m_timer, SIGNAL(timeout()), this, SLOT(check()));
}
+
+KSnifferPassivePopup::~KSnifferPassivePopup()
+{
+ delete m_timer;
+ delete m_queue;
+}
+
+
void KSnifferPassivePopup::message(const QString& caption, const QString& text, \
QWidget *parent, const char *name, int seconds) {
+ // we need a semaphore to keep the order in a multi threaded environment:
+ // for KSniffer it's not the case, but this could become a new generic class
+ // and could have sense use a mutex here
+ m_mutex.lock();
+
+ PassiveMessage *mex = new PassiveMessage(caption, text, parent, (char*)name, \
seconds); + m_queue->enqueue(mex);
+ if (m_queue->count() == 1)
+ showMessage();
+ m_mutex.unlock();
+}
+
+
+void KSnifferPassivePopup::check()
+{
+ // the message has been shown and you can remove it from the queue
+ m_queue->dequeue();
+ if (!m_queue->isEmpty())
+ showMessage();
+}
+
+
+void KSnifferPassivePopup::showMessage()
+{
+ // extract the message
+ PassiveMessage *mex = m_queue->head();
+ m_timer->start(mex->seconds() * 1000, true);
+
QPixmap icon = BarIcon( "ksniffer" );
- KPassivePopup *popup = new KPassivePopup( parent, "popup" );
+ KPassivePopup *popup = new KPassivePopup( mex->parent(), "popup" );
popup->setAutoDelete( true );
- popup->setTimeout( seconds*1000 );
- popup->setView( caption, text, icon);
+ popup->setTimeout( mex->seconds()*1000 );
+ popup->setView( mex->caption(), mex->text(), icon);
popup->show();
- if (parent->isShown() && !parent->isMinimized())
+ if (mex->parent()->isShown() && !mex->parent()->isMinimized())
{
- popup->move( QPoint(parent->x() + (parent->width() - popup->width()) / 2,
- parent->y() + (parent->height() - popup->height()) / 2) );
+ popup->move( QPoint(mex->parent()->x() + (mex->parent()->width() - \
popup->width()) / 2, + mex->parent()->y() + (mex->parent()->height() - \
popup->height()) / 2) ); }
}
+
+#include "ksnifferpassivepopup.moc"
--- trunk/playground/network/ksniffer/ksnifferpassivepopup.h #872299:872300
@@ -21,14 +21,55 @@
#ifndef KSNIFFERPASSIVEPOPUP_H_
#define KSNIFFERPASSIVEPOPUP_H_
-#include <kpassivepopup.h>
+#include <qptrqueue.h>
+#include <qmutex.h>
-class KSnifferPassivePopup : public KPassivePopup
+class QTimer;
+class KPassivePopup;
+
+class PassiveMessage
{
- KSnifferPassivePopup();
+ private:
+ QString m_caption;
+ QString m_text;
+ QWidget *m_parent;
+ char *m_name;
+ int m_seconds;
public:
- static void message(const QString& caption, const QString& text, QWidget \
*parent, const char *name=0, int seconds = 3); + PassiveMessage() {}
+ PassiveMessage(const QString& caption, const QString& text, QWidget *parent, \
char *name=0, int seconds = 3) : + m_caption(caption), m_text(text), \
m_parent(parent), m_name(name), m_seconds(seconds) {} +
+ QString caption() const { return m_caption; }
+ QString text() const { return m_text; }
+ QWidget* parent() const { return m_parent; }
+ char* name() const { return m_name; }
+ int seconds() { return m_seconds; }
};
+
+class KSnifferPassivePopup : public QObject
+{
+ Q_OBJECT
+
+ public:
+ KSnifferPassivePopup();
+ ~KSnifferPassivePopup();
+
+ void message(const QString& caption, const QString& text, QWidget *parent, const \
char *name=0, int seconds = 3); +
+ private:
+ void showMessage();
+
+ private:
+ KPassivePopup *m_passivePopup;
+ QTimer *m_timer;
+ QPtrQueue<PassiveMessage> *m_queue;
+ QMutex m_mutex;
+
+ private slots:
+ void check();
+};
+
#endif // KSNIFFERPASSIVEPOPUP_H_
--- trunk/playground/network/ksniffer/main.cpp #872299:872300
@@ -119,8 +119,8 @@
}
else
{
- int i = 0;
- for (; i < args->count(); i++)
+ int i;
+ for (i = 0; i < args->count(); i++)
{
mainWidget = new KSniffer( captureEnabled );
mainWidget->show();
--- trunk/playground/network/ksniffer/options/guioptiontab.cpp #872299:872300
@@ -154,7 +154,6 @@
c->setGroup( "General Options" );
c->writeEntry( "Show splash", m_checkShowSplash->isChecked() );
- c->writeEntry( "Version", "0.3.2" );
c->writeEntry( "Show packets after stopped capture", m_afterDisplay->isChecked() \
); c->writeEntry( "Show Tray Bar", m_trayBar->isChecked() );
--- trunk/playground/network/ksniffer/options/snifferoptiontab.cpp #872299:872300
@@ -245,7 +245,6 @@
}
m_editTempDir->setURL( fi.absFilePath() );
- c->writeEntry( "Version", "0.3.2" );
c->writePathEntry( "Temp dir", m_editTempDir->url() );
// save stopping capture type: manually, ...
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic